0025778: Gradient background will cut view if there is ClipPlane defined.
[occt.git] / src / ViewerTest / ViewerTest_ViewerCommands.cxx
CommitLineData
b311480e 1// Created on: 1998-09-01
2// Created by: Robert COUBLANC
3// Copyright (c) 1998-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
58655684 17#include <OpenGl_GlCore20.hxx>
0a768f56 18#include <AIS_Shape.hxx>
0a768f56 19#include <AIS_InteractiveObject.hxx>
20#include <AIS_ListOfInteractive.hxx>
21#include <AIS_ListIteratorOfListOfInteractive.hxx>
22#include <DBRep.hxx>
2bd4c032 23#include <Graphic3d_AspectMarker3d.hxx>
7fd59977 24#include <Graphic3d_ExportFormat.hxx>
269294d6 25#include <Graphic3d_NameOfTextureEnv.hxx>
a79f67f8 26#include <Graphic3d_GraduatedTrihedron.hxx>
269294d6 27#include <Graphic3d_TextureEnv.hxx>
28#include <Graphic3d_TextureParams.hxx>
29#include <Graphic3d_TypeOfTextureFilter.hxx>
4269bd1b 30#include <Graphic3d_AspectFillArea3d.hxx>
7fd59977 31#include <ViewerTest.hxx>
8625ef7e 32#include <ViewerTest_AutoUpdater.hxx>
7fd59977 33#include <ViewerTest_EventManager.hxx>
4754e164 34#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
4269bd1b 35#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
7fd59977 36#include <Visual3d_View.hxx>
25289ec1 37#include <Visual3d_ViewManager.hxx>
12381341 38#include <V3d_AmbientLight.hxx>
71215351 39#include <V3d_ColorScale.hxx>
12381341 40#include <V3d_DirectionalLight.hxx>
25289ec1 41#include <V3d_LayerMgr.hxx>
12381341 42#include <V3d_LayerMgrPointer.hxx>
43#include <V3d_PositionalLight.hxx>
44#include <V3d_SpotLight.hxx>
18d715bd 45#include <NCollection_DoubleMap.hxx>
46#include <NCollection_List.hxx>
47#include <NCollection_Vector.hxx>
7fd59977 48#include <NIS_View.hxx>
49#include <NIS_Triangulated.hxx>
50#include <NIS_InteractiveContext.hxx>
51#include <AIS_InteractiveContext.hxx>
52#include <Draw_Interpretor.hxx>
53#include <Draw.hxx>
54#include <Draw_Appli.hxx>
7edf74fd 55#include <Aspect_PrintAlgo.hxx>
692613e5 56#include <Image_AlienPixMap.hxx>
58655684 57#include <OpenGl_GraphicDriver.hxx>
208e6839 58#include <OSD_Timer.hxx>
900f7229 59#include <TColStd_HSequenceOfAsciiString.hxx>
59f45b7c 60#include <TColStd_SequenceOfInteger.hxx>
4754e164 61#include <TColStd_HSequenceOfReal.hxx>
62#include <TColgp_Array1OfPnt2d.hxx>
197ac94e 63#include <TColStd_MapOfAsciiString.hxx>
20637bd2 64#include <Visual3d_LayerItem.hxx>
20637bd2 65#include <Aspect_TypeOfLine.hxx>
692613e5 66#include <Image_Diff.hxx>
dc3fe572 67#include <Aspect_DisplayConnection.hxx>
4269bd1b 68#include <gp_Pnt.hxx>
69#include <gp_Dir.hxx>
70#include <gp_Pln.hxx>
71#include <PrsMgr_PresentableObject.hxx>
72#include <Graphic3d_ClipPlane.hxx>
73#include <NCollection_DataMap.hxx>
74#include <Graphic3d_Texture2Dmanual.hxx>
75#include <Prs3d_ShadingAspect.hxx>
6262338c 76#include <Prs3d_Drawer.hxx>
7fd59977 77
25289ec1 78#ifdef WNT
79#undef DrawText
80#endif
81
82#include <Visual3d_Layer.hxx>
692613e5 83#include <cstdlib>
25289ec1 84
58655684 85#if defined(_WIN32)
4fe56619 86 #include <WNT_WClass.hxx>
87 #include <WNT_Window.hxx>
88
89 #if defined(_MSC_VER)
90 #define _CRT_SECURE_NO_DEPRECATE
91 #pragma warning (disable:4996)
92 #endif
93#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
4fe56619 94 #include <Cocoa_Window.hxx>
7fd59977 95#else
4fe56619 96 #include <Xw_Window.hxx>
97 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
98 #include <X11/Xutil.h>
99 #include <tk.h>
7fd59977 100#endif
101
8625ef7e 102inline Standard_Boolean parseOnOff (Standard_CString theArg,
103 Standard_Boolean& theIsOn)
104{
105 TCollection_AsciiString aFlag (theArg);
106 aFlag.LowerCase();
107 if (aFlag == "on"
108 || aFlag == "1")
109 {
110 theIsOn = Standard_True;
111 return Standard_True;
112 }
113 else if (aFlag == "off"
114 || aFlag == "0")
115 {
116 theIsOn = Standard_False;
117 return Standard_True;
118 }
119 return Standard_False;
120}
121
b514beda 122// Auxiliary definitions
123static const char THE_KEY_DELETE = 127;
7fd59977 124
125//==============================================================================
126// VIEWER GLOBAL VARIABLES
127//==============================================================================
128
129Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
b514beda 130Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
7fd59977 131
132Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
133extern const Handle(NIS_InteractiveContext)& TheNISContext();
4754e164 134extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
7fd59977 135
b514beda 136extern int VErase (Draw_Interpretor& theDI,
137 Standard_Integer theArgNb,
138 const char** theArgVec);
139
58655684 140#if defined(_WIN32)
7fd59977 141static Handle(WNT_Window)& VT_GetWindow() {
142 static Handle(WNT_Window) WNTWin;
143 return WNTWin;
144}
4fe56619 145#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
4fe56619 146static Handle(Cocoa_Window)& VT_GetWindow()
147{
148 static Handle(Cocoa_Window) aWindow;
149 return aWindow;
150}
151extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
18d715bd 152extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
153extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
154
7fd59977 155#else
7fd59977 156static Handle(Xw_Window)& VT_GetWindow(){
157 static Handle(Xw_Window) XWWin;
158 return XWWin;
159}
7fd59977 160
161static void VProcessEvents(ClientData,int);
162#endif
163
18d715bd 164static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
165{
166 static Handle(Aspect_DisplayConnection) aDisplayConnection;
167 return aDisplayConnection;
168}
169
170static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
171{
172 GetDisplayConnection() = theDisplayConnection;
173}
174
58655684 175#if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
18d715bd 176Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
dc3fe572 177{
0ebaa4db 178 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
58655684 179#if defined(_WIN32)
18d715bd 180 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
181 if (!aWindow.IsNull())
182 return aWindow->HWindow();
183#elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
184 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
185 if (!aWindow.IsNull())
186 return aWindow->XWindow();
187#endif
188 return aWindowHandle;
dc3fe572 189}
18d715bd 190#endif
dc3fe572 191
de75ed09 192static Standard_Boolean MyHLRIsOn = Standard_False;
7fd59977 193
18d715bd 194NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
58655684 195static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
18d715bd 196static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
58655684 197static OpenGl_Caps ViewerTest_myDefaultCaps;
18d715bd 198
7fd59977 199#define ZCLIPWIDTH 1.
200
201static void OSWindowSetup();
202
203//==============================================================================
204// EVENT GLOBAL VARIABLES
205//==============================================================================
206
207static int Start_Rot = 0;
208static int ZClipIsOn = 0;
4fe56619 209int X_Motion = 0; // Current cursor position
210int Y_Motion = 0;
211int X_ButtonPress = 0; // Last ButtonPress position
212int Y_ButtonPress = 0;
213Standard_Boolean IsDragged = Standard_False;
8abada55 214Standard_Boolean DragFirst = Standard_False;
7fd59977 215
216//==============================================================================
217
218#ifdef WNT
219static LRESULT WINAPI ViewerWindowProc(
220 HWND hwnd,
221 UINT uMsg,
222 WPARAM wParam,
223 LPARAM lParam );
224static LRESULT WINAPI AdvViewerWindowProc(
225 HWND hwnd,
226 UINT uMsg,
227 WPARAM wParam,
228 LPARAM lParam );
229#endif
230
231
232//==============================================================================
233//function : WClass
234//purpose :
235//==============================================================================
236
237const Handle(MMgt_TShared)& ViewerTest::WClass()
238{
239 static Handle(MMgt_TShared) theWClass;
58655684 240#if defined(_WIN32)
4fe56619 241 if (theWClass.IsNull())
242 {
7fd59977 243 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
244 CS_VREDRAW | CS_HREDRAW, 0, 0,
245 ::LoadCursor (NULL, IDC_ARROW));
246 }
247#endif
248 return theWClass;
249}
250
18d715bd 251//==============================================================================
252//function : CreateName
253//purpose : Create numerical name for new object in theMap
254//==============================================================================
255template <typename ObjectType>
256TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
257 const TCollection_AsciiString& theDefaultString)
258{
259 if (theObjectMap.IsEmpty())
260 return theDefaultString + TCollection_AsciiString(1);
261
262 Standard_Integer aNextKey = 1;
263 Standard_Boolean isFound = Standard_False;
264 while (!isFound)
265 {
266 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
267 // Look for objects with default names
268 if (theObjectMap.IsBound1(aStringKey))
269 {
270 aNextKey++;
271 }
272 else
273 isFound = Standard_True;
274 }
275
276 return theDefaultString + TCollection_AsciiString(aNextKey);
277}
278
279//==============================================================================
280//structure : ViewerTest_Names
281//purpose : Allow to operate with full view name: driverName/viewerName/viewName
282//==============================================================================
283struct ViewerTest_Names
284{
285private:
286 TCollection_AsciiString myDriverName;
287 TCollection_AsciiString myViewerName;
288 TCollection_AsciiString myViewName;
289
290public:
291
292 const TCollection_AsciiString& GetDriverName () const
293 {
294 return myDriverName;
295 }
296 void SetDriverName (const TCollection_AsciiString& theDriverName)
297 {
298 myDriverName = theDriverName;
299 }
300 const TCollection_AsciiString& GetViewerName () const
301 {
302 return myViewerName;
303 }
304 void SetViewerName (const TCollection_AsciiString& theViewerName)
305 {
306 myViewerName = theViewerName;
307 }
308 const TCollection_AsciiString& GetViewName () const
309 {
310 return myViewName;
311 }
312 void SetViewName (const TCollection_AsciiString& theViewName)
313 {
314 myViewName = theViewName;
315 }
316
317 //===========================================================================
318 //function : Constructor for ViewerTest_Names
319 //purpose : Get view, viewer, driver names from custom string
320 //===========================================================================
321
322 ViewerTest_Names (const TCollection_AsciiString& theInputString)
323 {
324 TCollection_AsciiString aName(theInputString);
325 if (theInputString.IsEmpty())
326 {
327 // Get current configuration
328 if (ViewerTest_myDrivers.IsEmpty())
329 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
330 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
331 else
332 myDriverName = ViewerTest_myDrivers.Find2
333 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
334
335 if(ViewerTest_myContexts.IsEmpty())
336 {
337 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
338 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
339 }
340 else
341 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
342
343 myViewName = CreateName <Handle(V3d_View)>
344 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
345 }
346 else
347 {
348 // There is at least view name
349 Standard_Integer aParserNumber = 0;
350 for (Standard_Integer i = 0; i < 3; ++i)
351 {
352 Standard_Integer aParserPos = aName.SearchFromEnd("/");
353 if(aParserPos != -1)
354 {
355 aParserNumber++;
356 aName.Split(aParserPos-1);
357 }
358 else
359 break;
360 }
361 if (aParserNumber == 0)
362 {
363 // Only view name
364 if (!ViewerTest::GetAISContext().IsNull())
365 {
366 myDriverName = ViewerTest_myDrivers.Find2
367 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
368 myViewerName = ViewerTest_myContexts.Find2
369 (ViewerTest::GetAISContext());
370 }
371 else
372 {
373 // There is no opened contexts here, need to create names for viewer and driver
374 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
375 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
376
377 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
378 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
379 }
380 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
381 }
382 else if (aParserNumber == 1)
383 {
384 // Here is viewerName/viewName
385 if (!ViewerTest::GetAISContext().IsNull())
386 myDriverName = ViewerTest_myDrivers.Find2
387 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
388 else
389 {
390 // There is no opened contexts here, need to create name for driver
391 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
392 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
393 }
394 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
395
396 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
397 }
398 else
399 {
400 //Here is driverName/viewerName/viewName
401 myDriverName = TCollection_AsciiString(aName);
402
403 TCollection_AsciiString aViewerName(theInputString);
404 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
405 myViewerName = TCollection_AsciiString(aViewerName);
406
407 myViewName = TCollection_AsciiString(theInputString);
408 }
409 }
410 }
411};
412
413//==============================================================================
414//function : FindContextByView
415//purpose : Find AIS_InteractiveContext by View
416//==============================================================================
417
418Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
419{
420 Handle(AIS_InteractiveContext) anAISContext;
421
422 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
423 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
424 {
425 if (anIter.Value()->CurrentViewer() == theView->Viewer())
426 return anIter.Key2();
427 }
428 return anAISContext;
429}
430
431
432//==============================================================================
433//function : SetWindowTitle
434//purpose : Set window title
435//==============================================================================
436
437void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
438 Standard_CString theTitle)
439{
58655684 440#if defined(_WIN32)
18d715bd 441 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
442 theTitle);
443#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
444 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
445#else
446 if(GetDisplayConnection()->GetDisplay())
447 {
448 Window aWindow =
449 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
450 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
451 }
452#endif
453}
454
455//==============================================================================
456//function : IsWindowOverlapped
457//purpose : Check if theWindow overlapp another view
458//==============================================================================
459
460Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
461 const Standard_Integer thePxTop,
462 const Standard_Integer thePxRight,
463 const Standard_Integer thePxBottom,
464 TCollection_AsciiString& theViewId)
465{
466 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
467 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
468 {
469 Standard_Integer aTop = 0,
470 aLeft = 0,
471 aRight = 0,
472 aBottom = 0;
473 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
474 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
475 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
476 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
477 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
478 {
479 theViewId = anIter.Key1();
480 return Standard_True;
481 }
482 }
483 return Standard_False;
484}
485
486// Workaround: to create and delete non-orthographic views outside ViewerTest
487void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
488{
489 ViewerTest_myViews.UnBind1 (theName);
490}
491
492void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
493 const Handle(V3d_View)& theView)
494{
495 ViewerTest_myViews.Bind (theName, theView);
496}
497
498TCollection_AsciiString ViewerTest::GetCurrentViewName ()
499{
500 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
501}
7fd59977 502//==============================================================================
503//function : ViewerInit
504//purpose : Create the window viewer and initialize all the global variable
505//==============================================================================
506
18d715bd 507TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
508 const Standard_Integer thePxTop,
509 const Standard_Integer thePxWidth,
510 const Standard_Integer thePxHeight,
511 Standard_CString theViewName,
512 Standard_CString theDisplayName)
7fd59977 513{
8c3c9904 514 // Default position and dimension of the viewer window.
4fe56619 515 // Note that left top corner is set to be sufficiently small to have
8c3c9904 516 // window fit in the small screens (actual for remote desktops, see #23003).
4fe56619 517 // The position corresponds to the window's client area, thus some
8c3c9904 518 // gap is added for window frame to be visible.
519 Standard_Integer aPxLeft = 20;
520 Standard_Integer aPxTop = 40;
7fd59977 521 Standard_Integer aPxWidth = 409;
522 Standard_Integer aPxHeight = 409;
18d715bd 523 Standard_Boolean toCreateViewer = Standard_False;
524
58655684 525 Handle(OpenGl_GraphicDriver) aGraphicDriver;
18d715bd 526 ViewerTest_Names aViewNames(theViewName);
527 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
528 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
529
530 if (thePxLeft != 0)
531 aPxLeft = thePxLeft;
532 if (thePxTop != 0)
533 aPxTop = thePxTop;
534 if (thePxWidth != 0)
535 aPxWidth = thePxWidth;
536 if (thePxHeight != 0)
7fd59977 537 aPxHeight = thePxHeight;
4269bd1b 538
18d715bd 539 // Get graphic driver (create it or get from another view)
540 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
541 {
542 // Get connection string
58655684 543 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
18d715bd 544 TCollection_AsciiString aDisplayName(theDisplayName);
498ce76b 545 if (!aDisplayName.IsEmpty())
18d715bd 546 SetDisplayConnection (new Aspect_DisplayConnection ());
547 else
548 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
18d715bd 549 #else
498ce76b 550 (void)theDisplayName; // avoid warning on unused argument
18d715bd 551 SetDisplayConnection (new Aspect_DisplayConnection ());
552 #endif
65993a95 553 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
58655684 554 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
18d715bd 555 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
556 toCreateViewer = Standard_True;
557 }
558 else
559 {
58655684 560 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
7fd59977 561 }
562
18d715bd 563 //Dispose the window if input parameters are default
564 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
7fd59977 565 {
18d715bd 566 Standard_Integer aTop = 0,
567 aLeft = 0,
568 aRight = 0,
569 aBottom = 0,
570 aScreenWidth = 0,
571 aScreenHeight = 0;
572
573 // Get screen resolution
574#if defined(_WIN32) || defined(__WIN32__)
575 RECT aWindowSize;
576 GetClientRect(GetDesktopWindow(), &aWindowSize);
577 aScreenHeight = aWindowSize.bottom;
578 aScreenWidth = aWindowSize.right;
579#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
580 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
581#else
582 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
583 aScreenWidth = WidthOfScreen(aScreen);
584 aScreenHeight = HeightOfScreen(aScreen);
585#endif
586
587 TCollection_AsciiString anOverlappedViewId("");
773f53f1 588
589 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
dc3fe572 590 {
18d715bd 591 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
592
593 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
594 && aRight + 2*aPxWidth + 40 > aScreenWidth)
595 {
596 if (aBottom + aPxHeight + 40 > aScreenHeight)
597 {
598 aPxLeft = 20;
599 aPxTop = 40;
600 break;
601 }
602 aPxLeft = 20;
603 aPxTop = aBottom + 40;
604 }
605 else
606 aPxLeft = aRight + 20;
dc3fe572 607 }
18d715bd 608 }
609
610 // Get viewer name
611 TCollection_AsciiString aTitle("3D View - ");
612 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
613
614 // Change name of current active window
615 if (!ViewerTest::CurrentView().IsNull())
616 {
617 TCollection_AsciiString aTitle("3D View - ");
618 aTitle = aTitle
619 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
620 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
621 }
622
623 // Create viewer
eb4320f2 624 Handle(V3d_Viewer) a3DViewer;
18d715bd 625 // If it's the single view, we first look for empty context
626 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
627 {
628 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
629 anIter(ViewerTest_myContexts);
630 if (anIter.More())
631 ViewerTest::SetAISContext (anIter.Value());
632 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
18d715bd 633 }
634 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
635 {
636 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
637 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
18d715bd 638 }
eb4320f2 639 else if (a3DViewer.IsNull())
18d715bd 640 {
641 toCreateViewer = Standard_True;
642 TCollection_ExtendedString NameOfWindow("Viewer3D");
643 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
644
645 NameOfWindow = TCollection_ExtendedString("Collector");
18d715bd 646
647 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
18d715bd 648 }
649
650 // AIS context setup
651 if (ViewerTest::GetAISContext().IsNull() ||
652 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
653 {
e79a94b9 654 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
18d715bd 655 ViewerTest::SetAISContext (aContext);
656 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
657 }
658 else
e79a94b9 659 {
18d715bd 660 ViewerTest::ResetEventManager();
e79a94b9 661 }
18d715bd 662
663 // Create window
e79a94b9 664#if defined(_WIN32)
665 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
666 Handle(WNT_WClass)::DownCast (WClass()),
667 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
668 aPxLeft, aPxTop,
669 aPxWidth, aPxHeight,
670 Quantity_NOC_BLACK);
4fe56619 671#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
e79a94b9 672 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
673 aPxLeft, aPxTop,
674 aPxWidth, aPxHeight);
675 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
7fd59977 676#else
e79a94b9 677 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
678 aTitle.ToCString(),
679 aPxLeft, aPxTop,
680 aPxWidth, aPxHeight);
7fd59977 681#endif
18d715bd 682 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
7fd59977 683
18d715bd 684 // NIS setup
685 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
4269bd1b 686
18d715bd 687 ViewerTest::CurrentView(aView);
688 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
689 TheNISContext()->AttachView (aView);
7fd59977 690
18d715bd 691 // Setup for X11 or NT
692 OSWindowSetup();
7fd59977 693
18d715bd 694 // Set parameters for V3d_View and V3d_Viewer
695 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
696 aV3dView->SetComputedMode(Standard_False);
697 MyHLRIsOn = aV3dView->ComputedMode();
698 aV3dView->SetZClippingDepth(0.5);
699 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
7fd59977 700
18d715bd 701 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
702 if (toCreateViewer)
703 {
7fd59977 704 a3DViewer->SetDefaultLights();
705 a3DViewer->SetLightOn();
18d715bd 706 }
7fd59977 707
e79a94b9 708 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
4fe56619 709 #if TCL_MAJOR_VERSION < 8
18d715bd 710 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 711 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
4fe56619 712 #else
18d715bd 713 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 714 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
4fe56619 715 #endif
716 #endif
7fd59977 717
7fd59977 718 VT_GetWindow()->Map();
4269bd1b 719
18d715bd 720 // Set the handle of created view in the event manager
721 ViewerTest::ResetEventManager();
722
4fe56619 723 ViewerTest::CurrentView()->Redraw();
18d715bd 724
725 aView.Nullify();
726 a3DViewer.Nullify();
18d715bd 727
728 return aViewNames.GetViewName();
729}
730
4269bd1b 731//==============================================================================
732//function : RedrawAllViews
733//purpose : Redraw all created views
734//==============================================================================
735void ViewerTest::RedrawAllViews()
736{
737 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
738 for (; aViewIt.More(); aViewIt.Next())
739 {
740 const Handle(V3d_View)& aView = aViewIt.Key2();
741 aView->Redraw();
742 }
743}
744
7fd59977 745//==============================================================================
746//function : Vinit
747//purpose : Create the window viewer and initialize all the global variable
e79a94b9 748// Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
7fd59977 749//==============================================================================
750
18d715bd 751static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 752{
e79a94b9 753 if (theArgsNb > 9)
18d715bd 754 {
e79a94b9 755 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
756 << "Type help for more information.\n";
18d715bd 757 return 1;
758 }
18d715bd 759
e79a94b9 760 TCollection_AsciiString aViewName, aDisplayName;
761 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
762 TCollection_AsciiString aName, aValue;
763 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
18d715bd 764 {
e79a94b9 765 const TCollection_AsciiString anArg = theArgVec[anArgIt];
766 TCollection_AsciiString anArgCase = anArg;
767 anArgCase.UpperCase();
1d7ca641 768 if (ViewerTest::SplitParameter (anArg, aName, aValue))
18d715bd 769 {
e79a94b9 770 aName.UpperCase();
771 if (aName.IsEqual ("NAME"))
18d715bd 772 {
773 aViewName = aValue;
774 }
e79a94b9 775 else if (aName.IsEqual ("L")
776 || aName.IsEqual ("LEFT"))
777 {
18d715bd 778 aPxLeft = aValue.IntegerValue();
e79a94b9 779 }
780 else if (aName.IsEqual ("T")
781 || aName.IsEqual ("TOP"))
782 {
18d715bd 783 aPxTop = aValue.IntegerValue();
e79a94b9 784 }
785 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
786 else if (aName.IsEqual ("DISP")
787 || aName.IsEqual ("DISPLAY"))
788 {
18d715bd 789 aDisplayName = aValue;
e79a94b9 790 }
791 #endif
792 else if (aName.IsEqual ("W")
793 || aName.IsEqual ("WIDTH"))
794 {
18d715bd 795 aPxWidth = aValue.IntegerValue();
e79a94b9 796 }
797 else if (aName.IsEqual ("H")
798 || aName.IsEqual ("HEIGHT"))
799 {
18d715bd 800 aPxHeight = aValue.IntegerValue();
e79a94b9 801 }
18d715bd 802 else
803 {
e79a94b9 804 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
18d715bd 805 }
806 }
e79a94b9 807 else if (aViewName.IsEmpty())
808 {
809 aViewName = anArg;
810 }
811 else
812 {
813 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
814 }
18d715bd 815 }
816
817 ViewerTest_Names aViewNames (aViewName);
e79a94b9 818 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
18d715bd 819 {
e79a94b9 820 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
821 theDi.Eval (aCommand.ToCString());
18d715bd 822 return 0;
823 }
824
825 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
826 aViewName.ToCString(),
827 aDisplayName.ToCString());
e79a94b9 828 theDi << aViewId;
7fd59977 829 return 0;
830}
831
0a768f56 832//==============================================================================
833//function : VHLR
834//purpose : hidden lines removal algorithm
e9224045 835//draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
0a768f56 836//==============================================================================
837
838static int VHLR (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
e9224045 846 if (argc < 2)
0a768f56 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
e9224045 853 // Enable or disable HLR mode.
0a768f56 854 Standard_Boolean isHLROn =
855 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
856
e9224045 857 if (isHLROn != MyHLRIsOn)
0a768f56 858 {
e9224045 859 MyHLRIsOn = isHLROn;
860 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
0a768f56 861 }
862
e9224045 863 // Show or hide hidden lines in HLR mode.
864 Standard_Boolean isCurrentShowHidden
865 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
866
867 Standard_Boolean isShowHidden =
868 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
869 : isCurrentShowHidden;
870
871
872 if (isShowHidden != isCurrentShowHidden)
873 {
874 if (isShowHidden)
875 {
876 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
877 }
878 else
879 {
880 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
881 }
882
883 // Redisplay shapes.
884 if (MyHLRIsOn)
885 {
886 AIS_ListOfInteractive aListOfShapes;
887 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
888
889 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
890 {
891 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
892 if (aShape.IsNull())
893 {
894 continue;
895 }
36132a2e 896 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
e9224045 897 }
898 }
899 }
0a768f56 900
e9224045 901 ViewerTest::CurrentView()->Update();
0a768f56 902 return 0;
903}
904
905//==============================================================================
906//function : VHLRType
907//purpose : change type of using HLR algorithm
908//==============================================================================
909
910static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
911{
912 if (ViewerTest::CurrentView().IsNull())
913 {
914 di << argv[0] << ": Call vinit before this command, please.\n";
915 return 1;
916 }
917
918 if (argc < 2)
919 {
920 di << argv[0] << ": Wrong number of command arguments.\n"
921 << "Type help " << argv[0] << " for more information.\n";
922 return 1;
923 }
924
925 Prs3d_TypeOfHLR aTypeOfHLR =
926 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
927
928 if (argc == 2)
929 {
930 AIS_ListOfInteractive aListOfShapes;
931 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
932 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
933 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
934 anIter.More(); anIter.Next())
935 {
936 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
937 if (aShape.IsNull())
938 continue;
939 if (aShape->TypeOfHLR() != aTypeOfHLR)
940 aShape->SetTypeOfHLR (aTypeOfHLR);
941 if (MyHLRIsOn)
36132a2e 942 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
0a768f56 943 }
944 ViewerTest::CurrentView()->Update();
945 return 0;
946 }
947 else
948 {
949 for (Standard_Integer i = 2; i < argc; ++i)
950 {
951 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
952 TCollection_AsciiString aName (argv[i]);
953
954 if (!aMap.IsBound2 (aName))
955 {
956 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
957 continue;
958 }
959 Handle(AIS_Shape) anAISObject =
960 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
961 if (anAISObject.IsNull())
962 continue;
963 anAISObject->SetTypeOfHLR (aTypeOfHLR);
964 if (MyHLRIsOn)
36132a2e 965 ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False);
0a768f56 966 }
967 ViewerTest::CurrentView()->Update();
968 }
969
970 return 0;
971}
972
18d715bd 973//==============================================================================
974//function : FindViewIdByWindowHandle
975//purpose : Find theView Id in the map of views by window handle
976//==============================================================================
977#if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
978TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
979{
980 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
981 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
982 {
983 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
984 if (aWindowHandle == theWindowHandle)
985 return anIter.Key1();
986 }
987 return TCollection_AsciiString("");
988}
989#endif
990
991//==============================================================================
992//function : ActivateView
993//purpose : Make the view active
994//==============================================================================
995
996void ActivateView (const TCollection_AsciiString& theViewName)
997{
998 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
999 if (!aView.IsNull())
1000 {
1001 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1002 if (!anAISContext.IsNull())
1003 {
1004 if (!ViewerTest::CurrentView().IsNull())
1005 {
1006 TCollection_AsciiString aTitle("3D View - ");
1007 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1008 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1009 }
1010
1011 ViewerTest::CurrentView (aView);
1012 // Update degenerate mode
1013 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
1014 ViewerTest::SetAISContext (anAISContext);
1015 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
1016 aTitle = aTitle + theViewName + "(*)";
1017 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1018#if defined(_WIN32) || defined(__WIN32__)
1019 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1020#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1021 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1022#else
1023 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1024#endif
1025 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1026 ViewerTest::CurrentView()->Redraw();
1027 }
1028 }
1029}
1030
0e93d9e5 1031//==============================================================================
1032//function : RemoveView
1033//purpose :
1034//==============================================================================
1035void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1036 const Standard_Boolean theToRemoveContext)
1037{
1038 if (!ViewerTest_myViews.IsBound2 (theView))
1039 {
1040 return;
1041 }
1042
1043 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1044 RemoveView (aViewName, theToRemoveContext);
1045}
1046
18d715bd 1047//==============================================================================
1048//function : RemoveView
1049//purpose : Close and remove view from display, clear maps if neccessary
1050//==============================================================================
1051void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1052{
1053 if (!ViewerTest_myViews.IsBound1(theViewName))
1054 {
1055 cout << "Wrong view name\n";
1056 return;
1057 }
1058
1059 // Activate another view if it's active now
1060 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1061 {
1062 if (ViewerTest_myViews.Extent() > 1)
1063 {
1064 TCollection_AsciiString aNewViewName;
1065 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1066 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1067 if (anIter.Key1() != theViewName)
1068 {
1069 aNewViewName = anIter.Key1();
1070 break;
1071 }
1072 ActivateView (aNewViewName);
1073 }
1074 else
1075 {
1076 Handle(V3d_View) anEmptyView;
1077#if defined(_WIN32) || defined(__WIN32__)
1078 Handle(WNT_Window) anEmptyWindow;
1079#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1080 Handle(Cocoa_Window) anEmptyWindow;
1081#else
1082 Handle(Xw_Window) anEmptyWindow;
1083#endif
1084 VT_GetWindow() = anEmptyWindow;
1085 ViewerTest::CurrentView (anEmptyView);
1086 if (isContextRemoved)
1087 {
1088 Handle(AIS_InteractiveContext) anEmptyContext;
1089 ViewerTest::SetAISContext(anEmptyContext);
1090 }
1091 }
1092 }
1093
1094 // Delete view
1095 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1096 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1097
1098 // Remove view resources
1099 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1100 ViewerTest_myViews.UnBind1(theViewName);
1101 aView->Remove();
1102
1103#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1104 XFlush (GetDisplayConnection()->GetDisplay());
1105#endif
1106
1107 // Keep context opened only if the closed view is last to avoid
1108 // unused empty contexts
1109 if (!aCurrentContext.IsNull())
1110 {
1111 // Check if there are more difined views in the viewer
1112 aCurrentContext->CurrentViewer()->InitDefinedViews();
1113 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1114 {
1115 // Remove driver if there is no viewers that use it
1116 Standard_Boolean isRemoveDriver = Standard_True;
1117 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1118 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1119 {
1120 if (aCurrentContext != anIter.Key2() &&
1121 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1122 {
1123 isRemoveDriver = Standard_False;
1124 break;
1125 }
1126 }
1127 if(isRemoveDriver)
1128 {
1129 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1130 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1131 #if TCL_MAJOR_VERSION < 8
1132 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1133 #else
1134 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1135 #endif
1136 #endif
1137 }
1138
1139 ViewerTest_myContexts.UnBind2(aCurrentContext);
1140 }
1141 }
1142 cout << "3D View - " << theViewName << " was deleted.\n";
1143
1144}
1145
1146//==============================================================================
1147//function : VClose
1148//purpose : Remove the view defined by its name
1149//==============================================================================
1150
d0cc1cb7 1151static int VClose (Draw_Interpretor& /*theDi*/,
1152 Standard_Integer theArgsNb,
1153 const char** theArgVec)
18d715bd 1154{
18d715bd 1155 NCollection_List<TCollection_AsciiString> aViewList;
d0cc1cb7 1156 if (theArgsNb > 1)
18d715bd 1157 {
d0cc1cb7 1158 TCollection_AsciiString anArg (theArgVec[1]);
1159 anArg.UpperCase();
1160 if (anArg.IsEqual ("ALL")
1161 || anArg.IsEqual ("*"))
1162 {
1163 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1164 anIter.More(); anIter.Next())
1165 {
1166 aViewList.Append (anIter.Key1());
1167 }
1168 if (aViewList.IsEmpty())
1169 {
1170 std::cout << "No view to close\n";
1171 return 0;
1172 }
1173 }
1174 else
18d715bd 1175 {
d0cc1cb7 1176 ViewerTest_Names aViewName (theArgVec[1]);
1177 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1178 {
1179 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1180 return 1;
1181 }
1182 aViewList.Append (aViewName.GetViewName());
18d715bd 1183 }
1184 }
1185 else
1186 {
d0cc1cb7 1187 // close active view
1188 if (ViewerTest::CurrentView().IsNull())
1189 {
1190 std::cerr << "No active view!\n";
1191 return 1;
1192 }
1193 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
18d715bd 1194 }
1195
d0cc1cb7 1196 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
18d715bd 1197 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1198 anIter.More(); anIter.Next())
1199 {
d0cc1cb7 1200 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
18d715bd 1201 }
1202
1203 return 0;
1204}
1205
1206//==============================================================================
1207//function : VActivate
1208//purpose : Activate the view defined by its ID
1209//==============================================================================
1210
1211static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1212{
1213 if (theArgsNb > 2)
1214 {
1215 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1216 << "Usage: " << theArgVec[0] << " ViewID\n";
1217 return 1;
1218 }
1219 if(theArgsNb == 1)
1220 {
1221 theDi.Eval("vviewlist");
1222 return 0;
1223 }
1224
1225 TCollection_AsciiString aNameString(theArgVec[1]);
29cb310a 1226 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
18d715bd 1227 {
1228 TCollection_AsciiString aTitle("3D View - ");
1229 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1230 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1231 Handle(V3d_View) anEmptyView;
1232#if defined(_WIN32) || defined(__WIN32__)
1233 Handle(WNT_Window) anEmptyWindow;
1234#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1235 Handle(Cocoa_Window) anEmptyWindow;
1236#else
1237 Handle(Xw_Window) anEmptyWindow;
1238#endif
1239 VT_GetWindow() = anEmptyWindow;
1240 ViewerTest::CurrentView (anEmptyView);
1241 ViewerTest::ResetEventManager();
1242 theDi << theArgVec[0] << ": all views are inactive\n";
1243 return 0;
1244 }
1245
1246 ViewerTest_Names aViewNames(aNameString);
1247
1248 // Check if this view exists in the viewer with the driver
1249 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1250 {
1251 theDi << "Wrong view name\n";
1252 return 1;
1253 }
1254
1255 // Check if it is active already
1256 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1257 {
1258 theDi << theArgVec[0] << ": the view is active already\n";
1259 return 0;
1260 }
1261
1262 ActivateView (aViewNames.GetViewName());
1263 return 0;
1264}
1265
1266//==============================================================================
1267//function : VViewList
1268//purpose : Print current list of views per viewer and graphic driver ID
1269// shared between viewers
1270//==============================================================================
1271
1272static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1273{
1274 if (theArgsNb > 2)
1275 {
1276 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
29cb310a 1277 << "Usage: " << theArgVec[0] << " name";
18d715bd 1278 return 1;
1279 }
1280 if (ViewerTest_myContexts.Size() < 1)
1281 return 0;
1282
18d715bd 1283 Standard_Boolean isTreeView =
29cb310a 1284 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
18d715bd 1285
1286 if (isTreeView)
1287 theDi << theArgVec[0] <<":\n";
1288
1289 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1290 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1291 {
1292 if (isTreeView)
1293 theDi << aDriverIter.Key1() << ":\n";
1294
1295 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1296 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1297 {
1298 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1299 {
1300 if (isTreeView)
1301 {
1302 TCollection_AsciiString aContextName(aContextIter.Key1());
1303 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1304 }
1305
1306 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1307 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1308 {
1309 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1310 {
1311 TCollection_AsciiString aViewName(aViewIter.Key1());
1312 if (isTreeView)
1313 {
1314 if (aViewIter.Value() == ViewerTest::CurrentView())
1315 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1316 else
1317 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1318 }
1319 else
1320 {
1321 theDi << aViewName << " ";
1322 }
1323 }
1324 }
1325 }
1326 }
1327 }
1328 return 0;
1329}
1330
7fd59977 1331//==============================================================================
4fe56619 1332//function : VT_ProcessKeyPress
7fd59977 1333//purpose : Handle KeyPress event from a CString
1334//==============================================================================
4fe56619 1335void VT_ProcessKeyPress (const char* buf_ret)
7fd59977 1336{
1337 //cout << "KeyPress" << endl;
1338 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1339 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1340 // Letter in alphabetic order
1341
b514beda 1342 if (!strcasecmp (buf_ret, "A"))
1343 {
7fd59977 1344 // AXO
1345 aView->SetProj(V3d_XposYnegZpos);
1346 }
b514beda 1347 else if (!strcasecmp (buf_ret, "D"))
1348 {
7fd59977 1349 // Reset
1350 aView->Reset();
1351 }
b514beda 1352 else if (!strcasecmp (buf_ret, "F"))
1353 {
7fd59977 1354 // FitAll
1355 if (aNisView.IsNull())
1356 aView->FitAll();
1357 else
1358 aNisView->FitAll3d();
1359 }
b514beda 1360 else if (!strcasecmp (buf_ret, "H"))
1361 {
7fd59977 1362 // HLR
1363 cout << "HLR" << endl;
de75ed09 1364 aView->SetComputedMode (!aView->ComputedMode());
1365 MyHLRIsOn = aView->ComputedMode();
7fd59977 1366 }
b514beda 1367 else if (!strcasecmp (buf_ret, "P"))
1368 {
0a768f56 1369 // Type of HLR
1370 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1371 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1372 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1373 else
1374 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1375 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1376 {
1377 AIS_ListOfInteractive aListOfShapes;
1378 aContext->DisplayedObjects(aListOfShapes);
1379 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1380 anIter.More(); anIter.Next())
1381 {
1382 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1383 if (aShape.IsNull())
1384 continue;
1385 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1386 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1387 else
1388 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
36132a2e 1389 aContext->Redisplay (aShape, Standard_False);
0a768f56 1390 }
1391 }
1392 else
1393 {
1394 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1395 {
1396 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1397 if (aShape.IsNull())
1398 continue;
1399 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1400 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1401 else
1402 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
36132a2e 1403 aContext->Redisplay (aShape, Standard_False);
0a768f56 1404 }
1405 }
1406
1407 aContext->UpdateCurrentViewer();
4269bd1b 1408
0a768f56 1409 }
b514beda 1410 else if (!strcasecmp (buf_ret, "S"))
1411 {
1412 std::cout << "setup Shaded display mode" << std::endl;
4fe56619 1413
7fd59977 1414 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1415 if(Ctx->NbCurrents()==0 ||
1416 Ctx->NbSelected()==0)
1417 Ctx->SetDisplayMode(AIS_Shaded);
1418 else{
1419 if(Ctx->HasOpenedContext()){
1420 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1421 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1422 }
1423 else{
1424 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1425 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1426 }
1427 Ctx->UpdateCurrentViewer();
1428 }
1429 }
b514beda 1430 else if (!strcasecmp (buf_ret, "U"))
1431 {
41811896 1432 // Unset display mode
b514beda 1433 std::cout << "reset display mode to defaults" << std::endl;
4fe56619 1434
7fd59977 1435 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1436 if(Ctx->NbCurrents()==0 ||
1437 Ctx->NbSelected()==0)
1438 Ctx->SetDisplayMode(AIS_WireFrame);
1439 else{
1440 if(Ctx->HasOpenedContext()){
1441 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1442 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1443 }
1444 else{
1445 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1446 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1447 }
1448 Ctx->UpdateCurrentViewer();
1449 }
1450
1451 }
b514beda 1452 else if (!strcasecmp (buf_ret, "T"))
1453 {
7fd59977 1454 // Top
1455 aView->SetProj(V3d_Zpos);
1456 }
b514beda 1457 else if (!strcasecmp (buf_ret, "B"))
1458 {
41811896 1459 // Bottom
7fd59977 1460 aView->SetProj(V3d_Zneg);
1461 }
b514beda 1462 else if (!strcasecmp (buf_ret, "L"))
1463 {
41811896 1464 // Left
7fd59977 1465 aView->SetProj(V3d_Xneg);
1466 }
b514beda 1467 else if (!strcasecmp (buf_ret, "R"))
1468 {
41811896 1469 // Right
7fd59977 1470 aView->SetProj(V3d_Xpos);
1471 }
b514beda 1472 else if (!strcasecmp (buf_ret, "W"))
1473 {
1474 std::cout << "setup WireFrame display mode" << std::endl;
7fd59977 1475 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1476 if(Ctx->NbCurrents()==0 ||
1477 Ctx->NbSelected()==0)
1478 Ctx->SetDisplayMode(AIS_WireFrame);
1479 else{
1480 if(Ctx->HasOpenedContext()){
1481 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1482 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1483 }
1484 else{
1485 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1486 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1487 }
1488 Ctx->UpdateCurrentViewer();
1489 }
1490 }
b514beda 1491 else if (!strcasecmp (buf_ret, "Z"))
1492 {
7fd59977 1493 // ZCLIP
7fd59977 1494 if ( ZClipIsOn ) {
1495 cout << "ZClipping OFF" << endl;
1496 ZClipIsOn = 0;
1497
1498 aView->SetZClippingType(V3d_OFF);
1499 aView->Redraw();
1500 }
1501 else {
1502 cout << "ZClipping ON" << endl;
1503 ZClipIsOn = 1;
1504
1505 aView->SetZClippingType(V3d_FRONT);
1506 aView->Redraw();
1507 }
1508 }
b514beda 1509 else if (!strcasecmp (buf_ret, ","))
1510 {
7fd59977 1511 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
7fd59977 1512 }
b514beda 1513 else if (!strcasecmp (buf_ret, "."))
1514 {
7fd59977 1515 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1516 }
b514beda 1517 else if (*buf_ret == THE_KEY_DELETE)
1518 {
1519 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1520 if (!aCtx.IsNull()
1521 && aCtx->NbCurrents() > 0
1522 && aCtx->NbSelected() > 0)
1523 {
1524 Draw_Interprete ("verase");
1525 }
1526 }
1527 else
1528 {
1529 // Number
91322f44 1530 Standard_Integer Num = Draw::Atoi(buf_ret);
7fd59977 1531 if(Num>=0 && Num<=7)
1532 ViewerTest::StandardModeActivation(Num);
1533 }
1534}
1535
1536//==============================================================================
4fe56619 1537//function : VT_ProcessExpose
7fd59977 1538//purpose : Redraw the View on an Expose Event
1539//==============================================================================
4fe56619 1540void VT_ProcessExpose()
1541{
1542 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1543 if (!aView3d.IsNull())
1544 {
1545 aView3d->Redraw();
1546 }
7fd59977 1547}
1548
1549//==============================================================================
4fe56619 1550//function : VT_ProcessConfigure
7fd59977 1551//purpose : Resize the View on an Configure Event
1552//==============================================================================
4fe56619 1553void VT_ProcessConfigure()
7fd59977 1554{
4fe56619 1555 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1556 if (aView3d.IsNull())
1557 {
1558 return;
1559 }
1560
1561 aView3d->MustBeResized();
1562 aView3d->Update();
1563 aView3d->Redraw();
7fd59977 1564}
1565
1566//==============================================================================
4fe56619 1567//function : VT_ProcessButton1Press
7fd59977 1568//purpose : Picking
1569//==============================================================================
e79a94b9 1570Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1571 const char** theArgVec,
1572 Standard_Boolean theToPick,
1573 Standard_Boolean theIsShift)
7fd59977 1574{
e79a94b9 1575 if (theToPick)
1576 {
7fd59977 1577 Standard_Real X, Y, Z;
e79a94b9 1578 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
7fd59977 1579
e79a94b9 1580 Draw::Set (theArgVec[1], X);
1581 Draw::Set (theArgVec[2], Y);
1582 Draw::Set (theArgVec[3], Z);
1583 }
7fd59977 1584
e79a94b9 1585 if (theIsShift)
1586 {
1587 ViewerTest::CurrentEventManager()->ShiftSelect();
1588 }
7fd59977 1589 else
e79a94b9 1590 {
1591 ViewerTest::CurrentEventManager()->Select();
1592 }
7fd59977 1593
e79a94b9 1594 return Standard_False;
7fd59977 1595}
1596
1597//==============================================================================
4fe56619 1598//function : VT_ProcessButton1Release
1599//purpose : End selecting
7fd59977 1600//==============================================================================
4fe56619 1601void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1602{
1603 if (IsDragged)
1604 {
1605 IsDragged = Standard_False;
1606 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1607 if (theIsShift)
1608 {
1609 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1610 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1611 }
1612 else
1613 {
1614 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1615 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1616 }
1617 }
1618}
7fd59977 1619
4fe56619 1620//==============================================================================
1621//function : VT_ProcessButton3Press
1622//purpose : Start Rotation
1623//==============================================================================
1624void VT_ProcessButton3Press()
1625{
7fd59977 1626 Start_Rot = 1;
de75ed09 1627 if (MyHLRIsOn)
1628 {
1629 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1630 }
7fd59977 1631 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
7fd59977 1632}
4fe56619 1633
7fd59977 1634//==============================================================================
4fe56619 1635//function : VT_ProcessButton3Release
1636//purpose : End rotation
7fd59977 1637//==============================================================================
4fe56619 1638void VT_ProcessButton3Release()
1639{
1640 if (Start_Rot)
1641 {
7fd59977 1642 Start_Rot = 0;
de75ed09 1643 if (MyHLRIsOn)
1644 {
1645 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1646 }
7fd59977 1647 }
7fd59977 1648}
1649
1650//==============================================================================
1651//function : ProcessZClipMotion
1652//purpose : Zoom
1653//==============================================================================
1654
1655void ProcessZClipMotion()
1656{
1657 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1658 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1659 static Standard_Real CurZPos = 0.;
1660
1661 //Quantity_Length VDX, VDY;
1662 //a3DView->Size(VDX,VDY);
1663 //Standard_Real VDZ = a3DView->ZSize();
1664 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1665
1666 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1667
1668 // Front = Depth + width/2.
1669 Standard_Real D = 0.5;
1670 Standard_Real W = 0.1;
1671
1672 CurZPos += (dx);
1673
1674 D += CurZPos;
1675
1676 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1677
1678 a3DView->SetZClippingType(V3d_OFF);
1679 a3DView->SetZClippingDepth(D);
1680 a3DView->SetZClippingWidth(W);
1681 a3DView->SetZClippingType(V3d_FRONT);
1682
1683 a3DView->Redraw();
1684
1685 X_ButtonPress = X_Motion;
1686 Y_ButtonPress = Y_Motion;
1687 }
1688}
1689
1690//==============================================================================
1691//function : ProcessControlButton1Motion
1692//purpose : Zoom
1693//==============================================================================
1694
900f7229 1695#if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 1696static void ProcessControlButton1Motion()
1697{
1698 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1699
1700 X_ButtonPress = X_Motion;
1701 Y_ButtonPress = Y_Motion;
1702}
900f7229 1703#endif
7fd59977 1704
1705//==============================================================================
4fe56619 1706//function : VT_ProcessControlButton2Motion
1707//purpose : Panning
7fd59977 1708//==============================================================================
4fe56619 1709void VT_ProcessControlButton2Motion()
7fd59977 1710{
197ac94e 1711 Standard_Integer aDx = X_Motion - X_ButtonPress;
1712 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
7fd59977 1713
197ac94e 1714 aDy = -aDy; // Xwindow Y axis is from top to Bottom
7fd59977 1715
197ac94e 1716 ViewerTest::CurrentView()->Pan (aDx, aDy);
7fd59977 1717
1718 X_ButtonPress = X_Motion;
1719 Y_ButtonPress = Y_Motion;
1720}
1721
1722//==============================================================================
4fe56619 1723//function : VT_ProcessControlButton3Motion
7fd59977 1724//purpose : Rotation
1725//==============================================================================
4fe56619 1726void VT_ProcessControlButton3Motion()
7fd59977 1727{
4fe56619 1728 if (Start_Rot)
1729 {
1730 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1731 }
7fd59977 1732}
1733
1734//==============================================================================
4fe56619 1735//function : VT_ProcessMotion
1736//purpose :
7fd59977 1737//==============================================================================
4fe56619 1738void VT_ProcessMotion()
7fd59977 1739{
1740 //pre-hilights detected objects at mouse position
1741
1742 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1743 EM->MoveTo(X_Motion, Y_Motion);
1744}
1745
1746
1747void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1748{
1749 Xpix = X_Motion;Ypix=Y_Motion;
1750}
1751
44b8f2d6 1752//==============================================================================
1753//function : ViewProject: implements VAxo, VTop, VLeft, ...
1754//purpose : Switches to an axonometric, top, left and other views
1755//==============================================================================
1756
1757static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1758{
4fe56619 1759 if ( ViewerTest::CurrentView().IsNull() )
44b8f2d6 1760 {
1761 di<<"Call vinit before this command, please"<<"\n";
1762 return 1;
1763 }
1764
1765 ViewerTest::CurrentView()->SetProj(ori);
1766 return 0;
1767}
1768
7fd59977 1769//==============================================================================
1770//function : VAxo
1771//purpose : Switch to an Axonometric view
1772//Draw arg : No args
1773//==============================================================================
1774
1775static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
44b8f2d6 1776{
1777 return ViewProject(di, V3d_XposYnegZpos);
7fd59977 1778}
1779
1780//==============================================================================
1781//function : VTop
1782//purpose : Switch to a Top View
1783//Draw arg : No args
1784//==============================================================================
1785
1786static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1787{
44b8f2d6 1788 return ViewProject(di, V3d_Zpos);
1789}
7fd59977 1790
44b8f2d6 1791//==============================================================================
1792//function : VBottom
1793//purpose : Switch to a Bottom View
1794//Draw arg : No args
1795//==============================================================================
7fd59977 1796
44b8f2d6 1797static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1798{
1799 return ViewProject(di, V3d_Zneg);
1800}
7fd59977 1801
44b8f2d6 1802//==============================================================================
1803//function : VLeft
1804//purpose : Switch to a Left View
1805//Draw arg : No args
1806//==============================================================================
1807
1808static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1809{
1810 return ViewProject(di, V3d_Ypos);
1811}
1812
1813//==============================================================================
1814//function : VRight
1815//purpose : Switch to a Right View
1816//Draw arg : No args
1817//==============================================================================
1818
1819static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1820{
1821 return ViewProject(di, V3d_Yneg);
1822}
7fd59977 1823
44b8f2d6 1824//==============================================================================
1825//function : VFront
1826//purpose : Switch to a Front View
1827//Draw arg : No args
1828//==============================================================================
1829
1830static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1831{
1832 return ViewProject(di, V3d_Xpos);
1833}
1834
1835//==============================================================================
1836//function : VBack
1837//purpose : Switch to a Back View
1838//Draw arg : No args
1839//==============================================================================
1840
1841static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1842{
1843 return ViewProject(di, V3d_Xneg);
7fd59977 1844}
1845
1846//==============================================================================
1847//function : VHelp
1848//purpose : Dsiplay help on viewer Keyboead and mouse commands
1849//Draw arg : No args
1850//==============================================================================
1851
1852static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1853{
1854
1855 di << "Q : Quit the application" << "\n";
1856
1857 di << "========================="<<"\n";
1858 di << "F : FitAll" << "\n";
1859 di << "T : TopView" << "\n";
41811896 1860 di << "B : BottomView" << "\n";
1861 di << "R : RightView" << "\n";
1862 di << "L : LeftView" << "\n";
7fd59977 1863 di << "A : AxonometricView" << "\n";
41811896 1864 di << "D : ResetView" << "\n";
7fd59977 1865
1866 di << "========================="<<"\n";
1867 di << "S : Shading" << "\n";
1868 di << "W : Wireframe" << "\n";
1869 di << "H : HidelLineRemoval" << "\n";
41811896 1870 di << "U : Unset display mode" << "\n";
b514beda 1871 di << "Delete : Remove selection from viewer" << "\n";
7fd59977 1872
1873 di << "========================="<<"\n";
1874 di << "Selection mode "<<"\n";
1875 di << "0 : Shape" <<"\n";
1876 di << "1 : Vertex" <<"\n";
1877 di << "2 : Edge" <<"\n";
1878 di << "3 : Wire" <<"\n";
1879 di << "4 : Face" <<"\n";
1880 di << "5 : Shell" <<"\n";
1881 di << "6 : Solid" <<"\n";
1882 di << "7 : Compound" <<"\n";
1883
41811896 1884 di << "========================="<<"\n";
1885 di << "Z : Switch Z clipping On/Off" << "\n";
1886 di << ", : Hilight next detected" << "\n";
1887 di << ". : Hilight previous detected" << "\n";
7fd59977 1888
1889 return 0;
1890}
1891
7fd59977 1892#ifdef WNT
1893
1894static Standard_Boolean Ppick = 0;
1895static Standard_Integer Pargc = 0;
1896static const char** Pargv = NULL;
1897
1898
1899static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1900 UINT Msg,
1901 WPARAM wParam,
1902 LPARAM lParam )
1903{
18d715bd 1904 if (!ViewerTest_myViews.IsEmpty()) {
7fd59977 1905
1906 WPARAM fwKeys = wParam;
1907
1908 switch( Msg ) {
18d715bd 1909 case WM_CLOSE:
1910 {
1911 // Delete view from map of views
1912 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1913 return 0;
1914 }
1915 break;
1916 case WM_ACTIVATE:
1917 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1918 || ViewerTest::CurrentView().IsNull())
1919 {
1920 // Activate inactive window
1921 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1922 {
1923 ActivateView (FindViewIdByWindowHandle(hwnd));
1924 }
1925 }
1926 break;
7fd59977 1927 case WM_LBUTTONUP:
8abada55 1928 if (!DragFirst)
7fd59977 1929 {
1930 HDC hdc = GetDC( hwnd );
7fd59977 1931 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1932 SetROP2( hdc, R2_NOT );
4fe56619 1933 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 1934 ReleaseDC( hwnd, hdc );
8abada55 1935 VT_ProcessButton1Release (fwKeys & MK_SHIFT);
7fd59977 1936 }
8abada55 1937 IsDragged = Standard_False;
7fd59977 1938 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1939
1940 case WM_LBUTTONDOWN:
1941 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1942 {
1943 IsDragged = Standard_True;
1944 DragFirst = Standard_True;
4fe56619 1945 X_ButtonPress = LOWORD(lParam);
1946 Y_ButtonPress = HIWORD(lParam);
7fd59977 1947 }
1948 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1949
1950 break;
1951
1952 case WM_MOUSEMOVE:
1953 if( IsDragged )
1954 {
1955 HDC hdc = GetDC( hwnd );
1956
1957 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1958 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1959 SetROP2( hdc, R2_NOT );
1960
1961 if( !DragFirst )
4fe56619 1962 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 1963
1964 DragFirst = Standard_False;
4fe56619 1965 X_Motion = LOWORD(lParam);
1966 Y_Motion = HIWORD(lParam);
7fd59977 1967
4fe56619 1968 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 1969
1970 SelectObject( hdc, anObj );
1971
1972 ReleaseDC( hwnd, hdc );
1973 }
1974 else
1975 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1976 break;
1977
1978 default:
1979 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1980 }
1981 return 0;
1982 }
1983 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1984}
1985
1986
1987static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1988 UINT Msg,
1989 WPARAM wParam,
1990 LPARAM lParam )
1991{
7fd59977 1992 static int Up = 1;
1993
1994 if ( !ViewerTest::CurrentView().IsNull() ) {
1995 PAINTSTRUCT ps;
1996
1997 switch( Msg ) {
7fd59977 1998 case WM_PAINT:
7fd59977 1999 BeginPaint(hwnd, &ps);
2000 EndPaint(hwnd, &ps);
4fe56619 2001 VT_ProcessExpose();
7fd59977 2002 break;
2003
2004 case WM_SIZE:
4fe56619 2005 VT_ProcessConfigure();
7fd59977 2006 break;
2007
2008 case WM_KEYDOWN:
4fe56619 2009 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2010 {
7fd59977 2011 char c[2];
2012 c[0] = (char) wParam;
2013 c[1] = '\0';
b514beda 2014 if (wParam == VK_DELETE)
2015 {
2016 c[0] = THE_KEY_DELETE;
2017 }
4ca4bbe8 2018 // comma
2019 else if (wParam == VK_OEM_COMMA)
2020 {
2021 c[0] = ',';
2022 }
2023 // dot
2024 else if (wParam == VK_OEM_PERIOD)
2025 {
2026 c[0] = '.';
2027 }
4fe56619 2028 VT_ProcessKeyPress (c);
7fd59977 2029 }
2030 break;
2031
2032 case WM_LBUTTONUP:
2033 case WM_MBUTTONUP:
2034 case WM_RBUTTONUP:
7fd59977 2035 Up = 1;
4fe56619 2036 VT_ProcessButton3Release();
7fd59977 2037 break;
2038
2039 case WM_LBUTTONDOWN:
2040 case WM_MBUTTONDOWN:
2041 case WM_RBUTTONDOWN:
2042 {
7fd59977 2043 WPARAM fwKeys = wParam;
2044
2045 Up = 0;
2046
2047 X_ButtonPress = LOWORD(lParam);
2048 Y_ButtonPress = HIWORD(lParam);
2049
4fe56619 2050 if (Msg == WM_LBUTTONDOWN)
2051 {
2052 if (fwKeys & MK_CONTROL)
2053 {
2054 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2055 }
2056 else
2057 {
2058 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2059 }
7fd59977 2060 }
4fe56619 2061 else if (Msg == WM_RBUTTONDOWN)
2062 {
7fd59977 2063 // Start rotation
4fe56619 2064 VT_ProcessButton3Press();
7fd59977 2065 }
2066 }
2067 break;
2068
2069 case WM_MOUSEMOVE:
2070 {
2071 //cout << "\t WM_MOUSEMOVE" << endl;
2072 WPARAM fwKeys = wParam;
2073 X_Motion = LOWORD(lParam);
2074 Y_Motion = HIWORD(lParam);
2075
2076 if ( Up &&
2077 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2078 Up = 0;
2079 X_ButtonPress = LOWORD(lParam);
2080 Y_ButtonPress = HIWORD(lParam);
2081
2082 if ( fwKeys & MK_RBUTTON ) {
2083 // Start rotation
4fe56619 2084 VT_ProcessButton3Press();
7fd59977 2085 }
2086 }
2087
2088 if ( fwKeys & MK_CONTROL ) {
2089 if ( fwKeys & MK_LBUTTON ) {
2090 ProcessControlButton1Motion();
2091 }
2092 else if ( fwKeys & MK_MBUTTON ||
2093 ((fwKeys&MK_LBUTTON) &&
2094 (fwKeys&MK_RBUTTON) ) ){
4fe56619 2095 VT_ProcessControlButton2Motion();
7fd59977 2096 }
2097 else if ( fwKeys & MK_RBUTTON ) {
4fe56619 2098 VT_ProcessControlButton3Motion();
7fd59977 2099 }
2100 }
2101#ifdef BUG
2102 else if ( fwKeys & MK_SHIFT ) {
2103 if ( fwKeys & MK_MBUTTON ||
2104 ((fwKeys&MK_LBUTTON) &&
2105 (fwKeys&MK_RBUTTON) ) ) {
2106 cout << "ProcessZClipMotion()" << endl;
2107 ProcessZClipMotion();
2108 }
2109 }
2110#endif
08398024 2111 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2112 {
4fe56619 2113 if ((fwKeys & MK_MBUTTON
2114 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2115 {
7fd59977 2116 ProcessZClipMotion();
2117 }
4fe56619 2118 else
2119 {
2120 VT_ProcessMotion();
7fd59977 2121 }
08398024 2122 }
7fd59977 2123 }
2124 break;
2125
2126 default:
2127 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2128 }
2129 return 0L;
2130 }
2131
2132 return DefWindowProc( hwnd, Msg, wParam, lParam );
2133}
2134
2135
2136
2137
2138//==============================================================================
2139//function : ViewerMainLoop
2140//purpose : Get a Event on the view and dispatch it
2141//==============================================================================
2142
2143
8263fcd3 2144int ViewerMainLoop(Standard_Integer argc, const char** argv)
7fd59977 2145{
7fd59977 2146 Ppick = (argc > 0)? 1 : 0;
2147 Pargc = argc;
2148 Pargv = argv;
2149
2150 if ( Ppick ) {
2151 MSG msg;
2152 msg.wParam = 1;
2153
2154 cout << "Start picking" << endl;
2155
7fd59977 2156 while ( Ppick == 1 ) {
4fe56619 2157 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
7fd59977 2158 if (GetMessage(&msg, NULL, 0, 0) ) {
2159 TranslateMessage(&msg);
2160 DispatchMessage(&msg);
2161 }
2162 }
2163
2164 cout << "Picking done" << endl;
2165 }
2166
2167 return Ppick;
2168}
2169
4fe56619 2170#elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 2171
2172int min( int a, int b )
2173{
2174 if( a<b )
2175 return a;
2176 else
2177 return b;
2178}
2179
2180int max( int a, int b )
2181{
2182 if( a>b )
2183 return a;
2184 else
2185 return b;
2186}
2187
2188int ViewerMainLoop(Standard_Integer argc, const char** argv)
2189
4269bd1b 2190{
18d715bd 2191 static XEvent aReport;
2192 Standard_Boolean pick = argc > 0;
2193 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2194 XNextEvent (aDisplay, &aReport);
7fd59977 2195
18d715bd 2196 // Handle event for the chosen display connection
2197 switch (aReport.type) {
2198 case ClientMessage:
2199 {
eb1ebea4 2200 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
18d715bd 2201 {
2202 // Close the window
2203 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2204 }
2205 }
2206 return 0;
2207 case FocusIn:
2208 {
2209 // Activate inactive view
2210 Window aWindow = GetWindowHandle(VT_GetWindow());
2211 if(aWindow != aReport.xfocus.window)
2212 {
2213 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2214 }
2215 }
2216 break;
7fd59977 2217 case Expose:
2218 {
4fe56619 2219 VT_ProcessExpose();
7fd59977 2220 }
2221 break;
2222 case ConfigureNotify:
2223 {
4fe56619 2224 VT_ProcessConfigure();
7fd59977 2225 }
2226 break;
2227 case KeyPress:
2228 {
2229
2230 KeySym ks_ret ;
2231 char buf_ret[11] ;
2232 int ret_len ;
2233 XComposeStatus status_in_out;
2234
18d715bd 2235 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
7fd59977 2236 (char *) buf_ret , 10 ,
2237 &ks_ret , &status_in_out ) ;
2238
2239
2240 buf_ret[ret_len] = '\0' ;
2241
4fe56619 2242 if (ret_len)
2243 {
2244 VT_ProcessKeyPress (buf_ret);
7fd59977 2245 }
2246 }
2247 break;
2248 case ButtonPress:
7fd59977 2249 {
18d715bd 2250 X_ButtonPress = aReport.xbutton.x;
2251 Y_ButtonPress = aReport.xbutton.y;
7fd59977 2252
18d715bd 2253 if (aReport.xbutton.button == Button1)
4fe56619 2254 {
18d715bd 2255 if (aReport.xbutton.state & ControlMask)
4fe56619 2256 {
18d715bd 2257 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
4fe56619 2258 }
7fd59977 2259 else
2260 {
2261 IsDragged = Standard_True;
7fd59977 2262 DragFirst = Standard_True;
2263 }
4fe56619 2264 }
18d715bd 2265 else if (aReport.xbutton.button == Button3)
4fe56619 2266 {
7fd59977 2267 // Start rotation
4fe56619 2268 VT_ProcessButton3Press();
2269 }
7fd59977 2270 }
2271 break;
2272 case ButtonRelease:
2273 {
7fd59977 2274 if( IsDragged )
2275 {
2276 if( !DragFirst )
2277 {
2278 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
18d715bd 2279 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2280 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
7fd59977 2281 }
2282
2283 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2284 if( aContext.IsNull() )
2285 {
2286 cout << "The context is null. Please use vinit before createmesh" << endl;
2287 return 0;
2288 }
2289
18d715bd 2290 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2291 if( aReport.xbutton.button==1 )
7fd59977 2292 if( DragFirst )
2293 if( ShiftPressed )
2294 {
2295 aContext->ShiftSelect();
7fd59977 2296 }
2297 else
2298 {
2299 aContext->Select();
7fd59977 2300 }
2301 else
2302 if( ShiftPressed )
2303 {
4fe56619 2304 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2305 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
7fd59977 2306 ViewerTest::CurrentView());
7fd59977 2307 }
2308 else
2309 {
4fe56619 2310 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2311 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
7fd59977 2312 ViewerTest::CurrentView() );
7fd59977 2313 }
2314 else
4fe56619 2315 VT_ProcessButton3Release();
7fd59977 2316
2317 IsDragged = Standard_False;
2318 }
2319 else
4fe56619 2320 VT_ProcessButton3Release();
7fd59977 2321 }
2322 break;
2323 case MotionNotify:
2324 {
08398024 2325 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2326 {
2327 break;
2328 }
7fd59977 2329 if( IsDragged )
2330 {
2331 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
18d715bd 2332 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2333 XSetFunction( aDisplay, gc, GXinvert );
7fd59977 2334
2335 if( !DragFirst )
18d715bd 2336 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
7fd59977 2337
18d715bd 2338 X_Motion = aReport.xmotion.x;
2339 Y_Motion = aReport.xmotion.y;
7fd59977 2340 DragFirst = Standard_False;
2341
18d715bd 2342 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
7fd59977 2343 }
2344 else
2345 {
18d715bd 2346 X_Motion = aReport.xmotion.x;
2347 Y_Motion = aReport.xmotion.y;
7fd59977 2348
18d715bd 2349 // remove all the ButtonMotionMaskr
2350 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
7fd59977 2351
18d715bd 2352 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
7fd59977 2353 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2354
2355 Quantity_Length VDX, VDY;
2356
2357 ViewerTest::CurrentView()->Size(VDX,VDY);
2358 Standard_Real VDZ =0 ;
2359 VDZ = ViewerTest::CurrentView()->ZSize();
2360
7fd59977 2361 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2362
2363 Quantity_Length dx = 0 ;
2364 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2365
2366 cout << dx << endl;
2367
2368 dx = dx / VDX * VDZ;
2369
2370 cout << dx << endl;
2371
7fd59977 2372 ViewerTest::CurrentView()->Redraw();
2373 }
2374 }
2375
18d715bd 2376 if ( aReport.xmotion.state & ControlMask ) {
2377 if ( aReport.xmotion.state & Button1Mask ) {
7fd59977 2378 ProcessControlButton1Motion();
2379 }
18d715bd 2380 else if ( aReport.xmotion.state & Button2Mask ) {
4fe56619 2381 VT_ProcessControlButton2Motion();
7fd59977 2382 }
18d715bd 2383 else if ( aReport.xmotion.state & Button3Mask ) {
4fe56619 2384 VT_ProcessControlButton3Motion();
7fd59977 2385 }
2386 }
4fe56619 2387 else
2388 {
2389 VT_ProcessMotion();
7fd59977 2390 }
2391 }
2392 }
2393 break;
2394}
7fd59977 2395return pick;
2396}
2397
2398//==============================================================================
2399//function : VProcessEvents
2400//purpose : call by Tk_CreateFileHandler() to be able to manage the
2401// event in the Viewer window
2402//==============================================================================
2403
2404static void VProcessEvents(ClientData,int)
2405{
18d715bd 2406 NCollection_Vector<int> anEventNumbers;
2407 // Get number of messages from every display
2408 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2409 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2410 {
2411 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
4269bd1b 2412 }
18d715bd 2413 // Handle events for every display
2414 int anEventIter = 0;
2415 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2416 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2417 {
4269bd1b 2418 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
18d715bd 2419 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2420 {
2421 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2422 int anEventResult = ViewerMainLoop( 0, NULL);
2423 // If window is closed or context was not found finish current event processing loop
2424 if (!anEventResult)
2425 return;
2426 }
7fd59977 2427 }
4269bd1b 2428
18d715bd 2429 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
4269bd1b 2430
7fd59977 2431}
2432#endif
2433
2434//==============================================================================
2435//function : OSWindowSetup
2436//purpose : Setup for the X11 window to be able to cath the event
2437//==============================================================================
2438
2439
2440static void OSWindowSetup()
2441{
4fe56619 2442#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 2443 // X11
2444
2445 Window window = VT_GetWindow()->XWindow();
18d715bd 2446 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2447 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2448 XSynchronize(aDisplay, 1);
7fd59977 2449
2450 // X11 : For keyboard on SUN
2451 XWMHints wmhints;
2452 wmhints.flags = InputHint;
2453 wmhints.input = 1;
2454
18d715bd 2455 XSetWMHints( aDisplay, window, &wmhints);
7fd59977 2456
18d715bd 2457 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
7fd59977 2458 ButtonPressMask | ButtonReleaseMask |
2459 StructureNotifyMask |
2460 PointerMotionMask |
2461 Button1MotionMask | Button2MotionMask |
18d715bd 2462 Button3MotionMask | FocusChangeMask
7fd59977 2463 );
18d715bd 2464 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2465 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
7fd59977 2466
18d715bd 2467 XSynchronize(aDisplay, 0);
7fd59977 2468
2469#else
2470 // WNT
2471#endif
2472
2473}
2474
2475
2476//==============================================================================
2477//function : VFit
2478
2479//purpose : Fitall, no DRAW arguments
2480//Draw arg : No args
2481//==============================================================================
2482
2483static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2484{
2485 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2486 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2487 if (V.IsNull() == Standard_False) {
2488 V->FitAll3d();
2489 } else if (aView.IsNull() == Standard_False) {
2490 aView->FitAll();
2491 }
2492 return 0;
2493}
2494
6262a303 2495//=======================================================================
2496//function : VFitArea
2497//purpose : Fit view to show area located between two points
2498// : given in world 2D or 3D coordinates.
2499//=======================================================================
2500static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2501{
2502 Handle(V3d_View) aView = ViewerTest::CurrentView();
2503 if (aView.IsNull())
2504 {
2505 std::cerr << theArgVec[0] << "Error: No active view.\n";
2506 return 1;
2507 }
2508
2509 // Parse arguments.
2510 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2511 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2512
2513 if (theArgNb == 5)
2514 {
2515 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2516 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2517 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2518 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2519 }
2520 else if (theArgNb == 7)
2521 {
2522 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2523 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2524 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2525 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2526 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2527 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2528 }
2529 else
2530 {
2531 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2532 theDI.PrintHelp(theArgVec[0]);
2533 return 1;
2534 }
2535
2536 // Convert model coordinates to view space
2537 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2538 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2539 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2540
2541 // Determine fit area
2542 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2543 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2544
2545 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2546
2547 if (aDiagonal < Precision::Confusion())
2548 {
2549 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2550 return 1;
2551 }
2552
2553 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2554 return 0;
2555}
2556
7fd59977 2557//==============================================================================
2558//function : VZFit
2559//purpose : ZFitall, no DRAW arguments
2560//Draw arg : No args
2561//==============================================================================
197ac94e 2562static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 2563{
197ac94e 2564 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2565
2566 if (aCurrentView.IsNull())
2567 {
2568 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2569 return 1;
2570 }
2571
2572 if (theArgsNb == 1)
2573 {
6bc6a6fc 2574 aCurrentView->View()->ZFitAll();
197ac94e 2575 aCurrentView->Redraw();
2576 return 0;
2577 }
2578
2579 Standard_Real aScale = 1.0;
2580
2581 if (theArgsNb >= 2)
2582 {
2583 aScale = Draw::Atoi (theArgVec[1]);
2584 }
2585
6bc6a6fc 2586 aCurrentView->View()->ZFitAll (aScale);
197ac94e 2587 aCurrentView->Redraw();
7fd59977 2588
197ac94e 2589 return 0;
2590}
7fd59977 2591
197ac94e 2592//==============================================================================
2593//function : VRepaint
2594//purpose :
2595//==============================================================================
2596static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
7fd59977 2597{
2598 Handle(V3d_View) V = ViewerTest::CurrentView();
2599 if ( !V.IsNull() ) V->Redraw(); return 0;
2600}
2601
7fd59977 2602//==============================================================================
2603//function : VClear
2604//purpose : Remove all the object from the viewer
2605//Draw arg : No args
2606//==============================================================================
2607
2608static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2609{
2610 Handle(V3d_View) V = ViewerTest::CurrentView();
2611 if(!V.IsNull())
2612 ViewerTest::Clear();
2613 return 0;
2614}
2615
2616//==============================================================================
2617//function : VPick
2618//purpose :
2619//==============================================================================
2620
2621static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2622{ if (ViewerTest::CurrentView().IsNull() ) return 1;
2623
2624if ( argc < 4 ) {
2625 di << argv[0] << "Invalid number of arguments" << "\n";
2626 return 1;
2627}
2628
2629while (ViewerMainLoop( argc, argv)) {
2630}
2631
2632return 0;
2633}
2634
7fd59977 2635//==============================================================================
2636//function : VSetBg
2637//purpose : Load image as background
2638//==============================================================================
2639
2640static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2641{
2642 if (argc < 2 || argc > 3)
2643 {
2644 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
f8b2ed36 2645 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
7fd59977 2646 return 1;
2647 }
2648
2649 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2650 if(AISContext.IsNull())
2651 {
2652 di << "use 'vinit' command before " << argv[0] << "\n";
2653 return 1;
2654 }
2655
2656 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2657 if (argc == 3)
2658 {
2659 const char* szType = argv[2];
2660 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2661 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2662 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2663 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2664 else
2665 {
2666 di << "Wrong fill type : " << szType << "\n";
2667 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2668 return 1;
2669 }
2670 }
2671
2672 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2673 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2674
2675 return 0;
2676}
2677
f8b2ed36 2678//==============================================================================
2679//function : VSetBgMode
2680//purpose : Change background image fill type
2681//==============================================================================
2682
2683static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2684{
2685 if (argc != 2)
2686 {
2687 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2688 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2689 return 1;
2690 }
2691
2692 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2693 if(AISContext.IsNull())
2694 {
2695 di << "use 'vinit' command before " << argv[0] << "\n";
2696 return 1;
2697 }
1d47d8d0 2698 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2699 const char* szType = argv[1];
2700 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2701 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2702 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2703 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2704 else
f8b2ed36 2705 {
1d47d8d0 2706 di << "Wrong fill type : " << szType << "\n";
2707 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2708 return 1;
f8b2ed36 2709 }
f8b2ed36 2710 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2711 V3dView->SetBgImageStyle(aFillType, Standard_True);
f8b2ed36 2712 return 0;
2713}
2714
7fd59977 2715//==============================================================================
2716//function : VSetGradientBg
2717//purpose : Mount gradient background
2718//==============================================================================
2719static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2720{
2721 if (argc != 8 )
2722 {
2723 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2724 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2725 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2726 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2727 return 1;
2728 }
2729
2730 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2731 if(AISContext.IsNull())
2732 {
2733 di << "use 'vinit' command before " << argv[0] << "\n";
2734 return 1;
2735 }
2736 if (argc == 8)
2737 {
2738
91322f44 2739 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2740 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2741 Standard_Real B1 = Draw::Atof(argv[3])/255.;
7fd59977 2742 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2743
91322f44 2744 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2745 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2746 Standard_Real B2 = Draw::Atof(argv[6])/255.;
7fd59977 2747
2748 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
91322f44 2749 int aType = Draw::Atoi(argv[7]);
7fd59977 2750 if( aType < 0 || aType > 8 )
2751 {
2752 di << "Wrong fill type " << "\n";
2753 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2754 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2755 return 1;
2756 }
2757
2758 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2759
2760 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2761 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2762 }
2763
2764 return 0;
2765}
2766
f8b2ed36 2767//==============================================================================
2768//function : VSetGradientBgMode
2769//purpose : Change gradient background fill style
2770//==============================================================================
2771static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2772{
2773 if (argc != 2 )
2774 {
2775 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2776 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2777 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2778 return 1;
2779 }
2780
2781 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2782 if(AISContext.IsNull())
2783 {
2784 di << "use 'vinit' command before " << argv[0] << "\n";
2785 return 1;
2786 }
2787 if (argc == 2)
2788 {
91322f44 2789 int aType = Draw::Atoi(argv[1]);
f8b2ed36 2790 if( aType < 0 || aType > 8 )
2791 {
2792 di << "Wrong fill type " << "\n";
2793 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2794 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2795 return 1;
2796 }
2797
2798 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2799
2800 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2801 V3dView->SetBgGradientStyle( aMethod, 1 );
2802 }
2803
2804 return 0;
2805}
2806
2807//==============================================================================
2808//function : VSetColorBg
2809//purpose : Set color background
2810//==============================================================================
2811static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2812{
2813 if (argc != 4 )
2814 {
2815 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2816 di << "R,G,B = [0..255]" << "\n";
2817 return 1;
2818 }
2819
2820 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2821 if(AISContext.IsNull())
2822 {
2823 di << "use 'vinit' command before " << argv[0] << "\n";
2824 return 1;
2825 }
2826 if (argc == 4)
2827 {
2828
91322f44 2829 Standard_Real R = Draw::Atof(argv[1])/255.;
2830 Standard_Real G = Draw::Atof(argv[2])/255.;
2831 Standard_Real B = Draw::Atof(argv[3])/255.;
f8b2ed36 2832 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2833
2834 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2835 V3dView->SetBackgroundColor( aColor );
2836 V3dView->Update();
2837 }
2838
2839 return 0;
2840}
2841
7fd59977 2842//==============================================================================
2843//function : VScale
2844//purpose : View Scaling
2845//==============================================================================
2846
2847static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2848{
2849 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2850 if ( V3dView.IsNull() ) return 1;
2851
2852 if ( argc != 4 ) {
2853 di << argv[0] << "Invalid number of arguments" << "\n";
2854 return 1;
2855 }
91322f44 2856 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
7fd59977 2857 return 0;
2858}
2859//==============================================================================
536d98e2 2860//function : VZBuffTrihedron
2861//purpose :
7fd59977 2862//==============================================================================
2863
536d98e2 2864static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
2865 Standard_Integer theArgNb,
2866 const char** theArgVec)
7fd59977 2867{
536d98e2 2868 Handle(V3d_View) aView = ViewerTest::CurrentView();
2869 if (aView.IsNull())
2870 {
2871 std::cout << "Error: no active viewer!\n";
2872 return 1;
2873 }
7fd59977 2874
536d98e2 2875 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7c8a8fcc 2876
536d98e2 2877 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2878 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
2879 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
2880 Quantity_Color anArrowColorX = Quantity_NOC_RED;
2881 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
2882 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
2883 Standard_Real aScale = 0.1;
2884 Standard_Real aSizeRatio = 0.8;
2885 Standard_Real anArrowDiam = 0.05;
2886 Standard_Integer aNbFacets = 12;
2887 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7c8a8fcc 2888 {
536d98e2 2889 Standard_CString anArg = theArgVec[anArgIter];
2890 TCollection_AsciiString aFlag (anArg);
2891 aFlag.LowerCase();
2892 if (anUpdateTool.parseRedrawMode (aFlag))
7c8a8fcc 2893 {
536d98e2 2894 continue;
2895 }
2896 else if (aFlag == "-on")
7c8a8fcc 2897 {
536d98e2 2898 continue;
2899 }
2900 else if (aFlag == "-off")
7c8a8fcc 2901 {
536d98e2 2902 aView->TriedronErase();
2903 return 0;
2904 }
2905 else if (aFlag == "-pos"
2906 || aFlag == "-position"
2907 || aFlag == "-corner")
7c8a8fcc 2908 {
536d98e2 2909 if (++anArgIter >= theArgNb)
2910 {
2911 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2912 return 1;
2913 }
2914
2915 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
2916 aPosName.LowerCase();
2917 if (aPosName == "center")
2918 {
2919 aPosition = Aspect_TOTP_CENTER;
2920 }
2921 else if (aPosName == "left_lower"
2922 || aPosName == "lower_left"
2923 || aPosName == "leftlower"
2924 || aPosName == "lowerleft")
2925 {
2926 aPosition = Aspect_TOTP_LEFT_LOWER;
2927 }
2928 else if (aPosName == "left_upper"
2929 || aPosName == "upper_left"
2930 || aPosName == "leftupper"
2931 || aPosName == "upperleft")
2932 {
2933 aPosition = Aspect_TOTP_LEFT_UPPER;
2934 }
2935 else if (aPosName == "right_lower"
2936 || aPosName == "lower_right"
2937 || aPosName == "rightlower"
2938 || aPosName == "lowerright")
2939 {
2940 aPosition = Aspect_TOTP_RIGHT_LOWER;
2941 }
2942 else if (aPosName == "right_upper"
2943 || aPosName == "upper_right"
2944 || aPosName == "rightupper"
2945 || aPosName == "upperright")
2946 {
2947 aPosition = Aspect_TOTP_RIGHT_UPPER;
2948 }
2949 else
2950 {
2951 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
2952 return 1;
2953 }
2954 }
2955 else if (aFlag == "-type")
7c8a8fcc 2956 {
536d98e2 2957 if (++anArgIter >= theArgNb)
2958 {
2959 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2960 return 1;
2961 }
2962
2963 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
2964 aTypeName.LowerCase();
2965 if (aTypeName == "wireframe"
2966 || aTypeName == "wire")
2967 {
2968 aVisType = V3d_WIREFRAME;
2969 }
2970 else if (aTypeName == "zbuffer"
2971 || aTypeName == "shaded")
2972 {
2973 aVisType = V3d_ZBUFFER;
2974 }
2975 else
2976 {
2977 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
2978 }
2979 }
2980 else if (aFlag == "-scale")
7c8a8fcc 2981 {
536d98e2 2982 if (++anArgIter >= theArgNb)
2983 {
2984 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2985 return 1;
2986 }
2987
2988 aScale = Draw::Atof (theArgVec[anArgIter]);
7c8a8fcc 2989 }
536d98e2 2990 else if (aFlag == "-size"
2991 || aFlag == "-sizeratio")
2992 {
2993 if (++anArgIter >= theArgNb)
2994 {
2995 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2996 return 1;
2997 }
7c8a8fcc 2998
536d98e2 2999 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3000 }
3001 else if (aFlag == "-arrowdiam"
3002 || aFlag == "-arrowdiameter")
3003 {
3004 if (++anArgIter >= theArgNb)
3005 {
3006 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3007 return 1;
3008 }
7c8a8fcc 3009
536d98e2 3010 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3011 }
3012 else if (aFlag == "-nbfacets")
3013 {
3014 if (++anArgIter >= theArgNb)
3015 {
3016 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3017 return 1;
3018 }
7c8a8fcc 3019
536d98e2 3020 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3021 }
3022 else if (aFlag == "-colorlabel"
3023 || aFlag == "-colorlabels")
7c8a8fcc 3024 {
536d98e2 3025 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3026 theArgVec + anArgIter + 1,
3027 aLabelsColor);
3028 if (aNbParsed == 0)
3029 {
3030 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3031 return 1;
3032 }
3033 anArgIter += aNbParsed;
7c8a8fcc 3034 }
536d98e2 3035 else if (aFlag == "-colorarrowx")
7c8a8fcc 3036 {
536d98e2 3037 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3038 theArgVec + anArgIter + 1,
3039 anArrowColorX);
3040 if (aNbParsed == 0)
3041 {
3042 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3043 return 1;
3044 }
3045 anArgIter += aNbParsed;
3046 }
3047 else if (aFlag == "-colorarrowy")
7c8a8fcc 3048 {
536d98e2 3049 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3050 theArgVec + anArgIter + 1,
3051 anArrowColorY);
3052 if (aNbParsed == 0)
3053 {
3054 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3055 return 1;
3056 }
3057 anArgIter += aNbParsed;
3058 }
3059 else if (aFlag == "-colorarrowz")
7c8a8fcc 3060 {
536d98e2 3061 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3062 theArgVec + anArgIter + 1,
3063 anArrowColorZ);
3064 if (aNbParsed == 0)
3065 {
3066 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3067 return 1;
3068 }
3069 anArgIter += aNbParsed;
3070 }
3071 else
3072 {
3073 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
7c8a8fcc 3074 return 1;
3075 }
7c8a8fcc 3076 }
3077
536d98e2 3078 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3079 aSizeRatio, anArrowDiam, aNbFacets);
3080 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3081 aView->View()->ZFitAll();
7fd59977 3082 return 0;
3083}
3084
3085//==============================================================================
3086//function : VRotate
3087//purpose : Camera Rotating
3088//==============================================================================
3089
4af098ba 3090static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3091{
3092 Handle(V3d_View) aView = ViewerTest::CurrentView();
3093 if (aView.IsNull())
3094 {
3095 std::cout << "No active view!\n";
7fd59977 3096 return 1;
3097 }
3098
4af098ba 3099 Standard_Boolean hasFlags = Standard_False;
3100 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3101 {
3102 Standard_CString anArg (theArgVec[anArgIter]);
3103 TCollection_AsciiString aFlag (anArg);
3104 aFlag.LowerCase();
3105 if (aFlag == "-mousestart"
3106 || aFlag == "-mousefrom")
3107 {
3108 hasFlags = Standard_True;
3109 if (anArgIter + 2 >= theArgNb)
3110 {
3111 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3112 return 1;
3113 }
3114
3115 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3116 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3117 aView->StartRotation (anX, anY);
3118 }
3119 else if (aFlag == "-mousemove")
3120 {
3121 hasFlags = Standard_True;
3122 if (anArgIter + 2 >= theArgNb)
3123 {
3124 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3125 return 1;
3126 }
3127
3128 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3129 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3130 aView->Rotation (anX, anY);
3131 }
3132 else if (theArgNb != 4
3133 && theArgNb != 7)
3134 {
3135 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3136 return 1;
3137 }
3138 }
3139
3140 if (hasFlags)
3141 {
7fd59977 3142 return 0;
4af098ba 3143 }
3144 else if (theArgNb == 4)
3145 {
3146 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3147 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3148 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3149 aView->Rotate (anAX, anAY, anAZ);
3150 return 0;
3151 }
3152 else if (theArgNb == 7)
3153 {
3154 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3155 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3156 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3157
3158 Standard_Real anX = Draw::Atof (theArgVec[4]);
3159 Standard_Real anY = Draw::Atof (theArgVec[5]);
3160 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3161
3162 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
7fd59977 3163 return 0;
7fd59977 3164 }
4af098ba 3165
3166 std::cout << "Error: Invalid number of arguments\n";
3167 return 1;
7fd59977 3168}
3169
3170//==============================================================================
3171//function : VZoom
3172//purpose : View zoom in / out (relative to current zoom)
3173//==============================================================================
3174
3175static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3176 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3177 if ( V3dView.IsNull() ) {
3178 return 1;
3179 }
3180
3181 if ( argc == 2 ) {
91322f44 3182 Standard_Real coef = Draw::Atof(argv[1]);
7fd59977 3183 if ( coef <= 0.0 ) {
3184 di << argv[1] << "Invalid value" << "\n";
3185 return 1;
3186 }
91322f44 3187 V3dView->SetZoom( Draw::Atof(argv[1]) );
7fd59977 3188 return 0;
3189 } else {
3190 di << argv[0] << " Invalid number of arguments" << "\n";
3191 return 1;
3192 }
3193}
3194
3195//==============================================================================
3196//function : VPan
3197//purpose : View panning (in pixels)
3198//==============================================================================
3199
3200static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3201 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3202 if ( V3dView.IsNull() ) return 1;
3203
3204 if ( argc == 3 ) {
91322f44 3205 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
7fd59977 3206 return 0;
3207 } else {
3208 di << argv[0] << " Invalid number of arguments" << "\n";
3209 return 1;
3210 }
3211}
3212
49e1a5c7 3213//==============================================================================
3214//function : VPlace
3215//purpose : Place the point (in pixels) at the center of the window
3216//==============================================================================
3217static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3218{
3219 Handle(V3d_View) aView = ViewerTest::CurrentView();
3220 if (aView.IsNull())
3221 {
3222 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3223 return 1;
3224 }
3225
3226 if (theArgNb != 3)
3227 {
3228 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3229 return 1;
3230 }
3231
3232 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3233
3234 return 0;
3235}
7fd59977 3236
3237//==============================================================================
3238//function : VExport
5cedc27f 3239//purpose : Export the view to a vector graphic format (PS, EMF, PDF)
7fd59977 3240//==============================================================================
3241
3242static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3243{
3244 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
5cedc27f
K
3245 if (V3dView.IsNull())
3246 return 1;
7fd59977 3247
5cedc27f
K
3248 if (argc == 1)
3249 {
3250 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
7fd59977 3251 return 1;
3252 }
3253
5cedc27f
K
3254 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
3255 TCollection_AsciiString aFormatStr;
3256
3257 TCollection_AsciiString aFileName (argv[1]);
3258 Standard_Integer aLen = aFileName.Length();
3259
3260 if (argc > 2)
3261 {
3262 aFormatStr = TCollection_AsciiString (argv[2]);
3263 }
3264 else if (aLen >= 4)
3265 {
3266 if (aFileName.Value (aLen - 2) == '.')
3267 {
3268 aFormatStr = aFileName.SubString (aLen - 1, aLen);
3269 }
3270 else if (aFileName.Value (aLen - 3) == '.')
3271 {
3272 aFormatStr = aFileName.SubString (aLen - 2, aLen);
3273 }
3274 else
3275 {
3276 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3277 return 1;
3278 }
3279 }
3280 else
3281 {
3282 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3283 return 1;
3284 }
3285
3286 aFormatStr.UpperCase();
3287 if (aFormatStr == "PS")
3288 anExpFormat = Graphic3d_EF_PostScript;
3289 else if (aFormatStr == "EPS")
3290 anExpFormat = Graphic3d_EF_EnhPostScript;
3291 else if (aFormatStr == "TEX")
3292 anExpFormat = Graphic3d_EF_TEX;
3293 else if (aFormatStr == "PDF")
3294 anExpFormat = Graphic3d_EF_PDF;
3295 else if (aFormatStr == "SVG")
3296 anExpFormat = Graphic3d_EF_SVG;
3297 else if (aFormatStr == "PGF")
3298 anExpFormat = Graphic3d_EF_PGF;
3299 else if (aFormatStr == "EMF")
3300 anExpFormat = Graphic3d_EF_EMF;
3301 else
3302 {
3303 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3304 return 1;
3305 }
3306
9753e6de 3307 try {
3308 if (!V3dView->View()->Export (argv[1], anExpFormat))
3309 {
3310 di << "Error: export of image to " << aFormatStr << " failed!\n";
3311 }
3312 }
3313 catch (Standard_Failure)
5cedc27f 3314 {
9753e6de 3315 di << "Error: export of image to " << aFormatStr << " failed";
3316 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
5cedc27f 3317 }
7fd59977 3318 return 0;
3319}
3320
3321//==============================================================================
3322//function : VColorScale
3323//purpose : representation color scale
3324//==============================================================================
7fd59977 3325
71215351 3326static Standard_Boolean checkColor (const TCollection_AsciiString& theRed,
3327 const TCollection_AsciiString& theGreen,
3328 const TCollection_AsciiString& theBlue,
3329 Standard_Real& theRedValue,
3330 Standard_Real& theGreenValue,
3331 Standard_Real& theBlueValue)
7fd59977 3332{
71215351 3333 if (!theRed.IsRealValue()
3334 || !theGreen.IsRealValue()
3335 || !theBlue.IsRealValue())
7fd59977 3336 {
71215351 3337 std::cout << "Error: RGB color values should be real!\n";
3338 return Standard_True;
3339 }
3340 theRedValue = theRed .RealValue();
3341 theGreenValue = theGreen.RealValue();
3342 theBlueValue = theBlue .RealValue();
3343 if (theRedValue < 0.0 || theRedValue > 1.0
3344 || theGreenValue < 0.0 || theGreenValue > 1.0
3345 || theBlueValue < 0.0 || theBlueValue > 1.0)
3346 {
3347 std::cout << "Error: RGB color values should be within range 0..1!\n";
3348 return Standard_True;
7fd59977 3349 }
71215351 3350 return Standard_False;
3351}
7fd59977 3352
71215351 3353static int VColorScale (Draw_Interpretor& theDI,
3354 Standard_Integer theArgNb,
3355 const char** theArgVec)
3356{
7fd59977 3357 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
71215351 3358 Handle(V3d_View) aView = ViewerTest::CurrentView();
3359 if (aContext.IsNull())
3360 {
3361 std::cout << "Error: no active view!\n";
3362 return 1;
7fd59977 3363 }
3364
71215351 3365 Handle(V3d_ColorScale) aCS = Handle(V3d_ColorScale)::DownCast (aView->ColorScale());
3366 if (aCS.IsNull())
3367 {
3368 std::cout << "Error: color scale is undefined!\n";
7fd59977 3369 return 1;
7fd59977 3370 }
71215351 3371
3372 Standard_Real aMinRange = aCS->GetMin();
3373 Standard_Real aMaxRange = aCS->GetMax();
3374 Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals();
3375 Standard_Integer aTextHeight = aCS->GetTextHeight();
3376 Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition();
3377 gp_XY aPos (aCS->GetXPosition(), aCS->GetYPosition());
3378
3379 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3380
3381 if (theArgNb <= 1)
3382 {
3383 theDI << "Current color scale parameters:\n"
3384 << "Min range: " << aMinRange << "\n"
3385 << "Max range: " << aMaxRange << "\n"
3386 << "Number of intervals: " << aNbIntervals << "\n"
3387 << "Text height: " << aTextHeight << "\n"
3388 << "Color scale position: " << aPos.X() <<" "<< aPos.Y()<< "\n"
3389 << "Color scale title: " << aCS->GetTitle() << "\n"
3390 << "Label position: ";
3391 switch (aLabPosition)
3392 {
3393 case Aspect_TOCSP_NONE:
3394 theDI << "None\n";
3395 break;
3396 case Aspect_TOCSP_LEFT:
3397 theDI << "Left\n";
3398 break;
3399 case Aspect_TOCSP_RIGHT:
3400 theDI << "Right\n";
3401 break;
3402 case Aspect_TOCSP_CENTER:
3403 theDI << "Center\n";
3404 break;
3405 }
3406 return 0;
3407 }
3408 Standard_CString aFirstArg = theArgVec[1];
3409 TCollection_AsciiString aFlag (aFirstArg);
3410 aFlag.LowerCase();
3411 if (aFlag == "-hide" ||
3412 aFlag == "-erase")
3413 {
3414 if (theArgNb > 2)
3415 {
3416 std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n";
3417 return 1;
3418 }
3419 if (!aView->ColorScaleIsDisplayed())
3420 {
3421 std::cout << "Error: color scale is not displayed!\n";
3422 return 1;
3423 }
3424 else
3425 {
3426 aView->ColorScaleErase();
3427 return 0;
3428 }
3429 }
3430 else if (aFlag == "-show" ||
3431 aFlag == "-display")
3432 {
3433 if (theArgNb > 2)
3434 {
3435 std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n";
3436 return 1;
3437 }
3438 aView->ColorScaleDisplay();
3439 return 0;
3440 }
3441
3442 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3443 {
3444 Standard_CString anArg = theArgVec[anArgIter];
3445 TCollection_AsciiString aFlag (anArg);
3446 aFlag.LowerCase();
3447 if (anUpdateTool.parseRedrawMode (aFlag))
3448 {
3449 continue;
3450 }
3451 else if (aFlag == "-range")
3452 {
3453 if (anArgIter + 3 >= theArgNb)
3454 {
3455 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3456 return 1;
3457 }
3458
3459 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
3460 TCollection_AsciiString anArg2 (theArgVec[++anArgIter]);
3461 TCollection_AsciiString anArg3 (theArgVec[++anArgIter]);
3462 if (!anArg1.IsRealValue())
3463 {
3464 std::cout << "Error: the minRange value should be real!\n";
3465 return 1;
3466 }
3467 else if (!anArg2.IsRealValue())
3468 {
3469 std::cout << "Error: the maxRange value should be real!\n";
3470 return 1;
3471 }
3472 else if (!anArg3.IsIntegerValue())
3473 {
3474 std::cout << "Error: the number of intervals should be integer!\n";
3475 return 1;
3476 }
3477
3478 aMinRange = anArg1.RealValue();
3479 aMaxRange = anArg2.RealValue();
3480 aNbIntervals = anArg3.IntegerValue();
3481 }
3482 else if (aFlag == "-font")
3483 {
3484 if (anArgIter + 1 >= theArgNb)
3485 {
3486 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3487 return 1;
3488 }
3489 TCollection_AsciiString anArg (theArgVec[anArgIter + 1]);
3490 if (!anArg.IsIntegerValue())
3491 {
3492 std::cout << "Error: HeightFont value should be integer!\n";
3493 return 1;
3494 }
3495
3496 aTextHeight = anArg.IntegerValue();
3497 anArgIter += 1;
3498 }
3499 else if (aFlag == "-textpos")
3500 {
3501 if (anArgIter + 1 >= theArgNb)
3502 {
3503 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3504 return 1;
3505 }
3506 TCollection_AsciiString anArg (theArgVec[++anArgIter]);
3507 anArg.LowerCase();
3508 if (anArg == "none")
3509 {
3510 aLabPosition = Aspect_TOCSP_NONE;
3511 }
3512 else if (anArg == "left")
3513 {
3514 aLabPosition = Aspect_TOCSP_LEFT;
3515 }
3516 else if (anArg == "right")
3517 {
3518 aLabPosition = Aspect_TOCSP_RIGHT;
3519 }
3520 else if (anArg == "center")
3521 {
3522 aLabPosition = Aspect_TOCSP_CENTER;
3523 }
3524 else
3525 {
3526 std::cout << "Error: unknown position '" << anArg << "'!\n";
3527 return 1;
3528 }
3529 }
3530 else if (aFlag == "-xy")
3531 {
3532 if (anArgIter + 2 >= theArgNb)
3533 {
3534 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3535 return 1;
3536 }
3537
3538 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3539 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3540 if (!aX.IsRealValue()
3541 || !aY.IsRealValue())
3542 {
3543 std::cout << "Error: coordinates should be real values!\n";
3544 return 1;
3545 }
3546
3547 aPos.SetCoord (aX.RealValue(), aY.RealValue());
3548 }
3549 else if (aFlag == "-color")
3550 {
3551 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3552 {
3553 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3554 return 1;
3555 }
3556
3557 Quantity_NameOfColor aColorName;
3558 if (anArgIter + 4 >= theArgNb)
3559 {
3560 if (anArgIter + 2 >= theArgNb)
3561 {
3562 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3563 return 1;
3564 }
3565 else if (!Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3566 {
3567 std::cout << "Error: wrong color name: '" << theArgVec[anArgIter + 2] << "' !\n";
3568 return 1;
3569 }
3570 }
3571
3572 TCollection_AsciiString anInd (theArgVec[anArgIter + 1]);
3573 if (!anInd.IsIntegerValue())
3574 {
3575 std::cout << "Error: Index value should be integer!\n";
3576 return 1;
3577 }
3578
3579 Standard_Integer anIndex = anInd.IntegerValue();
3580 if (anIndex < 0
3581 || anIndex > aNbIntervals - 1)
3582 {
3583 std::cout << "Error: Index value should be within range 0..." << (aNbIntervals - 1) <<"!\n";
3584 return 1;
3585 }
3586
3587 if (Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3588 {
3589 aCS->SetColor (Quantity_Color (aColorName), anIndex);
3590 aCS->SetColorType(Aspect_TOCSD_USER);
3591 anArgIter += 2;
3592 continue;
3593 }
3594
3595 TCollection_AsciiString aRed (theArgVec[anArgIter + 2]);
3596 TCollection_AsciiString aGreen (theArgVec[anArgIter + 3]);
3597 TCollection_AsciiString aBlue (theArgVec[anArgIter + 4]);
3598 Standard_Real aRedValue,aGreenValue, aBlueValue;
3599 if(checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3600 {
3601 return 1;
3602 }
3603 aCS->SetColor (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex);
3604 aCS->SetColorType (Aspect_TOCSD_USER);
3605 anArgIter += 4;
3606 }
3607 else if (aFlag == "-label")
3608 {
3609 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3610 {
3611 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
3612 return 1;
3613 }
3614 else if (anArgIter + 2 >= theArgNb)
3615 {
3616 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3617 return 1;
3618 }
3619
3620 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
3621 if (anIndex < 0
3622 || anIndex > aNbIntervals)
3623 {
3624 std::cout << "Error: Index value should be within range 0..." << aNbIntervals <<"!\n";
3625 return 1;
3626 }
3627
3628 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
3629 aCS->SetLabel (aText, anIndex);
3630 aCS->SetLabelType (Aspect_TOCSD_USER);
3631 anArgIter += 2;
3632 }
3633 else if (aFlag == "-colors")
3634 {
3635 Aspect_SequenceOfColor aSeq;
3636 if (anArgIter + aNbIntervals + 1 > theArgNb)
3637 {
3638 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3639 << aNbIntervals << " intervals\n";
3640 return 1;
3641 }
3642
3643 Standard_Integer aColorIter = anArgIter + 1;
3644 while (aColorIter < theArgNb)
3645 {
3646 if (theArgVec[aColorIter][0] == '-')
3647 {
3648 break;
3649 }
3650
3651 else if (theArgVec[aColorIter][0] >= 97
3652 && theArgVec[aColorIter][0] <= 122)
3653 {
3654 Quantity_NameOfColor aColorName;
3655 if (!Quantity_Color::ColorFromName (theArgVec[aColorIter], aColorName))
3656 {
3657 std::cout << "Error: wrong color name: " << theArgVec[aColorIter] << " !\n";
3658 return 1;
3659 }
3660 aSeq.Append (Quantity_Color (aColorName));
3661 aColorIter++;
3662 anArgIter++;
3663 }
3664 else
3665 {
3666 TCollection_AsciiString aRed (theArgVec[aColorIter]);
3667 TCollection_AsciiString aGreen (theArgVec[aColorIter + 1]);
3668 TCollection_AsciiString aBlue (theArgVec[aColorIter + 2]);
3669 Standard_Real aRedValue,aGreenValue, aBlueValue;
3670 if (checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3671 {
3672 return 1;
3673 }
3674 aSeq.Append (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB));
3675 aColorIter += 3;
3676 anArgIter += 3;
3677 }
3678 }
3679 if (aSeq.Length() < aNbIntervals)
3680 {
3681 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3682 << aNbIntervals << " intervals\n";
3683 return 1;
3684 }
3685
3686 aCS->SetColors (aSeq);
3687 aCS->SetColorType (Aspect_TOCSD_USER);
3688 }
3689 else if (aFlag == "-labels")
3690 {
3691 if (anArgIter + aNbIntervals + 1 >= theArgNb)
3692 {
3693 std::cout << "Error: not enough arguments! You should provide " << (aNbIntervals + 1)
3694 << " text labels for " << aNbIntervals << " intervals.\n";
3695 return 1;
3696 }
3697
3698 TColStd_SequenceOfExtendedString aSeq;
3699 for (int aLabelIter = anArgIter + 1; aLabelIter <= anArgIter + aNbIntervals + 1; aLabelIter += 1)
3700 {
3701 aSeq.Append (TCollection_ExtendedString (theArgVec[aLabelIter]));
3702 }
3703 aCS->SetLabels (aSeq);
3704 aCS->SetLabelType (Aspect_TOCSD_USER);
3705 anArgIter += aSeq.Length();
3706 }
3707 else if (aFlag == "-title")
3708 {
3709 if (anArgIter + 1 >= theArgNb)
3710 {
3711 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3712 return 1;
3713 }
3714
3715 Standard_Boolean isTwoArgs = Standard_False;
3716 if (anArgIter + 2 < theArgNb)
3717 {
3718 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
3719 aSecondArg.LowerCase();
3720 if (aSecondArg == "none")
3721 {
3722 aCS->SetTitlePosition (Aspect_TOCSP_NONE);
3723 isTwoArgs = Standard_True;
3724 }
3725 else if (aSecondArg == "left")
3726 {
3727 aCS->SetTitlePosition (Aspect_TOCSP_LEFT);
3728 isTwoArgs = Standard_True;
3729 }
3730 else if (aSecondArg == "right")
3731 {
3732 aCS->SetTitlePosition (Aspect_TOCSP_RIGHT);
3733 isTwoArgs = Standard_True;
3734 }
3735 else if (aSecondArg == "center")
3736 {
3737 aCS->SetTitlePosition (Aspect_TOCSP_CENTER);
3738 isTwoArgs = Standard_True;
3739 }
3740 }
3741
3742 aCS->SetTitle (theArgVec[anArgIter + 1]);
3743 if (isTwoArgs)
3744 {
3745 anArgIter += 1;
3746 }
3747 anArgIter += 1;
3748 }
3749 else if (aFlag == "-demoversion"
3750 || aFlag == "-demo")
3751 {
3752 aPos.SetCoord (0.0, 0.0);
3753 aTextHeight = 16;
3754 aMinRange = 0.0;
3755 aMaxRange = 100;
3756 aNbIntervals = 10;
3757 aLabPosition = Aspect_TOCSP_RIGHT;
3758 aCS->SetColorType(Aspect_TOCSD_AUTO);
3759 aCS->SetLabelType(Aspect_TOCSD_AUTO);
3760 }
3761 else
3762 {
3763 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
3764 return 1;
3765 }
3766 }
3767
3768 aCS->SetPosition (aPos.X(), aPos.Y());
3769 aCS->SetHeight (0.95);
3770 aCS->SetTextHeight (aTextHeight);
3771 aCS->SetRange (aMinRange, aMaxRange);
3772 aCS->SetNumberOfIntervals (aNbIntervals);
3773 aCS->SetLabelPosition (aLabPosition);
3774
3775 if (!aView->ColorScaleIsDisplayed())
3776 {
3777 aView->ColorScaleDisplay();
3778 }
3779
7fd59977 3780 return 0;
3781}
3782
3783//==============================================================================
3784//function : VGraduatedTrihedron
a79f67f8 3785//purpose : Displays or hides a graduated trihedron
7fd59977 3786//==============================================================================
a79f67f8 3787static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
3788 Quantity_Color& theColor)
13a22457 3789{
a79f67f8 3790 Quantity_NameOfColor aColorName;
3791 TCollection_AsciiString aVal = theValue;
3792 aVal.UpperCase();
3793 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
13a22457 3794 {
a79f67f8 3795 return Standard_False;
13a22457 3796 }
a79f67f8 3797 theColor = Quantity_Color (aColorName);
3798 return Standard_True;
13a22457
S
3799}
3800
a79f67f8 3801static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
7fd59977 3802{
a79f67f8 3803 if (theArgNum < 2)
13a22457 3804 {
a79f67f8 3805 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
3806 << theArgs[0] <<"' for more information.\n";
3807 return 1; //TCL_ERROR
13a22457 3808 }
7fd59977 3809
a79f67f8 3810 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3811 TCollection_AsciiString aParseKey;
3812 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
3813 {
3814 TCollection_AsciiString anArg (theArgs [anArgIt]);
3815
3816 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3817 {
3818 aParseKey = anArg;
3819 aParseKey.Remove (1);
3820 aParseKey.LowerCase();
3821 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3822 continue;
3823 }
13a22457 3824
a79f67f8 3825 if (aParseKey.IsEmpty())
3826 {
3827 continue;
3828 }
3829
3830 aMapOfArgs(aParseKey)->Append (anArg);
3831 }
3832
3833 // Check parameters
3834 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
3835 aMapIt.More(); aMapIt.Next())
7fd59977 3836 {
a79f67f8 3837 const TCollection_AsciiString& aKey = aMapIt.Key();
3838 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3839
3840 // Bool key, without arguments
3841 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
3842 && anArgs->IsEmpty())
3843 {
3844 continue;
3845 }
3846
3847 // One argument
3848 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
3849 && anArgs->Length() == 1)
3850 {
3851 continue;
3852 }
3853
3854 // On/off arguments
3855 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
3856 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
536d98e2 3857 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
3858 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
a79f67f8 3859 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
3860 {
3861 continue;
3862 }
3863
3864 // One string argument
3865 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
3866 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
3867 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
3868 {
3869 continue;
3870 }
3871
3872 // One integer argument
3873 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
3874 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
3875 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
3876 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
3877 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
3878 {
3879 continue;
3880 }
3881
3882 // One real argument
3883 if ( aKey.IsEqual ("arrowlength")
3884 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
3885 {
3886 continue;
3887 }
3888
3889 // Two string arguments
3890 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
3891 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
13a22457 3892 {
a79f67f8 3893 continue;
13a22457 3894 }
a79f67f8 3895
3896 TCollection_AsciiString aLowerKey;
3897 aLowerKey = "-";
3898 aLowerKey += aKey;
3899 aLowerKey.LowerCase();
3900 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3901 std::cout << "Type help for more information.\n";
3902 return 1;
7fd59977 3903 }
3904
a79f67f8 3905 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3906 if (anAISContext.IsNull())
3907 {
3908 std::cout << theArgs[0] << ": " << " please use 'vinit' command to initialize view.\n";
3909 return 1;
3910 }
7fd59977 3911
a79f67f8 3912 Standard_Boolean toDisplay = Standard_True;
3913 Quantity_Color aColor;
3914 Graphic3d_GraduatedTrihedron aTrihedronData;
3915 // Process parameters
3916 Handle(TColStd_HSequenceOfAsciiString) aValues;
3917 if (aMapOfArgs.Find ("off", aValues))
7fd59977 3918 {
a79f67f8 3919 toDisplay = Standard_False;
3920 }
13a22457 3921
a79f67f8 3922 // AXES NAMES
3923 if (aMapOfArgs.Find ("xname", aValues))
3924 {
3925 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
3926 }
3927 if (aMapOfArgs.Find ("yname", aValues))
3928 {
3929 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
3930 }
3931 if (aMapOfArgs.Find ("zname", aValues))
3932 {
3933 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
3934 }
3935 if (aMapOfArgs.Find ("xdrawname", aValues))
3936 {
536d98e2 3937 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
a79f67f8 3938 }
3939 if (aMapOfArgs.Find ("ydrawname", aValues))
3940 {
536d98e2 3941 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
a79f67f8 3942 }
3943 if (aMapOfArgs.Find ("zdrawname", aValues))
3944 {
536d98e2 3945 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
a79f67f8 3946 }
3947 if (aMapOfArgs.Find ("xnameoffset", aValues))
3948 {
3949 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
3950 }
3951 if (aMapOfArgs.Find ("ynameoffset", aValues))
3952 {
3953 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
3954 }
3955 if (aMapOfArgs.Find ("znameoffset", aValues))
3956 {
3957 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
3958 }
13a22457 3959
a79f67f8 3960 // COLORS
3961 if (aMapOfArgs.Find ("xnamecolor", aValues))
3962 {
3963 if (!GetColor (aValues->Value(1), aColor))
13a22457 3964 {
a79f67f8 3965 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
3966 return 1;
13a22457 3967 }
a79f67f8 3968 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
3969 }
3970 if (aMapOfArgs.Find ("ynamecolor", aValues))
3971 {
3972 if (!GetColor (aValues->Value(1), aColor))
13a22457 3973 {
a79f67f8 3974 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
3975 return 1;
3976 }
3977 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
3978 }
3979 if (aMapOfArgs.Find ("znamecolor", aValues))
3980 {
3981 if (!GetColor (aValues->Value(1), aColor))
3982 {
3983 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
3984 return 1;
3985 }
3986 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
3987 }
3988 if (aMapOfArgs.Find ("xcolor", aValues))
3989 {
3990 if (!GetColor (aValues->Value(1), aColor))
3991 {
3992 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
3993 return 1;
3994 }
3995 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
3996 }
3997 if (aMapOfArgs.Find ("ycolor", aValues))
3998 {
3999 if (!GetColor (aValues->Value(1), aColor))
4000 {
4001 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4002 return 1;
4003 }
4004 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4005 }
4006 if (aMapOfArgs.Find ("zcolor", aValues))
4007 {
4008 if (!GetColor (aValues->Value(1), aColor))
4009 {
4010 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4011 return 1;
4012 }
4013 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4014 }
4015
4016 // TICKMARKS
4017 if (aMapOfArgs.Find ("xticks", aValues))
4018 {
536d98e2 4019 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
a79f67f8 4020 }
4021 if (aMapOfArgs.Find ("yticks", aValues))
4022 {
536d98e2 4023 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
a79f67f8 4024 }
4025 if (aMapOfArgs.Find ("zticks", aValues))
4026 {
536d98e2 4027 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
a79f67f8 4028 }
4029 if (aMapOfArgs.Find ("xticklength", aValues))
4030 {
536d98e2 4031 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
a79f67f8 4032 }
4033 if (aMapOfArgs.Find ("yticklength", aValues))
4034 {
536d98e2 4035 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
a79f67f8 4036 }
4037 if (aMapOfArgs.Find ("zticklength", aValues))
4038 {
536d98e2 4039 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
a79f67f8 4040 }
4041 if (aMapOfArgs.Find ("xdrawticks", aValues))
4042 {
536d98e2 4043 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
a79f67f8 4044 }
4045 if (aMapOfArgs.Find ("ydrawticks", aValues))
4046 {
536d98e2 4047 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
a79f67f8 4048 }
4049 if (aMapOfArgs.Find ("zdrawticks", aValues))
4050 {
536d98e2 4051 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
a79f67f8 4052 }
4053
4054 // VALUES
4055 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4056 {
536d98e2 4057 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
a79f67f8 4058 }
4059 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4060 {
536d98e2 4061 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
a79f67f8 4062 }
4063 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4064 {
536d98e2 4065 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
a79f67f8 4066 }
4067 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4068 {
4069 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4070 }
4071 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4072 {
4073 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4074 }
4075 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4076 {
4077 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4078 }
4079
4080 // ARROWS
4081 if (aMapOfArgs.Find ("arrowlength", aValues))
4082 {
536d98e2 4083 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
a79f67f8 4084 }
4085
4086 // FONTS
4087 if (aMapOfArgs.Find ("namefont", aValues))
4088 {
4089 aTrihedronData.SetNamesFont (aValues->Value(1));
4090 }
4091 if (aMapOfArgs.Find ("valuesfont", aValues))
4092 {
4093 aTrihedronData.SetValuesFont (aValues->Value(1));
4094 }
4095
536d98e2 4096 if (aMapOfArgs.Find ("drawgrid", aValues))
4097 {
4098 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4099 }
4100 if (aMapOfArgs.Find ("drawaxes", aValues))
4101 {
4102 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4103 }
4104
a79f67f8 4105 // The final step: display of erase trihedron
4106 if (toDisplay)
4107 {
4108 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
13a22457 4109 }
7fd59977 4110 else
a79f67f8 4111 {
4112 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4113 }
7fd59977 4114
4115 ViewerTest::GetAISContext()->UpdateCurrentViewer();
a79f67f8 4116 ViewerTest::CurrentView()->Redraw();
13a22457 4117
7fd59977 4118 return 0;
4119}
4120
7edf74fd
A
4121//==============================================================================
4122//function : VPrintView
4123//purpose : Test printing algorithm, print the view to image file with given
4124// width and height. Printing implemented only for WNT.
4125//==============================================================================
4fe56619 4126static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
7edf74fd
A
4127 const char** argv)
4128{
4129#ifndef WNT
4130 di << "Printing implemented only for wnt!\n";
b5ac8292 4131 return 0;
7edf74fd
A
4132#else
4133
4134 Handle(AIS_InteractiveContext) aContextAIS = NULL;
4135 Handle(V3d_View) aView = NULL;
4136 aContextAIS = ViewerTest::GetAISContext();
4137 if (!aContextAIS.IsNull())
4138 {
4139 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
4140 Vwr->InitActiveViews();
4141 if(Vwr->MoreActiveViews())
4142 aView = Vwr->ActiveView();
4143 }
4144
4145 // check for errors
4146 if (aView.IsNull())
4147 {
4148 di << "Call vinit before!\n";
4149 return 1;
4150 }
4151 else if (argc < 4)
4152 {
4153 di << "Use: " << argv[0];
b5ac8292 4154 di << " width height filename [print algo=0] [tile_width tile_height]\n";
7edf74fd
A
4155 di << "width, height of the intermediate buffer for operation\n";
4156 di << "algo : {0|1}\n";
4157 di << " 0 - stretch algorithm\n";
4158 di << " 1 - tile algorithm\n";
4159 di << "test printing algorithms into an intermediate buffer\n";
b5ac8292 4160 di << "using specific tile size if provided\n";
7edf74fd
A
4161 di << "with saving output to an image file\n";
4162 return 1;
4163 }
4164
4165 // get the input params
91322f44 4166 Standard_Integer aWidth = Draw::Atoi (argv[1]);
4167 Standard_Integer aHeight = Draw::Atoi (argv[2]);
7edf74fd
A
4168 Standard_Integer aMode = 0;
4169 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
b5ac8292 4170 if (argc >= 5)
91322f44 4171 aMode = Draw::Atoi (argv[4]);
7edf74fd 4172
b5ac8292 4173 Standard_Integer aTileWidth = 0;
4174 Standard_Integer aTileHeight = 0;
4175 Standard_Boolean isTileSizeProvided = Standard_False;
4176 if (argc == 7)
4177 {
4178 isTileSizeProvided = Standard_True;
4179 aTileWidth = Draw::Atoi (argv[5]);
4180 aTileHeight = Draw::Atoi (argv[6]);
4181 }
4182
7edf74fd
A
4183 // check the input parameters
4184 if (aWidth <= 0 || aHeight <= 0)
4185 {
4186 di << "Width and height must be positive values!\n";
4187 return 1;
4188 }
4189 if (aMode != 0 && aMode != 1)
4190 aMode = 0;
4191
7edf74fd 4192 // define compatible bitmap
692613e5 4193 HDC anDC = CreateCompatibleDC(0);
7edf74fd
A
4194 BITMAPINFO aBitmapData;
4195 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
4196 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
4197 aBitmapData.bmiHeader.biWidth = aWidth ;
4198 aBitmapData.bmiHeader.biHeight = aHeight;
4199 aBitmapData.bmiHeader.biPlanes = 1;
4200 aBitmapData.bmiHeader.biBitCount = 24;
4201 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
4202 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
4203 aBitmapData.bmiHeader.biClrUsed = 0;
4204 aBitmapData.bmiHeader.biClrImportant = 0;
4205 aBitmapData.bmiHeader.biCompression = BI_RGB;
4206 aBitmapData.bmiHeader.biSizeImage = 0;
4207
4208 // Create Device Independent Bitmap
692613e5 4209 void* aBitsOut = NULL;
7edf74fd 4210 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
692613e5 4211 &aBitsOut, NULL, 0);
7edf74fd
A
4212 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
4213
4214 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
692613e5 4215 if (aBitsOut != NULL)
4fe56619 4216 {
7edf74fd
A
4217 if (aMode == 0)
4218 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
4219 else
b5ac8292 4220 {
4221 if (isTileSizeProvided)
4222 {
4223 Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
4224 Graphic3d_PtrFrameBuffer anOldBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
4225 aCView->ptrFBO = aView->View()->FBOCreate (aTileWidth, aTileHeight);
4226
4227 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
4228
4229 Graphic3d_PtrFrameBuffer aNewBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
4230 aView->View()->FBORelease (aNewBuffer);
4231 aCView->ptrFBO = anOldBuffer;
4232 }
4233 else
4234 {
4235 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
4236 }
4237 }
7edf74fd
A
4238
4239 // succesfully printed into an intermediate buffer
4240 if (isPrinted)
4241 {
692613e5 4242 Image_PixMap aWrapper;
4243 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
4244 aWrapper.SetTopDown (false);
4245
4246 Image_AlienPixMap anImageBitmap;
4247 anImageBitmap.InitCopy (aWrapper);
4248 isSaved = anImageBitmap.Save (aFileName);
7edf74fd
A
4249 }
4250 else
4251 {
4252 di << "Print operation failed due to printing errors or\n";
4253 di << "insufficient memory available\n";
4254 di << "Please, try to use smaller dimensions for this test\n";
4255 di << "command, as it allocates intermediate buffer for storing\n";
4256 di << "the result\n";
4257 }
4258 }
4259 else
4260 {
4261 di << "Can't allocate memory for intermediate buffer\n";
4262 di << "Please use smaller dimensions\n";
4263 }
4264
4265 if (aMemoryBitmap)
4266 {
4267 SelectObject (anDC, anOldBitmap);
4268 DeleteObject (aMemoryBitmap);
4269 DeleteDC(anDC);
4270 }
4271
4272 if (!isSaved)
4273 {
4274 di << "Save to file operation failed. This operation may fail\n";
4275 di << "if you don't have enough available memory, then you can\n";
4276 di << "use smaller dimensions for the output file\n";
4277 return 1;
4278 }
4279
4280 return 0;
4281
4282#endif
4283}
4284
59f45b7c 4285//==============================================================================
4286//function : VZLayer
4287//purpose : Test z layer operations for v3d viewer
4288//==============================================================================
4289static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4290{
4291 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
4292 if (aContextAIS.IsNull())
4293 {
4294 di << "Call vinit before!\n";
4295 return 1;
4296 }
4297 else if (argc < 2)
4298 {
c5751993 4299 di << "Use: vzlayer ";
4300 di << " add/del/get/settings/enable/disable [id]\n";
59f45b7c 4301 di << " add - add new z layer to viewer and print its id\n";
4302 di << " del - del z layer by its id\n";
4303 di << " get - print sequence of z layers in increasing order of their overlay level\n";
c5751993 4304 di << " settings - print status of z layer settings\n";
4305 di << " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n";
4306 di << " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n";
4307 di << " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n";
4308 di << "\nWhere id is the layer identificator\n";
4309 di << "\nExamples:\n";
4310 di << " vzlayer add\n";
4311 di << " vzlayer enable poffset 1\n";
4312 di << " vzlayer disable depthtest 1\n";
4313 di << " vzlayer del 1\n";
59f45b7c 4314 return 1;
4315 }
4316
4317 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4318 if (aViewer.IsNull())
4319 {
4320 di << "No active viewer!\n";
4321 return 1;
4322 }
4323
4324 // perform operation
4325 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
4326 if (anOp == "add")
4327 {
4328 Standard_Integer aNewId;
4329 if (!aViewer->AddZLayer (aNewId))
4330 {
4331 di << "Impossible to add new z layer!\n";
4332 return 1;
4333 }
4334
4335 di << "New z layer added with index: " << aNewId << "\n";
4336 }
4337 else if (anOp == "del")
4338 {
4339 if (argc < 3)
4340 {
4341 di << "Please also provide as argument id of z layer to remove\n";
4342 return 1;
4343 }
4344
91322f44 4345 Standard_Integer aDelId = Draw::Atoi (argv[2]);
59f45b7c 4346 if (!aViewer->RemoveZLayer (aDelId))
4347 {
4348 di << "Impossible to remove the z layer or invalid id!\n";
4349 return 1;
4350 }
4351
a1954302 4352 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4353 anObjIter.More(); anObjIter.Next())
4354 {
4355 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1());
4356 if (aPrs.IsNull()
4357 || aPrs->ZLayer() != aDelId)
4358 {
4359 continue;
4360 }
4361 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4362 }
4363
59f45b7c 4364 di << "Z layer " << aDelId << " has been removed\n";
4365 }
4366 else if (anOp == "get")
4367 {
4368 TColStd_SequenceOfInteger anIds;
4369 aViewer->GetAllZLayers (anIds);
4370 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
4371 {
4372 di << anIds.Value (aSeqIdx) << " ";
4373 }
4374
4375 di << "\n";
4376 }
c5751993 4377 else if (anOp == "settings")
4378 {
4379 if (argc < 3)
4380 {
4381 di << "Please also provide an id\n";
4382 return 1;
4383 }
4384
4385 Standard_Integer anId = Draw::Atoi (argv[2]);
4386 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4387
4388 di << "Depth test - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthTest) ? "enabled" : "disabled") << "\n";
4389 di << "Depth write - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? "enabled" : "disabled") << "\n";
4390 di << "Depth buffer clearing - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) ? "enabled" : "disabled") << "\n";
4391 di << "Depth offset - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthOffset) ? "enabled" : "disabled") << "\n";
4392
4393 }
4394 else if (anOp == "enable")
4395 {
4396 if (argc < 3)
4397 {
4398 di << "Please also provide an option to enable\n";
4399 return 1;
4400 }
4401
4402 if (argc < 4)
4403 {
4404 di << "Please also provide a layer id\n";
4405 return 1;
4406 }
4407
4408 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4409 Standard_Integer anId = Draw::Atoi (argv[3]);
4410 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4411
4412 if (aSubOp == "depthtest" || aSubOp == "test")
4413 {
4414 aSettings.EnableSetting (Graphic3d_ZLayerDepthTest);
4415 }
4416 else if (aSubOp == "depthwrite" || aSubOp == "write")
4417 {
4418 aSettings.EnableSetting (Graphic3d_ZLayerDepthWrite);
4419 }
4420 else if (aSubOp == "depthclear" || aSubOp == "clear")
4421 {
4422 aSettings.EnableSetting (Graphic3d_ZLayerDepthClear);
4423 }
4424 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4425 {
4426 if (argc < 6)
4427 {
4428 di << "Please also provide a factor and units values for depth offset\n";
4429 di << "Format is: vzlayer enable offset [factor] [units] [layerId]\n";
4430 return 1;
4431 }
4432
4433 Standard_ShortReal aFactor = static_cast<Standard_ShortReal> (Draw::Atof (argv[3]));
4434 Standard_ShortReal aUnits = static_cast<Standard_ShortReal> (Draw::Atof (argv[4]));
4435 anId = Draw::Atoi (argv[5]);
4436 aSettings = aViewer->ZLayerSettings (anId);
4437
4438 aSettings.DepthOffsetFactor = aFactor;
4439 aSettings.DepthOffsetUnits = aUnits;
4440
4441 aSettings.EnableSetting (Graphic3d_ZLayerDepthOffset);
4442 }
4443 else if (aSubOp == "positiveoffset" || aSubOp == "poffset")
4444 {
4445 aSettings.SetDepthOffsetPositive();
4446 }
4447 else if (aSubOp == "negativeoffset" || aSubOp == "noffset")
4448 {
4449 aSettings.SetDepthOffsetNegative();
4450 }
4451
4452 aViewer->SetZLayerSettings (anId, aSettings);
4453 }
4454 else if (anOp == "disable")
4455 {
4456 if (argc < 3)
4457 {
4458 di << "Please also provide an option to disable\n";
4459 return 1;
4460 }
4461
4462 if (argc < 4)
4463 {
4464 di << "Please also provide a layer id\n";
4465 return 1;
4466 }
4467
4468 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4469 Standard_Integer anId = Draw::Atoi (argv[3]);
4470 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4471
4472 if (aSubOp == "depthtest" || aSubOp == "test")
4473 {
4474 aSettings.DisableSetting (Graphic3d_ZLayerDepthTest);
4475 }
4476 else if (aSubOp == "depthwrite" || aSubOp == "write")
4477 {
4478 aSettings.DisableSetting (Graphic3d_ZLayerDepthWrite);
4479 }
4480 else if (aSubOp == "depthclear" || aSubOp == "clear")
4481 {
4482 aSettings.DisableSetting (Graphic3d_ZLayerDepthClear);
4483 }
4484 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4485 {
4486 aSettings.DisableSetting (Graphic3d_ZLayerDepthOffset);
4487 }
4488
4489 aViewer->SetZLayerSettings (anId, aSettings);
4490 }
59f45b7c 4491 else
4492 {
c5751993 4493 di << "Invalid operation, please use { add / del / get / settings / enable / disable}\n";
59f45b7c 4494 return 1;
4495 }
4496
4497 return 0;
4498}
4499
25289ec1 4500DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
4501
4502// this class provides a presentation of text item in v3d view under-/overlayer
4503class V3d_TextItem : public Visual3d_LayerItem
4504{
4505public:
4506
4507 // CASCADE RTTI
4508 DEFINE_STANDARD_RTTI(V3d_TextItem)
4509
4510 // constructor
4511 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
4512 const Standard_Real theX1,
4513 const Standard_Real theY1,
4514 const Standard_Real theHeight,
4515 const TCollection_AsciiString& theFontName,
4516 const Quantity_Color& theColor,
4517 const Quantity_Color& theSubtitleColor,
4518 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
4519 const Handle(Visual3d_Layer)& theLayer);
4520
4521 // redraw method
4522 Standard_EXPORT void RedrawLayerPrs();
4523
4524private:
4525
4526 Standard_Real myX1;
4527 Standard_Real myY1;
25289ec1 4528 TCollection_AsciiString myText;
eafb234b 4529 Standard_Real myHeight;
4530 Handle(Visual3d_Layer) myLayer;
25289ec1 4531 Quantity_Color myColor;
4532 Quantity_Color mySubtitleColor;
4533 Aspect_TypeOfDisplayText myType;
eafb234b 4534 TCollection_AsciiString myFontName;
25289ec1 4535};
4536
4537IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
4538IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
4539
4540// create and add to display the text item
4541V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
4542 const Standard_Real theX1,
4543 const Standard_Real theY1,
4544 const Standard_Real theHeight,
4545 const TCollection_AsciiString& theFontName,
4546 const Quantity_Color& theColor,
4547 const Quantity_Color& theSubtitleColor,
4548 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
4549 const Handle(Visual3d_Layer)& theLayer)
4550 : myX1 (theX1), myY1 (theY1),
4551 myText (theText),
4552 myHeight (theHeight),
4553 myLayer (theLayer),
4554 myColor (theColor),
4555 mySubtitleColor (theSubtitleColor),
4556 myType (theTypeOfDisplay),
4557 myFontName (theFontName)
4558{
4559 if (!myLayer.IsNull ())
4560 myLayer->AddLayerItem (this);
4561}
4562
4563// render item
4564void V3d_TextItem::RedrawLayerPrs ()
4fe56619 4565{
25289ec1 4566 if (myLayer.IsNull ())
4567 return;
4568
4569 myLayer->SetColor (myColor);
4570 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
4571 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
4572}
4573
20637bd2 4574DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
4575
4576// The Visual3d_LayerItem line item for "vlayerline" command
4fe56619 4577// it provides a presentation of line with user-defined
20637bd2 4578// linewidth, linetype and transparency.
4fe56619 4579class V3d_LineItem : public Visual3d_LayerItem
20637bd2 4580{
4581public:
4582 // CASCADE RTTI
4fe56619 4583 DEFINE_STANDARD_RTTI(V3d_LineItem)
4584
20637bd2 4585 // constructor
4586 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4587 Standard_Real X2, Standard_Real Y2,
4588 V3d_LayerMgrPointer theLayerMgr,
4589 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
4590 Standard_Real theWidth = 0.5,
4591 Standard_Real theTransp = 1.0);
4592
4593 // redraw method
4594 Standard_EXPORT void RedrawLayerPrs();
4595
4596private:
4597
4598 Standard_Real myX1, myY1, myX2, myY2;
eafb234b 4599 V3d_LayerMgrPointer myLayerMgr;
4600 Aspect_TypeOfLine myType;
20637bd2 4601 Standard_Real myWidth;
4602 Standard_Real myTransparency;
20637bd2 4603};
4604
4605IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
4606IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
4607
4608// default constructor for line item
4fe56619 4609V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
20637bd2 4610 Standard_Real X2, Standard_Real Y2,
4611 V3d_LayerMgrPointer theLayerMgr,
4612 Aspect_TypeOfLine theType,
4613 Standard_Real theWidth,
4614 Standard_Real theTransp) :
4615 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
4616 myType(theType), myWidth(theWidth), myTransparency(theTransp)
4617{
9e4c2fbb 4618 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
20637bd2 4619 myLayerMgr->Overlay()->AddLayerItem (this);
4620}
4621
4622// render line
4623void V3d_LineItem::RedrawLayerPrs ()
4624{
4625 Handle (Visual3d_Layer) aOverlay;
4fe56619 4626
20637bd2 4627 if (myLayerMgr)
4628 aOverlay = myLayerMgr->Overlay();
4629
4630 if (!aOverlay.IsNull())
4631 {
4632 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
4633 aOverlay->SetColor(aColor);
4634 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
4635 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
4636 aOverlay->BeginPolyline();
4637 aOverlay->AddVertex(myX1, myY1);
4638 aOverlay->AddVertex(myX2, myY2);
4639 aOverlay->ClosePrimitive();
4640 }
4641}
4642
4643//=============================================================================
4644//function : VLayerLine
4645//purpose : Draws line in the v3d view layer with given attributes: linetype,
4646// : linewidth, transparency coefficient
4647//============================================================================
4648static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4649{
4650 // get the active view
4651 Handle(V3d_View) aView = ViewerTest::CurrentView();
4652 if (aView.IsNull())
4653 {
4654 di << "Call vinit before!\n";
4655 return 1;
4656 }
4657 else if (argc < 5)
4658 {
4659 di << "Use: " << argv[0];
4660 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
4661 di << " linetype : { 0 | 1 | 2 | 3 } \n";
4662 di << " 0 - solid \n";
4663 di << " 1 - dashed \n";
4664 di << " 2 - dot \n";
4665 di << " 3 - dashdot\n";
4666 di << " transparency : { 0.0 - 1.0 } \n";
4667 di << " 0.0 - transparent\n";
4668 di << " 1.0 - visible \n";
4669 return 1;
4670 }
4671
4672 // get the input params
91322f44 4673 Standard_Real X1 = Draw::Atof(argv[1]);
4674 Standard_Real Y1 = Draw::Atof(argv[2]);
4675 Standard_Real X2 = Draw::Atof(argv[3]);
4676 Standard_Real Y2 = Draw::Atof(argv[4]);
20637bd2 4677
4678 Standard_Real aWidth = 0.5;
4679 Standard_Integer aType = 0;
4680 Standard_Real aTransparency = 1.0;
4681
4682 // has width
4683 if (argc > 5)
91322f44 4684 aWidth = Draw::Atof(argv[5]);
20637bd2 4685
4686 // has type
4687 if (argc > 6)
91322f44 4688 aType = (Standard_Integer) Draw::Atoi(argv[6]);
20637bd2 4689
4690 // has transparency
4691 if (argc > 7)
4692 {
91322f44 4693 aTransparency = Draw::Atof(argv[7]);
4fe56619 4694 if (aTransparency < 0 || aTransparency > 1.0)
20637bd2 4695 aTransparency = 1.0;
4696 }
4697
4698 // select appropriate line type
4699 Aspect_TypeOfLine aLineType;
4700 switch (aType)
4701 {
4702 case 1:
4703 aLineType = Aspect_TOL_DASH;
4704 break;
4705
4706 case 2:
4707 aLineType = Aspect_TOL_DOT;
4708 break;
4709
4710 case 3:
4711 aLineType = Aspect_TOL_DOTDASH;
4712 break;
4713
4714 default:
4715 aLineType = Aspect_TOL_SOLID;
4716 }
4717
4718 // replace layer manager
4719 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
4720 aView->SetLayerMgr(aMgr);
4721
4722 // add line item
4fe56619 4723 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
20637bd2 4724 aMgr.operator->(),
4fe56619 4725 aLineType, aWidth,
20637bd2 4726 aTransparency);
4727
4728 // update view
4729 aView->MustBeResized();
4730 aView->Redraw();
4731
4732 return 0;
4733}
4734
25289ec1 4735//=======================================================================
4736//function : VOverlayText
4737//purpose : Test text displaying in view overlay
4738//=======================================================================
4739static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
4740{
4741 // get the active view
4742 Handle(V3d_View) aView = ViewerTest::CurrentView();
4743 if (aView.IsNull())
4744 {
4745 di << "No active view. Please call vinit.\n";
4746 return 1;
4747 }
4748 else if (argc < 4 || argc > 13)
4749 {
4750 di << "Use: " << argv[0];
4751 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
4752 di << "[background_color: R G B]\n";
4753 di << " height - pixel height of the text (default=10.0)\n";
4754 di << " font_name - name of font (default=courier)\n";
4755 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
a6eb515f 4756 di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n";
25289ec1 4757 di << " background_color- R G B values used for subtitle and decal text\n";
4758 di << "(default=255.0 255.0 255.0)\n";
4759 return 1;
4760 }
4fe56619 4761
25289ec1 4762 TCollection_AsciiString aText (argv[1]);
91322f44 4763 Standard_Real aPosX = Draw::Atof(argv[2]);
4764 Standard_Real aPosY = Draw::Atof(argv[3]);
4765 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
25289ec1 4766
4767 // font name
4768 TCollection_AsciiString aFontName = "Courier";
4769 if (argc >= 6)
4770 aFontName = TCollection_AsciiString (argv[5]);
4771
4772 // text colors
4773 Quantity_Parameter aColorRed = 1.0;
4774 Quantity_Parameter aColorGreen = 1.0;
4775 Quantity_Parameter aColorBlue = 1.0;
4776 if (argc >= 9)
4777 {
91322f44 4778 aColorRed = Draw::Atof (argv[6])/255.;
4779 aColorGreen = Draw::Atof (argv[7])/255.;
4780 aColorBlue = Draw::Atof (argv[8])/255.;
25289ec1 4781 }
4782
4783 // display type
4784 TCollection_AsciiString aDispStr;
4785 if (argc >= 10)
4786 aDispStr = TCollection_AsciiString (argv[9]);
4787
4788 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
4789 if (aDispStr.IsEqual ("subtitle"))
4790 aTextType = Aspect_TODT_SUBTITLE;
4791 else if (aDispStr.IsEqual ("decal"))
4792 aTextType = Aspect_TODT_DEKALE;
4793 else if (aDispStr.IsEqual ("blend"))
4794 aTextType = Aspect_TODT_BLEND;
a6eb515f 4795 else if (aDispStr.IsEqual ("dimension"))
4796 aTextType = Aspect_TODT_DIMENSION;
25289ec1 4797
4798 // subtitle color
4799 Quantity_Parameter aSubRed = 1.0;
4800 Quantity_Parameter aSubGreen = 1.0;
4801 Quantity_Parameter aSubBlue = 1.0;
4802 if (argc == 13)
4803 {
91322f44 4804 aSubRed = Draw::Atof (argv[10])/255.;
4805 aSubGreen = Draw::Atof (argv[11])/255.;
4806 aSubBlue = Draw::Atof (argv[12])/255.;
25289ec1 4807 }
4808
4809 // check fo current overlay
4810 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
4811 if (anOverlay.IsNull ())
4812 {
4813 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
4814 anOverlay = aMgr->Overlay ();
4815 aView->SetLayerMgr (aMgr);
4816 }
4817
4fe56619 4818 Quantity_Color aTextColor (aColorRed, aColorGreen,
25289ec1 4819 aColorBlue, Quantity_TOC_RGB);
4fe56619 4820 Quantity_Color aSubtColor (aSubRed, aSubGreen,
25289ec1 4821 aSubBlue, Quantity_TOC_RGB);
4822
4823 // add text item
4824 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
4825 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
4826
4827 // update view
4828 aView->MustBeResized();
4829 aView->Redraw();
4830
4831 return 0;
4832}
4833
2bd4c032 4834//==============================================================================
4835//function : VGrid
4836//purpose :
4837//==============================================================================
4838
35e08fe8 4839static int VGrid (Draw_Interpretor& /*theDI*/,
2bd4c032 4840 Standard_Integer theArgNb,
4841 const char** theArgVec)
4842{
4843 // get the active view
4844 Handle(V3d_View) aView = ViewerTest::CurrentView();
4845 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4846 if (aView.IsNull() || aViewer.IsNull())
4847 {
4848 std::cerr << "No active view. Please call vinit.\n";
4849 return 1;
4850 }
4851
4852 Aspect_GridType aType = aViewer->GridType();
4853 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
4854
4855 Standard_Integer anIter = 1;
4856 for (; anIter < theArgNb; ++anIter)
4857 {
4858 const char* aValue = theArgVec[anIter];
4859 if (*aValue == 'r')
4860 {
4861 aType = Aspect_GT_Rectangular;
4862 }
4863 else if (*aValue == 'c')
4864 {
4865 aType = Aspect_GT_Circular;
4866 }
4867 else if (*aValue == 'l')
4868 {
4869 aMode = Aspect_GDM_Lines;
4870 }
4871 else if (*aValue == 'p')
4872 {
4873 aMode = Aspect_GDM_Points;
4874 }
4875 else if (strcmp (aValue, "off" ) == 0)
4876 {
4877 aViewer->DeactivateGrid();
4878 return 0;
4879 }
4880 else
4881 {
4882 break;
4883 }
4884 }
4885
4886 Standard_Integer aTail = (theArgNb - anIter);
4887 if (aTail == 0)
4888 {
4889 aViewer->ActivateGrid (aType, aMode);
4890 return 0;
4891 }
4892 else if (aTail != 2 && aTail != 5)
4893 {
4894 std::cerr << "Incorrect arguments number! Usage:\n"
4895 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
4896 return 1;
4897 }
4898
4899 Quantity_Length anOriginX, anOriginY;
4900 Quantity_PlaneAngle aRotAngle;
4901 if (aType == Aspect_GT_Rectangular)
4902 {
4903 Quantity_Length aRStepX, aRStepY;
4904 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4905
91322f44 4906 anOriginX = Draw::Atof (theArgVec[anIter++]);
4907 anOriginY = Draw::Atof (theArgVec[anIter++]);
2bd4c032 4908 if (aTail == 5)
4909 {
91322f44 4910 aRStepX = Draw::Atof (theArgVec[anIter++]);
4911 aRStepY = Draw::Atof (theArgVec[anIter++]);
4912 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2bd4c032 4913 }
4914 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4915 aViewer->ActivateGrid (aType, aMode);
4916 }
4917 else if (aType == Aspect_GT_Circular)
4918 {
4919 Quantity_Length aRadiusStep;
4920 Standard_Integer aDivisionNumber;
4921 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4922
91322f44 4923 anOriginX = Draw::Atof (theArgVec[anIter++]);
4924 anOriginY = Draw::Atof (theArgVec[anIter++]);
2bd4c032 4925 if (aTail == 5)
4926 {
91322f44 4927 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
4928 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
4929 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2bd4c032 4930 }
4931
4932 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4933 aViewer->ActivateGrid (aType, aMode);
4934 }
4935
4936 return 0;
4937}
4938
c40b7d58 4939//==============================================================================
4940//function : VPriviledgedPlane
4941//purpose :
4942//==============================================================================
4943
4944static int VPriviledgedPlane (Draw_Interpretor& theDI,
4945 Standard_Integer theArgNb,
4946 const char** theArgVec)
4947{
4948 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
4949 {
4950 std::cerr << "Error: wrong number of arguments! See usage:\n";
4951 theDI.PrintHelp (theArgVec[0]);
4952 return 1;
4953 }
4954
4955 // get the active viewer
4956 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4957 if (aViewer.IsNull())
4958 {
4959 std::cerr << "Error: no active viewer. Please call vinit.\n";
4960 return 1;
4961 }
4962
4963 if (theArgNb == 1)
4964 {
4965 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
4966 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
4967 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
4968 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
4969 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
4970 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
4971 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
4972 return 0;
4973 }
4974
4975 Standard_Integer anArgIdx = 1;
4976 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
4977 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
4978 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
4979 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
4980 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
4981 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
4982
4983 gp_Ax3 aPriviledgedPlane;
4984 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
4985 gp_Dir aNorm (aNormX, aNormY, aNormZ);
4986 if (theArgNb > 7)
4987 {
4988 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
4989 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
4990 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
4991 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
4992 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
4993 }
4994 else
4995 {
4996 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
4997 }
4998
4999 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
5000
5001 return 0;
5002}
5003
f25b82d6 5004//==============================================================================
5005//function : VConvert
5006//purpose :
5007//==============================================================================
5008
5009static int VConvert (Draw_Interpretor& theDI,
5010 Standard_Integer theArgNb,
5011 const char** theArgVec)
5012{
5013 // get the active view
5014 Handle(V3d_View) aView = ViewerTest::CurrentView();
5015 if (aView.IsNull())
5016 {
c40b7d58 5017 std::cerr << "Error: no active view. Please call vinit.\n";
f25b82d6 5018 return 1;
5019 }
5020
5021 enum { Model, Ray, View, Window, Grid } aMode = Model;
5022
5023 // access coordinate arguments
5024 TColStd_SequenceOfReal aCoord;
5025 Standard_Integer anArgIdx = 1;
5026 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5027 {
5028 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5029 if (!anArg.IsRealValue())
5030 {
5031 break;
5032 }
5033 aCoord.Append (anArg.RealValue());
5034 }
5035
5036 // non-numeric argument too early
5037 if (aCoord.IsEmpty())
5038 {
5039 std::cerr << "Error: wrong number of arguments! See usage:\n";
5040 theDI.PrintHelp (theArgVec[0]);
5041 return 1;
5042 }
5043
5044 // collect all other arguments and options
5045 for (; anArgIdx < theArgNb; ++anArgIdx)
5046 {
5047 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5048 anArg.LowerCase();
5049 if (anArg == "window") aMode = Window;
5050 else if (anArg == "view") aMode = View;
5051 else if (anArg == "grid") aMode = Grid;
5052 else if (anArg == "ray") aMode = Ray;
5053 else
5054 {
5055 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5056 theDI.PrintHelp (theArgVec[0]);
5057 return 1;
5058 }
5059 }
5060
5061 // complete input checks
5062 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5063 (aCoord.Length() == 2 && theArgNb > 4) ||
5064 (aCoord.Length() == 3 && theArgNb > 5))
5065 {
5066 std::cerr << "Error: wrong number of arguments! See usage:\n";
5067 theDI.PrintHelp (theArgVec[0]);
5068 return 1;
5069 }
5070
5071 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5072 Standard_Integer aXYp[2] = {0, 0};
5073
5074 // convert one-dimensional coordinate
5075 if (aCoord.Length() == 1)
5076 {
5077 switch (aMode)
5078 {
5079 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer) aCoord (1)); return 0;
5080 case Window : theDI << "Window Vp: " << aView->Convert ((Quantity_Length) aCoord (1)); return 0;
5081 default:
5082 std::cerr << "Error: wrong arguments! See usage:\n";
5083 theDI.PrintHelp (theArgVec[0]);
5084 return 1;
5085 }
5086 }
5087
5088 // convert 2D coordinates from projection or view reference space
5089 if (aCoord.Length() == 2)
5090 {
5091 switch (aMode)
5092 {
5093 case Model :
5094 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5095 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5096 return 0;
5097
5098 case View :
5099 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5100 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5101 return 0;
5102
5103 case Window :
5104 aView->Convert ((V3d_Coordinate) aCoord (1), (V3d_Coordinate) aCoord (2), aXYp[0], aXYp[1]);
5105 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5106 return 0;
5107
5108 case Grid :
5109 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5110 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5111 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5112 return 0;
5113
5114 case Ray :
5115 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5116 (Standard_Integer) aCoord (2),
5117 aXYZ[0], aXYZ[1], aXYZ[2],
5118 aXYZ[3], aXYZ[4], aXYZ[5]);
5119 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5120 return 0;
5121
5122 default:
5123 std::cerr << "Error: wrong arguments! See usage:\n";
5124 theDI.PrintHelp (theArgVec[0]);
5125 return 1;
5126 }
5127 }
5128
5129 // convert 3D coordinates from view reference space
5130 else if (aCoord.Length() == 3)
5131 {
5132 switch (aMode)
5133 {
5134 case Window :
5135 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5136 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5137 return 0;
5138
5139 case Grid :
5140 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5141 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5142 return 0;
5143
5144 default:
5145 std::cerr << "Error: wrong arguments! See usage:\n";
5146 theDI.PrintHelp (theArgVec[0]);
5147 return 1;
5148 }
5149 }
5150
5151 return 0;
5152}
5153
208e6839 5154//==============================================================================
5155//function : VFps
5156//purpose :
5157//==============================================================================
5158
5159static int VFps (Draw_Interpretor& theDI,
5160 Standard_Integer theArgNb,
5161 const char** theArgVec)
5162{
5163 // get the active view
5164 Handle(V3d_View) aView = ViewerTest::CurrentView();
5165 if (aView.IsNull())
5166 {
5167 std::cerr << "No active view. Please call vinit.\n";
5168 return 1;
5169 }
5170
91322f44 5171 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
208e6839 5172 if (aFramesNb <= 0)
5173 {
5174 std::cerr << "Incorrect arguments!\n";
5175 return 1;
5176 }
5177
5178 // the time is meaningless for first call
5179 // due to async OpenGl rendering
5180 aView->Redraw();
5181
5182 // redraw view in loop to estimate average values
5183 OSD_Timer aTimer;
5184 aTimer.Start();
5185 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
5186 {
5187 aView->Redraw();
5188 }
5189 aTimer.Stop();
5190 Standard_Real aCpu;
5191 const Standard_Real aTime = aTimer.ElapsedTime();
5192 aTimer.OSD_Chronometer::Show (aCpu);
5193
5194 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
5195 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
5196
5197 // return statistics
5198 theDI << "FPS: " << aFpsAver << "\n"
5199 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5200
5201 return 0;
5202}
5203
58655684 5204//==============================================================================
5205//function : VGlDebug
5206//purpose :
5207//==============================================================================
5208
5209static int VGlDebug (Draw_Interpretor& theDI,
5210 Standard_Integer theArgNb,
5211 const char** theArgVec)
5212{
aaf512f1 5213 Handle(OpenGl_GraphicDriver) aDriver;
5214 Handle(V3d_View) aView = ViewerTest::CurrentView();
5215 if (!aView.IsNull())
5216 {
5217 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5218 }
58655684 5219 if (theArgNb < 2)
5220 {
aaf512f1 5221 if (aDriver.IsNull())
58655684 5222 {
5223 std::cerr << "No active view. Please call vinit.\n";
5224 return 0;
5225 }
5226
5227 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
5228 "GL_ARB_debug_output");
5229 std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
5230 theDI << (isActive ? "1" : "0");
5231 return 0;
5232 }
5233
aaf512f1 5234 const Standard_Boolean toEnableDebug = Draw::Atoi (theArgVec[1]) != 0;
5235 ViewerTest_myDefaultCaps.contextDebug = toEnableDebug;
5236 ViewerTest_myDefaultCaps.glslWarnings = toEnableDebug;
5237 if (aDriver.IsNull())
5238 {
5239 return 0;
5240 }
5241
5242 aDriver->ChangeOptions().glslWarnings = toEnableDebug;
58655684 5243 return 0;
5244}
208e6839 5245
5246//==============================================================================
5247//function : VVbo
5248//purpose :
5249//==============================================================================
5250
58655684 5251static int VVbo (Draw_Interpretor& theDI,
208e6839 5252 Standard_Integer theArgNb,
5253 const char** theArgVec)
5254{
58655684 5255 const Standard_Boolean toSet = (theArgNb > 1);
5256 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5257 if (toSet)
208e6839 5258 {
58655684 5259 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
208e6839 5260 }
5261
58655684 5262 // get the context
5263 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5264 if (aContextAIS.IsNull())
208e6839 5265 {
58655684 5266 if (!toSet)
5267 {
5268 std::cerr << "No active view!\n";
5269 }
208e6839 5270 return 1;
5271 }
58655684 5272 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5273 if (!aDriver.IsNull())
208e6839 5274 {
58655684 5275 if (!toSet)
5276 {
5277 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5278 }
5279 else
5280 {
5281 aDriver->ChangeOptions().vboDisable = toUseVbo;
5282 }
208e6839 5283 }
5284
208e6839 5285 return 0;
5286}
5287
a577aaab 5288//==============================================================================
5289//function : VCaps
5290//purpose :
5291//==============================================================================
5292
5293static int VCaps (Draw_Interpretor& theDI,
5294 Standard_Integer theArgNb,
5295 const char** theArgVec)
5296{
5297 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5298 Handle(OpenGl_GraphicDriver) aDriver;
8625ef7e 5299 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5300 if (!aContext.IsNull())
a577aaab 5301 {
8625ef7e 5302 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
a577aaab 5303 aCaps = &aDriver->ChangeOptions();
5304 }
5305
5306 if (theArgNb < 2)
5307 {
5308 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5309 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
abe46077 5310 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
8625ef7e 5311 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
4e1523ef 5312 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
a577aaab 5313 return 0;
5314 }
5315
8625ef7e 5316 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
a577aaab 5317 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5318 {
8625ef7e 5319 Standard_CString anArg = theArgVec[anArgIter];
5320 TCollection_AsciiString anArgCase (anArg);
5321 anArgCase.LowerCase();
5322 if (anUpdateTool.parseRedrawMode (anArg))
5323 {
5324 continue;
5325 }
5326 else if (anArgCase == "-ffp")
5327 {
5328 Standard_Boolean toEnable = Standard_True;
5329 if (++anArgIter < theArgNb
5330 && !parseOnOff (theArgVec[anArgIter], toEnable))
5331 {
5332 --anArgIter;
5333 }
5334 aCaps->ffpEnable = toEnable;
5335 }
5336 else if (anArgCase == "-vbo")
a577aaab 5337 {
8625ef7e 5338 Standard_Boolean toEnable = Standard_True;
5339 if (++anArgIter < theArgNb
5340 && !parseOnOff (theArgVec[anArgIter], toEnable))
5341 {
5342 --anArgIter;
5343 }
5344 aCaps->vboDisable = !toEnable;
a577aaab 5345 }
8625ef7e 5346 else if (anArgCase == "-sprite"
5347 || anArgCase == "-sprites")
a577aaab 5348 {
8625ef7e 5349 Standard_Boolean toEnable = Standard_True;
5350 if (++anArgIter < theArgNb
5351 && !parseOnOff (theArgVec[anArgIter], toEnable))
5352 {
5353 --anArgIter;
5354 }
5355 aCaps->pntSpritesDisable = !toEnable;
a577aaab 5356 }
8625ef7e 5357 else if (anArgCase == "-softmode")
abe46077 5358 {
8625ef7e 5359 Standard_Boolean toEnable = Standard_True;
5360 if (++anArgIter < theArgNb
5361 && !parseOnOff (theArgVec[anArgIter], toEnable))
5362 {
5363 --anArgIter;
5364 }
5365 aCaps->contextNoAccel = toEnable;
5366 }
5367 else if (anArgCase == "-accel"
5368 || anArgCase == "-acceleration")
5369 {
5370 Standard_Boolean toEnable = Standard_True;
5371 if (++anArgIter < theArgNb
5372 && !parseOnOff (theArgVec[anArgIter], toEnable))
5373 {
5374 --anArgIter;
5375 }
5376 aCaps->contextNoAccel = !toEnable;
abe46077 5377 }
4e1523ef 5378 else if (anArgCase == "-compat"
5379 || anArgCase == "-compatprofile"
5380 || anArgCase == "-compatible"
5381 || anArgCase == "-compatibleprofile")
5382 {
5383 Standard_Boolean toEnable = Standard_True;
5384 if (++anArgIter < theArgNb
5385 && !parseOnOff (theArgVec[anArgIter], toEnable))
5386 {
5387 --anArgIter;
5388 }
5389 aCaps->contextCompatible = toEnable;
5390 if (!aCaps->contextCompatible)
5391 {
5392 aCaps->ffpEnable = Standard_False;
5393 }
5394 }
5395 else if (anArgCase == "-core"
5396 || anArgCase == "-coreprofile")
5397 {
5398 Standard_Boolean toEnable = Standard_True;
5399 if (++anArgIter < theArgNb
5400 && !parseOnOff (theArgVec[anArgIter], toEnable))
5401 {
5402 --anArgIter;
5403 }
5404 aCaps->contextCompatible = !toEnable;
5405 if (!aCaps->contextCompatible)
5406 {
5407 aCaps->ffpEnable = Standard_False;
5408 }
5409 }
a577aaab 5410 else
5411 {
8625ef7e 5412 std::cout << "Error: unknown argument '" << anArg << "'\n";
5413 return 1;
a577aaab 5414 }
5415 }
5416 if (aCaps != &ViewerTest_myDefaultCaps)
5417 {
5418 ViewerTest_myDefaultCaps = *aCaps;
5419 }
5420 return 0;
5421}
5422
f0430952 5423//==============================================================================
5424//function : VMemGpu
5425//purpose :
5426//==============================================================================
5427
5428static int VMemGpu (Draw_Interpretor& theDI,
5429 Standard_Integer theArgNb,
5430 const char** theArgVec)
5431{
5432 // get the context
5433 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5434 if (aContextAIS.IsNull())
5435 {
5436 std::cerr << "No active view. Please call vinit.\n";
5437 return 1;
5438 }
5439
dc3fe572 5440 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
f0430952 5441 if (aDriver.IsNull())
5442 {
5443 std::cerr << "Graphic driver not available.\n";
5444 return 1;
5445 }
5446
5447 Standard_Size aFreeBytes = 0;
5448 TCollection_AsciiString anInfo;
5449 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
5450 {
5451 std::cerr << "Information not available.\n";
5452 return 1;
5453 }
5454
5455 if (theArgNb > 1 && *theArgVec[1] == 'f')
5456 {
5457 theDI << Standard_Real (aFreeBytes);
5458 }
5459 else
5460 {
5461 theDI << anInfo;
5462 }
5463
5464 return 0;
5465}
5466
85e096c3 5467// ==============================================================================
5468// function : VReadPixel
5469// purpose :
5470// ==============================================================================
5471static int VReadPixel (Draw_Interpretor& theDI,
5472 Standard_Integer theArgNb,
5473 const char** theArgVec)
5474{
5475 // get the active view
5476 Handle(V3d_View) aView = ViewerTest::CurrentView();
5477 if (aView.IsNull())
5478 {
5479 std::cerr << "No active view. Please call vinit.\n";
5480 return 1;
5481 }
5482 else if (theArgNb < 3)
5483 {
5484 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
5485 return 1;
5486 }
5487
692613e5 5488 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5489 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
5490
85e096c3 5491 Standard_Integer aWidth, aHeight;
5492 aView->Window()->Size (aWidth, aHeight);
91322f44 5493 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
5494 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
85e096c3 5495 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
5496 {
5497 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
5498 return 1;
5499 }
5500
5501 Standard_Boolean toShowName = Standard_False;
5502 Standard_Boolean toShowHls = Standard_False;
5503 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
5504 {
29cb310a 5505 const char* aParam = theArgVec[anIter];
5506 if ( strcasecmp( aParam, "rgb" ) == 0 )
85e096c3 5507 {
692613e5 5508 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5509 aBufferType = Graphic3d_BT_RGB;
85e096c3 5510 }
29cb310a 5511 else if ( strcasecmp( aParam, "hls" ) == 0 )
85e096c3 5512 {
692613e5 5513 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5514 aBufferType = Graphic3d_BT_RGB;
85e096c3 5515 toShowHls = Standard_True;
5516 }
29cb310a 5517 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
85e096c3 5518 {
692613e5 5519 aFormat = Image_PixMap::ImgRGBF;
5520 aBufferType = Graphic3d_BT_RGB;
85e096c3 5521 }
29cb310a 5522 else if ( strcasecmp( aParam, "rgba" ) == 0 )
85e096c3 5523 {
692613e5 5524 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5525 aBufferType = Graphic3d_BT_RGBA;
85e096c3 5526 }
29cb310a 5527 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
85e096c3 5528 {
692613e5 5529 aFormat = Image_PixMap::ImgRGBAF;
5530 aBufferType = Graphic3d_BT_RGBA;
85e096c3 5531 }
29cb310a 5532 else if ( strcasecmp( aParam, "depth" ) == 0 )
85e096c3 5533 {
692613e5 5534 aFormat = Image_PixMap::ImgGrayF;
5535 aBufferType = Graphic3d_BT_Depth;
85e096c3 5536 }
29cb310a 5537 else if ( strcasecmp( aParam, "name" ) == 0 )
85e096c3 5538 {
5539 toShowName = Standard_True;
5540 }
5541 }
5542
692613e5 5543 Image_PixMap anImage;
5544 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
5545 {
5546 std::cerr << "Image allocation failed\n";
5547 return 1;
5548 }
5549 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
85e096c3 5550 {
5551 std::cerr << "Image dump failed\n";
5552 return 1;
5553 }
5554
5555 Quantity_Parameter anAlpha;
692613e5 5556 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
85e096c3 5557 if (toShowName)
5558 {
692613e5 5559 if (aBufferType == Graphic3d_BT_RGBA)
85e096c3 5560 {
64c759f8 5561 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
85e096c3 5562 }
5563 else
5564 {
64c759f8 5565 theDI << Quantity_Color::StringName (aColor.Name());
85e096c3 5566 }
5567 }
5568 else
5569 {
5570 switch (aBufferType)
5571 {
5572 default:
692613e5 5573 case Graphic3d_BT_RGB:
85e096c3 5574 {
5575 if (toShowHls)
5576 {
64c759f8 5577 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
85e096c3 5578 }
5579 else
5580 {
64c759f8 5581 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
85e096c3 5582 }
5583 break;
5584 }
692613e5 5585 case Graphic3d_BT_RGBA:
85e096c3 5586 {
64c759f8 5587 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
85e096c3 5588 break;
5589 }
692613e5 5590 case Graphic3d_BT_Depth:
85e096c3 5591 {
64c759f8 5592 theDI << aColor.Red();
85e096c3 5593 break;
5594 }
5595 }
5596 }
5597
5598 return 0;
5599}
5600
692613e5 5601//==============================================================================
5602//function : VDiffImage
5603//purpose : The draw-command compares two images.
5604//==============================================================================
5605
5606static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
5607{
5608 if (theArgNb < 6)
5609 {
5610 theDI << "Not enough arguments.\n";
5611 return 1;
5612 }
5613
5614 // image file names
5615 const char* anImgPathRef = theArgVec[1];
5616 const char* anImgPathNew = theArgVec[2];
5617
5618 // get string tolerance and check its validity
91322f44 5619 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
692613e5 5620 if (aTolColor < 0.0)
5621 aTolColor = 0.0;
5622 if (aTolColor > 1.0)
5623 aTolColor = 1.0;
5624
91322f44 5625 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
5626 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
692613e5 5627
5628 // image file of difference
5629 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
5630
5631 // compare the images
5632 Image_Diff aComparer;
5633 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
5634 {
5635 return 1;
5636 }
5637
5638 aComparer.SetColorTolerance (aTolColor);
5639 aComparer.SetBorderFilterOn (isBorderFilterOn);
5640 Standard_Integer aDiffColorsNb = aComparer.Compare();
5641 theDI << aDiffColorsNb << "\n";
5642
5643 // save image of difference
936f43da 5644 if (aDiffColorsNb >0 && aDiffImagePath != NULL)
692613e5 5645 {
5646 aComparer.SaveDiffImage (aDiffImagePath);
5647 }
5648
5649 return 0;
5650}
5651
4754e164 5652//=======================================================================
5653//function : VSelect
5654//purpose : Emulates different types of selection by mouse:
5655// 1) single click selection
5656// 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
5657// 3) selection with polygon having corners at
dc3fe572 5658// pixel positions (x1,y1),...,(xn,yn)
4754e164 5659// 4) any of these selections with shift button pressed
5660//=======================================================================
5661static Standard_Integer VSelect (Draw_Interpretor& di,
5662 Standard_Integer argc,
5663 const char ** argv)
5664{
dc3fe572 5665 if(argc < 3)
4754e164 5666 {
5667 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
5668 return 1;
5669 }
5670
5671 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
dc3fe572 5672 if(myAIScontext.IsNull())
4754e164 5673 {
5674 di << "use 'vinit' command before " << argv[0] << "\n";
5675 return 1;
5676 }
5677 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
5678 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
5679 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
5680 if(argc <= 4)
5681 {
5682 if(isShiftSelection)
5683 aCurrentEventManager->ShiftSelect();
5684 else
5685 aCurrentEventManager->Select();
5686 }
5687 else if(argc <= 6)
5688 {
5689 if(isShiftSelection)
5690 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
5691 else
5692 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
5693 }
5694 else
5695 {
5696 Standard_Integer anUpper = 0;
5697
5698 if(isShiftSelection)
5699 anUpper = (argc-1)/2;
5700 else
5701 anUpper = argc/2;
5702 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
5703
5704 for(Standard_Integer i=1;i<=anUpper;++i)
5705 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
5706
5707 if(isShiftSelection)
5708 aCurrentEventManager->ShiftSelect(aPolyline);
5709 else
5710 aCurrentEventManager->Select(aPolyline);
5711 }
5712 return 0;
5713}
5714
5715//=======================================================================
5716//function : VMoveTo
dc3fe572 5717//purpose : Emulates cursor movement to defined pixel position
4754e164 5718//=======================================================================
5719static Standard_Integer VMoveTo (Draw_Interpretor& di,
5720 Standard_Integer argc,
5721 const char ** argv)
5722{
dc3fe572 5723 if(argc != 3)
4754e164 5724 {
5725 di << "Usage : " << argv[0] << " x y" << "\n";
5726 return 1;
5727 }
5728
5729 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
dc3fe572 5730 if(aContext.IsNull())
4754e164 5731 {
5732 di << "use 'vinit' command before " << argv[0] << "\n";
5733 return 1;
5734 }
5735 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
5736 return 0;
5737}
5738
197ac94e 5739//=================================================================================================
4754e164 5740//function : VViewParams
dc3fe572 5741//purpose : Gets or sets AIS View characteristics
197ac94e 5742//=================================================================================================
5743static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4754e164 5744{
197ac94e 5745 Handle(V3d_View) anAISView = ViewerTest::CurrentView();
5746 if (anAISView.IsNull())
4754e164 5747 {
197ac94e 5748 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
4754e164 5749 return 1;
5750 }
197ac94e 5751
5752 if (theArgsNb == 1)
4754e164 5753 {
197ac94e 5754 // print all of the available view parameters
5755 Quantity_Factor anAISViewScale = anAISView->Scale();
5756
4754e164 5757 Standard_Real anAISViewProjX = 0.0;
5758 Standard_Real anAISViewProjY = 0.0;
5759 Standard_Real anAISViewProjZ = 0.0;
197ac94e 5760 anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
5761
4754e164 5762 Standard_Real anAISViewUpX = 0.0;
5763 Standard_Real anAISViewUpY = 0.0;
5764 Standard_Real anAISViewUpZ = 0.0;
197ac94e 5765 anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
5766
4754e164 5767 Standard_Real anAISViewAtX = 0.0;
5768 Standard_Real anAISViewAtY = 0.0;
5769 Standard_Real anAISViewAtZ = 0.0;
197ac94e 5770 anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
5771
5772 Standard_Real anAISViewEyeX = 0.0;
5773 Standard_Real anAISViewEyeY = 0.0;
5774 Standard_Real anAISViewEyeZ = 0.0;
5775 anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ);
5776
5777 theDi << "Scale of current view: " << anAISViewScale << "\n";
5778 theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
5779 theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
5780 theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
5781 theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n";
5782 return 0;
4754e164 5783 }
197ac94e 5784
5785 // -------------------------
5786 // Parse options and values
5787 // -------------------------
5788
900f7229 5789 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues;
197ac94e 5790 TCollection_AsciiString aParseKey;
5791 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5792 {
5793 TCollection_AsciiString anArg (theArgVec [anArgIt]);
5794
5795 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
5796 {
5797 aParseKey = anArg;
5798 aParseKey.Remove (1);
5799 aParseKey.UpperCase();
900f7229 5800 aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
197ac94e 5801 continue;
5802 }
5803
3dfe95cd 5804 if (aParseKey.IsEmpty())
5805 {
5806 std::cout << theArgVec[0] << ": values should be passed with key.\n";
5807 std::cout << "Type help for more information.\n";
5808 return 1;
5809 }
5810
900f7229 5811 aMapOfKeysByValues(aParseKey)->Append (anArg);
197ac94e 5812 }
5813
5814 // ---------------------------------------------
5815 // Change or print parameters, order plays role
5816 // ---------------------------------------------
5817
5818 // Check arguments for validity
900f7229 5819 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues);
197ac94e 5820 for (; aMapIt.More(); aMapIt.Next())
4754e164 5821 {
197ac94e 5822 const TCollection_AsciiString& aKey = aMapIt.Key();
900f7229 5823 const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value();
5824
5825 if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5826 && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5827 && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty()))
5828 && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty()))
5829 && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty()))
5830 && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty()))
5831 && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2))
197ac94e 5832 {
5833 TCollection_AsciiString aLowerKey;
5834 aLowerKey = "-";
5835 aLowerKey += aKey;
5836 aLowerKey.LowerCase();
5837 std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n";
5838 std::cout << "Type help for more information.\n";
5839 return 1;
5840 }
4754e164 5841 }
197ac94e 5842
900f7229 5843 Handle(TColStd_HSequenceOfAsciiString) aValues;
197ac94e 5844
5845 // Change view parameters in proper order
5846 if (aMapOfKeysByValues.Find ("SCALE", aValues))
5847 {
900f7229 5848 if (aValues->IsEmpty())
197ac94e 5849 {
5850 theDi << "Scale: " << anAISView->Scale() << "\n";
5851 }
5852 else
5853 {
900f7229 5854 anAISView->SetScale (aValues->Value(1).RealValue());
197ac94e 5855 }
5856 }
3dfe95cd 5857 if (aMapOfKeysByValues.Find ("SIZE", aValues))
5858 {
900f7229 5859 if (aValues->IsEmpty())
3dfe95cd 5860 {
5861 Standard_Real aSizeX = 0.0;
5862 Standard_Real aSizeY = 0.0;
5863 anAISView->Size (aSizeX, aSizeY);
5864 theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n";
5865 }
5866 else
5867 {
900f7229 5868 anAISView->SetSize (aValues->Value(1).RealValue());
3dfe95cd 5869 }
5870 }
197ac94e 5871 if (aMapOfKeysByValues.Find ("EYE", aValues))
5872 {
900f7229 5873 if (aValues->IsEmpty())
197ac94e 5874 {
5875 Standard_Real anEyeX = 0.0;
5876 Standard_Real anEyeY = 0.0;
5877 Standard_Real anEyeZ = 0.0;
5878 anAISView->Eye (anEyeX, anEyeY, anEyeZ);
5879 theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n";
5880 }
5881 else
5882 {
900f7229 5883 anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
197ac94e 5884 }
5885 }
5886 if (aMapOfKeysByValues.Find ("AT", aValues))
5887 {
900f7229 5888 if (aValues->IsEmpty())
197ac94e 5889 {
5890 Standard_Real anAtX = 0.0;
5891 Standard_Real anAtY = 0.0;
5892 Standard_Real anAtZ = 0.0;
5893 anAISView->At (anAtX, anAtY, anAtZ);
5894 theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n";
5895 }
5896 else
5897 {
900f7229 5898 anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
197ac94e 5899 }
5900 }
5901 if (aMapOfKeysByValues.Find ("PROJ", aValues))
5902 {
900f7229 5903 if (aValues->IsEmpty())
197ac94e 5904 {
5905 Standard_Real aProjX = 0.0;
5906 Standard_Real aProjY = 0.0;
5907 Standard_Real aProjZ = 0.0;
5908 anAISView->Proj (aProjX, aProjY, aProjZ);
5909 theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n";
5910 }
5911 else
5912 {
900f7229 5913 anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
197ac94e 5914 }
5915 }
5916 if (aMapOfKeysByValues.Find ("UP", aValues))
5917 {
900f7229 5918 if (aValues->IsEmpty())
197ac94e 5919 {
5920 Standard_Real anUpX = 0.0;
5921 Standard_Real anUpY = 0.0;
5922 Standard_Real anUpZ = 0.0;
5923 anAISView->Up (anUpX, anUpY, anUpZ);
5924 theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n";
5925 }
5926 else
5927 {
900f7229 5928 anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
197ac94e 5929 }
5930 }
5931 if (aMapOfKeysByValues.Find ("CENTER", aValues))
5932 {
900f7229 5933 anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue());
197ac94e 5934 }
5935
4754e164 5936 return 0;
5937}
5938
5939//=======================================================================
5940//function : VChangeSelected
dc3fe572 5941//purpose : Adds the shape to selection or remove one from it
4754e164 5942//=======================================================================
5943static Standard_Integer VChangeSelected (Draw_Interpretor& di,
5944 Standard_Integer argc,
5945 const char ** argv)
5946{
5947 if(argc != 2)
5948 {
5949 di<<"Usage : " << argv[0] << " shape \n";
5950 return 1;
5951 }
5952 //get AIS_Shape:
5953 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5954 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5955 TCollection_AsciiString aName(argv[1]);
5956 Handle(AIS_InteractiveObject) anAISObject;
5957
5958 if(!aMap.IsBound2(aName))
5959 {
5960 di<<"Use 'vdisplay' before";
5961 return 1;
5962 }
5963 else
5964 {
5965 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
5966 if(anAISObject.IsNull()){
5967 di<<"No interactive object \n";
5968 return 1;
5969 }
5970
5971 if(aContext->HasOpenedContext())
5972 {
5973 aContext->AddOrRemoveSelected(anAISObject);
5974 }
dc3fe572 5975 else
4754e164 5976 {
5977 aContext->AddOrRemoveCurrentObject(anAISObject);
5978 }
5979 }
5980 return 0;
5981}
5982
5983//=======================================================================
5984//function : VZClipping
dc3fe572 5985//purpose : Gets or sets ZClipping mode, width and depth
4754e164 5986//=======================================================================
5987static Standard_Integer VZClipping (Draw_Interpretor& di,
5988 Standard_Integer argc,
5989 const char ** argv)
5990{
dc3fe572 5991 if(argc>4)
4754e164 5992 {
5993 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
5994 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
5995 return -1;
5996 }
5997 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
dc3fe572 5998 if(aContext.IsNull())
4754e164 5999 {
6000 di << "use 'vinit' command before " << argv[0] << "\n";
6001 return 1;
6002 }
6003 Handle(V3d_View) aView = ViewerTest::CurrentView();
1d47d8d0 6004 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
4754e164 6005 if(argc==1)
6006 {
6007 TCollection_AsciiString aZClippingModeString;
6008 Quantity_Length aDepth, aWidth;
6009 aZClippingMode = aView->ZClipping(aDepth, aWidth);
6010 switch (aZClippingMode)
6011 {
6012 case V3d_OFF:
6013 aZClippingModeString.Copy("OFF");
6014 break;
6015 case V3d_BACK:
6016 aZClippingModeString.Copy("BACK");
6017 break;
6018 case V3d_FRONT:
6019 aZClippingModeString.Copy("FRONT");
6020 break;
6021 case V3d_SLICE:
6022 aZClippingModeString.Copy("SLICE");
6023 break;
6024 default:
6025 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
6026 break;
6027 }
6028 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
6029 << "ZClipping depth = " << aDepth << "\n"
6030 << "ZClipping width = " << aWidth << "\n";
6031 }
6032 else
6033 {
6034 if(argc !=3)
6035 {
6036 Standard_Integer aStatus = 0;
6037 if ( strcmp (argv [1], "OFF") == 0 ) {
6038 aStatus = 1;
6039 aZClippingMode = V3d_OFF;
6040 }
6041 if ( strcmp (argv [1], "BACK") == 0 ) {
6042 aStatus = 1;
6043 aZClippingMode = V3d_BACK;
6044 }
6045 if ( strcmp (argv [1], "FRONT") == 0 ) {
6046 aStatus = 1;
6047 aZClippingMode = V3d_FRONT;
6048 }
6049 if ( strcmp (argv [1], "SLICE") == 0 ) {
6050 aStatus = 1;
6051 aZClippingMode = V3d_SLICE;
6052 }
6053 if (aStatus != 1)
6054 {
6055 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6056 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6057 return 1;
dc3fe572 6058 }
4754e164 6059 aView->SetZClippingType(aZClippingMode);
6060 }
6061 if(argc >2)
6062 {
6063 Quantity_Length aDepth = 0., aWidth = 1.;
6064 if(argc == 3)
6065 {
6b62b2da 6066 aDepth = Draw::Atof (argv[1]);
6067 aWidth = Draw::Atof (argv[2]);
4754e164 6068 }
6069 else if(argc == 4)
6070 {
6b62b2da 6071 aDepth = Draw::Atof (argv[2]);
6072 aWidth = Draw::Atof (argv[3]);
4754e164 6073 }
dc3fe572 6074
4754e164 6075 if(aDepth<0. || aDepth>1.)
6076 {
6077 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6078 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6079 return 1;
6080 }
6081 if(aWidth<0. || aWidth>1.)
6082 {
6083 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6084 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6085 return 1;
6086 }
6087
6088 aView->SetZClippingDepth(aDepth);
6089 aView->SetZClippingWidth(aWidth);
6090 }
6091 aView->Redraw();
6092 }
6093 return 0;
6094}
6095
6096//=======================================================================
6097//function : VNbSelected
dc3fe572 6098//purpose : Returns number of selected objects
4754e164 6099//=======================================================================
6100static Standard_Integer VNbSelected (Draw_Interpretor& di,
6101 Standard_Integer argc,
6102 const char ** argv)
6103{
6104 if(argc != 1)
6105 {
6106 di << "Usage : " << argv[0] << "\n";
6107 return 1;
6108 }
6109 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6110 if(aContext.IsNull())
6111 {
6112 di << "use 'vinit' command before " << argv[0] << "\n";
6113 return 1;
6114 }
6115 di << aContext->NbSelected() << "\n";
6116 return 0;
6117}
6118
6119//=======================================================================
6120//function : VAntialiasing
dc3fe572 6121//purpose : Switches altialiasing on or off
4754e164 6122//=======================================================================
6123static Standard_Integer VAntialiasing (Draw_Interpretor& di,
6124 Standard_Integer argc,
6125 const char ** argv)
6126{
6127 if(argc > 2)
6128 {
6129 di << "Usage : " << argv[0] << " [1|0]" << "\n";
6130 return 1;
6131 }
6132
6133 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6134 if(aContext.IsNull())
6135 {
6136 di << "use 'vinit' command before " << argv[0] << "\n";
6137 return 1;
6138 }
6139
6140 Handle(V3d_View) aView = ViewerTest::CurrentView();
6141
6142 if((argc == 2) && (atof(argv[1]) == 0))
6143 aView->SetAntialiasingOff();
6144 else
6145 aView->SetAntialiasingOn();
6146 aView->Update();
6147 return 0;
6148}
6149
6150//=======================================================================
6151//function : VPurgeDisplay
dc3fe572 6152//purpose : Switches altialiasing on or off
4754e164 6153//=======================================================================
6154static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
6155 Standard_Integer argc,
6156 const char ** argv)
6157{
eb4320f2 6158 if (argc > 1)
4754e164 6159 {
eb4320f2 6160 di << "Usage : " << argv[0] << "\n";
4754e164 6161 return 1;
6162 }
4754e164 6163 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6164 if (aContext.IsNull())
6165 {
6166 di << "use 'vinit' command before " << argv[0] << "\n";
6167 return 1;
6168 }
6169 aContext->CloseAllContexts(Standard_False);
eb4320f2 6170 di << aContext->PurgeDisplay() << "\n";
4754e164 6171 return 0;
6172}
6173
6174//=======================================================================
6175//function : VSetViewSize
6176//purpose :
6177//=======================================================================
6178static Standard_Integer VSetViewSize (Draw_Interpretor& di,
6179 Standard_Integer argc,
6180 const char ** argv)
6181{
6182 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6183 if(aContext.IsNull())
6184 {
6185 di << "use 'vinit' command before " << argv[0] << "\n";
6186 return 1;
6187 }
6188 if(argc != 2)
6189 {
6190 di<<"Usage : " << argv[0] << " Size\n";
6191 return 1;
6192 }
6b62b2da 6193 Standard_Real aSize = Draw::Atof (argv[1]);
4754e164 6194 if (aSize <= 0.)
6195 {
6196 di<<"Bad Size value : " << aSize << "\n";
6197 return 1;
6198 }
6199
6200 Handle(V3d_View) aView = ViewerTest::CurrentView();
6201 aView->SetSize(aSize);
6202 return 0;
6203}
6204
6205//=======================================================================
6206//function : VMoveView
6207//purpose :
6208//=======================================================================
6209static Standard_Integer VMoveView (Draw_Interpretor& di,
6210 Standard_Integer argc,
6211 const char ** argv)
6212{
6213 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6214 if(aContext.IsNull())
6215 {
6216 di << "use 'vinit' command before " << argv[0] << "\n";
6217 return 1;
6218 }
6219 if(argc < 4 || argc > 5)
6220 {
6221 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6222 return 1;
6223 }
6b62b2da 6224 Standard_Real Dx = Draw::Atof (argv[1]);
6225 Standard_Real Dy = Draw::Atof (argv[2]);
6226 Standard_Real Dz = Draw::Atof (argv[3]);
4754e164 6227 Standard_Boolean aStart = Standard_True;
6228 if (argc == 5)
6229 {
6b62b2da 6230 aStart = (Draw::Atoi (argv[4]) > 0);
4754e164 6231 }
6232
6233 Handle(V3d_View) aView = ViewerTest::CurrentView();
6234 aView->Move(Dx,Dy,Dz,aStart);
6235 return 0;
6236}
6237
6238//=======================================================================
6239//function : VTranslateView
6240//purpose :
6241//=======================================================================
6242static Standard_Integer VTranslateView (Draw_Interpretor& di,
6243 Standard_Integer argc,
6244 const char ** argv)
6245{
6246 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6247 if(aContext.IsNull())
6248 {
6249 di << "use 'vinit' command before " << argv[0] << "\n";
6250 return 1;
6251 }
6252 if(argc < 4 || argc > 5)
6253 {
6254 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6255 return 1;
6256 }
6b62b2da 6257 Standard_Real Dx = Draw::Atof (argv[1]);
6258 Standard_Real Dy = Draw::Atof (argv[2]);
6259 Standard_Real Dz = Draw::Atof (argv[3]);
4754e164 6260 Standard_Boolean aStart = Standard_True;
dc3fe572 6261 if (argc == 5)
4754e164 6262 {
6b62b2da 6263 aStart = (Draw::Atoi (argv[4]) > 0);
4754e164 6264 }
6265
6266 Handle(V3d_View) aView = ViewerTest::CurrentView();
6267 aView->Translate(Dx,Dy,Dz,aStart);
6268 return 0;
6269}
6270
6271//=======================================================================
6272//function : VTurnView
6273//purpose :
6274//=======================================================================
6275static Standard_Integer VTurnView (Draw_Interpretor& di,
6276 Standard_Integer argc,
6277 const char ** argv)
6278{
6279 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6280 if(aContext.IsNull()) {
6281 di << "use 'vinit' command before " << argv[0] << "\n";
6282 return 1;
6283 }
6284 if(argc < 4 || argc > 5){
6285 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
6286 return 1;
6287 }
6b62b2da 6288 Standard_Real Ax = Draw::Atof (argv[1]);
6289 Standard_Real Ay = Draw::Atof (argv[2]);
6290 Standard_Real Az = Draw::Atof (argv[3]);
4754e164 6291 Standard_Boolean aStart = Standard_True;
dc3fe572 6292 if (argc == 5)
4754e164 6293 {
6b62b2da 6294 aStart = (Draw::Atoi (argv[4]) > 0);
4754e164 6295 }
6296
6297 Handle(V3d_View) aView = ViewerTest::CurrentView();
6298 aView->Turn(Ax,Ay,Az,aStart);
6299 return 0;
6300}
6301
269294d6 6302//==============================================================================
6303//function : VTextureEnv
6304//purpose : ENables or disables environment mapping
6305//==============================================================================
6306class OCC_TextureEnv : public Graphic3d_TextureEnv
6307{
6308public:
6309 OCC_TextureEnv(const Standard_CString FileName);
6310 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
6311 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
6312 const Standard_Boolean theModulateFlag,
6313 const Graphic3d_TypeOfTextureFilter theFilter,
6314 const Standard_ShortReal theXScale,
6315 const Standard_ShortReal theYScale,
6316 const Standard_ShortReal theXShift,
6317 const Standard_ShortReal theYShift,
6318 const Standard_ShortReal theAngle);
6319 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
6320};
6321DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
6322IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
6323IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
6324
6325OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
6326 : Graphic3d_TextureEnv(theFileName)
6327{
6328}
6329
6330OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
6331 : Graphic3d_TextureEnv(theTexId)
6332{
6333}
6334
6335void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
6336 const Standard_Boolean theModulateFlag,
6337 const Graphic3d_TypeOfTextureFilter theFilter,
6338 const Standard_ShortReal theXScale,
6339 const Standard_ShortReal theYScale,
6340 const Standard_ShortReal theXShift,
6341 const Standard_ShortReal theYShift,
6342 const Standard_ShortReal theAngle)
6343{
6344 myParams->SetRepeat (theRepeatFlag);
6345 myParams->SetModulate (theModulateFlag);
6346 myParams->SetFilter (theFilter);
6347 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
6348 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
6349 myParams->SetRotation (theAngle);
6350}
6351
35e08fe8 6352static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
269294d6 6353{
6354 // get the active view
6355 Handle(V3d_View) aView = ViewerTest::CurrentView();
6356 if (aView.IsNull())
6357 {
6358 std::cerr << "No active view. Please call vinit.\n";
6359 return 1;
6360 }
6361
6362 // Checking the input arguments
6363 Standard_Boolean anEnableFlag = Standard_False;
6364 Standard_Boolean isOk = theArgNb >= 2;
6365 if (isOk)
6366 {
6367 TCollection_AsciiString anEnableOpt(theArgVec[1]);
6368 anEnableFlag = anEnableOpt.IsEqual("on");
6369 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
6370 }
6371 if (anEnableFlag)
6372 {
6373 isOk = (theArgNb == 3 || theArgNb == 11);
6374 if (isOk)
6375 {
6376 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6377 isOk = (!aTextureOpt.IsIntegerValue() ||
6378 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
6379
6380 if (isOk && theArgNb == 11)
6381 {
6382 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
6383 aModulateOpt(theArgVec[4]),
6384 aFilterOpt (theArgVec[5]),
6385 aSScaleOpt (theArgVec[6]),
6386 aTScaleOpt (theArgVec[7]),
6387 aSTransOpt (theArgVec[8]),
6388 aTTransOpt (theArgVec[9]),
6389 anAngleOpt (theArgVec[10]);
6390 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
6391 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
6392 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
6393 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
6394 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
6395 anAngleOpt.IsRealValue());
6396 }
6397 }
6398 }
6399
6400 if (!isOk)
6401 {
6402 std::cerr << "Usage :" << std::endl;
6403 std::cerr << theArgVec[0] << " off" << std::endl;
6404 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;
6405 return 1;
6406 }
6407
6408 if (anEnableFlag)
6409 {
6410 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6411 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
6412 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
6413 new OCC_TextureEnv(theArgVec[2]);
6414
6415 if (theArgNb == 11)
6416 {
6417 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
6418 aTexEnv->SetTextureParameters(
6419 aRepeatOpt. IsEqual("repeat"),
6420 aModulateOpt.IsEqual("modulate"),
6421 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
6422 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
6423 Graphic3d_TOTF_TRILINEAR,
6424 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
6425 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
6426 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
6427 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
6428 (Standard_ShortReal)Draw::Atof(theArgVec[10])
6429 );
6430 }
6431 aView->SetTextureEnv(aTexEnv);
6432 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
6433 }
6434 else // Disabling environment mapping
6435 {
6436 aView->SetSurfaceDetail(V3d_TEX_NONE);
6437 Handle(Graphic3d_TextureEnv) aTexture;
6438 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
6439 }
6440
6441 aView->Redraw();
6442 return 0;
6443}
6444
4269bd1b 6445//===============================================================================================
6446//function : VClipPlane
6447//purpose :
6448//===============================================================================================
6449static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6450{
6451 // use short-cut for created clip planes map of created (or "registered by name") clip planes
6452 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
6453 static MapOfPlanes aRegPlanes;
6454
6455 if (theArgsNb < 2)
6456 {
6457 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
6458 return 1;
6459 }
6460
6461 TCollection_AsciiString aCommand (theArgVec[1]);
6462
6463 // print maximum number of planes for current viewer
6464 if (aCommand == "maxplanes")
6465 {
6466 if (theArgsNb < 3)
6467 {
6468 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
6469 return 1;
6470 }
6471
6472 TCollection_AsciiString aViewName (theArgVec[2]);
6473
6474 if (!ViewerTest_myViews.IsBound1 (aViewName))
6475 {
6476 theDi << theArgVec[0] << ": view is not found.\n";
6477 return 1;
6478 }
6479
6480 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
6481
6482 theDi << theArgVec[0] << ": "
6483 << aView->Viewer()->Driver()->InquirePlaneLimit()
6484 << " plane slots provided by driver."
6485 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
6486
6487 return 0;
6488 }
6489
6490 // create / delete plane instance
6491 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
6492 {
6493 if (theArgsNb < 3)
6494 {
6495 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
6496 return 1;
6497 }
6498
6499 Standard_Boolean toCreate = (aCommand == "create");
6500 Standard_Boolean toClone = (aCommand == "clone");
6501 TCollection_AsciiString aPlane (theArgVec[2]);
6502
6503 if (toCreate)
6504 {
6505 if (aRegPlanes.IsBound (aPlane))
6506 {
6507 theDi << theArgVec[0] << ": plane name is in use.\n";
6508 return 1;
6509 }
6510
6511 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
6512 }
6513 else if (toClone) // toClone
6514 {
6515 if (!aRegPlanes.IsBound (aPlane))
6516 {
6517 theDi << theArgVec[0] << ": no such plane.\n";
6518 return 1;
6519 }
6520
6521 if (theArgsNb < 4)
6522 {
6523 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
6524 return 1;
6525 }
6526
6527 TCollection_AsciiString aClone (theArgVec[3]);
6528 if (aRegPlanes.IsBound (aClone))
6529 {
6530 theDi << theArgVec[0] << ": plane name is in use.\n";
6531 return 1;
6532 }
6533
6534 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6535
6536 aRegPlanes.Bind (aClone, aClipPlane->Clone());
6537 }
6538 else// toDelete
6539 {
6540 if (!aRegPlanes.IsBound (aPlane))
6541 {
6542 theDi << theArgVec[0] << ": no such plane.\n";
6543 return 1;
6544 }
6545
6546 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
6547 aRegPlanes.UnBind (aPlane);
6548
6549 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
6550 for (; anIObjIt.More(); anIObjIt.Next())
6551 {
6552 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
6553 aPrs->RemoveClipPlane(aClipPlane);
6554 }
6555
6556 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
6557 for (; aViewIt.More(); aViewIt.Next())
6558 {
6559 const Handle(V3d_View)& aView = aViewIt.Key2();
6560 aView->RemoveClipPlane(aClipPlane);
6561 }
6562
6563 ViewerTest::RedrawAllViews();
6564 }
6565
6566 return 0;
6567 }
6568
6569 // set / unset plane command
6570 if (aCommand == "set" || aCommand == "unset")
6571 {
6572 if (theArgsNb < 4)
6573 {
6574 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6575 return 1;
6576 }
6577
6578 Standard_Boolean toSet = (aCommand == "set");
6579 TCollection_AsciiString aPlane (theArgVec [2]);
6580 if (!aRegPlanes.IsBound (aPlane))
6581 {
6582 theDi << theArgVec[0] << ": no such plane.\n";
6583 return 1;
6584 }
6585
6586 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6587
6588 TCollection_AsciiString aTarget (theArgVec [3]);
6589 if (aTarget != "object" && aTarget != "view")
6590 {
6591 theDi << theArgVec[0] << ": invalid target.\n";
6592 return 1;
6593 }
6594
6595 if (aTarget == "object" || aTarget == "view")
6596 {
6597 if (theArgsNb < 5)
6598 {
6599 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6600 return 1;
6601 }
6602
6603 Standard_Boolean isObject = (aTarget == "object");
6604
6605 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
6606 {
6607 TCollection_AsciiString anEntityName (theArgVec[anIt]);
6608 if (isObject) // to object
6609 {
6610 if (!GetMapOfAIS().IsBound2 (anEntityName))
6611 {
6612 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
6613 continue;
6614 }
6615
6616 Handle(AIS_InteractiveObject) aIObj =
6617 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
6618
6619 if (toSet)
6620 aIObj->AddClipPlane (aClipPlane);
6621 else
6622 aIObj->RemoveClipPlane (aClipPlane);
6623 }
6624 else // to view
6625 {
6626 if (!ViewerTest_myViews.IsBound1 (anEntityName))
6627 {
6628 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
6629 continue;
6630 }
6631
6632 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
6633 if (toSet)
6634 aView->AddClipPlane (aClipPlane);
6635 else
6636 aView->RemoveClipPlane (aClipPlane);
6637 }
6638 }
6639
6640 ViewerTest::RedrawAllViews();
6641 }
6642
6643 return 0;
6644 }
6645
6646 // change plane command
6647 if (aCommand == "change")
6648 {
6649 if (theArgsNb < 4)
6650 {
6651 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6652 return 1;
6653 }
6654
6655 TCollection_AsciiString aPlane (theArgVec [2]);
6656 if (!aRegPlanes.IsBound (aPlane))
6657 {
6658 theDi << theArgVec[0] << ": no such plane.\n";
6659 return 1;
6660 }
6661
6662 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6663
6664 TCollection_AsciiString aChangeArg (theArgVec [3]);
6665 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
6666 {
6667 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6668 return 1;
6669 }
6670
6671 if (aChangeArg == "on" || aChangeArg == "off") // on / off
6672 {
6673 aClipPlane->SetOn (aChangeArg == "on");
6674 }
6675 else if (aChangeArg == "equation") // change equation
6676 {
6677 if (theArgsNb < 8)
6678 {
6679 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6680 return 1;
6681 }
6682
6b62b2da 6683 Standard_Real aCoeffA = Draw::Atof (theArgVec [4]);
6684 Standard_Real aCoeffB = Draw::Atof (theArgVec [5]);
6685 Standard_Real aCoeffC = Draw::Atof (theArgVec [6]);
6686 Standard_Real aCoeffD = Draw::Atof (theArgVec [7]);
4269bd1b 6687 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
6688 }
6689 else if (aChangeArg == "capping") // change capping aspects
6690 {
6691 if (theArgsNb < 5)
6692 {
6693 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6694 return 1;
6695 }
6696
6697 TCollection_AsciiString aCappingArg (theArgVec [4]);
6698 if (aCappingArg != "on" && aCappingArg != "off" &&
6699 aCappingArg != "color" && aCappingArg != "texname" &&
6700 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
6701 aCappingArg != "texrotate" && aCappingArg != "hatch")
6702 {
6703 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6704 return 1;
6705 }
6706
6707 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
6708 {
6709 aClipPlane->SetCapping (aCappingArg == "on");
6710 }
6711 else if (aCappingArg == "color") // color aspect for capping
6712 {
6713 if (theArgsNb < 8)
6714 {
6715 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6716 return 1;
6717 }
6718
6b62b2da 6719 Standard_Real aRed = Draw::Atof (theArgVec [5]);
6720 Standard_Real aGrn = Draw::Atof (theArgVec [6]);
6721 Standard_Real aBlu = Draw::Atof (theArgVec [7]);
4269bd1b 6722
6723 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8aeeca44 6724 Quantity_Color aColor (aRed, aGrn, aBlu, Quantity_TOC_RGB);
6725 aMat.SetAmbientColor (aColor);
6726 aMat.SetDiffuseColor (aColor);
4269bd1b 6727 aClipPlane->SetCappingMaterial (aMat);
6728 }
6729 else if (aCappingArg == "texname") // texture name
6730 {
6731 if (theArgsNb < 6)
6732 {
6733 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6734 return 1;
6735 }
6736
6737 TCollection_AsciiString aTextureName (theArgVec [5]);
6738
6739 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
6740 if (!aTexture->IsDone ())
6741 {
6742 aClipPlane->SetCappingTexture (NULL);
6743 }
6744 else
6745 {
6746 aTexture->EnableModulate();
6747 aTexture->EnableRepeat();
6748 aClipPlane->SetCappingTexture (aTexture);
6749 }
6750 }
6751 else if (aCappingArg == "texscale") // texture scale
6752 {
6753 if (aClipPlane->CappingTexture().IsNull())
6754 {
6755 theDi << theArgVec[0] << ": no texture is set.\n";
6756 return 1;
6757 }
6758
6759 if (theArgsNb < 7)
6760 {
6761 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6762 return 1;
6763 }
6764
6765 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
6766 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
6767
6768 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
6769 }
6770 else if (aCappingArg == "texorigin") // texture origin
6771 {
6772 if (aClipPlane->CappingTexture().IsNull())
6773 {
6774 theDi << theArgVec[0] << ": no texture is set.\n";
6775 return 1;
6776 }
6777
6778 if (theArgsNb < 7)
6779 {
6780 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6781 return 1;
6782 }
6783
6784 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
6785 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
6786
6787 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
6788 }
6789 else if (aCappingArg == "texrotate") // texture rotation
6790 {
6791 if (aClipPlane->CappingTexture().IsNull())
6792 {
6793 theDi << theArgVec[0] << ": no texture is set.\n";
6794 return 1;
6795 }
6796
6797 if (theArgsNb < 6)
6798 {
6799 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6800 return 1;
6801 }
6802
6803 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
6804
6805 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
6806 }
6807 else if (aCappingArg == "hatch") // hatch style
6808 {
6809 if (theArgsNb < 6)
6810 {
6811 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6812 return 1;
6813 }
6814
6815 TCollection_AsciiString aHatchStr (theArgVec [5]);
6816 if (aHatchStr == "on")
6817 {
6818 aClipPlane->SetCappingHatchOn();
6819 }
6820 else if (aHatchStr == "off")
6821 {
6822 aClipPlane->SetCappingHatchOff();
6823 }
6824 else
6825 {
6826 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
6827 }
6828 }
6829 }
6830
6831 ViewerTest::RedrawAllViews();
6832
6833 return 0;
6834 }
6835
6836 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
6837 return 1;
6838}
6839
6840//===============================================================================================
6841//function : VSetTextureMode
6842//purpose :
6843//===============================================================================================
6844static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6845{
6846 if (theArgsNb < 3)
6847 {
6848 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
6849 return 1;
6850 }
6851
6852 TCollection_AsciiString aViewName (theArgVec[1]);
6853 if (!ViewerTest_myViews.IsBound1 (aViewName))
6854 {
6855 theDi << theArgVec[0] << ": view is not found.\n";
6856 return 1;
6857 }
6858
6859 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
6860 switch (atoi (theArgVec[2]))
6861 {
6862 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
6863 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
6864 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
6865 default:
6866 theDi << theArgVec[0] << ": invalid mode.\n";
6867 return 1;
6868 }
6869
6870 aView->Redraw();
6871 return 0;
6872}
6873
b5ac8292 6874//===============================================================================================
6875//function : VZRange
6876//purpose :
6877//===============================================================================================
6878static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6879{
197ac94e 6880 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
6881
6882 if (aCurrentView.IsNull())
b5ac8292 6883 {
197ac94e 6884 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
b5ac8292 6885 return 1;
6886 }
6887
197ac94e 6888 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
b5ac8292 6889
6890 if (theArgsNb < 2)
6891 {
6892 theDi << "ZNear: " << aCamera->ZNear() << "\n";
6893 theDi << "ZFar: " << aCamera->ZFar() << "\n";
6894 return 0;
6895 }
6896
6897 if (theArgsNb == 3)
6898 {
6b62b2da 6899 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
6900 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
197ac94e 6901
6902 if (aNewZNear >= aNewZFar)
6903 {
6904 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
6905 return 1;
6906 }
6907
6908 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
6909 {
6910 std::cout << theArgVec[0] << ": invalid arguments: ";
6911 std::cout << "znear, zfar should be positive for perspective camera.\n";
6912 return 1;
6913 }
6914
6915 aCamera->SetZRange (aNewZNear, aNewZFar);
b5ac8292 6916 }
6917 else
6918 {
197ac94e 6919 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
b5ac8292 6920 return 1;
6921 }
6922
197ac94e 6923 aCurrentView->Redraw();
6924
b5ac8292 6925 return 0;
6926}
6927
6928//===============================================================================================
6929//function : VAutoZFit
6930//purpose :
6931//===============================================================================================
6932static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6933{
197ac94e 6934 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
6935
6936 if (aCurrentView.IsNull())
b5ac8292 6937 {
197ac94e 6938 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
b5ac8292 6939 return 1;
6940 }
6941
6bc6a6fc 6942 Standard_Real aScale = aCurrentView->View()->AutoZFitScaleFactor();
197ac94e 6943
6944 if (theArgsNb > 3)
b5ac8292 6945 {
197ac94e 6946 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
6947 return 1;
b5ac8292 6948 }
6949
197ac94e 6950 if (theArgsNb < 2)
b5ac8292 6951 {
197ac94e 6952 theDi << "Auto z-fit mode: " << "\n"
6bc6a6fc 6953 << "On: " << (aCurrentView->View()->AutoZFitMode() ? "enabled" : "disabled") << "\n"
197ac94e 6954 << "Scale: " << aScale << "\n";
6955 return 0;
b5ac8292 6956 }
197ac94e 6957
6958 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
6959
6960 if (theArgsNb >= 3)
b5ac8292 6961 {
197ac94e 6962 aScale = Draw::Atoi (theArgVec[2]);
b5ac8292 6963 }
6964
6bc6a6fc 6965 aCurrentView->View()->SetAutoZFitMode (isOn, aScale);
6966 aCurrentView->View()->AutoZFit();
197ac94e 6967 aCurrentView->Redraw();
6968
b5ac8292 6969 return 0;
6970}
6971
6b62b2da 6972//! Auxiliary function to print projection type
6973inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
6974{
6975 switch (theProjType)
6976 {
6977 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
6978 case Graphic3d_Camera::Projection_Perspective: return "perspective";
6979 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
6980 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
6981 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
6982 }
6983 return "UNKNOWN";
6984}
6985
b5ac8292 6986//===============================================================================================
6b62b2da 6987//function : VCamera
b5ac8292 6988//purpose :
6989//===============================================================================================
6b62b2da 6990static int VCamera (Draw_Interpretor& theDI,
6991 Standard_Integer theArgsNb,
6992 const char** theArgVec)
b5ac8292 6993{
6b62b2da 6994 Handle(V3d_View) aView = ViewerTest::CurrentView();
6995 if (aView.IsNull())
b5ac8292 6996 {
6b62b2da 6997 std::cout << "Error: no active view.\n";
b5ac8292 6998 return 1;
6999 }
7000
6b62b2da 7001 Handle(Graphic3d_Camera) aCamera = aView->Camera();
7002 if (theArgsNb < 2)
b5ac8292 7003 {
6b62b2da 7004 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
7005 theDI << "FOVy: " << aCamera->FOVy() << "\n";
7006 theDI << "Distance: " << aCamera->Distance() << "\n";
7007 theDI << "IOD: " << aCamera->IOD() << "\n";
7008 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
7009 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
7010 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
7011 return 0;
b5ac8292 7012 }
7013
6b62b2da 7014 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
b5ac8292 7015 {
6b62b2da 7016 Standard_CString anArg = theArgVec[anArgIter];
7017 TCollection_AsciiString anArgCase (anArg);
7018 anArgCase.LowerCase();
7019 if (anArgCase == "-proj"
7020 || anArgCase == "-projection"
7021 || anArgCase == "-projtype"
7022 || anArgCase == "-projectiontype")
7023 {
7024 theDI << projTypeName (aCamera->ProjectionType()) << " ";
7025 }
7026 else if (anArgCase == "-ortho"
7027 || anArgCase == "-orthographic")
b5ac8292 7028 {
7029 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
6b62b2da 7030 }
7031 else if (anArgCase == "-persp"
7032 || anArgCase == "-perspective"
7033 || anArgCase == "-perspmono"
7034 || anArgCase == "-perspectivemono"
7035 || anArgCase == "-mono")
b5ac8292 7036 {
7037 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
7038 }
6b62b2da 7039 else if (anArgCase == "-stereo"
7040 || anArgCase == "-stereoscopic"
7041 || anArgCase == "-perspstereo"
7042 || anArgCase == "-perspectivestereo")
7043 {
7044 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7045 }
7046 else if (anArgCase == "-left"
7047 || anArgCase == "-lefteye"
7048 || anArgCase == "-monoleft"
7049 || anArgCase == "-monolefteye"
7050 || anArgCase == "-perpsleft"
7051 || anArgCase == "-perpslefteye")
b5ac8292 7052 {
7053 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
7054 }
6b62b2da 7055 else if (anArgCase == "-right"
7056 || anArgCase == "-righteye"
7057 || anArgCase == "-monoright"
7058 || anArgCase == "-monorighteye"
7059 || anArgCase == "-perpsright")
b5ac8292 7060 {
7061 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
7062 }
6b62b2da 7063 else if (anArgCase == "-dist"
7064 || anArgCase == "-distance")
b5ac8292 7065 {
6b62b2da 7066 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7067 if (anArgValue != NULL
7068 && *anArgValue != '-')
7069 {
7070 ++anArgIter;
7071 aCamera->SetDistance (Draw::Atof (anArgValue));
7072 continue;
7073 }
7074 theDI << aCamera->Distance() << " ";
b5ac8292 7075 }
6b62b2da 7076 else if (anArgCase == "-iod")
b5ac8292 7077 {
6b62b2da 7078 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7079 if (anArgValue != NULL
7080 && *anArgValue != '-')
7081 {
7082 ++anArgIter;
7083 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
7084 continue;
7085 }
7086 theDI << aCamera->IOD() << " ";
b5ac8292 7087 }
6b62b2da 7088 else if (anArgCase == "-iodtype")
b5ac8292 7089 {
6b62b2da 7090 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7091 TCollection_AsciiString anValueCase (anArgValue);
7092 anValueCase.LowerCase();
7093 if (anValueCase == "abs"
7094 || anValueCase == "absolute")
7095 {
7096 ++anArgIter;
7097 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
7098 continue;
7099 }
7100 else if (anValueCase == "rel"
7101 || anValueCase == "relative")
7102 {
7103 ++anArgIter;
7104 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
7105 continue;
7106 }
7107 else if (*anArgValue != '-')
7108 {
7109 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
7110 return 1;
7111 }
7112 switch (aCamera->GetIODType())
7113 {
7114 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
7115 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
7116 }
b5ac8292 7117 }
6b62b2da 7118 else if (anArgCase == "-zfocus")
b5ac8292 7119 {
6b62b2da 7120 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7121 if (anArgValue != NULL
7122 && *anArgValue != '-')
7123 {
7124 ++anArgIter;
7125 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
7126 continue;
7127 }
7128 theDI << aCamera->ZFocus() << " ";
b5ac8292 7129 }
6b62b2da 7130 else if (anArgCase == "-zfocustype")
b5ac8292 7131 {
6b62b2da 7132 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7133 TCollection_AsciiString anValueCase (anArgValue);
7134 anValueCase.LowerCase();
7135 if (anValueCase == "abs"
7136 || anValueCase == "absolute")
7137 {
7138 ++anArgIter;
7139 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
7140 continue;
7141 }
7142 else if (anValueCase == "rel"
7143 || anValueCase == "relative")
7144 {
7145 ++anArgIter;
7146 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
7147 continue;
7148 }
7149 else if (*anArgValue != '-')
7150 {
7151 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
7152 return 1;
7153 }
7154 switch (aCamera->ZFocusType())
7155 {
7156 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
7157 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
7158 }
7159 }
7160 else if (anArgCase == "-fov"
7161 || anArgCase == "-fovy")
b5ac8292 7162 {
6b62b2da 7163 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7164 if (anArgValue != NULL
7165 && *anArgValue != '-')
7166 {
7167 ++anArgIter;
7168 aCamera->SetFOVy (Draw::Atof (anArgValue));
7169 continue;
7170 }
7171 theDI << aCamera->FOVy() << " ";
b5ac8292 7172 }
7173 else
7174 {
6b62b2da 7175 std::cout << "Error: unknown argument '" << anArg << "'\n";
b5ac8292 7176 return 1;
7177 }
7178 }
b5ac8292 7179
6b62b2da 7180 aView->View()->AutoZFit();
7181 aView->Redraw();
b5ac8292 7182
7183 return 0;
7184}
7185
7186//==============================================================================
7187//function : VStereo
7188//purpose :
7189//==============================================================================
7190
7191static int VStereo (Draw_Interpretor& theDI,
7192 Standard_Integer theArgNb,
7193 const char** theArgVec)
7194{
7195 if (theArgNb < 2)
7196 {
7197 Handle(V3d_View) aView = ViewerTest::CurrentView();
7198 if (aView.IsNull())
7199 {
7200 std::cerr << "No active view. Please call vinit.\n";
7201 return 0;
7202 }
7203
7204 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
7205 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
7206 return 0;
7207 }
7208
7209 ViewerTest_myDefaultCaps.contextStereo = Draw::Atoi (theArgVec[1]) != 0;
7210 return 0;
7211}
7212
392ac980 7213//===============================================================================================
7214//function : VDefaults
7215//purpose :
7216//===============================================================================================
7217static int VDefaults (Draw_Interpretor& theDi,
7218 Standard_Integer theArgsNb,
7219 const char** theArgVec)
7220{
7221 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
7222 if (aCtx.IsNull())
7223 {
7224 std::cerr << "No active viewer!\n";
7225 return 1;
7226 }
7227
7228 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
7229 if (theArgsNb < 2)
7230 {
7231 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
7232 {
7233 theDi << "DeflType: relative\n"
7234 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
7235 }
7236 else
7237 {
7238 theDi << "DeflType: absolute\n"
7239 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
7240 }
7241 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
4c513386 7242 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
392ac980 7243 return 0;
7244 }
7245
7246 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7247 {
7248 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4c513386 7249 anArg.UpperCase();
7250 if (anArg == "-ABSDEFL"
7251 || anArg == "-ABSOLUTEDEFLECTION"
7252 || anArg == "-DEFL"
7253 || anArg == "-DEFLECTION")
392ac980 7254 {
4c513386 7255 if (++anArgIter >= theArgsNb)
7256 {
7257 std::cout << "Error: wrong syntax at " << anArg << "\n";
7258 return 1;
7259 }
392ac980 7260 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
4c513386 7261 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
392ac980 7262 }
4c513386 7263 else if (anArg == "-RELDEFL"
7264 || anArg == "-RELATIVEDEFLECTION"
7265 || anArg == "-DEVCOEFF"
7266 || anArg == "-DEVIATIONCOEFF"
7267 || anArg == "-DEVIATIONCOEFFICIENT")
392ac980 7268 {
4c513386 7269 if (++anArgIter >= theArgsNb)
7270 {
7271 std::cout << "Error: wrong syntax at " << anArg << "\n";
7272 return 1;
7273 }
392ac980 7274 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
4c513386 7275 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
392ac980 7276 }
4c513386 7277 else if (anArg == "-ANGDEFL"
7278 || anArg == "-ANGULARDEFL"
7279 || anArg == "-ANGULARDEFLECTION")
392ac980 7280 {
4c513386 7281 if (++anArgIter >= theArgsNb)
7282 {
7283 std::cout << "Error: wrong syntax at " << anArg << "\n";
7284 return 1;
7285 }
392ac980 7286 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
4c513386 7287 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
7288 }
7289 if (anArg == "-AUTOTR"
7290 || anArg == "-AUTOTRIANG"
7291 || anArg == "-AUTOTRIANGULATION")
7292 {
7293 if (++anArgIter >= theArgsNb)
7294 {
7295 std::cout << "Error: wrong syntax at " << anArg << "\n";
7296 return 1;
7297 }
7298 TCollection_AsciiString aValue (theArgVec[anArgIter]);
7299 aValue.LowerCase();
7300 if (aValue == "on"
7301 || aValue == "1")
7302 {
7303 aDefParams->SetAutoTriangulation (Standard_True);
7304 }
7305 else if (aValue == "off"
7306 || aValue == "0")
7307 {
7308 aDefParams->SetAutoTriangulation (Standard_False);
7309 }
392ac980 7310 }
7311 else
7312 {
7313 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
7314 }
7315 }
7316
7317 return 0;
7318}
7319
12381341 7320//! Auxiliary method
7321inline void addLight (const Handle(V3d_Light)& theLightNew,
7322 const Standard_Boolean theIsGlobal)
7323{
7324 if (theLightNew.IsNull())
7325 {
7326 return;
7327 }
7328
7329 if (theIsGlobal)
7330 {
7331 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
7332 }
7333 else
7334 {
7335 ViewerTest::CurrentView()->SetLightOn (theLightNew);
7336 }
7337}
7338
7339//! Auxiliary method
7340inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
7341{
7342 TCollection_AsciiString anArgNextCase (theArgNext);
7343 anArgNextCase.UpperCase();
7344 if (anArgNextCase.Length() > 5
7345 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
7346 {
7347 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
7348 }
7349 else
7350 {
7351 return theArgNext.IntegerValue();
7352 }
7353}
7354
7355//===============================================================================================
7356//function : VLight
7357//purpose :
7358//===============================================================================================
7359static int VLight (Draw_Interpretor& theDi,
7360 Standard_Integer theArgsNb,
7361 const char** theArgVec)
7362{
7363 Handle(V3d_View) aView = ViewerTest::CurrentView();
7364 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
7365 if (aView.IsNull()
7366 || aViewer.IsNull())
7367 {
7368 std::cerr << "No active viewer!\n";
7369 return 1;
7370 }
7371
7372 Standard_Real anXYZ[3];
7373 Quantity_Coefficient anAtten[2];
7374 if (theArgsNb < 2)
7375 {
7376 // print lights info
7377 Standard_Integer aLightId = 0;
7378 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
7379 {
7380 Handle(V3d_Light) aLight = aView->ActiveLight();
7381 const Quantity_Color aColor = aLight->Color();
7382 theDi << "Light" << aLightId << "\n";
7383 switch (aLight->Type())
7384 {
7385 case V3d_AMBIENT:
7386 {
7387 theDi << " Type: Ambient\n";
7388 break;
7389 }
7390 case V3d_DIRECTIONAL:
7391 {
7392 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
7393 theDi << " Type: Directional\n";
7394 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7395 if (!aLightDir.IsNull())
7396 {
7397 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7398 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7399 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7400 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7401 }
7402 break;
7403 }
7404 case V3d_POSITIONAL:
7405 {
7406 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
7407 theDi << " Type: Positional\n";
7408 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7409 if (!aLightPos.IsNull())
7410 {
7411 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7412 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7413 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7414 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7415 }
7416 break;
7417 }
7418 case V3d_SPOT:
7419 {
7420 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
7421 theDi << " Type: Spot\n";
7422 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7423 if (!aLightSpot.IsNull())
7424 {
7425 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7426 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7427 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7428 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7429 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7430 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7431 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
7432 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
7433 }
7434 break;
7435 }
7436 default:
7437 {
7438 theDi << " Type: UNKNOWN\n";
7439 break;
7440 }
7441 }
7442 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
7443 }
7444 }
7445
7446 Handle(V3d_Light) aLightNew;
7447 Handle(V3d_Light) aLightOld;
7448 Standard_Boolean isGlobal = Standard_True;
7449 Standard_Boolean toCreate = Standard_False;
7450 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7451 {
7452 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
7453 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
7454 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
7455 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
7456 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
7457
7458 TCollection_AsciiString aName, aValue;
7459 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
7460 TCollection_AsciiString anArgCase (anArg);
7461 anArgCase.UpperCase();
7462 if (anArgCase.IsEqual ("NEW")
7463 || anArgCase.IsEqual ("ADD")
7464 || anArgCase.IsEqual ("CREATE"))
7465 {
7466 toCreate = Standard_True;
7467 }
7468 else if (anArgCase.IsEqual ("GLOB")
7469 || anArgCase.IsEqual ("GLOBAL"))
7470 {
7471 isGlobal = Standard_True;
7472 }
7473 else if (anArgCase.IsEqual ("LOC")
7474 || anArgCase.IsEqual ("LOCAL"))
7475 {
7476 isGlobal = Standard_False;
7477 }
4fe9ad57 7478 else if (anArgCase.IsEqual ("DEF")
7479 || anArgCase.IsEqual ("DEFAULTS"))
7480 {
7481 toCreate = Standard_False;
7482 aViewer->SetDefaultLights();
7483 }
7484 else if (anArgCase.IsEqual ("CLR")
7485 || anArgCase.IsEqual ("CLEAR"))
7486 {
7487 toCreate = Standard_False;
7488 aView->InitActiveLights();
7489 while (aView->MoreActiveLights())
7490 {
7491 aViewer->DelLight (aView->ActiveLight());
7492 aView->InitActiveLights();
7493 }
7494 }
12381341 7495 else if (anArgCase.IsEqual ("AMB")
7496 || anArgCase.IsEqual ("AMBIENT")
7497 || anArgCase.IsEqual ("AMBLIGHT"))
7498 {
7499 addLight (aLightNew, isGlobal);
7500 if (!toCreate)
7501 {
7502 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7503 return 1;
7504 }
7505 toCreate = Standard_False;
7506 aLightNew = new V3d_AmbientLight (aViewer);
7507 }
7508 else if (anArgCase.IsEqual ("DIRECTIONAL")
7509 || anArgCase.IsEqual ("DIRLIGHT"))
7510 {
7511 addLight (aLightNew, isGlobal);
7512 if (!toCreate)
7513 {
7514 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7515 return 1;
7516 }
7517 toCreate = Standard_False;
7518 aLightNew = new V3d_DirectionalLight (aViewer);
7519 }
7520 else if (anArgCase.IsEqual ("SPOT")
7521 || anArgCase.IsEqual ("SPOTLIGHT"))
7522 {
7523 addLight (aLightNew, isGlobal);
7524 if (!toCreate)
7525 {
7526 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7527 return 1;
7528 }
7529 toCreate = Standard_False;
7530 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
7531 }
7532 else if (anArgCase.IsEqual ("POSLIGHT")
7533 || anArgCase.IsEqual ("POSITIONAL"))
7534 {
7535 addLight (aLightNew, isGlobal);
7536 if (!toCreate)
7537 {
7538 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7539 return 1;
7540 }
7541 toCreate = Standard_False;
7542 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
7543 }
7544 else if (anArgCase.IsEqual ("CHANGE"))
7545 {
7546 addLight (aLightNew, isGlobal);
7547 aLightNew.Nullify();
7548 if (++anArgIt >= theArgsNb)
7549 {
7550 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7551 return 1;
7552 }
7553
7554 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
7555 Standard_Integer aLightIt = 0;
7556 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7557 {
7558 if (aLightIt == aLightId)
7559 {
7560 aLightOld = aView->ActiveLight();
7561 break;
7562 }
7563 }
7564
7565 if (aLightOld.IsNull())
7566 {
7567 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
7568 return 1;
7569 }
7570 }
7571 else if (anArgCase.IsEqual ("DEL")
7572 || anArgCase.IsEqual ("DELETE"))
7573 {
7574 Handle(V3d_Light) aLightDel;
7575 if (++anArgIt >= theArgsNb)
7576 {
7577 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7578 return 1;
7579 }
7580
7581 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7582 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
7583 Standard_Integer aLightIt = 0;
7584 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7585 {
7586 aLightDel = aView->ActiveLight();
7587 if (aLightIt == aLightDelId)
7588 {
7589 break;
7590 }
7591 }
7592 if (!aLightDel.IsNull())
7593 {
7594 aViewer->DelLight (aLightDel);
7595 }
7596 }
7597 else if (anArgCase.IsEqual ("COLOR")
7598 || anArgCase.IsEqual ("COLOUR"))
7599 {
7600 if (++anArgIt >= theArgsNb)
7601 {
7602 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7603 return 1;
7604 }
7605
7606 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7607 anArgNext.UpperCase();
7608 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
7609 if (!aLightCurr.IsNull())
7610 {
7611 aLightCurr->SetColor (aColor);
7612 }
7613 }
7614 else if (anArgCase.IsEqual ("POS")
7615 || anArgCase.IsEqual ("POSITION"))
7616 {
7617 if ((anArgIt + 3) >= theArgsNb)
7618 {
7619 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7620 return 1;
7621 }
7622
7623 anXYZ[0] = Atof (theArgVec[++anArgIt]);
7624 anXYZ[1] = Atof (theArgVec[++anArgIt]);
7625 anXYZ[2] = Atof (theArgVec[++anArgIt]);
7626 if (!aLightDir.IsNull())
7627 {
7628 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7629 }
7630 else if (!aLightPos.IsNull())
7631 {
7632 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7633 }
7634 else if (!aLightSpot.IsNull())
7635 {
7636 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7637 }
7638 else
7639 {
7640 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7641 return 1;
7642 }
7643 }
7644 else if (anArgCase.IsEqual ("DIR")
7645 || anArgCase.IsEqual ("DIRECTION"))
7646 {
7647 if ((anArgIt + 3) >= theArgsNb)
7648 {
7649 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7650 return 1;
7651 }
7652
7653 anXYZ[0] = Atof (theArgVec[++anArgIt]);
7654 anXYZ[1] = Atof (theArgVec[++anArgIt]);
7655 anXYZ[2] = Atof (theArgVec[++anArgIt]);
7656 if (!aLightDir.IsNull())
7657 {
7658 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
7659 }
7660 else if (!aLightSpot.IsNull())
7661 {
7662 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
7663 }
7664 else
7665 {
7666 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7667 return 1;
7668 }
7669 }
4fe9ad57 7670 else if (anArgCase.IsEqual ("ANG")
7671 || anArgCase.IsEqual ("ANGLE"))
7672 {
7673 if (++anArgIt >= theArgsNb)
7674 {
7675 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7676 return 1;
7677 }
7678
7679 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
7680
7681 if (!aLightSpot.IsNull())
7682 {
7683 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
7684 }
7685 }
12381341 7686 else if (anArgCase.IsEqual ("CONSTATTEN")
7687 || anArgCase.IsEqual ("CONSTATTENUATION"))
7688 {
7689 if (++anArgIt >= theArgsNb)
7690 {
7691 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7692 return 1;
7693 }
7694
7695 if (!aLightPos.IsNull())
7696 {
7697 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7698 anAtten[0] = Atof (theArgVec[anArgIt]);
7699 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
7700 }
7701 else if (!aLightSpot.IsNull())
7702 {
7703 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7704 anAtten[0] = Atof (theArgVec[anArgIt]);
7705 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
7706 }
7707 else
7708 {
7709 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7710 return 1;
7711 }
7712 }
7713 else if (anArgCase.IsEqual ("LINATTEN")
7714 || anArgCase.IsEqual ("LINEARATTEN")
7715 || anArgCase.IsEqual ("LINEARATTENUATION"))
7716 {
7717 if (++anArgIt >= theArgsNb)
7718 {
7719 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7720 return 1;
7721 }
7722
7723 if (!aLightPos.IsNull())
7724 {
7725 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7726 anAtten[1] = Atof (theArgVec[anArgIt]);
7727 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
7728 }
7729 else if (!aLightSpot.IsNull())
7730 {
7731 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7732 anAtten[1] = Atof (theArgVec[anArgIt]);
7733 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
7734 }
7735 else
7736 {
7737 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7738 return 1;
7739 }
7740 }
7741 else if (anArgCase.IsEqual ("EXP")
7742 || anArgCase.IsEqual ("EXPONENT")
7743 || anArgCase.IsEqual ("SPOTEXP")
7744 || anArgCase.IsEqual ("SPOTEXPONENT"))
7745 {
7746 if (++anArgIt >= theArgsNb)
7747 {
7748 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7749 return 1;
7750 }
7751
7752 if (!aLightSpot.IsNull())
7753 {
7754 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
7755 }
7756 else
7757 {
7758 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7759 return 1;
7760 }
7761 }
7762 else if (anArgCase.IsEqual ("HEAD")
7763 || anArgCase.IsEqual ("HEADLIGHT"))
7764 {
7765 if (++anArgIt >= theArgsNb)
7766 {
7767 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7768 return 1;
7769 }
7770
7771 if (aLightAmb.IsNull()
7772 && !aLightCurr.IsNull())
7773 {
7774 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
7775 }
7776 else
7777 {
7778 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7779 return 1;
7780 }
7781 }
7782 else
7783 {
7784 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
7785 }
7786 }
7787
7788 addLight (aLightNew, isGlobal);
7789 aViewer->UpdateLights();
7790
7791 return 0;
7792}
7793
e276548b 7794//=======================================================================
bc8c79bb 7795//function : VRenderParams
7796//purpose : Enables/disables rendering features
e276548b 7797//=======================================================================
7798
bc8c79bb 7799static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
7800 Standard_Integer theArgNb,
7801 const char** theArgVec)
e276548b 7802{
7ae4a307 7803 Handle(V3d_View) aView = ViewerTest::CurrentView();
7804 if (aView.IsNull())
e276548b 7805 {
bc8c79bb 7806 std::cerr << "Error: no active viewer!\n";
e276548b 7807 return 1;
7808 }
bc8c79bb 7809
7810 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
6b62b2da 7811 TCollection_AsciiString aCmdName (theArgVec[0]);
7812 aCmdName.LowerCase();
7813 if (aCmdName == "vraytrace")
7814 {
7815 if (theArgNb == 1)
7816 {
7817 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
7818 return 0;
7819 }
7820 else if (theArgNb == 2)
7821 {
7822 TCollection_AsciiString aValue (theArgVec[1]);
7823 aValue.LowerCase();
7824 if (aValue == "on"
7825 || aValue == "1")
7826 {
7827 aParams.Method = Graphic3d_RM_RAYTRACING;
7828 aView->Redraw();
7829 return 0;
7830 }
7831 else if (aValue == "off"
7832 || aValue == "0")
7833 {
7834 aParams.Method = Graphic3d_RM_RASTERIZATION;
7835 aView->Redraw();
7836 return 0;
7837 }
7838 else
7839 {
7840 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
7841 return 1;
7842 }
7843 }
7844 else
7845 {
7846 std::cout << "Error: wrong number of arguments\n";
7847 return 1;
7848 }
7849 }
bc8c79bb 7850
7851 if (theArgNb < 2)
e276548b 7852 {
bc8c79bb 7853 theDI << "renderMode: ";
7854 switch (aParams.Method)
7855 {
7856 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
7857 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
7858 }
7859 theDI << "\n";
8625ef7e 7860 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
7861 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
7862 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
7863 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
7864 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
7865 theDI << "shadingModel: ";
7866 switch (aView->ShadingModel())
7867 {
7868 case V3d_COLOR: theDI << "color"; break;
7869 case V3d_FLAT: theDI << "flat"; break;
7870 case V3d_GOURAUD: theDI << "gouraud"; break;
7871 case V3d_PHONG: theDI << "phong"; break;
7872 }
7873 theDI << "\n";
bc8c79bb 7874 return 0;
e276548b 7875 }
7876
bc8c79bb 7877 Standard_Boolean toPrint = Standard_False;
8625ef7e 7878 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
e276548b 7879 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7880 {
bc8c79bb 7881 Standard_CString anArg (theArgVec[anArgIter]);
7882 TCollection_AsciiString aFlag (anArg);
7883 aFlag.LowerCase();
8625ef7e 7884 if (anUpdateTool.parseRedrawMode (aFlag))
7885 {
7886 continue;
7887 }
7888 else if (aFlag == "-echo"
7889 || aFlag == "-print")
e276548b 7890 {
bc8c79bb 7891 toPrint = Standard_True;
8625ef7e 7892 anUpdateTool.Invalidate();
e276548b 7893 }
bc8c79bb 7894 else if (aFlag == "-mode"
7895 || aFlag == "-rendermode"
7896 || aFlag == "-render_mode")
e276548b 7897 {
bc8c79bb 7898 if (toPrint)
7899 {
7900 switch (aParams.Method)
7901 {
7902 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
7903 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
7904 }
7905 continue;
7906 }
e276548b 7907 else
bc8c79bb 7908 {
7909 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
7910 return 1;
7911 }
7912 }
7913 else if (aFlag == "-ray"
7914 || aFlag == "-raytrace")
7915 {
7916 if (toPrint)
7917 {
7918 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
7919 continue;
7920 }
7921
7922 aParams.Method = Graphic3d_RM_RAYTRACING;
e276548b 7923 }
bc8c79bb 7924 else if (aFlag == "-rast"
7925 || aFlag == "-raster"
7926 || aFlag == "-rasterization")
e276548b 7927 {
bc8c79bb 7928 if (toPrint)
7929 {
7930 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
7931 continue;
7932 }
7933
7934 aParams.Method = Graphic3d_RM_RASTERIZATION;
7935 }
7936 else if (aFlag == "-raydepth"
7937 || aFlag == "-ray_depth")
7938 {
7939 if (toPrint)
7940 {
7941 theDI << aParams.RaytracingDepth << " ";
7942 continue;
7943 }
7944 else if (++anArgIter >= theArgNb)
7945 {
7946 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
7947 return 1;
7948 }
7949
7950 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
7951 if (aDepth < 1 || aDepth > 10)
7952 {
7953 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
7954 return 1;
7955 }
e276548b 7956 else
bc8c79bb 7957 {
7958 aParams.RaytracingDepth = aDepth;
7959 }
7960 }
7961 else if (aFlag == "-shad"
7962 || aFlag == "-shadows")
7963 {
7964 if (toPrint)
7965 {
7966 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
7967 continue;
7968 }
7969
7970 Standard_Boolean toEnable = Standard_True;
7971 if (++anArgIter < theArgNb
7972 && !parseOnOff (theArgVec[anArgIter], toEnable))
7973 {
7974 --anArgIter;
7975 }
7976 aParams.IsShadowEnabled = toEnable;
7977 }
7978 else if (aFlag == "-refl"
7979 || aFlag == "-reflections")
7980 {
7981 if (toPrint)
7982 {
7983 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
7984 continue;
7985 }
7986
7987 Standard_Boolean toEnable = Standard_True;
7988 if (++anArgIter < theArgNb
7989 && !parseOnOff (theArgVec[anArgIter], toEnable))
7990 {
7991 --anArgIter;
7992 }
7993 aParams.IsReflectionEnabled = toEnable;
7994 }
7995 else if (aFlag == "-fsaa")
7996 {
7997 if (toPrint)
7998 {
7999 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
8000 continue;
8001 }
8002
8003 Standard_Boolean toEnable = Standard_True;
8004 if (++anArgIter < theArgNb
8005 && !parseOnOff (theArgVec[anArgIter], toEnable))
8006 {
8007 --anArgIter;
8008 }
8009 aParams.IsAntialiasingEnabled = toEnable;
8010 }
8011 else if (aFlag == "-gleam")
8012 {
8013 if (toPrint)
8014 {
8015 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
8016 continue;
8017 }
8018
8019 Standard_Boolean toEnable = Standard_True;
8020 if (++anArgIter < theArgNb
8021 && !parseOnOff (theArgVec[anArgIter], toEnable))
8022 {
8023 --anArgIter;
8024 }
8025 aParams.IsTransparentShadowEnabled = toEnable;
e276548b 8026 }
8625ef7e 8027 else if (aFlag == "-shademodel"
8028 || aFlag == "-shadingmodel"
8029 || aFlag == "-shading")
8030 {
8031 if (toPrint)
8032 {
8033 switch (aView->ShadingModel())
8034 {
8035 case V3d_COLOR: theDI << "color "; break;
8036 case V3d_FLAT: theDI << "flat "; break;
8037 case V3d_GOURAUD: theDI << "gouraud "; break;
8038 case V3d_PHONG: theDI << "phong "; break;
8039 }
8040 continue;
8041 }
8042
8043 if (++anArgIter >= theArgNb)
8044 {
8045 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8046 }
8047
8048 TCollection_AsciiString aMode (theArgVec[anArgIter]);
8049 aMode.LowerCase();
8050 if (aMode == "color"
8051 || aMode == "none")
8052 {
8053 aView->SetShadingModel (V3d_COLOR);
8054 }
8055 else if (aMode == "flat"
8056 || aMode == "facet")
8057 {
8058 aView->SetShadingModel (V3d_FLAT);
8059 }
8060 else if (aMode == "gouraud"
8061 || aMode == "vertex"
8062 || aMode == "vert")
8063 {
8064 aView->SetShadingModel (V3d_GOURAUD);
8065 }
8066 else if (aMode == "phong"
8067 || aMode == "fragment"
8068 || aMode == "frag"
8069 || aMode == "pixel")
8070 {
8071 aView->SetShadingModel (V3d_PHONG);
8072 }
8073 else
8074 {
8075 std::cout << "Error: unknown shading model '" << aMode << "'\n";
8076 return 1;
8077 }
8078 }
e276548b 8079 else
8080 {
bc8c79bb 8081 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
8082 return 1;
e276548b 8083 }
8084 }
e276548b 8085 return 0;
8086}
8087
b7cd4ba7 8088//=======================================================================
8089//function : VFrustumCulling
8090//purpose : enables/disables view volume's culling.
8091//=======================================================================
8092static int VFrustumCulling (Draw_Interpretor& theDI,
8093 Standard_Integer theArgNb,
8094 const char** theArgVec)
8095{
8096 Handle(V3d_View) aView = ViewerTest::CurrentView();
8097 if (aView.IsNull())
8098 {
8099 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
8100 return 1;
8101 }
8102
8103 if (theArgNb < 2)
8104 {
8105 theDI << (aView->IsCullingEnabled() ? "on" : "off");
8106 return 0;
8107 }
8108 else if (theArgNb != 2)
8109 {
8110 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
8111 return 1;
8112 }
8113
8114 TCollection_AsciiString aModeStr (theArgVec[1]);
8115 aModeStr.LowerCase();
8116 Standard_Boolean toEnable = 0;
8117 if (aModeStr == "on")
8118 {
8119 toEnable = 1;
8120 }
8121 else if (aModeStr == "off")
8122 {
8123 toEnable = 0;
8124 }
8125 else
8126 {
8127 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8128 }
8129
8130 aView->SetFrustumCulling (toEnable);
8131 aView->Redraw();
8132 return 0;
8133}
8134
c398b00e 8135//=======================================================================
8136//function : VHighlightSelected
8137//purpose :
8138//=======================================================================
8139static int VHighlightSelected (Draw_Interpretor& theDI,
8140 Standard_Integer theArgNb,
8141 const char** theArgVec)
8142{
8143 if (ViewerTest::GetAISContext().IsNull())
8144 {
8145 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
8146 return 1;
8147 }
8148
8149 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8150
8151 if (theArgNb < 2)
8152 {
8153 theDI << (aContext->ToHilightSelected() ? "on" : "off");
8154 return 0;
8155 }
8156
8157 if (theArgNb != 2)
8158 {
8159 std::cout << theArgVec[0] << " error : wrong number of parameters."
8160 << "Type 'help" << theArgVec[0] << "' for more information.";
8161 return 1;
8162 }
8163
8164 // Parse parameter
8165 TCollection_AsciiString aMode (theArgVec[1]);
8166 aMode.LowerCase();
8167 Standard_Boolean toEnable = Standard_False;
8168 if (aMode.IsEqual ("on"))
8169 {
8170 toEnable = Standard_True;
8171 }
8172 else if (aMode.IsEqual ("off"))
8173 {
8174 toEnable = Standard_False;
8175 }
8176 else
8177 {
8178 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8179 }
8180
8181 if (toEnable != aContext->ToHilightSelected())
8182 {
8183 aContext->SetToHilightSelected (toEnable);
8184
8185 // Move cursor to null position and back to process updating of detection
8186 // and highlighting of selected object immediatly.
8187 Standard_Integer aPixX = 0;
8188 Standard_Integer aPixY = 0;
8189 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
8190
8191 anEventManager->GetCurrentPosition (aPixX, aPixY);
8192 anEventManager->MoveTo (0, 0);
8193 anEventManager->MoveTo (aPixX, aPixY);
8194 }
8195
8196 return 0;
8197}
8198
0717ddc1 8199//=======================================================================
8200//function : VXRotate
8201//purpose :
8202//=======================================================================
8203static Standard_Integer VXRotate (Draw_Interpretor& di,
8204 Standard_Integer argc,
8205 const char ** argv)
8206{
8207 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8208 if (aContext.IsNull())
8209 {
8210 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
8211 return 1;
8212 }
8213
8214 if (argc != 3)
8215 {
8216 di << "ERROR : Usage : " << argv[0] << " name angle" << "\n";
8217 return 1;
8218 }
8219
8220 TCollection_AsciiString aName (argv[1]);
8221 Standard_Real anAngle = Draw::Atof (argv[2]);
8222
8223 // find object
8224 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
8225 Handle(AIS_InteractiveObject) anIObj;
8226 if (!aMap.IsBound2 (aName) )
8227 {
8228 di << "Use 'vdisplay' before" << "\n";
8229 return 1;
8230 }
8231 else
8232 {
8233 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
8234
8235 gp_Trsf aTransform;
8236 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
8237 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
8238
8239 aContext->SetLocation (anIObj, aTransform);
8240 aContext->UpdateCurrentViewer();
8241 }
8242
8243 return 0;
8244}
8245
7fd59977 8246//=======================================================================
8247//function : ViewerCommands
8248//purpose :
8249//=======================================================================
8250
8251void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
8252{
8253
8254 const char *group = "ZeViewer";
18d715bd 8255 theCommands.Add("vinit",
8256#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8257 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
8258#else
8259 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
8260#endif
8261 " - Creates new View window with specified name view_name.\n"
8262 "By default the new view is created in the viewer and in"
8263 " graphic driver shared with active view.\n"
8264 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
8265 "If driverName isn't specified the driver will be shared with active view.\n"
8266 "If viewerName isn't specified the viewer will be shared with active view.\n"
8267#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8268 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
8269 "is used in creation of graphic driver\n"
8270#endif
8271 " - l, t: pixel position of left top corner of the window\n"
8272 " - w,h: width and heigth of window respectively.\n"
8273 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
7fd59977 8274 __FILE__,VInit,group);
18d715bd 8275 theCommands.Add("vclose" ,
d0cc1cb7 8276 "[view_id [keep_context=0|1]]\n"
18d715bd 8277 "or vclose ALL - to remove all created views\n"
8278 " - removes view(viewer window) defined by its view_id.\n"
8279 " - keep_context: by default 0; if 1 and the last view is deleted"
8280 " the current context is not removed.",
8281 __FILE__,VClose,group);
8282 theCommands.Add("vactivate" ,
8283 "view_id"
8284 " - activates view(viewer window) defined by its view_id",
8285 __FILE__,VActivate,group);
8286 theCommands.Add("vviewlist",
8287 "vviewlist [format={tree, long}]"
8288 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
8289 " - format: format of result output, if tree the output is a tree view;"
8290 "otherwise it's a list of full view names. By default format = tree",
8291 __FILE__,VViewList,group);
7fd59977 8292 theCommands.Add("vhelp" ,
8293 "vhelp : display help on the viewer commands",
8294 __FILE__,VHelp,group);
8295 theCommands.Add("vtop" ,
44b8f2d6 8296 "vtop or <T> : Top view" ,
7fd59977 8297 __FILE__,VTop,group);
44b8f2d6 8298 theCommands.Add("vbottom" ,
8299 "vbottom : Bottom view" ,
8300 __FILE__,VBottom,group);
8301 theCommands.Add("vleft" ,
8302 "vleft : Left view" ,
8303 __FILE__,VLeft,group);
8304 theCommands.Add("vright" ,
8305 "vright : Right view" ,
8306 __FILE__,VRight,group);
7fd59977 8307 theCommands.Add("vaxo" ,
8308 " vaxo or <A> : Axonometric view ",
8309 __FILE__,VAxo,group);
44b8f2d6 8310 theCommands.Add("vfront" ,
8311 "vfront : Front view" ,
8312 __FILE__,VFront,group);
8313 theCommands.Add("vback" ,
8314 "vback : Back view" ,
8315 __FILE__,VBack,group);
7fd59977 8316 theCommands.Add("vpick" ,
8317 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
8318 VPick,group);
8319 theCommands.Add("vfit" ,
8320 "vfit or <F> : vfit",
8321 __FILE__,VFit,group);
6262a303 8322 theCommands.Add ("vfitarea",
8323 "vfitarea x1 y1 x2 y2"
8324 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
8325 "\n\t\t: Fit view to show area located between two points"
8326 "\n\t\t: given in world 2D or 3D corrdinates.",
8327 __FILE__, VFitArea, group);
197ac94e 8328 theCommands.Add ("vzfit", "vzfit [scale]\n"
8329 " Matches Z near, Z far view volume planes to the displayed objects.\n"
8330 " \"scale\" - specifies factor to scale computed z range.\n",
8331 __FILE__, VZFit, group);
7fd59977 8332 theCommands.Add("vrepaint",
8333 "vrepaint : vrepaint, force redraw",
8334 __FILE__,VRepaint,group);
8335 theCommands.Add("vclear",
8336 "vclear : vclear",
8337 __FILE__,VClear,group);
8338 theCommands.Add("vsetbg",
8339 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
8340 __FILE__,VSetBg,group);
f8b2ed36 8341 theCommands.Add("vsetbgmode",
8342 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
8343 __FILE__,VSetBgMode,group);
7fd59977 8344 theCommands.Add("vsetgradientbg",
f8b2ed36 8345 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
7fd59977 8346 __FILE__,VSetGradientBg,group);
f8b2ed36 8347 theCommands.Add("vsetgrbgmode",
8348 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
8349 __FILE__,VSetGradientBgMode,group);
8350 theCommands.Add("vsetcolorbg",
8351 "vsetcolorbg : vsetcolorbg r g b : Set background color",
8352 __FILE__,VSetColorBg,group);
7fd59977 8353 theCommands.Add("vscale",
8354 "vscale : vscale X Y Z",
8355 __FILE__,VScale,group);
8356 theCommands.Add("vzbufftrihedron",
536d98e2 8357 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
8358 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
8359 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
8360 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
8361 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
8362 "\n\t\t: Displays a trihedron",
8363 __FILE__,VZBuffTrihedron,group);
7fd59977 8364 theCommands.Add("vrotate",
4af098ba 8365 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
8366 "\n : Option -mouseStart starts rotation according to the mouse position"
8367 "\n : Option -mouseMove continues rotation with angle computed"
8368 "\n : from last and new mouse position."
8369 "\n : vrotate AX AY AZ [X Y Z]",
7fd59977 8370 __FILE__,VRotate,group);
8371 theCommands.Add("vzoom",
8372 "vzoom : vzoom coef",
8373 __FILE__,VZoom,group);
8374 theCommands.Add("vpan",
8375 "vpan : vpan dx dy",
8376 __FILE__,VPan,group);
8377 theCommands.Add("vexport",
5cedc27f
K
8378 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
8379 " : exports the view to a vector file of a given format"
8380 " : notice that EMF format requires patched gl2ps",
7fd59977 8381 __FILE__,VExport,group);
8382 theCommands.Add("vcolorscale",
71215351 8383 "vcolorscale : vcolorscale [-range RangeMin = 0 RangeMax = 100 Intervals = 10 -font HeightFont = 16 -textpos "
8384 "Position = left -xy X = 0 Y = 0] [-noupdate|-update]: draw color scale\n"
8385 "-demo/-demoversion draw a demoversion of color scale.\n"
8386 "-show/display display color scale.\n"
8387 "-hide/erase erase color scale.\n"
8388 "Please note that -show/-hide option must be the first argument!\n"
8389 "-color Index R G B: set color for indexed interval\n"
8390 "-color Index ColorName: set color for indexed interval\n"
8391 "-colors R G B R G B ...: set colors for all intervals\n"
8392 "-colors ColorName1 ColorName2 ...: set colors for all intervals\n"
8393 "-colors supports both color names and rgb values in one call\n"
8394 "-label Index Text: set label for indexed interval\n"
8395 "-labels Text Text Text ...: set labels for all intervals\n"
8396 "-title Title [Position]: set the title for color scale with certain position. Default position = center;\n"
8397 "Available text positions: left, right, center, none;\n",
7fd59977 8398 __FILE__,VColorScale,group);
8399 theCommands.Add("vgraduatedtrihedron",
a79f67f8 8400 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
8401 "\t[-namefont Name] [-valuesfont Name]\n"
8402 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
8403 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
8404 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
8405 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
8406 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
8407 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
8408 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
8409 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
8410 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
536d98e2 8411 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
a79f67f8 8412 " - Displays or erases graduated trihedron"
8413 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
8414 " - namefont - font of axes names. Default: Arial\n"
8415 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
8416 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
8417 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
8418 " - valuesfont - font of axes values. Default: Arial\n"
8419 " - xcolor, ycolor, zcolor - color of axis and values\n"
8420 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
8421 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
7fd59977 8422 __FILE__,VGraduatedTrihedron,group);
7edf74fd 8423 theCommands.Add("vprintview" ,
b5ac8292 8424 "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
7edf74fd 8425 __FILE__,VPrintView,group);
59f45b7c 8426 theCommands.Add("vzlayer",
c5751993 8427 "vzlayer add/del/get/settings/enable/disable [id]\n"
8428 " add - add new z layer to viewer and print its id\n"
8429 " del - del z layer by its id\n"
8430 " get - print sequence of z layers in increasing order of their overlay level\n"
8431 " settings - print status of z layer settings\n"
8432 " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"
8433 " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"
8434 " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"
8435 "\nWhere id is the layer identificator\n"
8436 "\nExamples:\n"
8437 " vzlayer add\n"
8438 " vzlayer enable poffset 1\n"
8439 " vzlayer disable depthtest 1\n"
8440 " vzlayer del 1\n",
59f45b7c 8441 __FILE__,VZLayer,group);
25289ec1 8442 theCommands.Add("voverlaytext",
8443 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
8444 " : height - pixel height of the text (default=10.0)"
8445 " : font_name - name of font (default=courier)"
8446 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
8447 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
8448 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
8449 __FILE__,VOverlayText,group);
20637bd2 8450 theCommands.Add("vlayerline",
8451 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
8452 __FILE__,VLayerLine,group);
2bd4c032 8453 theCommands.Add ("vgrid",
8454 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
8455 " : Mode - rectangular or circular"
8456 " : Type - lines or points",
8457 __FILE__, VGrid, group);
c40b7d58 8458 theCommands.Add ("vpriviledgedplane",
8459 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
8460 "\n\t\t: Ox, Oy, Oz - plane origin"
8461 "\n\t\t: Nx, Ny, Nz - plane normal direction"
8462 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
8463 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
8464 __FILE__, VPriviledgedPlane, group);
f25b82d6 8465 theCommands.Add ("vconvert",
8466 "vconvert v [Mode={window|view}]"
8467 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
8468 "\n\t\t: vconvert x y z [Mode={window|grid}]"
8469 "\n\t\t: window - convert to window coordinates, pixels"
8470 "\n\t\t: view - convert to view projection plane"
8471 "\n\t\t: grid - convert to model coordinates, given on grid"
8472 "\n\t\t: ray - convert projection ray to model coordiantes"
8473 "\n\t\t: - vconvert v window : convert view to window;"
8474 "\n\t\t: - vconvert v view : convert window to view;"
8475 "\n\t\t: - vconvert x y window : convert view to window;"
8476 "\n\t\t: - vconvert x y view : convert window to view;"
8477 "\n\t\t: - vconvert x y : convert window to model;"
8478 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
8479 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
8480 "\n\t\t: - vconvert x y z window : convert model to window;"
8481 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
8482 "\n\t\t: Converts the given coordinates to window/view/model space.",
8483 __FILE__, VConvert, group);
208e6839 8484 theCommands.Add ("vfps",
8485 "vfps [framesNb=100] : estimate average frame rate for active view",
8486 __FILE__, VFps, group);
58655684 8487 theCommands.Add ("vgldebug",
8488 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
8489 " : this function is implemented only for Windows\n"
8490 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
8491 __FILE__, VGlDebug, group);
208e6839 8492 theCommands.Add ("vvbo",
58655684 8493 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
208e6839 8494 __FILE__, VVbo, group);
b5ac8292 8495 theCommands.Add ("vstereo",
8496 "\nvstereo [{0|1}] : turn stereo usage On/Off; affects only newly displayed objects",
8497 __FILE__, VStereo, group);
a577aaab 8498 theCommands.Add ("vcaps",
8625ef7e 8499 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
4e1523ef 8500 "\n\t\t: [-compatibleContext {0|1}]"
8625ef7e 8501 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
8502 "\n\t\t: Modify particular graphic driver options:"
8503 "\n\t\t: FFP - use fixed-function pipeline instead of"
8504 "\n\t\t: built-in GLSL programs"
4e1523ef 8505 "\n\t\t: (requires compatible profile)"
8625ef7e 8506 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
8507 "\n\t\t: arrays to GPU memory)"
8508 "\n\t\t: sprite - use textured sprites instead of bitmaps"
4e1523ef 8509 "\n\t\t: Context creation options:"
8510 "\n\t\t: softMode - software OpenGL implementation"
8511 "\n\t\t: compatibleProfile - backward-compatible profile"
8625ef7e 8512 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
8513 "\n\t\t: rendering paths producing the same visual result when"
8514 "\n\t\t: possible."
8515 "\n\t\t: Command is intended for testing old hardware compatibility.",
a577aaab 8516 __FILE__, VCaps, group);
f0430952 8517 theCommands.Add ("vmemgpu",
8518 "vmemgpu [f]: print system-dependent GPU memory information if available;"
8519 " with f option returns free memory in bytes",
8520 __FILE__, VMemGpu, group);
85e096c3 8521 theCommands.Add ("vreadpixel",
8522 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
8523 " : Read pixel value for active view",
8524 __FILE__, VReadPixel, group);
692613e5 8525 theCommands.Add("diffimage",
8526 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
8527 __FILE__, VDiffImage, group);
4754e164 8528 theCommands.Add ("vselect",
8529 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
8530 "- emulates different types of selection:\n"
8531 "- 1) single click selection\n"
8532 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
8533 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
8534 "- 4) any of these selections with shift button pressed",
8535 __FILE__, VSelect, group);
8536 theCommands.Add ("vmoveto",
8537 "vmoveto x y"
8538 "- emulates cursor movement to pixel postion (x,y)",
8539 __FILE__, VMoveTo, group);
197ac94e 8540 theCommands.Add ("vviewparams", "vviewparams usage:\n"
8541 "- vviewparams\n"
8542 "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n"
3dfe95cd 8543 " [-proj [x y z]] [-center x y] [-size sx]\n"
197ac94e 8544 "- Gets or sets current view parameters.\n"
8545 "- If called without arguments, all view parameters are printed.\n"
8546 "- The options are:\n"
3dfe95cd 8547 " -scale [s] : prints or sets viewport relative scale.\n"
197ac94e 8548 " -eye [x y z] : prints or sets eye location.\n"
8549 " -at [x y z] : prints or sets center of look.\n"
8550 " -up [x y z] : prints or sets direction of up vector.\n"
8551 " -proj [x y z] : prints or sets direction of look.\n"
3dfe95cd 8552 " -center x y : sets location of center of the screen in pixels.\n"
8553 " -size [sx] : prints viewport projection width and height sizes\n"
8554 " : or changes the size of its maximum dimension.\n",
197ac94e 8555 __FILE__, VViewParams, group);
4754e164 8556 theCommands.Add("vchangeselected",
dc3fe572 8557 "vchangeselected shape"
4754e164 8558 "- adds to shape to selection or remove one from it",
8559 __FILE__, VChangeSelected, group);
8560 theCommands.Add("vzclipping",
8561 "vzclipping [mode] [depth width]\n"
8562 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
8563 "- gets or sets ZClipping mode, width and depth",
8564 __FILE__,VZClipping,group);
8565 theCommands.Add ("vnbselected",
8566 "vnbselected", __FILE__, VNbSelected, group);
6b62b2da 8567 theCommands.Add ("vcamera",
8568 "vcamera [-ortho] [-projtype]"
8569 "\n\t\t: [-persp]"
8570 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
8571 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
8572 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
8573 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
8574 "\n\t\t: Manage camera parameters."
8575 "\n\t\t: Prints current value when option called without argument."
8576 "\n\t\t: Orthographic camera:"
8577 "\n\t\t: -ortho activate orthographic projection"
8578 "\n\t\t: Perspective camera:"
8579 "\n\t\t: -persp activate perspective projection (mono)"
8580 "\n\t\t: -fovy field of view in y axis, in degrees"
8581 "\n\t\t: -distance distance of eye from camera center"
8582 "\n\t\t: Stereoscopic camera:"
8583 "\n\t\t: -stereo perspective projection (stereo)"
8584 "\n\t\t: -leftEye perspective projection (left eye)"
8585 "\n\t\t: -rightEye perspective projection (right eye)"
8586 "\n\t\t: -iod intraocular distance value"
8587 "\n\t\t: -iodType distance type, absolute or relative"
8588 "\n\t\t: -zfocus stereographic focus value"
8589 "\n\t\t: -zfocusType focus type, absolute or relative",
8590 __FILE__, VCamera, group);
b5ac8292 8591 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
197ac94e 8592 "- vautozfit [on={1|0}] [scale]\n"
8593 " Prints or changes parameters of automatic z-fit mode:\n"
8594 " \"on\" - turns automatic z-fit on or off\n"
8595 " \"scale\" - specifies factor to scale computed z range.\n",
8596 __FILE__, VAutoZFit, group);
b5ac8292 8597 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
8598 " vzrange - without parameters shows current values\n"
8599 " vzrange [znear] [zfar] - applies provided values to view",
8600 __FILE__,VZRange, group);
4754e164 8601 theCommands.Add("vantialiasing",
8602 "vantialiasing 1|0",
8603 __FILE__,VAntialiasing,group);
8604 theCommands.Add ("vpurgedisplay",
eb4320f2 8605 "vpurgedisplay"
4754e164 8606 "- removes structures which don't belong to objects displayed in neutral point",
8607 __FILE__, VPurgeDisplay, group);
8608 theCommands.Add("vsetviewsize",
8609 "vsetviewsize size",
8610 __FILE__,VSetViewSize,group);
8611 theCommands.Add("vmoveview",
8612 "vmoveview Dx Dy Dz [Start = 1|0]",
8613 __FILE__,VMoveView,group);
8614 theCommands.Add("vtranslateview",
8615 "vtranslateview Dx Dy Dz [Start = 1|0)]",
8616 __FILE__,VTranslateView,group);
8617 theCommands.Add("vturnview",
8618 "vturnview Ax Ay Az [Start = 1|0]",
8619 __FILE__,VTurnView,group);
269294d6 8620 theCommands.Add("vtextureenv",
8621 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
8622 "or user-defined file and optionally applying texture mapping parameters\n"
8623 " Usage:\n"
8624 " vtextureenv off - disables environment mapping\n"
8625 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
8626 " std_texture = (0..7)\n"
8627 " rep = {clamp|repeat}\n"
8628 " mod = {decal|modulate}\n"
8629 " flt = {nearest|bilinear|trilinear}\n"
8630 " ss, st - scale factors for s and t texture coordinates\n"
8631 " ts, tt - translation for s and t texture coordinates\n"
8632 " rot - texture rotation angle in degrees",
8633 __FILE__, VTextureEnv, group);
0a768f56 8634 theCommands.Add("vhlr" ,
e9224045 8635 "is_enabled={on|off} [show_hidden={1|0}]"
0a768f56 8636 " - Hidden line removal algorithm:"
e9224045 8637 " - is_enabled: if is on HLR algorithm is applied\n"
8638 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
0a768f56 8639 __FILE__,VHLR,group);
8640 theCommands.Add("vhlrtype" ,
8641 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
8642 " - Changes the type of HLR algorithm using for shapes."
8643 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
8644 " if equals to polyalgo, polygonal HLR algorithm is applied."
8645 "If shapes are not given HLR algoithm of given type is applied"
8646 " to all shapes in the view\n",
8647 __FILE__,VHLRType,group);
4269bd1b 8648 theCommands.Add("vclipplane", "vclipplane usage: \n"
8649 " maxplanes <view_name> - get plane limit for view.\n"
8650 " create <plane_name> - create new plane.\n"
8651 " delete <plane_name> - delete plane.\n"
8652 " clone <source_plane> <plane_name> - clone the plane definition.\n"
8653 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
8654 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
8655 " change <plane_name> on/off - turn clipping on/off.\n"
8656 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
8657 " change <plane_name> capping on/off - turn capping on/off.\n"
8658 " change <plane_name> capping color <r> <g> <b> - set color.\n"
8659 " change <plane name> capping texname <texture> - set texture.\n"
8660 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
8661 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
8662 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
8663 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
8664 " please use VSetTextureMode command to enable texture rendering in view.\n"
8665 , __FILE__, VClipPlane, group);
8666 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
8667 " mode can be:\n"
8668 " 0 - no textures enabled in view.\n"
8669 " 1 - only environment textures enabled.\n"
8670 " 2 - all textures enabled.\n"
8671 " this command sets texture details mode for the specified view.\n"
8672 , __FILE__, VSetTextureMode, group);
392ac980 8673 theCommands.Add("vdefaults",
4c513386 8674 "vdefaults [-absDefl value]"
8675 "\n\t\t: [-devCoeff value]"
8676 "\n\t\t: [-angDefl value]"
8677 "\n\t\t: [-autoTriang {off/on | 0/1}]"
8678 , __FILE__, VDefaults, group);
12381341 8679 theCommands.Add("vlight",
816d03ee 8680 "tool to manage light sources, without arguments shows list of lights."
8681 "\n Main commands: "
8682 "\n 'clear' to clear lights"
8683 "\n '{def}aults' to load deafault lights"
8684 "\n 'add' (or 'new') <type> to add any light source"
8685 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
8686 "\n 'change' <lightId> to edit light source with specified lightId"
8687 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
8688 "\n {pos}ition X Y Z"
8689 "\n {dir}ection X Y Z (for directional light or for spotlight)"
8690 "\n color colorName"
8691 "\n {head}light 0|1"
8692 "\n {constAtten}uation value"
8693 "\n {linearAtten}uation value"
8694 "\n angle angleDeg"
8695 "\n {spotexp}onent value"
8696 "\n local|global"
8697 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
8698 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
12381341 8699 __FILE__, VLight, group);
6b62b2da 8700 theCommands.Add("vraytrace",
8701 "vraytrace [0|1]"
8702 "\n\t\t: Turn on/off raytracing renderer."
8703 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
8704 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
8705 __FILE__, VRenderParams, group);
bc8c79bb 8706 theCommands.Add("vrenderparams",
8707 "\n Manages rendering parameters: "
8625ef7e 8708 "\n '-rayTrace' Enables GPU ray-tracing"
8709 "\n '-raster' Disables GPU ray-tracing"
8710 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
8711 "\n '-shadows on|off' Enables/disables shadows rendering"
8712 "\n '-reflections on|off' Enables/disables specular reflections"
8713 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
8714 "\n '-gleam on|off' Enables/disables transparency shadow effects"
8715 "\n '-shadingModel model' Controls shading model from enumeration"
8716 "\n color, flat, gouraud, phong"
8717 "\n Unlike vcaps, these parameters dramatically change visual properties."
8718 "\n Command is intended to control presentation quality depending on"
8719 "\n hardware capabilities and performance.",
bc8c79bb 8720 __FILE__, VRenderParams, group);
b7cd4ba7 8721 theCommands.Add("vfrustumculling",
8722 "vfrustumculling [toEnable]: enables/disables objects clipping",
8723 __FILE__,VFrustumCulling,group);
c398b00e 8724 theCommands.Add("vhighlightselected",
8725 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
8726 "Without arguments it shows if highlighting of selected objects is enabled now.",
8727 __FILE__,VHighlightSelected,group);
49e1a5c7 8728 theCommands.Add ("vplace",
8729 "vplace dx dy"
8730 "\n\t\t: Places the point (in pixels) at the center of the window",
8731 __FILE__, VPlace, group);
0717ddc1 8732 theCommands.Add("vxrotate",
8733 "vxrotate",
8734 __FILE__,VXRotate,group);
8735
7fd59977 8736}