mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-04 13:13:25 +03:00
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
This commit is contained in:
parent
c13de40280
commit
e59839c8c2
@ -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
|
||||
|
@ -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
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include <Standard_ErrorHandler.hxx>
|
||||
#include <Standard_Failure.hxx>
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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<Draw_Drawable3D*>(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<Draw_Drawable3D*>(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<ClientData>(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<Draw_Drawable3D*>(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
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include <Image_AlienPixMap.hxx>
|
||||
#include <NCollection_List.hxx>
|
||||
|
||||
extern Draw_Interpretor theCommands;
|
||||
extern Standard_Boolean Draw_VirtualWindows;
|
||||
static Tcl_Interp *interp; /* Interpreter for this application. */
|
||||
static NCollection_List<Draw_Window::FCallbackBeforeTerminate> 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user