Warning was fixed.
Remarks were applied.
- class VMap in Draw was removed
- NCollection_DataMap is used to store objects
- name of object is used to associate Tcl variable with the object
- creation and changing of objects are correclty handled
Redundant casts were removed.
Initial value is restored if variable is protected.
Tests for bug #24863 were added.
Some test cases and tcl command "save" were improved.
Useless using of upvar was removed.
class Printer;
- class VMap instantiates
- DataMap from TCollection(Integer,
- Drawable3D from Draw,
- MapIntegerHasher from TColStd);
-
class MapOfAsciiString instantiates IndexedMap from TCollection(AsciiString from TCollection,AsciiString from TCollection);
Load(theDI: out Interpretor from Draw;
#include <Draw_Grid.hxx>
#include <Draw_Drawable3D.hxx>
#include <Draw_SequenceOfDrawable3D.hxx>
-#include <Draw_VMap.hxx>
#include <Draw_ProgressIndicator.hxx>
+#include <NCollection_DataMap.hxx>
+
#include <ios>
#ifdef WNT
// The Integer Value is the content of the TCl variable
//===============================================
-static Draw_VMap theVariables;
+static NCollection_DataMap<TCollection_AsciiString,Handle(Draw_Drawable3D)> theVariables;
//=======================================================================
//function : FindVariable
// sauvegarde des proteges visibles
Draw_SequenceOfDrawable3D prot;
- for (i = 1; i <= theVariables.Extent(); i++) {
- const Handle(Draw_Drawable3D)& D = *((Handle(Draw_Drawable3D)*)&theVariables(i));
+ NCollection_DataMap<TCollection_AsciiString,Handle(Draw_Drawable3D)>::Iterator aMapIt (theVariables);
+ for (; aMapIt.More(); aMapIt.Next()) {
+ const Handle(Draw_Drawable3D)& D = aMapIt.Value();
if (!D.IsNull()) {
if (D->Protected() && D->Visible())
prot.Append(D);
}
// MKV 29.03.05
-#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST)
-static char* tracevar(ClientData CD, Tcl_Interp*,const char*,const char*, Standard_Integer)
-#else
-static char* tracevar(ClientData CD, Tcl_Interp*, char*, char*, Standard_Integer)
-#endif
+static char* tracevar(ClientData, Tcl_Interp*,const char* name,const char*, Standard_Integer)
{
// protect if the map was destroyed before the interpretor
if (theVariables.IsEmpty()) return NULL;
-
// MKV 29.03.05
-#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST)
- Handle(Draw_Drawable3D)& D = *((Handle(Draw_Drawable3D)*)&theVariables((long)CD));
-#else
- Standard_Integer index = (Standard_Integer) CD;
- Handle(Draw_Drawable3D)& D = *((Handle(Draw_Drawable3D)*)&theVariables(index));
-#endif
- if (D.IsNull())
+ Handle(Draw_Drawable3D)& D = theVariables(name);
+ if (D.IsNull()) {
+ theVariables.UnBind(name);
return NULL;
- if (D->Protected())
+ }
+ if (D->Protected()) {
+ D->Name(Tcl_SetVar(theCommands.Interp(),name,name,0));
return (char*) "variable is protected";
- else {
+ } else {
+ Tcl_UntraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,tracevar,NULL);
if (D->Visible()) {
dout.RemoveDrawable(D);
if (D->Is3D())
repaint2d = Standard_True;
}
D.Nullify();
+ theVariables.UnBind(name);
return NULL;
}
}
}
}
else {
-
- Tcl_UnsetVar(theCommands.Interp(),name,0);
+ if (theVariables.IsBound(name)) {
+ if (theVariables(name)->Protected()) {
+ cout << "variable is protected" << endl;
+ return;
+ }
+ }
if (!D.IsNull()) {
- Standard_Integer ival = theVariables.Extent() + 1;
- theVariables.Bind(ival,D);
+ Tcl_UnsetVar(theCommands.Interp(),name,0);
+ theVariables.Bind(name,D);
// MKV 29.03.05
-#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST)
D->Name(Tcl_SetVar(theCommands.Interp(),name,name,0));
-#else
- D->Name(Tcl_SetVar(theCommands.Interp(),(char*)name,(char*)name,0));
-#endif
-
// set the trace function
- Tcl_TraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS,
- tracevar,(ClientData)ival);
-
+ Tcl_TraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,tracevar,NULL);
if (displ) {
if (!D->Visible())
dout << D;
}
else if (D->Visible())
dout.RemoveDrawable(D);
+ } else {
+ Tcl_UnsetVar(theCommands.Interp(),name,0);
}
}
}
Handle(Draw_Drawable3D) Draw::Get(Standard_CString& name,
const Standard_Boolean )
{
-#if !((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) || defined(USE_NON_CONST)
- Standard_PCharacter pName;
- pName=(Standard_PCharacter)name;
-#endif
- //
Standard_Boolean pick = ((name[0] == '.') && (name[1] == '\0'));
Handle(Draw_Drawable3D) D;
if (pick) {
}
else {
// MKV 29.03.05
-#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST)
- Standard_Address index =
- Tcl_VarTraceInfo(theCommands.Interp(),name,TCL_TRACE_UNSETS,
- tracevar, NULL);
- if (index != 0)
- D = Handle(Draw_Drawable3D)::DownCast(theVariables((long)index));
-#else
- Standard_Integer index = (Standard_Integer)
- Tcl_VarTraceInfo(theCommands.Interp(),
- pName,
- TCL_TRACE_UNSETS,
- tracevar, NULL);
- if (index != 0)
- D = Handle(Draw_Drawable3D)::DownCast(theVariables(index));
-#endif
+ theVariables.Find(name,D);
#if 0
if (D.IsNull() && complain)
cout <<name<<" does not exist"<<endl;
proc save {name {file ""}} {
if {$file == ""} {set file $name}
- upvar $name n
- if {![isdraw n]} {error "save : $name is not a Draw variable"}
+ if {![isdraw $name]} {error "save : $name is not a Draw variable"}
global Draw_DataDir
- bsave n [file join $Draw_DataDir $file]
+ bsave $name [file join $Draw_DataDir $file]
return [file join $Draw_DataDir $file]
}
--- /dev/null
+# Test for #24863: memory leak
+
+set listmem {}
+
+for {set i 1} {$i < 100000} {incr i} {
+ box b 10 10 10
+
+ lappend listmem [meminfo h]
+
+ if { [checktrend $listmem 0 256 "Memory leak detected"] } {
+ puts "No memory leak, $i iterations"
+ break
+ }
+}
\ No newline at end of file
--- /dev/null
+# Test for #24863: creation of variables
+
+box b 10 10 10
+set is_ok [whatis b]
+
+set b aaaa
+
+box b 10 10 10
+
+set check_ok [whatis b]
+if {$is_ok != $check_ok} {
+ puts "Error : results of command \"whatis\" are different"
+}
+
+set check_puts [puts $b]
+if {$check_puts != ""} {
+ puts "Error : result of command \"puts\" is wrong"
+}
\ No newline at end of file
--- /dev/null
+# Test for #24863: protect variable
+
+box b 10 10 10
+set is_ok [whatis b]
+protect b
+
+if {![catch {set b aaaaa}]} {
+ puts "Error : variable was changed"
+}
+
+set check_puts [puts $b]
+if {$check_puts != ""} {
+ puts "Error : result of command \"puts\" is wrong"
+}
+
+set check_ok [whatis b]
+if {$is_ok != $check_ok} {
+ puts "Error : results of command \"whatis\" are different"
+}
\ No newline at end of file
restore [locate_data_file OCC298.brep] result
checkshape result
-if [catch {tcopy result a } result] {
+if [catch {tcopy result a } res] {
puts "Faulty OCC298: function TCOPY works wrongly"
} else {
puts "OCC298 OK: function TCOPY works properly"
checkshape b2
-if [catch {bcut result b2 b1 } result] {
+if [catch {bcut result b2 b1 } res] {
puts "Faulty OCC410: function CUT works wrongly"
} else {
puts " OCC410 OK: function CUT works properly"
restore [locate_data_file OCC485a.brep] a_2
checkshape a_2
-if [catch {bfuse result a_1 a_2 } result] {
+if [catch {bfuse result a_1 a_2 } res] {
puts "Faulty OCC485: Draw hangs up during performing fuse operation"
} else {
puts "OCC485 OK: function FUSE works without Draw hangs up "
restore [locate_data_file CFI_pro15441.rle] m
explode m e
-if [catch {blend result m 2 m_36 2 m_21 } result] {
+if [catch {blend result m 2 m_36 2 m_21 } res] {
puts "Faulty OCC485: function BLEND works wrongly"
} else {
puts "OCC485 OK: function BLEND works properly "
}
regexp {max tol = ([-0-9.+eE]+)} $tolmaxres full maxtolerance
-if { [catch { expr $maxtolerance } result] } {
+if { [catch { expr $maxtolerance } res] } {
puts "Faulty ${BugNumber} : maxtolerance is wrong (1)."
}
if { $maxtolerance > 1. } {
mkedge result c 20 36
donly result
-set result [bounding result]
+set res [bounding result]
fit
-set x1 [lindex ${result} 0]
-set y1 [lindex ${result} 1]
-set z1 [lindex ${result} 2]
-set x2 [lindex ${result} 3]
-set y2 [lindex ${result} 4]
-set z2 [lindex ${result} 5]
+set x1 [lindex ${res} 0]
+set y1 [lindex ${res} 1]
+set z1 [lindex ${res} 2]
+set x2 [lindex ${res} 3]
+set y2 [lindex ${res} 4]
+set z2 [lindex ${res} 5]
set good_x1 -17.6105835090592
set good_y1 -4.7133570660117909
regexp {Mass +: +([-0-9.+eE]+)} $props_6 full CircleLength_6
# Calculation
-set pi [expr 2. * asin(1.0)]
-set TheoryCircleLength_4 [expr ${pi} * ${dia1}]
-set TheoryCircleLength_3 [expr ${pi} * (${dia1} + 2 * ${wall_thickness}) ]
-set TheoryCircleLength_6 [expr ${pi} * ${dia2}]
-set TheoryCircleLength_5 [expr ${pi} * (${dia2} + 2 * ${wall_thickness}) ]
+set Pi [expr 2. * asin(1.0)]
+set TheoryCircleLength_4 [expr ${Pi} * ${dia1}]
+set TheoryCircleLength_3 [expr ${Pi} * (${dia1} + 2 * ${wall_thickness}) ]
+set TheoryCircleLength_6 [expr ${Pi} * ${dia2}]
+set TheoryCircleLength_5 [expr ${Pi} * (${dia2} + 2 * ${wall_thickness}) ]
set delta_3 [expr abs(${CircleLength_3} - ${TheoryCircleLength_3}) / ${TheoryCircleLength_3} * 100]
set delta_4 [expr abs(${CircleLength_4} - ${TheoryCircleLength_4}) / ${TheoryCircleLength_4} * 100]
puts "OCC945: Source shape is valid."
}
-if [catch {fixshape result a 29.9 } result] {
+if [catch {fixshape result a 29.9 } res] {
puts "Faulty OCC945: here is problem with FIXSHAPE function"
} else {
decho off
#################### select shape and check selection procedure ####################
proc Select {lab shape context} {
global D IsDone TestError
- upvar 1 $shape myshape $context mycontext
set res ""
if {[string compare $context ""] == 0} {
- if {[catch {set res [SelectShape D $lab myshape]}]} {
+ if {[catch {set res [SelectShape D $lab $shape]}]} {
set IsDone 0
- set TestError "$TestError # SelectShape bad result for args: $lab myshape"
+ set TestError "$TestError # SelectShape bad result for args: $lab shape"
}
} else {
- if {[catch {set res [SelectShape D $lab myshape mycontext]}]} {
+ if {[catch {set res [SelectShape D $lab $shape $context]}]} {
set IsDone 0
- set TestError "$TestError # SelectShape bad result for args: $lab myshape"
+ set TestError "$TestError # SelectShape bad result for args: $lab shape"
}
}
- return [CenterOfShape myshape]
+ return [CenterOfShape $shape]
}
if {[catch {set TestLab}] == 1} {
proc val2d { c u1 u2 n } {
dset du ($u2-$u1)/$n
- upvar $c cc
set i 1
for {dset u $u1} { [dval u] <= $u2} {dset u ($u1+$i*[dval du])} {
- 2dcvalue cc u x y dx dy d2x d2y ;
+ 2dcvalue $c u x y dx dy d2x d2y ;
global p_$i d1_$i d2_$i
point p_$i x y;
puts "u = [dval u]"
proc val3d { c u1 u2 n } {
dset du ($u2-$u1)/$n
- upvar $c cc
set i 1
for {dset u $u1} { [dval u] <= $u2} {dset u (u+[dval du])} {
- cvalue cc u x y z dx dy dz d2x d2y d2z ;
+ cvalue $c u x y z dx dy dz d2x d2y d2z ;
point p_$i x y z;
puts "u = [dval u]"
puts "p_$i [dval x ] [dval y ] [dval z]";
}
proc comparepnt2d {p1 p2 tol} {
- upvar $p1 pp1
- upvar $p2 pp2
- coord pp1 x1 y1
- coord pp2 x2 y2
+ coord $p1 x1 y1
+ coord $p2 x2 y2
compare [dval x1] [dval x2] $tol
compare [dval y1] [dval y2] $tol
}
# Check if area of triangles is valid
proc CheckTriArea {shape {eps 0}} {
- upvar #0 $shape a
- set area [triarea a $eps]
+ set area [triarea $shape $eps]
set t_area [lindex $area 0]
set g_area [expr abs([lindex $area 1])]
puts "area by triangles: $t_area"
puts "TODO ?OCC23748 ALL: Tcl Exception: ERROR. offsetperform operation not done."
puts "TODO ?OCC23748 ALL: Faulty shapes in variables faulty_1 to faulty_"
puts "TODO ?OCC23748 ALL: Error : The volume of the resulting shape is"
+puts "TODO ?OCC23748 ALL: Error : The area of face result_. of the resulting shape is negative"
puts "TODO ?OCC23748 ALL: TEST INCOMPLETE"
puts "TODO ?DEBUG_OCC24121 : Error : The area of face"
puts "TODO ?OCC24156 MacOS: Error : The area of face"
upvar $aD D
global FileSuffix ValidatorCheck
catch {[file delete ${aFile}]}
- SaveAs D $aFile
+ SaveAs $D $aFile
if { [file exists $aFile] } {
if { $FileSuffix == "xml" && $ValidatorCheck} {
ValidateXml $aFile