d69cbf04f47f191569f9ac74a0be3cd1dce8957d
[occt.git] / src / QADraw / QADraw.cxx
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
20
21
22 #if defined(WNT)
23 #include <windows.h>
24 #endif
25 #include <QADraw.hxx>
26 #include <QADraw_DataMapOfAsciiStringOfAddress.hxx>
27 #include <Draw_Interpretor.hxx>
28 #include <Image_AlienPixMap.hxx>
29 #include <V3d_View.hxx>
30 #include <ViewerTest.hxx>
31 #include <ViewerTest_EventManager.hxx>
32 #include <TColStd_StackOfInteger.hxx>
33 #include <TColStd_ListOfInteger.hxx>
34 #include <TColStd_ListIteratorOfListOfInteger.hxx>
35 #include <TColStd_HSequenceOfReal.hxx>
36 #include <AIS_InteractiveContext.hxx>
37 #include <Draw.hxx>
38 #include <Draw_Window.hxx>
39 #include <Draw_Viewer.hxx>
40 #include <Aspect_WindowDriver.hxx>
41 #include <stdio.h>
42 #include <Aspect_DisplayConnection.hxx>
43 #include <Graphic3d.hxx>
44
45 #if ! defined(WNT)
46 #include <Xw_Window.hxx>
47 //#include <Xm/Xm.h>
48 #include <X11/Xlib.h>
49 #include <X11/Xutil.h>
50 #include <Xw_Cextern.hxx>
51 #include <unistd.h>
52 #else
53 #include <WNT.h>
54 #include <WNT_Window.hxx>
55 #include <io.h>
56 #endif
57
58 #include <tcl.h>
59
60 #if ! defined(STDOUT_FILENO)
61 #define STDOUT_FILENO fileno(stdout)
62 #endif
63
64 // mkv 15.07.03
65 #if ! defined(STDERR_FILENO)
66 #define STDERR_FILENO fileno(stderr)
67 #endif
68
69 Draw_Interpretor *thePCommands = NULL;
70
71 #if ! defined(WNT)
72 //extern Draw_Interpretor theCommands;
73
74 extern void (*Draw_BeforeCommand)();
75 extern void (*Draw_AfterCommand)(Standard_Integer);
76 #else
77 //Standard_EXPORT Draw_Interpretor theCommands;
78
79 Standard_EXPORT void (*Draw_BeforeCommand)();
80 Standard_EXPORT void (*Draw_AfterCommand)(Standard_Integer);
81 #endif
82
83
84 #include <Draw_PluginMacro.hxx>
85
86 // avoid warnings on 'extern "C"' functions returning C++ classes
87 #ifdef WNT
88 #pragma warning(4:4190)
89 #endif
90
91
92 int st_err = 0;
93
94 void (*Draw_BeforeCommand_old)();
95 void (*Draw_AfterCommand_old)(Standard_Integer);
96
97 static Standard_Boolean should_be_printed = Standard_True;
98
99 static Standard_Boolean shouldDUP() {
100   // MKV 30.03.05
101 #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST)
102   const Standard_Character * adup = Tcl_GetVar(thePCommands->Interp(),
103                                          "QA_DUP",TCL_GLOBAL_ONLY);
104 #else
105   Standard_Character * adup = Tcl_GetVar(thePCommands->Interp(),
106                                          "QA_DUP",TCL_GLOBAL_ONLY);
107 #endif
108   Standard_Integer aDUP=1;
109   if((adup != NULL) && (Draw::Atof(adup) == 0)) {
110     aDUP = 0;
111   }
112
113   return aDUP;
114 }
115
116 static void before() {
117   should_be_printed = Standard_True;
118   if(Draw_BeforeCommand_old) (*Draw_BeforeCommand_old) ();
119 }
120
121 static void  after(Standard_Integer a)
122 {
123   if(Draw_AfterCommand_old) (*Draw_AfterCommand_old) (a);
124   if(!should_be_printed) {
125 //    Tcl_ResetResult(theCommands.Interp());
126   }
127 }
128
129 static QADraw_DataMapOfAsciiStringOfAddress stFuncMap;
130
131   // MKV 30.03.05
132 #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST)
133 static Standard_Integer (*CommandCmd_Old)
134 (ClientData clientData, Tcl_Interp *interp,
135  Standard_Integer argc, const char* argv[]) = NULL;
136 #else
137 static Standard_Integer (*CommandCmd_Old)
138 (ClientData clientData, Tcl_Interp *interp,
139  Standard_Integer argc, char* argv[]) = NULL;
140 #endif
141
142   // MKV 30.03.05
143 #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST)
144 static Standard_Integer CommandCmd
145 (ClientData clientData, Tcl_Interp *interp,
146  Standard_Integer argc, const char* argv[])
147 #else
148 static Standard_Integer CommandCmd
149 (ClientData clientData, Tcl_Interp *interp,
150  Standard_Integer argc, char* argv[])
151 #endif
152 {
153   Standard_Integer old_out = 0;
154   Standard_Integer old_err = 0;
155   Standard_Integer fd_out = 0;
156   Standard_Integer fd_err = 0;
157
158   FILE * aFile_out = NULL;
159   FILE * aFile_err = NULL;
160
161   char *nameo = NULL;
162   char *namee = NULL;
163 #ifdef WNT
164   if(strlen(getenv("TEMP")) == 0) {
165     cerr << "The TEMP variable is not set." << endl;
166     aFile_out = tmpfile();
167     aFile_err = tmpfile();
168   } else {
169     nameo = _tempnam(getenv("TEMP"),"tmpo");
170     namee = _tempnam(getenv("TEMP"),"tmpe");
171     aFile_out=fopen(nameo, "w+");
172     aFile_err=fopen(namee, "w+");
173   }
174 #else
175     aFile_out = tmpfile();
176     aFile_err = tmpfile();
177 #endif
178   fd_out = fileno(aFile_out);
179   fd_err = fileno(aFile_err);
180   if(fd_out !=-1 && fd_err !=-1) {
181     old_err = dup(STDERR_FILENO);
182     old_out = dup(STDOUT_FILENO);
183     dup2(fd_err,STDERR_FILENO);
184     dup2(fd_out,STDOUT_FILENO);
185   } else
186     cout << "Faulty : Can not create temporary file."   << endl;
187
188   Standard_Integer clen = sizeof(Standard_Character);
189
190   Standard_Character * QA = getenv("QA_print_command");
191   if((QA != NULL) && (!strcmp(QA,"1"))) {
192     for(Standard_Integer i=0;i<argc;i++) {
193       write(st_err,argv[i],clen*strlen(argv[i]));
194       write(st_err," ",clen);
195     }
196     write(st_err,"\n",clen);
197   }
198
199   // MKV 30.03.05
200 #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST)
201   TCollection_AsciiString aName((char *) argv[0]);
202 #else
203   TCollection_AsciiString aName(argv[0]);
204 #endif
205
206   Standard_Integer res = 0;
207
208   if(stFuncMap.IsBound(aName)) {
209     // MKV 30.03.05
210 #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST)
211     CommandCmd_Old  = (int(*)(void*, Tcl_Interp*, int, const char**))  stFuncMap((char *) argv[0]);
212 #else
213     CommandCmd_Old  = (int(*)(void*, Tcl_Interp*, int, char**))  stFuncMap(argv[0]);
214 #endif
215     res = (*CommandCmd_Old) (clientData,interp,argc,argv);
216   }
217
218   fflush(stderr);
219   fflush(stdout);
220   close(STDERR_FILENO);
221   close(STDOUT_FILENO);
222   dup2(old_err,STDERR_FILENO);
223   dup2(old_out,STDOUT_FILENO);
224   close(old_err);
225   close(old_out);
226
227   Standard_Character buf[256];
228   Standard_Integer len = 0;
229
230   rewind(aFile_err);
231   while((len = read(fd_err,buf,clen*255)/clen) > 0) {
232     buf[len]='\0';
233     if(shouldDUP()) {
234       (*thePCommands) << buf;
235     } else {
236       write(st_err,buf,clen*len);
237     }
238   }
239   close(fd_err);
240
241   rewind(aFile_out);
242   buf[0] = '\0';
243   len = 0;
244   while((len = read(fd_out,buf,clen*255)/clen) > 0) {
245     buf[len]='\0';
246     if(shouldDUP()) {
247       (*thePCommands) << buf;
248     } else {
249       write(st_err,buf,clen*len);
250     }
251   }
252   close(fd_out);
253
254   if(shouldDUP()) {
255     Standard_Character *Result = (Standard_Character *)thePCommands->Result();
256     if(Result[0] != '\0') {
257       Standard_Integer pos = 0;
258       Standard_Integer rlen = strlen(Result);
259       while(pos < rlen) {
260         Standard_Integer nb = 256;
261         if((rlen - pos) <= 256) {
262           nb = rlen - pos;
263         }
264         write(st_err,Result+pos,nb*clen);
265         pos += nb;
266       }
267       write(st_err,"\n",clen);
268       should_be_printed = Standard_False  ;
269     }
270   } //else {
271   if(nameo)
272     free(nameo);
273   if(namee)
274     free(namee);
275   return res;
276 }
277
278 static Standard_Integer QARebuild (Draw_Interpretor& di, Standard_Integer /*n*/, const char ** a)
279 {
280
281   Tcl_CmdInfo *infoPtr = new Tcl_CmdInfo;
282
283   if(!strcmp(a[0],a[1]))
284     return 0;
285
286   char* var_a = (char*)a[1];
287   Standard_Integer res = Tcl_GetCommandInfo(di.Interp(),var_a,infoPtr);
288   if(res && (infoPtr->proc != &CommandCmd)) {
289     TCollection_AsciiString aName(var_a);
290     if (!stFuncMap.IsBound(aName)) {
291       stFuncMap.Bind(aName, (Standard_Address) infoPtr->proc);
292
293       infoPtr->proc = &CommandCmd;
294 #if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 3
295       infoPtr->isNativeObjectProc = 0;
296       infoPtr->objProc = NULL;
297 #endif
298       Tcl_SetCommandInfo(di.Interp(),var_a,infoPtr);
299     }
300   }
301
302   return 0;
303 }
304
305 Handle(TColStd_HSequenceOfReal) GetColorOfPixel (const Image_PixMap&    theImage,
306                                                  const Standard_Integer theCoordinateX,
307                                                  const Standard_Integer theCoordinateY,
308                                                  const Standard_Integer theRadius)
309 {
310   Handle(TColStd_HSequenceOfReal) aSeq = new TColStd_HSequenceOfReal();
311   if (theImage.IsEmpty()) {
312     std::cerr << "The image is null.\n";
313     return aSeq;
314   }
315   Standard_Integer aWidth   = (Standard_Integer )theImage.SizeX();
316   Standard_Integer anHeight = (Standard_Integer )theImage.SizeY();
317
318   Quantity_Color aColorTmp;
319   for (Standard_Integer anXIter = theCoordinateX - theRadius;
320        anXIter <= theCoordinateX + theRadius; ++anXIter)
321   {
322     if (anXIter < 0 || anXIter >= aWidth)
323     {
324       continue;
325     }
326     for (Standard_Integer anYIter = theCoordinateY - theRadius;
327          anYIter <= theCoordinateY + theRadius; ++anYIter)
328     {
329       if (anYIter < 0 || anYIter >= anHeight)
330       {
331         continue;
332       }
333       // Image_PixMap stores image upside-down in memory!
334       aColorTmp = theImage.PixelColor (anXIter, anYIter);
335       aSeq->Append (aColorTmp.Red());
336       aSeq->Append (aColorTmp.Green());
337       aSeq->Append (aColorTmp.Blue());
338     }
339   }
340   return aSeq;
341 }
342
343 static Standard_Integer QAAISGetPixelColor (Draw_Interpretor& theDi,
344                                             Standard_Integer  theArgsNb,
345                                             const char**      theArgs)
346 {
347   if (theArgsNb != 3 && theArgsNb != 6)
348   {
349     theDi << "Usage : " << theArgs[0] << " coordinate_X coordinate_Y [color_R color_G color_B]" << "\n";
350     return 1; // TCL_ERROR
351   }
352
353   Handle(V3d_View) aView3d = ViewerTest::CurrentView();
354   if (aView3d.IsNull())
355   {
356     theDi << "You must initialize AISViewer before this command.\n";
357     return 1; // TCL_ERROR
358   }
359
360   const Handle(Aspect_Window) anAISWindow = aView3d->Window();
361   Standard_Integer aWindowSizeX = 0;
362   Standard_Integer aWindowSizeY = 0;
363   anAISWindow->Size (aWindowSizeX, aWindowSizeY);
364
365   Standard_Integer anArgIter = 1;
366   const Standard_Integer aPickCoordX = Draw::Atoi (theArgs[anArgIter++]);
367   const Standard_Integer aPickCoordY = Draw::Atoi (theArgs[anArgIter++]);
368   const Standard_Integer aRadius = (theArgsNb == 3) ? 0 : 1;
369
370   Image_ColorRGBF aColorInput = {{ 0.0f, 0.0f, 0.0f }};
371   if (theArgsNb == 6)
372   {
373     aColorInput.r() = (Standard_ShortReal )Draw::Atof (theArgs[anArgIter++]);
374     aColorInput.g() = (Standard_ShortReal )Draw::Atof (theArgs[anArgIter++]);
375     aColorInput.b() = (Standard_ShortReal )Draw::Atof (theArgs[anArgIter++]);
376   }
377
378   Image_PixMap anImage;
379   aView3d->ToPixMap (anImage, aWindowSizeX, aWindowSizeY);
380   const Handle(TColStd_HSequenceOfReal) aSeq = GetColorOfPixel (anImage, aPickCoordX, aPickCoordY, aRadius);
381   cout << "Length = " << aSeq->Length() << endl;
382
383   Image_ColorRGBF aColorPicked = {{ 0.0f, 0.0f, 0.0f }};
384   Standard_Boolean isNotEqual = Standard_True;
385   for (Standard_Integer i = 1; i <= aSeq->Length(); i += 3)
386   {
387     aColorPicked.r() = (Standard_ShortReal )aSeq->Value (i + 0);
388     aColorPicked.g() = (Standard_ShortReal )aSeq->Value (i + 1);
389     aColorPicked.b() = (Standard_ShortReal )aSeq->Value (i + 2);
390
391     if (theArgsNb == 3 ||
392         ((Abs (aColorPicked.r() - aColorInput.r()) <= Precision::Confusion())
393       && (Abs (aColorPicked.g() - aColorInput.g()) <= Precision::Confusion())
394       && (Abs (aColorPicked.b() - aColorInput.b()) <= Precision::Confusion())))
395     {
396       isNotEqual = Standard_False;
397       break;
398     }
399   }
400
401   theDi << "RED :   " << aColorPicked.r() << " "
402         << "GREEN : " << aColorPicked.g() << " "
403         << "BLUE :  " << aColorPicked.b() << "\n";
404
405   if (theArgsNb == 6)
406   {
407     theDi << "User color: \n"
408           << "RED :   " << aColorInput.r() << " "
409           << "GREEN : " << aColorInput.g() << " "
410           << "BLUE :  " << aColorInput.b() << "\n";
411   }
412
413   if (isNotEqual)
414   {
415     theDi << "Faulty : colors are not equal.\n";
416     return 1; // TCL_ERROR
417   }
418   return 0;
419 }
420
421 #if ! defined(WNT)
422 extern int ViewerMainLoop (Standard_Integer argc, const char ** argv);
423 #else
424 Standard_EXPORT int ViewerMainLoop (Standard_Integer argc, const char ** argv);
425 #endif
426
427 static Standard_Integer QAAISGetMousePoint (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
428 {
429   if ( argc != 1 ) {
430     di << "Usage : " << argv[0] << "\n";
431     return 1;
432   }
433   Handle (V3d_View) QAAISView = ViewerTest::CurrentView ();
434   if ( QAAISView.IsNull () ) {
435     di << "You must initialize AISViewer before this command." << "\n";
436     return 1;
437   }
438   Standard_Integer QAAISMouseCoordinateX = 0;
439   Standard_Integer QAAISMouseCoordinateY = 0;
440   Standard_Integer argccc = 5;
441   const char *bufff[] = { "A", "B", "C", "D", "E" };
442   const char **argvvv = (const char **) bufff;
443   while ( ViewerMainLoop (argccc, argvvv) ) {
444     ViewerTest::GetMousePosition (QAAISMouseCoordinateX, QAAISMouseCoordinateY);
445   }
446   ViewerTest::GetMousePosition (QAAISMouseCoordinateX, QAAISMouseCoordinateY);
447   di << "X-coordinate: " << QAAISMouseCoordinateX << "; Y-coordinate: " << QAAISMouseCoordinateY << "\n";
448   return 0;
449 }
450
451 static Standard_Integer QAAISGetColorCoord (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
452 {
453 #if ! defined(WNT)
454   if ( argc > 1 ) {
455     di << "Usage : " << argv[0] << "\n";
456     return 1;
457   }
458   Handle(Xw_Window) QAAISWindow;
459
460   Handle (V3d_View) QAAIS_MainView = ViewerTest::CurrentView ();
461   if ( QAAIS_MainView.IsNull () ) {
462     di << "You must initialize AISViewer before this command." << "\n";
463     return 1;
464   }
465   QAAISWindow = Handle(Xw_Window)::DownCast (QAAIS_MainView->V3d_View::Window());
466
467   Standard_Integer QAAIS_WindowSize_X = 0;
468   Standard_Integer QAAIS_WindowSize_Y = 0;
469   QAAISWindow->Size(QAAIS_WindowSize_X, QAAIS_WindowSize_Y);
470   Handle(Aspect_DisplayConnection) aDisplayConnection = new Aspect_DisplayConnection();
471   Handle(Graphic3d_GraphicDriver)  aGraphicDriver = Graphic3d::InitGraphicDriver (aDisplayConnection);
472
473   Draw_Window QAAIS_CoordWindow ("coordinate", 421, 205, 200, 60);
474   QAAIS_CoordWindow.DisplayWindow ();
475   QAAIS_CoordWindow.SetColor (12);
476
477   Handle (Xw_Window) QAAIS_ColorWindow = new Xw_Window (aDisplayConnection, "color", 0.4074, 0.678, 0.1962, 0.06, Quantity_NOC_BLACK);
478   Handle (V3d_Viewer) QAAIS_ColorViewer = new V3d_Viewer (aGraphicDriver, Standard_ExtString ("COLOR"));
479   Handle (V3d_View) QAAIS_ColorView = QAAIS_ColorViewer -> CreateView ();
480   QAAIS_ColorWindow -> Map ();
481   QAAIS_ColorView -> SetWindow (QAAIS_ColorWindow);
482   QAAIS_ColorView -> SetBackgroundColor (Quantity_NOC_BLACK);
483   QAAIS_ColorView -> Redraw ();
484
485   Standard_Integer QAAIS_MousePoint_X = 0;
486   Standard_Integer QAAIS_MousePoint_Y = 0;
487   Standard_Character QAAIS_MousePointX[32];
488   Sprintf (QAAIS_MousePointX, "X : %d", QAAIS_MousePoint_X);
489   Standard_Character QAAIS_MousePointY[32];
490   Sprintf (QAAIS_MousePointY, "Y : %d", QAAIS_MousePoint_Y);
491   Standard_ShortReal QAAIS_ColorRED = 0;
492   Standard_ShortReal QAAIS_ColorGRN = 0;
493   Standard_ShortReal QAAIS_ColorBLU = 0;
494   Quantity_Color QAAIS_ShowingColor;
495   QAAIS_ShowingColor.SetValues (QAAIS_ColorRED, QAAIS_ColorGRN, QAAIS_ColorBLU, Quantity_TOC_RGB);
496   Standard_Integer argccc = 5;
497   const char *bufff[] = { "A", "B", "C", "D", "E" };
498   const char **argvvv = (const char **) bufff;
499   while (ViewerMainLoop (argccc, argvvv)) {
500     Handle(TColStd_HSequenceOfReal) aSeq;
501     Image_PixMap anImage;
502
503     ViewerTest::GetMousePosition (QAAIS_MousePoint_X, QAAIS_MousePoint_Y);
504     Handle (V3d_View) QAAIS_MainView = ViewerTest::CurrentView();
505     QAAIS_MainView->ToPixMap (anImage, QAAIS_WindowSize_X, QAAIS_WindowSize_Y);
506
507     aSeq = GetColorOfPixel (anImage, QAAIS_MousePoint_X, QAAIS_MousePoint_Y, 0);
508
509     QAAIS_ColorRED = aSeq->Value(1);
510     QAAIS_ColorGRN = aSeq->Value(2);
511     QAAIS_ColorBLU = aSeq->Value(3);
512     QAAIS_ShowingColor.SetValues (QAAIS_ColorRED, QAAIS_ColorGRN, QAAIS_ColorBLU, Quantity_TOC_RGB);
513     QAAIS_ColorView -> SetBackgroundColor (QAAIS_ShowingColor);
514     QAAIS_ColorView -> Redraw ();
515     QAAIS_CoordWindow.Clear();
516     Sprintf (QAAIS_MousePointX, "X : %d", QAAIS_MousePoint_X);
517     Sprintf (QAAIS_MousePointY, "Y : %d", QAAIS_MousePoint_Y);
518     QAAIS_CoordWindow.DrawString (30, 35, QAAIS_MousePointX);
519     QAAIS_CoordWindow.DrawString (125, 35, QAAIS_MousePointY);
520   }
521   QAAIS_CoordWindow.Destroy ();
522 #endif //WNT
523     return 0;
524 }
525
526 //==============================================================================
527 //  VIEWER GLOBALs
528 //==============================================================================
529 #ifndef WNT
530 extern Draw_Viewer dout;
531 extern Display*         Draw_WindowDisplay;
532 extern Colormap         Draw_WindowColorMap;
533 #else
534 Standard_IMPORT Draw_Viewer dout;
535 #endif
536
537 //=======================================================================
538 #if ! defined(WNT)
539 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
540 extern Handle(AIS_InteractiveContext)& TheAISContext();
541 #else
542 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
543 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext();
544 #endif
545 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
546 #include <AIS_Trihedron.hxx>
547 #include <AIS_Axis.hxx>
548 #include <Geom_Line.hxx>
549 #include <AIS_Line.hxx>
550
551 //==============================================================================
552 // function : VTrihedronOrigins
553 // author   : ota
554 // purpose  : draws triheron axis origin lines.
555 // Draw arg : vtri_orig trihedron_name
556 //==============================================================================
557 static int VTrihedronOrigins(Draw_Interpretor& di,
558                               Standard_Integer argc,
559                               const char ** argv)
560 {
561   if(argc != 2){
562     di <<"Usage : vtri_orig tri_name"<<"\n";
563     return 1;
564   }
565
566   if(TheAISContext().IsNull()){
567     di<<"Make 'vinit' before this method call"<<"\n";
568     return 1;
569   }
570
571   //get trihedron from AIS map.
572   TCollection_AsciiString aName(argv[1]);
573   if(!GetMapOfAIS().IsBound2(aName)){
574     di<<"No object named '"<<argv[1]<<"'"<<"\n";
575     return 1;
576   }
577
578   Handle(AIS_Trihedron) aTrih =
579     Handle(AIS_Trihedron)::DownCast(GetMapOfAIS().Find2(aName));
580   if(aTrih.IsNull()){
581     di<<"Trihedron is not found, try another name"<<"\n";
582     return 1;
583   }
584
585   //get axis
586   Handle(AIS_Axis) XAxis = aTrih->XAxis();
587   Handle(AIS_Axis) YAxis = aTrih->YAxis();
588   Handle(AIS_Axis) ZAxis = aTrih->Axis();
589
590   //get geometrical lines
591   Handle(Geom_Line) XGLine = XAxis->Component();
592   Handle(Geom_Line) YGLine = YAxis->Component();
593   Handle(Geom_Line) ZGLine = ZAxis->Component();
594
595   //make AIS_Lines
596   Handle(AIS_Line) XLine = new AIS_Line(XGLine);
597   Handle(AIS_Line) YLine = new AIS_Line(YGLine);
598   Handle(AIS_Line) ZLine = new AIS_Line(ZGLine);
599
600   //put them into AIS map:
601   GetMapOfAIS().Bind(XLine,aName+"_X");
602   GetMapOfAIS().Bind(YLine,aName+"_Y");
603   GetMapOfAIS().Bind(ZLine,aName+"_Z");
604   //print names of created objects:
605   di<<argv[1]<<"_X  "<<argv[1]<<"_Y  "<<argv[1]<<"_Z"<<"\n";
606
607   //try to draw them:
608   TheAISContext()->Display(XLine);
609   TheAISContext()->Display(YLine);
610   TheAISContext()->Display(ZLine);
611
612   return 0;
613 }
614
615 #include <Draw_Viewer.hxx>
616 #include <Draw.hxx>
617
618 static Standard_Integer ViewId(const Standard_CString a)
619 {
620   Standard_Integer id = Draw::Atoi(a);
621   if ((id < 0) || (id >= MAXVIEW)) {
622     cout << "Incorrect view-id, must be in 0.."<<MAXVIEW-1<<endl;
623     return -1;
624   }
625   if (!dout.HasView(id)) {
626     cout <<"View "<<id<<" does not exist."<<endl;
627     return -1;
628   }
629   return id;
630 }
631
632 #include <Draw_Display.hxx>
633
634 //=======================================================================
635 // QArename
636 //=======================================================================
637
638 static Standard_Integer QArename(Draw_Interpretor& di, Standard_Integer n, const char** a)
639 {
640   if (n < 3) return 1;
641   Standard_Boolean cop = !strcasecmp(a[0],"copy");
642
643   Handle(Draw_Drawable3D) D;
644   for (Standard_Integer i = 1; i < n; i += 2) {
645     if (i+1 >= n) return 0;
646     D = Draw::Get(a[i]);
647     if (!D.IsNull()) {
648       if (cop)
649         D = D->Copy();
650       else
651         // clear old name
652         Draw::Set(a[i],Handle(Draw_Drawable3D()));
653
654       Draw::Set(a[i+1],D);
655     }
656   }
657   return 0;
658 }
659
660 //#if defined(V2D)
661 //#include <AIS2D_InteractiveContext.hxx>
662 //static Standard_Integer QANbSelected2d (Draw_Interpretor& /*di*/, Standard_Integer argc, char** argv)
663 //{
664 //  if(argc != 1) {
665 //    cout << "Usage : " << argv[0] << endl;
666 //    return 1;
667 //  }
668 //  Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext();
669 //  if(aContext.IsNull()) {
670 //    cerr << "use 'v2dinit' command before " << argv[0] << endl;
671 //    return 1;
672 //  }
673 //  cout << aContext->NbSelected() << endl;
674 //  return 0;
675 //}
676 //#endif
677
678 void QADraw::CommonCommands(Draw_Interpretor& theCommands)
679 {
680   ios::sync_with_stdio();
681
682   st_err = dup(STDERR_FILENO);
683
684   Draw_BeforeCommand_old = Draw_BeforeCommand;
685   Draw_AfterCommand_old  = Draw_AfterCommand;
686
687   Draw_BeforeCommand = &before;
688   Draw_AfterCommand  = &after;
689
690   const char* group = "QA_Commands";
691
692   theCommands.Add("QARebuild","QARebuild command_name",__FILE__,QARebuild,group);
693   theCommands.Add("QAGetPixelColor", "QAGetPixelColor coordinate_X coordinate_Y [color_R color_G color_B]", __FILE__,QAAISGetPixelColor, group);
694   theCommands.Add("QAGetMousePoint", "QAGetMousePoint", __FILE__,QAAISGetMousePoint, group);
695   theCommands.Add("QAGetColorCoord", "QAGetColorCoord", __FILE__,QAAISGetColorCoord, group);
696   theCommands.Add("vtri_orig",
697                   "vtri_orig         : vtri_orig trihedron_name  -  draws axis origin lines",
698                   __FILE__,VTrihedronOrigins,group);
699
700 // adding commands "rename" leads to the fact that QA commands doesn't work properly OCC23410, use function "renamevar"
701 // theCommands.Add("rename","rename name1 toname1 name2 toname2 ...",__FILE__,QArename,group);
702 }
703 /*
704 extern "C" int Tkqadraw_Init(Tcl_Interp *);
705
706 int Tkqadraw_Init(Tcl_Interp * ) {
707
708   ios::sync_with_stdio();
709
710   QADraw::CommonCommands(theCommands);
711   QADraw::AdditionalCommands(theCommands);
712
713   ViewerTest::Commands (theCommands);
714   ViewerTest::ViewerCommands (theCommands);
715
716   Viewer2dTest::Commands(theCommands);
717 //   if (Tcl_PkgProvide(theCommands.Interp(), "Qa", "1.0") != TCL_OK) {
718 //     return TCL_ERROR;
719 //   }
720
721   return TCL_OK;
722 }
723 */
724 //==============================================================================
725 // QADraw::Factory
726 //==============================================================================
727 void QADraw::Factory(Draw_Interpretor& theCommands)
728 {
729   thePCommands = &theCommands;
730
731   // definition of QA Command
732   QADraw::CommonCommands(theCommands);
733   QADraw::AdditionalCommands(theCommands);
734
735   //ViewerTest::Commands (theCommands);
736   //ViewerTest::ViewerCommands (theCommands);
737
738 //#if defined(V2D)
739 //    Viewer2dTest::Commands(theCommands);
740 //#endif
741
742 //#ifdef DEB
743 //      cout << "Draw Plugin : QA commands are loaded" << endl;
744 //#endif
745 }
746
747 // Declare entry point PLUGINFACTORY
748 DPLUGIN(QADraw)