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