1 // File: Draw_BasicCommands.cxx
2 // Created: Thu Feb 23 18:21:17 1995
3 // Author: Remi LEQUETTE
6 #include <Standard_Macro.hxx>
7 #include <Standard_Stream.hxx>
8 #include <Standard_SStream.hxx>
11 #include <Draw_Appli.hxx>
12 #include <Draw_Printer.hxx>
14 #include <Message.hxx>
15 #include <Message_Messenger.hxx>
21 #if defined(HAVE_TIME_H) || defined(WNT)
30 # include <sys/resource.h>
31 # ifdef HAVE_STRINGS_H
36 extern Standard_Boolean Draw_Batch;
44 #elif defined (HAVE_LIMITS_H)
52 static clock_t MDTV_CPU_LIMIT; // Cpu_limit in Sec.
53 static clock_t MDTV_CPU_CURRENT; // cpu time already used at last
54 // cpulimit call. (sec.)
55 //#define strcasecmp strcmp Already defined
56 #define RLIM_INFINITY 0x7fffffff
59 #include <Draw_Chronometer.hxx>
61 #if defined (__hpux) || defined ( HPUX )
62 #define RLIM_INFINITY 0x7fffffff
68 //=======================================================================
70 //=======================================================================
72 extern Standard_Boolean Draw_Chrono;
74 static Standard_Integer chronom(Draw_Interpretor& di,
75 Standard_Integer n,const char** a)
77 if ((n == 1) || (*a[1] == '0') || (*a[1] == '1')) {
79 Draw_Chrono = !Draw_Chrono;
81 Draw_Chrono = (*a[1] == '1');
83 if (Draw_Chrono) di << "Chronometers activated."<<"\n";
84 else di << "Chronometers desactivated."<<"\n";
87 Handle(Draw_Drawable3D) D = Draw::Get(a[1]);
88 Handle(Draw_Chronometer) C;
90 C = Handle(Draw_Chronometer)::DownCast(D);
93 C = new Draw_Chronometer();
94 Draw::Set(a[1],C,Standard_False);
100 if (!strcasecmp(a[2],"reset"))
102 if (!strcasecmp(a[2],"start"))
104 if (!strcasecmp(a[2],"stop"))
106 if (!strcasecmp(a[2],"show"))
113 static Standard_Integer dchronom(Draw_Interpretor& I,
114 Standard_Integer n,const char** a)
116 if ((n == 1) || (*a[1] == '0') || (*a[1] == '1')) {
118 Draw_Chrono = !Draw_Chrono;
120 Draw_Chrono = (*a[1] == '1');
122 if (Draw_Chrono) I << "Chronometers activated."<<"\n";
123 else I << "Chronometers desactivated."<<"\n";
126 Handle(Draw_Drawable3D) D = Draw::Get(a[1]);
127 Handle(Draw_Chronometer) C;
129 C = Handle(Draw_Chronometer)::DownCast(D);
132 C = new Draw_Chronometer();
133 Draw::Set(a[1],C,Standard_False);
139 if (!strcasecmp(a[2],"reset"))
141 if (!strcasecmp(a[2],"start"))
143 if (!strcasecmp(a[2],"stop"))
145 if (!strcasecmp(a[2],"show")) {
157 //=======================================================================
160 //=======================================================================
162 static Standard_Integer ifbatch(Draw_Interpretor& DI, Standard_Integer , const char** )
172 //=======================================================================
175 //=======================================================================
177 extern Standard_Boolean Draw_Spying;
178 extern filebuf Draw_Spyfile;
180 static Standard_Integer spy(Draw_Interpretor& di, Standard_Integer n, const char** a)
183 Draw_Spyfile.close();
184 Draw_Spying = Standard_False;
186 if (!Draw_Spyfile.open(a[1],ios::out)) {
187 di << "Cannot open "<<a[1]<<" for writing"<<"\n";
190 Draw_Spying = Standard_True;
195 //=======================================================================
198 //=======================================================================
200 static Standard_Integer Draw_wait(Draw_Interpretor& , Standard_Integer n, const char** a)
202 Standard_Integer w = 10;
205 time_t ct = time(NULL) + w;
206 while (time(NULL) < ct) {};
211 static Standard_Integer cpulimit(Draw_Interpretor& di, Standard_Integer n, const char** a)
215 rlp.rlim_max = RLIM_INFINITY;
217 rlp.rlim_cur = RLIM_INFINITY;
219 rlp.rlim_cur = atoi(a[1]);
222 status=setrlimit(RLIMIT_CPU,&rlp);
224 di << "status cpulimit setrlimit : " << status << "\n";
230 unsigned int __stdcall CpuFunc(void * );
233 if (n <= 1) MDTV_CPU_LIMIT = RLIM_INFINITY;
236 MDTV_CPU_LIMIT = atoi(a[1]);
237 MDTV_CPU_CURRENT = clock()/1000;
239 if (first) // Lancer le thread au 1er appel seulement.
242 _beginthreadex(NULL,0,CpuFunc,NULL,0,&ThreadID);
253 void Draw::BasicCommands(Draw_Interpretor& theCommands)
255 static Standard_Boolean Done = Standard_False;
257 Done = Standard_True;
259 const char* g = "DRAW General Commands";
261 theCommands.Add("batch", "returns 1 in batch mode",
263 theCommands.Add("spy","spy [file], Save commands in file. no file close",
265 theCommands.Add("wait","wait [time(10)], wait time seconds",
266 __FILE__,Draw_wait,g);
267 theCommands.Add("cpulimit","cpulimit [nbseconds], no args remove limits",
268 __FILE__,cpulimit,g);
269 theCommands.Add("chrono","chrono [ name start/stop/reset/show]",
271 theCommands.Add("dchrono","dchrono [ name start/stop/reset/show]",
272 __FILE__,dchronom,g);