mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-10 18:51:21 +03:00
0025344: Draw variables do not follow the scope of TCL level
Use NCollection_Map instead of instantiation of TCollection_Map Test-cases for issue #25344 Correct error in test script: the shape variable assigned by the command 'restore' must not be referred by '$'.
This commit is contained in:
parent
a69a08ee9e
commit
191082ac71
@ -29,7 +29,7 @@
|
|||||||
#include <Draw_SequenceOfDrawable3D.hxx>
|
#include <Draw_SequenceOfDrawable3D.hxx>
|
||||||
#include <Draw_ProgressIndicator.hxx>
|
#include <Draw_ProgressIndicator.hxx>
|
||||||
|
|
||||||
#include <NCollection_DataMap.hxx>
|
#include <NCollection_Map.hxx>
|
||||||
|
|
||||||
#include <ios>
|
#include <ios>
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ extern Draw_Interpretor theCommands;
|
|||||||
// The Integer Value is the content of the TCl variable
|
// The Integer Value is the content of the TCl variable
|
||||||
//===============================================
|
//===============================================
|
||||||
|
|
||||||
static NCollection_DataMap<TCollection_AsciiString,Handle(Draw_Drawable3D)> theVariables;
|
static NCollection_Map<Handle(Draw_Drawable3D)> theVariables;
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
//function : FindVariable
|
//function : FindVariable
|
||||||
@ -305,9 +305,9 @@ static Standard_Integer erase(Draw_Interpretor& di, Standard_Integer n, const ch
|
|||||||
|
|
||||||
// sauvegarde des proteges visibles
|
// sauvegarde des proteges visibles
|
||||||
Draw_SequenceOfDrawable3D prot;
|
Draw_SequenceOfDrawable3D prot;
|
||||||
NCollection_DataMap<TCollection_AsciiString,Handle(Draw_Drawable3D)>::Iterator aMapIt (theVariables);
|
NCollection_Map<Handle(Draw_Drawable3D)>::Iterator aMapIt (theVariables);
|
||||||
for (; aMapIt.More(); aMapIt.Next()) {
|
for (; aMapIt.More(); aMapIt.Next()) {
|
||||||
const Handle(Draw_Drawable3D)& D = aMapIt.Value();
|
const Handle(Draw_Drawable3D)& D = aMapIt.Key();
|
||||||
if (!D.IsNull()) {
|
if (!D.IsNull()) {
|
||||||
if (D->Protected() && D->Visible())
|
if (D->Protected() && D->Visible())
|
||||||
prot.Append(D);
|
prot.Append(D);
|
||||||
@ -719,30 +719,32 @@ void Draw::Set(const Standard_CString name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MKV 29.03.05
|
// MKV 29.03.05
|
||||||
static char* tracevar(ClientData, Tcl_Interp*,const char* name,const char*, Standard_Integer)
|
static char* tracevar(ClientData CD, Tcl_Interp*,const char* name,const char*, int)
|
||||||
{
|
{
|
||||||
// protect if the map was destroyed before the interpretor
|
// protect if the map was destroyed before the interpretor
|
||||||
if (theVariables.IsEmpty()) return NULL;
|
if (theVariables.IsEmpty()) return NULL;
|
||||||
// MKV 29.03.05
|
|
||||||
Handle(Draw_Drawable3D)& D = theVariables(name);
|
// MSV 9.10.14 CR25344
|
||||||
|
Handle(Draw_Drawable3D) D(reinterpret_cast<Draw_Drawable3D*>(CD));
|
||||||
if (D.IsNull()) {
|
if (D.IsNull()) {
|
||||||
theVariables.UnBind(name);
|
Tcl_UntraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,
|
||||||
|
tracevar,CD);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (D->Protected()) {
|
if (D->Protected()) {
|
||||||
D->Name(Tcl_SetVar(theCommands.Interp(),name,name,0));
|
D->Name(Tcl_SetVar(theCommands.Interp(),name,name,0));
|
||||||
return (char*) "variable is protected";
|
return (char*) "variable is protected";
|
||||||
} else {
|
} else {
|
||||||
Tcl_UntraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,tracevar,NULL);
|
|
||||||
if (D->Visible()) {
|
if (D->Visible()) {
|
||||||
dout.RemoveDrawable(D);
|
dout.RemoveDrawable(D);
|
||||||
if (D->Is3D())
|
if (D->Is3D())
|
||||||
repaint3d = Standard_True;
|
repaint3d = Standard_True;
|
||||||
else
|
else
|
||||||
repaint2d = Standard_True;
|
repaint2d = Standard_True;
|
||||||
}
|
}
|
||||||
D.Nullify();
|
Tcl_UntraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,
|
||||||
theVariables.UnBind(name);
|
tracevar,CD);
|
||||||
|
theVariables.Remove(D);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -752,8 +754,8 @@ static char* tracevar(ClientData, Tcl_Interp*,const char* name,const char*, Stan
|
|||||||
//purpose :
|
//purpose :
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
void Draw::Set(const Standard_CString name,
|
void Draw::Set(const Standard_CString name,
|
||||||
const Handle(Draw_Drawable3D)& D,
|
const Handle(Draw_Drawable3D)& D,
|
||||||
const Standard_Boolean displ)
|
const Standard_Boolean displ)
|
||||||
{
|
{
|
||||||
if ((name[0] == '.') && (name[1] == '\0')) {
|
if ((name[0] == '.') && (name[1] == '\0')) {
|
||||||
if (!D.IsNull()) {
|
if (!D.IsNull()) {
|
||||||
@ -762,27 +764,34 @@ void Draw::Set(const Standard_CString name,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (theVariables.IsBound(name)) {
|
// Check if the variable with the same name exists
|
||||||
if (theVariables(name)->Protected()) {
|
ClientData aCD =
|
||||||
|
Tcl_VarTraceInfo(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,
|
||||||
|
tracevar, NULL);
|
||||||
|
Handle(Draw_Drawable3D) anOldD(reinterpret_cast<Draw_Drawable3D*>(aCD));
|
||||||
|
if (!anOldD.IsNull()) {
|
||||||
|
if (theVariables.Contains(anOldD) && anOldD->Protected()) {
|
||||||
cout << "variable is protected" << endl;
|
cout << "variable is protected" << endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
anOldD.Nullify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Tcl_UnsetVar(theCommands.Interp(),name,0);
|
||||||
|
|
||||||
if (!D.IsNull()) {
|
if (!D.IsNull()) {
|
||||||
Tcl_UnsetVar(theCommands.Interp(),name,0);
|
theVariables.Add(D);
|
||||||
theVariables.Bind(name,D);
|
|
||||||
// MKV 29.03.05
|
|
||||||
D->Name(Tcl_SetVar(theCommands.Interp(),name,name,0));
|
D->Name(Tcl_SetVar(theCommands.Interp(),name,name,0));
|
||||||
|
|
||||||
// set the trace function
|
// set the trace function
|
||||||
Tcl_TraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,tracevar,NULL);
|
Tcl_TraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,
|
||||||
|
tracevar,reinterpret_cast<ClientData>(D.operator->()));
|
||||||
if (displ) {
|
if (displ) {
|
||||||
if (!D->Visible())
|
if (!D->Visible())
|
||||||
dout << D;
|
dout << D;
|
||||||
}
|
}
|
||||||
else if (D->Visible())
|
else if (D->Visible())
|
||||||
dout.RemoveDrawable(D);
|
dout.RemoveDrawable(D);
|
||||||
} else {
|
|
||||||
Tcl_UnsetVar(theCommands.Interp(),name,0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -827,8 +836,12 @@ Handle(Draw_Drawable3D) Draw::Get(Standard_CString& name,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// MKV 29.03.05
|
ClientData aCD =
|
||||||
theVariables.Find(name,D);
|
Tcl_VarTraceInfo(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,
|
||||||
|
tracevar, NULL);
|
||||||
|
D = reinterpret_cast<Draw_Drawable3D*>(aCD);
|
||||||
|
if (!theVariables.Contains(D))
|
||||||
|
D.Nullify();
|
||||||
#if 0
|
#if 0
|
||||||
if (D.IsNull() && complain)
|
if (D.IsNull() && complain)
|
||||||
cout <<name<<" does not exist"<<endl;
|
cout <<name<<" does not exist"<<endl;
|
||||||
|
@ -275,9 +275,10 @@ help datadir {datadir [directory]} "DRAW Variables management"
|
|||||||
|
|
||||||
proc save {name {file ""}} {
|
proc save {name {file ""}} {
|
||||||
if {$file == ""} {set file $name}
|
if {$file == ""} {set file $name}
|
||||||
if {![isdraw $name]} {error "save : $name is not a Draw variable"}
|
upvar $name n
|
||||||
|
if {![isdraw n]} {error "save : $name is not a Draw variable"}
|
||||||
global Draw_DataDir
|
global Draw_DataDir
|
||||||
bsave $name [file join $Draw_DataDir $file]
|
bsave n [file join $Draw_DataDir $file]
|
||||||
return [file join $Draw_DataDir $file]
|
return [file join $Draw_DataDir $file]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +290,8 @@ proc restore {file {name ""}} {
|
|||||||
set name [file rootname [file tail $file]]
|
set name [file rootname [file tail $file]]
|
||||||
}
|
}
|
||||||
global Draw_DataDir
|
global Draw_DataDir
|
||||||
uplevel #0 "brestore [file join $Draw_DataDir $file ] $name"
|
upvar $name n
|
||||||
|
brestore [file join $Draw_DataDir $file ] n
|
||||||
return $name
|
return $name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
tests/bugs/demo/bug25344_1
Normal file
22
tests/bugs/demo/bug25344_1
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
puts "========"
|
||||||
|
puts "OCC25344"
|
||||||
|
puts "========"
|
||||||
|
puts ""
|
||||||
|
#######################################################
|
||||||
|
# Draw variables do not follow the scope of TCL level
|
||||||
|
#######################################################
|
||||||
|
|
||||||
|
proc setproc {} {
|
||||||
|
dset local_var 1.1
|
||||||
|
puts "in setproc scope: local_var=[dval local_var]"
|
||||||
|
}
|
||||||
|
|
||||||
|
setproc
|
||||||
|
puts "in global scope: local_var=[dval local_var]"
|
||||||
|
|
||||||
|
if {[dval local_var] != 0} {
|
||||||
|
puts "ERROR: local_var is set, but must not"
|
||||||
|
if {[lsearch [directory] local_var] == -1} {
|
||||||
|
puts "ERROR: as it is absent among TCL variables"
|
||||||
|
}
|
||||||
|
}
|
27
tests/bugs/demo/bug25344_2
Normal file
27
tests/bugs/demo/bug25344_2
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
puts "========"
|
||||||
|
puts "OCC25344"
|
||||||
|
puts "========"
|
||||||
|
puts ""
|
||||||
|
#######################################################
|
||||||
|
# Draw variables do not follow the scope of TCL level
|
||||||
|
#######################################################
|
||||||
|
|
||||||
|
proc setproc {var val} {
|
||||||
|
upvar $var local_var
|
||||||
|
dset local_var $val
|
||||||
|
}
|
||||||
|
|
||||||
|
setproc a 1.1
|
||||||
|
|
||||||
|
puts "dval a = [dval a]"
|
||||||
|
puts "dval local_var = [dval local_var]"
|
||||||
|
|
||||||
|
if {[dval a] == 0} {
|
||||||
|
puts "ERROR: value is not set"
|
||||||
|
}
|
||||||
|
if {[dval local_var] == -1} {
|
||||||
|
puts "ERROR: local_var is set, but must not"
|
||||||
|
if {[lsearch [directory] local_var] == -1} {
|
||||||
|
puts "ERROR: as it is absent among TCL variables"
|
||||||
|
}
|
||||||
|
}
|
32
tests/bugs/demo/bug25344_3
Normal file
32
tests/bugs/demo/bug25344_3
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
puts "========"
|
||||||
|
puts "OCC25344"
|
||||||
|
puts "========"
|
||||||
|
puts ""
|
||||||
|
#######################################################
|
||||||
|
# Draw variables do not follow the scope of TCL level
|
||||||
|
#######################################################
|
||||||
|
|
||||||
|
proc boxproc {shape} {
|
||||||
|
upvar $shape local_shape
|
||||||
|
box local_shape 1 1 1
|
||||||
|
}
|
||||||
|
|
||||||
|
boxproc mybox
|
||||||
|
|
||||||
|
if {[dtyp mybox] == ""} {
|
||||||
|
puts "ERROR: box mybox is not created"
|
||||||
|
} else {
|
||||||
|
puts "SUCCESS: mybox is created"
|
||||||
|
if {[lsearch [directory] mybox] == -1} {
|
||||||
|
puts "ERRROR: but it is absent among TCL variables"
|
||||||
|
} else {
|
||||||
|
puts "SUCCESS: and it is present among TCL variables"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if {[dtyp local_shape] != ""} {
|
||||||
|
puts "Box local_shape is created"
|
||||||
|
if {[lsearch [directory] local_shape] == -1} {
|
||||||
|
puts "ERROR: but it is absent among TCL variables"
|
||||||
|
}
|
||||||
|
}
|
28
tests/bugs/demo/bug25344_4
Normal file
28
tests/bugs/demo/bug25344_4
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
puts "========"
|
||||||
|
puts "OCC25344"
|
||||||
|
puts "========"
|
||||||
|
puts ""
|
||||||
|
#######################################################
|
||||||
|
# Draw variables do not follow the scope of TCL level
|
||||||
|
#######################################################
|
||||||
|
|
||||||
|
box a 1 1 1
|
||||||
|
|
||||||
|
set filename "box file.brep"
|
||||||
|
|
||||||
|
if [catch {save a $filename}] {
|
||||||
|
puts "ERROR: save failure"
|
||||||
|
} else {
|
||||||
|
if ![file exists $filename] {
|
||||||
|
puts "ERROR: file \"$filename\" is not created"
|
||||||
|
} else {
|
||||||
|
if [catch {restore $filename b}] {
|
||||||
|
puts "ERROR: restore of file \"$filename\" is failure"
|
||||||
|
} else {
|
||||||
|
if {[dtyp a] != [dtyp b]} {
|
||||||
|
puts "ERROR: types of shape and its restored copy do not equal"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file delete $filename
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,6 @@ if {$is_ok != $check_ok} {
|
|||||||
puts "Error : results of command \"whatis\" are different"
|
puts "Error : results of command \"whatis\" are different"
|
||||||
}
|
}
|
||||||
|
|
||||||
set check_puts [puts $b]
|
if {$b != "b"} {
|
||||||
if {$check_puts != ""} {
|
puts "Error : tcl variable doesn't point to same-named draw variable"
|
||||||
puts "Error : result of command \"puts\" is wrong"
|
|
||||||
}
|
}
|
@ -8,9 +8,8 @@ if {![catch {set b aaaaa}]} {
|
|||||||
puts "Error : variable was changed"
|
puts "Error : variable was changed"
|
||||||
}
|
}
|
||||||
|
|
||||||
set check_puts [puts $b]
|
if {$b != "b"} {
|
||||||
if {$check_puts != ""} {
|
puts "Error : tcl variable doesn't point to same-named draw variable"
|
||||||
puts "Error : result of command \"puts\" is wrong"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set check_ok [whatis b]
|
set check_ok [whatis b]
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
#################### select shape and check selection procedure ####################
|
#################### select shape and check selection procedure ####################
|
||||||
proc Select {lab shape context} {
|
proc Select {lab shape context} {
|
||||||
global D IsDone TestError
|
global D IsDone TestError
|
||||||
|
upvar 1 $shape myshape $context mycontext
|
||||||
set res ""
|
set res ""
|
||||||
if {[string compare $context ""] == 0} {
|
if {[string compare $context ""] == 0} {
|
||||||
if {[catch {set res [SelectShape D $lab $shape]}]} {
|
if {[catch {set res [SelectShape D $lab myshape]}]} {
|
||||||
set IsDone 0
|
set IsDone 0
|
||||||
set TestError "$TestError # SelectShape bad result for args: $lab shape"
|
set TestError "$TestError # SelectShape bad result for args: $lab myshape"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if {[catch {set res [SelectShape D $lab $shape $context]}]} {
|
if {[catch {set res [SelectShape D $lab myshape mycontext]}]} {
|
||||||
set IsDone 0
|
set IsDone 0
|
||||||
set TestError "$TestError # SelectShape bad result for args: $lab shape"
|
set TestError "$TestError # SelectShape bad result for args: $lab myshape"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [CenterOfShape $shape]
|
return [CenterOfShape myshape]
|
||||||
}
|
}
|
||||||
|
|
||||||
if {[catch {set TestLab}] == 1} {
|
if {[catch {set TestLab}] == 1} {
|
||||||
|
@ -21,11 +21,12 @@ if { [info exists test_image ] == 0 } {
|
|||||||
proc val2d { c u1 u2 n } {
|
proc val2d { c u1 u2 n } {
|
||||||
|
|
||||||
dset du ($u2-$u1)/$n
|
dset du ($u2-$u1)/$n
|
||||||
|
upvar $c cc
|
||||||
|
|
||||||
set i 1
|
set i 1
|
||||||
|
|
||||||
for {dset u $u1} { [dval u] <= $u2} {dset u ($u1+$i*[dval du])} {
|
for {dset u $u1} { [dval u] <= $u2} {dset u ($u1+$i*[dval du])} {
|
||||||
2dcvalue $c u x y dx dy d2x d2y ;
|
2dcvalue cc u x y dx dy d2x d2y ;
|
||||||
global p_$i d1_$i d2_$i
|
global p_$i d1_$i d2_$i
|
||||||
point p_$i x y;
|
point p_$i x y;
|
||||||
puts "u = [dval u]"
|
puts "u = [dval u]"
|
||||||
@ -46,11 +47,12 @@ proc val2d { c u1 u2 n } {
|
|||||||
proc val3d { c u1 u2 n } {
|
proc val3d { c u1 u2 n } {
|
||||||
|
|
||||||
dset du ($u2-$u1)/$n
|
dset du ($u2-$u1)/$n
|
||||||
|
upvar $c cc
|
||||||
|
|
||||||
set i 1
|
set i 1
|
||||||
|
|
||||||
for {dset u $u1} { [dval u] <= $u2} {dset u (u+[dval du])} {
|
for {dset u $u1} { [dval u] <= $u2} {dset u (u+[dval du])} {
|
||||||
cvalue $c u x y z dx dy dz d2x d2y d2z ;
|
cvalue cc u x y z dx dy dz d2x d2y d2z ;
|
||||||
point p_$i x y z;
|
point p_$i x y z;
|
||||||
puts "u = [dval u]"
|
puts "u = [dval u]"
|
||||||
puts "p_$i [dval x ] [dval y ] [dval z]";
|
puts "p_$i [dval x ] [dval y ] [dval z]";
|
||||||
@ -73,8 +75,10 @@ proc compare {r1 r2 tol} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
proc comparepnt2d {p1 p2 tol} {
|
proc comparepnt2d {p1 p2 tol} {
|
||||||
coord $p1 x1 y1
|
upvar $p1 pp1
|
||||||
coord $p2 x2 y2
|
upvar $p2 pp2
|
||||||
|
coord pp1 x1 y1
|
||||||
|
coord pp2 x2 y2
|
||||||
compare [dval x1] [dval x2] $tol
|
compare [dval x1] [dval x2] $tol
|
||||||
compare [dval y1] [dval y2] $tol
|
compare [dval y1] [dval y2] $tol
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,8 @@ puts " "
|
|||||||
|
|
||||||
# Check if area of triangles is valid
|
# Check if area of triangles is valid
|
||||||
proc CheckTriArea {shape {eps 0}} {
|
proc CheckTriArea {shape {eps 0}} {
|
||||||
set area [triarea $shape $eps]
|
upvar #0 $shape a
|
||||||
|
set area [triarea a $eps]
|
||||||
set t_area [lindex $area 0]
|
set t_area [lindex $area 0]
|
||||||
set g_area [expr abs([lindex $area 1])]
|
set g_area [expr abs([lindex $area 1])]
|
||||||
puts "area by triangles: $t_area"
|
puts "area by triangles: $t_area"
|
||||||
|
@ -115,7 +115,7 @@ if { [isdraw result] && $mist == 0} {
|
|||||||
}
|
}
|
||||||
#check for bsection
|
#check for bsection
|
||||||
if { [info exists GlobFaces] && [llength $GlobFaces] == 0 } {
|
if { [info exists GlobFaces] && [llength $GlobFaces] == 0 } {
|
||||||
puts [ bsection re $result $s ]
|
puts [ bsection re result s ]
|
||||||
if { [ isdraw re ] } {
|
if { [ isdraw re ] } {
|
||||||
regexp {Mass +: +([-0-9.+eE]+)} [lprops $re] full remass
|
regexp {Mass +: +([-0-9.+eE]+)} [lprops $re] full remass
|
||||||
if { $remass != 0 } {
|
if { $remass != 0 } {
|
||||||
|
@ -43,7 +43,7 @@ proc SaveToFile { aD aFile } {
|
|||||||
upvar $aD D
|
upvar $aD D
|
||||||
global FileSuffix ValidatorCheck
|
global FileSuffix ValidatorCheck
|
||||||
catch {[file delete ${aFile}]}
|
catch {[file delete ${aFile}]}
|
||||||
SaveAs $D $aFile
|
SaveAs D $aFile
|
||||||
if { [file exists $aFile] } {
|
if { [file exists $aFile] } {
|
||||||
if { $FileSuffix == "xml" && $ValidatorCheck} {
|
if { $FileSuffix == "xml" && $ValidatorCheck} {
|
||||||
ValidateXml $aFile
|
ValidateXml $aFile
|
||||||
|
Loading…
x
Reference in New Issue
Block a user