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