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