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 | |
692613e5 |
309 | Handle(TColStd_HSequenceOfReal) GetColorOfPixel (const Image_PixMap& theImage, |
7fd59977 |
310 | const Standard_Integer theCoordinateX, |
311 | const Standard_Integer theCoordinateY, |
312 | const Standard_Integer theRadius) |
313 | { |
314 | Handle(TColStd_HSequenceOfReal) aSeq = new TColStd_HSequenceOfReal(); |
692613e5 |
315 | if (theImage.IsEmpty()) { |
7fd59977 |
316 | std::cerr << "The image is null.\n"; |
317 | return aSeq; |
318 | } |
692613e5 |
319 | Standard_Integer aWidth = (Standard_Integer )theImage.SizeX(); |
320 | Standard_Integer anHeight = (Standard_Integer )theImage.SizeY(); |
7fd59977 |
321 | |
322 | Quantity_Color aColorTmp; |
323 | for (Standard_Integer anXIter = theCoordinateX - theRadius; |
324 | anXIter <= theCoordinateX + theRadius; ++anXIter) |
325 | { |
326 | if (anXIter < 0 || anXIter >= aWidth) |
327 | { |
328 | continue; |
329 | } |
330 | for (Standard_Integer anYIter = theCoordinateY - theRadius; |
331 | anYIter <= theCoordinateY + theRadius; ++anYIter) |
332 | { |
333 | if (anYIter < 0 || anYIter >= anHeight) |
334 | { |
335 | continue; |
336 | } |
337 | // Image_PixMap stores image upside-down in memory! |
692613e5 |
338 | aColorTmp = theImage.PixelColor (anXIter, anYIter); |
7fd59977 |
339 | aSeq->Append (aColorTmp.Red()); |
340 | aSeq->Append (aColorTmp.Green()); |
341 | aSeq->Append (aColorTmp.Blue()); |
342 | } |
343 | } |
344 | return aSeq; |
345 | } |
346 | |
792c785c |
347 | static Standard_Integer QAAISGetPixelColor (Draw_Interpretor& theDi, |
348 | Standard_Integer theArgsNb, |
349 | const char** theArgs) |
7fd59977 |
350 | { |
4754e164 |
351 | if (theArgsNb != 3 && theArgsNb != 6) |
352 | { |
353 | theDi << "Usage : " << theArgs[0] << " coordinate_X coordinate_Y [color_R color_G color_B]" << "\n"; |
354 | return 1; // TCL_ERROR |
355 | } |
356 | |
357 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); |
358 | if (aView3d.IsNull()) |
359 | { |
360 | theDi << "You must initialize AISViewer before this command.\n"; |
361 | return 1; // TCL_ERROR |
362 | } |
363 | |
364 | const Handle(Aspect_Window) anAISWindow = aView3d->Window(); |
365 | Standard_Integer aWindowSizeX = 0; |
366 | Standard_Integer aWindowSizeY = 0; |
367 | anAISWindow->Size (aWindowSizeX, aWindowSizeY); |
368 | |
369 | Standard_Integer anArgIter = 1; |
370 | const Standard_Integer aPickCoordX = atoi (theArgs[anArgIter++]); |
371 | const Standard_Integer aPickCoordY = atoi (theArgs[anArgIter++]); |
372 | const Standard_Integer aRadius = (theArgsNb == 3) ? 0 : 1; |
373 | |
374 | Image_ColorRGBF aColorInput = {{ 0.0f, 0.0f, 0.0f }}; |
375 | if (theArgsNb == 6) |
376 | { |
377 | aColorInput.r() = (Standard_ShortReal )atof (theArgs[anArgIter++]); |
378 | aColorInput.g() = (Standard_ShortReal )atof (theArgs[anArgIter++]); |
379 | aColorInput.b() = (Standard_ShortReal )atof (theArgs[anArgIter++]); |
380 | } |
381 | |
382 | Image_PixMap anImage; |
383 | aView3d->ToPixMap (anImage, aWindowSizeX, aWindowSizeY); |
384 | const Handle(TColStd_HSequenceOfReal) aSeq = GetColorOfPixel (anImage, aPickCoordX, aPickCoordY, aRadius); |
385 | cout << "Length = " << aSeq->Length() << endl; |
386 | |
387 | Image_ColorRGBF aColorPicked = {{ 0.0f, 0.0f, 0.0f }}; |
388 | Standard_Boolean isNotEqual = Standard_True; |
389 | for (Standard_Integer i = 1; i <= aSeq->Length(); i += 3) |
390 | { |
391 | aColorPicked.r() = (Standard_ShortReal )aSeq->Value (i + 0); |
392 | aColorPicked.g() = (Standard_ShortReal )aSeq->Value (i + 1); |
393 | aColorPicked.b() = (Standard_ShortReal )aSeq->Value (i + 2); |
394 | |
395 | if (theArgsNb == 3 || |
396 | ((Abs (aColorPicked.r() - aColorInput.r()) <= Precision::Confusion()) |
397 | && (Abs (aColorPicked.g() - aColorInput.g()) <= Precision::Confusion()) |
398 | && (Abs (aColorPicked.b() - aColorInput.b()) <= Precision::Confusion()))) |
399 | { |
400 | isNotEqual = Standard_False; |
401 | break; |
402 | } |
403 | } |
404 | |
405 | theDi << "RED : " << aColorPicked.r() << " " |
406 | << "GREEN : " << aColorPicked.g() << " " |
407 | << "BLUE : " << aColorPicked.b() << "\n"; |
408 | |
409 | if (theArgsNb == 6) |
410 | { |
411 | theDi << "User color: \n" |
412 | << "RED : " << aColorInput.r() << " " |
413 | << "GREEN : " << aColorInput.g() << " " |
414 | << "BLUE : " << aColorInput.b() << "\n"; |
415 | } |
416 | |
417 | if (isNotEqual) |
418 | { |
419 | theDi << "Faulty : colors are not equal.\n"; |
420 | return 1; // TCL_ERROR |
421 | } |
422 | return 0; |
7fd59977 |
423 | } |
424 | |
425 | #if ! defined(WNT) |
426 | extern int ViewerMainLoop (Standard_Integer argc, const char ** argv); |
427 | #else |
428 | Standard_EXPORT int ViewerMainLoop (Standard_Integer argc, const char ** argv); |
429 | #endif |
430 | #if ! defined(WNT) |
431 | extern int ViewerMainLoop2d (Standard_Integer argc, const char ** argv); |
432 | #else |
433 | Standard_EXPORT int ViewerMainLoop2d (Standard_Integer argc, const char ** argv); |
434 | #endif |
435 | |
436 | static Standard_Integer QAAISGetMousePoint (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
437 | { |
4754e164 |
438 | if ( argc != 1 ) { |
439 | di << "Usage : " << argv[0] << "\n"; |
440 | return 1; |
441 | } |
442 | Handle (V3d_View) QAAISView = ViewerTest::CurrentView (); |
443 | if ( QAAISView.IsNull () ) { |
444 | di << "You must initialize AISViewer before this command." << "\n"; |
445 | return 1; |
446 | } |
447 | Standard_Integer QAAISMouseCoordinateX = 0; |
448 | Standard_Integer QAAISMouseCoordinateY = 0; |
449 | Standard_Integer argccc = 5; |
450 | const char *bufff[] = { "A", "B", "C", "D", "E" }; |
451 | const char **argvvv = (const char **) bufff; |
452 | while ( ViewerMainLoop (argccc, argvvv) ) { |
453 | ViewerTest::GetMousePosition (QAAISMouseCoordinateX, QAAISMouseCoordinateY); |
454 | } |
455 | ViewerTest::GetMousePosition (QAAISMouseCoordinateX, QAAISMouseCoordinateY); |
456 | di << "X-coordinate: " << QAAISMouseCoordinateX << "; Y-coordinate: " << QAAISMouseCoordinateY << "\n"; |
457 | return 0; |
7fd59977 |
458 | } |
459 | |
460 | static Standard_Integer QAAISGetColorCoord (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
461 | { |
462 | #if ! defined(WNT) |
463 | if ( argc > 2 ) { |
464 | di << "Usage : " << argv[0] << " [3d|2d]" << "\n"; |
465 | return 1; |
466 | } |
692613e5 |
467 | Handle(Xw_Window) QAAISWindow; |
7fd59977 |
468 | |
469 | Standard_Boolean is3d = 1; |
470 | |
471 | if(argc == 1 || !strcmp(argv[1],"3d")) { |
472 | |
473 | Handle (V3d_View) QAAIS_MainView = ViewerTest::CurrentView (); |
474 | if ( QAAIS_MainView.IsNull () ) { |
475 | di << "You must initialize AISViewer before this command." << "\n"; |
476 | return 1; |
477 | } |
692613e5 |
478 | QAAISWindow = Handle(Xw_Window)::DownCast (QAAIS_MainView->V3d_View::Window()); |
7fd59977 |
479 | is3d = 1; |
480 | } |
481 | |
482 | if(argc == 2 && !strcmp(argv[1],"2d")) { |
483 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
484 | if (V.IsNull()) { |
485 | di << "You must initialize AIS 2D Viewer before this command." << "\n"; |
486 | return 1; |
487 | } |
692613e5 |
488 | QAAISWindow = Handle(Xw_Window)::DownCast (V->Driver()->Window()); |
7fd59977 |
489 | is3d = 0; |
490 | } |
491 | |
492 | Standard_Integer QAAIS_WindowSize_X = 0; |
493 | Standard_Integer QAAIS_WindowSize_Y = 0; |
494 | QAAISWindow->Size(QAAIS_WindowSize_X, QAAIS_WindowSize_Y); |
495 | Handle (Graphic3d_GraphicDevice) QAAIS_GraphicDevice = new Graphic3d_GraphicDevice (getenv ("DISPLAY")); |
496 | |
497 | Draw_Window QAAIS_CoordWindow ("coordinate", 421, 205, 200, 60); |
498 | QAAIS_CoordWindow.DisplayWindow (); |
499 | QAAIS_CoordWindow.SetColor (12); |
500 | |
501 | 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); |
502 | Handle (V3d_Viewer) QAAIS_ColorViewer = new V3d_Viewer (QAAIS_GraphicDevice, Standard_ExtString ("COLOR")); |
503 | Handle (V3d_View) QAAIS_ColorView = QAAIS_ColorViewer -> CreateView (); |
504 | QAAIS_ColorWindow -> Map (); |
505 | QAAIS_ColorView -> SetWindow (QAAIS_ColorWindow); |
506 | QAAIS_ColorView -> SetBackgroundColor (Quantity_NOC_BLACK); |
507 | QAAIS_ColorView -> Redraw (); |
508 | |
509 | Standard_Integer QAAIS_MousePoint_X = 0; |
510 | Standard_Integer QAAIS_MousePoint_Y = 0; |
511 | Standard_Character QAAIS_MousePointX[32]; |
512 | sprintf (QAAIS_MousePointX, "X : %d", QAAIS_MousePoint_X); |
513 | Standard_Character QAAIS_MousePointY[32]; |
514 | sprintf (QAAIS_MousePointY, "Y : %d", QAAIS_MousePoint_Y); |
515 | Standard_ShortReal QAAIS_ColorRED = 0; |
516 | Standard_ShortReal QAAIS_ColorGRN = 0; |
517 | Standard_ShortReal QAAIS_ColorBLU = 0; |
518 | Quantity_Color QAAIS_ShowingColor; |
519 | QAAIS_ShowingColor.SetValues (QAAIS_ColorRED, QAAIS_ColorGRN, QAAIS_ColorBLU, Quantity_TOC_RGB); |
520 | Standard_Integer argccc = 5; |
521 | const char *bufff[] = { "A", "B", "C", "D", "E" }; |
522 | const char **argvvv = (const char **) bufff; |
523 | while ( is3d ? ViewerMainLoop (argccc, argvvv) : ViewerMainLoop2d (argccc, argvvv)) { |
524 | Handle(TColStd_HSequenceOfReal) aSeq; |
692613e5 |
525 | Image_PixMap anImage; |
7fd59977 |
526 | if(is3d) |
527 | { |
528 | ViewerTest::GetMousePosition (QAAIS_MousePoint_X, QAAIS_MousePoint_Y); |
529 | Handle (V3d_View) QAAIS_MainView = ViewerTest::CurrentView(); |
692613e5 |
530 | QAAIS_MainView->ToPixMap (anImage, QAAIS_WindowSize_X, QAAIS_WindowSize_Y); |
7fd59977 |
531 | } |
532 | else |
533 | { |
534 | Viewer2dTest::GetMousePosition (QAAIS_MousePoint_X, QAAIS_MousePoint_Y); |
692613e5 |
535 | QAAISWindow->ToPixMap (anImage); |
7fd59977 |
536 | } |
692613e5 |
537 | aSeq = GetColorOfPixel (anImage, QAAIS_MousePoint_X, QAAIS_MousePoint_Y, 0); |
538 | |
7fd59977 |
539 | QAAIS_ColorRED = aSeq->Value(1); |
540 | QAAIS_ColorGRN = aSeq->Value(2); |
541 | QAAIS_ColorBLU = aSeq->Value(3); |
542 | QAAIS_ShowingColor.SetValues (QAAIS_ColorRED, QAAIS_ColorGRN, QAAIS_ColorBLU, Quantity_TOC_RGB); |
543 | QAAIS_ColorView -> SetBackgroundColor (QAAIS_ShowingColor); |
544 | QAAIS_ColorView -> Redraw (); |
545 | QAAIS_CoordWindow.Clear(); |
546 | sprintf (QAAIS_MousePointX, "X : %d", QAAIS_MousePoint_X); |
547 | sprintf (QAAIS_MousePointY, "Y : %d", QAAIS_MousePoint_Y); |
548 | QAAIS_CoordWindow.DrawString (30, 35, QAAIS_MousePointX); |
549 | QAAIS_CoordWindow.DrawString (125, 35, QAAIS_MousePointY); |
550 | } |
551 | QAAIS_CoordWindow.Destroy (); |
552 | #endif //WNT |
553 | return 0; |
554 | } |
555 | |
556 | //============================================================================== |
557 | // VIEWER GLOBALs |
558 | //============================================================================== |
559 | #if ! defined(WNT) |
560 | extern int V2dPickGrid (Draw_Interpretor& , Standard_Integer argc, const char ** argv); |
561 | #else |
562 | Standard_EXPORT int V2dPickGrid (Draw_Interpretor& , Standard_Integer argc, const char ** argv); |
563 | #endif |
564 | //============================================================================== |
565 | //function : V2dSetHighlightMode |
566 | //purpose : QAv2dSetHighlightMode mode |
567 | //============================================================================== |
568 | static int V2dSetHighlightMode (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
569 | { |
570 | if (argc != 2) |
571 | { |
572 | di << "Usage: QAv2dSetHighlightMode mode" << "\n"; |
573 | return 1; |
574 | } |
575 | |
576 | Viewer2dTest::StandardModeActivation(atoi(argv[1])); |
577 | return 0; |
578 | } |
579 | |
f1aa2b62 |
580 | //#ifndef WNT |
7fd59977 |
581 | //============================================================================== |
582 | //function : QAAISGetPixelColor2d |
583 | //purpose : QAAISGetPixelColor2d coord_X coord_Y Red Green Blue |
584 | //============================================================================== |
585 | |
586 | static int QAAISGetPixelColor2d (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
587 | { |
588 | if (argc != 6 && argc != 3) |
589 | { |
590 | di << "Args: coord_X coord_Y [Red Green Blue]" << "\n"; |
591 | return 1; |
592 | } |
593 | |
594 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
595 | if (V.IsNull()) |
596 | { |
597 | di << "You must initialize AIS 2D Viewer before this command." << "\n"; |
598 | return 1; |
599 | } |
692613e5 |
600 | |
7fd59977 |
601 | // Get Color |
692613e5 |
602 | #if (defined(_WIN32) || defined(__WIN32__)) |
603 | Handle(WNT_Window) QAAISWindow = Handle(WNT_Window)::DownCast (V->Driver()->Window()); |
604 | #else |
605 | Handle(Xw_Window) QAAISWindow = Handle(Xw_Window )::DownCast (V->Driver()->Window()); |
606 | #endif |
7fd59977 |
607 | |
608 | Standard_ShortReal aCoordinateX = atoi(argv[1]); |
609 | Standard_ShortReal aCoordinateY = atoi(argv[2]); |
610 | |
611 | // Get Color |
612 | Standard_ShortReal aColorRED_V = 0; |
613 | Standard_ShortReal aColorGRN_V = 0; |
614 | Standard_ShortReal aColorBLU_V = 0; |
615 | |
616 | if ( argc == 6 ) { |
617 | aColorRED_V = atof (argv [3]); |
618 | aColorGRN_V = atof (argv [4]); |
619 | aColorBLU_V = atof (argv [5]); |
620 | |
621 | di << "Begin aColorRED_User = " << aColorRED_V << "\n"; |
622 | di << "Begin aColorGRN_User = " << aColorGRN_V << "\n"; |
623 | di << "Begin aColorBLU_User = " << aColorBLU_V << "\n"; |
624 | } |
625 | |
626 | Standard_Integer aRadius = 1; |
627 | if ( argc == 3 ) { |
628 | aRadius=0; |
629 | } |
630 | |
692613e5 |
631 | Image_PixMap anImage; |
632 | QAAISWindow->ToPixMap (anImage); |
633 | Handle(TColStd_HSequenceOfReal) aSeq = GetColorOfPixel (anImage, aCoordinateX, aCoordinateY, aRadius); |
7fd59977 |
634 | |
635 | Standard_Boolean IsNotEqual = Standard_True; |
636 | Standard_Integer i; |
637 | for(i=1; i<=aSeq->Length();i+=3) { |
638 | // mkv 29.04.03 |
639 | Standard_ShortReal aColorRED_R = (((Standard_ShortReal) ((Standard_Integer) (aSeq->Value(i+0) * 1000000))) / 1000000.); |
640 | Standard_ShortReal aColorGRN_R = (((Standard_ShortReal) ((Standard_Integer) (aSeq->Value(i+1) * 1000000))) / 1000000.); |
641 | Standard_ShortReal aColorBLU_R = (((Standard_ShortReal) ((Standard_Integer) (aSeq->Value(i+2) * 1000000))) / 1000000.); |
642 | // mkv 29.04.03 |
643 | |
644 | if ( argc == 3 ) { |
645 | di << "RED : " << aColorRED_R << " GREEN : " << aColorGRN_R << " BLUE : " << aColorBLU_R << "\n"; |
646 | IsNotEqual = Standard_False; |
647 | break; |
648 | } |
649 | |
650 | if ( aColorRED_R == aColorRED_V |
651 | && aColorGRN_R == aColorGRN_V |
652 | && aColorBLU_R == aColorBLU_V |
653 | ) { |
654 | IsNotEqual = Standard_False; |
655 | break; |
656 | } |
657 | } |
658 | if (IsNotEqual) { |
659 | di << "Faulty : colors are not equal." << "\n"; |
660 | return 1; |
661 | } |
662 | return 0; |
663 | } |
f1aa2b62 |
664 | //#endif // !WNT |
7fd59977 |
665 | |
666 | //============================================================================== |
667 | //function : QAMoveTo2d |
668 | //purpose : QAMoveTo2d x y |
669 | //============================================================================== |
670 | static int QAMoveTo2d (Draw_Interpretor& di, int argc, const char ** argv) |
671 | { |
672 | if (argc != 3) |
673 | { |
674 | di << "Usage : " << argv[0] << " x y" << "\n"; |
675 | return -1; |
676 | } |
677 | |
678 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
679 | if (myAIScontext.IsNull()) |
680 | { |
681 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
682 | return -1; |
683 | } |
684 | Viewer2dTest::CurrentEventManager()->MoveTo |
685 | (atoi(argv[1]), atoi(argv[2]), Viewer2dTest::CurrentView()); |
686 | return 0; |
687 | } |
688 | |
689 | //============================================================================== |
690 | //function : QASelect2d |
691 | //purpose : QASelect2d x y |
692 | //============================================================================== |
693 | static int QASelect2d (Draw_Interpretor& di, int argc, const char ** argv) |
694 | { |
695 | if (argc != 3) |
696 | { |
697 | di << "Usage : " << argv[0] << " x y" << "\n"; |
698 | return -1; |
699 | } |
700 | |
701 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
702 | if (myAIScontext.IsNull()) |
703 | { |
704 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
705 | return -1; |
706 | } |
707 | Viewer2dTest::CurrentEventManager()->MoveTo |
708 | (atoi(argv[1]), atoi(argv[2]), Viewer2dTest::CurrentView()); |
709 | Viewer2dTest::CurrentEventManager()->Select(); |
710 | return 0; |
711 | } |
712 | |
713 | //============================================================================== |
714 | //function : QAShiftSelect2d |
715 | //purpose : QAShiftSelect2d x y |
716 | //============================================================================== |
717 | static int QAShiftSelect2d (Draw_Interpretor& di, int argc, const char ** argv) |
718 | { |
719 | if (argc != 3) |
720 | { |
721 | di << "Usage : " << argv[0] << " x y" << "\n"; |
722 | return -1; |
723 | } |
724 | |
725 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
726 | if (myAIScontext.IsNull()) |
727 | { |
728 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
729 | return -1; |
730 | } |
731 | Viewer2dTest::CurrentEventManager()->MoveTo |
732 | (atoi(argv[1]), atoi(argv[2]), Viewer2dTest::CurrentView()); |
733 | Viewer2dTest::CurrentEventManager()->ShiftSelect(); |
734 | return 0; |
735 | } |
736 | |
737 | //============================================================================== |
738 | //function : V2dZoom |
739 | //purpose : QAv2dzoom zoom_factor |
740 | //============================================================================== |
741 | static int V2dZoom (Draw_Interpretor& di, int argc, const char ** argv) |
742 | { |
743 | if (argc != 2) |
744 | { |
745 | di << "Usage : " << argv[0] << " zoom_factor" << "\n"; |
746 | return -1; |
747 | } |
748 | |
749 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
750 | if (myAIScontext.IsNull()) |
751 | { |
752 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
753 | return -1; |
754 | } |
755 | Viewer2dTest::CurrentView()->Zoom(atof(argv[1])); |
756 | return 0; |
757 | } |
758 | |
759 | //============================================================================== |
760 | //function : V2dPan |
761 | //purpose : QAv2dpan dx dy |
762 | //============================================================================== |
763 | static int V2dPan (Draw_Interpretor& di, int argc, const char ** argv) |
764 | { |
765 | if (argc != 3) |
766 | { |
767 | di << "Usage : " << argv[0] << " dx dy" << "\n"; |
768 | return -1; |
769 | } |
770 | |
771 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
772 | if (myAIScontext.IsNull()) |
773 | { |
774 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
775 | return -1; |
776 | } |
692613e5 |
777 | Viewer2dTest::CurrentView()->Pan(atoi(argv[1]), atoi(argv[2])); |
7fd59977 |
778 | return 0; |
779 | } |
780 | |
781 | //============================================================================== |
782 | //function : V2dGetViewCharac |
783 | //purpose : v2dGetViewCharac |
784 | //============================================================================== |
785 | static int V2dGetViewCharac (Draw_Interpretor& di, int si, const char ** /*sc*/) |
786 | { |
787 | if (si != 1) |
788 | { |
789 | di << "Use - v2dGetViewCharac" << "\n"; |
790 | return 1; |
791 | } |
792 | |
793 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
794 | if (V.IsNull()) |
795 | { |
796 | di << "You must initialize AIS 2D Viewer before this command." << "\n"; |
797 | return 1; |
798 | } |
799 | |
800 | // Quantity_Factor aViewScale = V->Scale(); |
801 | |
802 | Standard_Real aCenterCoordX = 0.0; |
803 | Standard_Real aCenterCoordY = 0.0; |
804 | V->Center(aCenterCoordX, aCenterCoordY); |
805 | |
806 | Standard_Real aViewProjX = 0.0; |
807 | Standard_Real aViewProjY = 0.0; |
808 | Standard_Real aViewProjZ = 0.0; |
809 | // V->Proj(aViewProjX, aViewProjY, aViewProjZ); |
810 | |
811 | Standard_Real aViewUpX = 0.0; |
812 | Standard_Real aViewUpY = 0.0; |
813 | Standard_Real aViewUpZ = 0.0; |
814 | // V->Up(aViewUpX, aViewUpY, aViewUpZ); |
815 | |
816 | Standard_Real aViewAtX = 0.0; |
817 | Standard_Real aViewAtY = 0.0; |
818 | Standard_Real aViewAtZ = 0.0; |
819 | // V->At(aViewAtX, aViewAtY, aViewAtZ); |
820 | |
821 | // cout << "Scale of current view: " << aViewScale << endl; |
822 | // cout << "Center on X : "<< aViewCenterCoordX << "; on Y: " << aViewCenterCoordY << endl; |
823 | // cout << "Proj on X : " << aViewProjX << "; on Y: " << aViewProjY << "; on Z: " << aViewProjZ << endl; |
824 | // cout << "Up on X : " << aViewUpX << "; on Y: " << aViewUpY << "; on Z: " << aViewUpZ << endl; |
825 | // cout << "At on X : " << aViewAtX << "; on Y: " << aViewAtY << "; on Z: " << aViewAtZ << endl; |
826 | |
827 | // cout << aViewScale << " " << aViewCenterCoordX << " " << aViewCenterCoordY << " "; |
828 | di << aViewProjX << " " << aViewProjY << " " << aViewProjZ << " "; |
829 | di << aViewUpX << " " << aViewUpY << " " << aViewUpZ << " "; |
830 | di << aViewAtX << " " << aViewAtY << " " << aViewAtZ << "\n"; |
831 | return 0; |
832 | } |
833 | |
834 | //============================================================================== |
835 | //function : V2dSetViewCharac |
836 | //purpose : v2dSetViewCharac |
837 | //============================================================================== |
838 | static int V2dSetViewCharac (Draw_Interpretor& di, int si, const char ** sc) |
839 | { |
840 | if (si != 13) |
841 | { |
842 | di << "Use - v2dSetViewCharac scale center(X Y) proj(X Y Z) up(X Y Z) at(X Y Z)" << "\n"; |
843 | return 1; |
844 | } |
845 | |
846 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
847 | if (V.IsNull()) |
848 | { |
849 | di << "You must initialize AIS 2D Viewer before this command." << "\n"; |
850 | return 1; |
851 | } |
852 | |
853 | Quantity_Factor aViewScale = atof(sc[1]); |
854 | |
855 | Standard_Real aViewCenterCoordX = atof(sc[2]); |
856 | Standard_Real aViewCenterCoordY = atof(sc[3]); |
857 | |
858 | Standard_Real aViewProjX = atof(sc[4]); |
859 | Standard_Real aViewProjY = atof(sc[5]); |
860 | Standard_Real aViewProjZ = atof(sc[6]); |
861 | |
862 | Standard_Real aViewUpX = atof(sc[7]); |
863 | Standard_Real aViewUpY = atof(sc[8]); |
864 | Standard_Real aViewUpZ = atof(sc[9]); |
865 | |
866 | Standard_Real aViewAtX = atof(sc[10]); |
867 | Standard_Real aViewAtY = atof(sc[11]); |
868 | Standard_Real aViewAtZ = atof(sc[12]); |
869 | |
870 | // V->SetScale(aViewScale); |
871 | // V->SetCenter(aViewCenterCoordX, aViewCenterCoordY); |
872 | // V->SetAt(aViewAtX, aViewAtY, aViewAtZ); |
873 | // V->SetProj(aViewProjX, aViewProjY, aViewProjZ); |
874 | // V->SetUp(aViewUpX, aViewUpY, aViewUpZ); |
875 | // V->SetProj(aViewProjX, aViewProjY, aViewProjZ); |
876 | return 0; |
877 | } |
878 | |
879 | //======================================================================= |
880 | //function : QAxwd_2d |
881 | //purpose : |
882 | //======================================================================= |
883 | static int QAxwd_2d (Draw_Interpretor& di, int argc, const char ** argv) |
884 | { |
885 | if (argc != 2) |
886 | { |
887 | di << "Usage : " << argv[0] << " filename" << "\n"; |
888 | return -1; |
889 | } |
890 | |
891 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
892 | if (myAIScontext.IsNull()) |
893 | { |
894 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
895 | return -1; |
896 | } |
897 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
898 | V->Dump(argv[1]); |
899 | return 0; |
900 | } |
901 | |
902 | #ifndef WNT |
903 | extern Draw_Viewer dout; |
7fd59977 |
904 | extern Display* Draw_WindowDisplay; |
905 | extern Colormap Draw_WindowColorMap; |
906 | #else |
907 | Standard_IMPORT Draw_Viewer dout; |
7fd59977 |
908 | #endif |
909 | |
7fd59977 |
910 | //======================================================================= |
911 | //function : QA2dGetIndexes |
912 | //purpose : |
913 | //======================================================================= |
914 | static int QA2dGetIndexes (Draw_Interpretor& di, int /*argc*/, const char ** argv) |
915 | { |
916 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
917 | if (myAIScontext.IsNull()) |
918 | { |
919 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
920 | return -1; |
921 | } |
922 | Handle(Aspect_WindowDriver) aWindowDriver = Viewer2dTest::CurrentView()->Driver(); |
923 | |
924 | Standard_Integer aFontMin, aFontMax, aColorMin, aColorMax; |
925 | aWindowDriver->FontBoundIndexs(aFontMin, aFontMax); |
926 | di << "Available font indexes are " << aFontMin << " - " << aFontMax << "\n"; |
927 | aWindowDriver->ColorBoundIndexs(aColorMin, aColorMax); |
928 | di << "Available color indexes are " << aColorMin << " - " << aColorMax << "\n"; |
692613e5 |
929 | return 0; |
7fd59977 |
930 | } |
931 | |
932 | #if ! defined(WNT) |
933 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
934 | extern Handle(AIS_InteractiveContext)& TheAISContext(); |
935 | #else |
936 | Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
937 | Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(); |
938 | #endif |
939 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
940 | #include <AIS_Trihedron.hxx> |
941 | #include <AIS_Axis.hxx> |
942 | #include <Geom_Line.hxx> |
943 | #include <AIS_Line.hxx> |
944 | |
945 | //============================================================================== |
946 | // function : VTrihedronOrigins |
947 | // author : ota |
948 | // purpose : draws triheron axis origin lines. |
949 | // Draw arg : vtri_orig trihedron_name |
950 | //============================================================================== |
951 | static int VTrihedronOrigins(Draw_Interpretor& di, |
952 | Standard_Integer argc, |
953 | const char ** argv) |
954 | { |
955 | if(argc != 2){ |
956 | di <<"Usage : vtri_orig tri_name"<<"\n"; |
957 | return 1; |
958 | } |
959 | |
960 | if(TheAISContext().IsNull()){ |
961 | di<<"Make 'vinit' before this method call"<<"\n"; |
962 | return 1; |
963 | } |
964 | |
965 | //get trihedron from AIS map. |
966 | TCollection_AsciiString aName(argv[1]); |
967 | if(!GetMapOfAIS().IsBound2(aName)){ |
968 | di<<"No object named '"<<argv[1]<<"'"<<"\n"; |
969 | return 1; |
970 | } |
971 | |
972 | Handle(AIS_Trihedron) aTrih = |
973 | Handle(AIS_Trihedron)::DownCast(GetMapOfAIS().Find2(aName)); |
974 | if(aTrih.IsNull()){ |
975 | di<<"Trihedron is not found, try another name"<<"\n"; |
976 | return 1; |
977 | } |
978 | |
979 | //get axis |
980 | Handle(AIS_Axis) XAxis = aTrih->XAxis(); |
981 | Handle(AIS_Axis) YAxis = aTrih->YAxis(); |
982 | Handle(AIS_Axis) ZAxis = aTrih->Axis(); |
983 | |
984 | //get geometrical lines |
985 | Handle(Geom_Line) XGLine = XAxis->Component(); |
986 | Handle(Geom_Line) YGLine = YAxis->Component(); |
987 | Handle(Geom_Line) ZGLine = ZAxis->Component(); |
988 | |
989 | //make AIS_Lines |
990 | Handle(AIS_Line) XLine = new AIS_Line(XGLine); |
991 | Handle(AIS_Line) YLine = new AIS_Line(YGLine); |
992 | Handle(AIS_Line) ZLine = new AIS_Line(ZGLine); |
993 | |
994 | //put them into AIS map: |
995 | GetMapOfAIS().Bind(XLine,aName+"_X"); |
996 | GetMapOfAIS().Bind(YLine,aName+"_Y"); |
997 | GetMapOfAIS().Bind(ZLine,aName+"_Z"); |
998 | //print names of created objects: |
999 | di<<argv[1]<<"_X "<<argv[1]<<"_Y "<<argv[1]<<"_Z"<<"\n"; |
1000 | |
1001 | //try to draw them: |
1002 | TheAISContext()->Display(XLine); |
1003 | TheAISContext()->Display(YLine); |
1004 | TheAISContext()->Display(ZLine); |
1005 | |
1006 | return 0; |
1007 | } |
1008 | |
7fd59977 |
1009 | #include <V2d_View.hxx> |
1010 | #include <AIS2D_InteractiveObject.hxx> |
1011 | #include <Graphic2d_Circle.hxx> |
1012 | #include <Graphic2d_TypeOfPolygonFilling.hxx> |
1013 | #include <V2d_Viewer.hxx> |
1014 | #include <Viewer2dTest_DoubleMapOfInteractiveAndName.hxx> |
1015 | |
1016 | #if ! defined(WNT) |
1017 | extern Viewer2dTest_DoubleMapOfInteractiveAndName& GetMapOfAIS2D(); |
1018 | #else |
1019 | Standard_EXPORT Viewer2dTest_DoubleMapOfInteractiveAndName& GetMapOfAIS2D(); |
1020 | #endif |
1021 | |
1022 | //======================================================================= |
1023 | //function : QAv2dcircle |
1024 | //purpose : |
1025 | //======================================================================= |
1026 | static Standard_Integer QAv2dcircle (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
1027 | { |
1028 | Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext(); |
1029 | if(aContext.IsNull()) { |
1030 | di << "ERROR: Use 'v2dinit' command before " << argv[0] << "\n"; |
1031 | return -1; |
1032 | } |
1033 | if(argc < 7){ |
1034 | di<<"Usage : " << argv[0] << " CircleName X Y Radius Alpha Beta [Color_index]\n"; |
1035 | return -1; |
1036 | } |
1037 | Handle(V2d_View) V = Viewer2dTest::CurrentView(); |
1038 | |
1039 | TCollection_AsciiString name = argv[1]; |
1040 | Standard_Real x = atof(argv[2]); |
1041 | Standard_Real y = atof(argv[3]); |
1042 | Standard_Real radius = atof(argv[4]); |
1043 | Standard_Real alpha = atof(argv[5]); |
1044 | Standard_Real beta = atof(argv[6]); |
1045 | |
1046 | if (GetMapOfAIS2D().IsBound2(name)) { |
1047 | di << "There is already an object with name " << name.ToCString() << "\n"; |
1048 | return -1; |
1049 | } |
1050 | Handle(AIS2D_InteractiveObject) aisobj = new AIS2D_InteractiveObject(); |
1051 | aisobj->SetView(V->View()); |
1052 | Handle(Graphic2d_Circle) circle = new Graphic2d_Circle(aisobj,x,y,radius,alpha,beta); |
1053 | if(argc > 7){ |
1054 | Standard_Integer color_index = atoi(argv[7]); |
1055 | circle->SetTypeOfPolygonFilling(Graphic2d_TOPF_FILLED); |
1056 | circle->SetInteriorColorIndex(color_index); |
1057 | } |
1058 | GetMapOfAIS2D().Bind(aisobj, name); |
1059 | aisobj->Display(); |
1060 | V->Viewer()->Update(); |
1061 | return 0; |
1062 | } |
1063 | |
1064 | #include <Draw_Viewer.hxx> |
1065 | #include <Draw.hxx> |
1066 | |
1067 | #ifndef WNT |
1068 | extern Draw_Viewer dout; |
1069 | #else |
1070 | Standard_IMPORT Draw_Viewer dout; |
1071 | #endif |
1072 | |
1073 | static Standard_Integer ViewId(const Standard_CString a) |
1074 | { |
1075 | Standard_Integer id = atoi(a); |
1076 | if ((id < 0) || (id >= MAXVIEW)) { |
1077 | cout << "Incorrect view-id, must be in 0.."<<MAXVIEW-1<<endl; |
1078 | return -1; |
1079 | } |
1080 | if (!dout.HasView(id)) { |
1081 | cout <<"View "<<id<<" does not exist."<<endl; |
1082 | return -1; |
1083 | } |
1084 | return id; |
1085 | } |
1086 | |
7fd59977 |
1087 | #include <Draw_Display.hxx> |
1088 | |
7fd59977 |
1089 | //======================================================================= |
1090 | // QArename |
1091 | //======================================================================= |
1092 | |
1093 | static Standard_Integer QArename(Draw_Interpretor& di, Standard_Integer n, const char** a) |
1094 | { |
1095 | if (n < 3) return 1; |
1096 | Standard_Boolean cop = !strcasecmp(a[0],"copy"); |
1097 | |
1098 | Handle(Draw_Drawable3D) D; |
1099 | for (Standard_Integer i = 1; i < n; i += 2) { |
1100 | if (i+1 >= n) return 0; |
1101 | D = Draw::Get(a[i]); |
1102 | if (!D.IsNull()) { |
1103 | if (cop) |
1104 | D = D->Copy(); |
1105 | else |
1106 | // clear old name |
1107 | Draw::Set(a[i],Handle(Draw_Drawable3D())); |
1108 | |
1109 | Draw::Set(a[i+1],D); |
1110 | } |
1111 | } |
1112 | return 0; |
1113 | } |
1114 | |
7fd59977 |
1115 | //#if defined(V2D) |
1116 | //#include <AIS2D_InteractiveContext.hxx> |
1117 | //static Standard_Integer QANbSelected2d (Draw_Interpretor& /*di*/, Standard_Integer argc, char** argv) |
1118 | //{ |
1119 | // if(argc != 1) { |
1120 | // cout << "Usage : " << argv[0] << endl; |
1121 | // return 1; |
1122 | // } |
1123 | // Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext(); |
1124 | // if(aContext.IsNull()) { |
1125 | // cerr << "use 'v2dinit' command before " << argv[0] << endl; |
1126 | // return 1; |
1127 | // } |
1128 | // cout << aContext->NbSelected() << endl; |
1129 | // return 0; |
1130 | //} |
1131 | //#endif |
1132 | |
7fd59977 |
1133 | static int QASelect2dRectangle (Draw_Interpretor& di, int argc, const char ** argv) |
1134 | { |
1135 | if (argc != 5) |
1136 | { |
1137 | di << "Usage : " << argv[0] << " x1 y1 x2 y2" << "\n"; |
1138 | return -1; |
1139 | } |
1140 | |
1141 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
1142 | if (myAIScontext.IsNull()) |
1143 | { |
1144 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
1145 | return -1; |
1146 | } |
1147 | |
1148 | Standard_Integer x1 = atoi(argv[1]); |
1149 | Standard_Integer y1 = atoi(argv[2]); |
1150 | Standard_Integer x2 = atoi(argv[3]); |
1151 | Standard_Integer y2 = atoi(argv[4]); |
1152 | |
1153 | Handle(Viewer2dTest_EventManager) aCurrentEventManager = Viewer2dTest::CurrentEventManager(); |
1154 | Handle(V2d_View) aCurrentView = Viewer2dTest::CurrentView(); |
1155 | |
1156 | aCurrentEventManager->MoveTo(x1,y1,aCurrentView); |
1157 | aCurrentEventManager->Select(x1,y1,x2,y2,aCurrentView); |
1158 | aCurrentEventManager->MoveTo(x2,y2,aCurrentView); |
1159 | |
1160 | return 0; |
1161 | } |
1162 | |
1163 | static int QAShiftSelect2dRectangle (Draw_Interpretor& di, int argc, const char ** argv) |
1164 | { |
1165 | if (argc != 5) |
1166 | { |
1167 | di << "Usage : " << argv[0] << " x1 y1 x2 y2" << "\n"; |
1168 | return -1; |
1169 | } |
1170 | |
1171 | Handle(AIS2D_InteractiveContext) myAIScontext = Viewer2dTest::GetAIS2DContext(); |
1172 | if (myAIScontext.IsNull()) |
1173 | { |
1174 | di << "use 'v2dinit' command before " << argv[0] << "\n"; |
1175 | return -1; |
1176 | } |
1177 | |
1178 | Standard_Integer x1 = atoi(argv[1]); |
1179 | Standard_Integer y1 = atoi(argv[2]); |
1180 | Standard_Integer x2 = atoi(argv[3]); |
1181 | Standard_Integer y2 = atoi(argv[4]); |
1182 | |
1183 | Handle(Viewer2dTest_EventManager) aCurrentEventManager = Viewer2dTest::CurrentEventManager(); |
1184 | Handle(V2d_View) aCurrentView = Viewer2dTest::CurrentView(); |
1185 | |
1186 | aCurrentEventManager->MoveTo(x1,y1,aCurrentView); |
1187 | aCurrentEventManager->ShiftSelect(x1,y1,x2,y2,aCurrentView); |
1188 | aCurrentEventManager->MoveTo(x2,y2,aCurrentView); |
1189 | |
1190 | return 0; |
1191 | } |
1192 | |
7fd59977 |
1193 | void QADraw::CommonCommands(Draw_Interpretor& theCommands) |
1194 | { |
1195 | ios::sync_with_stdio(); |
1196 | |
1197 | st_err = dup(STDERR_FILENO); |
1198 | |
1199 | Draw_BeforeCommand_old = Draw_BeforeCommand; |
1200 | Draw_AfterCommand_old = Draw_AfterCommand; |
1201 | |
1202 | Draw_BeforeCommand = &before; |
1203 | Draw_AfterCommand = &after; |
1204 | |
1205 | const char* group = "QA_Commands"; |
1206 | |
1207 | theCommands.Add("QARebuild","QARebuild command_name",__FILE__,QARebuild,group); |
7fd59977 |
1208 | theCommands.Add("QAGetPixelColor", "QAGetPixelColor coordinate_X coordinate_Y [color_R color_G color_B]", __FILE__,QAAISGetPixelColor, group); |
7fd59977 |
1209 | theCommands.Add("QAGetMousePoint", "QAGetMousePoint", __FILE__,QAAISGetMousePoint, group); |
7fd59977 |
1210 | theCommands.Add("QAGetColorCoord", "QAGetColorCoord [3d|2d]", __FILE__,QAAISGetColorCoord, group); |
f1aa2b62 |
1211 | //#ifndef WNT |
7fd59977 |
1212 | theCommands.Add("QAAISGetPixelColor2d", |
1213 | "QAAISGetPixelColor2d coord_X coord_Y [Red Green Blue] : Check a color of pixel", |
1214 | __FILE__, QAAISGetPixelColor2d, group); |
f1aa2b62 |
1215 | //#endif |
7fd59977 |
1216 | |
1217 | theCommands.Add("v2dgetgrid", |
1218 | "v2dgetgrid coord_X coord_Y [grid_X grid_Y] : Get/print coordinates of a grid point near to (coord_X, coord_Y)", |
1219 | __FILE__, V2dPickGrid, group); |
1220 | |
1221 | theCommands.Add("QAv2dzoom", |
1222 | "QAv2dzoom zoom_factor : Set Scale Factor", |
1223 | __FILE__, V2dZoom, group); |
1224 | |
1225 | theCommands.Add("QAv2dpan", |
1226 | "QAv2dpan dx dy : script analog of Ctrl+MB2", |
1227 | __FILE__, V2dPan, group); |
1228 | |
1229 | // theCommands.Add("QAGetViewCharac2d", |
1230 | // "QAGetViewCharac2d - dumps viewer characteristics", |
1231 | // V2dGetViewCharac, group); |
1232 | |
1233 | // theCommands.Add("QASetViewCharac2d", |
1234 | // "QASetViewCharac2d scale center(X Y) proj(X Y Z) up(X Y Z) at(X Y Z)", |
1235 | // V2dSetViewCharac, group); |
1236 | |
1237 | theCommands.Add("QAMoveTo2d", "QAMoveTo2d x y", __FILE__, QAMoveTo2d, group); |
1238 | theCommands.Add("QASelect2d", "QASelect2d x y", __FILE__, QASelect2d, group); |
1239 | theCommands.Add("QAShiftSelect2d", "QAShiftSelect2d x y", __FILE__, QAShiftSelect2d, group); |
7fd59977 |
1240 | theCommands.Add("QAv2dSetHighlightMode", |
1241 | "QAv2dSetHighlightMode mode", __FILE__, V2dSetHighlightMode, group); |
7fd59977 |
1242 | theCommands.Add("QAxwd_2d", "QAxwd_2d filename", __FILE__, QAxwd_2d, group); |
7fd59977 |
1243 | theCommands.Add("QA2dGetIndexes", "QA2dGetIndexes", __FILE__, QA2dGetIndexes, group); |
1244 | |
1245 | theCommands.Add("vtri_orig", |
1246 | "vtri_orig : vtri_orig trihedron_name - draws axis origin lines", |
1247 | __FILE__,VTrihedronOrigins,group); |
7fd59977 |
1248 | theCommands.Add("QAv2dcircle", "QAv2dcircle CircleName X Y Radius Alpha Beta [Color_index]", __FILE__, QAv2dcircle, group); |
1249 | |
319e4241 |
1250 | // adding commands "rename" leads to the fact that QA commands doesn't work properly OCC23410, use function "renamevar" |
1251 | // theCommands.Add("rename","rename name1 toname1 name2 toname2 ...",__FILE__,QArename,group); |
7fd59977 |
1252 | //#if defined(V2D) |
1253 | // theCommands.Add ("QANbSelected2d", "QANbSelected2d", __FILE__, QANbSelected2d, group); |
1254 | //#endif |
7fd59977 |
1255 | theCommands.Add("QASelect2dRectangle","QASelect2dRectangle x1 y1 x2 y2",__FILE__,QASelect2dRectangle,group); |
1256 | theCommands.Add("QAShiftSelect2dRectangle","QAShiftSelect2dRectangle x1 y1 x2 y2",__FILE__,QAShiftSelect2dRectangle,group); |
7fd59977 |
1257 | } |
1258 | /* |
1259 | extern "C" int Tkqadraw_Init(Tcl_Interp *); |
1260 | |
1261 | int Tkqadraw_Init(Tcl_Interp * ) { |
1262 | |
1263 | ios::sync_with_stdio(); |
1264 | |
1265 | QADraw::CommonCommands(theCommands); |
1266 | QADraw::AdditionalCommands(theCommands); |
1267 | |
1268 | ViewerTest::Commands (theCommands); |
1269 | ViewerTest::ViewerCommands (theCommands); |
1270 | |
1271 | Viewer2dTest::Commands(theCommands); |
1272 | // if (Tcl_PkgProvide(theCommands.Interp(), "Qa", "1.0") != TCL_OK) { |
1273 | // return TCL_ERROR; |
1274 | // } |
1275 | |
1276 | return TCL_OK; |
1277 | } |
1278 | */ |
1279 | //============================================================================== |
1280 | // QADraw::Factory |
1281 | //============================================================================== |
1282 | void QADraw::Factory(Draw_Interpretor& theCommands) |
1283 | { |
1284 | thePCommands = &theCommands; |
1285 | |
1286 | // definition of QA Command |
1287 | QADraw::CommonCommands(theCommands); |
1288 | QADraw::AdditionalCommands(theCommands); |
1289 | |
1290 | //ViewerTest::Commands (theCommands); |
1291 | //ViewerTest::ViewerCommands (theCommands); |
1292 | |
1293 | //#if defined(V2D) |
1294 | // Viewer2dTest::Commands(theCommands); |
1295 | //#endif |
1296 | |
1297 | //#ifdef DEB |
1298 | // cout << "Draw Plugin : QA commands are loaded" << endl; |
1299 | //#endif |
1300 | } |
1301 | |
1302 | // Declare entry point PLUGINFACTORY |
1303 | DPLUGIN(QADraw) |