From 191082ac712e8c73a00be98e6b64730838ce1305 Mon Sep 17 00:00:00 2001 From: msv Date: Thu, 23 Oct 2014 14:30:28 +0400 Subject: [PATCH] 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 '$'. --- src/Draw/Draw_VariableCommands.cxx | 69 +++++++++++++++----------- src/DrawResources/StandardCommands.tcl | 8 +-- tests/bugs/demo/bug25344_1 | 22 ++++++++ tests/bugs/demo/bug25344_2 | 27 ++++++++++ tests/bugs/demo/bug25344_3 | 32 ++++++++++++ tests/bugs/demo/bug25344_4 | 28 +++++++++++ tests/bugs/fclasses/bug24863_2 | 5 +- tests/bugs/fclasses/bug24863_3 | 5 +- tests/caf/nam/A5 | 11 ++-- tests/geometry/begin | 12 +++-- tests/mesh/end | 3 +- tests/offset/end | 2 +- tests/xml/begin | 2 +- 13 files changed, 177 insertions(+), 49 deletions(-) create mode 100644 tests/bugs/demo/bug25344_1 create mode 100644 tests/bugs/demo/bug25344_2 create mode 100644 tests/bugs/demo/bug25344_3 create mode 100644 tests/bugs/demo/bug25344_4 diff --git a/src/Draw/Draw_VariableCommands.cxx b/src/Draw/Draw_VariableCommands.cxx index be7f061d01..2f93b05cc3 100644 --- a/src/Draw/Draw_VariableCommands.cxx +++ b/src/Draw/Draw_VariableCommands.cxx @@ -29,7 +29,7 @@ #include #include -#include +#include #include @@ -55,7 +55,7 @@ extern Draw_Interpretor theCommands; // The Integer Value is the content of the TCl variable //=============================================== -static NCollection_DataMap theVariables; +static NCollection_Map theVariables; //======================================================================= //function : FindVariable @@ -305,9 +305,9 @@ static Standard_Integer erase(Draw_Interpretor& di, Standard_Integer n, const ch // sauvegarde des proteges visibles Draw_SequenceOfDrawable3D prot; - NCollection_DataMap::Iterator aMapIt (theVariables); + NCollection_Map::Iterator aMapIt (theVariables); for (; aMapIt.More(); aMapIt.Next()) { - const Handle(Draw_Drawable3D)& D = aMapIt.Value(); + const Handle(Draw_Drawable3D)& D = aMapIt.Key(); if (!D.IsNull()) { if (D->Protected() && D->Visible()) prot.Append(D); @@ -719,30 +719,32 @@ void Draw::Set(const Standard_CString name, } // 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 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(CD)); if (D.IsNull()) { - theVariables.UnBind(name); + Tcl_UntraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, + tracevar,CD); return NULL; } if (D->Protected()) { D->Name(Tcl_SetVar(theCommands.Interp(),name,name,0)); return (char*) "variable is protected"; } else { - Tcl_UntraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,tracevar,NULL); if (D->Visible()) { dout.RemoveDrawable(D); if (D->Is3D()) - repaint3d = Standard_True; + repaint3d = Standard_True; else - repaint2d = Standard_True; + repaint2d = Standard_True; } - D.Nullify(); - theVariables.UnBind(name); + Tcl_UntraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, + tracevar,CD); + theVariables.Remove(D); return NULL; } } @@ -752,8 +754,8 @@ static char* tracevar(ClientData, Tcl_Interp*,const char* name,const char*, Stan //purpose : //======================================================================= void Draw::Set(const Standard_CString name, - const Handle(Draw_Drawable3D)& D, - const Standard_Boolean displ) + const Handle(Draw_Drawable3D)& D, + const Standard_Boolean displ) { if ((name[0] == '.') && (name[1] == '\0')) { if (!D.IsNull()) { @@ -762,27 +764,34 @@ void Draw::Set(const Standard_CString name, } } else { - if (theVariables.IsBound(name)) { - if (theVariables(name)->Protected()) { + // Check if the variable with the same name exists + ClientData aCD = + Tcl_VarTraceInfo(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, + tracevar, NULL); + Handle(Draw_Drawable3D) anOldD(reinterpret_cast(aCD)); + if (!anOldD.IsNull()) { + if (theVariables.Contains(anOldD) && anOldD->Protected()) { cout << "variable is protected" << endl; return; } + anOldD.Nullify(); } + + Tcl_UnsetVar(theCommands.Interp(),name,0); + if (!D.IsNull()) { - Tcl_UnsetVar(theCommands.Interp(),name,0); - theVariables.Bind(name,D); - // MKV 29.03.05 + theVariables.Add(D); D->Name(Tcl_SetVar(theCommands.Interp(),name,name,0)); + // 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(D.operator->())); if (displ) { - if (!D->Visible()) - dout << D; + if (!D->Visible()) + dout << D; } else if (D->Visible()) - dout.RemoveDrawable(D); - } else { - Tcl_UnsetVar(theCommands.Interp(),name,0); + dout.RemoveDrawable(D); } } } @@ -827,8 +836,12 @@ Handle(Draw_Drawable3D) Draw::Get(Standard_CString& name, } } else { - // MKV 29.03.05 - theVariables.Find(name,D); + ClientData aCD = + Tcl_VarTraceInfo(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, + tracevar, NULL); + D = reinterpret_cast(aCD); + if (!theVariables.Contains(D)) + D.Nullify(); #if 0 if (D.IsNull() && complain) cout <