0024863: CLang warnings -Wint-to-void-pointer-cast
[occt.git] / src / Draw / Draw_VariableCommands.cxx
index 2ab2e82..e94de8f 100644 (file)
 #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
@@ -60,7 +61,7 @@ extern Draw_Interpretor theCommands;
 // 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
@@ -310,8 +311,9 @@ static Standard_Integer erase(Draw_Interpretor& di, Standard_Integer n, const ch
     
     // 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);
@@ -723,27 +725,21 @@ void Draw::Set(const Standard_CString name,
 }
 
 // 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()) 
@@ -752,6 +748,7 @@ static char* tracevar(ClientData CD, Tcl_Interp*, char*, char*, Standard_Integer
        repaint2d = Standard_True;
     }
     D.Nullify();
+    theVariables.UnBind(name);
     return NULL;
   }
 }
@@ -771,28 +768,27 @@ void Draw::Set(const Standard_CString name,
     }
   }
   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);
     }
   }
 }
@@ -823,11 +819,6 @@ void Draw::Set(const Standard_CString Name, const Standard_Real val)
 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) {
@@ -843,21 +834,7 @@ Handle(Draw_Drawable3D) Draw::Get(Standard_CString& name,
   }
   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;