1 // Created on: 2003-08-11
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2003-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
18 #include <DrawTrSurf.hxx>
19 #include <Message.hxx>
20 #include <Message_PrinterOStream.hxx>
21 #include <Message_PrinterSystemLog.hxx>
22 #include <NCollection_IndexedMap.hxx>
23 #include <Standard_ErrorHandler.hxx>
25 #ifdef OCCT_NO_PLUGINS
26 #include <BOPTest.hxx>
27 #include <DPrsStd.hxx>
28 #if defined(HAVE_OPENGL) || defined(HAVE_GLES2)
29 #include <OpenGlTest.hxx>
31 #include <TObjDRAW.hxx>
32 #include <ViewerTest.hxx>
33 #include <XSDRAWSTLVRML.hxx>
34 #include <XDEDRAW.hxx>
37 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
39 #if defined(__EMSCRIPTEN__)
40 #include <emscripten/bind.h>
41 #include <emscripten/emscripten.h>
43 //! Draw Harness interface for JavaScript.
47 //! Evaluate Tcl command.
48 static int eval (const std::string& theCommand)
54 //aRes = Draw::GetInterpretor().Eval (theCommand.c_str());
55 aRes = Draw_Interprete (theCommand.c_str()) ? 1 : 0;
57 catch (Standard_Failure& anExcept)
59 std::cout << "Failed to evaluate command: " << anExcept.GetMessageString() << std::endl;
64 //! Check if Tcl command is complete.
65 static bool isComplete (const std::string& theCommand)
67 return Draw::GetInterpretor().Complete (theCommand.c_str());
71 //! Print message to Module.printMessage callback.
72 EM_JS(void, occJSPrintMessage, (const char* theStr, int theGravity), {
73 if (Module.printMessage != undefined && Module.printMessage != null) {
74 Module.printMessage (UTF8ToString(theStr), theGravity);
75 } else if (Module.print != undefined && Module.print != null) {
76 Module.print (UTF8ToString(theStr));
78 //console.info (UTF8ToString(theStr));
82 //! Auxiliary printer to a Module.printMessage callback accepting text and gravity.
83 class DRAWEXE_WasmModulePrinter : public Message_Printer
85 DEFINE_STANDARD_RTTI_INLINE(DRAWEXE_WasmModulePrinter, Message_Printer)
89 DRAWEXE_WasmModulePrinter (const Message_Gravity theTraceLevel = Message_Info)
91 SetTraceLevel (theTraceLevel);
95 virtual ~DRAWEXE_WasmModulePrinter() {}
100 virtual void send (const TCollection_AsciiString& theString,
101 const Message_Gravity theGravity) const Standard_OVERRIDE
103 if (theGravity >= myTraceLevel)
105 occJSPrintMessage (theString.ToCString(), (int )theGravity);
110 EMSCRIPTEN_BINDINGS(DRAWEXE) {
111 emscripten::function("eval", &DRAWEXE::eval);
112 emscripten::function("isComplete", &DRAWEXE::isComplete);
116 #ifdef OCCT_NO_PLUGINS
117 //! Mimic pload command by loading pre-defined set of statically linked plugins.
118 static Standard_Integer Pload (Draw_Interpretor& theDI,
119 Standard_Integer theNbArgs,
120 const char** theArgVec)
122 NCollection_IndexedMap<TCollection_AsciiString, TCollection_AsciiString> aPlugins;
123 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
125 TCollection_AsciiString anArg (theArgVec[anArgIter]);
127 if (anArg == "DEFAULT")
129 aPlugins.Add ("TOPTEST");
131 else if (anArg == "MODELING")
133 aPlugins.Add ("TOPTEST");
135 else if (anArg == "VISUALIZATION")
137 aPlugins.Add ("AISV");
139 else if (anArg == "OCAFKERNEL")
141 aPlugins.Add ("DCAF");
143 else if (anArg == "DATAEXCHANGEKERNEL")
145 aPlugins.Add ("XSDRAW");
147 else if (anArg == "OCAF")
149 aPlugins.Add ("AISV");
150 aPlugins.Add ("DCAF");
152 else if (anArg == "DATAEXCHANGE")
154 aPlugins.Add ("XSDRAW");
155 aPlugins.Add ("XDEDRAW");
156 aPlugins.Add ("AISV");
158 else if (anArg == "XDE")
160 aPlugins.Add ("XSDRAW");
161 aPlugins.Add ("XDEDRAW");
163 else if (anArg == "ALL")
165 aPlugins.Add ("TOPTEST");
166 aPlugins.Add ("DCAF");
167 aPlugins.Add ("XSDRAW");
168 aPlugins.Add ("XDEDRAW");
169 aPlugins.Add ("AISV");
173 aPlugins.Add (anArg);
177 for (NCollection_IndexedMap<TCollection_AsciiString, TCollection_AsciiString>::Iterator aPluginIter (aPlugins);
178 aPluginIter.More(); aPluginIter.Next())
180 const TCollection_AsciiString& aPlugin = aPluginIter.Value();
181 if (aPlugin == "TOPTEST")
183 BOPTest::Factory (theDI);
185 else if (aPlugin == "DCAF")
187 DPrsStd::Factory (theDI);
189 else if (aPlugin == "AISV")
191 ViewerTest::Factory (theDI);
193 #if defined(HAVE_OPENGL)
194 else if (aPlugin == "GL"
195 || aPlugin == "OPENGL")
197 OpenGlTest::Factory (theDI);
200 #if defined(HAVE_GLES2)
201 else if (aPlugin == "GLES"
202 || aPlugin == "OPENGLES")
204 OpenGlTest::Factory (theDI);
207 else if (aPlugin == "XSDRAW")
209 XSDRAWSTLVRML::Factory (theDI);
211 else if (aPlugin == "XDEDRAW")
213 XDEDRAW::Factory (theDI);
215 //else if (aPlugin == "TOBJ") { TObjDRAW::Factory (theDI); }
216 //else if (aPlugin == "QACOMMANDS") { QADraw::Factory (theDI); }
219 theDI << "Error: unknown plugin '" << aPlugin << "'";
228 //=======================================================================
229 //function : Draw_InitAppli
231 //=======================================================================
233 void Draw_InitAppli (Draw_Interpretor& theDI)
235 #if defined(__EMSCRIPTEN__)
236 // open JavaScript console within the Browser to see this output
237 Message_Gravity aGravity = Message_Info;
238 Handle(Message_PrinterSystemLog) aJSConsolePrinter = new Message_PrinterSystemLog ("DRAWEXE", aGravity);
239 Message::DefaultMessenger()->AddPrinter (aJSConsolePrinter);
240 // replace printer into std::cout by a printer into a custom callback Module.printMessage accepting message gravity
241 Message::DefaultMessenger()->RemovePrinters (STANDARD_TYPE(Message_PrinterOStream));
242 Handle(DRAWEXE_WasmModulePrinter) aJSModulePrinter = new DRAWEXE_WasmModulePrinter (aGravity);
243 Message::DefaultMessenger()->AddPrinter (aJSModulePrinter);
246 Draw::Commands (theDI);
247 DBRep::BasicCommands (theDI);
248 DrawTrSurf::BasicCommands (theDI);
250 #ifdef OCCT_NO_PLUGINS
251 theDI.Add ("pload" , "pload [[Key1] [Key2] ...]: Loads Draw plugins",
252 __FILE__, Pload, "Draw Plugin");
256 #include <Draw_Main.hxx>