b311480e |
1 | // Created on: 2002-02-04 |
2 | // Created by: QA Admin |
3 | // Copyright (c) 2002-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
7fd59977 |
20 | |
21 | |
22 | #if defined(WNT) |
23 | #include <windows.h> |
24 | #endif |
25 | #include <QADraw.hxx> |
26 | #include <QADraw_DataMapOfAsciiStringOfAddress.hxx> |
27 | #include <Draw_Interpretor.hxx> |
28 | #include <Image_PixMap.hxx> |
29 | #include <V3d_View.hxx> |
30 | #include <ViewerTest.hxx> |
31 | #include <ViewerTest_EventManager.hxx> |
32 | #include <TColStd_StackOfInteger.hxx> |
33 | #include <TColStd_ListOfInteger.hxx> |
34 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
35 | #include <TColStd_HSequenceOfReal.hxx> |
36 | #include <AIS_InteractiveContext.hxx> |
37 | #include <Graphic3d_GraphicDevice.hxx> |
38 | #include <Draw_Window.hxx> |
39 | #include <Draw_Viewer.hxx> |
40 | #include <Aspect_WindowDriver.hxx> |
41 | #include <stdio.h> |
42 | |
43 | #include <Viewer2dTest.hxx> |
44 | #include <V2d_View.hxx> |
45 | #include <Viewer2dTest_EventManager.hxx> |
46 | |
47 | #if ! defined(WNT) |
48 | #include <Xw_Window.hxx> |
49 | //#include <Xm/Xm.h> |
50 | #include <X11/Xlib.h> |
51 | #include <X11/Xutil.h> |
52 | #include <Xw_GraphicDevice.hxx> |
53 | #include <Xw_Cextern.hxx> |
54 | #include <unistd.h> |
55 | #else |
56 | #include <WNT.h> |
57 | #include <WNT_GraphicDevice.hxx> |
58 | #include <WNT_Window.hxx> |
59 | #include <io.h> |
60 | #endif |
61 | |
62 | #include <tcl.h> |
63 | |
64 | #if ! defined(STDOUT_FILENO) |
65 | #define STDOUT_FILENO fileno(stdout) |
66 | #endif |
67 | |
68 | // mkv 15.07.03 |
69 | #if ! defined(STDERR_FILENO) |
70 | #define STDERR_FILENO fileno(stderr) |
71 | #endif |
72 | |
73 | Draw_Interpretor *thePCommands = NULL; |
74 | |
75 | #if ! defined(WNT) |
76 | //extern Draw_Interpretor theCommands; |
77 | |
78 | extern void (*Draw_BeforeCommand)(); |
79 | extern void (*Draw_AfterCommand)(Standard_Integer); |
80 | #else |
81 | //Standard_EXPORT Draw_Interpretor theCommands; |
82 | |
83 | Standard_EXPORT void (*Draw_BeforeCommand)(); |
84 | Standard_EXPORT void (*Draw_AfterCommand)(Standard_Integer); |
85 | #endif |
86 | |
87 | |
88 | #include <Draw_PluginMacro.hxx> |
89 | |
90 | // avoid warnings on 'extern "C"' functions returning C++ classes |
91 | #ifdef WNT |
92 | #pragma warning(4:4190) |
93 | #endif |
94 | |
95 | |
96 | int st_err = 0; |
97 | |
98 | void (*Draw_BeforeCommand_old)(); |
99 | void (*Draw_AfterCommand_old)(Standard_Integer); |
100 | |
101 | static Standard_Boolean should_be_printed = Standard_True; |
102 | |
103 | static Standard_Boolean shouldDUP() { |
104 | // MKV 30.03.05 |
105 | #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST) |
106 | const Standard_Character * adup = Tcl_GetVar(thePCommands->Interp(), |
107 | "QA_DUP",TCL_GLOBAL_ONLY); |
108 | #else |
109 | Standard_Character * adup = Tcl_GetVar(thePCommands->Interp(), |
110 | "QA_DUP",TCL_GLOBAL_ONLY); |
111 | #endif |
112 | Standard_Integer aDUP=1; |
113 | if((adup != NULL) && (atof(adup) == 0)) { |
114 | aDUP = 0; |
115 | } |
116 | |
117 | return aDUP; |
118 | } |
119 | |
120 | static void before() { |
121 | should_be_printed = Standard_True; |
122 | if(Draw_BeforeCommand_old) (*Draw_BeforeCommand_old) (); |
123 | } |
124 | |
125 | static void after(Standard_Integer a) |
126 | { |
127 | if(Draw_AfterCommand_old) (*Draw_AfterCommand_old) (a); |
128 | if(!should_be_printed) { |
129 | // Tcl_ResetResult(theCommands.Interp()); |
130 | } |
131 | } |
132 | |
133 | static QADraw_DataMapOfAsciiStringOfAddress stFuncMap; |
134 | |
135 | // MKV 30.03.05 |
136 | #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST) |
137 | static Standard_Integer (*CommandCmd_Old) |
138 | (ClientData clientData, Tcl_Interp *interp, |
139 | Standard_Integer argc, const char* argv[]) = NULL; |
140 | #else |
141 | static Standard_Integer (*CommandCmd_Old) |
142 | (ClientData clientData, Tcl_Interp *interp, |
143 | Standard_Integer argc, char* argv[]) = NULL; |
144 | #endif |
145 | |
146 | // MKV 30.03.05 |
147 | #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST) |
148 | static Standard_Integer CommandCmd |
149 | (ClientData clientData, Tcl_Interp *interp, |
150 | Standard_Integer argc, const char* argv[]) |
151 | #else |
152 | static Standard_Integer CommandCmd |
153 | (ClientData clientData, Tcl_Interp *interp, |
154 | Standard_Integer argc, char* argv[]) |
155 | #endif |
156 | { |
157 | Standard_Integer old_out = 0; |
158 | Standard_Integer old_err = 0; |
159 | Standard_Integer fd_out = 0; |
160 | Standard_Integer fd_err = 0; |
161 | |
162 | FILE * aFile_out = NULL; |
163 | FILE * aFile_err = NULL; |
164 | |
165 | char *nameo = NULL; |
166 | char *namee = NULL; |
167 | #ifdef WNT |
168 | if(strlen(getenv("TEMP")) == 0) { |
169 | cerr << "The TEMP variable is not set." << endl; |
170 | aFile_out = tmpfile(); |
171 | aFile_err = tmpfile(); |
172 | } else { |
173 | nameo = _tempnam(getenv("TEMP"),"tmpo"); |
174 | namee = _tempnam(getenv("TEMP"),"tmpe"); |
175 | aFile_out=fopen(nameo, "w+"); |
176 | aFile_err=fopen(namee, "w+"); |
177 | } |
178 | #else |
179 | aFile_out = tmpfile(); |
180 | aFile_err = tmpfile(); |
181 | #endif |
182 | fd_out = fileno(aFile_out); |
183 | fd_err = fileno(aFile_err); |
184 | if(fd_out !=-1 && fd_err !=-1) { |
185 | old_err = dup(STDERR_FILENO); |
186 | old_out = dup(STDOUT_FILENO); |
187 | dup2(fd_err,STDERR_FILENO); |
188 | dup2(fd_out,STDOUT_FILENO); |
189 | } else |
190 | cout << "Faulty : Can not create temporary file." << endl; |
191 | |
192 | Standard_Integer clen = sizeof(Standard_Character); |
193 | |
194 | Standard_Character * QA = getenv("QA_print_command"); |
195 | if((QA != NULL) && (!strcmp(QA,"1"))) { |
196 | for(Standard_Integer i=0;i<argc;i++) { |
197 | write(st_err,argv[i],clen*strlen(argv[i])); |
198 | write(st_err," ",clen); |
199 | } |
200 | write(st_err,"\n",clen); |
201 | } |
202 | |
203 | // MKV 30.03.05 |
204 | #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST) |
205 | TCollection_AsciiString aName((char *) argv[0]); |
206 | #else |
207 | TCollection_AsciiString aName(argv[0]); |
208 | #endif |
209 | |
210 | Standard_Integer res = 0; |
211 | |
212 | if(stFuncMap.IsBound(aName)) { |
213 | // MKV 30.03.05 |
214 | #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST) |
215 | CommandCmd_Old = (int(*)(void*, Tcl_Interp*, int, const char**)) stFuncMap((char *) argv[0]); |
216 | #else |
217 | CommandCmd_Old = (int(*)(void*, Tcl_Interp*, int, char**)) stFuncMap(argv[0]); |
218 | #endif |
219 | res = (*CommandCmd_Old) (clientData,interp,argc,argv); |
220 | } |
221 | |
222 | fflush(stderr); |
223 | fflush(stdout); |
224 | close(STDERR_FILENO); |
225 | close(STDOUT_FILENO); |
226 | dup2(old_err,STDERR_FILENO); |
227 | dup2(old_out,STDOUT_FILENO); |
228 | close(old_err); |
229 | close(old_out); |
230 | |
231 | Standard_Character buf[256]; |
232 | Standard_Integer len = 0; |
233 | |
234 | rewind(aFile_err); |
235 | while((len = read(fd_err,buf,clen*255)/clen) > 0) { |
236 | buf[len]='\0'; |
237 | if(shouldDUP()) { |
238 | (*thePCommands) << buf; |
239 | } else { |
240 | write(st_err,buf,clen*len); |
241 | } |
242 | } |
243 | close(fd_err); |
244 | |
245 | rewind(aFile_out); |
246 | buf[0] = '\0'; |
247 | len = 0; |
248 | while((len = read(fd_out,buf,clen*255)/clen) > 0) { |
249 | buf[len]='\0'; |
250 | if(shouldDUP()) { |
251 | (*thePCommands) << buf; |
252 | } else { |
253 | write(st_err,buf,clen*len); |
254 | } |
255 | } |
256 | close(fd_out); |
257 | |
258 | if(shouldDUP()) { |
259 | Standard_Character *Result = (Standard_Character *)thePCommands->Result(); |
260 | if(Result[0] != '\0') { |
261 | Standard_Integer pos = 0; |
262 | Standard_Integer rlen = strlen(Result); |
263 | while(pos < rlen) { |
264 | Standard_Integer nb = 256; |
265 | if((rlen - pos) <= 256) { |
266 | nb = rlen - pos; |
267 | } |
268 | write(st_err,Result+pos,nb*clen); |
269 | pos += nb; |
270 | } |
271 | write(st_err,"\n",clen); |
272 | should_be_printed = Standard_False ; |
273 | } |
274 | } //else { |
275 | if(nameo) |
276 | free(nameo); |
277 | if(namee) |
278 | free(namee); |
279 | return res; |
280 | } |
281 | |
282 | static Standard_Integer QARebuild (Draw_Interpretor& di, Standard_Integer /*n*/, const char ** a) |
283 | { |
284 | |
285 | Tcl_CmdInfo *infoPtr = new Tcl_CmdInfo; |
286 | |
287 | if(!strcmp(a[0],a[1])) |
288 | return 0; |
289 | |
290 | char* var_a = (char*)a[1]; |
291 | Standard_Integer res = Tcl_GetCommandInfo(di.Interp(),var_a,infoPtr); |
292 | if(res && (infoPtr->proc != &CommandCmd)) { |
293 | TCollection_AsciiString aName(var_a); |
294 | if (!stFuncMap.IsBound(aName)) { |
295 | stFuncMap.Bind(aName, (Standard_Address) infoPtr->proc); |
296 | |
297 | infoPtr->proc = &CommandCmd; |
298 | #if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 3 |
299 | infoPtr->isNativeObjectProc = 0; |
300 | infoPtr->objProc = NULL; |
301 | #endif |
302 | Tcl_SetCommandInfo(di.Interp(),var_a,infoPtr); |
303 | } |
304 | } |
305 | |
306 | return 0; |
307 | } |
308 | |
309 | static Standard_Integer QAUpdateLights(Draw_Interpretor& di, Standard_Integer argc, const char ** argv ) |
310 | { |
311 | if(argc != 1) { |
312 | di << "Usage : " << argv[0] << "\n"; |
313 | return -1; |
314 | } |
315 | |
316 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); |
317 | if(myAIScontext.IsNull()) { |
318 | di << "use 'vinit' command before " << argv[0] << "\n"; |
319 | return -1; |
320 | } |
321 | ViewerTest::CurrentView()->UpdateLights(); |
322 | ViewerTest::CurrentView()->Update(); |
323 | return 0; |
324 | } |
325 | |
326 | static Standard_Integer QAxwd_3d(Draw_Interpretor& di, Standard_Integer argc, const char** argv ) |
327 | { |
328 | if(argc != 2) { |
329 | di << "Usage : " << argv[0] << " filename" << "\n"; |
330 | return -1; |
331 | } |
332 | |
333 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); |
334 | if(myAIScontext.IsNull()) { |
335 | di << "use 'vinit' command before " << argv[0] << "\n"; |
336 | return -1; |
337 | } |
338 | Handle(V3d_View) myV3dView = ViewerTest::CurrentView(); |
339 | //cout << myV3dView->Dump(argv[1]) << endl; |
340 | myV3dView->Dump(argv[1]); |
341 | return 0; |
342 | } |
343 | |
344 | |
345 | static Standard_Integer QAMoveTo(Draw_Interpretor& di, Standard_Integer argc, const char ** argv ) |
346 | { |
347 | if(argc != 3) { |
348 | di << "Usage : " << argv[0] << " x y" << "\n"; |
349 | return -1; |
350 | } |
351 | |
352 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); |
353 | if(myAIScontext.IsNull()) { |
354 | di << "use 'vinit' command before " << argv[0] << "\n"; |
355 | return -1; |
356 | } |
357 | ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2])); |
358 | return 0; |
359 | } |
360 | |
361 | static Standard_Integer QASelect(Draw_Interpretor& di, Standard_Integer argc, const char ** argv ) |
362 | { |
363 | if(argc != 3) { |
364 | di << "Usage : " << argv[0] << " x y" << "\n"; |
365 | return -1; |
366 | } |
367 | |
368 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); |
369 | if(myAIScontext.IsNull()) { |
370 | di << "use 'vinit' command before " << argv[0] << "\n"; |
371 | return -1; |
372 | } |
373 | ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2])); |
374 | ViewerTest::CurrentEventManager()->Select(); |
375 | return 0; |
376 | } |
377 | |
378 | static Standard_Integer QAShiftSelect(Draw_Interpretor& di, Standard_Integer argc, const char ** argv ) |
379 | { |
380 | if(argc != 3) { |
381 | di << "Usage : " << argv[0] << " x y" << "\n"; |
382 | return -1; |
383 | } |
384 | |
385 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); |
386 | if(myAIScontext.IsNull()) { |
387 | di << "use 'vinit' command before " << argv[0] << "\n"; |
388 | return -1; |
389 | } |
390 | ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2])); |
391 | ViewerTest::CurrentEventManager()->ShiftSelect(); |
392 | return 0; |
393 | } |
394 | |
395 | static Standard_Integer QASetAntialiasing(Draw_Interpretor& di, Standard_Integer argc, const char ** argv ) |
396 | { |
397 | if(argc > 2) { |
398 | di << "Usage : " << argv[0] << " [1/0]" << "\n"; |
399 | return -1; |
400 | } |
401 | |
402 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); |
403 | if(myAIScontext.IsNull()) { |
404 | di << "use 'vinit' command before " << argv[0] << "\n"; |
405 | return -1; |
406 | } |
407 | |
408 | Handle(V3d_View) myV3dView = ViewerTest::CurrentView(); |
409 | |
410 | if((argc == 2) && (atof(argv[1]) == 0)) |
411 | myV3dView->SetAntialiasingOff(); |
412 | else |
413 | myV3dView->SetAntialiasingOn(); |
414 | myV3dView->Update(); |
415 | return 0; |
416 | } |
417 | |
418 | static Standard_Integer QAvzfit(Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv ) |
419 | { |
420 | Handle(V3d_View) V = ViewerTest::CurrentView(); |
421 | if ( V.IsNull() ) { |
422 | di << "use 'vinit' command before " << argv[0] << "\n"; |
423 | return -1; |
424 | } |
425 | V->ZFitAll(); |
426 | return 0; |
427 | } |
428 | |
429 | Handle(TColStd_HSequenceOfReal) GetColorOfPixel (const Handle(Aspect_PixMap) theImage, |
430 | const Standard_Integer theCoordinateX, |
431 | const Standard_Integer theCoordinateY, |
432 | const Standard_Integer theRadius) |
433 | { |
434 | Handle(TColStd_HSequenceOfReal) aSeq = new TColStd_HSequenceOfReal(); |
435 | if (theImage.IsNull()) { |
436 | std::cerr << "The image is null.\n"; |
437 | return aSeq; |
438 | } |
439 | Standard_Integer aWidth = 0; |
440 | Standard_Integer anHeight = 0; |
441 | theImage->Size (aWidth, anHeight); |
442 | |
443 | Quantity_Color aColorTmp; |
444 | for (Standard_Integer anXIter = theCoordinateX - theRadius; |
445 | anXIter <= theCoordinateX + theRadius; ++anXIter) |
446 | { |
447 | if (anXIter < 0 || anXIter >= aWidth) |
448 | { |
449 | continue; |
450 | } |
451 | for (Standard_Integer anYIter = theCoordinateY - theRadius; |
452 | anYIter <= theCoordinateY + theRadius; ++anYIter) |
453 | { |
454 | if (anYIter < 0 || anYIter >= anHeight) |
455 | { |
456 | continue; |
457 | } |
458 | // Image_PixMap stores image upside-down in memory! |
459 | aColorTmp = theImage->PixelColor (anXIter, anYIter); |
460 | aSeq->Append (aColorTmp.Red()); |
461 | aSeq->Append (aColorTmp.Green()); |
462 | aSeq->Append (aColorTmp.Blue()); |
463 | } |
464 | } |
465 | return aSeq; |
466 | } |
467 | |
468 | static Standard_Integer QAAISGetPixelColor (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
469 | { |
470 | if ( argc != 3 ) { |
471 | if ( argc != 6 ) { |
472 | di << "Usage : " << argv[0] << " coordinate_X coordinate_Y [color_R color_G color_B]" << "\n"; |
473 | return 1; |
474 | } |
475 | } |
476 | Handle (V3d_View) QAAISView = ViewerTest::CurrentView (); |
477 | if ( QAAISView.IsNull () ) { |
478 | di << "You must initialize AISViewer before this command." << "\n"; |
479 | return 1; |
480 | } |
481 | Handle (Aspect_Window) QAAISWindow = QAAISView->Window (); |
482 | Standard_Integer QAAISXWindowSize_X = 0; |
483 | Standard_Integer QAAISXWindowSize_Y = 0; |
484 | QAAISWindow->Size(QAAISXWindowSize_X, QAAISXWindowSize_Y); |
485 | Standard_ShortReal QAAISCoordinateX = atoi (argv [1]); |
486 | Standard_ShortReal QAAISCoordinateY = atoi (argv [2]); |
487 | |
488 | Standard_ShortReal QAAISColorRED_V = 0; |
489 | Standard_ShortReal QAAISColorGRN_V = 0; |
490 | Standard_ShortReal QAAISColorBLU_V = 0; |
491 | |
492 | if ( argc == 6 ) { |
493 | QAAISColorRED_V = atof (argv [3]); |
494 | QAAISColorGRN_V = atof (argv [4]); |
495 | QAAISColorBLU_V = atof (argv [5]); |
496 | |
497 | di << "Begin aColorRED_User = " << QAAISColorRED_V << "\n"; |
498 | di << "Begin aColorGRN_User = " << QAAISColorRED_V << "\n"; |
499 | di << "Begin aColorBLU_User = " << QAAISColorRED_V << "\n"; |
500 | } |
501 | |
502 | Standard_Integer aRadius = 1; |
503 | if ( argc == 3 ) { |
504 | aRadius=0; |
505 | } |
506 | |
507 | Handle(TColStd_HSequenceOfReal) aSeq = GetColorOfPixel (QAAISView->ToPixMap (QAAISXWindowSize_X, QAAISXWindowSize_Y, Image_TOI_RGB), |
508 | QAAISCoordinateX, QAAISCoordinateY, |
509 | aRadius); |
510 | cout << "Length = " << aSeq->Length() << endl; |
511 | |
512 | Standard_Boolean IsNotEqual = Standard_True; |
513 | Standard_Integer i; |
514 | for(i=1; i<=aSeq->Length();i+=3) { |
515 | // mkv 29.04.03 |
516 | Standard_ShortReal QAAISColorRED_R = (((Standard_ShortReal) ((Standard_Integer) (aSeq->Value(i+0) * 1000000))) / 1000000.); |
517 | Standard_ShortReal QAAISColorGRN_R = (((Standard_ShortReal) ((Standard_Integer) (aSeq->Value(i+1) * 1000000))) / 1000000.); |
518 | Standard_ShortReal QAAISColorBLU_R = (((Standard_ShortReal) ((Standard_Integer) (aSeq->Value(i+2) * 1000000))) / 1000000.); |
519 | // mkv 29.04.03 |
520 | |
521 | if ( argc == 3 ) { |
522 | di << "RED : " << QAAISColorRED_R |
523 | << " GREEN : " << QAAISColorGRN_R |
524 | << " BLUE : " << QAAISColorBLU_R |
525 | << "\n"; |
526 | IsNotEqual = Standard_False; |
527 | break; |
528 | } |
529 | |
530 | if ( QAAISColorRED_R == QAAISColorRED_V |
531 | && QAAISColorGRN_R == QAAISColorGRN_V |
532 | && QAAISColorBLU_R == QAAISColorBLU_V |
533 | ) { |
534 | IsNotEqual = Standard_False; |
535 | break; |
536 | } |
537 | } |
538 | if (IsNotEqual) { |
539 | di << "Faulty : colors are not equal." << "\n"; |
540 | return 1; |
541 | } |
542 | return 0; |
543 | } |
544 | |
545 | static Standard_Boolean IsSelectionModeCurrentlyON (Standard_Integer theMode) { |
546 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
547 | if(!aContext->HasOpenedContext()) { |
548 | return Standard_False ; |
549 | } |
550 | const TColStd_ListOfInteger& List = aContext->ActivatedStandardModes(); |
551 | TColStd_ListIteratorOfListOfInteger it; |
552 | Standard_Boolean Found=Standard_False; |
553 | for (it.Initialize(List); it.More()&&!Found; it.Next() ) { |
554 | if (it.Value()==theMode ) Found=Standard_True; |
555 | } |
556 | return Found; |
557 | } |
558 | |
559 | static Standard_Integer QAAISSetChoiceMode (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
560 | { |
561 | if ( argc != 3 ) { |
562 | di << "Usage : " << argv[0] << " mode switch" << "\n"; |
563 | di << " mode: " << "\n"; |
564 | // cout << " SHAPE " << endl; |
565 | di << " VERTEX " << "\n"; |
566 | di << " EDGE " << "\n"; |
567 | di << " WIRE " << "\n"; |
568 | di << " FACE " << "\n"; |
569 | di << " SHELL " << "\n"; |
570 | di << " SOLID " << "\n"; |
571 | di << " COMPOUND " << "\n"; |
572 | di << " switch: " << "\n"; |
573 | di << " ON " << "\n"; |
574 | di << " OFF " << "\n"; |
575 | return 1; |
576 | } |
577 | Handle (V3d_View) QAAISView = ViewerTest::CurrentView (); |
578 | if ( QAAISView.IsNull () ) { |
579 | di << "You must initialize AISViewer before this command." << "\n"; |
580 | return 1; |
581 | } |
582 | Standard_Integer QAChoosingMode = -1; |
583 | // if ( strcmp (sc [1], "SHAPE") == 0 ) { |
584 | // QAChoosingMode = 0; |
585 | // } |
586 | if ( strcmp (argv [1], "VERTEX") == 0 ) { |
587 | QAChoosingMode = 1; |
588 | } |
589 | if ( strcmp (argv [1], "EDGE") == 0 ) { |
590 | QAChoosingMode = 2; |
591 | } |
592 | if ( strcmp (argv [1], "WIRE") == 0 ) { |
593 | QAChoosingMode = 3; |
594 | } |
595 | if ( strcmp (argv [1], "FACE") == 0 ) { |
596 | QAChoosingMode = 4; |
597 | } |
598 | if ( strcmp (argv [1], "SHELL") == 0 ) { |
599 | QAChoosingMode = 5; |
600 | } |
601 | if ( strcmp (argv [1], "SOLID") == 0 ) { |
602 | QAChoosingMode = 6; |
603 | } |
604 | if ( strcmp (argv [1], "COMPOUND") == 0 ) { |
605 | QAChoosingMode = 7; |
606 | } |
607 | if ( QAChoosingMode == -1 ) { |
608 | di << "Use - QAAISSetChoiceMode mode switch" << "\n"; |
609 | return 1; |
610 | } |
611 | |
612 | if ( strcmp (argv [2], "ON") == 0 ) { |
613 | if ( IsSelectionModeCurrentlyON (QAChoosingMode)) { |
614 | di << "Mode already ON." << "\n"; |
615 | return 1; |
616 | } |
617 | ViewerTest::StandardModeActivation (QAChoosingMode); |
618 | return 0; |
619 | } |
620 | if ( strcmp (argv [2], "OFF") == 0 ) { |
621 | if (!IsSelectionModeCurrentlyON (QAChoosingMode)) { |
622 | di << "Mode already OFF." << "\n"; |
623 | return 1; |
624 | } |
625 | ViewerTest::StandardModeActivation (QAChoosingMode); |
626 | return 0; |
627 | } |
628 | di << "Usage : " << argv[0] << " mode switch" << "\n"; |
629 | return 1; |
630 | } |
631 | |
632 | #if ! defined(WNT) |
633 | extern int ViewerMainLoop (Standard_Integer argc, const char ** argv); |
634 | #else |
635 | Standard_EXPORT int ViewerMainLoop (Standard_Integer argc, const char ** argv); |
636 | #endif |
637 | #if ! defined(WNT) |
638 | extern int ViewerMainLoop2d (Standard_Integer argc, const char ** argv); |
639 | #else |
640 | Standard_EXPORT int ViewerMainLoop2d (Standard_Integer argc, const char ** argv); |
641 | #endif |
642 | |
643 | static Standard_Integer QAAISGetMousePoint (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
644 | { |
645 | if ( argc != 1 ) { |
646 | di << "Usage : " << argv[0] << "\n"; |
647 | return 1; |
648 | } |
649 | Handle (V3d_View) QAAISView = ViewerTest::CurrentView (); |
650 | if ( QAAISView.IsNull () ) { |
651 | di << "You must initialize AISViewer before this command." << "\n"; |
652 | return 1; |
653 | } |
654 | Standard_Integer QAAISMouseCoordinateX = 0; |
655 | Standard_Integer QAAISMouseCoordinateY = 0; |
656 | Standard_Integer argccc = 5; |
657 | const char *bufff[] = { "A", "B", "C", "D", "E" }; |
658 | const char **argvvv = (const char **) bufff; |
659 | while ( ViewerMainLoop (argccc, argvvv) ) { |
660 | ViewerTest::GetMousePosition (QAAISMouseCoordinateX, QAAISMouseCoordinateY); |
661 | } |
662 | ViewerTest::GetMousePosition (QAAISMouseCoordinateX, QAAISMouseCoordinateY); |
663 | di << "X-coordinate: " << QAAISMouseCoordinateX << "; Y-coordinate: " << QAAISMouseCoordinateY << "\n"; |
664 | return 0; |
665 | } |
666 | |
667 | static Standard_Integer QAAISGetViewCharac (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
668 | { |
669 | if ( argc != 1 ) { |
670 | di << "Usage : " << argv[0] << "\n"; |
671 | return 1; |
672 | } |
673 | Handle (V3d_View) QAAISView = ViewerTest::CurrentView (); |
674 | if ( QAAISView.IsNull () ) { |
675 | di << "You must initialize AISViewer before this command." << "\n"; |
676 | return 1; |
677 | } |
678 | Quantity_Factor QAAISViewScale = QAAISView -> V3d_View::Scale (); |
679 | Standard_Real QAAISViewCenterCoordinateX = 0.0; |
680 | Standard_Real QAAISViewCenterCoordinateY = 0.0; |
681 | QAAISView -> V3d_View::Center (QAAISViewCenterCoordinateX, QAAISViewCenterCoordinateY); |
682 | Standard_Real QAAISViewProjX = 0.0; |
683 | Standard_Real QAAISViewProjY = 0.0; |
684 | Standard_Real QAAISViewProjZ = 0.0; |
685 | QAAISView -> V3d_View::Proj (QAAISViewProjX, QAAISViewProjY, QAAISViewProjZ); |
686 | Standard_Real QAAISViewUpX = 0.0; |
687 | Standard_Real QAAISViewUpY = 0.0; |
688 | Standard_Real QAAISViewUpZ = 0.0; |
689 | QAAISView -> V3d_View::Up (QAAISViewUpX, QAAISViewUpY, QAAISViewUpZ); |
690 | Standard_Real QAAISViewAtX = 0.0; |
691 | Standard_Real QAAISViewAtY = 0.0; |
692 | Standard_Real QAAISViewAtZ = 0.0; |
693 | QAAISView -> V3d_View::At (QAAISViewAtX, QAAISViewAtY, QAAISViewAtZ); |
694 | di << "Scale of current view: " << QAAISViewScale << "\n"; |
695 | di << "Center on X : "<< QAAISViewCenterCoordinateX << "; on Y: " << QAAISViewCenterCoordinateY << "\n"; |
696 | di << "Proj on X : " << QAAISViewProjX << "; on Y: " << QAAISViewProjY << "; on Z: " << QAAISViewProjZ << "\n"; |
697 | di << "Up on X : " << QAAISViewUpX << "; on Y: " << QAAISViewUpY << "; on Z: " << QAAISViewUpZ << "\n"; |
698 | di << "At on X : " << QAAISViewAtX << "; on Y: " << QAAISViewAtY << "; on Z: " << QAAISViewAtZ << "\n"; |
699 | } |
700 | |
701 | static Standard_Integer QAAISSetViewCharac (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
702 | { |
703 | if ( argc != 13 ) { |
704 | di << "Usage : " << argv[0] << " scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z" << "\n"; |
705 | return 1; |
706 | } |
707 | Handle (V3d_View) QAAISView = ViewerTest::CurrentView (); |
708 | if ( QAAISView.IsNull () ) { |
709 | di << "You must initialize AISViewer before this command." << "\n"; |
710 | return 1; |
711 | } |
712 | Quantity_Factor QAAISViewScale = atof (argv [1]); |
713 | Standard_Real QAAISViewCenterCoordinateX = atof (argv [2]); |
714 | Standard_Real QAAISViewCenterCoordinateY = atof (argv [3]); |
715 | Standard_Real QAAISViewProjX = atof (argv [4]); |
716 | Standard_Real QAAISViewProjY = atof (argv [5]); |
717 | Standard_Real QAAISViewProjZ = atof (argv [6]); |
718 | Standard_Real QAAISViewUpX = atof (argv [7]); |
719 | Standard_Real QAAISViewUpY = atof (argv [8]); |
720 | Standard_Real QAAISViewUpZ = atof (argv [9]); |
721 | Standard_Real QAAISViewAtX = atof (argv [10]); |
722 | Standard_Real QAAISViewAtY = atof (argv [11]); |
723 | Standard_Real QAAISViewAtZ = atof (argv [12]); |
724 | QAAISView -> V3d_View::SetScale (QAAISViewScale); |
725 | QAAISView -> V3d_View::SetCenter (QAAISViewCenterCoordinateX, QAAISViewCenterCoordinateY); |
726 | QAAISView -> V3d_View::SetAt (QAAISViewAtX, QAAISViewAtY, QAAISViewAtZ); |
727 | QAAISView -> V3d_View::SetProj (QAAISViewProjX, QAAISViewProjY, QAAISViewProjZ); |
728 | QAAISView -> V3d_View::SetUp (QAAISViewUpX, QAAISViewUpY, QAAISViewUpZ); |
729 | QAAISView -> V3d_View::SetProj (QAAISViewProjX, QAAISViewProjY, QAAISViewProjZ); |
730 | return 0; |
731 | } |
732 | |
733 | static Standard_Integer QAAISGetColorCoord (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
734 | { |
735 | #if ! defined(WNT) |
736 | if ( argc > 2 ) { |
737 | di << "Usage : " << argv[0] << " [3d|2d]" << "\n"; |
738 | return 1; |
739 | } |
740 | Handle (Aspect_Window) QAAISWindow; |
741 | |
742 | Standard_Boolean is3d = 1; |
743 | |
744 | if(argc == 1 || !strcmp(argv[1],"3d")) { |
745 | |
746 | Handle (V3d_View) QAAIS_MainView = ViewerTest::CurrentView (); |
747 | if ( QAAIS_MainView.IsNull () ) { |
748 | di << "You must initialize AISViewer before this command." << "\n"; |
749 | return 1; |
750 | } |
751 | QAAISWindow = QAAIS_MainView -> V3d_View::Window (); |
752 | is3d = 1; |
753 | } |
754 | |
755 | if(argc == 2 && !strcmp(argv[1],"2d")) { |
756 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
757 | if (V.IsNull()) { |
758 | di << "You must initialize AIS 2D Viewer before this command." << "\n"; |
759 | return 1; |
760 | } |
761 | QAAISWindow = V->Driver()->Window(); |
762 | is3d = 0; |
763 | } |
764 | |
765 | Standard_Integer QAAIS_WindowSize_X = 0; |
766 | Standard_Integer QAAIS_WindowSize_Y = 0; |
767 | QAAISWindow->Size(QAAIS_WindowSize_X, QAAIS_WindowSize_Y); |
768 | Handle (Graphic3d_GraphicDevice) QAAIS_GraphicDevice = new Graphic3d_GraphicDevice (getenv ("DISPLAY")); |
769 | |
770 | Draw_Window QAAIS_CoordWindow ("coordinate", 421, 205, 200, 60); |
771 | QAAIS_CoordWindow.DisplayWindow (); |
772 | QAAIS_CoordWindow.SetColor (12); |
773 | |
774 | Handle (Xw_Window) QAAIS_ColorWindow = new Xw_Window (QAAIS_GraphicDevice, "color", 0.4074, 0.678, 0.1962, 0.06, Xw_WQ_3DQUALITY, Quantity_NOC_BLACK); |
775 | Handle (V3d_Viewer) QAAIS_ColorViewer = new V3d_Viewer (QAAIS_GraphicDevice, Standard_ExtString ("COLOR")); |
776 | Handle (V3d_View) QAAIS_ColorView = QAAIS_ColorViewer -> CreateView (); |
777 | QAAIS_ColorWindow -> Map (); |
778 | QAAIS_ColorView -> SetWindow (QAAIS_ColorWindow); |
779 | QAAIS_ColorView -> SetBackgroundColor (Quantity_NOC_BLACK); |
780 | QAAIS_ColorView -> Redraw (); |
781 | |
782 | Standard_Integer QAAIS_MousePoint_X = 0; |
783 | Standard_Integer QAAIS_MousePoint_Y = 0; |
784 | Standard_Character QAAIS_MousePointX[32]; |
785 | sprintf (QAAIS_MousePointX, "X : %d", QAAIS_MousePoint_X); |
786 | Standard_Character QAAIS_MousePointY[32]; |
787 | sprintf (QAAIS_MousePointY, "Y : %d", QAAIS_MousePoint_Y); |
788 | Standard_ShortReal QAAIS_ColorRED = 0; |
789 | Standard_ShortReal QAAIS_ColorGRN = 0; |
790 | Standard_ShortReal QAAIS_ColorBLU = 0; |
791 | Quantity_Color QAAIS_ShowingColor; |
792 | QAAIS_ShowingColor.SetValues (QAAIS_ColorRED, QAAIS_ColorGRN, QAAIS_ColorBLU, Quantity_TOC_RGB); |
793 | Standard_Integer argccc = 5; |
794 | const char *bufff[] = { "A", "B", "C", "D", "E" }; |
795 | const char **argvvv = (const char **) bufff; |
796 | while ( is3d ? ViewerMainLoop (argccc, argvvv) : ViewerMainLoop2d (argccc, argvvv)) { |
797 | Handle(TColStd_HSequenceOfReal) aSeq; |
798 | if(is3d) |
799 | { |
800 | ViewerTest::GetMousePosition (QAAIS_MousePoint_X, QAAIS_MousePoint_Y); |
801 | Handle (V3d_View) QAAIS_MainView = ViewerTest::CurrentView(); |
802 | aSeq = GetColorOfPixel (QAAIS_MainView->ToPixMap (QAAIS_WindowSize_X, QAAIS_WindowSize_Y, Image_TOI_RGB), |
803 | QAAIS_MousePoint_X, QAAIS_MousePoint_Y, 0); |
804 | } |
805 | else |
806 | { |
807 | Viewer2dTest::GetMousePosition (QAAIS_MousePoint_X, QAAIS_MousePoint_Y); |
808 | aSeq = GetColorOfPixel (QAAISWindow->ToPixMap(), |
809 | QAAIS_MousePoint_X, QAAIS_MousePoint_Y, 0); |
810 | } |
811 | QAAIS_ColorRED = aSeq->Value(1); |
812 | QAAIS_ColorGRN = aSeq->Value(2); |
813 | QAAIS_ColorBLU = aSeq->Value(3); |
814 | QAAIS_ShowingColor.SetValues (QAAIS_ColorRED, QAAIS_ColorGRN, QAAIS_ColorBLU, Quantity_TOC_RGB); |
815 | QAAIS_ColorView -> SetBackgroundColor (QAAIS_ShowingColor); |
816 | QAAIS_ColorView -> Redraw (); |
817 | QAAIS_CoordWindow.Clear(); |
818 | sprintf (QAAIS_MousePointX, "X : %d", QAAIS_MousePoint_X); |
819 | sprintf (QAAIS_MousePointY, "Y : %d", QAAIS_MousePoint_Y); |
820 | QAAIS_CoordWindow.DrawString (30, 35, QAAIS_MousePointX); |
821 | QAAIS_CoordWindow.DrawString (125, 35, QAAIS_MousePointY); |
822 | } |
823 | QAAIS_CoordWindow.Destroy (); |
824 | #endif //WNT |
825 | return 0; |
826 | } |
827 | |
828 | //============================================================================== |
829 | // VIEWER GLOBALs |
830 | //============================================================================== |
831 | #if ! defined(WNT) |
832 | extern int V2dPickGrid (Draw_Interpretor& , Standard_Integer argc, const char ** argv); |
833 | #else |
834 | Standard_EXPORT int V2dPickGrid (Draw_Interpretor& , Standard_Integer argc, const char ** argv); |
835 | #endif |
836 | //============================================================================== |
837 | //function : V2dSetHighlightMode |
838 | //purpose : QAv2dSetHighlightMode mode |
839 | //============================================================================== |
840 | static int V2dSetHighlightMode (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
841 | { |
842 | if (argc != 2) |
843 | { |
844 | di << "Usage: QAv2dSetHighlightMode mode" << "\n"; |
845 | return 1; |
846 | } |
847 | |
848 | Viewer2dTest::StandardModeActivation(atoi(argv[1])); |
849 | return 0; |
850 | } |
851 | |
852 | #ifndef WNT |
853 | //============================================================================== |
854 | //function : QAAISGetPixelColor2d |
855 | //purpose : QAAISGetPixelColor2d coord_X coord_Y Red Green Blue |
856 | //============================================================================== |
857 | |
858 | static int QAAISGetPixelColor2d (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
859 | { |
860 | if (argc != 6 && argc != 3) |
861 | { |
862 | di << "Args: coord_X coord_Y [Red Green Blue]" << "\n"; |
863 | return 1; |
864 | } |
865 | |
866 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
867 | if (V.IsNull()) |
868 | { |
869 | di << "You must initialize AIS 2D Viewer before this command." << "\n"; |
870 | return 1; |
871 | } |
872 | // Get Color |
873 | Handle(Aspect_Window) QAAISWindow = V->Driver()->Window(); |
874 | |
875 | Standard_ShortReal aCoordinateX = atoi(argv[1]); |
876 | Standard_ShortReal aCoordinateY = atoi(argv[2]); |
877 | |
878 | // Get Color |
879 | Standard_ShortReal aColorRED_V = 0; |
880 | Standard_ShortReal aColorGRN_V = 0; |
881 | Standard_ShortReal aColorBLU_V = 0; |
882 | |
883 | if ( argc == 6 ) { |
884 | aColorRED_V = atof (argv [3]); |
885 | aColorGRN_V = atof (argv [4]); |
886 | aColorBLU_V = atof (argv [5]); |
887 | |
888 | di << "Begin aColorRED_User = " << aColorRED_V << "\n"; |
889 | di << "Begin aColorGRN_User = " << aColorGRN_V << "\n"; |
890 | di << "Begin aColorBLU_User = " << aColorBLU_V << "\n"; |
891 | } |
892 | |
893 | Standard_Integer aRadius = 1; |
894 | if ( argc == 3 ) { |
895 | aRadius=0; |
896 | } |
897 | |
898 | Handle(TColStd_HSequenceOfReal) aSeq = GetColorOfPixel (QAAISWindow->ToPixMap(), |
899 | aCoordinateX, aCoordinateY, |
900 | aRadius); |
901 | |
902 | Standard_Boolean IsNotEqual = Standard_True; |
903 | Standard_Integer i; |
904 | for(i=1; i<=aSeq->Length();i+=3) { |
905 | // mkv 29.04.03 |
906 | Standard_ShortReal aColorRED_R = (((Standard_ShortReal) ((Standard_Integer) (aSeq->Value(i+0) * 1000000))) / 1000000.); |
907 | Standard_ShortReal aColorGRN_R = (((Standard_ShortReal) ((Standard_Integer) (aSeq->Value(i+1) * 1000000))) / 1000000.); |
908 | Standard_ShortReal aColorBLU_R = (((Standard_ShortReal) ((Standard_Integer) (aSeq->Value(i+2) * 1000000))) / 1000000.); |
909 | // mkv 29.04.03 |
910 | |
911 | if ( argc == 3 ) { |
912 | di << "RED : " << aColorRED_R << " GREEN : " << aColorGRN_R << " BLUE : " << aColorBLU_R << "\n"; |
913 | IsNotEqual = Standard_False; |
914 | break; |
915 | } |
916 | |
917 | if ( aColorRED_R == aColorRED_V |
918 | && aColorGRN_R == aColorGRN_V |
919 | && aColorBLU_R == aColorBLU_V |
920 | ) { |
921 | IsNotEqual = Standard_False; |
922 | break; |
923 | } |
924 | } |
925 | if (IsNotEqual) { |
926 | di << "Faulty : colors are not equal." << "\n"; |
927 | return 1; |
928 | } |
929 | return 0; |
930 | } |
931 | #endif // !WNT |
932 | |
933 | //============================================================================== |
934 | //function : QAMoveTo2d |
935 | //purpose : QAMoveTo2d x y |
936 | //============================================================================== |
937 | static int QAMoveTo2d (Draw_Interpretor& di, int argc, const char ** argv) |
938 | { |
939 | if (argc != 3) |
940 | { |
941 | di << "Usage : " << argv[0] << " x y" << "\n"; |
942 | return -1; |
943 | } |
944 | |
945 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
946 | if (myAIScontext.IsNull()) |
947 | { |
948 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
949 | return -1; |
950 | } |
951 | Viewer2dTest::CurrentEventManager()->MoveTo |
952 | (atoi(argv[1]), atoi(argv[2]), Viewer2dTest::CurrentView()); |
953 | return 0; |
954 | } |
955 | |
956 | //============================================================================== |
957 | //function : QASelect2d |
958 | //purpose : QASelect2d x y |
959 | //============================================================================== |
960 | static int QASelect2d (Draw_Interpretor& di, int argc, const char ** argv) |
961 | { |
962 | if (argc != 3) |
963 | { |
964 | di << "Usage : " << argv[0] << " x y" << "\n"; |
965 | return -1; |
966 | } |
967 | |
968 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
969 | if (myAIScontext.IsNull()) |
970 | { |
971 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
972 | return -1; |
973 | } |
974 | Viewer2dTest::CurrentEventManager()->MoveTo |
975 | (atoi(argv[1]), atoi(argv[2]), Viewer2dTest::CurrentView()); |
976 | Viewer2dTest::CurrentEventManager()->Select(); |
977 | return 0; |
978 | } |
979 | |
980 | //============================================================================== |
981 | //function : QAShiftSelect2d |
982 | //purpose : QAShiftSelect2d x y |
983 | //============================================================================== |
984 | static int QAShiftSelect2d (Draw_Interpretor& di, int argc, const char ** argv) |
985 | { |
986 | if (argc != 3) |
987 | { |
988 | di << "Usage : " << argv[0] << " x y" << "\n"; |
989 | return -1; |
990 | } |
991 | |
992 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
993 | if (myAIScontext.IsNull()) |
994 | { |
995 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
996 | return -1; |
997 | } |
998 | Viewer2dTest::CurrentEventManager()->MoveTo |
999 | (atoi(argv[1]), atoi(argv[2]), Viewer2dTest::CurrentView()); |
1000 | Viewer2dTest::CurrentEventManager()->ShiftSelect(); |
1001 | return 0; |
1002 | } |
1003 | |
1004 | //============================================================================== |
1005 | //function : V2dZoom |
1006 | //purpose : QAv2dzoom zoom_factor |
1007 | //============================================================================== |
1008 | static int V2dZoom (Draw_Interpretor& di, int argc, const char ** argv) |
1009 | { |
1010 | if (argc != 2) |
1011 | { |
1012 | di << "Usage : " << argv[0] << " zoom_factor" << "\n"; |
1013 | return -1; |
1014 | } |
1015 | |
1016 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
1017 | if (myAIScontext.IsNull()) |
1018 | { |
1019 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
1020 | return -1; |
1021 | } |
1022 | Viewer2dTest::CurrentView()->Zoom(atof(argv[1])); |
1023 | return 0; |
1024 | } |
1025 | |
1026 | //============================================================================== |
1027 | //function : V2dPan |
1028 | //purpose : QAv2dpan dx dy |
1029 | //============================================================================== |
1030 | static int V2dPan (Draw_Interpretor& di, int argc, const char ** argv) |
1031 | { |
1032 | if (argc != 3) |
1033 | { |
1034 | di << "Usage : " << argv[0] << " dx dy" << "\n"; |
1035 | return -1; |
1036 | } |
1037 | |
1038 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
1039 | if (myAIScontext.IsNull()) |
1040 | { |
1041 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
1042 | return -1; |
1043 | } |
1044 | Viewer2dTest::CurrentView()->Pan(atof(argv[1]), atof(argv[2])); |
1045 | return 0; |
1046 | } |
1047 | |
1048 | //============================================================================== |
1049 | //function : V2dGetViewCharac |
1050 | //purpose : v2dGetViewCharac |
1051 | //============================================================================== |
1052 | static int V2dGetViewCharac (Draw_Interpretor& di, int si, const char ** /*sc*/) |
1053 | { |
1054 | if (si != 1) |
1055 | { |
1056 | di << "Use - v2dGetViewCharac" << "\n"; |
1057 | return 1; |
1058 | } |
1059 | |
1060 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
1061 | if (V.IsNull()) |
1062 | { |
1063 | di << "You must initialize AIS 2D Viewer before this command." << "\n"; |
1064 | return 1; |
1065 | } |
1066 | |
1067 | // Quantity_Factor aViewScale = V->Scale(); |
1068 | |
1069 | Standard_Real aCenterCoordX = 0.0; |
1070 | Standard_Real aCenterCoordY = 0.0; |
1071 | V->Center(aCenterCoordX, aCenterCoordY); |
1072 | |
1073 | Standard_Real aViewProjX = 0.0; |
1074 | Standard_Real aViewProjY = 0.0; |
1075 | Standard_Real aViewProjZ = 0.0; |
1076 | // V->Proj(aViewProjX, aViewProjY, aViewProjZ); |
1077 | |
1078 | Standard_Real aViewUpX = 0.0; |
1079 | Standard_Real aViewUpY = 0.0; |
1080 | Standard_Real aViewUpZ = 0.0; |
1081 | // V->Up(aViewUpX, aViewUpY, aViewUpZ); |
1082 | |
1083 | Standard_Real aViewAtX = 0.0; |
1084 | Standard_Real aViewAtY = 0.0; |
1085 | Standard_Real aViewAtZ = 0.0; |
1086 | // V->At(aViewAtX, aViewAtY, aViewAtZ); |
1087 | |
1088 | // cout << "Scale of current view: " << aViewScale << endl; |
1089 | // cout << "Center on X : "<< aViewCenterCoordX << "; on Y: " << aViewCenterCoordY << endl; |
1090 | // cout << "Proj on X : " << aViewProjX << "; on Y: " << aViewProjY << "; on Z: " << aViewProjZ << endl; |
1091 | // cout << "Up on X : " << aViewUpX << "; on Y: " << aViewUpY << "; on Z: " << aViewUpZ << endl; |
1092 | // cout << "At on X : " << aViewAtX << "; on Y: " << aViewAtY << "; on Z: " << aViewAtZ << endl; |
1093 | |
1094 | // cout << aViewScale << " " << aViewCenterCoordX << " " << aViewCenterCoordY << " "; |
1095 | di << aViewProjX << " " << aViewProjY << " " << aViewProjZ << " "; |
1096 | di << aViewUpX << " " << aViewUpY << " " << aViewUpZ << " "; |
1097 | di << aViewAtX << " " << aViewAtY << " " << aViewAtZ << "\n"; |
1098 | return 0; |
1099 | } |
1100 | |
1101 | //============================================================================== |
1102 | //function : V2dSetViewCharac |
1103 | //purpose : v2dSetViewCharac |
1104 | //============================================================================== |
1105 | static int V2dSetViewCharac (Draw_Interpretor& di, int si, const char ** sc) |
1106 | { |
1107 | if (si != 13) |
1108 | { |
1109 | di << "Use - v2dSetViewCharac scale center(X Y) proj(X Y Z) up(X Y Z) at(X Y Z)" << "\n"; |
1110 | return 1; |
1111 | } |
1112 | |
1113 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
1114 | if (V.IsNull()) |
1115 | { |
1116 | di << "You must initialize AIS 2D Viewer before this command." << "\n"; |
1117 | return 1; |
1118 | } |
1119 | |
1120 | Quantity_Factor aViewScale = atof(sc[1]); |
1121 | |
1122 | Standard_Real aViewCenterCoordX = atof(sc[2]); |
1123 | Standard_Real aViewCenterCoordY = atof(sc[3]); |
1124 | |
1125 | Standard_Real aViewProjX = atof(sc[4]); |
1126 | Standard_Real aViewProjY = atof(sc[5]); |
1127 | Standard_Real aViewProjZ = atof(sc[6]); |
1128 | |
1129 | Standard_Real aViewUpX = atof(sc[7]); |
1130 | Standard_Real aViewUpY = atof(sc[8]); |
1131 | Standard_Real aViewUpZ = atof(sc[9]); |
1132 | |
1133 | Standard_Real aViewAtX = atof(sc[10]); |
1134 | Standard_Real aViewAtY = atof(sc[11]); |
1135 | Standard_Real aViewAtZ = atof(sc[12]); |
1136 | |
1137 | // V->SetScale(aViewScale); |
1138 | // V->SetCenter(aViewCenterCoordX, aViewCenterCoordY); |
1139 | // V->SetAt(aViewAtX, aViewAtY, aViewAtZ); |
1140 | // V->SetProj(aViewProjX, aViewProjY, aViewProjZ); |
1141 | // V->SetUp(aViewUpX, aViewUpY, aViewUpZ); |
1142 | // V->SetProj(aViewProjX, aViewProjY, aViewProjZ); |
1143 | return 0; |
1144 | } |
1145 | |
1146 | //======================================================================= |
1147 | //function : QAxwd_2d |
1148 | //purpose : |
1149 | //======================================================================= |
1150 | static int QAxwd_2d (Draw_Interpretor& di, int argc, const char ** argv) |
1151 | { |
1152 | if (argc != 2) |
1153 | { |
1154 | di << "Usage : " << argv[0] << " filename" << "\n"; |
1155 | return -1; |
1156 | } |
1157 | |
1158 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
1159 | if (myAIScontext.IsNull()) |
1160 | { |
1161 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
1162 | return -1; |
1163 | } |
1164 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
1165 | V->Dump(argv[1]); |
1166 | return 0; |
1167 | } |
1168 | |
1169 | #ifndef WNT |
1170 | extern Draw_Viewer dout; |
1171 | extern XW_STATUS Xw_save_image_adv (Display *aDisplay,Window aWindow,XWindowAttributes aWinAttr,XImage *aPximage,Colormap aColormap,int aNcolors,char *filename); |
1172 | extern Display* Draw_WindowDisplay; |
1173 | extern Colormap Draw_WindowColorMap; |
1174 | #else |
1175 | Standard_IMPORT Draw_Viewer dout; |
1176 | int __WNT_API SaveWindowToFile (Handle( WNT_GraphicDevice )& gDev, |
1177 | HWND hWnd, char* fName, int x, int y, int w, int h); |
1178 | #endif |
1179 | |
1180 | //======================================================================= |
1181 | //function : QAxwd |
1182 | //purpose : |
1183 | //======================================================================= |
1184 | static int QAxwd (Draw_Interpretor& di, int argc, const char ** argv) |
1185 | { |
1186 | if (argc < 2) |
1187 | { |
1188 | di << "Usage : " << argv[0] << " [id=1] filename" << "\n"; |
1189 | return -1; |
1190 | } |
1191 | |
1192 | // enforce repaint if necessary |
1193 | Standard_Integer id = 1; |
1194 | const char* file = argv[1]; |
1195 | if (argc > 2) { |
1196 | id = atoi(argv[1]); |
1197 | file = argv[2]; |
1198 | } |
1199 | |
1200 | after(id); |
1201 | |
1202 | dout.Flush(); |
1203 | if(dout.HasView(id)) { |
1204 | #if defined (WNT) |
1205 | Handle(WNT_GraphicDevice) aGd = new WNT_GraphicDevice(Standard_False); |
1206 | RECT rc; |
1207 | GetClientRect((HWND)dout.GetWindow(id), &rc); |
1208 | SaveWindowToFile(aGd,(HWND)dout.GetWindow(id),(char*)file,rc.left, rc.top,rc.right-rc.left, rc.bottom-rc.top); |
1209 | #else |
1210 | XSync(Draw_WindowDisplay,True); |
1211 | |
1212 | XWindowAttributes winAttr; |
1213 | XGetWindowAttributes (Draw_WindowDisplay, dout.GetWindow(id), &winAttr); |
1214 | |
1215 | XImage *pximage = XGetImage(Draw_WindowDisplay,dout.GetWindow(id), |
1216 | 0,0,winAttr.width,winAttr.height, |
1217 | AllPlanes,ZPixmap); |
1218 | |
1219 | Xw_save_image_adv(Draw_WindowDisplay,dout.GetWindow(id),winAttr,pximage,Draw_WindowColorMap,256,(char*)file); |
1220 | #endif |
1221 | } |
1222 | |
1223 | return 0; |
1224 | } |
1225 | |
1226 | //======================================================================= |
1227 | //function : QA2dGetIndexes |
1228 | //purpose : |
1229 | //======================================================================= |
1230 | static int QA2dGetIndexes (Draw_Interpretor& di, int /*argc*/, const char ** argv) |
1231 | { |
1232 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
1233 | if (myAIScontext.IsNull()) |
1234 | { |
1235 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
1236 | return -1; |
1237 | } |
1238 | Handle(Aspect_WindowDriver) aWindowDriver = Viewer2dTest::CurrentView()->Driver(); |
1239 | |
1240 | Standard_Integer aFontMin, aFontMax, aColorMin, aColorMax; |
1241 | aWindowDriver->FontBoundIndexs(aFontMin, aFontMax); |
1242 | di << "Available font indexes are " << aFontMin << " - " << aFontMax << "\n"; |
1243 | aWindowDriver->ColorBoundIndexs(aColorMin, aColorMax); |
1244 | di << "Available color indexes are " << aColorMin << " - " << aColorMax << "\n"; |
1245 | } |
1246 | |
1247 | #if ! defined(WNT) |
1248 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
1249 | extern Handle(AIS_InteractiveContext)& TheAISContext(); |
1250 | #else |
1251 | Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
1252 | Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(); |
1253 | #endif |
1254 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
1255 | #include <AIS_Trihedron.hxx> |
1256 | #include <AIS_Axis.hxx> |
1257 | #include <Geom_Line.hxx> |
1258 | #include <AIS_Line.hxx> |
1259 | |
1260 | //============================================================================== |
1261 | // function : VTrihedronOrigins |
1262 | // author : ota |
1263 | // purpose : draws triheron axis origin lines. |
1264 | // Draw arg : vtri_orig trihedron_name |
1265 | //============================================================================== |
1266 | static int VTrihedronOrigins(Draw_Interpretor& di, |
1267 | Standard_Integer argc, |
1268 | const char ** argv) |
1269 | { |
1270 | if(argc != 2){ |
1271 | di <<"Usage : vtri_orig tri_name"<<"\n"; |
1272 | return 1; |
1273 | } |
1274 | |
1275 | if(TheAISContext().IsNull()){ |
1276 | di<<"Make 'vinit' before this method call"<<"\n"; |
1277 | return 1; |
1278 | } |
1279 | |
1280 | //get trihedron from AIS map. |
1281 | TCollection_AsciiString aName(argv[1]); |
1282 | if(!GetMapOfAIS().IsBound2(aName)){ |
1283 | di<<"No object named '"<<argv[1]<<"'"<<"\n"; |
1284 | return 1; |
1285 | } |
1286 | |
1287 | Handle(AIS_Trihedron) aTrih = |
1288 | Handle(AIS_Trihedron)::DownCast(GetMapOfAIS().Find2(aName)); |
1289 | if(aTrih.IsNull()){ |
1290 | di<<"Trihedron is not found, try another name"<<"\n"; |
1291 | return 1; |
1292 | } |
1293 | |
1294 | //get axis |
1295 | Handle(AIS_Axis) XAxis = aTrih->XAxis(); |
1296 | Handle(AIS_Axis) YAxis = aTrih->YAxis(); |
1297 | Handle(AIS_Axis) ZAxis = aTrih->Axis(); |
1298 | |
1299 | //get geometrical lines |
1300 | Handle(Geom_Line) XGLine = XAxis->Component(); |
1301 | Handle(Geom_Line) YGLine = YAxis->Component(); |
1302 | Handle(Geom_Line) ZGLine = ZAxis->Component(); |
1303 | |
1304 | //make AIS_Lines |
1305 | Handle(AIS_Line) XLine = new AIS_Line(XGLine); |
1306 | Handle(AIS_Line) YLine = new AIS_Line(YGLine); |
1307 | Handle(AIS_Line) ZLine = new AIS_Line(ZGLine); |
1308 | |
1309 | //put them into AIS map: |
1310 | GetMapOfAIS().Bind(XLine,aName+"_X"); |
1311 | GetMapOfAIS().Bind(YLine,aName+"_Y"); |
1312 | GetMapOfAIS().Bind(ZLine,aName+"_Z"); |
1313 | //print names of created objects: |
1314 | di<<argv[1]<<"_X "<<argv[1]<<"_Y "<<argv[1]<<"_Z"<<"\n"; |
1315 | |
1316 | //try to draw them: |
1317 | TheAISContext()->Display(XLine); |
1318 | TheAISContext()->Display(YLine); |
1319 | TheAISContext()->Display(ZLine); |
1320 | |
1321 | return 0; |
1322 | } |
1323 | |
1324 | //======================================================================= |
1325 | //function : QAAddOrRemoveSelected |
1326 | //purpose : |
1327 | //======================================================================= |
1328 | static Standard_Integer QAAddOrRemoveSelected (Draw_Interpretor& di, Standard_Integer n, const char ** a) |
1329 | { |
1330 | if( n != 2) |
1331 | { |
1332 | di<<"Usage : QAAddOrRemoveSelected shape \n"; |
1333 | return 1; |
1334 | } |
1335 | //get AIS_Shape: |
1336 | Handle(AIS_InteractiveContext) anAISCtx = ViewerTest::GetAISContext(); |
1337 | |
1338 | //ViewerTest_DoubleMapOfInteractiveAndName& aMap = |
1339 | // ViewerTest::GetDataMapOfAIS (); |
1340 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); |
1341 | |
1342 | TCollection_AsciiString aName(a[1]); |
1343 | Handle(AIS_InteractiveObject) AISObj; |
1344 | |
1345 | if(aMap.IsBound2(aName)){ |
1346 | AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName)); |
1347 | if(AISObj.IsNull()){ |
1348 | di<<"No interactive object \n"; |
1349 | return 1; |
1350 | } |
1351 | |
1352 | if(anAISCtx->HasOpenedContext()){ |
1353 | anAISCtx->InitSelected(); |
1354 | anAISCtx->AddOrRemoveSelected(AISObj); |
1355 | } |
1356 | else { |
1357 | anAISCtx->InitCurrent(); |
1358 | anAISCtx->AddOrRemoveCurrentObject(AISObj); |
1359 | } |
1360 | return 0; |
1361 | } |
1362 | //select this shape: |
1363 | else { |
1364 | di<<"Use 'vdisplay' before"; |
1365 | return 1; |
1366 | } |
1367 | } |
1368 | |
1369 | //======================================================================= |
1370 | //function : QASetZClippingMode |
1371 | //purpose : |
1372 | //======================================================================= |
1373 | static Standard_Integer QASetZClippingMode (Draw_Interpretor& di, int argc, const char ** argv) |
1374 | { |
1375 | if (argc != 2) { |
1376 | di << "Usage : " << argv[0] << " mode(OFF/BACK/FRONT/SLICE)" << "\n"; |
1377 | return -1; |
1378 | } |
1379 | |
1380 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
1381 | if(AIScontext.IsNull()) { |
1382 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1383 | return -1; |
1384 | } |
1385 | |
1386 | Standard_Integer aStatus = 0; |
1387 | V3d_TypeOfZclipping ZClippingMode; |
1388 | if ( strcmp (argv [1], "OFF") == 0 ) { |
1389 | aStatus = 1; |
1390 | ZClippingMode = V3d_OFF; |
1391 | } |
1392 | if ( strcmp (argv [1], "BACK") == 0 ) { |
1393 | aStatus = 1; |
1394 | ZClippingMode = V3d_BACK; |
1395 | } |
1396 | if ( strcmp (argv [1], "FRONT") == 0 ) { |
1397 | aStatus = 1; |
1398 | ZClippingMode = V3d_FRONT; |
1399 | } |
1400 | if ( strcmp (argv [1], "SLICE") == 0 ) { |
1401 | aStatus = 1; |
1402 | ZClippingMode = V3d_SLICE; |
1403 | } |
1404 | if (aStatus != 1) |
1405 | { |
1406 | di << "Bad mode; Usage : " << argv[0] << " mode(OFF/BACK/FRONT/SLICE)" << "\n"; |
1407 | return -1; |
1408 | } |
1409 | |
1410 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
1411 | aView->SetZClippingType(ZClippingMode); |
1412 | aView->Redraw(); |
1413 | |
1414 | return 0; |
1415 | } |
1416 | |
1417 | //======================================================================= |
1418 | //function : QAGetZClippingMode |
1419 | //purpose : |
1420 | //======================================================================= |
1421 | static Standard_Integer QAGetZClippingMode (Draw_Interpretor& di, int /*argc*/, const char ** argv) |
1422 | { |
1423 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
1424 | if(AIScontext.IsNull()) { |
1425 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1426 | return -1; |
1427 | } |
1428 | |
1429 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
1430 | TCollection_AsciiString ZClippingModeString; |
1431 | Quantity_Length Depth, Width; |
1432 | V3d_TypeOfZclipping ZClippingMode = aView->ZClipping(Depth, Width); |
1433 | switch (ZClippingMode) |
1434 | { |
1435 | case V3d_OFF: |
1436 | ZClippingModeString.Copy("OFF"); |
1437 | break; |
1438 | case V3d_BACK: |
1439 | ZClippingModeString.Copy("BACK"); |
1440 | break; |
1441 | case V3d_FRONT: |
1442 | ZClippingModeString.Copy("FRONT"); |
1443 | break; |
1444 | case V3d_SLICE: |
1445 | ZClippingModeString.Copy("SLICE"); |
1446 | break; |
1447 | default: |
1448 | ZClippingModeString.Copy(TCollection_AsciiString(ZClippingMode)); |
1449 | break; |
1450 | } |
1451 | di << "ZClippingMode = " << ZClippingModeString.ToCString() << "\n"; |
1452 | |
1453 | return 0; |
1454 | } |
1455 | |
1456 | #include <V2d_View.hxx> |
1457 | #include <AIS2D_InteractiveObject.hxx> |
1458 | #include <Graphic2d_Circle.hxx> |
1459 | #include <Graphic2d_TypeOfPolygonFilling.hxx> |
1460 | #include <V2d_Viewer.hxx> |
1461 | #include <Viewer2dTest_DoubleMapOfInteractiveAndName.hxx> |
1462 | |
1463 | #if ! defined(WNT) |
1464 | extern Viewer2dTest_DoubleMapOfInteractiveAndName& GetMapOfAIS2D(); |
1465 | #else |
1466 | Standard_EXPORT Viewer2dTest_DoubleMapOfInteractiveAndName& GetMapOfAIS2D(); |
1467 | #endif |
1468 | |
1469 | //======================================================================= |
1470 | //function : QAv2dcircle |
1471 | //purpose : |
1472 | //======================================================================= |
1473 | static Standard_Integer QAv2dcircle (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
1474 | { |
1475 | Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext(); |
1476 | if(aContext.IsNull()) { |
1477 | di << "ERROR: Use 'v2dinit' command before " << argv[0] << "\n"; |
1478 | return -1; |
1479 | } |
1480 | if(argc < 7){ |
1481 | di<<"Usage : " << argv[0] << " CircleName X Y Radius Alpha Beta [Color_index]\n"; |
1482 | return -1; |
1483 | } |
1484 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
1485 | |
1486 | TCollection_AsciiString name = argv[1]; |
1487 | Standard_Real x = atof(argv[2]); |
1488 | Standard_Real y = atof(argv[3]); |
1489 | Standard_Real radius = atof(argv[4]); |
1490 | Standard_Real alpha = atof(argv[5]); |
1491 | Standard_Real beta = atof(argv[6]); |
1492 | |
1493 | if (GetMapOfAIS2D().IsBound2(name)) { |
1494 | di << "There is already an object with name " << name.ToCString() << "\n"; |
1495 | return -1; |
1496 | } |
1497 | Handle(AIS2D_InteractiveObject) aisobj = new AIS2D_InteractiveObject(); |
1498 | aisobj->SetView(V->View()); |
1499 | Handle(Graphic2d_Circle) circle = new Graphic2d_Circle(aisobj,x,y,radius,alpha,beta); |
1500 | if(argc > 7){ |
1501 | Standard_Integer color_index = atoi(argv[7]); |
1502 | circle->SetTypeOfPolygonFilling(Graphic2d_TOPF_FILLED); |
1503 | circle->SetInteriorColorIndex(color_index); |
1504 | } |
1505 | GetMapOfAIS2D().Bind(aisobj, name); |
1506 | aisobj->Display(); |
1507 | V->Viewer()->Update(); |
1508 | return 0; |
1509 | } |
1510 | |
1511 | #include <Draw_Viewer.hxx> |
1512 | #include <Draw.hxx> |
1513 | |
1514 | #ifndef WNT |
1515 | extern Draw_Viewer dout; |
1516 | #else |
1517 | Standard_IMPORT Draw_Viewer dout; |
1518 | #endif |
1519 | |
1520 | static Standard_Integer ViewId(const Standard_CString a) |
1521 | { |
1522 | Standard_Integer id = atoi(a); |
1523 | if ((id < 0) || (id >= MAXVIEW)) { |
1524 | cout << "Incorrect view-id, must be in 0.."<<MAXVIEW-1<<endl; |
1525 | return -1; |
1526 | } |
1527 | if (!dout.HasView(id)) { |
1528 | cout <<"View "<<id<<" does not exist."<<endl; |
1529 | return -1; |
1530 | } |
1531 | return id; |
1532 | } |
1533 | |
1534 | //======================================================================= |
1535 | //function : QAwzoom |
1536 | //purpose : |
1537 | //======================================================================= |
1538 | |
1539 | static Standard_Integer QAwzoom(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) { |
1540 | if(argc < 6){ |
1541 | di<<"Usage : " << argv[0] << " view-id X1 Y1 X2 Y2\n"; |
1542 | return -1; |
1543 | } |
1544 | |
1545 | Standard_Integer id = ViewId(argv [1]); |
1546 | if (id < 0) { |
1547 | return -1; |
1548 | } |
1549 | |
1550 | Standard_Integer X1 = atoi (argv [2]); |
1551 | Standard_Integer Y1 = atoi (argv [3]); |
1552 | Standard_Integer X2 = atoi (argv [4]); |
1553 | Standard_Integer Y2 = atoi (argv [5]); |
1554 | |
1555 | Standard_Real zx,zy; |
1556 | |
1557 | Standard_Integer X,Y,W,H; |
1558 | dout.GetPosSize(id,X,Y,W,H); |
1559 | |
1560 | if ((X1 == X2) || (Y1 == Y2)) return 0; |
1561 | |
1562 | zx = (Standard_Real) Abs(X2-X1) / (Standard_Real) W; |
1563 | zy = (Standard_Real) Abs(Y2-Y1) / (Standard_Real) H; |
1564 | if (zy > zx) zx = zy; |
1565 | zx = 1/zx; |
1566 | if (X2 < X1) X1 = X2; |
1567 | if (Y2 > Y1) Y1 = Y2; |
1568 | X1 = (Standard_Integer ) (X1*zx); |
1569 | Y1 = (Standard_Integer ) (Y1*zx); |
1570 | dout.SetZoom(id,zx*dout.Zoom(id)); |
1571 | dout.SetPan(id,-X1,-Y1); |
1572 | dout.RepaintView(id); |
1573 | if (dout.HasView(id)) { |
1574 | char title[255]; |
1575 | sprintf(title,"%d : %s - Zoom %f",id,dout.GetType(id),dout.Zoom(id)); |
1576 | dout.SetTitle(id,title); |
1577 | } |
1578 | return 0; |
1579 | } |
1580 | |
1581 | #include <Draw_Display.hxx> |
1582 | |
1583 | //======================================================================= |
1584 | //function : QAGetCoordinatesWzoom |
1585 | //purpose : |
1586 | //======================================================================= |
1587 | |
1588 | static Standard_Integer QAGetCoordinatesWzoom(Draw_Interpretor& di, Standard_Integer, const char **) |
1589 | { |
1590 | Standard_Integer id1,X1,Y1,b; |
1591 | Standard_Integer X2,Y2; |
1592 | Standard_Real dX1,dY1,dX2,dY2; |
1593 | di << "Pick first corner"<<"\n"; |
1594 | dout.Select(id1,X1,Y1,b); |
1595 | |
1596 | gp_Trsf T; |
1597 | gp_Pnt P0(0,0,0); |
1598 | dout.GetTrsf(id1,T); |
1599 | T.Invert(); |
1600 | P0.Transform(T); |
1601 | Standard_Real z = dout.Zoom(id1); |
1602 | |
1603 | dX1=X1; dY1=Y1; |
1604 | dX1-=P0.X(); dY1-=P0.Y(); |
1605 | dX1/=z; dY1/=z; |
1606 | |
1607 | if (b != 1) return 0; |
1608 | if (id1 < 0) return 0; |
1609 | Draw_Display d = dout.MakeDisplay(id1); |
1610 | d.SetColor(Draw_blanc); |
1611 | d.SetMode(10); |
1612 | Standard_Real dOX2 = dX1; |
1613 | Standard_Real dOY2 = dY1; |
1614 | d.Draw(gp_Pnt2d(dX1,dY1),gp_Pnt2d(dX1,dOY2)); |
1615 | d.Draw(gp_Pnt2d(dX1,dOY2),gp_Pnt2d(dOX2,dOY2)); |
1616 | d.Draw(gp_Pnt2d(dOX2,dOY2),gp_Pnt2d(dOX2,dY1)); |
1617 | d.Draw(gp_Pnt2d(dOX2,dY1),gp_Pnt2d(dX1,dY1)); |
1618 | d.Flush(); |
1619 | Standard_Real zx,zy; |
1620 | Standard_Integer X,Y,W,H; |
1621 | dout.GetPosSize(id1,X,Y,W,H); |
1622 | di << "Pick second corner"<<"\n"; |
1623 | b = 0; |
1624 | while (b == 0) { |
1625 | dout.Select(id1,X2,Y2,b,Standard_False); |
1626 | dX2=X2; dY2=Y2; |
1627 | dX2-=P0.X(); dY2-=P0.Y(); |
1628 | dX2/=z; dY2/=z; |
1629 | |
1630 | d.Draw(gp_Pnt2d(dX1,dY1),gp_Pnt2d(dX1,dOY2)); |
1631 | d.Draw(gp_Pnt2d(dX1,dOY2),gp_Pnt2d(dOX2,dOY2)); |
1632 | d.Draw(gp_Pnt2d(dOX2,dOY2),gp_Pnt2d(dOX2,dY1)); |
1633 | d.Draw(gp_Pnt2d(dOX2,dY1),gp_Pnt2d(dX1,dY1)); |
1634 | d.Draw(gp_Pnt2d(dX1,dY1),gp_Pnt2d(dX1,dY2)); |
1635 | d.Draw(gp_Pnt2d(dX1,dY2),gp_Pnt2d(dX2,dY2)); |
1636 | d.Draw(gp_Pnt2d(dX2,dY2),gp_Pnt2d(dX2,dY1)); |
1637 | d.Draw(gp_Pnt2d(dX2,dY1),gp_Pnt2d(dX1,dY1)); |
1638 | d.Flush(); |
1639 | dOX2 = dX2; |
1640 | dOY2 = dY2; |
1641 | } |
1642 | d.Draw(gp_Pnt2d(dX1,dY1),gp_Pnt2d(dX1,dOY2)); |
1643 | d.Draw(gp_Pnt2d(dX1,dOY2),gp_Pnt2d(dOX2,dOY2)); |
1644 | d.Draw(gp_Pnt2d(dOX2,dOY2),gp_Pnt2d(dOX2,dY1)); |
1645 | d.Draw(gp_Pnt2d(dOX2,dY1),gp_Pnt2d(dX1,dY1)); |
1646 | d.Flush(); |
1647 | if (b != 1) return 0; |
1648 | |
1649 | if ((X1 == X2) || (Y1 == Y2)) return 0; |
1650 | |
1651 | di << "X1=" << X1 << " Y1=" << Y1 <<"\n"; |
1652 | di << "X2=" << X2 << " Y2=" << Y2 <<"\n"; |
1653 | |
1654 | zx = (Standard_Real) Abs(X2-X1) / (Standard_Real) W; |
1655 | zy = (Standard_Real) Abs(Y2-Y1) / (Standard_Real) H; |
1656 | if (zy > zx) zx = zy; |
1657 | zx = 1/zx; |
1658 | if (X2 < X1) X1 = X2; |
1659 | if (Y2 > Y1) Y1 = Y2; |
1660 | X1 = (Standard_Integer ) (X1*zx); |
1661 | Y1 = (Standard_Integer ) (Y1*zx); |
1662 | dout.SetZoom(id1,zx*dout.Zoom(id1)); |
1663 | dout.SetPan(id1,-X1,-Y1); |
1664 | dout.RepaintView(id1); |
1665 | //SetTitle(id1); |
1666 | char title[255]; |
1667 | sprintf(title,"%d : %s - Zoom %f",id1,dout.GetType(id1),dout.Zoom(id1)); |
1668 | dout.SetTitle(id1,title); |
1669 | return 0; |
1670 | } |
1671 | |
1672 | //======================================================================= |
1673 | // QArename |
1674 | //======================================================================= |
1675 | |
1676 | static Standard_Integer QArename(Draw_Interpretor& di, Standard_Integer n, const char** a) |
1677 | { |
1678 | if (n < 3) return 1; |
1679 | Standard_Boolean cop = !strcasecmp(a[0],"copy"); |
1680 | |
1681 | Handle(Draw_Drawable3D) D; |
1682 | for (Standard_Integer i = 1; i < n; i += 2) { |
1683 | if (i+1 >= n) return 0; |
1684 | D = Draw::Get(a[i]); |
1685 | if (!D.IsNull()) { |
1686 | if (cop) |
1687 | D = D->Copy(); |
1688 | else |
1689 | // clear old name |
1690 | Draw::Set(a[i],Handle(Draw_Drawable3D())); |
1691 | |
1692 | Draw::Set(a[i+1],D); |
1693 | } |
1694 | } |
1695 | return 0; |
1696 | } |
1697 | |
1698 | static Standard_Integer QANbSelected (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
1699 | { |
1700 | if(argc != 1) { |
1701 | di << "Usage : " << argv[0] << "\n"; |
1702 | return 1; |
1703 | } |
1704 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
1705 | if(aContext.IsNull()) { |
1706 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1707 | return 1; |
1708 | } |
1709 | di << aContext->NbSelected() << "\n"; |
1710 | return 0; |
1711 | } |
1712 | |
1713 | //#if defined(V2D) |
1714 | //#include <AIS2D_InteractiveContext.hxx> |
1715 | //static Standard_Integer QANbSelected2d (Draw_Interpretor& /*di*/, Standard_Integer argc, char** argv) |
1716 | //{ |
1717 | // if(argc != 1) { |
1718 | // cout << "Usage : " << argv[0] << endl; |
1719 | // return 1; |
1720 | // } |
1721 | // Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext(); |
1722 | // if(aContext.IsNull()) { |
1723 | // cerr << "use 'v2dinit' command before " << argv[0] << endl; |
1724 | // return 1; |
1725 | // } |
1726 | // cout << aContext->NbSelected() << endl; |
1727 | // return 0; |
1728 | //} |
1729 | //#endif |
1730 | |
1731 | static Standard_Integer QAPurgeDisplay (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
1732 | { |
1733 | if (argc > 2) { |
1734 | di << "Usage : " << argv[0] << " [CollectorToo=0/1]" << "\n"; |
1735 | return 1; |
1736 | } |
1737 | Standard_Boolean CollectorTooBoolean = Standard_False; |
1738 | if (argc == 2) { |
1739 | Standard_Integer CollectorTooInteger = atoi (argv [1]); |
1740 | if (CollectorTooInteger != 0) |
1741 | CollectorTooBoolean = Standard_True; |
1742 | } |
1743 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
1744 | if (aContext.IsNull()) { |
1745 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1746 | return 1; |
1747 | } |
1748 | aContext->CloseAllContexts(Standard_False); |
1749 | di << aContext->PurgeDisplay(CollectorTooBoolean) << "\n"; |
1750 | return 0; |
1751 | } |
1752 | |
1753 | static Standard_Integer QACloseLocalContext (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
1754 | { |
1755 | if (argc > 3) { |
1756 | di << "Usage : " << argv[0] << " [Index [updateviewer=1/0]]" << "\n"; |
1757 | return 1; |
1758 | } |
1759 | Standard_Integer Index = -1; |
1760 | if (argc > 1) { |
1761 | Index = atoi (argv [1]); |
1762 | } |
1763 | //cout << "Index = " << Index << endl; |
1764 | Standard_Boolean updateviewerBoolean = Standard_True; |
1765 | if (argc == 3) { |
1766 | Standard_Integer updateviewerInteger = atoi (argv [2]); |
1767 | if (updateviewerInteger == 0) |
1768 | updateviewerBoolean = Standard_False; |
1769 | } |
1770 | //if (updateviewerBoolean) |
1771 | // cout << "updateviewer = Standard_True" << endl; |
1772 | //else |
1773 | // cout << "updateviewer = Standard_False" << endl; |
1774 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
1775 | if (aContext.IsNull()) { |
1776 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1777 | return 1; |
1778 | } |
1779 | aContext->CloseLocalContext(Index, updateviewerBoolean); |
1780 | return 0; |
1781 | } |
1782 | |
1783 | static Standard_Integer QACloseAllContexts (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
1784 | { |
1785 | if (argc > 2) { |
1786 | di << "Usage : " << argv[0] << " [updateviewer=1/0]" << "\n"; |
1787 | return 1; |
1788 | } |
1789 | Standard_Boolean updateviewerBoolean = Standard_True; |
1790 | if (argc == 2) { |
1791 | Standard_Integer updateviewerInteger = atoi (argv [1]); |
1792 | if (updateviewerInteger == 0) |
1793 | updateviewerBoolean = Standard_False; |
1794 | } |
1795 | //if (updateviewerBoolean) |
1796 | // cout << "updateviewer = Standard_True" << endl; |
1797 | //else |
1798 | // cout << "updateviewer = Standard_False" << endl; |
1799 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
1800 | if (aContext.IsNull()) { |
1801 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1802 | return 1; |
1803 | } |
1804 | aContext->CloseAllContexts(updateviewerBoolean); |
1805 | return 0; |
1806 | } |
1807 | |
1808 | static Standard_Integer QAIndexOfCurrentLocal (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
1809 | { |
1810 | if (argc > 1) { |
1811 | di << "Usage : " << argv[0] << "\n"; |
1812 | return 1; |
1813 | } |
1814 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
1815 | if (aContext.IsNull()) { |
1816 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1817 | return 1; |
1818 | } |
1819 | di << aContext->IndexOfCurrentLocal() << "\n"; |
1820 | return 0; |
1821 | } |
1822 | |
1823 | #include <AIS_ListOfInteractive.hxx> |
1824 | static Standard_Integer QADisplayedObjects (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
1825 | { |
1826 | if (argc > 2) { |
1827 | di << "Usage : " << argv[0] << " [OnlyFromNeutral=0/1]" << "\n"; |
1828 | return 1; |
1829 | } |
1830 | |
1831 | Standard_Boolean OnlyFromNeutralBoolean = Standard_False; |
1832 | if (argc == 2) { |
1833 | Standard_Integer OnlyFromNeutralInteger = atoi (argv [1]); |
1834 | if (OnlyFromNeutralInteger != 0) |
1835 | OnlyFromNeutralBoolean = Standard_True; |
1836 | } |
1837 | //if (OnlyFromNeutralBoolean) |
1838 | // cout << "OnlyFromNeutral = Standard_True" << endl; |
1839 | //else |
1840 | // cout << "OnlyFromNeutral = Standard_False" << endl; |
1841 | |
1842 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
1843 | if (aContext.IsNull()) { |
1844 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1845 | return 1; |
1846 | } |
1847 | Standard_Integer ListOfInteractiveExtent = 0; |
1848 | if(!aContext->HasOpenedContext()) { |
1849 | ListOfInteractiveExtent = 0; |
1850 | } else { |
1851 | AIS_ListOfInteractive ListOfInteractive; |
1852 | aContext->DisplayedObjects(ListOfInteractive, OnlyFromNeutralBoolean); |
1853 | ListOfInteractiveExtent = ListOfInteractive.Extent(); |
1854 | } |
1855 | di << ListOfInteractiveExtent << "\n"; |
1856 | return 0; |
1857 | } |
1858 | |
1859 | static Standard_Integer QASelectRectangle(Draw_Interpretor& di, Standard_Integer argc, const char ** argv ) |
1860 | { |
1861 | if(argc != 5) { |
1862 | di << "Usage : " << argv[0] << " x1 y1 x2 y2" << "\n"; |
1863 | return -1; |
1864 | } |
1865 | |
1866 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); |
1867 | if(myAIScontext.IsNull()) { |
1868 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1869 | return -1; |
1870 | } |
1871 | |
1872 | Standard_Integer x1 = atoi(argv[1]); |
1873 | Standard_Integer y1 = atoi(argv[2]); |
1874 | Standard_Integer x2 = atoi(argv[3]); |
1875 | Standard_Integer y2 = atoi(argv[4]); |
1876 | |
1877 | Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); |
1878 | // Handle(V3d_View) aCurrentView = ViewerTest::CurrentView(); |
1879 | |
1880 | aCurrentEventManager->MoveTo(x1,y1); |
1881 | aCurrentEventManager->Select(x1,y1,x2,y2); |
1882 | aCurrentEventManager->MoveTo(x2,y2); |
1883 | |
1884 | return 0; |
1885 | } |
1886 | |
1887 | static Standard_Integer QAShiftSelectRectangle(Draw_Interpretor& di, Standard_Integer argc, const char ** argv ) |
1888 | { |
1889 | if(argc != 5) { |
1890 | di << "Usage : " << argv[0] << " x1 y1 x2 y2" << "\n"; |
1891 | return -1; |
1892 | } |
1893 | |
1894 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); |
1895 | if(myAIScontext.IsNull()) { |
1896 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1897 | return -1; |
1898 | } |
1899 | Standard_Integer x1 = atoi(argv[1]); |
1900 | Standard_Integer y1 = atoi(argv[2]); |
1901 | Standard_Integer x2 = atoi(argv[3]); |
1902 | Standard_Integer y2 = atoi(argv[4]); |
1903 | |
1904 | Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); |
1905 | // Handle(V3d_View) aCurrentView = ViewerTest::CurrentView(); |
1906 | |
1907 | aCurrentEventManager->MoveTo(x1,y1); |
1908 | aCurrentEventManager->ShiftSelect(x1,y1,x2,y2); |
1909 | aCurrentEventManager->MoveTo(x2,y2); |
1910 | |
1911 | return 0; |
1912 | } |
1913 | |
1914 | static int QASelect2dRectangle (Draw_Interpretor& di, int argc, const char ** argv) |
1915 | { |
1916 | if (argc != 5) |
1917 | { |
1918 | di << "Usage : " << argv[0] << " x1 y1 x2 y2" << "\n"; |
1919 | return -1; |
1920 | } |
1921 | |
1922 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
1923 | if (myAIScontext.IsNull()) |
1924 | { |
1925 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
1926 | return -1; |
1927 | } |
1928 | |
1929 | Standard_Integer x1 = atoi(argv[1]); |
1930 | Standard_Integer y1 = atoi(argv[2]); |
1931 | Standard_Integer x2 = atoi(argv[3]); |
1932 | Standard_Integer y2 = atoi(argv[4]); |
1933 | |
1934 | Handle(Viewer2dTest_EventManager) aCurrentEventManager = Viewer2dTest::CurrentEventManager(); |
1935 | Handle(V2d_View) aCurrentView = Viewer2dTest::CurrentView(); |
1936 | |
1937 | aCurrentEventManager->MoveTo(x1,y1,aCurrentView); |
1938 | aCurrentEventManager->Select(x1,y1,x2,y2,aCurrentView); |
1939 | aCurrentEventManager->MoveTo(x2,y2,aCurrentView); |
1940 | |
1941 | return 0; |
1942 | } |
1943 | |
1944 | static int QAShiftSelect2dRectangle (Draw_Interpretor& di, int argc, const char ** argv) |
1945 | { |
1946 | if (argc != 5) |
1947 | { |
1948 | di << "Usage : " << argv[0] << " x1 y1 x2 y2" << "\n"; |
1949 | return -1; |
1950 | } |
1951 | |
1952 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
1953 | if (myAIScontext.IsNull()) |
1954 | { |
1955 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
1956 | return -1; |
1957 | } |
1958 | |
1959 | Standard_Integer x1 = atoi(argv[1]); |
1960 | Standard_Integer y1 = atoi(argv[2]); |
1961 | Standard_Integer x2 = atoi(argv[3]); |
1962 | Standard_Integer y2 = atoi(argv[4]); |
1963 | |
1964 | Handle(Viewer2dTest_EventManager) aCurrentEventManager = Viewer2dTest::CurrentEventManager(); |
1965 | Handle(V2d_View) aCurrentView = Viewer2dTest::CurrentView(); |
1966 | |
1967 | aCurrentEventManager->MoveTo(x1,y1,aCurrentView); |
1968 | aCurrentEventManager->ShiftSelect(x1,y1,x2,y2,aCurrentView); |
1969 | aCurrentEventManager->MoveTo(x2,y2,aCurrentView); |
1970 | |
1971 | return 0; |
1972 | } |
1973 | |
1974 | //======================================================================= |
1975 | //function : QARotateV3dView |
1976 | //purpose : |
1977 | //======================================================================= |
1978 | static Standard_Integer QARotateV3dView (Draw_Interpretor& di, int argc, const char ** argv) |
1979 | { |
1980 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
1981 | if(AIScontext.IsNull()) { |
1982 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1983 | return -1; |
1984 | } |
1985 | if(argc < 4 || argc > 5){ |
1986 | di<<"Usage : " << argv[0] << " Ax Ay Az [Start(1/0)]\n"; |
1987 | return -1; |
1988 | } |
1989 | Standard_Real Ax = atof(argv[1]); |
1990 | Standard_Real Ay = atof(argv[2]); |
1991 | Standard_Real Az = atof(argv[3]); |
1992 | Standard_Boolean Start = Standard_True; |
1993 | if (argc == 5) { |
1994 | Standard_Integer StartInteger = atoi(argv[4]); |
1995 | if (StartInteger > 0) { |
1996 | Start = Standard_True; |
1997 | } else { |
1998 | Start = Standard_False; |
1999 | } |
2000 | } |
2001 | |
2002 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2003 | aView->Rotate(Ax,Ay,Az,Start); |
2004 | return 0; |
2005 | } |
2006 | |
2007 | //======================================================================= |
2008 | //function : QAMoveV3dView |
2009 | //purpose : |
2010 | //======================================================================= |
2011 | static Standard_Integer QAMoveV3dView (Draw_Interpretor& di, int argc, const char ** argv) |
2012 | { |
2013 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
2014 | if(AIScontext.IsNull()) { |
2015 | di << "use 'vinit' command before " << argv[0] << "\n"; |
2016 | return -1; |
2017 | } |
2018 | if(argc < 4 || argc > 5){ |
2019 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start(1/0)]\n"; |
2020 | return -1; |
2021 | } |
2022 | Standard_Real Dx = atof(argv[1]); |
2023 | Standard_Real Dy = atof(argv[2]); |
2024 | Standard_Real Dz = atof(argv[3]); |
2025 | Standard_Boolean Start = Standard_True; |
2026 | if (argc == 5) { |
2027 | Standard_Integer StartInteger = atoi(argv[4]); |
2028 | if (StartInteger > 0) { |
2029 | Start = Standard_True; |
2030 | } else { |
2031 | Start = Standard_False; |
2032 | } |
2033 | } |
2034 | |
2035 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2036 | aView->Move(Dx,Dy,Dz,Start); |
2037 | return 0; |
2038 | } |
2039 | |
2040 | //======================================================================= |
2041 | //function : QATranslateV3dView |
2042 | //purpose : |
2043 | //======================================================================= |
2044 | static Standard_Integer QATranslateV3dView (Draw_Interpretor& di, int argc, const char ** argv) |
2045 | { |
2046 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
2047 | if(AIScontext.IsNull()) { |
2048 | di << "use 'vinit' command before " << argv[0] << "\n"; |
2049 | return -1; |
2050 | } |
2051 | if(argc < 4 || argc > 5){ |
2052 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start(1/0)]\n"; |
2053 | return -1; |
2054 | } |
2055 | Standard_Real Dx = atof(argv[1]); |
2056 | Standard_Real Dy = atof(argv[2]); |
2057 | Standard_Real Dz = atof(argv[3]); |
2058 | Standard_Boolean Start = Standard_True; |
2059 | if (argc == 5) { |
2060 | Standard_Integer StartInteger = atoi(argv[4]); |
2061 | if (StartInteger > 0) { |
2062 | Start = Standard_True; |
2063 | } else { |
2064 | Start = Standard_False; |
2065 | } |
2066 | } |
2067 | |
2068 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2069 | aView->Translate(Dx,Dy,Dz,Start); |
2070 | return 0; |
2071 | } |
2072 | |
2073 | //======================================================================= |
2074 | //function : QATurnV3dView |
2075 | //purpose : |
2076 | //======================================================================= |
2077 | static Standard_Integer QATurnV3dView (Draw_Interpretor& di, int argc, const char ** argv) |
2078 | { |
2079 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
2080 | if(AIScontext.IsNull()) { |
2081 | di << "use 'vinit' command before " << argv[0] << "\n"; |
2082 | return -1; |
2083 | } |
2084 | if(argc < 4 || argc > 5){ |
2085 | di<<"Usage : " << argv[0] << " Ax Ay Az [Start(1/0)]\n"; |
2086 | return -1; |
2087 | } |
2088 | Standard_Real Ax = atof(argv[1]); |
2089 | Standard_Real Ay = atof(argv[2]); |
2090 | Standard_Real Az = atof(argv[3]); |
2091 | Standard_Boolean Start = Standard_True; |
2092 | if (argc == 5) { |
2093 | Standard_Integer StartInteger = atoi(argv[4]); |
2094 | if (StartInteger > 0) { |
2095 | Start = Standard_True; |
2096 | } else { |
2097 | Start = Standard_False; |
2098 | } |
2099 | } |
2100 | |
2101 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2102 | aView->Turn(Ax,Ay,Az,Start); |
2103 | return 0; |
2104 | } |
2105 | |
2106 | //======================================================================= |
2107 | //function : QAPanningV3dView |
2108 | //purpose : |
2109 | //======================================================================= |
2110 | static Standard_Integer QAPanningV3dView (Draw_Interpretor& di, int argc, const char ** argv) |
2111 | { |
2112 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
2113 | if(AIScontext.IsNull()) { |
2114 | di << "use 'vinit' command before " << argv[0] << "\n"; |
2115 | return -1; |
2116 | } |
2117 | if(argc < 3 || argc > 5){ |
2118 | di<<"Usage : " << argv[0] << " Dx Dy [Zoom [Start(1/0)]]\n"; |
2119 | return -1; |
2120 | } |
2121 | Standard_Real Dx = atof(argv[1]); |
2122 | Standard_Real Dy = atof(argv[2]); |
2123 | Standard_Real Zoom = 1.; |
2124 | if (argc > 3) { |
2125 | Zoom = atof(argv[3]); |
2126 | if (Zoom <= 0.) { |
2127 | di<<"Bad Zoom value : " << Zoom << "\n"; |
2128 | return -1; |
2129 | } |
2130 | } |
2131 | Standard_Boolean Start = Standard_True; |
2132 | if (argc == 5) { |
2133 | Standard_Integer StartInteger = atoi(argv[4]); |
2134 | if (StartInteger > 0) { |
2135 | Start = Standard_True; |
2136 | } else { |
2137 | Start = Standard_False; |
2138 | } |
2139 | } |
2140 | |
2141 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2142 | aView->Panning(Dx,Dy,Zoom,Start); |
2143 | return 0; |
2144 | } |
2145 | |
2146 | //======================================================================= |
2147 | //function : QASetZoomV3dView |
2148 | //purpose : |
2149 | //======================================================================= |
2150 | static Standard_Integer QASetZoomV3dView (Draw_Interpretor& di, int argc, const char ** argv) |
2151 | { |
2152 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
2153 | if(AIScontext.IsNull()) { |
2154 | di << "use 'vinit' command before " << argv[0] << "\n"; |
2155 | return -1; |
2156 | } |
2157 | if(argc < 2 || argc > 3){ |
2158 | di<<"Usage : " << argv[0] << " Zoom [Start(1/0)]\n"; |
2159 | return -1; |
2160 | } |
2161 | Standard_Real Zoom = atof(argv[1]); |
2162 | if (Zoom <= 0.) { |
2163 | di<<"Bad Zoom value : " << Zoom << "\n"; |
2164 | return -1; |
2165 | } |
2166 | Standard_Boolean Start = Standard_True; |
2167 | if (argc == 3) { |
2168 | Standard_Integer StartInteger = atoi(argv[2]); |
2169 | if (StartInteger > 0) { |
2170 | Start = Standard_True; |
2171 | } else { |
2172 | Start = Standard_False; |
2173 | } |
2174 | } |
2175 | |
2176 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2177 | aView->SetZoom(Zoom,Start); |
2178 | return 0; |
2179 | } |
2180 | |
2181 | //======================================================================= |
2182 | //function : QASetSizeV3dView |
2183 | //purpose : |
2184 | //======================================================================= |
2185 | static Standard_Integer QASetSizeV3dView (Draw_Interpretor& di, int argc, const char ** argv) |
2186 | { |
2187 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
2188 | if(AIScontext.IsNull()) { |
2189 | di << "use 'vinit' command before " << argv[0] << "\n"; |
2190 | return -1; |
2191 | } |
2192 | if(argc != 2){ |
2193 | di<<"Usage : " << argv[0] << " Size\n"; |
2194 | return -1; |
2195 | } |
2196 | Standard_Real Size = atof(argv[1]); |
2197 | if (Size <= 0.) { |
2198 | di<<"Bad Size value : " << Size << "\n"; |
2199 | return -1; |
2200 | } |
2201 | |
2202 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2203 | aView->SetSize(Size); |
2204 | return 0; |
2205 | } |
2206 | |
2207 | void QADraw::CommonCommands(Draw_Interpretor& theCommands) |
2208 | { |
2209 | ios::sync_with_stdio(); |
2210 | |
2211 | st_err = dup(STDERR_FILENO); |
2212 | |
2213 | Draw_BeforeCommand_old = Draw_BeforeCommand; |
2214 | Draw_AfterCommand_old = Draw_AfterCommand; |
2215 | |
2216 | Draw_BeforeCommand = &before; |
2217 | Draw_AfterCommand = &after; |
2218 | |
2219 | const char* group = "QA_Commands"; |
2220 | |
2221 | theCommands.Add("QARebuild","QARebuild command_name",__FILE__,QARebuild,group); |
2222 | theCommands.Add("QAxwd_3d","QAxwd_3d filename",__FILE__,QAxwd_3d,group); |
2223 | theCommands.Add("QAMoveTo","QAMoveTo x y",__FILE__,QAMoveTo,group); |
2224 | theCommands.Add("QASelect","QASelect x y",__FILE__,QASelect,group); |
2225 | theCommands.Add("QAShiftSelect","QAShiftSelect x y",__FILE__,QAShiftSelect,group); |
2226 | theCommands.Add("QAUpdateLights","QAUpdateLights",__FILE__,QAUpdateLights,group); |
2227 | theCommands.Add("QASetAntialiasing","QASetAntialiasing [1/0]",__FILE__,QASetAntialiasing,group); |
2228 | theCommands.Add("QAvzfit","QAvzfit",__FILE__,QAvzfit,group); |
2229 | theCommands.Add("QAGetPixelColor", "QAGetPixelColor coordinate_X coordinate_Y [color_R color_G color_B]", __FILE__,QAAISGetPixelColor, group); |
2230 | theCommands.Add("QASetChoiceMode", "QASetChoiceMode mode switch ; Use without params to see a help ", __FILE__,QAAISSetChoiceMode, group); |
2231 | theCommands.Add("QAGetMousePoint", "QAGetMousePoint", __FILE__,QAAISGetMousePoint, group); |
2232 | theCommands.Add("QAGetViewCharac", "QAGetViewCharac", __FILE__,QAAISGetViewCharac, group); |
2233 | theCommands.Add("QASetViewCharac", "QASetViewCharac scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z", __FILE__,QAAISSetViewCharac, group); |
2234 | theCommands.Add("QAGetColorCoord", "QAGetColorCoord [3d|2d]", __FILE__,QAAISGetColorCoord, group); |
2235 | #ifndef WNT |
2236 | theCommands.Add("QAAISGetPixelColor2d", |
2237 | "QAAISGetPixelColor2d coord_X coord_Y [Red Green Blue] : Check a color of pixel", |
2238 | __FILE__, QAAISGetPixelColor2d, group); |
2239 | #endif |
2240 | |
2241 | theCommands.Add("v2dgetgrid", |
2242 | "v2dgetgrid coord_X coord_Y [grid_X grid_Y] : Get/print coordinates of a grid point near to (coord_X, coord_Y)", |
2243 | __FILE__, V2dPickGrid, group); |
2244 | |
2245 | theCommands.Add("QAv2dzoom", |
2246 | "QAv2dzoom zoom_factor : Set Scale Factor", |
2247 | __FILE__, V2dZoom, group); |
2248 | |
2249 | theCommands.Add("QAv2dpan", |
2250 | "QAv2dpan dx dy : script analog of Ctrl+MB2", |
2251 | __FILE__, V2dPan, group); |
2252 | |
2253 | // theCommands.Add("QAGetViewCharac2d", |
2254 | // "QAGetViewCharac2d - dumps viewer characteristics", |
2255 | // V2dGetViewCharac, group); |
2256 | |
2257 | // theCommands.Add("QASetViewCharac2d", |
2258 | // "QASetViewCharac2d scale center(X Y) proj(X Y Z) up(X Y Z) at(X Y Z)", |
2259 | // V2dSetViewCharac, group); |
2260 | |
2261 | theCommands.Add("QAMoveTo2d", "QAMoveTo2d x y", __FILE__, QAMoveTo2d, group); |
2262 | theCommands.Add("QASelect2d", "QASelect2d x y", __FILE__, QASelect2d, group); |
2263 | theCommands.Add("QAShiftSelect2d", "QAShiftSelect2d x y", __FILE__, QAShiftSelect2d, group); |
2264 | |
2265 | theCommands.Add("QAv2dSetHighlightMode", |
2266 | "QAv2dSetHighlightMode mode", __FILE__, V2dSetHighlightMode, group); |
2267 | |
2268 | theCommands.Add("QAxwd_2d", "QAxwd_2d filename", __FILE__, QAxwd_2d, group); |
2269 | |
2270 | theCommands.Add("QAxwd", "QAxwd [id=1] filename", __FILE__, QAxwd, group); |
2271 | |
2272 | theCommands.Add("QA2dGetIndexes", "QA2dGetIndexes", __FILE__, QA2dGetIndexes, group); |
2273 | |
2274 | theCommands.Add("vtri_orig", |
2275 | "vtri_orig : vtri_orig trihedron_name - draws axis origin lines", |
2276 | __FILE__,VTrihedronOrigins,group); |
2277 | |
2278 | theCommands.Add("QAAddOrRemoveSelected", |
2279 | "QAAddOrRemoveSelected shape : selects the shape by AddOrRemoveSelected method", |
2280 | __FILE__, QAAddOrRemoveSelected, group); |
2281 | |
2282 | theCommands.Add("QASetZClippingMode","QASetZClippingMode mode(OFF/BACK/FRONT/SLICE)",__FILE__,QASetZClippingMode,group); |
2283 | theCommands.Add("QAGetZClippingMode","QAGetZClippingMode",__FILE__,QAGetZClippingMode,group); |
2284 | theCommands.Add("QAv2dcircle", "QAv2dcircle CircleName X Y Radius Alpha Beta [Color_index]", __FILE__, QAv2dcircle, group); |
2285 | |
2286 | theCommands.Add("QAwzoom","QAwzoom view-id X1 Y1 X2 Y2; zoom on a window",__FILE__,QAwzoom,group); |
2287 | theCommands.Add("QAGetCoordinatesWzoom","QAGetCoordinatesWzoom ; Get coordinates for zoom on a window",__FILE__,QAGetCoordinatesWzoom,group); |
2288 | |
319e4241 |
2289 | // adding commands "rename" leads to the fact that QA commands doesn't work properly OCC23410, use function "renamevar" |
2290 | // theCommands.Add("rename","rename name1 toname1 name2 toname2 ...",__FILE__,QArename,group); |
7fd59977 |
2291 | |
2292 | theCommands.Add ("QANbSelected", "QANbSelected", __FILE__, QANbSelected, group); |
2293 | //#if defined(V2D) |
2294 | // theCommands.Add ("QANbSelected2d", "QANbSelected2d", __FILE__, QANbSelected2d, group); |
2295 | //#endif |
2296 | |
2297 | theCommands.Add ("QAPurgeDisplay", "QAPurgeDisplay [CollectorToo=0/1]", __FILE__, QAPurgeDisplay, group); |
2298 | theCommands.Add ("QACloseLocalContext", "QACloseLocalContext [Index [updateviewer=1/0]]", __FILE__, QACloseLocalContext, group); |
2299 | theCommands.Add ("QACloseAllContexts", "QACloseAllContexts [updateviewer=1/0]", __FILE__, QACloseAllContexts, group); |
2300 | theCommands.Add ("QAIndexOfCurrentLocal", "QAIndexOfCurrentLocal", __FILE__, QAIndexOfCurrentLocal, group); |
2301 | theCommands.Add ("QADisplayedObjects", "QADisplayedObjects [OnlyFromNeutral=0/1]", __FILE__, QADisplayedObjects, group); |
2302 | |
2303 | theCommands.Add("QASelectRectangle","QASelectRectangle x1 y1 x2 y2",__FILE__,QASelectRectangle,group); |
2304 | theCommands.Add("QAShiftSelectRectangle","QAShiftSelectRectangle x1 y1 x2 y2",__FILE__,QAShiftSelectRectangle,group); |
2305 | theCommands.Add("QASelect2dRectangle","QASelect2dRectangle x1 y1 x2 y2",__FILE__,QASelect2dRectangle,group); |
2306 | theCommands.Add("QAShiftSelect2dRectangle","QAShiftSelect2dRectangle x1 y1 x2 y2",__FILE__,QAShiftSelect2dRectangle,group); |
2307 | |
2308 | theCommands.Add("QARotateV3dView","QARotateV3dView Ax Ay Az [Start(1/0)]",__FILE__,QARotateV3dView,group); |
2309 | theCommands.Add("QAMoveV3dView","QAMoveV3dView Dx Dy Dz [Start(1/0)]",__FILE__,QAMoveV3dView,group); |
2310 | theCommands.Add("QATranslateV3dView","QATranslateV3dView Dx Dy Dz [Start(1/0)]",__FILE__,QATranslateV3dView,group); |
2311 | theCommands.Add("QATurnV3dView","QATurnV3dView Ax Ay Az [Start(1/0)]",__FILE__,QATurnV3dView,group); |
2312 | theCommands.Add("QAPanningV3dView","QAPanningV3dView Dx Dy [Zoom [Start(1/0)]]",__FILE__,QAPanningV3dView,group); |
2313 | theCommands.Add("QASetZoomV3dView","QASetZoomV3dView Zoom [Start(1/0)]",__FILE__,QASetZoomV3dView,group); |
2314 | theCommands.Add("QASetSizeV3dView","QASetSizeV3dView Size",__FILE__,QASetSizeV3dView,group); |
2315 | } |
2316 | /* |
2317 | extern "C" int Tkqadraw_Init(Tcl_Interp *); |
2318 | |
2319 | int Tkqadraw_Init(Tcl_Interp * ) { |
2320 | |
2321 | ios::sync_with_stdio(); |
2322 | |
2323 | QADraw::CommonCommands(theCommands); |
2324 | QADraw::AdditionalCommands(theCommands); |
2325 | |
2326 | ViewerTest::Commands (theCommands); |
2327 | ViewerTest::ViewerCommands (theCommands); |
2328 | |
2329 | Viewer2dTest::Commands(theCommands); |
2330 | // if (Tcl_PkgProvide(theCommands.Interp(), "Qa", "1.0") != TCL_OK) { |
2331 | // return TCL_ERROR; |
2332 | // } |
2333 | |
2334 | return TCL_OK; |
2335 | } |
2336 | */ |
2337 | //============================================================================== |
2338 | // QADraw::Factory |
2339 | //============================================================================== |
2340 | void QADraw::Factory(Draw_Interpretor& theCommands) |
2341 | { |
2342 | thePCommands = &theCommands; |
2343 | |
2344 | // definition of QA Command |
2345 | QADraw::CommonCommands(theCommands); |
2346 | QADraw::AdditionalCommands(theCommands); |
2347 | |
2348 | //ViewerTest::Commands (theCommands); |
2349 | //ViewerTest::ViewerCommands (theCommands); |
2350 | |
2351 | //#if defined(V2D) |
2352 | // Viewer2dTest::Commands(theCommands); |
2353 | //#endif |
2354 | |
2355 | //#ifdef DEB |
2356 | // cout << "Draw Plugin : QA commands are loaded" << endl; |
2357 | //#endif |
2358 | } |
2359 | |
2360 | // Declare entry point PLUGINFACTORY |
2361 | DPLUGIN(QADraw) |