Added info on VTK availability in dversion command; VTK tests are corrected to report...
[occt.git] / src / Draw / Draw_BasicCommands.cxx
CommitLineData
b311480e 1// Created on: 1995-02-23
2// Created by: Remi LEQUETTE
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
7fd59977 17#include <Standard_Macro.hxx>
18#include <Standard_Stream.hxx>
19#include <Standard_SStream.hxx>
8a262fa1 20#include <Standard_Version.hxx>
7fd59977 21
22#include <Draw.ixx>
23#include <Draw_Appli.hxx>
a60b9727 24#include <Draw_Chronometer.hxx>
7fd59977 25#include <Draw_Printer.hxx>
26
27#include <Message.hxx>
28#include <Message_Messenger.hxx>
a60b9727 29
f0430952 30#include <OSD_MemInfo.hxx>
a60b9727 31#include <OSD_MAllocHook.hxx>
32#include <OSD_Chronometer.hxx>
8a262fa1 33#include <OSD.hxx>
34#include <OSD_Exception_CTRL_BREAK.hxx>
7fd59977 35
a60b9727 36#ifdef _WIN32
7fd59977 37
7fd59977 38#include <windows.h>
39#include <winbase.h>
40#include <process.h>
41#include <stdio.h>
42#include <stdlib.h>
a60b9727 43#include <time.h>
44#include <limits>
45
46#define RLIM_INFINITY 0x7fffffff
47
48static clock_t CPU_CURRENT; // cpu time already used at last
49 // cpulimit call. (sec.)
50
51#else /* _WIN32 */
52
53#include <sys/resource.h>
03155c18 54#include <signal.h>
7fd59977 55
56#if defined (__hpux) || defined ( HPUX )
57#define RLIM_INFINITY 0x7fffffff
58#define RLIMIT_CPU 0
59#endif
60
a60b9727 61#endif /* _WIN32 */
7fd59977 62
a60b9727 63extern Standard_Boolean Draw_Batch;
64
65static clock_t CPU_LIMIT; // Cpu_limit in Sec.
7fd59977 66
67//=======================================================================
68// chronom
69//=======================================================================
70
71extern Standard_Boolean Draw_Chrono;
72
73static Standard_Integer chronom(Draw_Interpretor& di,
74 Standard_Integer n,const char** a)
75{
76 if ((n == 1) || (*a[1] == '0') || (*a[1] == '1')) {
77 if (n == 1)
78 Draw_Chrono = !Draw_Chrono;
79 else
80 Draw_Chrono = (*a[1] == '1');
81
82 if (Draw_Chrono) di << "Chronometers activated."<<"\n";
83 else di << "Chronometers desactivated."<<"\n";
84 }
85 else {
86 Handle(Draw_Drawable3D) D = Draw::Get(a[1]);
87 Handle(Draw_Chronometer) C;
88 if (!D.IsNull()) {
89 C = Handle(Draw_Chronometer)::DownCast(D);
90 }
91 if (C.IsNull()) {
92 C = new Draw_Chronometer();
93 Draw::Set(a[1],C,Standard_False);
94 }
95 if (n <= 2) {
96 C->Timer().Reset();
97 }
98 else {
99 if (!strcasecmp(a[2],"reset"))
100 C->Timer().Reset();
101 if (!strcasecmp(a[2],"start"))
102 C->Timer().Start();
103 if (!strcasecmp(a[2],"stop"))
104 C->Timer().Stop();
105 if (!strcasecmp(a[2],"show"))
106 C->Timer().Show();
107 }
108 }
109 return 0;
110}
111
112static Standard_Integer dchronom(Draw_Interpretor& I,
113 Standard_Integer n,const char** a)
114{
115 if ((n == 1) || (*a[1] == '0') || (*a[1] == '1')) {
116 if (n == 1)
117 Draw_Chrono = !Draw_Chrono;
118 else
119 Draw_Chrono = (*a[1] == '1');
120
121 if (Draw_Chrono) I << "Chronometers activated."<<"\n";
122 else I << "Chronometers desactivated."<<"\n";
123 }
124 else {
125 Handle(Draw_Drawable3D) D = Draw::Get(a[1]);
126 Handle(Draw_Chronometer) C;
127 if (!D.IsNull()) {
128 C = Handle(Draw_Chronometer)::DownCast(D);
129 }
130 if (C.IsNull()) {
131 C = new Draw_Chronometer();
132 Draw::Set(a[1],C,Standard_False);
133 }
134 if (n <= 2) {
135 C->Timer().Reset();
136 }
137 else {
138 if (!strcasecmp(a[2],"reset"))
139 C->Timer().Reset();
140 if (!strcasecmp(a[2],"start"))
141 C->Timer().Start();
142 if (!strcasecmp(a[2],"stop"))
143 C->Timer().Stop();
144 if (!strcasecmp(a[2],"show")) {
145 Standard_SStream ss;
146 C->Timer().Show(ss);
147 I << ss;
148 }
149 }
150 }
151 return 0;
152}
153
154
155
156//=======================================================================
157//function : ifbatch
158//purpose :
159//=======================================================================
160
161static Standard_Integer ifbatch(Draw_Interpretor& DI, Standard_Integer , const char** )
162{
163 if (Draw_Batch)
164 DI << "1";
165 else
166 DI << "0";
167
168 return 0;
169}
170
171//=======================================================================
172//function : spy
173//purpose :
174//=======================================================================
175
176extern Standard_Boolean Draw_Spying;
177extern filebuf Draw_Spyfile;
178
179static Standard_Integer spy(Draw_Interpretor& di, Standard_Integer n, const char** a)
180{
181 if (Draw_Spying)
182 Draw_Spyfile.close();
183 Draw_Spying = Standard_False;
184 if (n > 1) {
185 if (!Draw_Spyfile.open(a[1],ios::out)) {
186 di << "Cannot open "<<a[1]<<" for writing"<<"\n";
187 return 1;
188 }
189 Draw_Spying = Standard_True;
190 }
191 return 0;
192}
193
aa02980d 194static Standard_Integer dlog(Draw_Interpretor& di, Standard_Integer n, const char** a)
195{
196 if (n != 2 && n != 3)
197 {
198 cout << "Enable or disable logging: " << a[0] << " {on|off}" << endl;
199 cout << "Reset log: " << a[0] << " reset" << endl;
200 cout << "Get log content: " << a[0] << " get" << endl;
201 return 1;
202 }
203
204 if (! strcmp (a[1], "on") && n == 2)
205 {
206 di.SetDoLog (Standard_True);
207// di.Log() << "dlog on" << endl; // for symmetry
208 }
209 else if (! strcmp (a[1], "off") && n == 2)
210 {
211 di.SetDoLog (Standard_False);
212 }
213 else if (! strcmp (a[1], "reset") && n == 2)
214 {
215 di.Log().str("");
216 }
217 else if (! strcmp (a[1], "get") && n == 2)
218 {
219 di << di.Log().str().c_str();
220 }
221 else if (! strcmp (a[1], "add") && n == 3)
222 {
223 di.Log() << a[2] << "\n";
224 }
225 else {
226 cout << "Unrecognized option(s): " << a[1] << endl;
227 return 1;
228 }
229 return 0;
230}
231
232static Standard_Integer decho(Draw_Interpretor& di, Standard_Integer n, const char** a)
233{
234 if (n != 2)
235 {
236 cout << "Enable or disable echoing: " << a[0] << " {on|off}" << endl;
237 return 1;
238 }
239
240 if (! strcmp (a[1], "on"))
241 {
242 di.SetDoEcho (Standard_True);
243 }
244 else if (! strcmp (a[1], "off"))
245 {
246 di.SetDoEcho (Standard_False);
247 }
248 else {
249 cout << "Unrecognized option: " << a[1] << endl;
250 return 1;
251 }
252 return 0;
253}
254
8a262fa1 255static Standard_Integer dbreak(Draw_Interpretor& di, Standard_Integer, const char**)
256{
257 try {
258 OSD::ControlBreak();
259 }
260 catch (OSD_Exception_CTRL_BREAK) {
261 di << "User pressed Control-Break";
262 return 1; // Tcl exception
263 }
264
265 return 0;
266}
267
268static Standard_Integer dversion(Draw_Interpretor& di, Standard_Integer, const char**)
269{
270 // print OCCT version and OCCTY-specific macros used
271 di << "Open CASCADE Technology " << OCC_VERSION_STRING_EXT << "\n";
272#if defined(DEB) || defined(_DEBUG)
273 di << "Debug mode\n";
274#endif
275#ifdef HAVE_TBB
276 di << "TBB enabled (HAVE_TBB)\n";
277#else
278 di << "TBB disabled\n";
279#endif
280#ifdef HAVE_GL2PS
281 di << "GL2PS enabled (HAVE_GL2PS)\n";
282#else
283 di << "GL2PS disabled\n";
284#endif
285#ifdef HAVE_FREEIMAGE
286 di << "FreeImage enabled (HAVE_FREEIMAGE)\n";
287#else
288 di << "FreeImage disabled\n";
289#endif
7ae4a307 290#ifdef HAVE_OPENCL
291 di << "OpenCL enabled (HAVE_OPENCL)\n";
292#else
293 di << "OpenCL disabled\n";
294#endif
476e84b1 295#ifdef HAVE_VTK
296 di << "VTK enabled (HAVE_VTK)\n";
297#else
298 di << "VTK disabled\n";
299#endif
8a262fa1 300#ifdef No_Exception
301 di << "Exceptions disabled (No_Exception)\n";
302#else
303 di << "Exceptions enabled\n";
304#endif
305
306 // check compiler, OS, etc. using pre-processor macros provided by compiler
307 // see "Pre-defined C/C++ Compiler Macros" http://sourceforge.net/p/predef/wiki/
308 // note that only modern compilers that are known to be used for OCCT are recognized
309
310 // compiler; note that GCC and MSVC are last as other compilers (e.g. Intel) can also define __GNUC__ and _MSC_VER
311#if defined(__INTEL_COMPILER)
312 di << "Compiler: Intel " << __INTEL_COMPILER << "\n";
313#elif defined(__BORLANDC__)
314 di << "Compiler: Borland C++ (__BORLANDC__ = " << __BORLANDC__ << ")\n";
315#elif defined(__clang__)
316 di << "Compiler: Clang " << __clang_major__ << "." << __clang_minor__ << "." << __clang_patchlevel__ << "\n";
317#elif defined(__SUNPRO_C)
318 di << "Compiler: Sun Studio (__SUNPRO_C = " << __SUNPROC_C << ")\n";
319#elif defined(_MSC_VER)
320 di << "Compiler: MS Visual C++ " << (int)(_MSC_VER/100-6) << "." << (int)((_MSC_VER/10)-60-10*(int)(_MSC_VER/100-6)) << " (_MSC_FULL_VER = " << _MSC_FULL_VER << ")\n";
321#elif defined(__GNUC__)
322 di << "Compiler: GCC " << __GNUC__ << "." << __GNUC_MINOR__ << "." << __GNUC_PATCHLEVEL__ << "\n";
323#else
324 di << "Compiler: unrecognized\n";
325#endif
326
327 // Cygwin and MinGW specifics
328#if defined(__CYGWIN__)
329 di << "Cygwin\n";
330#endif
331#if defined(__MINGW64__)
332 di << "MinGW 64 " << __MINGW64_MAJOR_VERSION << "." << __MINGW64_MINOR_VERSION << "\n";
333#elif defined(__MINGW32__)
334 di << "MinGW 32 " << __MINGW32_MAJOR_VERSION << "." << __MINGW32_MINOR_VERSION << "\n";
335#endif
336
337 // architecture
338#if defined(__amd64) || defined(__x86_64) || defined(_M_AMD64)
339 di << "Architecture: AMD64\n";
340#elif defined(__i386) || defined(_M_IX86) || defined(__X86__)|| defined(_X86_)
341 di << "Architecture: Intel x86\n";
342#elif defined(_M_IA64) || defined(__ia64__)
343 di << "Architecture: Intel Itanium (IA 64)\n";
344#elif defined(__sparc__) || defined(__sparc)
345 di << "Architecture: SPARC\n";
346#else
347 di << "Architecture: unrecognized\n";
348#endif
349
350 // OS
351#if defined(_WIN32) || defined(__WINDOWS__) || defined(__WIN32__)
352 di << "OS: Windows\n";
353#elif defined(__APPLE__) || defined(__MACH__)
354 di << "OS: Mac OS X\n";
355#elif defined(__sun)
356 di << "OS: SUN Solaris\n";
357#elif defined(__ANDROID__) /* must be before Linux */
358 #include <android/api-level.h>
359 di << "OS: Android (__ANDROID_API__ = " << __ANDROID_API__ << ")\n";
360#elif defined(__linux__)
361 di << "OS: Linux\n";
362#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
363 #include <sys/param.h>
364 di << "OS: BSD (BSD = " << BSD << ")\n";
365#else
366 di << "OS: unrecognized\n";
367#endif
368
369 return 0;
370}
371
7fd59977 372//=======================================================================
373//function : wait
374//purpose :
375//=======================================================================
376
377static Standard_Integer Draw_wait(Draw_Interpretor& , Standard_Integer n, const char** a)
378{
379 Standard_Integer w = 10;
380 if (n > 1)
91322f44 381 w = Draw::Atoi(a[1]);
7fd59977 382 time_t ct = time(NULL) + w;
383 while (time(NULL) < ct) {};
384 return 0;
385}
386
47cbc555
A
387//=======================================================================
388//function : cpulimit
389//purpose :
390//=======================================================================
a60b9727 391#ifdef _WIN32
35e08fe8 392static unsigned int __stdcall CpuFunc (void * /*param*/)
47cbc555
A
393{
394 clock_t aCurrent;
302f96fb 395 for(;;)
47cbc555
A
396 {
397 Sleep (5);
398 Standard_Real anUserSeconds, aSystemSeconds;
399 OSD_Chronometer::GetProcessCPU (anUserSeconds, aSystemSeconds);
400 aCurrent = clock_t(anUserSeconds + aSystemSeconds);
401
a60b9727 402 if ((aCurrent - CPU_CURRENT) >= CPU_LIMIT)
47cbc555 403 {
a60b9727 404 cout << "Process killed by CPU limit (" << CPU_LIMIT << " sec)" << endl;
47cbc555 405 ExitProcess (2);
d3f26155 406// return 0;
47cbc555
A
407 }
408 }
47cbc555 409}
a60b9727 410#else
411static void CpuFunc (int)
412{
413 cout << "Process killed by CPU limit (" << CPU_LIMIT << " sec)" << endl;
414 exit(2);
415}
47cbc555 416#endif
7fd59977 417
35e08fe8 418#ifdef _WIN32
419static Standard_Integer cpulimit(Draw_Interpretor&, Standard_Integer n, const char** a)
420{
421#else
7fd59977 422static Standard_Integer cpulimit(Draw_Interpretor& di, Standard_Integer n, const char** a)
423{
35e08fe8 424#endif
a60b9727 425#ifdef _WIN32
426 // Windows specific code
7fd59977 427
47cbc555 428 static int aFirst = 1;
7fd59977 429
47cbc555
A
430 unsigned int __stdcall CpuFunc (void *);
431 unsigned aThreadID;
432
433 if (n <= 1)
a60b9727 434 CPU_LIMIT = RLIM_INFINITY;
47cbc555
A
435 else
436 {
91322f44 437 CPU_LIMIT = Draw::Atoi (a[1]);
47cbc555
A
438 Standard_Real anUserSeconds, aSystemSeconds;
439 OSD_Chronometer::GetProcessCPU (anUserSeconds, aSystemSeconds);
a60b9727 440 CPU_CURRENT = clock_t(anUserSeconds + aSystemSeconds);
47cbc555
A
441
442 if (aFirst) // Launch the thread only at the 1st call.
443 {
444 aFirst = 0;
445 _beginthreadex (NULL, 0, CpuFunc, NULL, 0, &aThreadID);
446 }
7fd59977 447 }
448
a60b9727 449#else
450
451 // Unix & Linux
452
453 rlimit rlp;
454 rlp.rlim_max = RLIM_INFINITY;
455 if (n <= 1)
456 rlp.rlim_cur = RLIM_INFINITY;
457 else
91322f44 458 rlp.rlim_cur = Draw::Atoi(a[1]);
a60b9727 459 CPU_LIMIT = rlp.rlim_cur;
460
461 int status;
462 status=setrlimit(RLIMIT_CPU,&rlp);
463 if (status !=0)
464 di << "status cpulimit setrlimit : " << status << "\n";
465
466 // set signal handler to print a message before death
467 struct sigaction act, oact;
468 memset (&act, 0, sizeof(act));
469 act.sa_handler = CpuFunc;
470 sigaction (SIGXCPU, &act, &oact);
471
7fd59977 472#endif
473
474 return 0;
475}
476
7af17f1e
MA
477//=======================================================================
478//function : mallochook
479//purpose :
480//=======================================================================
481
482static Standard_Integer mallochook(Draw_Interpretor& di, Standard_Integer n,
483 const char** a)
484{
485 if (n < 2)
486 {
487 di << "\
488usage: mallochook cmd\n\
489where cmd is one of:\n\
490 set [<op>] - set callback to malloc/free; op is one of the following:\n\
491 0 - set callback to NULL,\n\
492 1 - set callback OSD_MAllocHook::CollectBySize (default)\n\
493 2 - set callback OSD_MAllocHook::LogFileHandler\n\
494 reset - reset the CollectBySize handler\n\
495 report1 [<outfile>]\n\
496 - write report from CollectBySize handler in <outfile>\n\
497 open [<logfile>]\n\
498 - open file for writing the log with LogFileHandler\n\
499 close - close the log file with LogFileHandler\n\
500 report2 [<flag>] [<logfile>] [<outfile>]\n\
501 - scan <logfile> written with LogFileHandler\n\
502 and make synthesized report in <outfile>; <flag> can be:\n\
503 0 - simple stats by sizes (default),\n\
504 1 - with alive allocation numbers\n\
505By default <logfile> is \"mem-log.txt\", <outfile> is \"mem-stat.txt\""
506 << "\n";
507 return 0;
508 }
509 if (strcmp(a[1], "set") == 0)
510 {
91322f44 511 int aType = (n > 2 ? Draw::Atoi(a[2]) : 1);
7af17f1e
MA
512 if (aType < 0 || aType > 2)
513 {
514 di << "unknown op of the command set" << "\n";
515 return 1;
516 }
517 else if (aType == 0)
518 {
519 OSD_MAllocHook::SetCallback(NULL);
520 di << "callback is unset" << "\n";
521 }
522 else if (aType == 1)
523 {
524 OSD_MAllocHook::SetCallback(OSD_MAllocHook::GetCollectBySize());
525 di << "callback is set to CollectBySize" << "\n";
526 }
527 else //if (aType == 2)
528 {
529 OSD_MAllocHook::SetCallback(OSD_MAllocHook::GetLogFileHandler());
530 di << "callback is set to LogFileHandler" << "\n";
531 }
532 }
533 else if (strcmp(a[1], "reset") == 0)
534 {
535 OSD_MAllocHook::GetCollectBySize()->Reset();
536 di << "CollectBySize handler is reset" << "\n";
537 }
538 else if (strcmp(a[1], "open") == 0)
539 {
540 const char* aFileName = (n > 2 ? a[2] : "mem-log.txt");
541 if (!OSD_MAllocHook::GetLogFileHandler()->Open(aFileName))
542 {
543 di << "cannot create file " << aFileName << " for writing" << "\n";
544 return 1;
545 }
546 di << "log file " << aFileName << " is opened for writing" << "\n";
547 }
548 else if (strcmp(a[1], "close") == 0)
549 {
550 OSD_MAllocHook::GetLogFileHandler()->Close();
551 di << "log file is closed" << "\n";
552 }
553 else if (strcmp(a[1], "report1") == 0)
554 {
555 const char* aOutFile = "mem-stat.txt";
556 if (n > 2)
557 aOutFile = a[2];
558 if (OSD_MAllocHook::GetCollectBySize()->MakeReport(aOutFile))
559 {
560 di << "report " << aOutFile << " has been created" << "\n";
561 }
562 else
563 {
564 di << "cannot create report " << aOutFile << "\n";
565 return 1;
566 }
567 }
568 else if (strcmp(a[1], "report2") == 0)
569 {
570 Standard_Boolean includeAlive = Standard_False;
571 const char* aLogFile = "mem-log.txt";
572 const char* aOutFile = "mem-stat.txt";
573 if (n > 2)
574 {
91322f44 575 includeAlive = (Draw::Atoi(a[2]) != 0);
7af17f1e
MA
576 if (n > 3)
577 {
578 aLogFile = a[3];
579 if (n > 4)
580 aOutFile = a[4];
581 }
582 }
583 if (OSD_MAllocHook::LogFileHandler::MakeReport(aLogFile, aOutFile, includeAlive))
584 {
585 di << "report " << aOutFile << " has been created" << "\n";
586 }
587 else
588 {
589 di << "cannot create report " << aOutFile << " from the log file "
590 << aLogFile << "\n";
591 return 1;
592 }
593 }
594 else
595 {
596 di << "unrecognized command " << a[1] << "\n";
597 return 1;
598 }
599 return 0;
600}
601
91322f44 602//==============================================================================
603//function : dlocale
604//purpose :
605//==============================================================================
606
607static int dlocale (Draw_Interpretor& di, Standard_Integer n, const char** argv)
608{
609 int category = LC_ALL;
610 if (n > 1)
611 {
612 const char *cat = argv[1];
613 if ( ! strcmp (cat, "LC_ALL") ) category = LC_ALL;
614 else if ( ! strcmp (cat, "LC_COLLATE") ) category = LC_COLLATE;
615 else if ( ! strcmp (cat, "LC_CTYPE") ) category = LC_CTYPE;
616 else if ( ! strcmp (cat, "LC_MONETARY") ) category = LC_MONETARY;
617 else if ( ! strcmp (cat, "LC_NUMERIC") ) category = LC_NUMERIC;
618 else if ( ! strcmp (cat, "LC_TIME") ) category = LC_TIME;
619 else
620 {
621 cout << "Error: cannot recognize argument " << cat << " as one of LC_ macros" << endl;
622 return 1;
623 }
624 }
625 const char* locale = (n > 2 ? argv[2] : NULL);
626 const char* result = setlocale (category, locale);
627 if (result)
628 di << result;
629 else
630 cout << "Error: unsupported locale specification: " << locale << endl;
631 return 0;
632}
633
f0430952 634//==============================================================================
635//function : dmeminfo
636//purpose :
637//==============================================================================
638
639static int dmeminfo (Draw_Interpretor& theDI,
640 Standard_Integer theArgNb,
641 const char** theArgVec)
642{
643 OSD_MemInfo aMemInfo;
644 if (theArgNb <= 1)
645 {
646 theDI << aMemInfo.ToString();
647 return 0;
648 }
649
650 for (Standard_Integer anIter = 1; anIter < theArgNb; ++anIter)
651 {
652 TCollection_AsciiString anArg (theArgVec[anIter]);
653 anArg.LowerCase();
654 if (anArg == "virt" || anArg == "v")
655 {
656 theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemVirtual)) << " ";
657 }
67a1064e 658 else if (anArg == "heap" || anArg == "h")
659 {
660 theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemHeapUsage)) << " ";
661 }
f0430952 662 else if (anArg == "wset" || anArg == "w")
663 {
664 theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemWorkingSet)) << " ";
665 }
666 else if (anArg == "wsetpeak")
667 {
668 theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemWorkingSetPeak)) << " ";
669 }
670 else if (anArg == "swap")
671 {
672 theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemSwapUsage)) << " ";
673 }
674 else if (anArg == "swappeak")
675 {
676 theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemSwapUsagePeak)) << " ";
677 }
678 else if (anArg == "private")
679 {
680 theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemPrivate)) << " ";
681 }
682 else
683 {
684 std::cerr << "Unknown argument '" << theArgVec[anIter] << "'!\n";
685 }
686 }
687 theDI << "\n";
688 return 0;
689}
7fd59977 690
785a9540 691//==============================================================================
692//function : dtracelevel
693//purpose :
694//==============================================================================
695
696static int dtracelevel (Draw_Interpretor& theDI,
697 Standard_Integer theArgNb,
698 const char** theArgVec)
699{
700 Message_Gravity aLevel = Message_Info;
701 if (theArgNb < 1 || theArgNb > 2)
702 {
703 std::cout << "Error: wrong number of arguments! See usage:\n";
704 theDI.PrintHelp (theArgVec[0]);
705 return 1;
706 }
707 else if (theArgNb == 2)
708 {
709 TCollection_AsciiString aVal (theArgVec[1]);
710 aVal.LowerCase();
711 if (aVal == "trace")
712 {
713 aLevel = Message_Trace;
714 }
715 else if (aVal == "info")
716 {
717 aLevel = Message_Info;
718 }
719 else if (aVal == "warn"
720 || aVal == "warning")
721 {
722 aLevel = Message_Warning;
723 }
724 else if (aVal == "alarm")
725 {
726 aLevel = Message_Alarm;
727 }
728 else if (aVal == "fail")
729 {
730 aLevel = Message_Fail;
731 }
732 else
733 {
734 std::cout << "Error: unknown gravity '" << theArgVec[1] << "'!\n";
735 return 1;
736 }
737 }
738
739 Handle(Message_Messenger) aMessenger = Message::DefaultMessenger();
740 if (aMessenger.IsNull())
741 {
742 std::cout << "Error: default messenger is unavailable!\n";
743 return 1;
744 }
745
746 Message_SequenceOfPrinters& aPrinters = aMessenger->ChangePrinters();
747 if (aPrinters.Length() < 1)
748 {
749 std::cout << "Error: no printers registered in default Messenger!\n";
750 return 0;
751 }
752
753 for (Standard_Integer aPrinterIter = 1; aPrinterIter <= aPrinters.Length(); ++aPrinterIter)
754 {
755 Handle(Message_Printer)& aPrinter = aPrinters.ChangeValue (aPrinterIter);
756 if (theArgNb == 1)
757 {
758 if (aPrinterIter == 1)
759 {
760 aLevel = aPrinter->GetTraceLevel();
761 }
762 else if (aLevel == aPrinter->GetTraceLevel())
763 {
764 continue;
765 }
766
767 switch (aPrinter->GetTraceLevel())
768 {
769 case Message_Trace: theDI << "trace"; break;
770 case Message_Info: theDI << "info"; break;
771 case Message_Warning: theDI << "warn"; break;
772 case Message_Alarm: theDI << "alarm"; break;
773 case Message_Fail: theDI << "fail"; break;
774 }
775 continue;
776 }
777
778 aPrinter->SetTraceLevel (aLevel);
779 }
780
781 return 0;
782}
783
7fd59977 784void Draw::BasicCommands(Draw_Interpretor& theCommands)
785{
786 static Standard_Boolean Done = Standard_False;
787 if (Done) return;
788 Done = Standard_True;
789
aa02980d 790 ios::sync_with_stdio();
791
7fd59977 792 const char* g = "DRAW General Commands";
785a9540 793
7fd59977 794 theCommands.Add("batch", "returns 1 in batch mode",
795 __FILE__,ifbatch,g);
796 theCommands.Add("spy","spy [file], Save commands in file. no file close",
797 __FILE__,spy,g);
798 theCommands.Add("wait","wait [time(10)], wait time seconds",
799 __FILE__,Draw_wait,g);
800 theCommands.Add("cpulimit","cpulimit [nbseconds], no args remove limits",
801 __FILE__,cpulimit,g);
802 theCommands.Add("chrono","chrono [ name start/stop/reset/show]",
803 __FILE__,chronom,g);
804 theCommands.Add("dchrono","dchrono [ name start/stop/reset/show]",
805 __FILE__,dchronom,g);
7af17f1e
MA
806 theCommands.Add("mallochook",
807 "debug memory allocation/deallocation, w/o args for help",
808 __FILE__, mallochook, g);
f0430952 809 theCommands.Add ("meminfo",
67a1064e 810 "meminfo [virt|v] [heap|h] [wset|w] [wsetpeak] [swap] [swappeak] [private]"
f0430952 811 " : memory counters for this process",
812 __FILE__, dmeminfo, g);
aa02980d 813
785a9540 814 // Logging commands; note that their names are hard-coded in the code
aa02980d 815 // of Draw_Interpretor, thus should not be changed without update of that code!
816 theCommands.Add("dlog", "manage logging of commands and output; run without args to get help",
817 __FILE__,dlog,g);
818 theCommands.Add("decho", "switch on / off echo of commands to cout; run without args to get help",
819 __FILE__,decho,g);
785a9540 820 theCommands.Add("dtracelevel", "dtracelevel [trace|info|warn|alarm|fail]",
821 __FILE__, dtracelevel, g);
822
8a262fa1 823 theCommands.Add("dbreak", "raises Tcl exception if user has pressed Control-Break key",
824 __FILE__,dbreak,g);
825 theCommands.Add("dversion", "provides information on OCCT build configuration (version, compiler, OS, C library, etc.)",
826 __FILE__,dversion,g);
91322f44 827 theCommands.Add("dlocale", "set and / or query locate of C subsystem (function setlocale())",
828 __FILE__,dlocale,g);
7fd59977 829}