0024059: Eliminate compiler warning C4701 in MSVC++ with warning level 4
[occt.git] / src / ViewerTest / ViewerTest_ViewerCommands.cxx
1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 // Robert Boehne 30 May 2000 : Dec Osf
23
24 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27
28 #ifdef WNT
29 #include <windows.h>
30 #endif
31
32 #include <AIS_Shape.hxx>
33 #include <AIS_Drawer.hxx>
34 #include <AIS_InteractiveObject.hxx>
35 #include <AIS_ListOfInteractive.hxx>
36 #include <AIS_ListIteratorOfListOfInteractive.hxx>
37 #include <DBRep.hxx>
38 #include <Graphic3d_AspectMarker3d.hxx>
39 #include <Graphic3d_GraphicDriver.hxx>
40 #include <Graphic3d_ExportFormat.hxx>
41 #include <Graphic3d_NameOfTextureEnv.hxx>
42 #include <Graphic3d_TextureEnv.hxx>
43 #include <Graphic3d_TextureParams.hxx>
44 #include <Graphic3d_TypeOfTextureFilter.hxx>
45 #include <ViewerTest.hxx>
46 #include <ViewerTest_EventManager.hxx>
47 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
48 #include <Visual3d_View.hxx>
49 #include <Visual3d_ViewManager.hxx>
50 #include <V3d_LayerMgr.hxx>
51 #include <NCollection_DoubleMap.hxx>
52 #include <NCollection_List.hxx>
53 #include <NCollection_Vector.hxx>
54 #include <NIS_View.hxx>
55 #include <NIS_Triangulated.hxx>
56 #include <NIS_InteractiveContext.hxx>
57 #include <AIS_InteractiveContext.hxx>
58 #include <Draw_Interpretor.hxx>
59 #include <Draw.hxx>
60 #include <Draw_Appli.hxx>
61 #include <Aspect_PrintAlgo.hxx>
62 #include <Image_AlienPixMap.hxx>
63 #include <OSD_Timer.hxx>
64 #include <TColStd_SequenceOfInteger.hxx>
65 #include <TColStd_HSequenceOfReal.hxx>
66 #include <TColgp_Array1OfPnt2d.hxx>
67 #include <Visual3d_LayerItem.hxx>
68 #include <V3d_LayerMgr.hxx>
69 #include <V3d_LayerMgrPointer.hxx>
70 #include <Aspect_TypeOfLine.hxx>
71 #include <Image_Diff.hxx>
72 #include <Aspect_DisplayConnection.hxx>
73 #include <Graphic3d.hxx>
74
75 #ifdef WNT
76 #undef DrawText
77 #endif
78
79 #include <Visual3d_Layer.hxx>
80 #include <cstdlib>
81
82 #if defined(_WIN32) || defined(__WIN32__)
83   #include <WNT_WClass.hxx>
84   #include <WNT_Window.hxx>
85
86   #if defined(_MSC_VER)
87     #define _CRT_SECURE_NO_DEPRECATE
88     #pragma warning (disable:4996)
89   #endif
90 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
91   #include <Cocoa_Window.hxx>
92   #include <tk.h>
93 #else
94   #include <Xw_Window.hxx>
95   #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
96   #include <X11/Xutil.h>
97   #include <tk.h>
98 #endif
99
100 //==============================================================================
101
102 //==============================================================================
103 //  VIEWER GLOBAL VARIABLES
104 //==============================================================================
105
106 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
107
108 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
109 extern const Handle(NIS_InteractiveContext)& TheNISContext();
110 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
111
112 #if defined(_WIN32) || defined(__WIN32__)
113 static Handle(WNT_Window)& VT_GetWindow() {
114   static Handle(WNT_Window) WNTWin;
115   return WNTWin;
116 }
117 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
118 static Handle(Cocoa_Window)& VT_GetWindow()
119 {
120   static Handle(Cocoa_Window) aWindow;
121   return aWindow;
122 }
123 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
124 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
125 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
126
127 #else
128 static Handle(Xw_Window)& VT_GetWindow(){
129   static Handle(Xw_Window) XWWin;
130   return XWWin;
131 }
132
133 static void VProcessEvents(ClientData,int);
134 #endif
135
136 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
137 {
138   static Handle(Aspect_DisplayConnection) aDisplayConnection;
139   return aDisplayConnection;
140 }
141
142 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
143 {
144   GetDisplayConnection() = theDisplayConnection;
145 }
146
147 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
148 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
149 {
150   Aspect_Handle aWindowHandle = NULL;
151 #if defined(_WIN32) || defined(__WIN32__)
152   const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
153   if (!aWindow.IsNull())
154     return aWindow->HWindow();
155 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
156   const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
157   if (!aWindow.IsNull())
158   return aWindow->XWindow();
159 #endif
160   return aWindowHandle;
161 }
162 #endif
163
164 static Standard_Boolean MyHLRIsOn = Standard_False;
165
166 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
167 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
168 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
169
170
171 #define ZCLIPWIDTH 1.
172
173 static void OSWindowSetup();
174
175 //==============================================================================
176 //  EVENT GLOBAL VARIABLES
177 //==============================================================================
178
179 static int Start_Rot = 0;
180 static int ZClipIsOn = 0;
181 int X_Motion = 0; // Current cursor position
182 int Y_Motion = 0;
183 int X_ButtonPress = 0; // Last ButtonPress position
184 int Y_ButtonPress = 0;
185 Standard_Boolean IsDragged = Standard_False;
186 Standard_Boolean DragFirst;
187
188 //==============================================================================
189
190 #ifdef WNT
191 static LRESULT WINAPI ViewerWindowProc(
192                                        HWND hwnd,
193                                        UINT uMsg,
194                                        WPARAM wParam,
195                                        LPARAM lParam );
196 static LRESULT WINAPI AdvViewerWindowProc(
197   HWND hwnd,
198   UINT uMsg,
199   WPARAM wParam,
200   LPARAM lParam );
201 #endif
202
203
204 //==============================================================================
205 //function : WClass
206 //purpose  :
207 //==============================================================================
208
209 const Handle(MMgt_TShared)& ViewerTest::WClass()
210 {
211   static Handle(MMgt_TShared) theWClass;
212 #if defined(_WIN32) || defined(__WIN32__)
213   if (theWClass.IsNull())
214   {
215     theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
216       CS_VREDRAW | CS_HREDRAW, 0, 0,
217       ::LoadCursor (NULL, IDC_ARROW));
218   }
219 #endif
220   return theWClass;
221 }
222
223 //==============================================================================
224 //function : CreateName
225 //purpose  : Create numerical name for new object in theMap
226 //==============================================================================
227 template <typename ObjectType>
228 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
229                                     const TCollection_AsciiString& theDefaultString)
230 {
231   if (theObjectMap.IsEmpty())
232     return theDefaultString + TCollection_AsciiString(1);
233
234   Standard_Integer aNextKey = 1;
235   Standard_Boolean isFound = Standard_False;
236   while (!isFound)
237   {
238     TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
239     // Look for objects with default names
240     if (theObjectMap.IsBound1(aStringKey))
241     {
242       aNextKey++;
243     }
244     else
245       isFound = Standard_True;
246   }
247
248   return theDefaultString + TCollection_AsciiString(aNextKey);
249 }
250
251 //==============================================================================
252 //structure : ViewerTest_Names
253 //purpose   : Allow to operate with full view name: driverName/viewerName/viewName
254 //==============================================================================
255 struct ViewerTest_Names
256 {
257 private:
258   TCollection_AsciiString myDriverName;
259   TCollection_AsciiString myViewerName;
260   TCollection_AsciiString myViewName;
261
262 public:
263
264   const TCollection_AsciiString& GetDriverName () const
265   {
266     return myDriverName;
267   }
268   void SetDriverName (const TCollection_AsciiString& theDriverName)
269   {
270     myDriverName = theDriverName;
271   }
272   const TCollection_AsciiString& GetViewerName () const
273   {
274     return myViewerName;
275   }
276   void SetViewerName (const TCollection_AsciiString& theViewerName)
277   {
278     myViewerName = theViewerName;
279   }
280   const TCollection_AsciiString& GetViewName () const
281   {
282     return myViewName;
283   }
284   void SetViewName (const TCollection_AsciiString& theViewName)
285   {
286     myViewName = theViewName;
287   }
288
289   //===========================================================================
290   //function : Constructor for ViewerTest_Names
291   //purpose  : Get view, viewer, driver names from custom string
292   //===========================================================================
293
294   ViewerTest_Names (const TCollection_AsciiString& theInputString)
295   {
296     TCollection_AsciiString aName(theInputString);
297     if (theInputString.IsEmpty())
298     {
299       // Get current configuration
300       if (ViewerTest_myDrivers.IsEmpty())
301         myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
302           (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
303       else
304         myDriverName = ViewerTest_myDrivers.Find2
305         (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
306
307       if(ViewerTest_myContexts.IsEmpty())
308       {
309         myViewerName = CreateName <Handle(AIS_InteractiveContext)>
310           (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
311       }
312       else
313         myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
314
315         myViewName = CreateName <Handle(V3d_View)>
316           (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
317     }
318     else
319     {
320       // There is at least view name
321       Standard_Integer aParserNumber = 0;
322       for (Standard_Integer i = 0; i < 3; ++i)
323       {
324         Standard_Integer aParserPos = aName.SearchFromEnd("/");
325         if(aParserPos != -1)
326         {
327           aParserNumber++;
328           aName.Split(aParserPos-1);
329         }
330         else
331           break;
332       }
333       if (aParserNumber == 0)
334       {
335         // Only view name
336         if (!ViewerTest::GetAISContext().IsNull())
337         {
338           myDriverName = ViewerTest_myDrivers.Find2
339           (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
340           myViewerName = ViewerTest_myContexts.Find2
341           (ViewerTest::GetAISContext());
342         }
343         else
344         {
345           // There is no opened contexts here, need to create names for viewer and driver
346           myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
347             (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
348
349           myViewerName = CreateName <Handle(AIS_InteractiveContext)>
350             (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
351         }
352         myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
353       }
354       else if (aParserNumber == 1)
355       {
356         // Here is viewerName/viewName
357         if (!ViewerTest::GetAISContext().IsNull())
358           myDriverName = ViewerTest_myDrivers.Find2
359           (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
360         else
361         {
362           // There is no opened contexts here, need to create name for driver
363           myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
364             (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
365         }
366         myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
367
368         myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
369       }
370       else
371       {
372         //Here is driverName/viewerName/viewName
373         myDriverName = TCollection_AsciiString(aName);
374
375         TCollection_AsciiString aViewerName(theInputString);
376         aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
377         myViewerName = TCollection_AsciiString(aViewerName);
378
379         myViewName = TCollection_AsciiString(theInputString);
380       }
381     }
382   }
383 };
384
385 //==============================================================================
386 //function : FindContextByView
387 //purpose  : Find AIS_InteractiveContext by View
388 //==============================================================================
389
390 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
391 {
392   Handle(AIS_InteractiveContext) anAISContext;
393
394   for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
395        anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
396   {
397     if (anIter.Value()->CurrentViewer() == theView->Viewer())
398        return anIter.Key2();
399   }
400   return anAISContext;
401 }
402
403
404 //==============================================================================
405 //function : SetWindowTitle
406 //purpose  : Set window title
407 //==============================================================================
408
409 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
410                      Standard_CString theTitle)
411 {
412 #if defined(_WIN32) || defined(__WIN32__)
413   SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
414     theTitle);
415 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
416   SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
417 #else
418   if(GetDisplayConnection()->GetDisplay())
419   {
420     Window aWindow =
421       Handle(Xw_Window)::DownCast(theWindow)->XWindow();
422     XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
423   }
424 #endif
425 }
426
427 //==============================================================================
428 //function : IsWindowOverlapped
429 //purpose  : Check if theWindow overlapp another view
430 //==============================================================================
431
432 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
433                                      const Standard_Integer thePxTop,
434                                      const Standard_Integer thePxRight,
435                                      const Standard_Integer thePxBottom,
436                                      TCollection_AsciiString& theViewId)
437 {
438   for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
439       anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
440   {
441     Standard_Integer aTop = 0,
442       aLeft = 0,
443       aRight = 0,
444       aBottom = 0;
445     anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
446     if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
447         (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
448         (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
449         (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
450     {
451       theViewId = anIter.Key1();
452       return Standard_True;
453     }
454   }
455   return Standard_False;
456 }
457
458 // Workaround: to create and delete non-orthographic views outside ViewerTest
459 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
460 {
461   ViewerTest_myViews.UnBind1 (theName);
462 }
463
464 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
465                                const Handle(V3d_View)& theView)
466 {
467   ViewerTest_myViews.Bind (theName, theView);
468 }
469
470 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
471 {
472   return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
473 }
474 //==============================================================================
475 //function : ViewerInit
476 //purpose  : Create the window viewer and initialize all the global variable
477 //==============================================================================
478
479 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
480                                                 const Standard_Integer thePxTop,
481                                                 const Standard_Integer thePxWidth,
482                                                 const Standard_Integer thePxHeight,
483                                                 Standard_CString theViewName,
484                                                 Standard_CString theDisplayName)
485 {
486   // Default position and dimension of the viewer window.
487   // Note that left top corner is set to be sufficiently small to have
488   // window fit in the small screens (actual for remote desktops, see #23003).
489   // The position corresponds to the window's client area, thus some
490   // gap is added for window frame to be visible.
491
492   Standard_Integer aPxLeft   = 20;
493   Standard_Integer aPxTop    = 40;
494   Standard_Integer aPxWidth  = 409;
495   Standard_Integer aPxHeight = 409;
496   Standard_Boolean toCreateViewer = Standard_False;
497
498
499   Handle(Graphic3d_GraphicDriver) aGraphicDriver;
500   ViewerTest_Names aViewNames(theViewName);
501   if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
502     aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
503
504   if (thePxLeft != 0)
505     aPxLeft = thePxLeft;
506   if (thePxTop != 0)
507     aPxTop = thePxTop;
508   if (thePxWidth != 0)
509     aPxWidth = thePxWidth;
510   if (thePxHeight != 0)
511     aPxHeight = thePxHeight;
512  
513   // Get graphic driver (create it or get from another view)
514   if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
515   {
516     // Get connection string
517   #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
518     TCollection_AsciiString aDisplayName(theDisplayName);
519     if (aDisplayName.IsEmpty())
520       SetDisplayConnection (new Aspect_DisplayConnection ());
521     else
522       SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
523
524   #else
525     SetDisplayConnection (new Aspect_DisplayConnection ());
526   #endif
527     aGraphicDriver = Graphic3d::InitGraphicDriver (GetDisplayConnection());
528     ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
529     toCreateViewer = Standard_True;
530   }
531   else
532   {
533     aGraphicDriver = ViewerTest_myDrivers.Find1(aViewNames.GetDriverName());
534   }
535
536   //Dispose the window if input parameters are default
537   if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
538   {
539     Standard_Integer aTop = 0,
540                      aLeft = 0,
541                      aRight = 0,
542                      aBottom = 0,
543                      aScreenWidth = 0,
544                      aScreenHeight = 0;
545
546     // Get screen resolution
547 #if defined(_WIN32) || defined(__WIN32__)
548     RECT aWindowSize;
549     GetClientRect(GetDesktopWindow(), &aWindowSize);
550     aScreenHeight = aWindowSize.bottom;
551     aScreenWidth = aWindowSize.right;
552 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
553     GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
554 #else
555     Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
556     aScreenWidth = WidthOfScreen(aScreen);
557     aScreenHeight = HeightOfScreen(aScreen);
558 #endif
559
560     TCollection_AsciiString anOverlappedViewId("");
561
562     while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
563     {
564       ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
565
566       if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
567         && aRight + 2*aPxWidth + 40 > aScreenWidth)
568       {
569         if (aBottom + aPxHeight + 40 > aScreenHeight)
570         {
571           aPxLeft = 20;
572           aPxTop = 40;
573           break;
574         }
575         aPxLeft = 20;
576         aPxTop = aBottom + 40;
577       }
578       else
579         aPxLeft = aRight + 20;
580     }
581   }
582
583   // Get viewer name
584   TCollection_AsciiString aTitle("3D View - ");
585   aTitle = aTitle + aViewNames.GetViewName() + "(*)";
586
587   // Change name of current active window
588   if (!ViewerTest::CurrentView().IsNull())
589   {
590     TCollection_AsciiString aTitle("3D View - ");
591     aTitle = aTitle
592       + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
593     SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
594   }
595
596   // Create viewer
597   Handle(V3d_Viewer) a3DViewer, a3DCollector;
598   // If it's the single view, we first look for empty context
599   if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
600   {
601     NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
602       anIter(ViewerTest_myContexts);
603     if (anIter.More())
604       ViewerTest::SetAISContext (anIter.Value());
605     a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
606     a3DCollector= ViewerTest::GetAISContext()->Collector();
607   }
608   else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
609   {
610     ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
611     a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
612     a3DCollector= ViewerTest::GetAISContext()->Collector();
613   }
614   else if (a3DViewer.IsNull() || a3DCollector.IsNull())
615   {
616     toCreateViewer = Standard_True;
617     TCollection_ExtendedString NameOfWindow("Viewer3D");
618     a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
619
620     NameOfWindow = TCollection_ExtendedString("Collector");
621     a3DCollector = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
622
623     a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
624     a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
625   }
626
627   // AIS context setup
628   if (ViewerTest::GetAISContext().IsNull() ||
629       !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
630   {
631     Handle(AIS_InteractiveContext) aContext =
632       new AIS_InteractiveContext(a3DViewer, a3DCollector);
633     ViewerTest::SetAISContext (aContext);
634     ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
635   }
636   else
637     ViewerTest::ResetEventManager();
638
639   // Create window
640 #if defined(_WIN32) || defined(__WIN32__)
641       VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
642                                        Handle(WNT_WClass)::DownCast (WClass()),
643                                        WS_OVERLAPPEDWINDOW,
644                                        aPxLeft, aPxTop,
645                                        aPxWidth, aPxHeight,
646                                        Quantity_NOC_BLACK);
647 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
648       VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
649                                          aPxLeft, aPxTop,
650                                          aPxWidth, aPxHeight);
651       ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
652 #else
653       VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
654                                       aTitle.ToCString(),
655                                       aPxLeft, aPxTop,
656                                       aPxWidth, aPxHeight);
657 #endif
658   VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
659
660   // NIS setup
661   Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
662   
663   ViewerTest::CurrentView(aView);
664   ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
665   TheNISContext()->AttachView (aView);
666
667   // Setup for X11 or NT
668   OSWindowSetup();
669
670   // Set parameters for V3d_View and V3d_Viewer
671   const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
672   aV3dView->SetComputedMode(Standard_False);
673   MyHLRIsOn = aV3dView->ComputedMode();
674   aV3dView->SetZClippingDepth(0.5);
675   aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
676
677   a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
678   if (toCreateViewer)
679   {
680     a3DViewer->SetDefaultLights();
681     a3DViewer->SetLightOn();
682   }
683
684   #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
685   #if TCL_MAJOR_VERSION  < 8
686   Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
687       TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
688   #else
689   Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
690       TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
691   #endif
692   #endif
693
694   VT_GetWindow()->Map();
695   
696   // Set the handle of created view in the event manager
697   ViewerTest::ResetEventManager();
698
699   ViewerTest::CurrentView()->Redraw();
700
701   aView.Nullify();
702   a3DViewer.Nullify();
703   a3DCollector.Nullify();
704
705   return aViewNames.GetViewName();
706 }
707
708 //==============================================================================
709 //function : SplitParameter
710 //purpose  : Split parameter string to parameter name an patameter value
711 //==============================================================================
712 Standard_Boolean SplitParameter (const TCollection_AsciiString& theString,
713                                       TCollection_AsciiString& theName,
714                                       TCollection_AsciiString& theValue)
715 {
716   Standard_Integer aParamNameEnd = theString.FirstLocationInSet("=",1, theString.Length());
717   if (aParamNameEnd == 0)
718     return Standard_False;
719   TCollection_AsciiString aString(theString);
720   if (aParamNameEnd != 0)
721   {
722     theValue = aString.Split(aParamNameEnd);
723     aString.Split(aString.Length()-1);
724     theName = aString;
725   }
726   return Standard_True;
727 }
728
729 //==============================================================================
730 //function : Vinit
731 //purpose  : Create the window viewer and initialize all the global variable
732 //    Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
733 //==============================================================================
734
735 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
736 {
737 if (theArgsNb > 9)
738   {
739     theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
740       << "Type help for more information.\n";
741     return 1;
742   }
743   TCollection_AsciiString aViewName (""),
744                           aDisplayName ("");
745   Standard_Integer aPxLeft = 0,
746                   aPxTop = 0,
747                   aPxWidth = 0,
748                   aPxHeight = 0;
749
750   for (Standard_Integer i = 1; i < theArgsNb; ++i)
751   {
752     TCollection_AsciiString aName = "", aValue = "";
753     if(!SplitParameter (TCollection_AsciiString(theArgVec[i]),aName,aValue) && theArgsNb == 2)
754     {
755       // In case of syntax: vinit ViewName
756       aViewName = theArgVec[1];
757     }
758     else
759     {
760       if (aName == "name")
761       {
762         aViewName = aValue;
763       }
764       else if (aName == "l" || aName == "left")
765         aPxLeft = aValue.IntegerValue();
766       else if (aName == "t" || aName == "top")
767         aPxTop = aValue.IntegerValue();
768 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
769       else if (aName == "display")
770         aDisplayName = aValue;
771 #endif
772       else if (aName == "w" || aName == "width")
773         aPxWidth = aValue.IntegerValue();
774       else if (aName == "h" || aName == "height")
775         aPxHeight = aValue.IntegerValue();
776       else
777       {
778         theDi << theArgVec[0] << ": Warning: unknown parameter " << aName.ToCString() << ".\n";
779       }
780     }
781   }
782
783   ViewerTest_Names aViewNames (aViewName);
784   if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
785   {
786     TCollection_AsciiString aCommand("vactivate ");
787     aCommand = aCommand + aViewNames.GetViewName();
788     theDi.Eval(aCommand.ToCString());
789     return 0;
790   }
791
792   TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
793                                                             aViewName.ToCString(),
794                                                             aDisplayName.ToCString());
795   cout << theArgVec[0] << ": 3D View - " << aViewId << " was created.\n";
796   return 0;
797 }
798
799 //==============================================================================
800 //function : VHLR
801 //purpose  : hidden lines removal algorithm
802 //==============================================================================
803
804 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
805 {
806   if (ViewerTest::CurrentView().IsNull())
807   {
808     di << argv[0] << ": Call vinit before this command, please.\n";
809     return 1;
810   }
811
812   if (argc != 2)
813   {
814     di << argv[0] << ": Wrong number of command arguments.\n"
815       << "Type help " << argv[0] << " for more information.\n";
816     return 1;
817   }
818
819   Standard_Boolean isHLROn =
820     (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
821
822   if (isHLROn == MyHLRIsOn)
823   {
824     return 0;
825   }
826
827   MyHLRIsOn = isHLROn;
828   ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
829
830   return 0;
831 }
832
833 //==============================================================================
834 //function : VHLRType
835 //purpose  : change type of using HLR algorithm
836 //==============================================================================
837
838 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
839 {
840   if (ViewerTest::CurrentView().IsNull())
841   {
842     di << argv[0] << ": Call vinit before this command, please.\n";
843     return 1;
844   }
845
846   if (argc < 2)
847   {
848     di << argv[0] << ": Wrong number of command arguments.\n"
849       << "Type help " << argv[0] << " for more information.\n";
850     return 1;
851   }
852
853   Prs3d_TypeOfHLR aTypeOfHLR =
854     (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
855
856   if (argc == 2)
857   {
858     AIS_ListOfInteractive aListOfShapes;
859     ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
860     ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
861     for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
862       anIter.More(); anIter.Next())
863     {
864       Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
865       if (aShape.IsNull())
866         continue;
867       if (aShape->TypeOfHLR() != aTypeOfHLR)
868         aShape->SetTypeOfHLR (aTypeOfHLR);
869       if (MyHLRIsOn)
870         aShape->Redisplay();
871     }
872     ViewerTest::CurrentView()->Update();
873     return 0;
874   }
875   else
876   {
877     for (Standard_Integer i = 2; i < argc; ++i)
878     {
879       ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
880       TCollection_AsciiString aName (argv[i]);
881
882       if (!aMap.IsBound2 (aName))
883       {
884         di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
885         continue;
886       }
887       Handle(AIS_Shape) anAISObject =
888         Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
889       if (anAISObject.IsNull())
890         continue;
891       anAISObject->SetTypeOfHLR (aTypeOfHLR);
892       if (MyHLRIsOn)
893         anAISObject->Redisplay();
894     }
895     ViewerTest::CurrentView()->Update();
896   }
897
898   return 0;
899 }
900
901 //==============================================================================
902 //function : FindViewIdByWindowHandle
903 //purpose  : Find theView Id in the map of views by window handle
904 //==============================================================================
905 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
906 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
907 {
908   for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
909        anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
910   {
911     Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
912     if (aWindowHandle == theWindowHandle)
913       return anIter.Key1();
914   }
915   return TCollection_AsciiString("");
916 }
917 #endif
918
919 //==============================================================================
920 //function : ActivateView
921 //purpose  : Make the view active
922 //==============================================================================
923
924 void ActivateView (const TCollection_AsciiString& theViewName)
925 {
926   const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
927   if (!aView.IsNull())
928   {
929     Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
930     if (!anAISContext.IsNull())
931     {
932       if (!ViewerTest::CurrentView().IsNull())
933       {
934         TCollection_AsciiString aTitle("3D View - ");
935         aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
936         SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
937       }
938
939       ViewerTest::CurrentView (aView);
940       // Update degenerate mode
941       MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
942       ViewerTest::SetAISContext (anAISContext);
943       TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
944       aTitle = aTitle + theViewName + "(*)";
945       SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
946 #if defined(_WIN32) || defined(__WIN32__)
947       VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
948 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
949       VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
950 #else
951       VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
952 #endif
953       SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
954       ViewerTest::CurrentView()->Redraw();
955     }
956   }
957 }
958
959 //==============================================================================
960 //function : RemoveView
961 //purpose  : Close and remove view from display, clear maps if neccessary
962 //==============================================================================
963 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
964 {
965   if (!ViewerTest_myViews.IsBound1(theViewName))
966   {
967     cout << "Wrong view name\n";
968     return;
969   }
970
971   // Activate another view if it's active now
972   if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
973   {
974     if (ViewerTest_myViews.Extent() > 1)
975     {
976       TCollection_AsciiString aNewViewName;
977       for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
978            anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
979         if (anIter.Key1() != theViewName)
980         {
981           aNewViewName = anIter.Key1();
982           break;
983         }
984         ActivateView (aNewViewName);
985     }
986     else
987     {
988       Handle(V3d_View) anEmptyView;
989 #if defined(_WIN32) || defined(__WIN32__)
990       Handle(WNT_Window) anEmptyWindow;
991 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
992       Handle(Cocoa_Window) anEmptyWindow;
993 #else
994       Handle(Xw_Window) anEmptyWindow;
995 #endif
996       VT_GetWindow() = anEmptyWindow;
997       ViewerTest::CurrentView (anEmptyView);
998       if (isContextRemoved)
999       {
1000         Handle(AIS_InteractiveContext) anEmptyContext;
1001         ViewerTest::SetAISContext(anEmptyContext);
1002       }
1003     }
1004   }
1005
1006   // Delete view
1007   Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1008   Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1009
1010   // Remove view resources
1011   TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1012   ViewerTest_myViews.UnBind1(theViewName);
1013   aView->Remove();
1014
1015 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1016   XFlush (GetDisplayConnection()->GetDisplay());
1017 #endif
1018
1019   // Keep context opened only if the closed view is last to avoid
1020   // unused empty contexts
1021   if (!aCurrentContext.IsNull())
1022   {
1023     // Check if there are more difined views in the viewer
1024     aCurrentContext->CurrentViewer()->InitDefinedViews();
1025     if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1026     {
1027       // Remove driver if there is no viewers that use it
1028       Standard_Boolean isRemoveDriver = Standard_True;
1029       for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1030           anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1031       {
1032         if (aCurrentContext != anIter.Key2() &&
1033           aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1034         {
1035           isRemoveDriver = Standard_False;
1036           break;
1037         }
1038       }
1039       if(isRemoveDriver)
1040       {
1041         ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1042       #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1043         #if TCL_MAJOR_VERSION  < 8
1044         Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1045         #else
1046         Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1047         #endif
1048       #endif
1049       }
1050
1051       ViewerTest_myContexts.UnBind2(aCurrentContext);
1052     }
1053   }
1054   cout << "3D View - " << theViewName << " was deleted.\n";
1055
1056 }
1057
1058 //==============================================================================
1059 //function : VClose
1060 //purpose  : Remove the view defined by its name
1061 //==============================================================================
1062
1063 static int VClose (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1064 {
1065   if (theArgsNb < 2)
1066   {
1067     theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
1068       << "Type help " << theArgVec[0] << " for more information.\n";
1069     return 1;
1070   }
1071
1072   if (ViewerTest_myViews.IsEmpty())
1073   {
1074     theDi << theArgVec[0] <<": there is no views to close.\n";
1075     return 0;
1076   }
1077
1078   TCollection_AsciiString anInputString(theArgVec[1]);
1079   
1080   // Create list to iterate and remove views from the map of views
1081   NCollection_List<TCollection_AsciiString> aViewList;
1082   if ( strcasecmp( anInputString.ToCString(), "ALL" ) == 0 )
1083   {
1084     for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter(ViewerTest_myViews);
1085          anIter.More(); anIter.Next())
1086     {
1087       aViewList.Append(anIter.Key1());
1088     }
1089   }
1090   else
1091   {
1092     ViewerTest_Names aViewNames(anInputString);
1093     aViewList.Append(aViewNames.GetViewName());
1094   }
1095
1096   Standard_Boolean isContextRemoved = (theArgsNb == 3 && atoi(theArgVec[2])==1) ? Standard_False : Standard_True;
1097   for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1098        anIter.More(); anIter.Next())
1099   {
1100     ViewerTest::RemoveView(anIter.Value(), isContextRemoved);
1101   }
1102
1103   return 0;
1104 }
1105
1106 //==============================================================================
1107 //function : VActivate
1108 //purpose  : Activate the view defined by its ID
1109 //==============================================================================
1110
1111 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1112 {
1113   if (theArgsNb > 2)
1114   {
1115     theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1116     << "Usage: " << theArgVec[0] << " ViewID\n";
1117     return 1;
1118   }
1119   if(theArgsNb == 1)
1120   {
1121     theDi.Eval("vviewlist");
1122     return 0;
1123   }
1124
1125   TCollection_AsciiString aNameString(theArgVec[1]);
1126   if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1127   {
1128     TCollection_AsciiString aTitle("3D View - ");
1129     aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1130     SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1131     Handle(V3d_View) anEmptyView;
1132 #if defined(_WIN32) || defined(__WIN32__)
1133     Handle(WNT_Window) anEmptyWindow;
1134 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1135     Handle(Cocoa_Window) anEmptyWindow;
1136 #else
1137     Handle(Xw_Window) anEmptyWindow;
1138 #endif
1139     VT_GetWindow() = anEmptyWindow;
1140     ViewerTest::CurrentView (anEmptyView);
1141     ViewerTest::ResetEventManager();
1142     theDi << theArgVec[0] << ": all views are inactive\n";
1143     return 0;
1144   }
1145
1146   ViewerTest_Names aViewNames(aNameString);
1147
1148   // Check if this view exists in the viewer with the driver
1149   if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1150   {
1151     theDi << "Wrong view name\n";
1152     return 1;
1153   }
1154
1155   // Check if it is active already
1156   if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1157   {
1158     theDi << theArgVec[0] << ": the view is active already\n";
1159     return 0;
1160   }
1161
1162   ActivateView (aViewNames.GetViewName());
1163   return 0;
1164 }
1165
1166 //==============================================================================
1167 //function : VViewList
1168 //purpose  : Print current list of views per viewer and graphic driver ID
1169 //           shared between viewers
1170 //==============================================================================
1171
1172 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1173 {
1174   if (theArgsNb > 2)
1175   {
1176     theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1177           << "Usage: " << theArgVec[0] << " name";
1178     return 1;
1179   }
1180   if (ViewerTest_myContexts.Size() < 1)
1181     return 0;
1182
1183   Standard_Boolean isTreeView =
1184     (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1185
1186   if (isTreeView)
1187     theDi << theArgVec[0] <<":\n";
1188
1189     for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1190       aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1191     {
1192       if (isTreeView)
1193         theDi << aDriverIter.Key1() << ":\n";
1194
1195       for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1196         aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1197       {
1198         if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1199         {
1200           if (isTreeView)
1201           {
1202             TCollection_AsciiString aContextName(aContextIter.Key1());
1203             theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1204           }
1205
1206           for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1207             aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1208           {
1209             if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1210             {
1211               TCollection_AsciiString aViewName(aViewIter.Key1());
1212               if (isTreeView)
1213               {
1214                 if (aViewIter.Value() == ViewerTest::CurrentView())
1215                   theDi << "  " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1216                 else
1217                   theDi << "  " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1218               }
1219               else
1220               {
1221                 theDi << aViewName << " ";
1222               }
1223             }
1224           }
1225         }
1226       }
1227     }
1228   return 0;
1229 }
1230
1231 //==============================================================================
1232 //function : VT_ProcessKeyPress
1233 //purpose  : Handle KeyPress event from a CString
1234 //==============================================================================
1235 void VT_ProcessKeyPress (const char* buf_ret)
1236 {
1237   //cout << "KeyPress" << endl;
1238   const Handle(V3d_View) aView = ViewerTest::CurrentView();
1239   const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1240   // Letter in alphabetic order
1241
1242   if ( !strcasecmp(buf_ret, "A") ) {
1243     // AXO
1244     aView->SetProj(V3d_XposYnegZpos);
1245   }
1246   else if ( !strcasecmp(buf_ret, "D") ) {
1247     // Reset
1248     aView->Reset();
1249   }
1250   else if ( !strcasecmp(buf_ret, "F") ) {
1251     // FitAll
1252     if (aNisView.IsNull())
1253       aView->FitAll();
1254     else
1255       aNisView->FitAll3d();
1256   }
1257   else if ( !strcasecmp(buf_ret, "H") ) {
1258     // HLR
1259     cout << "HLR" << endl;
1260     aView->SetComputedMode (!aView->ComputedMode());
1261     MyHLRIsOn = aView->ComputedMode();
1262   }
1263   else if ( !strcasecmp(buf_ret, "P") ) {
1264     // Type of HLR
1265     Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1266     if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1267       aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1268     else
1269       aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1270     if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1271     {
1272       AIS_ListOfInteractive aListOfShapes;
1273       aContext->DisplayedObjects(aListOfShapes);
1274       for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1275         anIter.More(); anIter.Next())
1276       {
1277         Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1278         if (aShape.IsNull())
1279           continue;
1280         if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1281           aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1282         else
1283           aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1284         aShape->Redisplay();
1285       }
1286     }
1287     else
1288     {
1289       for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1290       {
1291         Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1292         if (aShape.IsNull())
1293           continue;
1294         if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1295           aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1296         else
1297           aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1298         aShape->Redisplay();
1299       }
1300     }
1301
1302     aContext->UpdateCurrentViewer();
1303     
1304   }
1305   else if ( !strcasecmp(buf_ret, "S") ) {
1306     // SHADING
1307     cout << "passage en mode 1 (shading pour les shapes)" << endl;
1308
1309     Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1310     if(Ctx->NbCurrents()==0 ||
1311       Ctx->NbSelected()==0)
1312       Ctx->SetDisplayMode(AIS_Shaded);
1313     else{
1314       if(Ctx->HasOpenedContext()){
1315         for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1316           Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1317       }
1318       else{
1319         for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1320           Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1321       }
1322       Ctx->UpdateCurrentViewer();
1323     }
1324   }
1325   else if ( !strcasecmp(buf_ret, "U") ) {
1326     // Unset display mode
1327     cout<<"passage au mode par defaut"<<endl;
1328
1329     Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1330     if(Ctx->NbCurrents()==0 ||
1331       Ctx->NbSelected()==0)
1332       Ctx->SetDisplayMode(AIS_WireFrame);
1333     else{
1334       if(Ctx->HasOpenedContext()){
1335         for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1336           Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1337       }
1338       else{
1339         for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1340           Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1341       }
1342       Ctx->UpdateCurrentViewer();
1343     }
1344
1345   }
1346   else if ( !strcasecmp(buf_ret, "T") ) {
1347     // Top
1348     aView->SetProj(V3d_Zpos);
1349   }
1350   else if ( !strcasecmp(buf_ret, "B") ) {
1351     // Bottom
1352     aView->SetProj(V3d_Zneg);
1353   }
1354   else if ( !strcasecmp(buf_ret, "L") ) {
1355     // Left
1356     aView->SetProj(V3d_Xneg);
1357   }
1358   else if ( !strcasecmp(buf_ret, "R") ) {
1359     // Right
1360     aView->SetProj(V3d_Xpos);
1361   }
1362
1363   else if ( !strcasecmp(buf_ret, "W") ) {
1364     // WIREFRAME
1365     cout << "passage en mode 0 (filaire pour les shapes)" << endl;
1366     Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1367     if(Ctx->NbCurrents()==0 ||
1368       Ctx->NbSelected()==0)
1369       Ctx->SetDisplayMode(AIS_WireFrame);
1370     else{
1371       if(Ctx->HasOpenedContext()){
1372         for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1373           Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1374       }
1375       else{
1376         for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1377           Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1378       }
1379       Ctx->UpdateCurrentViewer();
1380     }
1381   }
1382   else if ( !strcasecmp(buf_ret, "Z") ) {
1383     // ZCLIP
1384
1385     if ( ZClipIsOn ) {
1386       cout << "ZClipping OFF" << endl;
1387       ZClipIsOn = 0;
1388
1389       aView->SetZClippingType(V3d_OFF);
1390       aView->Redraw();
1391     }
1392     else {
1393       cout << "ZClipping ON" << endl;
1394       ZClipIsOn = 1;
1395
1396       aView->SetZClippingType(V3d_FRONT);
1397       aView->Redraw();
1398     }
1399   }
1400   else if ( !strcasecmp(buf_ret, ",") ) {
1401     ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1402
1403
1404   }
1405   else if ( !strcasecmp(buf_ret, ".") ) {
1406     ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1407   }
1408   // Number
1409   else{
1410     Standard_Integer Num = Draw::Atoi(buf_ret);
1411     if(Num>=0 && Num<=7)
1412       ViewerTest::StandardModeActivation(Num);
1413   }
1414 }
1415
1416 //==============================================================================
1417 //function : VT_ProcessExpose
1418 //purpose  : Redraw the View on an Expose Event
1419 //==============================================================================
1420 void VT_ProcessExpose()
1421 {
1422   Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1423   if (!aView3d.IsNull())
1424   {
1425     aView3d->Redraw();
1426   }
1427 }
1428
1429 //==============================================================================
1430 //function : VT_ProcessConfigure
1431 //purpose  : Resize the View on an Configure Event
1432 //==============================================================================
1433 void VT_ProcessConfigure()
1434 {
1435   Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1436   if (aView3d.IsNull())
1437   {
1438     return;
1439   }
1440
1441   aView3d->MustBeResized();
1442   aView3d->Update();
1443   aView3d->Redraw();
1444 }
1445
1446 //==============================================================================
1447 //function : VT_ProcessButton1Press
1448 //purpose  : Picking
1449 //==============================================================================
1450 Standard_Boolean VT_ProcessButton1Press(
1451   Standard_Integer ,
1452   const char**     argv,
1453   Standard_Boolean pick,
1454   Standard_Boolean shift)
1455 {
1456   Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1457   if ( pick ) {
1458     Standard_Real X, Y, Z;
1459
1460     ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
1461
1462     Draw::Set(argv[1], X);
1463     Draw::Set(argv[2], Y);
1464     Draw::Set(argv[3], Z);}
1465
1466   if(shift)
1467     EM->ShiftSelect();
1468   else
1469     EM->Select();
1470
1471   pick = 0;
1472   return pick;
1473 }
1474
1475 //==============================================================================
1476 //function : VT_ProcessButton1Release
1477 //purpose  : End selecting
1478 //==============================================================================
1479 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1480 {
1481   if (IsDragged)
1482   {
1483     IsDragged = Standard_False;
1484     Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1485     if (theIsShift)
1486     {
1487       EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1488                        Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1489     }
1490     else
1491     {
1492       EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1493                   Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1494     }
1495   }
1496 }
1497
1498 //==============================================================================
1499 //function : VT_ProcessButton3Press
1500 //purpose  : Start Rotation
1501 //==============================================================================
1502 void VT_ProcessButton3Press()
1503 {
1504   Start_Rot = 1;
1505   if (MyHLRIsOn)
1506   {
1507     ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1508   }
1509   ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1510 }
1511
1512 //==============================================================================
1513 //function : VT_ProcessButton3Release
1514 //purpose  : End rotation
1515 //==============================================================================
1516 void VT_ProcessButton3Release()
1517 {
1518   if (Start_Rot)
1519   {
1520     Start_Rot = 0;
1521     if (MyHLRIsOn)
1522     {
1523       ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1524     }
1525   }
1526 }
1527
1528 //==============================================================================
1529 //function : ProcessZClipMotion
1530 //purpose  : Zoom
1531 //==============================================================================
1532
1533 void ProcessZClipMotion()
1534 {
1535   Handle(V3d_View)  a3DView = ViewerTest::CurrentView();
1536   if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1537     static Standard_Real CurZPos = 0.;
1538
1539     //Quantity_Length VDX, VDY;
1540     //a3DView->Size(VDX,VDY);
1541     //Standard_Real VDZ = a3DView->ZSize();
1542     //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1543
1544     Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1545
1546     // Front = Depth + width/2.
1547     Standard_Real D = 0.5;
1548     Standard_Real W = 0.1;
1549
1550     CurZPos += (dx);
1551
1552     D += CurZPos;
1553
1554     //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1555
1556     a3DView->SetZClippingType(V3d_OFF);
1557     a3DView->SetZClippingDepth(D);
1558     a3DView->SetZClippingWidth(W);
1559     a3DView->SetZClippingType(V3d_FRONT);
1560
1561     a3DView->Redraw();
1562
1563     X_ButtonPress = X_Motion;
1564     Y_ButtonPress = Y_Motion;
1565   }
1566 }
1567
1568 //==============================================================================
1569 //function : ProcessControlButton1Motion
1570 //purpose  : Zoom
1571 //==============================================================================
1572
1573 static void ProcessControlButton1Motion()
1574 {
1575   ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1576
1577   X_ButtonPress = X_Motion;
1578   Y_ButtonPress = Y_Motion;
1579 }
1580
1581 //==============================================================================
1582 //function : VT_ProcessControlButton2Motion
1583 //purpose  : Panning
1584 //==============================================================================
1585 void VT_ProcessControlButton2Motion()
1586 {
1587   Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1588   Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
1589
1590   dy = -dy; // Xwindow Y axis is from top to Bottom
1591
1592   ViewerTest::CurrentView()->Panning( dx, dy );
1593
1594   X_ButtonPress = X_Motion;
1595   Y_ButtonPress = Y_Motion;
1596 }
1597
1598 //==============================================================================
1599 //function : VT_ProcessControlButton3Motion
1600 //purpose  : Rotation
1601 //==============================================================================
1602 void VT_ProcessControlButton3Motion()
1603 {
1604   if (Start_Rot)
1605   {
1606     ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1607   }
1608 }
1609
1610 //==============================================================================
1611 //function : VT_ProcessMotion
1612 //purpose  :
1613 //==============================================================================
1614 void VT_ProcessMotion()
1615 {
1616   //pre-hilights detected objects at mouse position
1617
1618   Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1619   EM->MoveTo(X_Motion, Y_Motion);
1620 }
1621
1622
1623 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1624 {
1625   Xpix = X_Motion;Ypix=Y_Motion;
1626 }
1627
1628 //==============================================================================
1629 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1630 //purpose  : Switches to an axonometric, top, left and other views
1631 //==============================================================================
1632
1633 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1634 {
1635   if ( ViewerTest::CurrentView().IsNull() )
1636   {
1637     di<<"Call vinit before this command, please"<<"\n";
1638     return 1;
1639   }
1640
1641   ViewerTest::CurrentView()->SetProj(ori);
1642   return 0;
1643 }
1644
1645 //==============================================================================
1646 //function : VAxo
1647 //purpose  : Switch to an Axonometric view
1648 //Draw arg : No args
1649 //==============================================================================
1650
1651 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1652 {
1653   return ViewProject(di, V3d_XposYnegZpos);
1654 }
1655
1656 //==============================================================================
1657 //function : VTop
1658 //purpose  : Switch to a Top View
1659 //Draw arg : No args
1660 //==============================================================================
1661
1662 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1663 {
1664   return ViewProject(di, V3d_Zpos);
1665 }
1666
1667 //==============================================================================
1668 //function : VBottom
1669 //purpose  : Switch to a Bottom View
1670 //Draw arg : No args
1671 //==============================================================================
1672
1673 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1674 {
1675   return ViewProject(di, V3d_Zneg);
1676 }
1677
1678 //==============================================================================
1679 //function : VLeft
1680 //purpose  : Switch to a Left View
1681 //Draw arg : No args
1682 //==============================================================================
1683
1684 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1685 {
1686   return ViewProject(di, V3d_Ypos);
1687 }
1688
1689 //==============================================================================
1690 //function : VRight
1691 //purpose  : Switch to a Right View
1692 //Draw arg : No args
1693 //==============================================================================
1694
1695 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1696 {
1697   return ViewProject(di, V3d_Yneg);
1698 }
1699
1700 //==============================================================================
1701 //function : VFront
1702 //purpose  : Switch to a Front View
1703 //Draw arg : No args
1704 //==============================================================================
1705
1706 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1707 {
1708   return ViewProject(di, V3d_Xpos);
1709 }
1710
1711 //==============================================================================
1712 //function : VBack
1713 //purpose  : Switch to a Back View
1714 //Draw arg : No args
1715 //==============================================================================
1716
1717 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1718 {
1719   return ViewProject(di, V3d_Xneg);
1720 }
1721
1722 //==============================================================================
1723 //function : VHelp
1724 //purpose  : Dsiplay help on viewer Keyboead and mouse commands
1725 //Draw arg : No args
1726 //==============================================================================
1727
1728 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1729 {
1730
1731   di << "Q : Quit the application" << "\n";
1732
1733   di << "========================="<<"\n";
1734   di << "F : FitAll" << "\n";
1735   di << "T : TopView" << "\n";
1736   di << "B : BottomView" << "\n";
1737   di << "R : RightView" << "\n";
1738   di << "L : LeftView" << "\n";
1739   di << "A : AxonometricView" << "\n";
1740   di << "D : ResetView" << "\n";
1741
1742   di << "========================="<<"\n";
1743   di << "S : Shading" << "\n";
1744   di << "W : Wireframe" << "\n";
1745   di << "H : HidelLineRemoval" << "\n";
1746   di << "U : Unset display mode" << "\n";
1747
1748   di << "========================="<<"\n";
1749   di << "Selection mode "<<"\n";
1750   di << "0 : Shape" <<"\n";
1751   di << "1 : Vertex" <<"\n";
1752   di << "2 : Edge" <<"\n";
1753   di << "3 : Wire" <<"\n";
1754   di << "4 : Face" <<"\n";
1755   di << "5 : Shell" <<"\n";
1756   di << "6 : Solid" <<"\n";
1757   di << "7 : Compound" <<"\n";
1758
1759   di << "========================="<<"\n";
1760   di << "Z : Switch Z clipping On/Off" << "\n";
1761   di << ", : Hilight next detected" << "\n";
1762   di << ". : Hilight previous detected" << "\n";
1763
1764   return 0;
1765 }
1766
1767 #ifdef WNT
1768
1769 static Standard_Boolean Ppick = 0;
1770 static Standard_Integer Pargc = 0;
1771 static const char**           Pargv = NULL;
1772
1773
1774 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1775                                           UINT Msg,
1776                                           WPARAM wParam,
1777                                           LPARAM lParam )
1778 {
1779   if (!ViewerTest_myViews.IsEmpty()) {
1780
1781     WPARAM fwKeys = wParam;
1782
1783     switch( Msg ) {
1784     case WM_CLOSE:
1785        {
1786          // Delete view from map of views
1787          ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1788          return 0;
1789        }
1790        break;
1791     case WM_ACTIVATE:
1792       if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1793         || ViewerTest::CurrentView().IsNull())
1794       {
1795         // Activate inactive window
1796         if(GetWindowHandle(VT_GetWindow()) != hwnd)
1797         {
1798           ActivateView (FindViewIdByWindowHandle(hwnd));
1799         }
1800       }
1801       break;
1802     case WM_LBUTTONUP:
1803       IsDragged = Standard_False;
1804       if( !DragFirst )
1805       {
1806         HDC hdc = GetDC( hwnd );
1807         SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1808         SetROP2( hdc, R2_NOT );
1809         Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1810         ReleaseDC( hwnd, hdc );
1811
1812         const Handle(ViewerTest_EventManager) EM =
1813           ViewerTest::CurrentEventManager();
1814         if ( fwKeys & MK_SHIFT )
1815           EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1816           max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1817         else
1818           EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1819           max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1820       }
1821       return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1822
1823     case WM_LBUTTONDOWN:
1824       if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1825       {
1826         IsDragged = Standard_True;
1827         DragFirst = Standard_True;
1828         X_ButtonPress = LOWORD(lParam);
1829         Y_ButtonPress = HIWORD(lParam);
1830       }
1831       return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1832
1833       break;
1834
1835     case WM_MOUSEMOVE:
1836       if( IsDragged )
1837       {
1838         HDC hdc = GetDC( hwnd );
1839
1840         HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1841         SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1842         SetROP2( hdc, R2_NOT );
1843
1844         if( !DragFirst )
1845           Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1846
1847         DragFirst = Standard_False;
1848         X_Motion = LOWORD(lParam);
1849         Y_Motion = HIWORD(lParam);
1850
1851         Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1852
1853         SelectObject( hdc, anObj );
1854
1855         ReleaseDC( hwnd, hdc );
1856       }
1857       else
1858         return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1859       break;
1860
1861     default:
1862       return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1863     }
1864     return 0;
1865   }
1866   return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1867 }
1868
1869
1870 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1871                                        UINT Msg,
1872                                        WPARAM wParam,
1873                                        LPARAM lParam )
1874 {
1875   static int Up = 1;
1876
1877   if ( !ViewerTest::CurrentView().IsNull() ) {
1878     PAINTSTRUCT    ps;
1879
1880     switch( Msg ) {
1881     case WM_PAINT:
1882       BeginPaint(hwnd, &ps);
1883       EndPaint(hwnd, &ps);
1884       VT_ProcessExpose();
1885       break;
1886
1887     case WM_SIZE:
1888       VT_ProcessConfigure();
1889       break;
1890
1891     case WM_KEYDOWN:
1892       if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1893       {
1894         char c[2];
1895         c[0] = (char) wParam;
1896         c[1] = '\0';
1897         VT_ProcessKeyPress (c);
1898       }
1899       break;
1900
1901     case WM_LBUTTONUP:
1902     case WM_MBUTTONUP:
1903     case WM_RBUTTONUP:
1904       Up = 1;
1905       VT_ProcessButton3Release();
1906       break;
1907
1908     case WM_LBUTTONDOWN:
1909     case WM_MBUTTONDOWN:
1910     case WM_RBUTTONDOWN:
1911       {
1912         WPARAM fwKeys = wParam;
1913
1914         Up = 0;
1915
1916         X_ButtonPress = LOWORD(lParam);
1917         Y_ButtonPress = HIWORD(lParam);
1918
1919         if (Msg == WM_LBUTTONDOWN)
1920         {
1921           if (fwKeys & MK_CONTROL)
1922           {
1923             Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1924           }
1925           else
1926           {
1927             VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1928           }
1929         }
1930         else if (Msg == WM_RBUTTONDOWN)
1931         {
1932           // Start rotation
1933           VT_ProcessButton3Press();
1934         }
1935       }
1936       break;
1937
1938     case WM_MOUSEMOVE:
1939       {
1940         //cout << "\t WM_MOUSEMOVE" << endl;
1941         WPARAM fwKeys = wParam;
1942         X_Motion = LOWORD(lParam);
1943         Y_Motion = HIWORD(lParam);
1944
1945         if ( Up &&
1946           fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
1947             Up = 0;
1948             X_ButtonPress = LOWORD(lParam);
1949             Y_ButtonPress = HIWORD(lParam);
1950
1951             if ( fwKeys & MK_RBUTTON ) {
1952               // Start rotation
1953               VT_ProcessButton3Press();
1954             }
1955           }
1956
1957           if ( fwKeys & MK_CONTROL ) {
1958             if ( fwKeys & MK_LBUTTON ) {
1959               ProcessControlButton1Motion();
1960             }
1961             else if ( fwKeys & MK_MBUTTON ||
1962               ((fwKeys&MK_LBUTTON) &&
1963               (fwKeys&MK_RBUTTON) ) ){
1964                 VT_ProcessControlButton2Motion();
1965               }
1966             else if ( fwKeys & MK_RBUTTON ) {
1967               VT_ProcessControlButton3Motion();
1968             }
1969           }
1970 #ifdef BUG
1971           else if ( fwKeys & MK_SHIFT ) {
1972             if ( fwKeys & MK_MBUTTON ||
1973               ((fwKeys&MK_LBUTTON) &&
1974               (fwKeys&MK_RBUTTON) ) ) {
1975                 cout << "ProcessZClipMotion()" << endl;
1976                 ProcessZClipMotion();
1977               }
1978           }
1979 #endif
1980           else
1981             if ((fwKeys & MK_MBUTTON
1982             || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
1983             {
1984               ProcessZClipMotion();
1985             }
1986             else
1987             {
1988               VT_ProcessMotion();
1989             }
1990       }
1991       break;
1992
1993     default:
1994       return( DefWindowProc( hwnd, Msg, wParam, lParam ));
1995     }
1996     return 0L;
1997   }
1998
1999   return DefWindowProc( hwnd, Msg, wParam, lParam );
2000 }
2001
2002
2003
2004
2005 //==============================================================================
2006 //function : ViewerMainLoop
2007 //purpose  : Get a Event on the view and dispatch it
2008 //==============================================================================
2009
2010
2011 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2012 {
2013   Ppick = (argc > 0)? 1 : 0;
2014   Pargc = argc;
2015   Pargv = argv;
2016
2017   if ( Ppick ) {
2018     MSG msg;
2019     msg.wParam = 1;
2020
2021     cout << "Start picking" << endl;
2022
2023     while ( Ppick == 1 ) {
2024       // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2025       if (GetMessage(&msg, NULL, 0, 0) ) {
2026         TranslateMessage(&msg);
2027         DispatchMessage(&msg);
2028       }
2029     }
2030
2031     cout << "Picking done" << endl;
2032   }
2033
2034   return Ppick;
2035 }
2036
2037 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2038
2039 int min( int a, int b )
2040 {
2041   if( a<b )
2042     return a;
2043   else
2044     return b;
2045 }
2046
2047 int max( int a, int b )
2048 {
2049   if( a>b )
2050     return a;
2051   else
2052     return b;
2053 }
2054
2055 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2056
2057
2058   static XEvent aReport;
2059   Standard_Boolean pick = argc > 0;
2060   Display *aDisplay = GetDisplayConnection()->GetDisplay();
2061   XNextEvent (aDisplay, &aReport);
2062
2063   // Handle event for the chosen display connection
2064   switch (aReport.type) {
2065       case ClientMessage:
2066         {
2067           if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2068           {
2069             // Close the window
2070             ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2071           }
2072         }
2073         return 0;
2074      case FocusIn:
2075       {
2076          // Activate inactive view
2077          Window aWindow = GetWindowHandle(VT_GetWindow());
2078          if(aWindow != aReport.xfocus.window)
2079          {
2080            ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2081          }
2082       }
2083       break;
2084       case Expose:
2085         {
2086           VT_ProcessExpose();
2087         }
2088         break;
2089       case ConfigureNotify:
2090         {
2091           VT_ProcessConfigure();
2092         }
2093         break;
2094       case KeyPress:
2095         {
2096
2097           KeySym ks_ret ;
2098           char buf_ret[11] ;
2099           int ret_len ;
2100           XComposeStatus status_in_out;
2101
2102           ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2103             (char *) buf_ret , 10 ,
2104             &ks_ret , &status_in_out ) ;
2105
2106
2107           buf_ret[ret_len] = '\0' ;
2108
2109           if (ret_len)
2110           {
2111             VT_ProcessKeyPress (buf_ret);
2112           }
2113         }
2114         break;
2115       case ButtonPress:
2116         {
2117           X_ButtonPress = aReport.xbutton.x;
2118           Y_ButtonPress = aReport.xbutton.y;
2119
2120           if (aReport.xbutton.button == Button1)
2121           {
2122             if (aReport.xbutton.state & ControlMask)
2123             {
2124               pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2125             }
2126             else
2127             {
2128               IsDragged = Standard_True;
2129               DragFirst = Standard_True;
2130             }
2131           }
2132           else if (aReport.xbutton.button == Button3)
2133           {
2134             // Start rotation
2135             VT_ProcessButton3Press();
2136           }
2137         }
2138         break;
2139       case ButtonRelease:
2140         {
2141           if( IsDragged )
2142           {
2143             if( !DragFirst )
2144             {
2145               Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2146               GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2147               XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2148             }
2149
2150             Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2151             if( aContext.IsNull() )
2152             {
2153               cout << "The context is null. Please use vinit before createmesh" << endl;
2154               return 0;
2155             }
2156
2157             Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2158             if( aReport.xbutton.button==1 )
2159               if( DragFirst )
2160                 if( ShiftPressed )
2161                 {
2162                   aContext->ShiftSelect();
2163                 }
2164                 else
2165                 {
2166                   aContext->Select();
2167                 }
2168               else
2169                 if( ShiftPressed )
2170                 {
2171                   aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2172                     max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2173                     ViewerTest::CurrentView());
2174                 }
2175                 else
2176                 {
2177                   aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2178                     max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2179                     ViewerTest::CurrentView() );
2180                 }
2181             else
2182               VT_ProcessButton3Release();
2183
2184             IsDragged = Standard_False;
2185           }
2186           else
2187             VT_ProcessButton3Release();
2188         }
2189         break;
2190       case MotionNotify:
2191         {
2192           if( IsDragged )
2193           {
2194             Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2195             GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2196             XSetFunction( aDisplay, gc, GXinvert );
2197
2198             if( !DragFirst )
2199               XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2200
2201             X_Motion = aReport.xmotion.x;
2202             Y_Motion = aReport.xmotion.y;
2203             DragFirst = Standard_False;
2204
2205             XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2206           }
2207           else
2208           {
2209             X_Motion = aReport.xmotion.x;
2210             Y_Motion = aReport.xmotion.y;
2211
2212             // remove all the ButtonMotionMaskr
2213             while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2214
2215             if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2216               if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2217
2218                 Quantity_Length VDX, VDY;
2219
2220                 ViewerTest::CurrentView()->Size(VDX,VDY);
2221                 Standard_Real VDZ =0 ;
2222                 VDZ = ViewerTest::CurrentView()->ZSize();
2223
2224                 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2225
2226                 Quantity_Length dx = 0 ;
2227                 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2228
2229                 cout << dx << endl;
2230
2231                 dx = dx / VDX * VDZ;
2232
2233                 cout << dx << endl;
2234
2235                 ViewerTest::CurrentView()->Redraw();
2236               }
2237             }
2238
2239             if ( aReport.xmotion.state & ControlMask ) {
2240               if ( aReport.xmotion.state & Button1Mask ) {
2241                 ProcessControlButton1Motion();
2242               }
2243               else if ( aReport.xmotion.state & Button2Mask ) {
2244                 VT_ProcessControlButton2Motion();
2245               }
2246               else if ( aReport.xmotion.state & Button3Mask ) {
2247                 VT_ProcessControlButton3Motion();
2248               }
2249             }
2250             else
2251             {
2252               VT_ProcessMotion();
2253             }
2254           }
2255         }
2256         break;
2257 }
2258 return pick;
2259 }
2260
2261 //==============================================================================
2262 //function : VProcessEvents
2263 //purpose  : call by Tk_CreateFileHandler() to be able to manage the
2264 //       event in the Viewer window
2265 //==============================================================================
2266
2267 static void VProcessEvents(ClientData,int)
2268 {
2269   NCollection_Vector<int> anEventNumbers;
2270   // Get number of messages from every display
2271   for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2272        anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2273   {
2274     anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2275   } 
2276     // Handle events for every display
2277   int anEventIter = 0;
2278   for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2279        anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2280   {
2281     for (int i = 0; i < anEventNumbers.Value(anEventIter) && 
2282          XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2283     {
2284       SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2285       int anEventResult = ViewerMainLoop( 0, NULL);
2286       // If window is closed or context was not found finish current event processing loop
2287       if (!anEventResult)
2288         return;
2289     }
2290   }
2291   
2292   SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2293   
2294 }
2295 #endif
2296
2297 //==============================================================================
2298 //function : OSWindowSetup
2299 //purpose  : Setup for the X11 window to be able to cath the event
2300 //==============================================================================
2301
2302
2303 static void OSWindowSetup()
2304 {
2305 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2306   // X11
2307
2308   Window  window   = VT_GetWindow()->XWindow();
2309   SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2310   Display *aDisplay = GetDisplayConnection()->GetDisplay();
2311   XSynchronize(aDisplay, 1);
2312
2313   // X11 : For keyboard on SUN
2314   XWMHints wmhints;
2315   wmhints.flags = InputHint;
2316   wmhints.input = 1;
2317
2318   XSetWMHints( aDisplay, window, &wmhints);
2319
2320   XSelectInput( aDisplay, window,  ExposureMask | KeyPressMask |
2321     ButtonPressMask | ButtonReleaseMask |
2322     StructureNotifyMask |
2323     PointerMotionMask |
2324     Button1MotionMask | Button2MotionMask |
2325     Button3MotionMask | FocusChangeMask
2326     );
2327   Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2328   XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2329
2330   XSynchronize(aDisplay, 0);
2331
2332 #else
2333   // WNT
2334 #endif
2335
2336 }
2337
2338
2339 //==============================================================================
2340 //function : VFit
2341
2342 //purpose  : Fitall, no DRAW arguments
2343 //Draw arg : No args
2344 //==============================================================================
2345
2346 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2347 {
2348   const Handle(V3d_View) aView = ViewerTest::CurrentView();
2349   Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2350   if (V.IsNull() == Standard_False) {
2351     V->FitAll3d();
2352   } else if (aView.IsNull() == Standard_False) {
2353     aView->FitAll();
2354   }
2355   return 0;
2356 }
2357
2358 //==============================================================================
2359 //function : VZFit
2360 //purpose  : ZFitall, no DRAW arguments
2361 //Draw arg : No args
2362 //==============================================================================
2363
2364 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
2365 {
2366   Handle(V3d_View) V = ViewerTest::CurrentView();
2367   if ( !V.IsNull() ) V->ZFitAll(); return 0; }
2368
2369
2370 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
2371 {
2372   Handle(V3d_View) V = ViewerTest::CurrentView();
2373   if ( !V.IsNull() ) V->Redraw(); return 0;
2374 }
2375
2376
2377 //==============================================================================
2378 //function : VClear
2379 //purpose  : Remove all the object from the viewer
2380 //Draw arg : No args
2381 //==============================================================================
2382
2383 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2384 {
2385   Handle(V3d_View) V = ViewerTest::CurrentView();
2386   if(!V.IsNull())
2387     ViewerTest::Clear();
2388   return 0;
2389 }
2390
2391 //==============================================================================
2392 //function : VPick
2393 //purpose  :
2394 //==============================================================================
2395
2396 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2397 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2398
2399 if ( argc < 4 ) {
2400   di << argv[0] << "Invalid number of arguments" << "\n";
2401   return 1;
2402 }
2403
2404 while (ViewerMainLoop( argc, argv)) {
2405 }
2406
2407 return 0;
2408 }
2409
2410 //==============================================================================
2411 //function : InitViewerTest
2412 //purpose  : initialisation de toutes les variables static de  ViewerTest (dp)
2413 //==============================================================================
2414
2415 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
2416 {
2417   Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2418   ViewerTest::SetAISContext(theContext);
2419   aViewer->InitActiveViews();
2420   Handle(V3d_View) aView = aViewer->ActiveView();
2421   if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
2422   ViewerTest::ResetEventManager();
2423   Handle(Aspect_Window) aWindow = aView->Window();
2424 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2425   // X11
2426   VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
2427   OSWindowSetup();
2428   static int aFirst = 1;
2429   if ( aFirst ) {
2430 #if TCL_MAJOR_VERSION  < 8
2431     Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2432       TK_READABLE, VProcessEvents, (ClientData) 0);
2433 #else
2434     Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2435       TK_READABLE, VProcessEvents, (ClientData) 0);
2436 #endif
2437     aFirst = 0;
2438   }
2439 #endif
2440 }
2441
2442 //==============================================================================
2443 //function : VSetBg
2444 //purpose  : Load image as background
2445 //==============================================================================
2446
2447 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2448 {
2449   if (argc < 2 || argc > 3)
2450   {
2451     di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2452     di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2453     return 1;
2454   }
2455
2456   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2457   if(AISContext.IsNull())
2458   {
2459     di << "use 'vinit' command before " << argv[0] << "\n";
2460     return 1;
2461   }
2462
2463   Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2464   if (argc == 3)
2465   {
2466     const char* szType = argv[2];
2467     if      (strcmp(szType, "NONE"    ) == 0) aFillType = Aspect_FM_NONE;
2468     else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2469     else if (strcmp(szType, "TILED"   ) == 0) aFillType = Aspect_FM_TILED;
2470     else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2471     else
2472     {
2473       di << "Wrong fill type : " << szType << "\n";
2474       di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2475       return 1;
2476     }
2477   }
2478
2479   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2480   V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2481
2482   return 0;
2483 }
2484
2485 //==============================================================================
2486 //function : VSetBgMode
2487 //purpose  : Change background image fill type
2488 //==============================================================================
2489
2490 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2491 {
2492   if (argc != 2)
2493   {
2494     di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2495     di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2496     return 1;
2497   }
2498
2499   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2500   if(AISContext.IsNull())
2501   {
2502     di << "use 'vinit' command before " << argv[0] << "\n";
2503     return 1;
2504   }
2505   Aspect_FillMethod aFillType = Aspect_FM_NONE;
2506   const char* szType = argv[1];
2507   if      (strcmp(szType, "NONE"    ) == 0) aFillType = Aspect_FM_NONE;
2508   else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2509   else if (strcmp(szType, "TILED"   ) == 0) aFillType = Aspect_FM_TILED;
2510   else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2511   else
2512   {
2513     di << "Wrong fill type : " << szType << "\n";
2514     di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2515     return 1;
2516   }
2517   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2518   V3dView->SetBgImageStyle(aFillType, Standard_True);
2519   return 0;
2520 }
2521
2522 //==============================================================================
2523 //function : VSetGradientBg
2524 //purpose  : Mount gradient background
2525 //==============================================================================
2526 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2527 {
2528   if (argc != 8 )
2529   {
2530     di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2531     di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2532     di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2533     di << "                    5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2534     return 1;
2535   }
2536
2537   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2538   if(AISContext.IsNull())
2539   {
2540     di << "use 'vinit' command before " << argv[0] << "\n";
2541     return 1;
2542   }
2543   if (argc == 8)
2544   {
2545
2546     Standard_Real R1 = Draw::Atof(argv[1])/255.;
2547     Standard_Real G1 = Draw::Atof(argv[2])/255.;
2548     Standard_Real B1 = Draw::Atof(argv[3])/255.;
2549     Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2550
2551     Standard_Real R2 = Draw::Atof(argv[4])/255.;
2552     Standard_Real G2 = Draw::Atof(argv[5])/255.;
2553     Standard_Real B2 = Draw::Atof(argv[6])/255.;
2554
2555     Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2556     int aType = Draw::Atoi(argv[7]);
2557     if( aType < 0 || aType > 8 )
2558     {
2559       di << "Wrong fill type " << "\n";
2560       di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2561       di << "               5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2562       return 1;
2563     }
2564
2565     Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2566
2567     Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2568     V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2569   }
2570
2571   return 0;
2572 }
2573
2574 //==============================================================================
2575 //function : VSetGradientBgMode
2576 //purpose  : Change gradient background fill style
2577 //==============================================================================
2578 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2579 {
2580   if (argc != 2 )
2581   {
2582     di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2583     di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2584     di << "                    5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2585     return 1;
2586   }
2587
2588   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2589   if(AISContext.IsNull())
2590   {
2591     di << "use 'vinit' command before " << argv[0] << "\n";
2592     return 1;
2593   }
2594   if (argc == 2)
2595   {
2596     int aType = Draw::Atoi(argv[1]);
2597     if( aType < 0 || aType > 8 )
2598     {
2599       di << "Wrong fill type " << "\n";
2600       di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2601       di << "               5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2602       return 1;
2603     }
2604
2605     Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2606
2607     Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2608     V3dView->SetBgGradientStyle( aMethod, 1 );
2609   }
2610
2611   return 0;
2612 }
2613
2614 //==============================================================================
2615 //function : VSetColorBg
2616 //purpose  : Set color background
2617 //==============================================================================
2618 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2619 {
2620   if (argc != 4 )
2621   {
2622     di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2623     di << "R,G,B = [0..255]" << "\n";
2624     return 1;
2625   }
2626
2627   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2628   if(AISContext.IsNull())
2629   {
2630     di << "use 'vinit' command before " << argv[0] << "\n";
2631     return 1;
2632   }
2633   if (argc == 4)
2634   {
2635
2636     Standard_Real R = Draw::Atof(argv[1])/255.;
2637     Standard_Real G = Draw::Atof(argv[2])/255.;
2638     Standard_Real B = Draw::Atof(argv[3])/255.;
2639     Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2640
2641     Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2642     V3dView->SetBackgroundColor( aColor );
2643     V3dView->Update();
2644   }
2645
2646   return 0;
2647 }
2648
2649 //==============================================================================
2650 //function : VScale
2651 //purpose  : View Scaling
2652 //==============================================================================
2653
2654 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2655 {
2656   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2657   if ( V3dView.IsNull() ) return 1;
2658
2659   if ( argc != 4 ) {
2660     di << argv[0] << "Invalid number of arguments" << "\n";
2661     return 1;
2662   }
2663   V3dView->SetAxialScale( Draw::Atof(argv[1]),  Draw::Atof(argv[2]),  Draw::Atof(argv[3]) );
2664   return 0;
2665 }
2666 //==============================================================================
2667 //function : VTestZBuffTrihedron
2668 //purpose  : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2669 //==============================================================================
2670
2671 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2672 {
2673   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2674   if ( V3dView.IsNull() ) return 1;
2675
2676   V3dView->ZBufferTriedronSetup();
2677
2678   if ( argc == 1 ) {
2679     // Set up default trihedron parameters
2680     V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2681   } else
2682   if ( argc == 7 )
2683   {
2684     Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2685     const char* aPosType = argv[1];
2686
2687     if ( strcmp(aPosType, "center") == 0 )
2688     {
2689       aPosition = Aspect_TOTP_CENTER;
2690     } else
2691     if (strcmp(aPosType, "left_lower") == 0)
2692     {
2693       aPosition = Aspect_TOTP_LEFT_LOWER;
2694     } else
2695     if (strcmp(aPosType, "left_upper") == 0)
2696     {
2697       aPosition = Aspect_TOTP_LEFT_UPPER;
2698     } else
2699     if (strcmp(aPosType, "right_lower") == 0)
2700     {
2701       aPosition = Aspect_TOTP_RIGHT_LOWER;
2702     } else
2703     if (strcmp(aPosType, "right_upper") == 0)
2704     {
2705       aPosition = Aspect_TOTP_RIGHT_UPPER;
2706     } else
2707     {
2708       di << argv[1] << " Invalid type of alignment"  << "\n";
2709       di << "Must be one of [ center, left_lower,"   << "\n";
2710       di << "left_upper, right_lower, right_upper ]" << "\n";
2711       return 1;
2712     }
2713
2714     Standard_Real R = Draw::Atof(argv[2])/255.;
2715     Standard_Real G = Draw::Atof(argv[3])/255.;
2716     Standard_Real B = Draw::Atof(argv[4])/255.;
2717     Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2718
2719     Standard_Real aScale = Draw::Atof(argv[5]);
2720
2721     if( aScale <= 0.0 )
2722     {
2723       di << argv[5] << " Invalid value. Must be > 0" << "\n";
2724       return 1;
2725     }
2726
2727     V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2728     const char* aPresType = argv[6];
2729
2730     if ( strcmp(aPresType, "wireframe") == 0 )
2731     {
2732       aPresentation = V3d_WIREFRAME;
2733     } else
2734     if (strcmp(aPresType, "zbuffer") == 0)
2735     {
2736       aPresentation = V3d_ZBUFFER;
2737     } else
2738     {
2739       di << argv[6] << " Invalid type of visualization" << "\n";
2740       di << "Must be one of [ wireframe, zbuffer ]"     << "\n";
2741       return 1;
2742     }
2743
2744     V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2745
2746   } else
2747   {
2748     di << argv[0] << " Invalid number of arguments" << "\n";
2749     return 1;
2750   }
2751
2752   V3dView->ZFitAll();
2753
2754   return 0;
2755 }
2756
2757 //==============================================================================
2758 //function : VRotate
2759 //purpose  : Camera Rotating
2760 //==============================================================================
2761
2762 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2763   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2764   if ( V3dView.IsNull() ) {
2765     return 1;
2766   }
2767
2768   if ( argc == 4 ) {
2769     V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2770     return 0;
2771   } else if ( argc == 7 ) {
2772     V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5]), Draw::Atof(argv[6]) );
2773     return 0;
2774   } else {
2775     di << argv[0] << " Invalid number of arguments" << "\n";
2776     return 1;
2777   }
2778 }
2779
2780 //==============================================================================
2781 //function : VZoom
2782 //purpose  : View zoom in / out (relative to current zoom)
2783 //==============================================================================
2784
2785 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2786   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2787   if ( V3dView.IsNull() ) {
2788     return 1;
2789   }
2790
2791   if ( argc == 2 ) {
2792     Standard_Real coef = Draw::Atof(argv[1]);
2793     if ( coef <= 0.0 ) {
2794       di << argv[1] << "Invalid value" << "\n";
2795       return 1;
2796     }
2797     V3dView->SetZoom( Draw::Atof(argv[1]) );
2798     return 0;
2799   } else {
2800     di << argv[0] << " Invalid number of arguments" << "\n";
2801     return 1;
2802   }
2803 }
2804
2805 //==============================================================================
2806 //function : VPan
2807 //purpose  : View panning (in pixels)
2808 //==============================================================================
2809
2810 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2811   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2812   if ( V3dView.IsNull() ) return 1;
2813
2814   if ( argc == 3 ) {
2815     V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2816     return 0;
2817   } else {
2818     di << argv[0] << " Invalid number of arguments" << "\n";
2819     return 1;
2820   }
2821 }
2822
2823
2824 //==============================================================================
2825 //function : VExport
2826 //purpose  : Export the view to a vector graphic format (PS, EMF, PDF)
2827 //==============================================================================
2828
2829 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2830 {
2831   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2832   if (V3dView.IsNull())
2833     return 1;
2834
2835   if (argc == 1)
2836   {
2837     std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2838     return 1;
2839   }
2840
2841   Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2842   TCollection_AsciiString aFormatStr;
2843
2844   TCollection_AsciiString aFileName (argv[1]);
2845   Standard_Integer aLen = aFileName.Length();
2846
2847   if (argc > 2)
2848   {
2849     aFormatStr = TCollection_AsciiString (argv[2]);
2850   }
2851   else if (aLen >= 4)
2852   {
2853     if (aFileName.Value (aLen - 2) == '.')
2854     {
2855       aFormatStr = aFileName.SubString (aLen - 1, aLen);
2856     }
2857     else if (aFileName.Value (aLen - 3) == '.')
2858     {
2859       aFormatStr = aFileName.SubString (aLen - 2, aLen);
2860     }
2861     else
2862     {
2863       std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2864       return 1;
2865     }
2866   }
2867   else
2868   {
2869     std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2870     return 1;
2871   }
2872
2873   aFormatStr.UpperCase();
2874   if (aFormatStr == "PS")
2875     anExpFormat = Graphic3d_EF_PostScript;
2876   else if (aFormatStr == "EPS")
2877     anExpFormat = Graphic3d_EF_EnhPostScript;
2878   else if (aFormatStr == "TEX")
2879     anExpFormat = Graphic3d_EF_TEX;
2880   else if (aFormatStr == "PDF")
2881     anExpFormat = Graphic3d_EF_PDF;
2882   else if (aFormatStr == "SVG")
2883     anExpFormat = Graphic3d_EF_SVG;
2884   else if (aFormatStr == "PGF")
2885     anExpFormat = Graphic3d_EF_PGF;
2886   else if (aFormatStr == "EMF")
2887     anExpFormat = Graphic3d_EF_EMF;
2888   else
2889   {
2890     std::cout << "Invalid export format '" << aFormatStr << "'\n";
2891     return 1;
2892   }
2893
2894   try {
2895     if (!V3dView->View()->Export (argv[1], anExpFormat))
2896     {
2897       di << "Error: export of image to " << aFormatStr << " failed!\n";
2898     }
2899   }
2900   catch (Standard_Failure)
2901   {
2902     di << "Error: export of image to " << aFormatStr << " failed";
2903     di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
2904   }
2905   return 0;
2906 }
2907
2908 //==============================================================================
2909 //function : VColorScale
2910 //purpose  : representation color scale
2911 //==============================================================================
2912 #include <V3d_ColorScale.hxx>
2913
2914 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2915 {
2916   if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
2917   {
2918     di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0]  " << "\n";
2919     return 1;
2920   }
2921
2922   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2923   if(aContext.IsNull()) {
2924     di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
2925     return -1;
2926   }
2927
2928   Standard_Real minRange = 0. , maxRange = 100. ;
2929
2930   Standard_Integer numIntervals = 10 ;
2931   Standard_Integer textHeight = 16;
2932   Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
2933   Standard_Real X = 0., Y = 0. ;
2934
2935   if ( argc < 9 )
2936   {
2937      if( argc > 3 )
2938      {
2939        minRange = Draw::Atof( argv[1] );
2940        maxRange = Draw::Atof( argv[2] );
2941        numIntervals = Draw::Atoi( argv[3] );
2942      }
2943      if ( argc > 4 )
2944        textHeight = Draw::Atoi( argv[4] );
2945      if ( argc > 5 )
2946        position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
2947      if ( argc > 7 )
2948      {
2949        X = Draw::Atof( argv[6] );
2950        Y = Draw::Atof( argv[7] );
2951      }
2952   }
2953   Handle(V3d_View) curView = ViewerTest::CurrentView( );
2954   if ( curView.IsNull( ) )
2955     return 1;
2956   Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
2957   Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
2958   if( ! aCS.IsNull( ) )
2959   {
2960     aCS->SetPosition( X , Y );
2961     aCS->SetHeight( 0.95) ;
2962     aCS->SetTextHeight( textHeight );
2963     aCS->SetRange( minRange , maxRange );
2964     aCS->SetNumberOfIntervals( numIntervals );
2965     aCS->SetLabelPosition( position );
2966     if( !curView->ColorScaleIsDisplayed() )
2967       curView->ColorScaleDisplay( );
2968   }
2969   return 0;
2970 }
2971
2972 //==============================================================================
2973 //function : VGraduatedTrihedron
2974 //purpose  : Displays a graduated trihedron
2975 //==============================================================================
2976
2977 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
2978 {
2979   const char *str = arg;
2980   while (*str)
2981   {
2982     unsigned short c1 = *str++;
2983     unsigned short c2 = *str++;
2984     if (!c1 || !c2) break;
2985     name += (Standard_ExtCharacter)((c1 << 8) | c2);
2986   }
2987 }
2988
2989 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2990 {
2991   // Check arguments
2992   if (argc != 2 && argc < 5)
2993   {
2994     di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2995     di<<"Usage: type help "<<argv[0]<<"\n";
2996     return 1; //TCL_ERROR
2997   }
2998
2999   Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3000
3001   // Create 3D view if it doesn't exist
3002   if ( aV3dView.IsNull() )
3003   {
3004     ViewerTest::ViewerInit();
3005     aV3dView = ViewerTest::CurrentView();
3006     if( aV3dView.IsNull() )
3007     {
3008       di << "Error: Cannot create a 3D view\n";
3009       return 1; //TCL_ERROR
3010     }
3011   }
3012
3013   // Erase (==0) or display (!=0)
3014   const int display = Draw::Atoi(argv[1]);
3015
3016   if (display)
3017   {
3018     // Text font
3019     TCollection_AsciiString font;
3020     if (argc < 6)
3021       font.AssignCat("Courier");
3022     else
3023       font.AssignCat(argv[5]);
3024
3025     // Text is multibyte
3026     const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3027
3028     // Set axis names
3029     TCollection_ExtendedString xname, yname, zname;
3030     if (argc >= 5)
3031     {
3032       if (isMultibyte)
3033       {
3034         AddMultibyteString(xname, argv[2]);
3035         AddMultibyteString(yname, argv[3]);
3036         AddMultibyteString(zname, argv[4]);
3037       }
3038       else
3039       {
3040         xname += argv[2];
3041         yname += argv[3];
3042         zname += argv[4];
3043       }
3044     }
3045     else
3046     {
3047       xname += "X (mm)";
3048       yname += "Y (mm)";
3049       zname += "Z (mm)";
3050     }
3051
3052     aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3053                                         Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3054                                         Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3055                                         Standard_True/*drawgrid*/,
3056                                         Standard_True/*drawaxes*/,
3057                                         5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3058                                         10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3059                                         30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3060                                         Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3061                                         10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3062                                         Quantity_NOC_WHITE/*gridcolor*/,
3063                                         Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3064                                         Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3065   }
3066   else
3067     aV3dView->GraduatedTrihedronErase();
3068
3069   ViewerTest::GetAISContext()->UpdateCurrentViewer();
3070   aV3dView->Redraw();
3071
3072   return 0;
3073 }
3074
3075 //==============================================================================
3076 //function : VPrintView
3077 //purpose  : Test printing algorithm, print the view to image file with given
3078 //           width and height. Printing implemented only for WNT.
3079 //==============================================================================
3080 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3081                        const char** argv)
3082 {
3083 #ifndef WNT
3084   di << "Printing implemented only for wnt!\n";
3085   return 1;
3086 #else
3087
3088   Handle(AIS_InteractiveContext) aContextAIS = NULL;
3089   Handle(V3d_View) aView = NULL;
3090   aContextAIS = ViewerTest::GetAISContext();
3091   if (!aContextAIS.IsNull())
3092   {
3093     const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3094     Vwr->InitActiveViews();
3095     if(Vwr->MoreActiveViews())
3096       aView = Vwr->ActiveView();
3097   }
3098
3099   // check for errors
3100   if (aView.IsNull())
3101   {
3102     di << "Call vinit before!\n";
3103     return 1;
3104   }
3105   else if (argc < 4)
3106   {
3107     di << "Use: " << argv[0];
3108     di << " width height filename [print algo=0]\n";
3109     di << "width, height of the intermediate buffer for operation\n";
3110     di << "algo : {0|1}\n";
3111     di << "        0 - stretch algorithm\n";
3112     di << "        1 - tile algorithm\n";
3113     di << "test printing algorithms into an intermediate buffer\n";
3114     di << "with saving output to an image file\n";
3115     return 1;
3116   }
3117
3118   // get the input params
3119   Standard_Integer aWidth  = Draw::Atoi (argv[1]);
3120   Standard_Integer aHeight = Draw::Atoi (argv[2]);
3121   Standard_Integer aMode   = 0;
3122   TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3123   if (argc==5)
3124     aMode = Draw::Atoi (argv[4]);
3125
3126   // check the input parameters
3127   if (aWidth <= 0 || aHeight <= 0)
3128   {
3129     di << "Width and height must be positive values!\n";
3130     return 1;
3131   }
3132   if (aMode != 0 && aMode != 1)
3133     aMode = 0;
3134
3135   // define compatible bitmap
3136   HDC anDC = CreateCompatibleDC(0);
3137   BITMAPINFO aBitmapData;
3138   memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3139   aBitmapData.bmiHeader.biSize          = sizeof (BITMAPINFOHEADER);
3140   aBitmapData.bmiHeader.biWidth         = aWidth ;
3141   aBitmapData.bmiHeader.biHeight        = aHeight;
3142   aBitmapData.bmiHeader.biPlanes        = 1;
3143   aBitmapData.bmiHeader.biBitCount      = 24;
3144   aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3145   aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3146   aBitmapData.bmiHeader.biClrUsed       = 0;
3147   aBitmapData.bmiHeader.biClrImportant  = 0;
3148   aBitmapData.bmiHeader.biCompression   = BI_RGB;
3149   aBitmapData.bmiHeader.biSizeImage     = 0;
3150
3151   // Create Device Independent Bitmap
3152   void* aBitsOut = NULL;
3153   HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3154                                             &aBitsOut, NULL, 0);
3155   HGDIOBJ anOldBitmap   = SelectObject(anDC, aMemoryBitmap);
3156
3157   Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3158   if (aBitsOut != NULL)
3159   {
3160     if (aMode == 0)
3161       isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3162     else
3163       isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
3164
3165     // succesfully printed into an intermediate buffer
3166     if (isPrinted)
3167     {
3168       Image_PixMap aWrapper;
3169       aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3170       aWrapper.SetTopDown (false);
3171
3172       Image_AlienPixMap anImageBitmap;
3173       anImageBitmap.InitCopy (aWrapper);
3174       isSaved = anImageBitmap.Save (aFileName);
3175     }
3176     else
3177     {
3178       di << "Print operation failed due to printing errors or\n";
3179       di << "insufficient memory available\n";
3180       di << "Please, try to use smaller dimensions for this test\n";
3181       di << "command, as it allocates intermediate buffer for storing\n";
3182       di << "the result\n";
3183     }
3184   }
3185   else
3186   {
3187     di << "Can't allocate memory for intermediate buffer\n";
3188     di << "Please use smaller dimensions\n";
3189   }
3190
3191   if (aMemoryBitmap)
3192   {
3193     SelectObject (anDC, anOldBitmap);
3194     DeleteObject (aMemoryBitmap);
3195     DeleteDC(anDC);
3196   }
3197
3198   if (!isSaved)
3199   {
3200     di << "Save to file operation failed. This operation may fail\n";
3201     di << "if you don't have enough available memory, then you can\n";
3202     di << "use smaller dimensions for the output file\n";
3203     return 1;
3204   }
3205
3206   return 0;
3207
3208 #endif
3209 }
3210
3211 //==============================================================================
3212 //function : VZLayer
3213 //purpose  : Test z layer operations for v3d viewer
3214 //==============================================================================
3215 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3216 {
3217   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3218   if (aContextAIS.IsNull())
3219   {
3220     di << "Call vinit before!\n";
3221     return 1;
3222   }
3223   else if (argc < 2)
3224   {
3225     di << "Use: vzlayer " << argv[0];
3226     di << " add/del/get [id]\n";
3227     di << " add - add new z layer to viewer and print its id\n";
3228     di << " del - del z layer by its id\n";
3229     di << " get - print sequence of z layers in increasing order of their overlay level\n";
3230     di << "id - the layer identificator value defined when removing z layer\n";
3231     return 1;
3232   }
3233
3234   const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3235   if (aViewer.IsNull())
3236   {
3237     di << "No active viewer!\n";
3238     return 1;
3239   }
3240
3241   // perform operation
3242   TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3243   if (anOp == "add")
3244   {
3245     Standard_Integer aNewId;
3246     if (!aViewer->AddZLayer (aNewId))
3247     {
3248       di << "Impossible to add new z layer!\n";
3249       return 1;
3250     }
3251
3252     di << "New z layer added with index: " << aNewId << "\n";
3253   }
3254   else if (anOp == "del")
3255   {
3256     if (argc < 3)
3257     {
3258       di << "Please also provide as argument id of z layer to remove\n";
3259       return 1;
3260     }
3261
3262     Standard_Integer aDelId = Draw::Atoi (argv[2]);
3263     if (!aViewer->RemoveZLayer (aDelId))
3264     {
3265       di << "Impossible to remove the z layer or invalid id!\n";
3266       return 1;
3267     }
3268
3269     di << "Z layer " << aDelId << " has been removed\n";
3270   }
3271   else if (anOp == "get")
3272   {
3273     TColStd_SequenceOfInteger anIds;
3274     aViewer->GetAllZLayers (anIds);
3275     for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3276     {
3277       di << anIds.Value (aSeqIdx) << " ";
3278     }
3279
3280     di << "\n";
3281   }
3282   else
3283   {
3284     di << "Invalid operation, please use { add / del / get }\n";
3285     return 1;
3286   }
3287
3288   return 0;
3289 }
3290
3291 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3292
3293 // this class provides a presentation of text item in v3d view under-/overlayer
3294 class V3d_TextItem : public Visual3d_LayerItem
3295 {
3296 public:
3297
3298   // CASCADE RTTI
3299   DEFINE_STANDARD_RTTI(V3d_TextItem)
3300
3301   // constructor
3302   Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3303                                const Standard_Real theX1,
3304                                const Standard_Real theY1,
3305                                const Standard_Real theHeight,
3306                                const TCollection_AsciiString& theFontName,
3307                                const Quantity_Color& theColor,
3308                                const Quantity_Color& theSubtitleColor,
3309                                const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3310                                const Handle(Visual3d_Layer)& theLayer);
3311
3312   // redraw method
3313   Standard_EXPORT void RedrawLayerPrs();
3314
3315 private:
3316
3317   Standard_Real            myX1;
3318   Standard_Real            myY1;
3319   Standard_Real            myHeight;
3320   TCollection_AsciiString  myText;
3321   TCollection_AsciiString  myFontName;
3322   Quantity_Color           myColor;
3323   Quantity_Color           mySubtitleColor;
3324   Aspect_TypeOfDisplayText myType;
3325   Handle(Visual3d_Layer)   myLayer;
3326
3327 };
3328
3329 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3330 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3331
3332 // create and add to display the text item
3333 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3334                             const Standard_Real theX1,
3335                             const Standard_Real theY1,
3336                             const Standard_Real theHeight,
3337                             const TCollection_AsciiString& theFontName,
3338                             const Quantity_Color& theColor,
3339                             const Quantity_Color& theSubtitleColor,
3340                             const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3341                             const Handle(Visual3d_Layer)& theLayer)
3342  : myX1 (theX1), myY1 (theY1),
3343    myText (theText),
3344    myHeight (theHeight),
3345    myLayer (theLayer),
3346    myColor (theColor),
3347    mySubtitleColor (theSubtitleColor),
3348    myType (theTypeOfDisplay),
3349    myFontName (theFontName)
3350 {
3351   if (!myLayer.IsNull ())
3352     myLayer->AddLayerItem (this);
3353 }
3354
3355 // render item
3356 void V3d_TextItem::RedrawLayerPrs ()
3357 {
3358   if (myLayer.IsNull ())
3359     return;
3360
3361   myLayer->SetColor (myColor);
3362   myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3363   myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3364 }
3365
3366 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3367
3368 // The Visual3d_LayerItem line item for "vlayerline" command
3369 // it provides a presentation of line with user-defined
3370 // linewidth, linetype and transparency.
3371 class V3d_LineItem : public Visual3d_LayerItem
3372 {
3373 public:
3374   // CASCADE RTTI
3375   DEFINE_STANDARD_RTTI(V3d_LineItem)
3376
3377   // constructor
3378   Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3379                                Standard_Real X2, Standard_Real Y2,
3380                                V3d_LayerMgrPointer theLayerMgr,
3381                                Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3382                                Standard_Real theWidth    = 0.5,
3383                                Standard_Real theTransp   = 1.0);
3384
3385   // redraw method
3386   Standard_EXPORT   void RedrawLayerPrs();
3387
3388 private:
3389
3390   Standard_Real       myX1, myY1, myX2, myY2;
3391   Standard_Real       myWidth;
3392   Standard_Real       myTransparency;
3393   Aspect_TypeOfLine   myType;
3394   V3d_LayerMgrPointer myLayerMgr;
3395 };
3396
3397 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3398 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3399
3400 // default constructor for line item
3401 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3402                            Standard_Real X2, Standard_Real Y2,
3403                            V3d_LayerMgrPointer theLayerMgr,
3404                            Aspect_TypeOfLine theType,
3405                            Standard_Real theWidth,
3406                            Standard_Real theTransp) :
3407   myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3408   myType(theType), myWidth(theWidth), myTransparency(theTransp)
3409 {
3410   if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3411     myLayerMgr->Overlay()->AddLayerItem (this);
3412 }
3413
3414 // render line
3415 void V3d_LineItem::RedrawLayerPrs ()
3416 {
3417   Handle (Visual3d_Layer) aOverlay;
3418
3419   if (myLayerMgr)
3420     aOverlay = myLayerMgr->Overlay();
3421
3422   if (!aOverlay.IsNull())
3423   {
3424     Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3425     aOverlay->SetColor(aColor);
3426     aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3427     aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3428     aOverlay->BeginPolyline();
3429     aOverlay->AddVertex(myX1, myY1);
3430     aOverlay->AddVertex(myX2, myY2);
3431     aOverlay->ClosePrimitive();
3432   }
3433 }
3434
3435 //=============================================================================
3436 //function : VLayerLine
3437 //purpose  : Draws line in the v3d view layer with given attributes: linetype,
3438 //         : linewidth, transparency coefficient
3439 //============================================================================
3440 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3441 {
3442   // get the active view
3443   Handle(V3d_View) aView = ViewerTest::CurrentView();
3444   if (aView.IsNull())
3445   {
3446     di << "Call vinit before!\n";
3447     return 1;
3448   }
3449   else if (argc < 5)
3450   {
3451     di << "Use: " << argv[0];
3452     di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3453     di << " linetype : { 0 | 1 | 2 | 3 } \n";
3454     di << "              0 - solid  \n";
3455     di << "              1 - dashed \n";
3456     di << "              2 - dot    \n";
3457     di << "              3 - dashdot\n";
3458     di << " transparency : { 0.0 - 1.0 } \n";
3459     di << "                  0.0 - transparent\n";
3460     di << "                  1.0 - visible    \n";
3461     return 1;
3462   }
3463
3464   // get the input params
3465   Standard_Real X1 = Draw::Atof(argv[1]);
3466   Standard_Real Y1 = Draw::Atof(argv[2]);
3467   Standard_Real X2 = Draw::Atof(argv[3]);
3468   Standard_Real Y2 = Draw::Atof(argv[4]);
3469
3470   Standard_Real    aWidth = 0.5;
3471   Standard_Integer aType  = 0;
3472   Standard_Real    aTransparency = 1.0;
3473
3474   // has width
3475   if (argc > 5)
3476     aWidth = Draw::Atof(argv[5]);
3477
3478   // has type
3479   if (argc > 6)
3480      aType = (Standard_Integer) Draw::Atoi(argv[6]);
3481
3482   // has transparency
3483   if (argc > 7)
3484   {
3485     aTransparency = Draw::Atof(argv[7]);
3486     if (aTransparency < 0 || aTransparency > 1.0)
3487       aTransparency = 1.0;
3488   }
3489
3490   // select appropriate line type
3491   Aspect_TypeOfLine aLineType;
3492   switch (aType)
3493   {
3494     case 1:
3495       aLineType = Aspect_TOL_DASH;
3496     break;
3497
3498     case 2:
3499       aLineType = Aspect_TOL_DOT;
3500     break;
3501
3502     case 3:
3503       aLineType = Aspect_TOL_DOTDASH;
3504     break;
3505
3506     default:
3507       aLineType = Aspect_TOL_SOLID;
3508   }
3509
3510   // replace layer manager
3511   Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3512   aView->SetLayerMgr(aMgr);
3513
3514   // add line item
3515   Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
3516                                                   aMgr.operator->(),
3517                                                   aLineType, aWidth,
3518                                                   aTransparency);
3519
3520   // update view
3521   aView->MustBeResized();
3522   aView->Redraw();
3523
3524   return 0;
3525 }
3526
3527 //=======================================================================
3528 //function : VOverlayText
3529 //purpose  : Test text displaying in view overlay
3530 //=======================================================================
3531 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3532 {
3533   // get the active view
3534   Handle(V3d_View) aView = ViewerTest::CurrentView();
3535   if (aView.IsNull())
3536   {
3537     di << "No active view. Please call vinit.\n";
3538     return 1;
3539   }
3540   else if (argc < 4 || argc > 13)
3541   {
3542     di << "Use: " << argv[0];
3543     di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3544     di << "[background_color: R G B]\n";
3545     di << "  height - pixel height of the text (default=10.0)\n";
3546     di << "  font_name - name of font (default=courier)\n";
3547     di << "  text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
3548     di << "  display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
3549     di << "  background_color- R G B values used for subtitle and decal text\n";
3550     di << "(default=255.0 255.0 255.0)\n";
3551     return 1;
3552   }
3553
3554   TCollection_AsciiString aText (argv[1]);
3555   Standard_Real aPosX = Draw::Atof(argv[2]);
3556   Standard_Real aPosY = Draw::Atof(argv[3]);
3557   Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
3558
3559   // font name
3560   TCollection_AsciiString aFontName = "Courier";
3561   if (argc >= 6)
3562     aFontName = TCollection_AsciiString (argv[5]);
3563
3564   // text colors
3565   Quantity_Parameter aColorRed   = 1.0;
3566   Quantity_Parameter aColorGreen = 1.0;
3567   Quantity_Parameter aColorBlue  = 1.0;
3568   if (argc >= 9)
3569   {
3570     aColorRed   = Draw::Atof (argv[6])/255.;
3571     aColorGreen = Draw::Atof (argv[7])/255.;
3572     aColorBlue  = Draw::Atof (argv[8])/255.;
3573   }
3574
3575   // display type
3576   TCollection_AsciiString aDispStr;
3577   if (argc >= 10)
3578     aDispStr = TCollection_AsciiString (argv[9]);
3579
3580   Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3581   if (aDispStr.IsEqual ("subtitle"))
3582     aTextType = Aspect_TODT_SUBTITLE;
3583   else if (aDispStr.IsEqual ("decal"))
3584     aTextType = Aspect_TODT_DEKALE;
3585   else if (aDispStr.IsEqual ("blend"))
3586     aTextType = Aspect_TODT_BLEND;
3587
3588   // subtitle color
3589   Quantity_Parameter aSubRed   = 1.0;
3590   Quantity_Parameter aSubGreen = 1.0;
3591   Quantity_Parameter aSubBlue  = 1.0;
3592   if (argc == 13)
3593   {
3594     aSubRed   = Draw::Atof (argv[10])/255.;
3595     aSubGreen = Draw::Atof (argv[11])/255.;
3596     aSubBlue  = Draw::Atof (argv[12])/255.;
3597   }
3598
3599   // check fo current overlay
3600   Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
3601   if (anOverlay.IsNull ())
3602   {
3603     Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
3604     anOverlay = aMgr->Overlay ();
3605     aView->SetLayerMgr (aMgr);
3606   }
3607
3608   Quantity_Color aTextColor (aColorRed, aColorGreen,
3609     aColorBlue, Quantity_TOC_RGB);
3610   Quantity_Color aSubtColor (aSubRed, aSubGreen,
3611     aSubBlue, Quantity_TOC_RGB);
3612
3613   // add text item
3614   Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
3615     aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
3616
3617   // update view
3618   aView->MustBeResized();
3619   aView->Redraw();
3620
3621   return 0;
3622 }
3623
3624 //==============================================================================
3625 //function : VGrid
3626 //purpose  :
3627 //==============================================================================
3628
3629 static int VGrid (Draw_Interpretor& /*theDI*/,
3630                   Standard_Integer  theArgNb,
3631                   const char**      theArgVec)
3632 {
3633   // get the active view
3634   Handle(V3d_View)   aView   = ViewerTest::CurrentView();
3635   Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3636   if (aView.IsNull() || aViewer.IsNull())
3637   {
3638     std::cerr << "No active view. Please call vinit.\n";
3639     return 1;
3640   }
3641
3642   Aspect_GridType     aType = aViewer->GridType();
3643   Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
3644
3645   Standard_Integer anIter = 1;
3646   for (; anIter < theArgNb; ++anIter)
3647   {
3648     const char* aValue = theArgVec[anIter];
3649     if (*aValue == 'r')
3650     {
3651       aType = Aspect_GT_Rectangular;
3652     }
3653     else if (*aValue == 'c')
3654     {
3655       aType = Aspect_GT_Circular;
3656     }
3657     else if (*aValue == 'l')
3658     {
3659       aMode = Aspect_GDM_Lines;
3660     }
3661     else if (*aValue == 'p')
3662     {
3663       aMode = Aspect_GDM_Points;
3664     }
3665     else if (strcmp (aValue, "off" ) == 0)
3666     {
3667       aViewer->DeactivateGrid();
3668       return 0;
3669     }
3670     else
3671     {
3672       break;
3673     }
3674   }
3675
3676   Standard_Integer aTail = (theArgNb - anIter);
3677   if (aTail == 0)
3678   {
3679     aViewer->ActivateGrid (aType, aMode);
3680     return 0;
3681   }
3682   else if (aTail != 2 && aTail != 5)
3683   {
3684     std::cerr << "Incorrect arguments number! Usage:\n"
3685               << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
3686     return 1;
3687   }
3688
3689   Quantity_Length anOriginX, anOriginY;
3690   Quantity_PlaneAngle aRotAngle;
3691   if (aType == Aspect_GT_Rectangular)
3692   {
3693     Quantity_Length aRStepX, aRStepY;
3694     aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3695
3696     anOriginX = Draw::Atof (theArgVec[anIter++]);
3697     anOriginY = Draw::Atof (theArgVec[anIter++]);
3698     if (aTail == 5)
3699     {
3700       aRStepX   = Draw::Atof (theArgVec[anIter++]);
3701       aRStepY   = Draw::Atof (theArgVec[anIter++]);
3702       aRotAngle = Draw::Atof (theArgVec[anIter++]);
3703     }
3704     aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3705     aViewer->ActivateGrid (aType, aMode);
3706   }
3707   else if (aType == Aspect_GT_Circular)
3708   {
3709     Quantity_Length aRadiusStep;
3710     Standard_Integer aDivisionNumber;
3711     aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3712
3713     anOriginX = Draw::Atof (theArgVec[anIter++]);
3714     anOriginY = Draw::Atof (theArgVec[anIter++]);
3715     if (aTail == 5)
3716     {
3717       aRadiusStep     = Draw::Atof (theArgVec[anIter++]);
3718       aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
3719       aRotAngle       = Draw::Atof (theArgVec[anIter++]);
3720     }
3721
3722     aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3723     aViewer->ActivateGrid (aType, aMode);
3724   }
3725
3726   return 0;
3727 }
3728
3729 //==============================================================================
3730 //function : VFps
3731 //purpose  :
3732 //==============================================================================
3733
3734 static int VFps (Draw_Interpretor& theDI,
3735                  Standard_Integer  theArgNb,
3736                  const char**      theArgVec)
3737 {
3738   // get the active view
3739   Handle(V3d_View) aView = ViewerTest::CurrentView();
3740   if (aView.IsNull())
3741   {
3742     std::cerr << "No active view. Please call vinit.\n";
3743     return 1;
3744   }
3745
3746   Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
3747   if (aFramesNb <= 0)
3748   {
3749     std::cerr << "Incorrect arguments!\n";
3750     return 1;
3751   }
3752
3753   // the time is meaningless for first call
3754   // due to async OpenGl rendering
3755   aView->Redraw();
3756
3757   // redraw view in loop to estimate average values
3758   OSD_Timer aTimer;
3759   aTimer.Start();
3760   for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
3761   {
3762     aView->Redraw();
3763   }
3764   aTimer.Stop();
3765   Standard_Real aCpu;
3766   const Standard_Real aTime = aTimer.ElapsedTime();
3767   aTimer.OSD_Chronometer::Show (aCpu);
3768
3769   const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
3770   const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
3771
3772   // return statistics
3773   theDI << "FPS: " << aFpsAver << "\n"
3774         << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
3775
3776   return 0;
3777 }
3778
3779
3780 //==============================================================================
3781 //function : VVbo
3782 //purpose  :
3783 //==============================================================================
3784
3785 static int VVbo (Draw_Interpretor& /*theDI*/,
3786                  Standard_Integer  theArgNb,
3787                  const char**      theArgVec)
3788 {
3789   // get the context
3790   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3791   if (aContextAIS.IsNull())
3792   {
3793     std::cerr << "No active view. Please call vinit.\n";
3794     return 1;
3795   }
3796
3797   Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
3798
3799   if (aDriver.IsNull())
3800   {
3801     std::cerr << "Graphic driver not available.\n";
3802     return 1;
3803   }
3804
3805   if (theArgNb < 2)
3806   {
3807     //theDI << "VBO: " << aDriver->ToUseVBO() << "\n";
3808     //return 0;
3809     std::cerr << "Wrong number of arguments.\n";
3810     return 1;
3811   }
3812
3813   aDriver->EnableVBO (Draw::Atoi(theArgVec[1]) != 0);
3814   return 0;
3815 }
3816
3817 //==============================================================================
3818 //function : VMemGpu
3819 //purpose  :
3820 //==============================================================================
3821
3822 static int VMemGpu (Draw_Interpretor& theDI,
3823                     Standard_Integer  theArgNb,
3824                     const char**      theArgVec)
3825 {
3826   // get the context
3827   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3828   if (aContextAIS.IsNull())
3829   {
3830     std::cerr << "No active view. Please call vinit.\n";
3831     return 1;
3832   }
3833
3834   Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
3835
3836   if (aDriver.IsNull())
3837   {
3838     std::cerr << "Graphic driver not available.\n";
3839     return 1;
3840   }
3841
3842   Standard_Size aFreeBytes = 0;
3843   TCollection_AsciiString anInfo;
3844   if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
3845   {
3846     std::cerr << "Information not available.\n";
3847     return 1;
3848   }
3849
3850   if (theArgNb > 1 && *theArgVec[1] == 'f')
3851   {
3852     theDI << Standard_Real (aFreeBytes);
3853   }
3854   else
3855   {
3856     theDI << anInfo;
3857   }
3858
3859   return 0;
3860 }
3861
3862 // ==============================================================================
3863 // function : VReadPixel
3864 // purpose  :
3865 // ==============================================================================
3866 static int VReadPixel (Draw_Interpretor& theDI,
3867                        Standard_Integer  theArgNb,
3868                        const char**      theArgVec)
3869 {
3870   // get the active view
3871   Handle(V3d_View) aView = ViewerTest::CurrentView();
3872   if (aView.IsNull())
3873   {
3874     std::cerr << "No active view. Please call vinit.\n";
3875     return 1;
3876   }
3877   else if (theArgNb < 3)
3878   {
3879     std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
3880     return 1;
3881   }
3882
3883   Image_PixMap::ImgFormat aFormat     = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
3884   Graphic3d_BufferType    aBufferType = Graphic3d_BT_RGBA;
3885
3886   Standard_Integer aWidth, aHeight;
3887   aView->Window()->Size (aWidth, aHeight);
3888   const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
3889   const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
3890   if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
3891   {
3892     std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
3893     return 1;
3894   }
3895
3896   Standard_Boolean toShowName = Standard_False;
3897   Standard_Boolean toShowHls  = Standard_False;
3898   for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
3899   {
3900     const char* aParam = theArgVec[anIter];
3901     if ( strcasecmp( aParam, "rgb" ) == 0 )
3902     {
3903       aFormat     = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
3904       aBufferType = Graphic3d_BT_RGB;
3905     }
3906     else if ( strcasecmp( aParam, "hls" ) == 0 )
3907     {
3908       aFormat     = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
3909       aBufferType = Graphic3d_BT_RGB;
3910       toShowHls   = Standard_True;
3911     }
3912     else if ( strcasecmp( aParam, "rgbf" ) == 0 )
3913     {
3914       aFormat     = Image_PixMap::ImgRGBF;
3915       aBufferType = Graphic3d_BT_RGB;
3916     }
3917     else if ( strcasecmp( aParam, "rgba" ) == 0 )
3918     {
3919       aFormat     = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
3920       aBufferType = Graphic3d_BT_RGBA;
3921     }
3922     else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
3923     {
3924       aFormat     = Image_PixMap::ImgRGBAF;
3925       aBufferType = Graphic3d_BT_RGBA;
3926     }
3927     else if ( strcasecmp( aParam, "depth" ) == 0 )
3928     {
3929       aFormat     = Image_PixMap::ImgGrayF;
3930       aBufferType = Graphic3d_BT_Depth;
3931     }
3932     else if ( strcasecmp( aParam, "name" ) == 0 )
3933     {
3934       toShowName = Standard_True;
3935     }
3936   }
3937
3938   Image_PixMap anImage;
3939   if (!anImage.InitTrash (aFormat, aWidth, aHeight))
3940   {
3941     std::cerr << "Image allocation failed\n";
3942     return 1;
3943   }
3944   else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
3945   {
3946     std::cerr << "Image dump failed\n";
3947     return 1;
3948   }
3949
3950   Quantity_Parameter anAlpha;
3951   Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
3952   if (toShowName)
3953   {
3954     if (aBufferType == Graphic3d_BT_RGBA)
3955     {
3956       theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
3957     }
3958     else
3959     {
3960       theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
3961     }
3962   }
3963   else
3964   {
3965     switch (aBufferType)
3966     {
3967       default:
3968       case Graphic3d_BT_RGB:
3969       {
3970         if (toShowHls)
3971         {
3972           theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
3973         }
3974         else
3975         {
3976           theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
3977         }
3978         break;
3979       }
3980       case Graphic3d_BT_RGBA:
3981       {
3982         theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
3983         break;
3984       }
3985       case Graphic3d_BT_Depth:
3986       {
3987         theDI << aColor.Red() << "\n";
3988         break;
3989       }
3990     }
3991   }
3992
3993   return 0;
3994 }
3995
3996 //==============================================================================
3997 //function : VDiffImage
3998 //purpose  : The draw-command compares two images.
3999 //==============================================================================
4000
4001 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4002 {
4003   if (theArgNb < 6)
4004   {
4005     theDI << "Not enough arguments.\n";
4006     return 1;
4007   }
4008
4009   // image file names
4010   const char* anImgPathRef = theArgVec[1];
4011   const char* anImgPathNew = theArgVec[2];
4012
4013   // get string tolerance and check its validity
4014   Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
4015   if (aTolColor < 0.0)
4016     aTolColor = 0.0;
4017   if (aTolColor > 1.0)
4018     aTolColor = 1.0;
4019
4020   Standard_Boolean toBlackWhite     = (Draw::Atoi (theArgVec[4]) == 1);
4021   Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
4022
4023   // image file of difference
4024   const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
4025
4026   // compare the images
4027   Image_Diff aComparer;
4028   if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
4029   {
4030     return 1;
4031   }
4032
4033   aComparer.SetColorTolerance (aTolColor);
4034   aComparer.SetBorderFilterOn (isBorderFilterOn);
4035   Standard_Integer aDiffColorsNb = aComparer.Compare();
4036   theDI << aDiffColorsNb << "\n";
4037
4038   // save image of difference
4039   if (aDiffImagePath != NULL)
4040   {
4041     aComparer.SaveDiffImage (aDiffImagePath);
4042   }
4043
4044   return 0;
4045 }
4046
4047 //=======================================================================
4048 //function : VSelect
4049 //purpose  : Emulates different types of selection by mouse:
4050 //           1) single click selection
4051 //           2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
4052 //           3) selection with polygon having corners at
4053 //           pixel positions (x1,y1),...,(xn,yn)
4054 //           4) any of these selections with shift button pressed
4055 //=======================================================================
4056 static Standard_Integer VSelect (Draw_Interpretor& di,
4057                                  Standard_Integer argc,
4058                                  const char ** argv)
4059 {
4060   if(argc < 3)
4061   {
4062     di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
4063     return 1;
4064   }
4065
4066   Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
4067   if(myAIScontext.IsNull())
4068   {
4069     di << "use 'vinit' command before " << argv[0] << "\n";
4070     return 1;
4071   }
4072   const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
4073   Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
4074   aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
4075   if(argc <= 4)
4076   {
4077     if(isShiftSelection)
4078       aCurrentEventManager->ShiftSelect();
4079     else
4080       aCurrentEventManager->Select();
4081   }
4082   else if(argc <= 6)
4083   {
4084     if(isShiftSelection)
4085       aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4086     else
4087       aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4088   }
4089   else
4090   {
4091     Standard_Integer anUpper = 0;
4092
4093     if(isShiftSelection)
4094       anUpper = (argc-1)/2;
4095     else
4096       anUpper = argc/2;
4097     TColgp_Array1OfPnt2d aPolyline(1,anUpper);
4098
4099     for(Standard_Integer i=1;i<=anUpper;++i)
4100       aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
4101
4102     if(isShiftSelection)
4103       aCurrentEventManager->ShiftSelect(aPolyline);
4104     else
4105       aCurrentEventManager->Select(aPolyline);
4106   }
4107   return 0;
4108 }
4109
4110 //=======================================================================
4111 //function : VMoveTo
4112 //purpose  : Emulates cursor movement to defined pixel position
4113 //=======================================================================
4114 static Standard_Integer VMoveTo (Draw_Interpretor& di,
4115                                 Standard_Integer argc,
4116                                 const char ** argv)
4117 {
4118   if(argc != 3)
4119   {
4120     di << "Usage : " << argv[0] << " x y" << "\n";
4121     return 1;
4122   }
4123
4124   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4125   if(aContext.IsNull())
4126   {
4127     di << "use 'vinit' command before " << argv[0] << "\n";
4128     return 1;
4129   }
4130   ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
4131   return 0;
4132 }
4133
4134 //=======================================================================
4135 //function : VViewParams
4136 //purpose  : Gets or sets AIS View characteristics
4137 //=======================================================================
4138 static Standard_Integer VViewParams (Draw_Interpretor& di,
4139                                 Standard_Integer argc,
4140                                 const char ** argv)
4141 {
4142   if ( argc != 1 && argc != 13)
4143   {
4144     di << "Usage : " << argv[0] << "\n";
4145     return 1;
4146   }
4147   Handle (V3d_View) anAISView = ViewerTest::CurrentView ();
4148   if ( anAISView.IsNull () )
4149   {
4150     di << "use 'vinit' command before " << argv[0] << "\n";
4151     return 1;
4152   }
4153   if(argc==1){
4154     Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale ();
4155     Standard_Real anAISViewCenterCoordinateX = 0.0;
4156     Standard_Real anAISViewCenterCoordinateY = 0.0;
4157     anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4158     Standard_Real anAISViewProjX = 0.0;
4159     Standard_Real anAISViewProjY = 0.0;
4160     Standard_Real anAISViewProjZ = 0.0;
4161     anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4162     Standard_Real anAISViewUpX = 0.0;
4163     Standard_Real anAISViewUpY = 0.0;
4164     Standard_Real anAISViewUpZ = 0.0;
4165     anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4166     Standard_Real anAISViewAtX = 0.0;
4167     Standard_Real anAISViewAtY = 0.0;
4168     Standard_Real anAISViewAtZ = 0.0;
4169     anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4170     di << "Scale of current view: " << anAISViewScale << "\n";
4171     di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n";
4172     di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
4173     di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
4174     di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
4175   }
4176   else
4177   {
4178     Quantity_Factor anAISViewScale = atof (argv [1]);
4179     Standard_Real anAISViewCenterCoordinateX = atof (argv [2]);
4180     Standard_Real anAISViewCenterCoordinateY = atof (argv [3]);
4181     Standard_Real anAISViewProjX = atof (argv [4]);
4182     Standard_Real anAISViewProjY = atof (argv [5]);
4183     Standard_Real anAISViewProjZ = atof (argv [6]);
4184     Standard_Real anAISViewUpX = atof (argv [7]);
4185     Standard_Real anAISViewUpY = atof (argv [8]);
4186     Standard_Real anAISViewUpZ = atof (argv [9]);
4187     Standard_Real anAISViewAtX = atof (argv [10]);
4188     Standard_Real anAISViewAtY = atof (argv [11]);
4189     Standard_Real anAISViewAtZ = atof (argv [12]);
4190     anAISView -> V3d_View::SetScale (anAISViewScale);
4191     anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4192     anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4193     anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4194     anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4195   }
4196   return 0;
4197 }
4198
4199 //=======================================================================
4200 //function : VChangeSelected
4201 //purpose  : Adds the shape to selection or remove one from it
4202 //=======================================================================
4203 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
4204                                 Standard_Integer argc,
4205                                 const char ** argv)
4206 {
4207   if(argc != 2)
4208   {
4209     di<<"Usage : " << argv[0] << " shape \n";
4210     return 1;
4211   }
4212   //get AIS_Shape:
4213   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4214   ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4215   TCollection_AsciiString aName(argv[1]);
4216   Handle(AIS_InteractiveObject) anAISObject;
4217
4218   if(!aMap.IsBound2(aName))
4219   {
4220     di<<"Use 'vdisplay' before";
4221     return 1;
4222   }
4223   else
4224   {
4225     anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
4226     if(anAISObject.IsNull()){
4227       di<<"No interactive object \n";
4228       return 1;
4229     }
4230
4231     if(aContext->HasOpenedContext())
4232     {
4233       aContext->AddOrRemoveSelected(anAISObject);
4234     }
4235     else
4236     {
4237       aContext->AddOrRemoveCurrentObject(anAISObject);
4238     }
4239   }
4240   return 0;
4241 }
4242
4243 //=======================================================================
4244 //function : VZClipping
4245 //purpose  : Gets or sets ZClipping mode, width and depth
4246 //=======================================================================
4247 static Standard_Integer VZClipping (Draw_Interpretor& di,
4248                                 Standard_Integer argc,
4249                                 const char ** argv)
4250 {
4251   if(argc>4)
4252   {
4253     di << "Usage : " << argv[0] << " [mode] [depth  width]" << "\n"
4254       <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4255     return -1;
4256   }
4257   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4258   if(aContext.IsNull())
4259   {
4260     di << "use 'vinit' command before " << argv[0] << "\n";
4261     return 1;
4262   }
4263   Handle(V3d_View) aView = ViewerTest::CurrentView();
4264   V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
4265   if(argc==1)
4266   {
4267     TCollection_AsciiString aZClippingModeString;
4268     Quantity_Length aDepth, aWidth;
4269     aZClippingMode = aView->ZClipping(aDepth, aWidth);
4270     switch (aZClippingMode)
4271     {
4272     case V3d_OFF:
4273       aZClippingModeString.Copy("OFF");
4274       break;
4275     case V3d_BACK:
4276       aZClippingModeString.Copy("BACK");
4277       break;
4278     case V3d_FRONT:
4279       aZClippingModeString.Copy("FRONT");
4280       break;
4281     case V3d_SLICE:
4282       aZClippingModeString.Copy("SLICE");
4283       break;
4284     default:
4285       aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
4286       break;
4287     }
4288     di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
4289       << "ZClipping depth = " << aDepth << "\n"
4290       << "ZClipping width = " << aWidth << "\n";
4291   }
4292   else
4293   {
4294     if(argc !=3)
4295     {
4296       Standard_Integer aStatus = 0;
4297       if ( strcmp (argv [1], "OFF") == 0 ) {
4298         aStatus = 1;
4299         aZClippingMode = V3d_OFF;
4300       }
4301       if ( strcmp (argv [1], "BACK") == 0 ) {
4302         aStatus = 1;
4303         aZClippingMode = V3d_BACK;
4304       }
4305       if ( strcmp (argv [1], "FRONT") == 0 ) {
4306         aStatus = 1;
4307         aZClippingMode = V3d_FRONT;
4308       }
4309       if ( strcmp (argv [1], "SLICE") == 0 ) {
4310         aStatus = 1;
4311         aZClippingMode = V3d_SLICE;
4312       }
4313       if (aStatus != 1)
4314       {
4315         di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4316           << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4317         return 1;
4318       }
4319       aView->SetZClippingType(aZClippingMode);
4320     }
4321     if(argc >2)
4322     {
4323       Quantity_Length aDepth = 0., aWidth = 1.;
4324       if(argc == 3)
4325       {
4326         aDepth = atof(argv[1]);
4327         aWidth = atof(argv[2]);
4328       }
4329       else if(argc == 4)
4330       {
4331         aDepth = atof(argv[2]);
4332         aWidth = atof(argv[3]);
4333       }
4334
4335       if(aDepth<0. || aDepth>1.)
4336       {
4337         di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4338         << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4339         return 1;
4340       }
4341       if(aWidth<0. || aWidth>1.)
4342       {
4343         di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4344         << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4345         return 1;
4346       }
4347
4348       aView->SetZClippingDepth(aDepth);
4349       aView->SetZClippingWidth(aWidth);
4350     }
4351     aView->Redraw();
4352   }
4353   return 0;
4354 }
4355
4356 //=======================================================================
4357 //function : VNbSelected
4358 //purpose  : Returns number of selected objects
4359 //=======================================================================
4360 static Standard_Integer VNbSelected (Draw_Interpretor& di,
4361                                 Standard_Integer argc,
4362                                 const char ** argv)
4363 {
4364   if(argc != 1)
4365   {
4366     di << "Usage : " << argv[0] << "\n";
4367     return 1;
4368   }
4369   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4370   if(aContext.IsNull())
4371   {
4372     di << "use 'vinit' command before " << argv[0] << "\n";
4373     return 1;
4374   }
4375   di << aContext->NbSelected() << "\n";
4376   return 0;
4377 }
4378
4379 //=======================================================================
4380 //function : VAntialiasing
4381 //purpose  : Switches altialiasing on or off
4382 //=======================================================================
4383 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
4384                                 Standard_Integer argc,
4385                                 const char ** argv)
4386 {
4387   if(argc > 2)
4388   {
4389     di << "Usage : " << argv[0] << " [1|0]" << "\n";
4390     return 1;
4391   }
4392
4393   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4394   if(aContext.IsNull())
4395   {
4396     di << "use 'vinit' command before " << argv[0] << "\n";
4397     return 1;
4398   }
4399
4400   Handle(V3d_View) aView = ViewerTest::CurrentView();
4401
4402   if((argc == 2) && (atof(argv[1]) == 0))
4403     aView->SetAntialiasingOff();
4404   else
4405     aView->SetAntialiasingOn();
4406   aView->Update();
4407   return 0;
4408 }
4409
4410 //=======================================================================
4411 //function : VPurgeDisplay
4412 //purpose  : Switches altialiasing on or off
4413 //=======================================================================
4414 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
4415                                 Standard_Integer argc,
4416                                 const char ** argv)
4417 {
4418   if (argc > 2)
4419   {
4420     di << "Usage : " << argv[0] << " [CollectorToo = 0|1]" << "\n";
4421     return 1;
4422   }
4423   Standard_Boolean isCollectorToo = Standard_False;
4424   if (argc == 2)
4425   {
4426       isCollectorToo = (atoi(argv [1]) != 0);
4427   }
4428   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4429   if (aContext.IsNull())
4430   {
4431     di << "use 'vinit' command before " << argv[0] << "\n";
4432     return 1;
4433   }
4434   aContext->CloseAllContexts(Standard_False);
4435   di << aContext->PurgeDisplay(isCollectorToo) << "\n";
4436   return 0;
4437 }
4438
4439 //=======================================================================
4440 //function : VSetViewSize
4441 //purpose  :
4442 //=======================================================================
4443 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
4444                                 Standard_Integer argc,
4445                                 const char ** argv)
4446 {
4447   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4448   if(aContext.IsNull())
4449   {
4450     di << "use 'vinit' command before " << argv[0] << "\n";
4451     return 1;
4452   }
4453   if(argc != 2)
4454   {
4455     di<<"Usage : " << argv[0] << " Size\n";
4456     return 1;
4457   }
4458   Standard_Real aSize = atof(argv[1]);
4459   if (aSize <= 0.)
4460   {
4461     di<<"Bad Size value  : " << aSize << "\n";
4462     return 1;
4463   }
4464
4465   Handle(V3d_View) aView = ViewerTest::CurrentView();
4466   aView->SetSize(aSize);
4467   return 0;
4468 }
4469
4470 //=======================================================================
4471 //function : VMoveView
4472 //purpose  :
4473 //=======================================================================
4474 static Standard_Integer VMoveView (Draw_Interpretor& di,
4475                                 Standard_Integer argc,
4476                                 const char ** argv)
4477 {
4478   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4479   if(aContext.IsNull())
4480   {
4481     di << "use 'vinit' command before " << argv[0] << "\n";
4482     return 1;
4483   }
4484   if(argc < 4 || argc > 5)
4485   {
4486     di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4487     return 1;
4488   }
4489   Standard_Real Dx = atof(argv[1]);
4490   Standard_Real Dy = atof(argv[2]);
4491   Standard_Real Dz = atof(argv[3]);
4492   Standard_Boolean aStart = Standard_True;
4493   if (argc == 5)
4494   {
4495       aStart = (atoi(argv[4]) > 0);
4496   }
4497
4498   Handle(V3d_View) aView = ViewerTest::CurrentView();
4499   aView->Move(Dx,Dy,Dz,aStart);
4500   return 0;
4501 }
4502
4503 //=======================================================================
4504 //function : VTranslateView
4505 //purpose  :
4506 //=======================================================================
4507 static Standard_Integer VTranslateView (Draw_Interpretor& di,
4508                                 Standard_Integer argc,
4509                                 const char ** argv)
4510 {
4511   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4512   if(aContext.IsNull())
4513   {
4514     di << "use 'vinit' command before " << argv[0] << "\n";
4515     return 1;
4516   }
4517   if(argc < 4 || argc > 5)
4518   {
4519     di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4520     return 1;
4521   }
4522   Standard_Real Dx = atof(argv[1]);
4523   Standard_Real Dy = atof(argv[2]);
4524   Standard_Real Dz = atof(argv[3]);
4525   Standard_Boolean aStart = Standard_True;
4526   if (argc == 5)
4527   {
4528       aStart = (atoi(argv[4]) > 0);
4529   }
4530
4531   Handle(V3d_View) aView = ViewerTest::CurrentView();
4532   aView->Translate(Dx,Dy,Dz,aStart);
4533   return 0;
4534 }
4535
4536 //=======================================================================
4537 //function : VTurnView
4538 //purpose  :
4539 //=======================================================================
4540 static Standard_Integer VTurnView (Draw_Interpretor& di,
4541                                 Standard_Integer argc,
4542                                 const char ** argv)
4543 {
4544   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4545   if(aContext.IsNull()) {
4546     di << "use 'vinit' command before " << argv[0] << "\n";
4547     return 1;
4548   }
4549   if(argc < 4 || argc > 5){
4550     di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
4551     return 1;
4552   }
4553   Standard_Real Ax = atof(argv[1]);
4554   Standard_Real Ay = atof(argv[2]);
4555   Standard_Real Az = atof(argv[3]);
4556   Standard_Boolean aStart = Standard_True;
4557   if (argc == 5)
4558   {
4559       aStart = (atoi(argv[4]) > 0);
4560   }
4561
4562   Handle(V3d_View) aView = ViewerTest::CurrentView();
4563   aView->Turn(Ax,Ay,Az,aStart);
4564   return 0;
4565 }
4566
4567 //==============================================================================
4568 //function : VTextureEnv
4569 //purpose  : ENables or disables environment mapping
4570 //==============================================================================
4571 class OCC_TextureEnv : public Graphic3d_TextureEnv
4572 {
4573 public:
4574   OCC_TextureEnv(const Standard_CString FileName);
4575   OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
4576   void SetTextureParameters(const Standard_Boolean theRepeatFlag,
4577                             const Standard_Boolean theModulateFlag,
4578                             const Graphic3d_TypeOfTextureFilter theFilter,
4579                             const Standard_ShortReal theXScale,
4580                             const Standard_ShortReal theYScale,
4581                             const Standard_ShortReal theXShift,
4582                             const Standard_ShortReal theYShift,
4583                             const Standard_ShortReal theAngle);
4584   DEFINE_STANDARD_RTTI(OCC_TextureEnv);
4585 };
4586 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4587 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4588 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
4589
4590 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
4591   : Graphic3d_TextureEnv(theFileName)
4592 {
4593 }
4594
4595 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
4596   : Graphic3d_TextureEnv(theTexId)
4597 {
4598 }
4599
4600 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
4601                                           const Standard_Boolean theModulateFlag,
4602                                           const Graphic3d_TypeOfTextureFilter theFilter,
4603                                           const Standard_ShortReal theXScale,
4604                                           const Standard_ShortReal theYScale,
4605                                           const Standard_ShortReal theXShift,
4606                                           const Standard_ShortReal theYShift,
4607                                           const Standard_ShortReal theAngle)
4608 {
4609   myParams->SetRepeat     (theRepeatFlag);
4610   myParams->SetModulate   (theModulateFlag);
4611   myParams->SetFilter     (theFilter);
4612   myParams->SetScale      (Graphic3d_Vec2(theXScale, theYScale));
4613   myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
4614   myParams->SetRotation   (theAngle);
4615 }
4616
4617 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
4618 {
4619   // get the active view
4620   Handle(V3d_View) aView = ViewerTest::CurrentView();
4621   if (aView.IsNull())
4622   {
4623     std::cerr << "No active view. Please call vinit.\n";
4624     return 1;
4625   }
4626
4627   // Checking the input arguments
4628   Standard_Boolean anEnableFlag = Standard_False;
4629   Standard_Boolean isOk         = theArgNb >= 2;
4630   if (isOk)
4631   {
4632     TCollection_AsciiString anEnableOpt(theArgVec[1]);
4633     anEnableFlag = anEnableOpt.IsEqual("on");
4634     isOk         = anEnableFlag || anEnableOpt.IsEqual("off");
4635   }
4636   if (anEnableFlag)
4637   {
4638     isOk = (theArgNb == 3 || theArgNb == 11);
4639     if (isOk)
4640     {
4641       TCollection_AsciiString aTextureOpt(theArgVec[2]);
4642       isOk = (!aTextureOpt.IsIntegerValue() ||
4643              (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
4644
4645       if (isOk && theArgNb == 11)
4646       {
4647         TCollection_AsciiString aRepeatOpt  (theArgVec[3]),
4648                                 aModulateOpt(theArgVec[4]),
4649                                 aFilterOpt  (theArgVec[5]),
4650                                 aSScaleOpt  (theArgVec[6]),
4651                                 aTScaleOpt  (theArgVec[7]),
4652                                 aSTransOpt  (theArgVec[8]),
4653                                 aTTransOpt  (theArgVec[9]),
4654                                 anAngleOpt  (theArgVec[10]);
4655         isOk = ((aRepeatOpt.  IsEqual("repeat")   || aRepeatOpt.  IsEqual("clamp")) &&
4656                 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
4657                 (aFilterOpt.  IsEqual("nearest")  || aFilterOpt.  IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
4658                 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
4659                 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
4660                 anAngleOpt.IsRealValue());
4661       }
4662     }
4663   }
4664
4665   if (!isOk)
4666   {
4667     std::cerr << "Usage :" << std::endl;
4668     std::cerr << theArgVec[0] << " off" << std::endl;
4669     std::cerr << theArgVec[0] << " on {index_of_std_texture(0..7)|texture_file_name} [{clamp|repeat} {decal|modulate} {nearest|bilinear|trilinear} scale_s scale_t translation_s translation_t rotation_degrees]" << std::endl;
4670     return 1;
4671   }
4672
4673   if (anEnableFlag)
4674   {
4675     TCollection_AsciiString aTextureOpt(theArgVec[2]);
4676     Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
4677                                      new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
4678                                      new OCC_TextureEnv(theArgVec[2]);
4679
4680     if (theArgNb == 11)
4681     {
4682       TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
4683       aTexEnv->SetTextureParameters(
4684         aRepeatOpt.  IsEqual("repeat"),
4685         aModulateOpt.IsEqual("modulate"),
4686         aFilterOpt.  IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
4687                                           aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
4688                                                                            Graphic3d_TOTF_TRILINEAR,
4689         (Standard_ShortReal)Draw::Atof(theArgVec[6]),
4690         (Standard_ShortReal)Draw::Atof(theArgVec[7]),
4691         (Standard_ShortReal)Draw::Atof(theArgVec[8]),
4692         (Standard_ShortReal)Draw::Atof(theArgVec[9]),
4693         (Standard_ShortReal)Draw::Atof(theArgVec[10])
4694         );
4695     }
4696     aView->SetTextureEnv(aTexEnv);
4697     aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
4698   }
4699   else // Disabling environment mapping
4700   {
4701     aView->SetSurfaceDetail(V3d_TEX_NONE);
4702     Handle(Graphic3d_TextureEnv) aTexture;
4703     aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
4704   }
4705
4706   aView->Redraw();
4707   return 0;
4708 }
4709
4710 //=======================================================================
4711 //function : ViewerCommands
4712 //purpose  :
4713 //=======================================================================
4714
4715 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
4716 {
4717
4718   const char *group = "ZeViewer";
4719   theCommands.Add("vinit",
4720 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
4721     "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
4722 #else
4723     "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
4724 #endif
4725     " - Creates new View window with specified name view_name.\n"
4726     "By default the new view is created in the viewer and in"
4727     " graphic driver shared with active view.\n"
4728     " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
4729     "If driverName isn't specified the driver will be shared with active view.\n"
4730     "If viewerName isn't specified the viewer will be shared with active view.\n"
4731 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
4732     " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
4733     "is used in creation of graphic driver\n"
4734 #endif
4735     " - l, t: pixel position of left top corner of the window\n"
4736     " - w,h: width and heigth of window respectively.\n"
4737     "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
4738     __FILE__,VInit,group);
4739   theCommands.Add("vclose" ,
4740     "view_id [keep_context=0|1]\n"
4741     "or vclose ALL - to remove all created views\n"
4742     " - removes view(viewer window) defined by its view_id.\n"
4743     " - keep_context: by default 0; if 1 and the last view is deleted"
4744     " the current context is not removed.",
4745     __FILE__,VClose,group);
4746   theCommands.Add("vactivate" ,
4747     "view_id"
4748     " - activates view(viewer window) defined by its view_id",
4749     __FILE__,VActivate,group);
4750   theCommands.Add("vviewlist",
4751     "vviewlist [format={tree, long}]"
4752     " - prints current list of views per viewer and graphic_driver ID shared between viewers"
4753     " - format: format of result output, if tree the output is a tree view;"
4754     "otherwise it's a list of full view names. By default format = tree",
4755     __FILE__,VViewList,group);
4756   theCommands.Add("vhelp" ,
4757     "vhelp            : display help on the viewer commands",
4758     __FILE__,VHelp,group);
4759   theCommands.Add("vtop" ,
4760     "vtop or <T>      : Top view" ,
4761     __FILE__,VTop,group);
4762   theCommands.Add("vbottom" ,
4763     "vbottom          : Bottom view" ,
4764     __FILE__,VBottom,group);
4765   theCommands.Add("vleft" ,
4766     "vleft            : Left view" ,
4767     __FILE__,VLeft,group);
4768   theCommands.Add("vright" ,
4769     "vright           : Right view" ,
4770     __FILE__,VRight,group);
4771   theCommands.Add("vaxo" ,
4772     " vaxo or <A>     : Axonometric view ",
4773     __FILE__,VAxo,group);
4774   theCommands.Add("vfront" ,
4775     "vfront           : Front view" ,
4776     __FILE__,VFront,group);
4777   theCommands.Add("vback" ,
4778     "vback            : Back view" ,
4779     __FILE__,VBack,group);
4780   theCommands.Add("vpick" ,
4781     "vpick           : vpick X Y Z [shape subshape] ( all variables as string )",
4782     VPick,group);
4783   theCommands.Add("vfit"    ,
4784     "vfit or <F>         : vfit",
4785     __FILE__,VFit,group);
4786   theCommands.Add("vzfit"    ,
4787     "vzfit",
4788     __FILE__,VZFit,group);
4789   theCommands.Add("vrepaint",
4790     "vrepaint        : vrepaint, force redraw",
4791     __FILE__,VRepaint,group);
4792   theCommands.Add("vclear",
4793     "vclear          : vclear",
4794     __FILE__,VClear,group);
4795   theCommands.Add("vsetbg",
4796     "vsetbg          : vsetbg imagefile [filltype] : Load image as background",
4797     __FILE__,VSetBg,group);
4798   theCommands.Add("vsetbgmode",
4799     "vsetbgmode      : vsetbgmode filltype : Change background image fill type",
4800     __FILE__,VSetBgMode,group);
4801   theCommands.Add("vsetgradientbg",
4802     "vsetgradientbg  : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
4803     __FILE__,VSetGradientBg,group);
4804   theCommands.Add("vsetgrbgmode",
4805     "vsetgrbgmode    : vsetgrbgmode filltype : Change gradient background fill type",
4806     __FILE__,VSetGradientBgMode,group);
4807   theCommands.Add("vsetcolorbg",
4808     "vsetcolorbg     : vsetcolorbg r g b : Set background color",
4809     __FILE__,VSetColorBg,group);
4810   theCommands.Add("vscale",
4811     "vscale          : vscale X Y Z",
4812     __FILE__,VScale,group);
4813   theCommands.Add("vzbufftrihedron",
4814     "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
4815     " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
4816     " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
4817     __FILE__,VTestZBuffTrihedron,group);
4818   theCommands.Add("vrotate",
4819     "vrotate         : vrotate AX AY AZ [X Y Z]",
4820     __FILE__,VRotate,group);
4821   theCommands.Add("vzoom",
4822     "vzoom           : vzoom coef",
4823     __FILE__,VZoom,group);
4824   theCommands.Add("vpan",
4825     "vpan            : vpan dx dy",
4826     __FILE__,VPan,group);
4827   theCommands.Add("vexport",
4828     "vexport         : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
4829     " : exports the view to a vector file of a given format"
4830     " : notice that EMF format requires patched gl2ps",
4831     __FILE__,VExport,group);
4832   theCommands.Add("vcolorscale",
4833     "vcolorscale     : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
4834     __FILE__,VColorScale,group);
4835   theCommands.Add("vgraduatedtrihedron",
4836     "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
4837     __FILE__,VGraduatedTrihedron,group);
4838   theCommands.Add("vprintview" ,
4839     "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
4840     __FILE__,VPrintView,group);
4841   theCommands.Add("vzlayer",
4842     "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
4843     __FILE__,VZLayer,group);
4844   theCommands.Add("voverlaytext",
4845     "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
4846     " : height - pixel height of the text (default=10.0)"
4847     " : font_name - name of font (default=courier)"
4848     " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
4849     " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
4850     " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
4851     __FILE__,VOverlayText,group);
4852   theCommands.Add("vlayerline",
4853     "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
4854     __FILE__,VLayerLine,group);
4855   theCommands.Add ("vgrid",
4856     "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
4857     " : Mode - rectangular or circular"
4858     " : Type - lines or points",
4859     __FILE__, VGrid, group);
4860   theCommands.Add ("vfps",
4861     "vfps [framesNb=100] : estimate average frame rate for active view",
4862     __FILE__, VFps, group);
4863   theCommands.Add ("vvbo",
4864     "vvbo {0|1} : turn VBO usage On/Off; affects only newly displayed objects",
4865     __FILE__, VVbo, group);
4866   theCommands.Add ("vmemgpu",
4867     "vmemgpu [f]: print system-dependent GPU memory information if available;"
4868     " with f option returns free memory in bytes",
4869     __FILE__, VMemGpu, group);
4870   theCommands.Add ("vreadpixel",
4871     "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
4872     " : Read pixel value for active view",
4873     __FILE__, VReadPixel, group);
4874   theCommands.Add("diffimage",
4875     "diffimage     : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
4876     __FILE__, VDiffImage, group);
4877   theCommands.Add ("vselect",
4878     "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
4879     "- emulates different types of selection:\n"
4880     "- 1) single click selection\n"
4881     "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
4882     "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
4883     "- 4) any of these selections with shift button pressed",
4884     __FILE__, VSelect, group);
4885   theCommands.Add ("vmoveto",
4886     "vmoveto x y"
4887     "- emulates cursor movement to pixel postion (x,y)",
4888     __FILE__, VMoveTo, group);
4889   theCommands.Add("vviewparams",
4890     "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
4891     "- gets or sets current view characteristics",
4892     __FILE__,VViewParams, group);
4893   theCommands.Add("vchangeselected",
4894     "vchangeselected shape"
4895     "- adds to shape to selection or remove one from it",
4896                 __FILE__, VChangeSelected, group);
4897   theCommands.Add("vzclipping",
4898     "vzclipping [mode] [depth width]\n"
4899     "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
4900     "- gets or sets ZClipping mode, width and depth",
4901     __FILE__,VZClipping,group);
4902   theCommands.Add ("vnbselected",
4903     "vnbselected", __FILE__, VNbSelected, group);
4904   theCommands.Add("vantialiasing",
4905     "vantialiasing 1|0",
4906     __FILE__,VAntialiasing,group);
4907   theCommands.Add ("vpurgedisplay",
4908     "vpurgedisplay [CollectorToo = 0|1]"
4909     "- removes structures which don't belong to objects displayed in neutral point",
4910     __FILE__, VPurgeDisplay, group);
4911   theCommands.Add("vsetviewsize",
4912     "vsetviewsize size",
4913     __FILE__,VSetViewSize,group);
4914   theCommands.Add("vmoveview",
4915     "vmoveview Dx Dy Dz [Start = 1|0]",
4916     __FILE__,VMoveView,group);
4917   theCommands.Add("vtranslateview",
4918     "vtranslateview Dx Dy Dz [Start = 1|0)]",
4919     __FILE__,VTranslateView,group);
4920   theCommands.Add("vturnview",
4921     "vturnview Ax Ay Az [Start = 1|0]",
4922     __FILE__,VTurnView,group);
4923   theCommands.Add("vtextureenv",
4924     "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
4925     "or user-defined file and optionally applying texture mapping parameters\n"
4926     "                  Usage:\n"
4927     "                  vtextureenv off - disables environment mapping\n"
4928     "                  vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
4929     "                              std_texture = (0..7)\n"
4930     "                              rep         = {clamp|repeat}\n"
4931     "                              mod         = {decal|modulate}\n"
4932     "                              flt         = {nearest|bilinear|trilinear}\n"
4933     "                              ss, st      - scale factors for s and t texture coordinates\n"
4934     "                              ts, tt      - translation for s and t texture coordinates\n"
4935     "                              rot         - texture rotation angle in degrees",
4936     __FILE__, VTextureEnv, group);
4937   theCommands.Add("vhlr" ,
4938     "is_enabled={on|off}"
4939     " - Hidden line removal algorithm:"
4940     " - is_enabled: if is on HLR algorithm is applied\n",
4941     __FILE__,VHLR,group);
4942   theCommands.Add("vhlrtype" ,
4943     "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
4944     " - Changes the type of HLR algorithm using for shapes."
4945     " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
4946     "   if equals to polyalgo, polygonal HLR algorithm is applied."
4947     "If shapes are not given HLR algoithm of given type is applied"
4948     " to all shapes in the view\n",
4949     __FILE__,VHLRType,group);
4950 }