From e59839c8c2f9232c8e915572cdefc61610284f4d Mon Sep 17 00:00:00 2001 From: duv Date: Fri, 3 Feb 2017 12:13:43 +0300 Subject: [PATCH] 0028360: Draw Harness - access for DRAW TCL interpreter needed for custom applications Components of DRAW now use interpreter with static method Draw::GetInterpretor() instead of shared global variable --- src/Draw/Draw.cxx | 9 ++++++ src/Draw/Draw.hxx | 3 ++ src/Draw/Draw_Debug.cxx | 9 +++--- src/Draw/Draw_VariableCommands.cxx | 46 ++++++++++++++++-------------- src/Draw/Draw_Window.cxx | 28 +++++++++++------- 5 files changed, 58 insertions(+), 37 deletions(-) diff --git a/src/Draw/Draw.cxx b/src/Draw/Draw.cxx index 4baf75fe2d..e6292aeb27 100644 --- a/src/Draw/Draw.cxx +++ b/src/Draw/Draw.cxx @@ -115,6 +115,15 @@ static void ReadInitFile (const TCollection_AsciiString& theFileName) #endif } +//======================================================================= +//function : GetInterpretor +//purpose : +//======================================================================= +Draw_Interpretor& Draw::GetInterpretor() +{ + return theCommands; +} + //======================================================================= //function : //purpose : Set/Get Progress Indicator diff --git a/src/Draw/Draw.hxx b/src/Draw/Draw.hxx index cae4d6404a..e546d98902 100644 --- a/src/Draw/Draw.hxx +++ b/src/Draw/Draw.hxx @@ -70,6 +70,9 @@ public: //! Sets a numeric variable. Standard_EXPORT static void Set (const Standard_CString Name, const Standard_Real val); + + //! Returns main DRAW interpretor. + Standard_EXPORT static Draw_Interpretor& GetInterpretor(); //! Returns a variable value. Null if the variable //! does not exist, a warning is printed if Complain diff --git a/src/Draw/Draw_Debug.cxx b/src/Draw/Draw_Debug.cxx index 2eb08cb5f1..4b60fc5e52 100644 --- a/src/Draw/Draw_Debug.cxx +++ b/src/Draw/Draw_Debug.cxx @@ -18,8 +18,6 @@ #include #include -extern Draw_Interpretor theCommands; - // This file defines global functions not declared in any public header, // intended for use from debugger prompt (Command Window in Visual Studio) @@ -32,9 +30,10 @@ Standard_EXPORT const char* Draw_Eval (const char *theCommandStr) } try { OCC_CATCH_SIGNALS - theCommands.Eval (theCommandStr); - cout << theCommands.Result() << endl; - return theCommands.Result(); + Draw_Interpretor& aCommands = Draw::GetInterpretor(); + aCommands.Eval (theCommandStr); + cout << aCommands.Result() << endl; + return aCommands.Result(); } catch (Standard_Failure const& anException) { diff --git a/src/Draw/Draw_VariableCommands.cxx b/src/Draw/Draw_VariableCommands.cxx index 2ae943706a..cfa2cedf33 100644 --- a/src/Draw/Draw_VariableCommands.cxx +++ b/src/Draw/Draw_VariableCommands.cxx @@ -46,8 +46,6 @@ Standard_Boolean Draw_ParseFailed; static Standard_Boolean autodisp = Standard_True; static Standard_Boolean repaint2d,repaint3d; -extern Draw_Interpretor theCommands; - //=============================================== // dictionnary of variables // Variables are stored in a map Integer, Transient @@ -737,15 +735,17 @@ static char* tracevar(ClientData CD, Tcl_Interp*,const char* name,const char*, i // protect if the map was destroyed before the interpretor if (theVariables.IsEmpty()) return NULL; + Draw_Interpretor& aCommands = Draw::GetInterpretor(); + // MSV 9.10.14 CR25344 Handle(Draw_Drawable3D) D(reinterpret_cast(CD)); if (D.IsNull()) { - Tcl_UntraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, + Tcl_UntraceVar(aCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, tracevar,CD); return NULL; } if (D->Protected()) { - D->Name(Tcl_SetVar(theCommands.Interp(),name,name,0)); + D->Name(Tcl_SetVar(aCommands.Interp(),name,name,0)); return (char*) "variable is protected"; } else { if (D->Visible()) { @@ -755,7 +755,7 @@ static char* tracevar(ClientData CD, Tcl_Interp*,const char* name,const char*, i else repaint2d = Standard_True; } - Tcl_UntraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, + Tcl_UntraceVar(aCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, tracevar,CD); theVariables.Remove(D); return NULL; @@ -770,6 +770,8 @@ void Draw::Set(const Standard_CString name, const Handle(Draw_Drawable3D)& D, const Standard_Boolean displ) { + Draw_Interpretor& aCommands = Draw::GetInterpretor(); + if ((name[0] == '.') && (name[1] == '\0')) { if (!D.IsNull()) { dout.RemoveDrawable(D); @@ -779,7 +781,7 @@ void Draw::Set(const Standard_CString name, else { // Check if the variable with the same name exists ClientData aCD = - Tcl_VarTraceInfo(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, + Tcl_VarTraceInfo(aCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, tracevar, NULL); Handle(Draw_Drawable3D) anOldD(reinterpret_cast(aCD)); if (!anOldD.IsNull()) { @@ -790,14 +792,14 @@ void Draw::Set(const Standard_CString name, anOldD.Nullify(); } - Tcl_UnsetVar(theCommands.Interp(),name,0); + Tcl_UnsetVar(aCommands.Interp(),name,0); if (!D.IsNull()) { theVariables.Add(D); - D->Name(Tcl_SetVar(theCommands.Interp(),name,name,0)); + D->Name(Tcl_SetVar(aCommands.Interp(),name,name,0)); // set the trace function - Tcl_TraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, + Tcl_TraceVar(aCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, tracevar,reinterpret_cast(D.operator->())); if (displ) { if (!D->Visible()) @@ -850,7 +852,7 @@ Handle(Draw_Drawable3D) Draw::Get(Standard_CString& name, } else { ClientData aCD = - Tcl_VarTraceInfo(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, + Tcl_VarTraceInfo(Draw::GetInterpretor().Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES, tracevar, NULL); D = reinterpret_cast(aCD); if (!theVariables.Contains(D)) @@ -1044,22 +1046,24 @@ static Standard_Real ParseValue(char*& name) *(p-1) = '\0'; c = *p; + Draw_Interpretor& aCommands = Draw::GetInterpretor(); + // call the function, save the current result char* sv = 0; - if (*theCommands.Result()) { - sv = new char [strlen(theCommands.Result())]; - strcpy(sv,theCommands.Result()); - theCommands.Reset(); + if (*aCommands.Result()) { + sv = new char [strlen(aCommands.Result())]; + strcpy(sv,aCommands.Result()); + aCommands.Reset(); } - if (theCommands.Eval(name) != 0) { + if (aCommands.Eval(name) != 0) { cout << "Call of function " << name << " failed" << endl; x = 0; } else - x = Atof(theCommands.Result()); - theCommands.Reset(); + x = Atof(aCommands.Result()); + aCommands.Reset(); if (sv) { - theCommands << sv; + aCommands << sv; delete [] sv; } } @@ -1124,8 +1128,8 @@ static Standard_Real Parse(char*& name) break; default : - name--; - return x; + name--; + return x; } } @@ -1162,7 +1166,7 @@ void Draw::Set(const Standard_CString Name, const Standard_CString val) pName=(Standard_PCharacter)Name; pVal=(Standard_PCharacter)val; // - Tcl_SetVar(theCommands.Interp(), pName, pVal, 0); + Tcl_SetVar(Draw::GetInterpretor().Interp(), pName, pVal, 0); } //======================================================================= // Command management diff --git a/src/Draw/Draw_Window.cxx b/src/Draw/Draw_Window.cxx index 7233f7f3c9..9c51b2be7f 100644 --- a/src/Draw/Draw_Window.cxx +++ b/src/Draw/Draw_Window.cxx @@ -30,7 +30,6 @@ #include #include -extern Draw_Interpretor theCommands; extern Standard_Boolean Draw_VirtualWindows; static Tcl_Interp *interp; /* Interpreter for this application. */ static NCollection_List MyCallbacks; @@ -1021,8 +1020,10 @@ void Run_Appli(Standard_Boolean (*interprete) (const char*)) #endif - if (tty) Prompt(theCommands.Interp(), 0); - Prompt(theCommands.Interp(), 0); + Draw_Interpretor& aCommands = Draw::GetInterpretor(); + + if (tty) Prompt(aCommands.Interp(), 0); + Prompt(aCommands.Interp(), 0); outChannel = Tcl_GetStdChannel(TCL_STDOUT); if (outChannel) { @@ -1040,7 +1041,7 @@ void Run_Appli(Standard_Boolean (*interprete) (const char*)) if (Draw_VirtualWindows) { // main window will never shown // but main loop will parse all Xlib messages - Tcl_Eval(theCommands.Interp(), "wm withdraw ."); + Tcl_Eval(aCommands.Interp(), "wm withdraw ."); } Tk_MainLoop(); @@ -1076,8 +1077,9 @@ void Run_Appli(Standard_Boolean (*interprete) (const char*)) //====================================================== Standard_Boolean Init_Appli() { - theCommands.Init(); - interp = theCommands.Interp(); + Draw_Interpretor& aCommands = Draw::GetInterpretor(); + aCommands.Init(); + interp = aCommands.Interp(); Tcl_Init(interp) ; try { @@ -1974,11 +1976,13 @@ bool volatile isTkLoopStarted = false; Standard_Boolean Init_Appli(HINSTANCE hInst, HINSTANCE hPrevInst, int nShow, HWND& hWndFrame ) { + Draw_Interpretor& aCommands = Draw::GetInterpretor(); + DWORD IDThread; HANDLE hThread; console_semaphore = STOP_CONSOLE; - theCommands.Init(); - interp = theCommands.Interp(); + aCommands.Init(); + interp = aCommands.Interp(); Tcl_Init(interp) ; dwMainThreadId = GetCurrentThreadId(); @@ -2112,6 +2116,8 @@ void exitProc(ClientData /*dc*/) \*--------------------------------------------------------*/ static DWORD WINAPI tkLoop(VOID) { + Draw_Interpretor& aCommands = Draw::GetInterpretor(); + Tcl_CreateExitHandler(exitProc, 0); #if (TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 5)) { @@ -2120,15 +2126,15 @@ static DWORD WINAPI tkLoop(VOID) Tcl_Channel aChannelErr = Tcl_GetStdChannel (TCL_STDERR); if (aChannelIn != NULL) { - Tcl_RegisterChannel (theCommands.Interp(), aChannelIn); + Tcl_RegisterChannel (aCommands.Interp(), aChannelIn); } if (aChannelOut != NULL) { - Tcl_RegisterChannel (theCommands.Interp(), aChannelOut); + Tcl_RegisterChannel (aCommands.Interp(), aChannelOut); } if (aChannelErr != NULL) { - Tcl_RegisterChannel (theCommands.Interp(), aChannelErr); + Tcl_RegisterChannel (aCommands.Interp(), aChannelErr); } } #endif -- 2.39.5