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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : GetInterpretor
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
|
Draw_Interpretor& Draw::GetInterpretor()
|
||||||
|
{
|
||||||
|
return theCommands;
|
||||||
|
}
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
//function :
|
//function :
|
||||||
//purpose : Set/Get Progress Indicator
|
//purpose : Set/Get Progress Indicator
|
||||||
|
@ -70,6 +70,9 @@ public:
|
|||||||
|
|
||||||
//! Sets a numeric variable.
|
//! Sets a numeric variable.
|
||||||
Standard_EXPORT static void Set (const Standard_CString Name, const Standard_Real val);
|
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
|
//! Returns a variable value. Null if the variable
|
||||||
//! does not exist, a warning is printed if Complain
|
//! does not exist, a warning is printed if Complain
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
#include <Standard_ErrorHandler.hxx>
|
#include <Standard_ErrorHandler.hxx>
|
||||||
#include <Standard_Failure.hxx>
|
#include <Standard_Failure.hxx>
|
||||||
|
|
||||||
extern Draw_Interpretor theCommands;
|
|
||||||
|
|
||||||
// This file defines global functions not declared in any public header,
|
// This file defines global functions not declared in any public header,
|
||||||
// intended for use from debugger prompt (Command Window in Visual Studio)
|
// 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 {
|
try {
|
||||||
OCC_CATCH_SIGNALS
|
OCC_CATCH_SIGNALS
|
||||||
theCommands.Eval (theCommandStr);
|
Draw_Interpretor& aCommands = Draw::GetInterpretor();
|
||||||
cout << theCommands.Result() << endl;
|
aCommands.Eval (theCommandStr);
|
||||||
return theCommands.Result();
|
cout << aCommands.Result() << endl;
|
||||||
|
return aCommands.Result();
|
||||||
}
|
}
|
||||||
catch (Standard_Failure const& anException)
|
catch (Standard_Failure const& anException)
|
||||||
{
|
{
|
||||||
|
@ -46,8 +46,6 @@ Standard_Boolean Draw_ParseFailed;
|
|||||||
static Standard_Boolean autodisp = Standard_True;
|
static Standard_Boolean autodisp = Standard_True;
|
||||||
static Standard_Boolean repaint2d,repaint3d;
|
static Standard_Boolean repaint2d,repaint3d;
|
||||||
|
|
||||||
extern Draw_Interpretor theCommands;
|
|
||||||
|
|
||||||
//===============================================
|
//===============================================
|
||||||
// dictionnary of variables
|
// dictionnary of variables
|
||||||
// Variables are stored in a map Integer, Transient
|
// 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
|
// protect if the map was destroyed before the interpretor
|
||||||
if (theVariables.IsEmpty()) return NULL;
|
if (theVariables.IsEmpty()) return NULL;
|
||||||
|
|
||||||
|
Draw_Interpretor& aCommands = Draw::GetInterpretor();
|
||||||
|
|
||||||
// MSV 9.10.14 CR25344
|
// MSV 9.10.14 CR25344
|
||||||
Handle(Draw_Drawable3D) D(reinterpret_cast<Draw_Drawable3D*>(CD));
|
Handle(Draw_Drawable3D) D(reinterpret_cast<Draw_Drawable3D*>(CD));
|
||||||
if (D.IsNull()) {
|
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);
|
tracevar,CD);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (D->Protected()) {
|
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";
|
return (char*) "variable is protected";
|
||||||
} else {
|
} else {
|
||||||
if (D->Visible()) {
|
if (D->Visible()) {
|
||||||
@ -755,7 +755,7 @@ static char* tracevar(ClientData CD, Tcl_Interp*,const char* name,const char*, i
|
|||||||
else
|
else
|
||||||
repaint2d = Standard_True;
|
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);
|
tracevar,CD);
|
||||||
theVariables.Remove(D);
|
theVariables.Remove(D);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -770,6 +770,8 @@ void Draw::Set(const Standard_CString name,
|
|||||||
const Handle(Draw_Drawable3D)& D,
|
const Handle(Draw_Drawable3D)& D,
|
||||||
const Standard_Boolean displ)
|
const Standard_Boolean displ)
|
||||||
{
|
{
|
||||||
|
Draw_Interpretor& aCommands = Draw::GetInterpretor();
|
||||||
|
|
||||||
if ((name[0] == '.') && (name[1] == '\0')) {
|
if ((name[0] == '.') && (name[1] == '\0')) {
|
||||||
if (!D.IsNull()) {
|
if (!D.IsNull()) {
|
||||||
dout.RemoveDrawable(D);
|
dout.RemoveDrawable(D);
|
||||||
@ -779,7 +781,7 @@ void Draw::Set(const Standard_CString name,
|
|||||||
else {
|
else {
|
||||||
// Check if the variable with the same name exists
|
// Check if the variable with the same name exists
|
||||||
ClientData aCD =
|
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);
|
tracevar, NULL);
|
||||||
Handle(Draw_Drawable3D) anOldD(reinterpret_cast<Draw_Drawable3D*>(aCD));
|
Handle(Draw_Drawable3D) anOldD(reinterpret_cast<Draw_Drawable3D*>(aCD));
|
||||||
if (!anOldD.IsNull()) {
|
if (!anOldD.IsNull()) {
|
||||||
@ -790,14 +792,14 @@ void Draw::Set(const Standard_CString name,
|
|||||||
anOldD.Nullify();
|
anOldD.Nullify();
|
||||||
}
|
}
|
||||||
|
|
||||||
Tcl_UnsetVar(theCommands.Interp(),name,0);
|
Tcl_UnsetVar(aCommands.Interp(),name,0);
|
||||||
|
|
||||||
if (!D.IsNull()) {
|
if (!D.IsNull()) {
|
||||||
theVariables.Add(D);
|
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
|
// 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->()));
|
tracevar,reinterpret_cast<ClientData>(D.operator->()));
|
||||||
if (displ) {
|
if (displ) {
|
||||||
if (!D->Visible())
|
if (!D->Visible())
|
||||||
@ -850,7 +852,7 @@ Handle(Draw_Drawable3D) Draw::Get(Standard_CString& name,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ClientData aCD =
|
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);
|
tracevar, NULL);
|
||||||
D = reinterpret_cast<Draw_Drawable3D*>(aCD);
|
D = reinterpret_cast<Draw_Drawable3D*>(aCD);
|
||||||
if (!theVariables.Contains(D))
|
if (!theVariables.Contains(D))
|
||||||
@ -1044,22 +1046,24 @@ static Standard_Real ParseValue(char*& name)
|
|||||||
*(p-1) = '\0';
|
*(p-1) = '\0';
|
||||||
c = *p;
|
c = *p;
|
||||||
|
|
||||||
|
Draw_Interpretor& aCommands = Draw::GetInterpretor();
|
||||||
|
|
||||||
// call the function, save the current result
|
// call the function, save the current result
|
||||||
char* sv = 0;
|
char* sv = 0;
|
||||||
if (*theCommands.Result()) {
|
if (*aCommands.Result()) {
|
||||||
sv = new char [strlen(theCommands.Result())];
|
sv = new char [strlen(aCommands.Result())];
|
||||||
strcpy(sv,theCommands.Result());
|
strcpy(sv,aCommands.Result());
|
||||||
theCommands.Reset();
|
aCommands.Reset();
|
||||||
}
|
}
|
||||||
if (theCommands.Eval(name) != 0) {
|
if (aCommands.Eval(name) != 0) {
|
||||||
cout << "Call of function " << name << " failed" << endl;
|
cout << "Call of function " << name << " failed" << endl;
|
||||||
x = 0;
|
x = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
x = Atof(theCommands.Result());
|
x = Atof(aCommands.Result());
|
||||||
theCommands.Reset();
|
aCommands.Reset();
|
||||||
if (sv) {
|
if (sv) {
|
||||||
theCommands << sv;
|
aCommands << sv;
|
||||||
delete [] sv;
|
delete [] sv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1124,8 +1128,8 @@ static Standard_Real Parse(char*& name)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default :
|
default :
|
||||||
name--;
|
name--;
|
||||||
return x;
|
return x;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1162,7 +1166,7 @@ void Draw::Set(const Standard_CString Name, const Standard_CString val)
|
|||||||
pName=(Standard_PCharacter)Name;
|
pName=(Standard_PCharacter)Name;
|
||||||
pVal=(Standard_PCharacter)val;
|
pVal=(Standard_PCharacter)val;
|
||||||
//
|
//
|
||||||
Tcl_SetVar(theCommands.Interp(), pName, pVal, 0);
|
Tcl_SetVar(Draw::GetInterpretor().Interp(), pName, pVal, 0);
|
||||||
}
|
}
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
// Command management
|
// Command management
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
#include <Image_AlienPixMap.hxx>
|
#include <Image_AlienPixMap.hxx>
|
||||||
#include <NCollection_List.hxx>
|
#include <NCollection_List.hxx>
|
||||||
|
|
||||||
extern Draw_Interpretor theCommands;
|
|
||||||
extern Standard_Boolean Draw_VirtualWindows;
|
extern Standard_Boolean Draw_VirtualWindows;
|
||||||
static Tcl_Interp *interp; /* Interpreter for this application. */
|
static Tcl_Interp *interp; /* Interpreter for this application. */
|
||||||
static NCollection_List<Draw_Window::FCallbackBeforeTerminate> MyCallbacks;
|
static NCollection_List<Draw_Window::FCallbackBeforeTerminate> MyCallbacks;
|
||||||
@ -1021,8 +1020,10 @@ void Run_Appli(Standard_Boolean (*interprete) (const char*))
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (tty) Prompt(theCommands.Interp(), 0);
|
Draw_Interpretor& aCommands = Draw::GetInterpretor();
|
||||||
Prompt(theCommands.Interp(), 0);
|
|
||||||
|
if (tty) Prompt(aCommands.Interp(), 0);
|
||||||
|
Prompt(aCommands.Interp(), 0);
|
||||||
|
|
||||||
outChannel = Tcl_GetStdChannel(TCL_STDOUT);
|
outChannel = Tcl_GetStdChannel(TCL_STDOUT);
|
||||||
if (outChannel) {
|
if (outChannel) {
|
||||||
@ -1040,7 +1041,7 @@ void Run_Appli(Standard_Boolean (*interprete) (const char*))
|
|||||||
if (Draw_VirtualWindows) {
|
if (Draw_VirtualWindows) {
|
||||||
// main window will never shown
|
// main window will never shown
|
||||||
// but main loop will parse all Xlib messages
|
// but main loop will parse all Xlib messages
|
||||||
Tcl_Eval(theCommands.Interp(), "wm withdraw .");
|
Tcl_Eval(aCommands.Interp(), "wm withdraw .");
|
||||||
}
|
}
|
||||||
Tk_MainLoop();
|
Tk_MainLoop();
|
||||||
|
|
||||||
@ -1076,8 +1077,9 @@ void Run_Appli(Standard_Boolean (*interprete) (const char*))
|
|||||||
//======================================================
|
//======================================================
|
||||||
Standard_Boolean Init_Appli()
|
Standard_Boolean Init_Appli()
|
||||||
{
|
{
|
||||||
theCommands.Init();
|
Draw_Interpretor& aCommands = Draw::GetInterpretor();
|
||||||
interp = theCommands.Interp();
|
aCommands.Init();
|
||||||
|
interp = aCommands.Interp();
|
||||||
|
|
||||||
Tcl_Init(interp) ;
|
Tcl_Init(interp) ;
|
||||||
try {
|
try {
|
||||||
@ -1974,11 +1976,13 @@ bool volatile isTkLoopStarted = false;
|
|||||||
Standard_Boolean Init_Appli(HINSTANCE hInst,
|
Standard_Boolean Init_Appli(HINSTANCE hInst,
|
||||||
HINSTANCE hPrevInst, int nShow, HWND& hWndFrame )
|
HINSTANCE hPrevInst, int nShow, HWND& hWndFrame )
|
||||||
{
|
{
|
||||||
|
Draw_Interpretor& aCommands = Draw::GetInterpretor();
|
||||||
|
|
||||||
DWORD IDThread;
|
DWORD IDThread;
|
||||||
HANDLE hThread;
|
HANDLE hThread;
|
||||||
console_semaphore = STOP_CONSOLE;
|
console_semaphore = STOP_CONSOLE;
|
||||||
theCommands.Init();
|
aCommands.Init();
|
||||||
interp = theCommands.Interp();
|
interp = aCommands.Interp();
|
||||||
Tcl_Init(interp) ;
|
Tcl_Init(interp) ;
|
||||||
|
|
||||||
dwMainThreadId = GetCurrentThreadId();
|
dwMainThreadId = GetCurrentThreadId();
|
||||||
@ -2112,6 +2116,8 @@ void exitProc(ClientData /*dc*/)
|
|||||||
\*--------------------------------------------------------*/
|
\*--------------------------------------------------------*/
|
||||||
static DWORD WINAPI tkLoop(VOID)
|
static DWORD WINAPI tkLoop(VOID)
|
||||||
{
|
{
|
||||||
|
Draw_Interpretor& aCommands = Draw::GetInterpretor();
|
||||||
|
|
||||||
Tcl_CreateExitHandler(exitProc, 0);
|
Tcl_CreateExitHandler(exitProc, 0);
|
||||||
#if (TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 5))
|
#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);
|
Tcl_Channel aChannelErr = Tcl_GetStdChannel (TCL_STDERR);
|
||||||
if (aChannelIn != NULL)
|
if (aChannelIn != NULL)
|
||||||
{
|
{
|
||||||
Tcl_RegisterChannel (theCommands.Interp(), aChannelIn);
|
Tcl_RegisterChannel (aCommands.Interp(), aChannelIn);
|
||||||
}
|
}
|
||||||
if (aChannelOut != NULL)
|
if (aChannelOut != NULL)
|
||||||
{
|
{
|
||||||
Tcl_RegisterChannel (theCommands.Interp(), aChannelOut);
|
Tcl_RegisterChannel (aCommands.Interp(), aChannelOut);
|
||||||
}
|
}
|
||||||
if (aChannelErr != NULL)
|
if (aChannelErr != NULL)
|
||||||
{
|
{
|
||||||
Tcl_RegisterChannel (theCommands.Interp(), aChannelErr);
|
Tcl_RegisterChannel (aCommands.Interp(), aChannelErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user