Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1993-08-13 |
2 | // Created by: Bruno DUMORTIER | |
3 | // Copyright (c) 1993-1999 Matra Datavision | |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
5 | // | |
6 | // The content of this file is subject to the Open CASCADE Technology Public | |
7 | // License Version 6.5 (the "License"). You may not use the content of this file | |
8 | // except in compliance with the License. Please obtain a copy of the License | |
9 | // at http://www.opencascade.org and read it completely before using this file. | |
10 | // | |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
13 | // | |
14 | // The Original Code and all software distributed under the License is | |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
16 | // Initial Developer hereby disclaims all such warranties, including without | |
17 | // limitation, any warranties of merchantability, fitness for a particular | |
18 | // purpose or non-infringement. Please see the License for the specific terms | |
19 | // and conditions governing the rights and limitations under the License. | |
20 | ||
7fd59977 | 21 | |
22 | #ifdef HAVE_CONFIG_H | |
23 | # include <config.h> | |
24 | #endif | |
25 | ||
26 | #include <Draw.ixx> | |
27 | ||
28 | #if defined(HAVE_TIME_H) || defined(WNT) | |
29 | # include <time.h> | |
30 | #endif | |
31 | ||
32 | #include <Draw_Appli.hxx> | |
33 | #include <OSD.hxx> | |
dac04bfa | 34 | #include <OSD_Environment.hxx> |
7fd59977 | 35 | #include <OSD_Timer.hxx> |
36 | ||
37 | #ifdef HAVE_SYS_TIME_H | |
38 | # include <sys/time.h> | |
39 | #endif | |
40 | ||
41 | #ifdef HAVE_SYS_TYPES_H | |
42 | # include <sys/types.h> | |
43 | #endif | |
44 | ||
45 | #ifdef HAVE_UNISTD_H | |
46 | # include <unistd.h> | |
47 | #endif | |
48 | ||
49 | #ifdef HAVE_STRINGS_H | |
50 | # include <strings.h> | |
51 | #endif | |
52 | ||
53 | ||
54 | #include <Draw_Window.hxx> | |
55 | #include <gp_Pnt2d.hxx> | |
56 | ||
57 | #include <Standard_Stream.hxx> | |
bf03eb83 | 58 | #include <Standard_Version.hxx> |
7fd59977 | 59 | |
60 | #include <Draw_Drawable3D.hxx> | |
61 | #include <Draw_Interpretor.hxx> | |
62 | #include <Draw_ProgressIndicator.hxx> | |
7fd59977 | 63 | |
64 | #include <Draw_MapOfFunctions.hxx> | |
65 | #include <OSD_SharedLibrary.hxx> | |
66 | #include <Resource_Manager.hxx> | |
67 | #include <Draw_Failure.hxx> | |
68 | #include <TCollection_AsciiString.hxx> | |
69 | #include <Standard_ErrorHandler.hxx> | |
6a0964c2 | 70 | |
71 | #include <tcl.h> | |
72 | ||
73 | // on MSVC, use #pragma to define name of the Tcl library to link with, | |
74 | // depending on Tcl version number | |
75 | #ifdef _MSC_VER | |
76 | // two helper macros are needed to convert version number macro to string literal | |
77 | #define STRINGIZE1(a) #a | |
78 | #define STRINGIZE2(a) STRINGIZE1(a) | |
79 | #pragma comment (lib, "tcl" STRINGIZE2(TCL_MAJOR_VERSION) STRINGIZE2(TCL_MINOR_VERSION) ".lib") | |
80 | #pragma comment (lib, "tk" STRINGIZE2(TCL_MAJOR_VERSION) STRINGIZE2(TCL_MINOR_VERSION) ".lib") | |
81 | #undef STRINGIZE2 | |
82 | #undef STRINGIZE1 | |
83 | #endif | |
84 | ||
7fd59977 | 85 | extern Standard_Boolean Draw_ParseFailed; |
7fd59977 | 86 | |
87 | Standard_EXPORT Draw_Viewer dout; | |
88 | Standard_EXPORT Draw_Interpretor theCommands; | |
89 | Standard_EXPORT Standard_Boolean Draw_Batch; | |
90 | Standard_EXPORT Standard_Boolean Draw_Spying = Standard_False; | |
91 | Standard_EXPORT Standard_Boolean Draw_Chrono = Standard_False; | |
92 | Standard_EXPORT Standard_Boolean Draw_VirtualWindows = Standard_False; | |
93 | Standard_EXPORT Standard_Boolean ErrorMessages = Standard_True; | |
94 | ||
95 | static const char* ColorNames[MAXCOLOR] = { | |
96 | "White","Red","Green","Blue","Cyan","Gold","Magenta", | |
97 | "Maroon","Orange","Pink","Salmon","Violet","Yellow","Khaki","Coral" | |
98 | }; | |
99 | ||
100 | filebuf Draw_Spyfile; | |
101 | ||
102 | static ostream spystream(&Draw_Spyfile); | |
103 | ||
104 | static Standard_Boolean XLoop; | |
105 | ||
106 | static Handle(Draw_ProgressIndicator) PInd = NULL; | |
107 | ||
bf03eb83 | 108 | Standard_EXPORT Standard_Boolean Draw_Interprete(const char* command); |
7fd59977 | 109 | // true if complete command |
110 | ||
7fd59977 | 111 | // ******************************************************************* |
112 | // read an init file | |
113 | // ******************************************************************* | |
114 | #ifdef WNT | |
115 | extern console_semaphore_value volatile console_semaphore; | |
116 | extern char console_command[1000]; | |
117 | #endif | |
118 | ||
86be4295 | 119 | static void ReadInitFile (const TCollection_AsciiString& theFileName) |
7fd59977 | 120 | { |
86be4295 | 121 | TCollection_AsciiString aPath = theFileName; |
7fd59977 | 122 | #ifdef WNT |
123 | if (!Draw_Batch) { | |
124 | try { | |
86be4295 A |
125 | aPath.ChangeAll ('\\', '/'); |
126 | ||
91322f44 | 127 | Sprintf(console_command, "source \"%.980s\"", aPath.ToCString()); |
7fd59977 | 128 | console_semaphore = HAS_CONSOLE_COMMAND; |
129 | while (console_semaphore == HAS_CONSOLE_COMMAND) | |
130 | Sleep(10); | |
131 | } | |
132 | catch(...) { | |
133 | cout << "Error while reading a script file." << endl; | |
134 | ExitProcess(0); | |
135 | } | |
136 | } else { | |
137 | #endif | |
86be4295 | 138 | char* com = new char [aPath.Length() + strlen ("source ") + 2]; |
91322f44 | 139 | Sprintf (com, "source %s", aPath.ToCString()); |
86be4295 | 140 | Draw_Interprete (com); |
7fd59977 | 141 | delete [] com; |
142 | #ifdef WNT | |
143 | } | |
144 | #endif | |
145 | } | |
7fd59977 | 146 | |
147 | //======================================================================= | |
148 | //function : | |
149 | //purpose : Set/Get Progress Indicator | |
150 | //======================================================================= | |
151 | void Draw::SetProgressBar(const Handle(Draw_ProgressIndicator)& thePI) | |
152 | { | |
153 | PInd = thePI; | |
154 | } | |
155 | ||
156 | Handle(Draw_ProgressIndicator) Draw::GetProgressBar() | |
157 | { | |
158 | return PInd; | |
159 | } | |
160 | ||
161 | #ifndef WNT | |
162 | /*--------------------------------------------------------*\ | |
163 | | exitProc: finalization handler for Tcl/Tk thread. Forces parent process to die | |
164 | \*--------------------------------------------------------*/ | |
165 | void exitProc(ClientData /*dc*/) | |
166 | { | |
167 | if (!Draw_Batch) { | |
168 | for (Standard_Integer id = 0; id < MAXVIEW; id++) | |
169 | dout.DeleteView(id); | |
170 | } | |
171 | } | |
172 | #endif | |
173 | ||
174 | // ******************************************************************* | |
175 | // main | |
176 | // ******************************************************************* | |
dac04bfa | 177 | #ifdef _WIN32 |
7fd59977 | 178 | //Standard_EXPORT void Draw_Appli(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lps |
179 | Standard_EXPORT void Draw_Appli(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszLine, int nShow,const FDraw_InitAppli Draw_InitAppli) | |
180 | #else | |
181 | void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_InitAppli) | |
182 | #endif | |
183 | { | |
dac04bfa | 184 | |
185 | // prepend extra DLL search path to override system libraries like opengl32.dll | |
186 | #ifdef _WIN32 | |
187 | OSD_Environment aUserDllEnv ("CSF_UserDllPath"); | |
188 | TCollection_AsciiString aUserDllPath = aUserDllEnv.Value(); | |
189 | if (!aUserDllPath.IsEmpty()) | |
190 | { | |
191 | // This function available since Win XP SP1 #if (_WIN32_WINNT >= 0x0502). | |
192 | // We retrieve dynamically here (kernel32 should be always preloaded). | |
193 | typedef BOOL (WINAPI *SetDllDirectoryA_t)(const char* thePathName); | |
194 | HMODULE aKern32Module = GetModuleHandleA ("kernel32"); | |
195 | SetDllDirectoryA_t aFunc = (aKern32Module != NULL) | |
196 | ? (SetDllDirectoryA_t )GetProcAddress (aKern32Module, "SetDllDirectoryA") : NULL; | |
197 | if (aFunc != NULL) | |
198 | { | |
199 | aFunc (aUserDllPath.ToCString()); | |
200 | } | |
201 | else | |
202 | { | |
203 | //std::cerr << "SetDllDirectoryA() is not available on this system!\n"; | |
204 | } | |
205 | if (aKern32Module != NULL) | |
206 | { | |
207 | FreeLibrary (aKern32Module); | |
208 | } | |
209 | } | |
210 | #endif | |
211 | ||
7fd59977 | 212 | // ***************************************************************** |
213 | // analyze arguments | |
214 | // ***************************************************************** | |
215 | Draw_Batch = Standard_False; | |
bf03eb83 | 216 | TCollection_AsciiString aRunFile, aCommand; |
7fd59977 | 217 | Standard_Integer i; |
218 | Standard_Boolean isInteractiveForced = Standard_False; | |
bf03eb83 | 219 | |
dac04bfa | 220 | #ifdef _WIN32 |
bf03eb83 | 221 | // On NT command line arguments are in the lpzline and not in argv |
222 | int argc = 0; | |
223 | const int MAXARGS = 1024; | |
224 | const char* argv[MAXARGS]; | |
225 | for (const char* p = strtok(lpszLine, " \t"); p != NULL; p = strtok(NULL, " \t")) { | |
226 | argv[argc++] = p; | |
227 | } | |
228 | #endif | |
229 | ||
230 | // parse command line | |
231 | for (i = 1; i < argc; i++) { | |
232 | if (strcasecmp (argv[i], "-h") == 0 || strcasecmp (argv[i], "--help") == 0) | |
233 | { | |
234 | cout << "Open CASCADE " << OCC_VERSION_STRING_EXT << " DRAW Test Harness" << endl << endl; | |
235 | cout << "Options: " << endl; | |
236 | cout << " -b: batch mode (no GUI, no viewers)" << endl; | |
237 | cout << " -v: no GUI, use virtual (off-screen) windows for viewers" << endl; | |
238 | cout << " -i: interactive mode" << endl; | |
239 | cout << " -f file: execute script from file" << endl; | |
240 | cout << " -c command args...: execute command (with optional arguments)" << endl << endl; | |
241 | cout << "Options -b, -v, and -i are mutually exclusive." << endl; | |
242 | cout << "If -c or -f are given, -v is default; otherwise default is -i." << endl; | |
243 | cout << "Options -c and -f are alternatives and should be at the end " << endl; | |
244 | cout << "of the command line. " << endl; | |
245 | cout << "Option -c can accept set of commands separated by ';'." << endl; | |
246 | return; | |
7fd59977 | 247 | } |
bf03eb83 | 248 | else if (strcasecmp (argv[i], "-b") == 0) |
249 | Draw_Batch = Standard_True; | |
250 | else if (strcasecmp (argv[i], "-v") == 0) { | |
7fd59977 | 251 | // force virtual windows |
252 | Draw_VirtualWindows = Standard_True; | |
bf03eb83 | 253 | } else if (strcasecmp (argv[i], "-i") == 0) { |
7fd59977 | 254 | // force interactive |
255 | Draw_VirtualWindows = Standard_False; | |
256 | isInteractiveForced = Standard_True; | |
bf03eb83 | 257 | } else if (strcasecmp (argv[i], "-f") == 0) { // -f option should be LAST! |
7fd59977 | 258 | Draw_VirtualWindows = !isInteractiveForced; |
259 | if (++i < argc) { | |
86be4295 | 260 | aRunFile = TCollection_AsciiString (argv[i]); |
7fd59977 | 261 | } |
262 | break; | |
bf03eb83 | 263 | } else if (strcasecmp (argv[i], "-c") == 0) { // -c option should be LAST! |
7fd59977 | 264 | Draw_VirtualWindows = !isInteractiveForced; |
bf03eb83 | 265 | if (++i < argc) { |
266 | aCommand = TCollection_AsciiString (argv[i]); | |
267 | } | |
268 | while (++i < argc) { | |
269 | aCommand.AssignCat (" "); | |
270 | aCommand.AssignCat (argv[i]); | |
7fd59977 | 271 | } |
272 | break; | |
bf03eb83 | 273 | } else { |
274 | cout << "Error: unsupported option " << argv[i] << endl; | |
7fd59977 | 275 | } |
276 | } | |
bf03eb83 | 277 | |
7fd59977 | 278 | // ***************************************************************** |
279 | // set signals | |
280 | // ***************************************************************** | |
281 | OSD::SetSignal(); | |
282 | ||
bf03eb83 | 283 | #ifdef _WIN32 |
284 | // in interactive mode, force Windows to report dll loading problems interactively | |
285 | if ( ! Draw_VirtualWindows && ! Draw_Batch ) | |
286 | ::SetErrorMode (0); | |
287 | #endif | |
288 | ||
7fd59977 | 289 | // ***************************************************************** |
290 | // init X window and create display | |
291 | // ***************************************************************** | |
292 | #ifdef WNT | |
1d47d8d0 | 293 | HWND hWnd = NULL; |
7fd59977 | 294 | #endif |
295 | ||
296 | if (!Draw_Batch) | |
297 | #ifdef WNT | |
bf03eb83 | 298 | Draw_Batch=!Init_Appli(hInst, hPrevInst, nShow, hWnd); |
7fd59977 | 299 | #else |
300 | Draw_Batch=!Init_Appli(); | |
301 | #endif | |
302 | else | |
bf03eb83 | 303 | cout << "DRAW is running in batch mode" << endl; |
7fd59977 | 304 | |
305 | XLoop = !Draw_Batch; | |
306 | if (XLoop) { | |
307 | // Default colors | |
308 | for (i=0;i<MAXCOLOR;i++) { | |
309 | if (!dout.DefineColor(i,ColorNames[i])) | |
310 | cout <<"Could not allocate default color "<<ColorNames[i]<<endl; | |
311 | } | |
312 | } | |
313 | ||
314 | // ***************************************************************** | |
315 | // set maximum precision for cout | |
316 | // ***************************************************************** | |
317 | cout.precision(15); | |
318 | ||
319 | // ***************************************************************** | |
320 | // standard commands | |
321 | // ***************************************************************** | |
322 | Draw::BasicCommands(theCommands); | |
323 | Draw::VariableCommands(theCommands); | |
324 | Draw::UnitCommands(theCommands); | |
325 | if (!Draw_Batch) Draw::GraphicCommands(theCommands); | |
326 | ||
327 | // ***************************************************************** | |
328 | // user commands | |
329 | // ***************************************************************** | |
330 | Draw_InitAppli(theCommands); | |
331 | ||
332 | #ifndef WNT | |
333 | Tcl_CreateExitHandler(exitProc, 0); | |
334 | #endif | |
335 | ||
336 | // ***************************************************************** | |
337 | // read init files | |
338 | // ***************************************************************** | |
339 | // default | |
86be4295 A |
340 | |
341 | if (getenv ("DRAWDEFAULT") == NULL) | |
7fd59977 | 342 | { |
86be4295 | 343 | if (getenv ("CASROOT") == NULL) |
7fd59977 | 344 | { |
345 | #ifdef WNT | |
86be4295 | 346 | ReadInitFile ("ddefault"); |
7fd59977 | 347 | #else |
86be4295 A |
348 | cout << " the CASROOT variable is mandatory to Run OpenCascade "<< endl; |
349 | cout << "No default file" << endl; | |
7fd59977 | 350 | #endif |
351 | } | |
352 | else | |
353 | { | |
86be4295 A |
354 | TCollection_AsciiString aDefStr (getenv ("CASROOT")); |
355 | aDefStr += "/src/DrawResources/DrawDefault"; | |
356 | ReadInitFile (aDefStr); | |
7fd59977 | 357 | } |
358 | } | |
359 | else | |
360 | { | |
86be4295 | 361 | ReadInitFile (getenv ("DRAWDEFAULT")); |
7fd59977 | 362 | } |
363 | ||
bf03eb83 | 364 | // read commands from file |
86be4295 | 365 | if (!aRunFile.IsEmpty()) { |
bf03eb83 | 366 | ReadInitFile (aRunFile); |
367 | // provide a clean exit, this is useful for some analysis tools | |
368 | if ( ! isInteractiveForced ) | |
7fd59977 | 369 | #ifndef WNT |
bf03eb83 | 370 | return; |
371 | #else | |
372 | ExitProcess(0); | |
7fd59977 | 373 | #endif |
bf03eb83 | 374 | } |
7fd59977 | 375 | |
bf03eb83 | 376 | // execute command from command line |
377 | if (!aCommand.IsEmpty()) { | |
378 | Draw_Interprete (aCommand.ToCString()); | |
379 | // provide a clean exit, this is useful for some analysis tools | |
380 | if ( ! isInteractiveForced ) | |
7fd59977 | 381 | #ifndef WNT |
bf03eb83 | 382 | return; |
7fd59977 | 383 | #else |
bf03eb83 | 384 | ExitProcess(0); |
7fd59977 | 385 | #endif |
386 | } | |
387 | ||
388 | // ***************************************************************** | |
389 | // X loop | |
390 | // ***************************************************************** | |
391 | if (XLoop) { | |
392 | #ifdef WNT | |
bf03eb83 | 393 | Run_Appli(hWnd); |
7fd59977 | 394 | #else |
395 | Run_Appli(Draw_Interprete); | |
396 | #endif | |
397 | } | |
398 | else | |
399 | { | |
400 | char cmd[255]; | |
401 | do { | |
402 | cout << "Viewer>"; | |
403 | i = -1; | |
404 | do { | |
405 | cin.get(cmd[++i]); | |
406 | } while ((cmd[i] != '\n') && (!cin.fail())); | |
407 | cmd[i] = '\0'; | |
408 | } while (Draw_Interprete(cmd) != (unsigned int ) -2); | |
409 | } | |
410 | #ifdef WNT | |
411 | // Destruction de l'application | |
412 | Destroy_Appli(hInst); | |
413 | #endif | |
414 | } | |
415 | //#endif | |
416 | ||
417 | // User functions called before and after each command | |
418 | void (*Draw_BeforeCommand)() = NULL; | |
419 | void (*Draw_AfterCommand)(Standard_Integer) = NULL; | |
420 | ||
bf03eb83 | 421 | Standard_Boolean Draw_Interprete(const char* com) |
7fd59977 | 422 | { |
423 | ||
424 | static Standard_Boolean first = Standard_True; | |
425 | static Tcl_DString command; | |
426 | ||
427 | if (first) { | |
428 | first = Standard_False; | |
429 | Tcl_DStringInit(&command); | |
430 | } | |
431 | ||
432 | #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 1))) | |
433 | // OCC63: Since Tcl 8.1 it uses UTF-8 encoding for internal representation of strings | |
434 | Tcl_ExternalToUtfDString ( NULL, com, -1, &command ); | |
435 | #else | |
436 | Tcl_DStringAppend(&command,com,-1); | |
437 | #endif | |
438 | ||
439 | if (!theCommands.Complete(Tcl_DStringValue(&command))) | |
440 | return Standard_False; | |
441 | ||
442 | // ******************************************************************* | |
443 | // Command interpreter | |
444 | // ******************************************************************* | |
445 | ||
446 | // Standard_Integer i = 0; | |
447 | // Standard_Integer j = 0; | |
448 | ||
449 | Standard_Boolean wasspying = Draw_Spying; | |
450 | ||
451 | OSD_Timer tictac; | |
452 | Standard_Boolean hadchrono = Draw_Chrono; | |
453 | if (hadchrono) tictac.Start(); | |
454 | ||
455 | if (Draw_BeforeCommand) (*Draw_BeforeCommand) (); | |
456 | ||
457 | Standard_Integer c; | |
458 | ||
459 | c = theCommands.RecordAndEval(Tcl_DStringValue(&command)); | |
460 | ||
461 | if (Draw_AfterCommand) (*Draw_AfterCommand)(c); | |
462 | ||
463 | if (wasspying && Draw_Spying) { | |
464 | if (c > 0) spystream << "# "; | |
465 | spystream << Tcl_DStringValue(&command) << "\n"; | |
466 | } | |
467 | ||
468 | dout.Flush(); | |
469 | ||
470 | if (*theCommands.Result()) | |
471 | cout << theCommands.Result() << endl; | |
472 | ||
473 | if (Draw_Chrono && hadchrono) { | |
474 | tictac.Stop(); | |
475 | tictac.Show(); | |
476 | } | |
477 | ||
478 | Tcl_DStringFree(&command); | |
479 | ||
480 | return Standard_True; | |
481 | } | |
482 | ||
483 | // | |
484 | // for TCl | |
485 | // | |
486 | ||
487 | Standard_Integer Tcl_AppInit (Tcl_Interp *) | |
488 | { | |
489 | return 0; | |
490 | } | |
491 | ||
492 | // | |
493 | // for debug call | |
494 | // | |
495 | ||
496 | ||
497 | ||
498 | Standard_Integer Draw_Call (char *c) | |
499 | { | |
500 | Standard_Integer r = theCommands.Eval(c); | |
501 | cout << theCommands.Result() << endl; | |
502 | return r; | |
503 | } | |
504 | ||
505 | ||
506 | //================================================================================= | |
507 | // | |
508 | //================================================================================= | |
509 | void Draw::Load(Draw_Interpretor& theDI, const TCollection_AsciiString& theKey, | |
510 | const TCollection_AsciiString& theResourceFileName) { | |
511 | ||
512 | static Draw_MapOfFunctions theMapOfFunctions; | |
513 | OSD_Function f; | |
514 | ||
515 | if(!theMapOfFunctions.IsBound(theKey)) { | |
516 | ||
517 | Handle(Resource_Manager) aPluginResource = new Resource_Manager(theResourceFileName.ToCString()); | |
518 | if(!aPluginResource->Find(theKey.ToCString())) { | |
519 | Standard_SStream aMsg; aMsg << "Could not find the resource:"; | |
520 | aMsg << theKey.ToCString()<< endl; | |
521 | cout << "could not find the resource:"<<theKey.ToCString()<< endl; | |
522 | Draw_Failure::Raise(aMsg); | |
523 | } | |
524 | ||
525 | TCollection_AsciiString aPluginLibrary(""); | |
526 | #ifndef WNT | |
527 | aPluginLibrary += "lib"; | |
528 | #endif | |
529 | aPluginLibrary += aPluginResource->Value(theKey.ToCString()); | |
530 | #ifdef WNT | |
531 | aPluginLibrary += ".dll"; | |
532 | #elif __APPLE__ | |
533 | aPluginLibrary += ".dylib"; | |
534 | #elif defined (HPUX) || defined(_hpux) | |
535 | aPluginLibrary += ".sl"; | |
536 | #else | |
537 | aPluginLibrary += ".so"; | |
538 | #endif | |
539 | OSD_SharedLibrary aSharedLibrary(aPluginLibrary.ToCString()); | |
540 | if(!aSharedLibrary.DlOpen(OSD_RTLD_LAZY)) { | |
541 | TCollection_AsciiString error(aSharedLibrary.DlError()); | |
542 | Standard_SStream aMsg; aMsg << "Could not open: "; | |
543 | aMsg << aPluginResource->Value(theKey.ToCString()); | |
544 | aMsg << "; reason: "; | |
545 | aMsg << error.ToCString(); | |
546 | #ifdef DEB | |
547 | cout << "could not open: " << aPluginResource->Value(theKey.ToCString())<< " ; reason: "<< error.ToCString() << endl; | |
548 | #endif | |
549 | Draw_Failure::Raise(aMsg); | |
550 | } | |
551 | f = aSharedLibrary.DlSymb("PLUGINFACTORY"); | |
552 | if( f == NULL ) { | |
553 | TCollection_AsciiString error(aSharedLibrary.DlError()); | |
554 | Standard_SStream aMsg; aMsg << "Could not find the factory in: "; | |
555 | aMsg << aPluginResource->Value(theKey.ToCString()); | |
556 | aMsg << error.ToCString(); | |
557 | Draw_Failure::Raise(aMsg); | |
558 | } | |
559 | theMapOfFunctions.Bind(theKey, f); | |
560 | } | |
561 | else | |
562 | f = theMapOfFunctions(theKey); | |
563 | ||
564 | // void (*fp) (Draw_Interpretor&, const TCollection_AsciiString&) = NULL; | |
565 | // fp = (void (*)(Draw_Interpretor&, const TCollection_AsciiString&)) f; | |
566 | // (*fp) (theDI, theKey); | |
567 | ||
568 | void (*fp) (Draw_Interpretor&) = NULL; | |
569 | fp = (void (*)(Draw_Interpretor&)) f; | |
570 | (*fp) (theDI); | |
571 | ||
572 | } | |
573 | ||
574 | ||
575 | //================================================================================= | |
576 | // | |
577 | //================================================================================= | |
578 | void Draw::Load(Draw_Interpretor& theDI, const TCollection_AsciiString& theKey, | |
579 | const TCollection_AsciiString& theResourceFileName, | |
580 | TCollection_AsciiString& theDefaultsDirectory, | |
581 | TCollection_AsciiString& theUserDefaultsDirectory, | |
582 | const Standard_Boolean Verbose ) { | |
583 | ||
584 | static Draw_MapOfFunctions theMapOfFunctions; | |
585 | OSD_Function f; | |
586 | ||
587 | if(!theMapOfFunctions.IsBound(theKey)) { | |
588 | ||
589 | Handle(Resource_Manager) aPluginResource = new Resource_Manager(theResourceFileName.ToCString(), theDefaultsDirectory, theUserDefaultsDirectory, Verbose); | |
590 | ||
591 | if(!aPluginResource->Find(theKey.ToCString())) { | |
592 | Standard_SStream aMsg; aMsg << "Could not find the resource:"; | |
593 | aMsg << theKey.ToCString()<< endl; | |
594 | cout << "could not find the resource:"<<theKey.ToCString()<< endl; | |
595 | Draw_Failure::Raise(aMsg); | |
596 | } | |
597 | ||
598 | TCollection_AsciiString aPluginLibrary(""); | |
599 | #ifndef WNT | |
600 | aPluginLibrary += "lib"; | |
601 | #endif | |
602 | aPluginLibrary += aPluginResource->Value(theKey.ToCString()); | |
603 | #ifdef WNT | |
604 | aPluginLibrary += ".dll"; | |
605 | #elif __APPLE__ | |
606 | aPluginLibrary += ".dylib"; | |
607 | #elif defined (HPUX) || defined(_hpux) | |
608 | aPluginLibrary += ".sl"; | |
609 | #else | |
610 | aPluginLibrary += ".so"; | |
611 | #endif | |
612 | OSD_SharedLibrary aSharedLibrary(aPluginLibrary.ToCString()); | |
613 | if(!aSharedLibrary.DlOpen(OSD_RTLD_LAZY)) { | |
614 | TCollection_AsciiString error(aSharedLibrary.DlError()); | |
615 | Standard_SStream aMsg; aMsg << "Could not open: "; | |
616 | aMsg << aPluginResource->Value(theKey.ToCString()); | |
617 | aMsg << "; reason: "; | |
618 | aMsg << error.ToCString(); | |
619 | #ifdef DEB | |
620 | cout << "could not open: " << aPluginResource->Value(theKey.ToCString())<< " ; reason: "<< error.ToCString() << endl; | |
621 | #endif | |
622 | Draw_Failure::Raise(aMsg); | |
623 | } | |
624 | f = aSharedLibrary.DlSymb("PLUGINFACTORY"); | |
625 | if( f == NULL ) { | |
626 | TCollection_AsciiString error(aSharedLibrary.DlError()); | |
627 | Standard_SStream aMsg; aMsg << "Could not find the factory in: "; | |
628 | aMsg << aPluginResource->Value(theKey.ToCString()); | |
629 | aMsg << error.ToCString(); | |
630 | Draw_Failure::Raise(aMsg); | |
631 | } | |
632 | theMapOfFunctions.Bind(theKey, f); | |
633 | } | |
634 | else | |
635 | f = theMapOfFunctions(theKey); | |
636 | ||
637 | // void (*fp) (Draw_Interpretor&, const TCollection_AsciiString&) = NULL; | |
638 | // fp = (void (*)(Draw_Interpretor&, const TCollection_AsciiString&)) f; | |
639 | // (*fp) (theDI, theKey); | |
640 | ||
641 | void (*fp) (Draw_Interpretor&) = NULL; | |
642 | fp = (void (*)(Draw_Interpretor&)) f; | |
643 | (*fp) (theDI); | |
644 | ||
645 | } |