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> |
692613e5 |
28 | #include <Image_AlienPixMap.hxx> |
7fd59977 |
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 | |
692613e5 |
429 | Handle(TColStd_HSequenceOfReal) GetColorOfPixel (const Image_PixMap& theImage, |
7fd59977 |
430 | const Standard_Integer theCoordinateX, |
431 | const Standard_Integer theCoordinateY, |
432 | const Standard_Integer theRadius) |
433 | { |
434 | Handle(TColStd_HSequenceOfReal) aSeq = new TColStd_HSequenceOfReal(); |
692613e5 |
435 | if (theImage.IsEmpty()) { |
7fd59977 |
436 | std::cerr << "The image is null.\n"; |
437 | return aSeq; |
438 | } |
692613e5 |
439 | Standard_Integer aWidth = (Standard_Integer )theImage.SizeX(); |
440 | Standard_Integer anHeight = (Standard_Integer )theImage.SizeY(); |
7fd59977 |
441 | |
442 | Quantity_Color aColorTmp; |
443 | for (Standard_Integer anXIter = theCoordinateX - theRadius; |
444 | anXIter <= theCoordinateX + theRadius; ++anXIter) |
445 | { |
446 | if (anXIter < 0 || anXIter >= aWidth) |
447 | { |
448 | continue; |
449 | } |
450 | for (Standard_Integer anYIter = theCoordinateY - theRadius; |
451 | anYIter <= theCoordinateY + theRadius; ++anYIter) |
452 | { |
453 | if (anYIter < 0 || anYIter >= anHeight) |
454 | { |
455 | continue; |
456 | } |
457 | // Image_PixMap stores image upside-down in memory! |
692613e5 |
458 | aColorTmp = theImage.PixelColor (anXIter, anYIter); |
7fd59977 |
459 | aSeq->Append (aColorTmp.Red()); |
460 | aSeq->Append (aColorTmp.Green()); |
461 | aSeq->Append (aColorTmp.Blue()); |
462 | } |
463 | } |
464 | return aSeq; |
465 | } |
466 | |
792c785c |
467 | static Standard_Integer QAAISGetPixelColor (Draw_Interpretor& theDi, |
468 | Standard_Integer theArgsNb, |
469 | const char** theArgs) |
7fd59977 |
470 | { |
792c785c |
471 | if (theArgsNb != 3 && theArgsNb != 6) |
472 | { |
473 | theDi << "Usage : " << theArgs[0] << " coordinate_X coordinate_Y [color_R color_G color_B]" << "\n"; |
474 | return 1; // TCL_ERROR |
7fd59977 |
475 | } |
792c785c |
476 | |
477 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); |
478 | if (aView3d.IsNull()) |
479 | { |
480 | theDi << "You must initialize AISViewer before this command.\n"; |
481 | return 1; // TCL_ERROR |
7fd59977 |
482 | } |
483 | |
792c785c |
484 | const Handle(Aspect_Window) anAISWindow = aView3d->Window(); |
485 | Standard_Integer aWindowSizeX = 0; |
486 | Standard_Integer aWindowSizeY = 0; |
487 | anAISWindow->Size (aWindowSizeX, aWindowSizeY); |
488 | |
489 | Standard_Integer anArgIter = 1; |
490 | const Standard_Integer aPickCoordX = atoi (theArgs[anArgIter++]); |
491 | const Standard_Integer aPickCoordY = atoi (theArgs[anArgIter++]); |
492 | const Standard_Integer aRadius = (theArgsNb == 3) ? 0 : 1; |
493 | |
494 | Image_ColorRGBF aColorInput = {{ 0.0f, 0.0f, 0.0f }}; |
495 | if (theArgsNb == 6) |
496 | { |
497 | aColorInput.r() = (Standard_ShortReal )atof (theArgs[anArgIter++]); |
498 | aColorInput.g() = (Standard_ShortReal )atof (theArgs[anArgIter++]); |
499 | aColorInput.b() = (Standard_ShortReal )atof (theArgs[anArgIter++]); |
7fd59977 |
500 | } |
501 | |
692613e5 |
502 | Image_PixMap anImage; |
792c785c |
503 | aView3d->ToPixMap (anImage, aWindowSizeX, aWindowSizeY); |
504 | const Handle(TColStd_HSequenceOfReal) aSeq = GetColorOfPixel (anImage, aPickCoordX, aPickCoordY, aRadius); |
7fd59977 |
505 | cout << "Length = " << aSeq->Length() << endl; |
506 | |
792c785c |
507 | Image_ColorRGBF aColorPicked = {{ 0.0f, 0.0f, 0.0f }}; |
508 | Standard_Boolean isNotEqual = Standard_True; |
509 | for (Standard_Integer i = 1; i <= aSeq->Length(); i += 3) |
510 | { |
511 | aColorPicked.r() = (Standard_ShortReal )aSeq->Value (i + 0); |
512 | aColorPicked.g() = (Standard_ShortReal )aSeq->Value (i + 1); |
513 | aColorPicked.b() = (Standard_ShortReal )aSeq->Value (i + 2); |
514 | |
515 | if (theArgsNb == 3 || |
516 | ((Abs (aColorPicked.r() - aColorInput.r()) <= Precision::Confusion()) |
517 | && (Abs (aColorPicked.g() - aColorInput.g()) <= Precision::Confusion()) |
518 | && (Abs (aColorPicked.b() - aColorInput.b()) <= Precision::Confusion()))) |
519 | { |
520 | isNotEqual = Standard_False; |
7fd59977 |
521 | break; |
522 | } |
792c785c |
523 | } |
7fd59977 |
524 | |
792c785c |
525 | theDi << "RED : " << aColorPicked.r() << " " |
526 | << "GREEN : " << aColorPicked.g() << " " |
527 | << "BLUE : " << aColorPicked.b() << "\n"; |
528 | |
529 | if (theArgsNb == 6) |
530 | { |
531 | theDi << "User color: \n" |
532 | << "RED : " << aColorInput.r() << " " |
533 | << "GREEN : " << aColorInput.g() << " " |
534 | << "BLUE : " << aColorInput.b() << "\n"; |
7fd59977 |
535 | } |
792c785c |
536 | |
537 | if (isNotEqual) |
538 | { |
539 | theDi << "Faulty : colors are not equal.\n"; |
540 | return 1; // TCL_ERROR |
7fd59977 |
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"; |
692613e5 |
699 | return 0; |
7fd59977 |
700 | } |
701 | |
702 | static Standard_Integer QAAISSetViewCharac (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
703 | { |
704 | if ( argc != 13 ) { |
705 | 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"; |
706 | return 1; |
707 | } |
708 | Handle (V3d_View) QAAISView = ViewerTest::CurrentView (); |
709 | if ( QAAISView.IsNull () ) { |
710 | di << "You must initialize AISViewer before this command." << "\n"; |
711 | return 1; |
712 | } |
713 | Quantity_Factor QAAISViewScale = atof (argv [1]); |
714 | Standard_Real QAAISViewCenterCoordinateX = atof (argv [2]); |
715 | Standard_Real QAAISViewCenterCoordinateY = atof (argv [3]); |
716 | Standard_Real QAAISViewProjX = atof (argv [4]); |
717 | Standard_Real QAAISViewProjY = atof (argv [5]); |
718 | Standard_Real QAAISViewProjZ = atof (argv [6]); |
719 | Standard_Real QAAISViewUpX = atof (argv [7]); |
720 | Standard_Real QAAISViewUpY = atof (argv [8]); |
721 | Standard_Real QAAISViewUpZ = atof (argv [9]); |
722 | Standard_Real QAAISViewAtX = atof (argv [10]); |
723 | Standard_Real QAAISViewAtY = atof (argv [11]); |
724 | Standard_Real QAAISViewAtZ = atof (argv [12]); |
725 | QAAISView -> V3d_View::SetScale (QAAISViewScale); |
726 | QAAISView -> V3d_View::SetCenter (QAAISViewCenterCoordinateX, QAAISViewCenterCoordinateY); |
727 | QAAISView -> V3d_View::SetAt (QAAISViewAtX, QAAISViewAtY, QAAISViewAtZ); |
728 | QAAISView -> V3d_View::SetProj (QAAISViewProjX, QAAISViewProjY, QAAISViewProjZ); |
729 | QAAISView -> V3d_View::SetUp (QAAISViewUpX, QAAISViewUpY, QAAISViewUpZ); |
730 | QAAISView -> V3d_View::SetProj (QAAISViewProjX, QAAISViewProjY, QAAISViewProjZ); |
731 | return 0; |
732 | } |
733 | |
734 | static Standard_Integer QAAISGetColorCoord (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
735 | { |
736 | #if ! defined(WNT) |
737 | if ( argc > 2 ) { |
738 | di << "Usage : " << argv[0] << " [3d|2d]" << "\n"; |
739 | return 1; |
740 | } |
692613e5 |
741 | Handle(Xw_Window) QAAISWindow; |
7fd59977 |
742 | |
743 | Standard_Boolean is3d = 1; |
744 | |
745 | if(argc == 1 || !strcmp(argv[1],"3d")) { |
746 | |
747 | Handle (V3d_View) QAAIS_MainView = ViewerTest::CurrentView (); |
748 | if ( QAAIS_MainView.IsNull () ) { |
749 | di << "You must initialize AISViewer before this command." << "\n"; |
750 | return 1; |
751 | } |
692613e5 |
752 | QAAISWindow = Handle(Xw_Window)::DownCast (QAAIS_MainView->V3d_View::Window()); |
7fd59977 |
753 | is3d = 1; |
754 | } |
755 | |
756 | if(argc == 2 && !strcmp(argv[1],"2d")) { |
757 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
758 | if (V.IsNull()) { |
759 | di << "You must initialize AIS 2D Viewer before this command." << "\n"; |
760 | return 1; |
761 | } |
692613e5 |
762 | QAAISWindow = Handle(Xw_Window)::DownCast (V->Driver()->Window()); |
7fd59977 |
763 | is3d = 0; |
764 | } |
765 | |
766 | Standard_Integer QAAIS_WindowSize_X = 0; |
767 | Standard_Integer QAAIS_WindowSize_Y = 0; |
768 | QAAISWindow->Size(QAAIS_WindowSize_X, QAAIS_WindowSize_Y); |
769 | Handle (Graphic3d_GraphicDevice) QAAIS_GraphicDevice = new Graphic3d_GraphicDevice (getenv ("DISPLAY")); |
770 | |
771 | Draw_Window QAAIS_CoordWindow ("coordinate", 421, 205, 200, 60); |
772 | QAAIS_CoordWindow.DisplayWindow (); |
773 | QAAIS_CoordWindow.SetColor (12); |
774 | |
775 | 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); |
776 | Handle (V3d_Viewer) QAAIS_ColorViewer = new V3d_Viewer (QAAIS_GraphicDevice, Standard_ExtString ("COLOR")); |
777 | Handle (V3d_View) QAAIS_ColorView = QAAIS_ColorViewer -> CreateView (); |
778 | QAAIS_ColorWindow -> Map (); |
779 | QAAIS_ColorView -> SetWindow (QAAIS_ColorWindow); |
780 | QAAIS_ColorView -> SetBackgroundColor (Quantity_NOC_BLACK); |
781 | QAAIS_ColorView -> Redraw (); |
782 | |
783 | Standard_Integer QAAIS_MousePoint_X = 0; |
784 | Standard_Integer QAAIS_MousePoint_Y = 0; |
785 | Standard_Character QAAIS_MousePointX[32]; |
786 | sprintf (QAAIS_MousePointX, "X : %d", QAAIS_MousePoint_X); |
787 | Standard_Character QAAIS_MousePointY[32]; |
788 | sprintf (QAAIS_MousePointY, "Y : %d", QAAIS_MousePoint_Y); |
789 | Standard_ShortReal QAAIS_ColorRED = 0; |
790 | Standard_ShortReal QAAIS_ColorGRN = 0; |
791 | Standard_ShortReal QAAIS_ColorBLU = 0; |
792 | Quantity_Color QAAIS_ShowingColor; |
793 | QAAIS_ShowingColor.SetValues (QAAIS_ColorRED, QAAIS_ColorGRN, QAAIS_ColorBLU, Quantity_TOC_RGB); |
794 | Standard_Integer argccc = 5; |
795 | const char *bufff[] = { "A", "B", "C", "D", "E" }; |
796 | const char **argvvv = (const char **) bufff; |
797 | while ( is3d ? ViewerMainLoop (argccc, argvvv) : ViewerMainLoop2d (argccc, argvvv)) { |
798 | Handle(TColStd_HSequenceOfReal) aSeq; |
692613e5 |
799 | Image_PixMap anImage; |
7fd59977 |
800 | if(is3d) |
801 | { |
802 | ViewerTest::GetMousePosition (QAAIS_MousePoint_X, QAAIS_MousePoint_Y); |
803 | Handle (V3d_View) QAAIS_MainView = ViewerTest::CurrentView(); |
692613e5 |
804 | QAAIS_MainView->ToPixMap (anImage, QAAIS_WindowSize_X, QAAIS_WindowSize_Y); |
7fd59977 |
805 | } |
806 | else |
807 | { |
808 | Viewer2dTest::GetMousePosition (QAAIS_MousePoint_X, QAAIS_MousePoint_Y); |
692613e5 |
809 | QAAISWindow->ToPixMap (anImage); |
7fd59977 |
810 | } |
692613e5 |
811 | aSeq = GetColorOfPixel (anImage, QAAIS_MousePoint_X, QAAIS_MousePoint_Y, 0); |
812 | |
7fd59977 |
813 | QAAIS_ColorRED = aSeq->Value(1); |
814 | QAAIS_ColorGRN = aSeq->Value(2); |
815 | QAAIS_ColorBLU = aSeq->Value(3); |
816 | QAAIS_ShowingColor.SetValues (QAAIS_ColorRED, QAAIS_ColorGRN, QAAIS_ColorBLU, Quantity_TOC_RGB); |
817 | QAAIS_ColorView -> SetBackgroundColor (QAAIS_ShowingColor); |
818 | QAAIS_ColorView -> Redraw (); |
819 | QAAIS_CoordWindow.Clear(); |
820 | sprintf (QAAIS_MousePointX, "X : %d", QAAIS_MousePoint_X); |
821 | sprintf (QAAIS_MousePointY, "Y : %d", QAAIS_MousePoint_Y); |
822 | QAAIS_CoordWindow.DrawString (30, 35, QAAIS_MousePointX); |
823 | QAAIS_CoordWindow.DrawString (125, 35, QAAIS_MousePointY); |
824 | } |
825 | QAAIS_CoordWindow.Destroy (); |
826 | #endif //WNT |
827 | return 0; |
828 | } |
829 | |
830 | //============================================================================== |
831 | // VIEWER GLOBALs |
832 | //============================================================================== |
833 | #if ! defined(WNT) |
834 | extern int V2dPickGrid (Draw_Interpretor& , Standard_Integer argc, const char ** argv); |
835 | #else |
836 | Standard_EXPORT int V2dPickGrid (Draw_Interpretor& , Standard_Integer argc, const char ** argv); |
837 | #endif |
838 | //============================================================================== |
839 | //function : V2dSetHighlightMode |
840 | //purpose : QAv2dSetHighlightMode mode |
841 | //============================================================================== |
842 | static int V2dSetHighlightMode (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
843 | { |
844 | if (argc != 2) |
845 | { |
846 | di << "Usage: QAv2dSetHighlightMode mode" << "\n"; |
847 | return 1; |
848 | } |
849 | |
850 | Viewer2dTest::StandardModeActivation(atoi(argv[1])); |
851 | return 0; |
852 | } |
853 | |
854 | #ifndef WNT |
855 | //============================================================================== |
856 | //function : QAAISGetPixelColor2d |
857 | //purpose : QAAISGetPixelColor2d coord_X coord_Y Red Green Blue |
858 | //============================================================================== |
859 | |
860 | static int QAAISGetPixelColor2d (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
861 | { |
862 | if (argc != 6 && argc != 3) |
863 | { |
864 | di << "Args: coord_X coord_Y [Red Green Blue]" << "\n"; |
865 | return 1; |
866 | } |
867 | |
868 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
869 | if (V.IsNull()) |
870 | { |
871 | di << "You must initialize AIS 2D Viewer before this command." << "\n"; |
872 | return 1; |
873 | } |
692613e5 |
874 | |
7fd59977 |
875 | // Get Color |
692613e5 |
876 | #if (defined(_WIN32) || defined(__WIN32__)) |
877 | Handle(WNT_Window) QAAISWindow = Handle(WNT_Window)::DownCast (V->Driver()->Window()); |
878 | #else |
879 | Handle(Xw_Window) QAAISWindow = Handle(Xw_Window )::DownCast (V->Driver()->Window()); |
880 | #endif |
7fd59977 |
881 | |
882 | Standard_ShortReal aCoordinateX = atoi(argv[1]); |
883 | Standard_ShortReal aCoordinateY = atoi(argv[2]); |
884 | |
885 | // Get Color |
886 | Standard_ShortReal aColorRED_V = 0; |
887 | Standard_ShortReal aColorGRN_V = 0; |
888 | Standard_ShortReal aColorBLU_V = 0; |
889 | |
890 | if ( argc == 6 ) { |
891 | aColorRED_V = atof (argv [3]); |
892 | aColorGRN_V = atof (argv [4]); |
893 | aColorBLU_V = atof (argv [5]); |
894 | |
895 | di << "Begin aColorRED_User = " << aColorRED_V << "\n"; |
896 | di << "Begin aColorGRN_User = " << aColorGRN_V << "\n"; |
897 | di << "Begin aColorBLU_User = " << aColorBLU_V << "\n"; |
898 | } |
899 | |
900 | Standard_Integer aRadius = 1; |
901 | if ( argc == 3 ) { |
902 | aRadius=0; |
903 | } |
904 | |
692613e5 |
905 | Image_PixMap anImage; |
906 | QAAISWindow->ToPixMap (anImage); |
907 | Handle(TColStd_HSequenceOfReal) aSeq = GetColorOfPixel (anImage, aCoordinateX, aCoordinateY, aRadius); |
7fd59977 |
908 | |
909 | Standard_Boolean IsNotEqual = Standard_True; |
910 | Standard_Integer i; |
911 | for(i=1; i<=aSeq->Length();i+=3) { |
912 | // mkv 29.04.03 |
913 | Standard_ShortReal aColorRED_R = (((Standard_ShortReal) ((Standard_Integer) (aSeq->Value(i+0) * 1000000))) / 1000000.); |
914 | Standard_ShortReal aColorGRN_R = (((Standard_ShortReal) ((Standard_Integer) (aSeq->Value(i+1) * 1000000))) / 1000000.); |
915 | Standard_ShortReal aColorBLU_R = (((Standard_ShortReal) ((Standard_Integer) (aSeq->Value(i+2) * 1000000))) / 1000000.); |
916 | // mkv 29.04.03 |
917 | |
918 | if ( argc == 3 ) { |
919 | di << "RED : " << aColorRED_R << " GREEN : " << aColorGRN_R << " BLUE : " << aColorBLU_R << "\n"; |
920 | IsNotEqual = Standard_False; |
921 | break; |
922 | } |
923 | |
924 | if ( aColorRED_R == aColorRED_V |
925 | && aColorGRN_R == aColorGRN_V |
926 | && aColorBLU_R == aColorBLU_V |
927 | ) { |
928 | IsNotEqual = Standard_False; |
929 | break; |
930 | } |
931 | } |
932 | if (IsNotEqual) { |
933 | di << "Faulty : colors are not equal." << "\n"; |
934 | return 1; |
935 | } |
936 | return 0; |
937 | } |
938 | #endif // !WNT |
939 | |
940 | //============================================================================== |
941 | //function : QAMoveTo2d |
942 | //purpose : QAMoveTo2d x y |
943 | //============================================================================== |
944 | static int QAMoveTo2d (Draw_Interpretor& di, int argc, const char ** argv) |
945 | { |
946 | if (argc != 3) |
947 | { |
948 | di << "Usage : " << argv[0] << " x y" << "\n"; |
949 | return -1; |
950 | } |
951 | |
952 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
953 | if (myAIScontext.IsNull()) |
954 | { |
955 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
956 | return -1; |
957 | } |
958 | Viewer2dTest::CurrentEventManager()->MoveTo |
959 | (atoi(argv[1]), atoi(argv[2]), Viewer2dTest::CurrentView()); |
960 | return 0; |
961 | } |
962 | |
963 | //============================================================================== |
964 | //function : QASelect2d |
965 | //purpose : QASelect2d x y |
966 | //============================================================================== |
967 | static int QASelect2d (Draw_Interpretor& di, int argc, const char ** argv) |
968 | { |
969 | if (argc != 3) |
970 | { |
971 | di << "Usage : " << argv[0] << " x y" << "\n"; |
972 | return -1; |
973 | } |
974 | |
975 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
976 | if (myAIScontext.IsNull()) |
977 | { |
978 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
979 | return -1; |
980 | } |
981 | Viewer2dTest::CurrentEventManager()->MoveTo |
982 | (atoi(argv[1]), atoi(argv[2]), Viewer2dTest::CurrentView()); |
983 | Viewer2dTest::CurrentEventManager()->Select(); |
984 | return 0; |
985 | } |
986 | |
987 | //============================================================================== |
988 | //function : QAShiftSelect2d |
989 | //purpose : QAShiftSelect2d x y |
990 | //============================================================================== |
991 | static int QAShiftSelect2d (Draw_Interpretor& di, int argc, const char ** argv) |
992 | { |
993 | if (argc != 3) |
994 | { |
995 | di << "Usage : " << argv[0] << " x y" << "\n"; |
996 | return -1; |
997 | } |
998 | |
999 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
1000 | if (myAIScontext.IsNull()) |
1001 | { |
1002 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
1003 | return -1; |
1004 | } |
1005 | Viewer2dTest::CurrentEventManager()->MoveTo |
1006 | (atoi(argv[1]), atoi(argv[2]), Viewer2dTest::CurrentView()); |
1007 | Viewer2dTest::CurrentEventManager()->ShiftSelect(); |
1008 | return 0; |
1009 | } |
1010 | |
1011 | //============================================================================== |
1012 | //function : V2dZoom |
1013 | //purpose : QAv2dzoom zoom_factor |
1014 | //============================================================================== |
1015 | static int V2dZoom (Draw_Interpretor& di, int argc, const char ** argv) |
1016 | { |
1017 | if (argc != 2) |
1018 | { |
1019 | di << "Usage : " << argv[0] << " zoom_factor" << "\n"; |
1020 | return -1; |
1021 | } |
1022 | |
1023 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
1024 | if (myAIScontext.IsNull()) |
1025 | { |
1026 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
1027 | return -1; |
1028 | } |
1029 | Viewer2dTest::CurrentView()->Zoom(atof(argv[1])); |
1030 | return 0; |
1031 | } |
1032 | |
1033 | //============================================================================== |
1034 | //function : V2dPan |
1035 | //purpose : QAv2dpan dx dy |
1036 | //============================================================================== |
1037 | static int V2dPan (Draw_Interpretor& di, int argc, const char ** argv) |
1038 | { |
1039 | if (argc != 3) |
1040 | { |
1041 | di << "Usage : " << argv[0] << " dx dy" << "\n"; |
1042 | return -1; |
1043 | } |
1044 | |
1045 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
1046 | if (myAIScontext.IsNull()) |
1047 | { |
1048 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
1049 | return -1; |
1050 | } |
692613e5 |
1051 | Viewer2dTest::CurrentView()->Pan(atoi(argv[1]), atoi(argv[2])); |
7fd59977 |
1052 | return 0; |
1053 | } |
1054 | |
1055 | //============================================================================== |
1056 | //function : V2dGetViewCharac |
1057 | //purpose : v2dGetViewCharac |
1058 | //============================================================================== |
1059 | static int V2dGetViewCharac (Draw_Interpretor& di, int si, const char ** /*sc*/) |
1060 | { |
1061 | if (si != 1) |
1062 | { |
1063 | di << "Use - v2dGetViewCharac" << "\n"; |
1064 | return 1; |
1065 | } |
1066 | |
1067 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
1068 | if (V.IsNull()) |
1069 | { |
1070 | di << "You must initialize AIS 2D Viewer before this command." << "\n"; |
1071 | return 1; |
1072 | } |
1073 | |
1074 | // Quantity_Factor aViewScale = V->Scale(); |
1075 | |
1076 | Standard_Real aCenterCoordX = 0.0; |
1077 | Standard_Real aCenterCoordY = 0.0; |
1078 | V->Center(aCenterCoordX, aCenterCoordY); |
1079 | |
1080 | Standard_Real aViewProjX = 0.0; |
1081 | Standard_Real aViewProjY = 0.0; |
1082 | Standard_Real aViewProjZ = 0.0; |
1083 | // V->Proj(aViewProjX, aViewProjY, aViewProjZ); |
1084 | |
1085 | Standard_Real aViewUpX = 0.0; |
1086 | Standard_Real aViewUpY = 0.0; |
1087 | Standard_Real aViewUpZ = 0.0; |
1088 | // V->Up(aViewUpX, aViewUpY, aViewUpZ); |
1089 | |
1090 | Standard_Real aViewAtX = 0.0; |
1091 | Standard_Real aViewAtY = 0.0; |
1092 | Standard_Real aViewAtZ = 0.0; |
1093 | // V->At(aViewAtX, aViewAtY, aViewAtZ); |
1094 | |
1095 | // cout << "Scale of current view: " << aViewScale << endl; |
1096 | // cout << "Center on X : "<< aViewCenterCoordX << "; on Y: " << aViewCenterCoordY << endl; |
1097 | // cout << "Proj on X : " << aViewProjX << "; on Y: " << aViewProjY << "; on Z: " << aViewProjZ << endl; |
1098 | // cout << "Up on X : " << aViewUpX << "; on Y: " << aViewUpY << "; on Z: " << aViewUpZ << endl; |
1099 | // cout << "At on X : " << aViewAtX << "; on Y: " << aViewAtY << "; on Z: " << aViewAtZ << endl; |
1100 | |
1101 | // cout << aViewScale << " " << aViewCenterCoordX << " " << aViewCenterCoordY << " "; |
1102 | di << aViewProjX << " " << aViewProjY << " " << aViewProjZ << " "; |
1103 | di << aViewUpX << " " << aViewUpY << " " << aViewUpZ << " "; |
1104 | di << aViewAtX << " " << aViewAtY << " " << aViewAtZ << "\n"; |
1105 | return 0; |
1106 | } |
1107 | |
1108 | //============================================================================== |
1109 | //function : V2dSetViewCharac |
1110 | //purpose : v2dSetViewCharac |
1111 | //============================================================================== |
1112 | static int V2dSetViewCharac (Draw_Interpretor& di, int si, const char ** sc) |
1113 | { |
1114 | if (si != 13) |
1115 | { |
1116 | di << "Use - v2dSetViewCharac scale center(X Y) proj(X Y Z) up(X Y Z) at(X Y Z)" << "\n"; |
1117 | return 1; |
1118 | } |
1119 | |
1120 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
1121 | if (V.IsNull()) |
1122 | { |
1123 | di << "You must initialize AIS 2D Viewer before this command." << "\n"; |
1124 | return 1; |
1125 | } |
1126 | |
1127 | Quantity_Factor aViewScale = atof(sc[1]); |
1128 | |
1129 | Standard_Real aViewCenterCoordX = atof(sc[2]); |
1130 | Standard_Real aViewCenterCoordY = atof(sc[3]); |
1131 | |
1132 | Standard_Real aViewProjX = atof(sc[4]); |
1133 | Standard_Real aViewProjY = atof(sc[5]); |
1134 | Standard_Real aViewProjZ = atof(sc[6]); |
1135 | |
1136 | Standard_Real aViewUpX = atof(sc[7]); |
1137 | Standard_Real aViewUpY = atof(sc[8]); |
1138 | Standard_Real aViewUpZ = atof(sc[9]); |
1139 | |
1140 | Standard_Real aViewAtX = atof(sc[10]); |
1141 | Standard_Real aViewAtY = atof(sc[11]); |
1142 | Standard_Real aViewAtZ = atof(sc[12]); |
1143 | |
1144 | // V->SetScale(aViewScale); |
1145 | // V->SetCenter(aViewCenterCoordX, aViewCenterCoordY); |
1146 | // V->SetAt(aViewAtX, aViewAtY, aViewAtZ); |
1147 | // V->SetProj(aViewProjX, aViewProjY, aViewProjZ); |
1148 | // V->SetUp(aViewUpX, aViewUpY, aViewUpZ); |
1149 | // V->SetProj(aViewProjX, aViewProjY, aViewProjZ); |
1150 | return 0; |
1151 | } |
1152 | |
1153 | //======================================================================= |
1154 | //function : QAxwd_2d |
1155 | //purpose : |
1156 | //======================================================================= |
1157 | static int QAxwd_2d (Draw_Interpretor& di, int argc, const char ** argv) |
1158 | { |
1159 | if (argc != 2) |
1160 | { |
1161 | di << "Usage : " << argv[0] << " filename" << "\n"; |
1162 | return -1; |
1163 | } |
1164 | |
1165 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
1166 | if (myAIScontext.IsNull()) |
1167 | { |
1168 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
1169 | return -1; |
1170 | } |
1171 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
1172 | V->Dump(argv[1]); |
1173 | return 0; |
1174 | } |
1175 | |
1176 | #ifndef WNT |
1177 | extern Draw_Viewer dout; |
1178 | extern XW_STATUS Xw_save_image_adv (Display *aDisplay,Window aWindow,XWindowAttributes aWinAttr,XImage *aPximage,Colormap aColormap,int aNcolors,char *filename); |
1179 | extern Display* Draw_WindowDisplay; |
1180 | extern Colormap Draw_WindowColorMap; |
1181 | #else |
1182 | Standard_IMPORT Draw_Viewer dout; |
1183 | int __WNT_API SaveWindowToFile (Handle( WNT_GraphicDevice )& gDev, |
1184 | HWND hWnd, char* fName, int x, int y, int w, int h); |
1185 | #endif |
1186 | |
1187 | //======================================================================= |
1188 | //function : QAxwd |
1189 | //purpose : |
1190 | //======================================================================= |
1191 | static int QAxwd (Draw_Interpretor& di, int argc, const char ** argv) |
1192 | { |
1193 | if (argc < 2) |
1194 | { |
1195 | di << "Usage : " << argv[0] << " [id=1] filename" << "\n"; |
1196 | return -1; |
1197 | } |
1198 | |
1199 | // enforce repaint if necessary |
1200 | Standard_Integer id = 1; |
1201 | const char* file = argv[1]; |
1202 | if (argc > 2) { |
1203 | id = atoi(argv[1]); |
1204 | file = argv[2]; |
1205 | } |
1206 | |
1207 | after(id); |
1208 | |
1209 | dout.Flush(); |
1210 | if(dout.HasView(id)) { |
1211 | #if defined (WNT) |
1212 | Handle(WNT_GraphicDevice) aGd = new WNT_GraphicDevice(Standard_False); |
1213 | RECT rc; |
1214 | GetClientRect((HWND)dout.GetWindow(id), &rc); |
1215 | SaveWindowToFile(aGd,(HWND)dout.GetWindow(id),(char*)file,rc.left, rc.top,rc.right-rc.left, rc.bottom-rc.top); |
1216 | #else |
1217 | XSync(Draw_WindowDisplay,True); |
1218 | |
1219 | XWindowAttributes winAttr; |
1220 | XGetWindowAttributes (Draw_WindowDisplay, dout.GetWindow(id), &winAttr); |
1221 | |
1222 | XImage *pximage = XGetImage(Draw_WindowDisplay,dout.GetWindow(id), |
1223 | 0,0,winAttr.width,winAttr.height, |
1224 | AllPlanes,ZPixmap); |
1225 | |
1226 | Xw_save_image_adv(Draw_WindowDisplay,dout.GetWindow(id),winAttr,pximage,Draw_WindowColorMap,256,(char*)file); |
1227 | #endif |
1228 | } |
1229 | |
1230 | return 0; |
1231 | } |
1232 | |
1233 | //======================================================================= |
1234 | //function : QA2dGetIndexes |
1235 | //purpose : |
1236 | //======================================================================= |
1237 | static int QA2dGetIndexes (Draw_Interpretor& di, int /*argc*/, const char ** argv) |
1238 | { |
1239 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
1240 | if (myAIScontext.IsNull()) |
1241 | { |
1242 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
1243 | return -1; |
1244 | } |
1245 | Handle(Aspect_WindowDriver) aWindowDriver = Viewer2dTest::CurrentView()->Driver(); |
1246 | |
1247 | Standard_Integer aFontMin, aFontMax, aColorMin, aColorMax; |
1248 | aWindowDriver->FontBoundIndexs(aFontMin, aFontMax); |
1249 | di << "Available font indexes are " << aFontMin << " - " << aFontMax << "\n"; |
1250 | aWindowDriver->ColorBoundIndexs(aColorMin, aColorMax); |
1251 | di << "Available color indexes are " << aColorMin << " - " << aColorMax << "\n"; |
692613e5 |
1252 | return 0; |
7fd59977 |
1253 | } |
1254 | |
1255 | #if ! defined(WNT) |
1256 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
1257 | extern Handle(AIS_InteractiveContext)& TheAISContext(); |
1258 | #else |
1259 | Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
1260 | Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(); |
1261 | #endif |
1262 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
1263 | #include <AIS_Trihedron.hxx> |
1264 | #include <AIS_Axis.hxx> |
1265 | #include <Geom_Line.hxx> |
1266 | #include <AIS_Line.hxx> |
1267 | |
1268 | //============================================================================== |
1269 | // function : VTrihedronOrigins |
1270 | // author : ota |
1271 | // purpose : draws triheron axis origin lines. |
1272 | // Draw arg : vtri_orig trihedron_name |
1273 | //============================================================================== |
1274 | static int VTrihedronOrigins(Draw_Interpretor& di, |
1275 | Standard_Integer argc, |
1276 | const char ** argv) |
1277 | { |
1278 | if(argc != 2){ |
1279 | di <<"Usage : vtri_orig tri_name"<<"\n"; |
1280 | return 1; |
1281 | } |
1282 | |
1283 | if(TheAISContext().IsNull()){ |
1284 | di<<"Make 'vinit' before this method call"<<"\n"; |
1285 | return 1; |
1286 | } |
1287 | |
1288 | //get trihedron from AIS map. |
1289 | TCollection_AsciiString aName(argv[1]); |
1290 | if(!GetMapOfAIS().IsBound2(aName)){ |
1291 | di<<"No object named '"<<argv[1]<<"'"<<"\n"; |
1292 | return 1; |
1293 | } |
1294 | |
1295 | Handle(AIS_Trihedron) aTrih = |
1296 | Handle(AIS_Trihedron)::DownCast(GetMapOfAIS().Find2(aName)); |
1297 | if(aTrih.IsNull()){ |
1298 | di<<"Trihedron is not found, try another name"<<"\n"; |
1299 | return 1; |
1300 | } |
1301 | |
1302 | //get axis |
1303 | Handle(AIS_Axis) XAxis = aTrih->XAxis(); |
1304 | Handle(AIS_Axis) YAxis = aTrih->YAxis(); |
1305 | Handle(AIS_Axis) ZAxis = aTrih->Axis(); |
1306 | |
1307 | //get geometrical lines |
1308 | Handle(Geom_Line) XGLine = XAxis->Component(); |
1309 | Handle(Geom_Line) YGLine = YAxis->Component(); |
1310 | Handle(Geom_Line) ZGLine = ZAxis->Component(); |
1311 | |
1312 | //make AIS_Lines |
1313 | Handle(AIS_Line) XLine = new AIS_Line(XGLine); |
1314 | Handle(AIS_Line) YLine = new AIS_Line(YGLine); |
1315 | Handle(AIS_Line) ZLine = new AIS_Line(ZGLine); |
1316 | |
1317 | //put them into AIS map: |
1318 | GetMapOfAIS().Bind(XLine,aName+"_X"); |
1319 | GetMapOfAIS().Bind(YLine,aName+"_Y"); |
1320 | GetMapOfAIS().Bind(ZLine,aName+"_Z"); |
1321 | //print names of created objects: |
1322 | di<<argv[1]<<"_X "<<argv[1]<<"_Y "<<argv[1]<<"_Z"<<"\n"; |
1323 | |
1324 | //try to draw them: |
1325 | TheAISContext()->Display(XLine); |
1326 | TheAISContext()->Display(YLine); |
1327 | TheAISContext()->Display(ZLine); |
1328 | |
1329 | return 0; |
1330 | } |
1331 | |
1332 | //======================================================================= |
1333 | //function : QAAddOrRemoveSelected |
1334 | //purpose : |
1335 | //======================================================================= |
1336 | static Standard_Integer QAAddOrRemoveSelected (Draw_Interpretor& di, Standard_Integer n, const char ** a) |
1337 | { |
1338 | if( n != 2) |
1339 | { |
1340 | di<<"Usage : QAAddOrRemoveSelected shape \n"; |
1341 | return 1; |
1342 | } |
1343 | //get AIS_Shape: |
1344 | Handle(AIS_InteractiveContext) anAISCtx = ViewerTest::GetAISContext(); |
1345 | |
1346 | //ViewerTest_DoubleMapOfInteractiveAndName& aMap = |
1347 | // ViewerTest::GetDataMapOfAIS (); |
1348 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); |
1349 | |
1350 | TCollection_AsciiString aName(a[1]); |
1351 | Handle(AIS_InteractiveObject) AISObj; |
1352 | |
1353 | if(aMap.IsBound2(aName)){ |
1354 | AISObj = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName)); |
1355 | if(AISObj.IsNull()){ |
1356 | di<<"No interactive object \n"; |
1357 | return 1; |
1358 | } |
1359 | |
1360 | if(anAISCtx->HasOpenedContext()){ |
1361 | anAISCtx->InitSelected(); |
1362 | anAISCtx->AddOrRemoveSelected(AISObj); |
1363 | } |
1364 | else { |
1365 | anAISCtx->InitCurrent(); |
1366 | anAISCtx->AddOrRemoveCurrentObject(AISObj); |
1367 | } |
1368 | return 0; |
1369 | } |
1370 | //select this shape: |
1371 | else { |
1372 | di<<"Use 'vdisplay' before"; |
1373 | return 1; |
1374 | } |
1375 | } |
1376 | |
1377 | //======================================================================= |
1378 | //function : QASetZClippingMode |
1379 | //purpose : |
1380 | //======================================================================= |
1381 | static Standard_Integer QASetZClippingMode (Draw_Interpretor& di, int argc, const char ** argv) |
1382 | { |
1383 | if (argc != 2) { |
1384 | di << "Usage : " << argv[0] << " mode(OFF/BACK/FRONT/SLICE)" << "\n"; |
1385 | return -1; |
1386 | } |
1387 | |
1388 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
1389 | if(AIScontext.IsNull()) { |
1390 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1391 | return -1; |
1392 | } |
1393 | |
1394 | Standard_Integer aStatus = 0; |
1395 | V3d_TypeOfZclipping ZClippingMode; |
1396 | if ( strcmp (argv [1], "OFF") == 0 ) { |
1397 | aStatus = 1; |
1398 | ZClippingMode = V3d_OFF; |
1399 | } |
1400 | if ( strcmp (argv [1], "BACK") == 0 ) { |
1401 | aStatus = 1; |
1402 | ZClippingMode = V3d_BACK; |
1403 | } |
1404 | if ( strcmp (argv [1], "FRONT") == 0 ) { |
1405 | aStatus = 1; |
1406 | ZClippingMode = V3d_FRONT; |
1407 | } |
1408 | if ( strcmp (argv [1], "SLICE") == 0 ) { |
1409 | aStatus = 1; |
1410 | ZClippingMode = V3d_SLICE; |
1411 | } |
1412 | if (aStatus != 1) |
1413 | { |
1414 | di << "Bad mode; Usage : " << argv[0] << " mode(OFF/BACK/FRONT/SLICE)" << "\n"; |
1415 | return -1; |
1416 | } |
1417 | |
1418 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
1419 | aView->SetZClippingType(ZClippingMode); |
1420 | aView->Redraw(); |
1421 | |
1422 | return 0; |
1423 | } |
1424 | |
1425 | //======================================================================= |
1426 | //function : QAGetZClippingMode |
1427 | //purpose : |
1428 | //======================================================================= |
1429 | static Standard_Integer QAGetZClippingMode (Draw_Interpretor& di, int /*argc*/, const char ** argv) |
1430 | { |
1431 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
1432 | if(AIScontext.IsNull()) { |
1433 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1434 | return -1; |
1435 | } |
1436 | |
1437 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
1438 | TCollection_AsciiString ZClippingModeString; |
1439 | Quantity_Length Depth, Width; |
1440 | V3d_TypeOfZclipping ZClippingMode = aView->ZClipping(Depth, Width); |
1441 | switch (ZClippingMode) |
1442 | { |
1443 | case V3d_OFF: |
1444 | ZClippingModeString.Copy("OFF"); |
1445 | break; |
1446 | case V3d_BACK: |
1447 | ZClippingModeString.Copy("BACK"); |
1448 | break; |
1449 | case V3d_FRONT: |
1450 | ZClippingModeString.Copy("FRONT"); |
1451 | break; |
1452 | case V3d_SLICE: |
1453 | ZClippingModeString.Copy("SLICE"); |
1454 | break; |
1455 | default: |
1456 | ZClippingModeString.Copy(TCollection_AsciiString(ZClippingMode)); |
1457 | break; |
1458 | } |
1459 | di << "ZClippingMode = " << ZClippingModeString.ToCString() << "\n"; |
1460 | |
1461 | return 0; |
1462 | } |
1463 | |
1464 | #include <V2d_View.hxx> |
1465 | #include <AIS2D_InteractiveObject.hxx> |
1466 | #include <Graphic2d_Circle.hxx> |
1467 | #include <Graphic2d_TypeOfPolygonFilling.hxx> |
1468 | #include <V2d_Viewer.hxx> |
1469 | #include <Viewer2dTest_DoubleMapOfInteractiveAndName.hxx> |
1470 | |
1471 | #if ! defined(WNT) |
1472 | extern Viewer2dTest_DoubleMapOfInteractiveAndName& GetMapOfAIS2D(); |
1473 | #else |
1474 | Standard_EXPORT Viewer2dTest_DoubleMapOfInteractiveAndName& GetMapOfAIS2D(); |
1475 | #endif |
1476 | |
1477 | //======================================================================= |
1478 | //function : QAv2dcircle |
1479 | //purpose : |
1480 | //======================================================================= |
1481 | static Standard_Integer QAv2dcircle (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
1482 | { |
1483 | Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext(); |
1484 | if(aContext.IsNull()) { |
1485 | di << "ERROR: Use 'v2dinit' command before " << argv[0] << "\n"; |
1486 | return -1; |
1487 | } |
1488 | if(argc < 7){ |
1489 | di<<"Usage : " << argv[0] << " CircleName X Y Radius Alpha Beta [Color_index]\n"; |
1490 | return -1; |
1491 | } |
1492 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
1493 | |
1494 | TCollection_AsciiString name = argv[1]; |
1495 | Standard_Real x = atof(argv[2]); |
1496 | Standard_Real y = atof(argv[3]); |
1497 | Standard_Real radius = atof(argv[4]); |
1498 | Standard_Real alpha = atof(argv[5]); |
1499 | Standard_Real beta = atof(argv[6]); |
1500 | |
1501 | if (GetMapOfAIS2D().IsBound2(name)) { |
1502 | di << "There is already an object with name " << name.ToCString() << "\n"; |
1503 | return -1; |
1504 | } |
1505 | Handle(AIS2D_InteractiveObject) aisobj = new AIS2D_InteractiveObject(); |
1506 | aisobj->SetView(V->View()); |
1507 | Handle(Graphic2d_Circle) circle = new Graphic2d_Circle(aisobj,x,y,radius,alpha,beta); |
1508 | if(argc > 7){ |
1509 | Standard_Integer color_index = atoi(argv[7]); |
1510 | circle->SetTypeOfPolygonFilling(Graphic2d_TOPF_FILLED); |
1511 | circle->SetInteriorColorIndex(color_index); |
1512 | } |
1513 | GetMapOfAIS2D().Bind(aisobj, name); |
1514 | aisobj->Display(); |
1515 | V->Viewer()->Update(); |
1516 | return 0; |
1517 | } |
1518 | |
1519 | #include <Draw_Viewer.hxx> |
1520 | #include <Draw.hxx> |
1521 | |
1522 | #ifndef WNT |
1523 | extern Draw_Viewer dout; |
1524 | #else |
1525 | Standard_IMPORT Draw_Viewer dout; |
1526 | #endif |
1527 | |
1528 | static Standard_Integer ViewId(const Standard_CString a) |
1529 | { |
1530 | Standard_Integer id = atoi(a); |
1531 | if ((id < 0) || (id >= MAXVIEW)) { |
1532 | cout << "Incorrect view-id, must be in 0.."<<MAXVIEW-1<<endl; |
1533 | return -1; |
1534 | } |
1535 | if (!dout.HasView(id)) { |
1536 | cout <<"View "<<id<<" does not exist."<<endl; |
1537 | return -1; |
1538 | } |
1539 | return id; |
1540 | } |
1541 | |
1542 | //======================================================================= |
1543 | //function : QAwzoom |
1544 | //purpose : |
1545 | //======================================================================= |
1546 | |
1547 | static Standard_Integer QAwzoom(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) { |
1548 | if(argc < 6){ |
1549 | di<<"Usage : " << argv[0] << " view-id X1 Y1 X2 Y2\n"; |
1550 | return -1; |
1551 | } |
1552 | |
1553 | Standard_Integer id = ViewId(argv [1]); |
1554 | if (id < 0) { |
1555 | return -1; |
1556 | } |
1557 | |
1558 | Standard_Integer X1 = atoi (argv [2]); |
1559 | Standard_Integer Y1 = atoi (argv [3]); |
1560 | Standard_Integer X2 = atoi (argv [4]); |
1561 | Standard_Integer Y2 = atoi (argv [5]); |
1562 | |
1563 | Standard_Real zx,zy; |
1564 | |
1565 | Standard_Integer X,Y,W,H; |
1566 | dout.GetPosSize(id,X,Y,W,H); |
1567 | |
1568 | if ((X1 == X2) || (Y1 == Y2)) return 0; |
1569 | |
1570 | zx = (Standard_Real) Abs(X2-X1) / (Standard_Real) W; |
1571 | zy = (Standard_Real) Abs(Y2-Y1) / (Standard_Real) H; |
1572 | if (zy > zx) zx = zy; |
1573 | zx = 1/zx; |
1574 | if (X2 < X1) X1 = X2; |
1575 | if (Y2 > Y1) Y1 = Y2; |
1576 | X1 = (Standard_Integer ) (X1*zx); |
1577 | Y1 = (Standard_Integer ) (Y1*zx); |
1578 | dout.SetZoom(id,zx*dout.Zoom(id)); |
1579 | dout.SetPan(id,-X1,-Y1); |
1580 | dout.RepaintView(id); |
1581 | if (dout.HasView(id)) { |
1582 | char title[255]; |
1583 | sprintf(title,"%d : %s - Zoom %f",id,dout.GetType(id),dout.Zoom(id)); |
1584 | dout.SetTitle(id,title); |
1585 | } |
1586 | return 0; |
1587 | } |
1588 | |
1589 | #include <Draw_Display.hxx> |
1590 | |
1591 | //======================================================================= |
1592 | //function : QAGetCoordinatesWzoom |
1593 | //purpose : |
1594 | //======================================================================= |
1595 | |
1596 | static Standard_Integer QAGetCoordinatesWzoom(Draw_Interpretor& di, Standard_Integer, const char **) |
1597 | { |
1598 | Standard_Integer id1,X1,Y1,b; |
1599 | Standard_Integer X2,Y2; |
1600 | Standard_Real dX1,dY1,dX2,dY2; |
1601 | di << "Pick first corner"<<"\n"; |
1602 | dout.Select(id1,X1,Y1,b); |
1603 | |
1604 | gp_Trsf T; |
1605 | gp_Pnt P0(0,0,0); |
1606 | dout.GetTrsf(id1,T); |
1607 | T.Invert(); |
1608 | P0.Transform(T); |
1609 | Standard_Real z = dout.Zoom(id1); |
1610 | |
1611 | dX1=X1; dY1=Y1; |
1612 | dX1-=P0.X(); dY1-=P0.Y(); |
1613 | dX1/=z; dY1/=z; |
1614 | |
1615 | if (b != 1) return 0; |
1616 | if (id1 < 0) return 0; |
1617 | Draw_Display d = dout.MakeDisplay(id1); |
1618 | d.SetColor(Draw_blanc); |
1619 | d.SetMode(10); |
1620 | Standard_Real dOX2 = dX1; |
1621 | Standard_Real dOY2 = dY1; |
1622 | d.Draw(gp_Pnt2d(dX1,dY1),gp_Pnt2d(dX1,dOY2)); |
1623 | d.Draw(gp_Pnt2d(dX1,dOY2),gp_Pnt2d(dOX2,dOY2)); |
1624 | d.Draw(gp_Pnt2d(dOX2,dOY2),gp_Pnt2d(dOX2,dY1)); |
1625 | d.Draw(gp_Pnt2d(dOX2,dY1),gp_Pnt2d(dX1,dY1)); |
1626 | d.Flush(); |
1627 | Standard_Real zx,zy; |
1628 | Standard_Integer X,Y,W,H; |
1629 | dout.GetPosSize(id1,X,Y,W,H); |
1630 | di << "Pick second corner"<<"\n"; |
1631 | b = 0; |
1632 | while (b == 0) { |
1633 | dout.Select(id1,X2,Y2,b,Standard_False); |
1634 | dX2=X2; dY2=Y2; |
1635 | dX2-=P0.X(); dY2-=P0.Y(); |
1636 | dX2/=z; dY2/=z; |
1637 | |
1638 | d.Draw(gp_Pnt2d(dX1,dY1),gp_Pnt2d(dX1,dOY2)); |
1639 | d.Draw(gp_Pnt2d(dX1,dOY2),gp_Pnt2d(dOX2,dOY2)); |
1640 | d.Draw(gp_Pnt2d(dOX2,dOY2),gp_Pnt2d(dOX2,dY1)); |
1641 | d.Draw(gp_Pnt2d(dOX2,dY1),gp_Pnt2d(dX1,dY1)); |
1642 | d.Draw(gp_Pnt2d(dX1,dY1),gp_Pnt2d(dX1,dY2)); |
1643 | d.Draw(gp_Pnt2d(dX1,dY2),gp_Pnt2d(dX2,dY2)); |
1644 | d.Draw(gp_Pnt2d(dX2,dY2),gp_Pnt2d(dX2,dY1)); |
1645 | d.Draw(gp_Pnt2d(dX2,dY1),gp_Pnt2d(dX1,dY1)); |
1646 | d.Flush(); |
1647 | dOX2 = dX2; |
1648 | dOY2 = dY2; |
1649 | } |
1650 | d.Draw(gp_Pnt2d(dX1,dY1),gp_Pnt2d(dX1,dOY2)); |
1651 | d.Draw(gp_Pnt2d(dX1,dOY2),gp_Pnt2d(dOX2,dOY2)); |
1652 | d.Draw(gp_Pnt2d(dOX2,dOY2),gp_Pnt2d(dOX2,dY1)); |
1653 | d.Draw(gp_Pnt2d(dOX2,dY1),gp_Pnt2d(dX1,dY1)); |
1654 | d.Flush(); |
1655 | if (b != 1) return 0; |
1656 | |
1657 | if ((X1 == X2) || (Y1 == Y2)) return 0; |
1658 | |
1659 | di << "X1=" << X1 << " Y1=" << Y1 <<"\n"; |
1660 | di << "X2=" << X2 << " Y2=" << Y2 <<"\n"; |
1661 | |
1662 | zx = (Standard_Real) Abs(X2-X1) / (Standard_Real) W; |
1663 | zy = (Standard_Real) Abs(Y2-Y1) / (Standard_Real) H; |
1664 | if (zy > zx) zx = zy; |
1665 | zx = 1/zx; |
1666 | if (X2 < X1) X1 = X2; |
1667 | if (Y2 > Y1) Y1 = Y2; |
1668 | X1 = (Standard_Integer ) (X1*zx); |
1669 | Y1 = (Standard_Integer ) (Y1*zx); |
1670 | dout.SetZoom(id1,zx*dout.Zoom(id1)); |
1671 | dout.SetPan(id1,-X1,-Y1); |
1672 | dout.RepaintView(id1); |
1673 | //SetTitle(id1); |
1674 | char title[255]; |
1675 | sprintf(title,"%d : %s - Zoom %f",id1,dout.GetType(id1),dout.Zoom(id1)); |
1676 | dout.SetTitle(id1,title); |
1677 | return 0; |
1678 | } |
1679 | |
1680 | //======================================================================= |
1681 | // QArename |
1682 | //======================================================================= |
1683 | |
1684 | static Standard_Integer QArename(Draw_Interpretor& di, Standard_Integer n, const char** a) |
1685 | { |
1686 | if (n < 3) return 1; |
1687 | Standard_Boolean cop = !strcasecmp(a[0],"copy"); |
1688 | |
1689 | Handle(Draw_Drawable3D) D; |
1690 | for (Standard_Integer i = 1; i < n; i += 2) { |
1691 | if (i+1 >= n) return 0; |
1692 | D = Draw::Get(a[i]); |
1693 | if (!D.IsNull()) { |
1694 | if (cop) |
1695 | D = D->Copy(); |
1696 | else |
1697 | // clear old name |
1698 | Draw::Set(a[i],Handle(Draw_Drawable3D())); |
1699 | |
1700 | Draw::Set(a[i+1],D); |
1701 | } |
1702 | } |
1703 | return 0; |
1704 | } |
1705 | |
1706 | static Standard_Integer QANbSelected (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
1707 | { |
1708 | if(argc != 1) { |
1709 | di << "Usage : " << argv[0] << "\n"; |
1710 | return 1; |
1711 | } |
1712 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
1713 | if(aContext.IsNull()) { |
1714 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1715 | return 1; |
1716 | } |
1717 | di << aContext->NbSelected() << "\n"; |
1718 | return 0; |
1719 | } |
1720 | |
1721 | //#if defined(V2D) |
1722 | //#include <AIS2D_InteractiveContext.hxx> |
1723 | //static Standard_Integer QANbSelected2d (Draw_Interpretor& /*di*/, Standard_Integer argc, char** argv) |
1724 | //{ |
1725 | // if(argc != 1) { |
1726 | // cout << "Usage : " << argv[0] << endl; |
1727 | // return 1; |
1728 | // } |
1729 | // Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext(); |
1730 | // if(aContext.IsNull()) { |
1731 | // cerr << "use 'v2dinit' command before " << argv[0] << endl; |
1732 | // return 1; |
1733 | // } |
1734 | // cout << aContext->NbSelected() << endl; |
1735 | // return 0; |
1736 | //} |
1737 | //#endif |
1738 | |
1739 | static Standard_Integer QAPurgeDisplay (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
1740 | { |
1741 | if (argc > 2) { |
1742 | di << "Usage : " << argv[0] << " [CollectorToo=0/1]" << "\n"; |
1743 | return 1; |
1744 | } |
1745 | Standard_Boolean CollectorTooBoolean = Standard_False; |
1746 | if (argc == 2) { |
1747 | Standard_Integer CollectorTooInteger = atoi (argv [1]); |
1748 | if (CollectorTooInteger != 0) |
1749 | CollectorTooBoolean = Standard_True; |
1750 | } |
1751 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
1752 | if (aContext.IsNull()) { |
1753 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1754 | return 1; |
1755 | } |
1756 | aContext->CloseAllContexts(Standard_False); |
1757 | di << aContext->PurgeDisplay(CollectorTooBoolean) << "\n"; |
1758 | return 0; |
1759 | } |
1760 | |
1761 | static Standard_Integer QACloseLocalContext (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
1762 | { |
1763 | if (argc > 3) { |
1764 | di << "Usage : " << argv[0] << " [Index [updateviewer=1/0]]" << "\n"; |
1765 | return 1; |
1766 | } |
1767 | Standard_Integer Index = -1; |
1768 | if (argc > 1) { |
1769 | Index = atoi (argv [1]); |
1770 | } |
1771 | //cout << "Index = " << Index << endl; |
1772 | Standard_Boolean updateviewerBoolean = Standard_True; |
1773 | if (argc == 3) { |
1774 | Standard_Integer updateviewerInteger = atoi (argv [2]); |
1775 | if (updateviewerInteger == 0) |
1776 | updateviewerBoolean = Standard_False; |
1777 | } |
1778 | //if (updateviewerBoolean) |
1779 | // cout << "updateviewer = Standard_True" << endl; |
1780 | //else |
1781 | // cout << "updateviewer = Standard_False" << endl; |
1782 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
1783 | if (aContext.IsNull()) { |
1784 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1785 | return 1; |
1786 | } |
1787 | aContext->CloseLocalContext(Index, updateviewerBoolean); |
1788 | return 0; |
1789 | } |
1790 | |
1791 | static Standard_Integer QACloseAllContexts (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
1792 | { |
1793 | if (argc > 2) { |
1794 | di << "Usage : " << argv[0] << " [updateviewer=1/0]" << "\n"; |
1795 | return 1; |
1796 | } |
1797 | Standard_Boolean updateviewerBoolean = Standard_True; |
1798 | if (argc == 2) { |
1799 | Standard_Integer updateviewerInteger = atoi (argv [1]); |
1800 | if (updateviewerInteger == 0) |
1801 | updateviewerBoolean = Standard_False; |
1802 | } |
1803 | //if (updateviewerBoolean) |
1804 | // cout << "updateviewer = Standard_True" << endl; |
1805 | //else |
1806 | // cout << "updateviewer = Standard_False" << endl; |
1807 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
1808 | if (aContext.IsNull()) { |
1809 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1810 | return 1; |
1811 | } |
1812 | aContext->CloseAllContexts(updateviewerBoolean); |
1813 | return 0; |
1814 | } |
1815 | |
1816 | static Standard_Integer QAIndexOfCurrentLocal (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
1817 | { |
1818 | if (argc > 1) { |
1819 | di << "Usage : " << argv[0] << "\n"; |
1820 | return 1; |
1821 | } |
1822 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
1823 | if (aContext.IsNull()) { |
1824 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1825 | return 1; |
1826 | } |
1827 | di << aContext->IndexOfCurrentLocal() << "\n"; |
1828 | return 0; |
1829 | } |
1830 | |
1831 | #include <AIS_ListOfInteractive.hxx> |
1832 | static Standard_Integer QADisplayedObjects (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
1833 | { |
1834 | if (argc > 2) { |
1835 | di << "Usage : " << argv[0] << " [OnlyFromNeutral=0/1]" << "\n"; |
1836 | return 1; |
1837 | } |
1838 | |
1839 | Standard_Boolean OnlyFromNeutralBoolean = Standard_False; |
1840 | if (argc == 2) { |
1841 | Standard_Integer OnlyFromNeutralInteger = atoi (argv [1]); |
1842 | if (OnlyFromNeutralInteger != 0) |
1843 | OnlyFromNeutralBoolean = Standard_True; |
1844 | } |
1845 | //if (OnlyFromNeutralBoolean) |
1846 | // cout << "OnlyFromNeutral = Standard_True" << endl; |
1847 | //else |
1848 | // cout << "OnlyFromNeutral = Standard_False" << endl; |
1849 | |
1850 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
1851 | if (aContext.IsNull()) { |
1852 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1853 | return 1; |
1854 | } |
1855 | Standard_Integer ListOfInteractiveExtent = 0; |
1856 | if(!aContext->HasOpenedContext()) { |
1857 | ListOfInteractiveExtent = 0; |
1858 | } else { |
1859 | AIS_ListOfInteractive ListOfInteractive; |
1860 | aContext->DisplayedObjects(ListOfInteractive, OnlyFromNeutralBoolean); |
1861 | ListOfInteractiveExtent = ListOfInteractive.Extent(); |
1862 | } |
1863 | di << ListOfInteractiveExtent << "\n"; |
1864 | return 0; |
1865 | } |
1866 | |
1867 | static Standard_Integer QASelectRectangle(Draw_Interpretor& di, Standard_Integer argc, const char ** argv ) |
1868 | { |
1869 | if(argc != 5) { |
1870 | di << "Usage : " << argv[0] << " x1 y1 x2 y2" << "\n"; |
1871 | return -1; |
1872 | } |
1873 | |
1874 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); |
1875 | if(myAIScontext.IsNull()) { |
1876 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1877 | return -1; |
1878 | } |
1879 | |
1880 | Standard_Integer x1 = atoi(argv[1]); |
1881 | Standard_Integer y1 = atoi(argv[2]); |
1882 | Standard_Integer x2 = atoi(argv[3]); |
1883 | Standard_Integer y2 = atoi(argv[4]); |
1884 | |
1885 | Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); |
1886 | // Handle(V3d_View) aCurrentView = ViewerTest::CurrentView(); |
1887 | |
1888 | aCurrentEventManager->MoveTo(x1,y1); |
1889 | aCurrentEventManager->Select(x1,y1,x2,y2); |
1890 | aCurrentEventManager->MoveTo(x2,y2); |
1891 | |
1892 | return 0; |
1893 | } |
1894 | |
1895 | static Standard_Integer QAShiftSelectRectangle(Draw_Interpretor& di, Standard_Integer argc, const char ** argv ) |
1896 | { |
1897 | if(argc != 5) { |
1898 | di << "Usage : " << argv[0] << " x1 y1 x2 y2" << "\n"; |
1899 | return -1; |
1900 | } |
1901 | |
1902 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); |
1903 | if(myAIScontext.IsNull()) { |
1904 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1905 | return -1; |
1906 | } |
1907 | Standard_Integer x1 = atoi(argv[1]); |
1908 | Standard_Integer y1 = atoi(argv[2]); |
1909 | Standard_Integer x2 = atoi(argv[3]); |
1910 | Standard_Integer y2 = atoi(argv[4]); |
1911 | |
1912 | Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); |
1913 | // Handle(V3d_View) aCurrentView = ViewerTest::CurrentView(); |
1914 | |
1915 | aCurrentEventManager->MoveTo(x1,y1); |
1916 | aCurrentEventManager->ShiftSelect(x1,y1,x2,y2); |
1917 | aCurrentEventManager->MoveTo(x2,y2); |
1918 | |
1919 | return 0; |
1920 | } |
1921 | |
1922 | static int QASelect2dRectangle (Draw_Interpretor& di, int argc, const char ** argv) |
1923 | { |
1924 | if (argc != 5) |
1925 | { |
1926 | di << "Usage : " << argv[0] << " x1 y1 x2 y2" << "\n"; |
1927 | return -1; |
1928 | } |
1929 | |
1930 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
1931 | if (myAIScontext.IsNull()) |
1932 | { |
1933 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
1934 | return -1; |
1935 | } |
1936 | |
1937 | Standard_Integer x1 = atoi(argv[1]); |
1938 | Standard_Integer y1 = atoi(argv[2]); |
1939 | Standard_Integer x2 = atoi(argv[3]); |
1940 | Standard_Integer y2 = atoi(argv[4]); |
1941 | |
1942 | Handle(Viewer2dTest_EventManager) aCurrentEventManager = Viewer2dTest::CurrentEventManager(); |
1943 | Handle(V2d_View) aCurrentView = Viewer2dTest::CurrentView(); |
1944 | |
1945 | aCurrentEventManager->MoveTo(x1,y1,aCurrentView); |
1946 | aCurrentEventManager->Select(x1,y1,x2,y2,aCurrentView); |
1947 | aCurrentEventManager->MoveTo(x2,y2,aCurrentView); |
1948 | |
1949 | return 0; |
1950 | } |
1951 | |
1952 | static int QAShiftSelect2dRectangle (Draw_Interpretor& di, int argc, const char ** argv) |
1953 | { |
1954 | if (argc != 5) |
1955 | { |
1956 | di << "Usage : " << argv[0] << " x1 y1 x2 y2" << "\n"; |
1957 | return -1; |
1958 | } |
1959 | |
1960 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
1961 | if (myAIScontext.IsNull()) |
1962 | { |
1963 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
1964 | return -1; |
1965 | } |
1966 | |
1967 | Standard_Integer x1 = atoi(argv[1]); |
1968 | Standard_Integer y1 = atoi(argv[2]); |
1969 | Standard_Integer x2 = atoi(argv[3]); |
1970 | Standard_Integer y2 = atoi(argv[4]); |
1971 | |
1972 | Handle(Viewer2dTest_EventManager) aCurrentEventManager = Viewer2dTest::CurrentEventManager(); |
1973 | Handle(V2d_View) aCurrentView = Viewer2dTest::CurrentView(); |
1974 | |
1975 | aCurrentEventManager->MoveTo(x1,y1,aCurrentView); |
1976 | aCurrentEventManager->ShiftSelect(x1,y1,x2,y2,aCurrentView); |
1977 | aCurrentEventManager->MoveTo(x2,y2,aCurrentView); |
1978 | |
1979 | return 0; |
1980 | } |
1981 | |
1982 | //======================================================================= |
1983 | //function : QARotateV3dView |
1984 | //purpose : |
1985 | //======================================================================= |
1986 | static Standard_Integer QARotateV3dView (Draw_Interpretor& di, int argc, const char ** argv) |
1987 | { |
1988 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
1989 | if(AIScontext.IsNull()) { |
1990 | di << "use 'vinit' command before " << argv[0] << "\n"; |
1991 | return -1; |
1992 | } |
1993 | if(argc < 4 || argc > 5){ |
1994 | di<<"Usage : " << argv[0] << " Ax Ay Az [Start(1/0)]\n"; |
1995 | return -1; |
1996 | } |
1997 | Standard_Real Ax = atof(argv[1]); |
1998 | Standard_Real Ay = atof(argv[2]); |
1999 | Standard_Real Az = atof(argv[3]); |
2000 | Standard_Boolean Start = Standard_True; |
2001 | if (argc == 5) { |
2002 | Standard_Integer StartInteger = atoi(argv[4]); |
2003 | if (StartInteger > 0) { |
2004 | Start = Standard_True; |
2005 | } else { |
2006 | Start = Standard_False; |
2007 | } |
2008 | } |
2009 | |
2010 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2011 | aView->Rotate(Ax,Ay,Az,Start); |
2012 | return 0; |
2013 | } |
2014 | |
2015 | //======================================================================= |
2016 | //function : QAMoveV3dView |
2017 | //purpose : |
2018 | //======================================================================= |
2019 | static Standard_Integer QAMoveV3dView (Draw_Interpretor& di, int argc, const char ** argv) |
2020 | { |
2021 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
2022 | if(AIScontext.IsNull()) { |
2023 | di << "use 'vinit' command before " << argv[0] << "\n"; |
2024 | return -1; |
2025 | } |
2026 | if(argc < 4 || argc > 5){ |
2027 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start(1/0)]\n"; |
2028 | return -1; |
2029 | } |
2030 | Standard_Real Dx = atof(argv[1]); |
2031 | Standard_Real Dy = atof(argv[2]); |
2032 | Standard_Real Dz = atof(argv[3]); |
2033 | Standard_Boolean Start = Standard_True; |
2034 | if (argc == 5) { |
2035 | Standard_Integer StartInteger = atoi(argv[4]); |
2036 | if (StartInteger > 0) { |
2037 | Start = Standard_True; |
2038 | } else { |
2039 | Start = Standard_False; |
2040 | } |
2041 | } |
2042 | |
2043 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2044 | aView->Move(Dx,Dy,Dz,Start); |
2045 | return 0; |
2046 | } |
2047 | |
2048 | //======================================================================= |
2049 | //function : QATranslateV3dView |
2050 | //purpose : |
2051 | //======================================================================= |
2052 | static Standard_Integer QATranslateV3dView (Draw_Interpretor& di, int argc, const char ** argv) |
2053 | { |
2054 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
2055 | if(AIScontext.IsNull()) { |
2056 | di << "use 'vinit' command before " << argv[0] << "\n"; |
2057 | return -1; |
2058 | } |
2059 | if(argc < 4 || argc > 5){ |
2060 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start(1/0)]\n"; |
2061 | return -1; |
2062 | } |
2063 | Standard_Real Dx = atof(argv[1]); |
2064 | Standard_Real Dy = atof(argv[2]); |
2065 | Standard_Real Dz = atof(argv[3]); |
2066 | Standard_Boolean Start = Standard_True; |
2067 | if (argc == 5) { |
2068 | Standard_Integer StartInteger = atoi(argv[4]); |
2069 | if (StartInteger > 0) { |
2070 | Start = Standard_True; |
2071 | } else { |
2072 | Start = Standard_False; |
2073 | } |
2074 | } |
2075 | |
2076 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2077 | aView->Translate(Dx,Dy,Dz,Start); |
2078 | return 0; |
2079 | } |
2080 | |
2081 | //======================================================================= |
2082 | //function : QATurnV3dView |
2083 | //purpose : |
2084 | //======================================================================= |
2085 | static Standard_Integer QATurnV3dView (Draw_Interpretor& di, int argc, const char ** argv) |
2086 | { |
2087 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
2088 | if(AIScontext.IsNull()) { |
2089 | di << "use 'vinit' command before " << argv[0] << "\n"; |
2090 | return -1; |
2091 | } |
2092 | if(argc < 4 || argc > 5){ |
2093 | di<<"Usage : " << argv[0] << " Ax Ay Az [Start(1/0)]\n"; |
2094 | return -1; |
2095 | } |
2096 | Standard_Real Ax = atof(argv[1]); |
2097 | Standard_Real Ay = atof(argv[2]); |
2098 | Standard_Real Az = atof(argv[3]); |
2099 | Standard_Boolean Start = Standard_True; |
2100 | if (argc == 5) { |
2101 | Standard_Integer StartInteger = atoi(argv[4]); |
2102 | if (StartInteger > 0) { |
2103 | Start = Standard_True; |
2104 | } else { |
2105 | Start = Standard_False; |
2106 | } |
2107 | } |
2108 | |
2109 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2110 | aView->Turn(Ax,Ay,Az,Start); |
2111 | return 0; |
2112 | } |
2113 | |
2114 | //======================================================================= |
2115 | //function : QAPanningV3dView |
2116 | //purpose : |
2117 | //======================================================================= |
2118 | static Standard_Integer QAPanningV3dView (Draw_Interpretor& di, int argc, const char ** argv) |
2119 | { |
2120 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
2121 | if(AIScontext.IsNull()) { |
2122 | di << "use 'vinit' command before " << argv[0] << "\n"; |
2123 | return -1; |
2124 | } |
2125 | if(argc < 3 || argc > 5){ |
2126 | di<<"Usage : " << argv[0] << " Dx Dy [Zoom [Start(1/0)]]\n"; |
2127 | return -1; |
2128 | } |
2129 | Standard_Real Dx = atof(argv[1]); |
2130 | Standard_Real Dy = atof(argv[2]); |
2131 | Standard_Real Zoom = 1.; |
2132 | if (argc > 3) { |
2133 | Zoom = atof(argv[3]); |
2134 | if (Zoom <= 0.) { |
2135 | di<<"Bad Zoom value : " << Zoom << "\n"; |
2136 | return -1; |
2137 | } |
2138 | } |
2139 | Standard_Boolean Start = Standard_True; |
2140 | if (argc == 5) { |
2141 | Standard_Integer StartInteger = atoi(argv[4]); |
2142 | if (StartInteger > 0) { |
2143 | Start = Standard_True; |
2144 | } else { |
2145 | Start = Standard_False; |
2146 | } |
2147 | } |
2148 | |
2149 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2150 | aView->Panning(Dx,Dy,Zoom,Start); |
2151 | return 0; |
2152 | } |
2153 | |
2154 | //======================================================================= |
2155 | //function : QASetZoomV3dView |
2156 | //purpose : |
2157 | //======================================================================= |
2158 | static Standard_Integer QASetZoomV3dView (Draw_Interpretor& di, int argc, const char ** argv) |
2159 | { |
2160 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
2161 | if(AIScontext.IsNull()) { |
2162 | di << "use 'vinit' command before " << argv[0] << "\n"; |
2163 | return -1; |
2164 | } |
2165 | if(argc < 2 || argc > 3){ |
2166 | di<<"Usage : " << argv[0] << " Zoom [Start(1/0)]\n"; |
2167 | return -1; |
2168 | } |
2169 | Standard_Real Zoom = atof(argv[1]); |
2170 | if (Zoom <= 0.) { |
2171 | di<<"Bad Zoom value : " << Zoom << "\n"; |
2172 | return -1; |
2173 | } |
2174 | Standard_Boolean Start = Standard_True; |
2175 | if (argc == 3) { |
2176 | Standard_Integer StartInteger = atoi(argv[2]); |
2177 | if (StartInteger > 0) { |
2178 | Start = Standard_True; |
2179 | } else { |
2180 | Start = Standard_False; |
2181 | } |
2182 | } |
2183 | |
2184 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2185 | aView->SetZoom(Zoom,Start); |
2186 | return 0; |
2187 | } |
2188 | |
2189 | //======================================================================= |
2190 | //function : QASetSizeV3dView |
2191 | //purpose : |
2192 | //======================================================================= |
2193 | static Standard_Integer QASetSizeV3dView (Draw_Interpretor& di, int argc, const char ** argv) |
2194 | { |
2195 | Handle(AIS_InteractiveContext) AIScontext = ViewerTest::GetAISContext(); |
2196 | if(AIScontext.IsNull()) { |
2197 | di << "use 'vinit' command before " << argv[0] << "\n"; |
2198 | return -1; |
2199 | } |
2200 | if(argc != 2){ |
2201 | di<<"Usage : " << argv[0] << " Size\n"; |
2202 | return -1; |
2203 | } |
2204 | Standard_Real Size = atof(argv[1]); |
2205 | if (Size <= 0.) { |
2206 | di<<"Bad Size value : " << Size << "\n"; |
2207 | return -1; |
2208 | } |
2209 | |
2210 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2211 | aView->SetSize(Size); |
2212 | return 0; |
2213 | } |
2214 | |
2215 | void QADraw::CommonCommands(Draw_Interpretor& theCommands) |
2216 | { |
2217 | ios::sync_with_stdio(); |
2218 | |
2219 | st_err = dup(STDERR_FILENO); |
2220 | |
2221 | Draw_BeforeCommand_old = Draw_BeforeCommand; |
2222 | Draw_AfterCommand_old = Draw_AfterCommand; |
2223 | |
2224 | Draw_BeforeCommand = &before; |
2225 | Draw_AfterCommand = &after; |
2226 | |
2227 | const char* group = "QA_Commands"; |
2228 | |
2229 | theCommands.Add("QARebuild","QARebuild command_name",__FILE__,QARebuild,group); |
2230 | theCommands.Add("QAxwd_3d","QAxwd_3d filename",__FILE__,QAxwd_3d,group); |
2231 | theCommands.Add("QAMoveTo","QAMoveTo x y",__FILE__,QAMoveTo,group); |
2232 | theCommands.Add("QASelect","QASelect x y",__FILE__,QASelect,group); |
2233 | theCommands.Add("QAShiftSelect","QAShiftSelect x y",__FILE__,QAShiftSelect,group); |
2234 | theCommands.Add("QAUpdateLights","QAUpdateLights",__FILE__,QAUpdateLights,group); |
2235 | theCommands.Add("QASetAntialiasing","QASetAntialiasing [1/0]",__FILE__,QASetAntialiasing,group); |
2236 | theCommands.Add("QAvzfit","QAvzfit",__FILE__,QAvzfit,group); |
2237 | theCommands.Add("QAGetPixelColor", "QAGetPixelColor coordinate_X coordinate_Y [color_R color_G color_B]", __FILE__,QAAISGetPixelColor, group); |
2238 | theCommands.Add("QASetChoiceMode", "QASetChoiceMode mode switch ; Use without params to see a help ", __FILE__,QAAISSetChoiceMode, group); |
2239 | theCommands.Add("QAGetMousePoint", "QAGetMousePoint", __FILE__,QAAISGetMousePoint, group); |
2240 | theCommands.Add("QAGetViewCharac", "QAGetViewCharac", __FILE__,QAAISGetViewCharac, group); |
2241 | 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); |
2242 | theCommands.Add("QAGetColorCoord", "QAGetColorCoord [3d|2d]", __FILE__,QAAISGetColorCoord, group); |
2243 | #ifndef WNT |
2244 | theCommands.Add("QAAISGetPixelColor2d", |
2245 | "QAAISGetPixelColor2d coord_X coord_Y [Red Green Blue] : Check a color of pixel", |
2246 | __FILE__, QAAISGetPixelColor2d, group); |
2247 | #endif |
2248 | |
2249 | theCommands.Add("v2dgetgrid", |
2250 | "v2dgetgrid coord_X coord_Y [grid_X grid_Y] : Get/print coordinates of a grid point near to (coord_X, coord_Y)", |
2251 | __FILE__, V2dPickGrid, group); |
2252 | |
2253 | theCommands.Add("QAv2dzoom", |
2254 | "QAv2dzoom zoom_factor : Set Scale Factor", |
2255 | __FILE__, V2dZoom, group); |
2256 | |
2257 | theCommands.Add("QAv2dpan", |
2258 | "QAv2dpan dx dy : script analog of Ctrl+MB2", |
2259 | __FILE__, V2dPan, group); |
2260 | |
2261 | // theCommands.Add("QAGetViewCharac2d", |
2262 | // "QAGetViewCharac2d - dumps viewer characteristics", |
2263 | // V2dGetViewCharac, group); |
2264 | |
2265 | // theCommands.Add("QASetViewCharac2d", |
2266 | // "QASetViewCharac2d scale center(X Y) proj(X Y Z) up(X Y Z) at(X Y Z)", |
2267 | // V2dSetViewCharac, group); |
2268 | |
2269 | theCommands.Add("QAMoveTo2d", "QAMoveTo2d x y", __FILE__, QAMoveTo2d, group); |
2270 | theCommands.Add("QASelect2d", "QASelect2d x y", __FILE__, QASelect2d, group); |
2271 | theCommands.Add("QAShiftSelect2d", "QAShiftSelect2d x y", __FILE__, QAShiftSelect2d, group); |
2272 | |
2273 | theCommands.Add("QAv2dSetHighlightMode", |
2274 | "QAv2dSetHighlightMode mode", __FILE__, V2dSetHighlightMode, group); |
2275 | |
2276 | theCommands.Add("QAxwd_2d", "QAxwd_2d filename", __FILE__, QAxwd_2d, group); |
2277 | |
2278 | theCommands.Add("QAxwd", "QAxwd [id=1] filename", __FILE__, QAxwd, group); |
2279 | |
2280 | theCommands.Add("QA2dGetIndexes", "QA2dGetIndexes", __FILE__, QA2dGetIndexes, group); |
2281 | |
2282 | theCommands.Add("vtri_orig", |
2283 | "vtri_orig : vtri_orig trihedron_name - draws axis origin lines", |
2284 | __FILE__,VTrihedronOrigins,group); |
2285 | |
2286 | theCommands.Add("QAAddOrRemoveSelected", |
2287 | "QAAddOrRemoveSelected shape : selects the shape by AddOrRemoveSelected method", |
2288 | __FILE__, QAAddOrRemoveSelected, group); |
2289 | |
2290 | theCommands.Add("QASetZClippingMode","QASetZClippingMode mode(OFF/BACK/FRONT/SLICE)",__FILE__,QASetZClippingMode,group); |
2291 | theCommands.Add("QAGetZClippingMode","QAGetZClippingMode",__FILE__,QAGetZClippingMode,group); |
2292 | theCommands.Add("QAv2dcircle", "QAv2dcircle CircleName X Y Radius Alpha Beta [Color_index]", __FILE__, QAv2dcircle, group); |
2293 | |
2294 | theCommands.Add("QAwzoom","QAwzoom view-id X1 Y1 X2 Y2; zoom on a window",__FILE__,QAwzoom,group); |
2295 | theCommands.Add("QAGetCoordinatesWzoom","QAGetCoordinatesWzoom ; Get coordinates for zoom on a window",__FILE__,QAGetCoordinatesWzoom,group); |
2296 | |
319e4241 |
2297 | // adding commands "rename" leads to the fact that QA commands doesn't work properly OCC23410, use function "renamevar" |
2298 | // theCommands.Add("rename","rename name1 toname1 name2 toname2 ...",__FILE__,QArename,group); |
7fd59977 |
2299 | |
2300 | theCommands.Add ("QANbSelected", "QANbSelected", __FILE__, QANbSelected, group); |
2301 | //#if defined(V2D) |
2302 | // theCommands.Add ("QANbSelected2d", "QANbSelected2d", __FILE__, QANbSelected2d, group); |
2303 | //#endif |
2304 | |
2305 | theCommands.Add ("QAPurgeDisplay", "QAPurgeDisplay [CollectorToo=0/1]", __FILE__, QAPurgeDisplay, group); |
2306 | theCommands.Add ("QACloseLocalContext", "QACloseLocalContext [Index [updateviewer=1/0]]", __FILE__, QACloseLocalContext, group); |
2307 | theCommands.Add ("QACloseAllContexts", "QACloseAllContexts [updateviewer=1/0]", __FILE__, QACloseAllContexts, group); |
2308 | theCommands.Add ("QAIndexOfCurrentLocal", "QAIndexOfCurrentLocal", __FILE__, QAIndexOfCurrentLocal, group); |
2309 | theCommands.Add ("QADisplayedObjects", "QADisplayedObjects [OnlyFromNeutral=0/1]", __FILE__, QADisplayedObjects, group); |
2310 | |
2311 | theCommands.Add("QASelectRectangle","QASelectRectangle x1 y1 x2 y2",__FILE__,QASelectRectangle,group); |
2312 | theCommands.Add("QAShiftSelectRectangle","QAShiftSelectRectangle x1 y1 x2 y2",__FILE__,QAShiftSelectRectangle,group); |
2313 | theCommands.Add("QASelect2dRectangle","QASelect2dRectangle x1 y1 x2 y2",__FILE__,QASelect2dRectangle,group); |
2314 | theCommands.Add("QAShiftSelect2dRectangle","QAShiftSelect2dRectangle x1 y1 x2 y2",__FILE__,QAShiftSelect2dRectangle,group); |
2315 | |
2316 | theCommands.Add("QARotateV3dView","QARotateV3dView Ax Ay Az [Start(1/0)]",__FILE__,QARotateV3dView,group); |
2317 | theCommands.Add("QAMoveV3dView","QAMoveV3dView Dx Dy Dz [Start(1/0)]",__FILE__,QAMoveV3dView,group); |
2318 | theCommands.Add("QATranslateV3dView","QATranslateV3dView Dx Dy Dz [Start(1/0)]",__FILE__,QATranslateV3dView,group); |
2319 | theCommands.Add("QATurnV3dView","QATurnV3dView Ax Ay Az [Start(1/0)]",__FILE__,QATurnV3dView,group); |
2320 | theCommands.Add("QAPanningV3dView","QAPanningV3dView Dx Dy [Zoom [Start(1/0)]]",__FILE__,QAPanningV3dView,group); |
2321 | theCommands.Add("QASetZoomV3dView","QASetZoomV3dView Zoom [Start(1/0)]",__FILE__,QASetZoomV3dView,group); |
2322 | theCommands.Add("QASetSizeV3dView","QASetSizeV3dView Size",__FILE__,QASetSizeV3dView,group); |
2323 | } |
2324 | /* |
2325 | extern "C" int Tkqadraw_Init(Tcl_Interp *); |
2326 | |
2327 | int Tkqadraw_Init(Tcl_Interp * ) { |
2328 | |
2329 | ios::sync_with_stdio(); |
2330 | |
2331 | QADraw::CommonCommands(theCommands); |
2332 | QADraw::AdditionalCommands(theCommands); |
2333 | |
2334 | ViewerTest::Commands (theCommands); |
2335 | ViewerTest::ViewerCommands (theCommands); |
2336 | |
2337 | Viewer2dTest::Commands(theCommands); |
2338 | // if (Tcl_PkgProvide(theCommands.Interp(), "Qa", "1.0") != TCL_OK) { |
2339 | // return TCL_ERROR; |
2340 | // } |
2341 | |
2342 | return TCL_OK; |
2343 | } |
2344 | */ |
2345 | //============================================================================== |
2346 | // QADraw::Factory |
2347 | //============================================================================== |
2348 | void QADraw::Factory(Draw_Interpretor& theCommands) |
2349 | { |
2350 | thePCommands = &theCommands; |
2351 | |
2352 | // definition of QA Command |
2353 | QADraw::CommonCommands(theCommands); |
2354 | QADraw::AdditionalCommands(theCommands); |
2355 | |
2356 | //ViewerTest::Commands (theCommands); |
2357 | //ViewerTest::ViewerCommands (theCommands); |
2358 | |
2359 | //#if defined(V2D) |
2360 | // Viewer2dTest::Commands(theCommands); |
2361 | //#endif |
2362 | |
2363 | //#ifdef DEB |
2364 | // cout << "Draw Plugin : QA commands are loaded" << endl; |
2365 | //#endif |
2366 | } |
2367 | |
2368 | // Declare entry point PLUGINFACTORY |
2369 | DPLUGIN(QADraw) |