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