0024757: DRAW: Move commands fixshape, tolerance, and similar to MODELING
[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;
196Standard_Boolean DragFirst;
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:
1894 IsDragged = Standard_False;
1895 if( !DragFirst )
1896 {
1897 HDC hdc = GetDC( hwnd );
7fd59977 1898 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1899 SetROP2( hdc, R2_NOT );
4fe56619 1900 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 1901 ReleaseDC( hwnd, hdc );
1902
1903 const Handle(ViewerTest_EventManager) EM =
1904 ViewerTest::CurrentEventManager();
1905 if ( fwKeys & MK_SHIFT )
4fe56619 1906 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1907 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
7fd59977 1908 else
4fe56619 1909 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1910 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
7fd59977 1911 }
1912 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1913
1914 case WM_LBUTTONDOWN:
1915 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1916 {
1917 IsDragged = Standard_True;
1918 DragFirst = Standard_True;
4fe56619 1919 X_ButtonPress = LOWORD(lParam);
1920 Y_ButtonPress = HIWORD(lParam);
7fd59977 1921 }
1922 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1923
1924 break;
1925
1926 case WM_MOUSEMOVE:
1927 if( IsDragged )
1928 {
1929 HDC hdc = GetDC( hwnd );
1930
1931 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1932 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1933 SetROP2( hdc, R2_NOT );
1934
1935 if( !DragFirst )
4fe56619 1936 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 1937
1938 DragFirst = Standard_False;
4fe56619 1939 X_Motion = LOWORD(lParam);
1940 Y_Motion = HIWORD(lParam);
7fd59977 1941
4fe56619 1942 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 1943
1944 SelectObject( hdc, anObj );
1945
1946 ReleaseDC( hwnd, hdc );
1947 }
1948 else
1949 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1950 break;
1951
1952 default:
1953 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1954 }
1955 return 0;
1956 }
1957 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1958}
1959
1960
1961static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1962 UINT Msg,
1963 WPARAM wParam,
1964 LPARAM lParam )
1965{
7fd59977 1966 static int Up = 1;
1967
1968 if ( !ViewerTest::CurrentView().IsNull() ) {
1969 PAINTSTRUCT ps;
1970
1971 switch( Msg ) {
7fd59977 1972 case WM_PAINT:
7fd59977 1973 BeginPaint(hwnd, &ps);
1974 EndPaint(hwnd, &ps);
4fe56619 1975 VT_ProcessExpose();
7fd59977 1976 break;
1977
1978 case WM_SIZE:
4fe56619 1979 VT_ProcessConfigure();
7fd59977 1980 break;
1981
1982 case WM_KEYDOWN:
4fe56619 1983 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1984 {
7fd59977 1985 char c[2];
1986 c[0] = (char) wParam;
1987 c[1] = '\0';
b514beda 1988 if (wParam == VK_DELETE)
1989 {
1990 c[0] = THE_KEY_DELETE;
1991 }
4fe56619 1992 VT_ProcessKeyPress (c);
7fd59977 1993 }
1994 break;
1995
1996 case WM_LBUTTONUP:
1997 case WM_MBUTTONUP:
1998 case WM_RBUTTONUP:
7fd59977 1999 Up = 1;
4fe56619 2000 VT_ProcessButton3Release();
7fd59977 2001 break;
2002
2003 case WM_LBUTTONDOWN:
2004 case WM_MBUTTONDOWN:
2005 case WM_RBUTTONDOWN:
2006 {
7fd59977 2007 WPARAM fwKeys = wParam;
2008
2009 Up = 0;
2010
2011 X_ButtonPress = LOWORD(lParam);
2012 Y_ButtonPress = HIWORD(lParam);
2013
4fe56619 2014 if (Msg == WM_LBUTTONDOWN)
2015 {
2016 if (fwKeys & MK_CONTROL)
2017 {
2018 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2019 }
2020 else
2021 {
2022 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2023 }
7fd59977 2024 }
4fe56619 2025 else if (Msg == WM_RBUTTONDOWN)
2026 {
7fd59977 2027 // Start rotation
4fe56619 2028 VT_ProcessButton3Press();
7fd59977 2029 }
2030 }
2031 break;
2032
2033 case WM_MOUSEMOVE:
2034 {
2035 //cout << "\t WM_MOUSEMOVE" << endl;
2036 WPARAM fwKeys = wParam;
2037 X_Motion = LOWORD(lParam);
2038 Y_Motion = HIWORD(lParam);
2039
2040 if ( Up &&
2041 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2042 Up = 0;
2043 X_ButtonPress = LOWORD(lParam);
2044 Y_ButtonPress = HIWORD(lParam);
2045
2046 if ( fwKeys & MK_RBUTTON ) {
2047 // Start rotation
4fe56619 2048 VT_ProcessButton3Press();
7fd59977 2049 }
2050 }
2051
2052 if ( fwKeys & MK_CONTROL ) {
2053 if ( fwKeys & MK_LBUTTON ) {
2054 ProcessControlButton1Motion();
2055 }
2056 else if ( fwKeys & MK_MBUTTON ||
2057 ((fwKeys&MK_LBUTTON) &&
2058 (fwKeys&MK_RBUTTON) ) ){
4fe56619 2059 VT_ProcessControlButton2Motion();
7fd59977 2060 }
2061 else if ( fwKeys & MK_RBUTTON ) {
4fe56619 2062 VT_ProcessControlButton3Motion();
7fd59977 2063 }
2064 }
2065#ifdef BUG
2066 else if ( fwKeys & MK_SHIFT ) {
2067 if ( fwKeys & MK_MBUTTON ||
2068 ((fwKeys&MK_LBUTTON) &&
2069 (fwKeys&MK_RBUTTON) ) ) {
2070 cout << "ProcessZClipMotion()" << endl;
2071 ProcessZClipMotion();
2072 }
2073 }
2074#endif
08398024 2075 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2076 {
4fe56619 2077 if ((fwKeys & MK_MBUTTON
2078 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2079 {
7fd59977 2080 ProcessZClipMotion();
2081 }
4fe56619 2082 else
2083 {
2084 VT_ProcessMotion();
7fd59977 2085 }
08398024 2086 }
7fd59977 2087 }
2088 break;
2089
2090 default:
2091 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2092 }
2093 return 0L;
2094 }
2095
2096 return DefWindowProc( hwnd, Msg, wParam, lParam );
2097}
2098
2099
2100
2101
2102//==============================================================================
2103//function : ViewerMainLoop
2104//purpose : Get a Event on the view and dispatch it
2105//==============================================================================
2106
2107
8263fcd3 2108int ViewerMainLoop(Standard_Integer argc, const char** argv)
7fd59977 2109{
7fd59977 2110 Ppick = (argc > 0)? 1 : 0;
2111 Pargc = argc;
2112 Pargv = argv;
2113
2114 if ( Ppick ) {
2115 MSG msg;
2116 msg.wParam = 1;
2117
2118 cout << "Start picking" << endl;
2119
7fd59977 2120 while ( Ppick == 1 ) {
4fe56619 2121 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
7fd59977 2122 if (GetMessage(&msg, NULL, 0, 0) ) {
2123 TranslateMessage(&msg);
2124 DispatchMessage(&msg);
2125 }
2126 }
2127
2128 cout << "Picking done" << endl;
2129 }
2130
2131 return Ppick;
2132}
2133
4fe56619 2134#elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 2135
2136int min( int a, int b )
2137{
2138 if( a<b )
2139 return a;
2140 else
2141 return b;
2142}
2143
2144int max( int a, int b )
2145{
2146 if( a>b )
2147 return a;
2148 else
2149 return b;
2150}
2151
2152int ViewerMainLoop(Standard_Integer argc, const char** argv)
2153
4269bd1b 2154{
18d715bd 2155 static XEvent aReport;
2156 Standard_Boolean pick = argc > 0;
2157 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2158 XNextEvent (aDisplay, &aReport);
7fd59977 2159
18d715bd 2160 // Handle event for the chosen display connection
2161 switch (aReport.type) {
2162 case ClientMessage:
2163 {
2164 if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2165 {
2166 // Close the window
2167 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2168 }
2169 }
2170 return 0;
2171 case FocusIn:
2172 {
2173 // Activate inactive view
2174 Window aWindow = GetWindowHandle(VT_GetWindow());
2175 if(aWindow != aReport.xfocus.window)
2176 {
2177 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2178 }
2179 }
2180 break;
7fd59977 2181 case Expose:
2182 {
4fe56619 2183 VT_ProcessExpose();
7fd59977 2184 }
2185 break;
2186 case ConfigureNotify:
2187 {
4fe56619 2188 VT_ProcessConfigure();
7fd59977 2189 }
2190 break;
2191 case KeyPress:
2192 {
2193
2194 KeySym ks_ret ;
2195 char buf_ret[11] ;
2196 int ret_len ;
2197 XComposeStatus status_in_out;
2198
18d715bd 2199 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
7fd59977 2200 (char *) buf_ret , 10 ,
2201 &ks_ret , &status_in_out ) ;
2202
2203
2204 buf_ret[ret_len] = '\0' ;
2205
4fe56619 2206 if (ret_len)
2207 {
2208 VT_ProcessKeyPress (buf_ret);
7fd59977 2209 }
2210 }
2211 break;
2212 case ButtonPress:
7fd59977 2213 {
18d715bd 2214 X_ButtonPress = aReport.xbutton.x;
2215 Y_ButtonPress = aReport.xbutton.y;
7fd59977 2216
18d715bd 2217 if (aReport.xbutton.button == Button1)
4fe56619 2218 {
18d715bd 2219 if (aReport.xbutton.state & ControlMask)
4fe56619 2220 {
18d715bd 2221 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
4fe56619 2222 }
7fd59977 2223 else
2224 {
2225 IsDragged = Standard_True;
7fd59977 2226 DragFirst = Standard_True;
2227 }
4fe56619 2228 }
18d715bd 2229 else if (aReport.xbutton.button == Button3)
4fe56619 2230 {
7fd59977 2231 // Start rotation
4fe56619 2232 VT_ProcessButton3Press();
2233 }
7fd59977 2234 }
2235 break;
2236 case ButtonRelease:
2237 {
7fd59977 2238 if( IsDragged )
2239 {
2240 if( !DragFirst )
2241 {
2242 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
18d715bd 2243 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2244 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 2245 }
2246
2247 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2248 if( aContext.IsNull() )
2249 {
2250 cout << "The context is null. Please use vinit before createmesh" << endl;
2251 return 0;
2252 }
2253
18d715bd 2254 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2255 if( aReport.xbutton.button==1 )
7fd59977 2256 if( DragFirst )
2257 if( ShiftPressed )
2258 {
2259 aContext->ShiftSelect();
7fd59977 2260 }
2261 else
2262 {
2263 aContext->Select();
7fd59977 2264 }
2265 else
2266 if( ShiftPressed )
2267 {
4fe56619 2268 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2269 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
7fd59977 2270 ViewerTest::CurrentView());
7fd59977 2271 }
2272 else
2273 {
4fe56619 2274 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2275 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
7fd59977 2276 ViewerTest::CurrentView() );
7fd59977 2277 }
2278 else
4fe56619 2279 VT_ProcessButton3Release();
7fd59977 2280
2281 IsDragged = Standard_False;
2282 }
2283 else
4fe56619 2284 VT_ProcessButton3Release();
7fd59977 2285 }
2286 break;
2287 case MotionNotify:
2288 {
08398024 2289 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2290 {
2291 break;
2292 }
7fd59977 2293 if( IsDragged )
2294 {
2295 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
18d715bd 2296 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2297 XSetFunction( aDisplay, gc, GXinvert );
7fd59977 2298
2299 if( !DragFirst )
18d715bd 2300 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 2301
18d715bd 2302 X_Motion = aReport.xmotion.x;
2303 Y_Motion = aReport.xmotion.y;
7fd59977 2304 DragFirst = Standard_False;
2305
18d715bd 2306 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 2307 }
2308 else
2309 {
18d715bd 2310 X_Motion = aReport.xmotion.x;
2311 Y_Motion = aReport.xmotion.y;
7fd59977 2312
18d715bd 2313 // remove all the ButtonMotionMaskr
2314 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
7fd59977 2315
18d715bd 2316 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
7fd59977 2317 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2318
2319 Quantity_Length VDX, VDY;
2320
2321 ViewerTest::CurrentView()->Size(VDX,VDY);
2322 Standard_Real VDZ =0 ;
2323 VDZ = ViewerTest::CurrentView()->ZSize();
2324
7fd59977 2325 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2326
2327 Quantity_Length dx = 0 ;
2328 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2329
2330 cout << dx << endl;
2331
2332 dx = dx / VDX * VDZ;
2333
2334 cout << dx << endl;
2335
7fd59977 2336 ViewerTest::CurrentView()->Redraw();
2337 }
2338 }
2339
18d715bd 2340 if ( aReport.xmotion.state & ControlMask ) {
2341 if ( aReport.xmotion.state & Button1Mask ) {
7fd59977 2342 ProcessControlButton1Motion();
2343 }
18d715bd 2344 else if ( aReport.xmotion.state & Button2Mask ) {
4fe56619 2345 VT_ProcessControlButton2Motion();
7fd59977 2346 }
18d715bd 2347 else if ( aReport.xmotion.state & Button3Mask ) {
4fe56619 2348 VT_ProcessControlButton3Motion();
7fd59977 2349 }
2350 }
4fe56619 2351 else
2352 {
2353 VT_ProcessMotion();
7fd59977 2354 }
2355 }
2356 }
2357 break;
2358}
7fd59977 2359return pick;
2360}
2361
2362//==============================================================================
2363//function : VProcessEvents
2364//purpose : call by Tk_CreateFileHandler() to be able to manage the
2365// event in the Viewer window
2366//==============================================================================
2367
2368static void VProcessEvents(ClientData,int)
2369{
18d715bd 2370 NCollection_Vector<int> anEventNumbers;
2371 // Get number of messages from every display
2372 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2373 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2374 {
2375 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
4269bd1b 2376 }
18d715bd 2377 // Handle events for every display
2378 int anEventIter = 0;
2379 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2380 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2381 {
4269bd1b 2382 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
18d715bd 2383 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2384 {
2385 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2386 int anEventResult = ViewerMainLoop( 0, NULL);
2387 // If window is closed or context was not found finish current event processing loop
2388 if (!anEventResult)
2389 return;
2390 }
7fd59977 2391 }
4269bd1b 2392
18d715bd 2393 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
4269bd1b 2394
7fd59977 2395}
2396#endif
2397
2398//==============================================================================
2399//function : OSWindowSetup
2400//purpose : Setup for the X11 window to be able to cath the event
2401//==============================================================================
2402
2403
2404static void OSWindowSetup()
2405{
4fe56619 2406#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 2407 // X11
2408
2409 Window window = VT_GetWindow()->XWindow();
18d715bd 2410 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2411 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2412 XSynchronize(aDisplay, 1);
7fd59977 2413
2414 // X11 : For keyboard on SUN
2415 XWMHints wmhints;
2416 wmhints.flags = InputHint;
2417 wmhints.input = 1;
2418
18d715bd 2419 XSetWMHints( aDisplay, window, &wmhints);
7fd59977 2420
18d715bd 2421 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
7fd59977 2422 ButtonPressMask | ButtonReleaseMask |
2423 StructureNotifyMask |
2424 PointerMotionMask |
2425 Button1MotionMask | Button2MotionMask |
18d715bd 2426 Button3MotionMask | FocusChangeMask
7fd59977 2427 );
18d715bd 2428 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2429 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
7fd59977 2430
18d715bd 2431 XSynchronize(aDisplay, 0);
7fd59977 2432
2433#else
2434 // WNT
2435#endif
2436
2437}
2438
2439
2440//==============================================================================
2441//function : VFit
2442
2443//purpose : Fitall, no DRAW arguments
2444//Draw arg : No args
2445//==============================================================================
2446
2447static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2448{
2449 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2450 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2451 if (V.IsNull() == Standard_False) {
2452 V->FitAll3d();
2453 } else if (aView.IsNull() == Standard_False) {
2454 aView->FitAll();
2455 }
2456 return 0;
2457}
2458
2459//==============================================================================
2460//function : VZFit
2461//purpose : ZFitall, no DRAW arguments
2462//Draw arg : No args
2463//==============================================================================
197ac94e 2464static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 2465{
197ac94e 2466 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2467
2468 if (aCurrentView.IsNull())
2469 {
2470 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2471 return 1;
2472 }
2473
2474 if (theArgsNb == 1)
2475 {
2476 aCurrentView->ZFitAll();
2477 aCurrentView->Redraw();
2478 return 0;
2479 }
2480
2481 Standard_Real aScale = 1.0;
2482
2483 if (theArgsNb >= 2)
2484 {
2485 aScale = Draw::Atoi (theArgVec[1]);
2486 }
2487
2488 aCurrentView->ZFitAll (aScale);
2489 aCurrentView->Redraw();
7fd59977 2490
197ac94e 2491 return 0;
2492}
7fd59977 2493
197ac94e 2494//==============================================================================
2495//function : VRepaint
2496//purpose :
2497//==============================================================================
2498static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
7fd59977 2499{
2500 Handle(V3d_View) V = ViewerTest::CurrentView();
2501 if ( !V.IsNull() ) V->Redraw(); return 0;
2502}
2503
7fd59977 2504//==============================================================================
2505//function : VClear
2506//purpose : Remove all the object from the viewer
2507//Draw arg : No args
2508//==============================================================================
2509
2510static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2511{
2512 Handle(V3d_View) V = ViewerTest::CurrentView();
2513 if(!V.IsNull())
2514 ViewerTest::Clear();
2515 return 0;
2516}
2517
2518//==============================================================================
2519//function : VPick
2520//purpose :
2521//==============================================================================
2522
2523static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2524{ if (ViewerTest::CurrentView().IsNull() ) return 1;
2525
2526if ( argc < 4 ) {
2527 di << argv[0] << "Invalid number of arguments" << "\n";
2528 return 1;
2529}
2530
2531while (ViewerMainLoop( argc, argv)) {
2532}
2533
2534return 0;
2535}
2536
7fd59977 2537//==============================================================================
2538//function : InitViewerTest
2539//purpose : initialisation de toutes les variables static de ViewerTest (dp)
2540//==============================================================================
2541
18d715bd 2542void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
7fd59977 2543{
18d715bd 2544 Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2545 ViewerTest::SetAISContext(theContext);
2546 aViewer->InitActiveViews();
2547 Handle(V3d_View) aView = aViewer->ActiveView();
2548 if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
7fd59977 2549 ViewerTest::ResetEventManager();
18d715bd 2550 Handle(Aspect_Window) aWindow = aView->Window();
4fe56619 2551#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 2552 // X11
18d715bd 2553 VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
7fd59977 2554 OSWindowSetup();
18d715bd 2555 static int aFirst = 1;
2556 if ( aFirst ) {
7fd59977 2557#if TCL_MAJOR_VERSION < 8
18d715bd 2558 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 2559 TK_READABLE, VProcessEvents, (ClientData) 0);
2560#else
18d715bd 2561 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 2562 TK_READABLE, VProcessEvents, (ClientData) 0);
2563#endif
18d715bd 2564 aFirst = 0;
7fd59977 2565 }
2566#endif
2567}
2568
7fd59977 2569//==============================================================================
2570//function : VSetBg
2571//purpose : Load image as background
2572//==============================================================================
2573
2574static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2575{
2576 if (argc < 2 || argc > 3)
2577 {
2578 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
f8b2ed36 2579 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
7fd59977 2580 return 1;
2581 }
2582
2583 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2584 if(AISContext.IsNull())
2585 {
2586 di << "use 'vinit' command before " << argv[0] << "\n";
2587 return 1;
2588 }
2589
2590 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2591 if (argc == 3)
2592 {
2593 const char* szType = argv[2];
2594 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2595 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2596 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2597 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2598 else
2599 {
2600 di << "Wrong fill type : " << szType << "\n";
2601 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2602 return 1;
2603 }
2604 }
2605
2606 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2607 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2608
2609 return 0;
2610}
2611
f8b2ed36 2612//==============================================================================
2613//function : VSetBgMode
2614//purpose : Change background image fill type
2615//==============================================================================
2616
2617static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2618{
2619 if (argc != 2)
2620 {
2621 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2622 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2623 return 1;
2624 }
2625
2626 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2627 if(AISContext.IsNull())
2628 {
2629 di << "use 'vinit' command before " << argv[0] << "\n";
2630 return 1;
2631 }
1d47d8d0 2632 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2633 const char* szType = argv[1];
2634 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2635 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2636 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2637 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2638 else
f8b2ed36 2639 {
1d47d8d0 2640 di << "Wrong fill type : " << szType << "\n";
2641 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2642 return 1;
f8b2ed36 2643 }
f8b2ed36 2644 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2645 V3dView->SetBgImageStyle(aFillType, Standard_True);
f8b2ed36 2646 return 0;
2647}
2648
7fd59977 2649//==============================================================================
2650//function : VSetGradientBg
2651//purpose : Mount gradient background
2652//==============================================================================
2653static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2654{
2655 if (argc != 8 )
2656 {
2657 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2658 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2659 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2660 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2661 return 1;
2662 }
2663
2664 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2665 if(AISContext.IsNull())
2666 {
2667 di << "use 'vinit' command before " << argv[0] << "\n";
2668 return 1;
2669 }
2670 if (argc == 8)
2671 {
2672
91322f44 2673 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2674 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2675 Standard_Real B1 = Draw::Atof(argv[3])/255.;
7fd59977 2676 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2677
91322f44 2678 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2679 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2680 Standard_Real B2 = Draw::Atof(argv[6])/255.;
7fd59977 2681
2682 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
91322f44 2683 int aType = Draw::Atoi(argv[7]);
7fd59977 2684 if( aType < 0 || aType > 8 )
2685 {
2686 di << "Wrong fill type " << "\n";
2687 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2688 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2689 return 1;
2690 }
2691
2692 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2693
2694 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2695 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2696 }
2697
2698 return 0;
2699}
2700
f8b2ed36 2701//==============================================================================
2702//function : VSetGradientBgMode
2703//purpose : Change gradient background fill style
2704//==============================================================================
2705static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2706{
2707 if (argc != 2 )
2708 {
2709 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2710 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2711 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2712 return 1;
2713 }
2714
2715 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2716 if(AISContext.IsNull())
2717 {
2718 di << "use 'vinit' command before " << argv[0] << "\n";
2719 return 1;
2720 }
2721 if (argc == 2)
2722 {
91322f44 2723 int aType = Draw::Atoi(argv[1]);
f8b2ed36 2724 if( aType < 0 || aType > 8 )
2725 {
2726 di << "Wrong fill type " << "\n";
2727 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2728 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2729 return 1;
2730 }
2731
2732 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2733
2734 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2735 V3dView->SetBgGradientStyle( aMethod, 1 );
2736 }
2737
2738 return 0;
2739}
2740
2741//==============================================================================
2742//function : VSetColorBg
2743//purpose : Set color background
2744//==============================================================================
2745static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2746{
2747 if (argc != 4 )
2748 {
2749 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2750 di << "R,G,B = [0..255]" << "\n";
2751 return 1;
2752 }
2753
2754 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2755 if(AISContext.IsNull())
2756 {
2757 di << "use 'vinit' command before " << argv[0] << "\n";
2758 return 1;
2759 }
2760 if (argc == 4)
2761 {
2762
91322f44 2763 Standard_Real R = Draw::Atof(argv[1])/255.;
2764 Standard_Real G = Draw::Atof(argv[2])/255.;
2765 Standard_Real B = Draw::Atof(argv[3])/255.;
f8b2ed36 2766 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2767
2768 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2769 V3dView->SetBackgroundColor( aColor );
2770 V3dView->Update();
2771 }
2772
2773 return 0;
2774}
2775
7fd59977 2776//==============================================================================
2777//function : VScale
2778//purpose : View Scaling
2779//==============================================================================
2780
2781static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2782{
2783 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2784 if ( V3dView.IsNull() ) return 1;
2785
2786 if ( argc != 4 ) {
2787 di << argv[0] << "Invalid number of arguments" << "\n";
2788 return 1;
2789 }
91322f44 2790 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
7fd59977 2791 return 0;
2792}
2793//==============================================================================
2794//function : VTestZBuffTrihedron
7c8a8fcc 2795//purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
7fd59977 2796//==============================================================================
2797
2798static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2799{
2800 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2801 if ( V3dView.IsNull() ) return 1;
2802
7fd59977 2803 V3dView->ZBufferTriedronSetup();
7c8a8fcc 2804
2805 if ( argc == 1 ) {
2806 // Set up default trihedron parameters
2807 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2808 } else
2809 if ( argc == 7 )
2810 {
2811 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2812 const char* aPosType = argv[1];
2813
2814 if ( strcmp(aPosType, "center") == 0 )
2815 {
2816 aPosition = Aspect_TOTP_CENTER;
2817 } else
2818 if (strcmp(aPosType, "left_lower") == 0)
2819 {
2820 aPosition = Aspect_TOTP_LEFT_LOWER;
2821 } else
2822 if (strcmp(aPosType, "left_upper") == 0)
2823 {
2824 aPosition = Aspect_TOTP_LEFT_UPPER;
2825 } else
2826 if (strcmp(aPosType, "right_lower") == 0)
2827 {
2828 aPosition = Aspect_TOTP_RIGHT_LOWER;
2829 } else
2830 if (strcmp(aPosType, "right_upper") == 0)
2831 {
2832 aPosition = Aspect_TOTP_RIGHT_UPPER;
2833 } else
2834 {
2835 di << argv[1] << " Invalid type of alignment" << "\n";
2836 di << "Must be one of [ center, left_lower," << "\n";
2837 di << "left_upper, right_lower, right_upper ]" << "\n";
2838 return 1;
2839 }
2840
91322f44 2841 Standard_Real R = Draw::Atof(argv[2])/255.;
2842 Standard_Real G = Draw::Atof(argv[3])/255.;
2843 Standard_Real B = Draw::Atof(argv[4])/255.;
7c8a8fcc 2844 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2845
91322f44 2846 Standard_Real aScale = Draw::Atof(argv[5]);
7c8a8fcc 2847
2848 if( aScale <= 0.0 )
2849 {
2850 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2851 return 1;
2852 }
2853
2854 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2855 const char* aPresType = argv[6];
2856
2857 if ( strcmp(aPresType, "wireframe") == 0 )
2858 {
2859 aPresentation = V3d_WIREFRAME;
2860 } else
2861 if (strcmp(aPresType, "zbuffer") == 0)
2862 {
2863 aPresentation = V3d_ZBUFFER;
2864 } else
2865 {
2866 di << argv[6] << " Invalid type of visualization" << "\n";
2867 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2868 return 1;
2869 }
2870
2871 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2872
2873 } else
2874 {
2875 di << argv[0] << " Invalid number of arguments" << "\n";
2876 return 1;
2877 }
2878
7fd59977 2879 V3dView->ZFitAll();
7c8a8fcc 2880
7fd59977 2881 return 0;
2882}
2883
2884//==============================================================================
2885//function : VRotate
2886//purpose : Camera Rotating
2887//==============================================================================
2888
2889static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2890 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2891 if ( V3dView.IsNull() ) {
2892 return 1;
2893 }
2894
2895 if ( argc == 4 ) {
91322f44 2896 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
7fd59977 2897 return 0;
2898 } else if ( argc == 7 ) {
91322f44 2899 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 2900 return 0;
2901 } else {
2902 di << argv[0] << " Invalid number of arguments" << "\n";
2903 return 1;
2904 }
2905}
2906
2907//==============================================================================
2908//function : VZoom
2909//purpose : View zoom in / out (relative to current zoom)
2910//==============================================================================
2911
2912static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2913 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2914 if ( V3dView.IsNull() ) {
2915 return 1;
2916 }
2917
2918 if ( argc == 2 ) {
91322f44 2919 Standard_Real coef = Draw::Atof(argv[1]);
7fd59977 2920 if ( coef <= 0.0 ) {
2921 di << argv[1] << "Invalid value" << "\n";
2922 return 1;
2923 }
91322f44 2924 V3dView->SetZoom( Draw::Atof(argv[1]) );
7fd59977 2925 return 0;
2926 } else {
2927 di << argv[0] << " Invalid number of arguments" << "\n";
2928 return 1;
2929 }
2930}
2931
2932//==============================================================================
2933//function : VPan
2934//purpose : View panning (in pixels)
2935//==============================================================================
2936
2937static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2938 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2939 if ( V3dView.IsNull() ) return 1;
2940
2941 if ( argc == 3 ) {
91322f44 2942 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
7fd59977 2943 return 0;
2944 } else {
2945 di << argv[0] << " Invalid number of arguments" << "\n";
2946 return 1;
2947 }
2948}
2949
2950
2951//==============================================================================
2952//function : VExport
5cedc27f 2953//purpose : Export the view to a vector graphic format (PS, EMF, PDF)
7fd59977 2954//==============================================================================
2955
2956static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2957{
2958 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
5cedc27f
K
2959 if (V3dView.IsNull())
2960 return 1;
7fd59977 2961
5cedc27f
K
2962 if (argc == 1)
2963 {
2964 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
7fd59977 2965 return 1;
2966 }
2967
5cedc27f
K
2968 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2969 TCollection_AsciiString aFormatStr;
2970
2971 TCollection_AsciiString aFileName (argv[1]);
2972 Standard_Integer aLen = aFileName.Length();
2973
2974 if (argc > 2)
2975 {
2976 aFormatStr = TCollection_AsciiString (argv[2]);
2977 }
2978 else if (aLen >= 4)
2979 {
2980 if (aFileName.Value (aLen - 2) == '.')
2981 {
2982 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2983 }
2984 else if (aFileName.Value (aLen - 3) == '.')
2985 {
2986 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2987 }
2988 else
2989 {
2990 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2991 return 1;
2992 }
2993 }
2994 else
2995 {
2996 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2997 return 1;
2998 }
2999
3000 aFormatStr.UpperCase();
3001 if (aFormatStr == "PS")
3002 anExpFormat = Graphic3d_EF_PostScript;
3003 else if (aFormatStr == "EPS")
3004 anExpFormat = Graphic3d_EF_EnhPostScript;
3005 else if (aFormatStr == "TEX")
3006 anExpFormat = Graphic3d_EF_TEX;
3007 else if (aFormatStr == "PDF")
3008 anExpFormat = Graphic3d_EF_PDF;
3009 else if (aFormatStr == "SVG")
3010 anExpFormat = Graphic3d_EF_SVG;
3011 else if (aFormatStr == "PGF")
3012 anExpFormat = Graphic3d_EF_PGF;
3013 else if (aFormatStr == "EMF")
3014 anExpFormat = Graphic3d_EF_EMF;
3015 else
3016 {
3017 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3018 return 1;
3019 }
3020
9753e6de 3021 try {
3022 if (!V3dView->View()->Export (argv[1], anExpFormat))
3023 {
3024 di << "Error: export of image to " << aFormatStr << " failed!\n";
3025 }
3026 }
3027 catch (Standard_Failure)
5cedc27f 3028 {
9753e6de 3029 di << "Error: export of image to " << aFormatStr << " failed";
3030 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
5cedc27f 3031 }
7fd59977 3032 return 0;
3033}
3034
3035//==============================================================================
3036//function : VColorScale
3037//purpose : representation color scale
3038//==============================================================================
3039#include <V3d_ColorScale.hxx>
3040
3041static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3042{
3043 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
3044 {
3045 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
3046 return 1;
3047 }
3048
3049 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3050 if(aContext.IsNull()) {
3051 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
3052 return -1;
3053 }
3054
3055 Standard_Real minRange = 0. , maxRange = 100. ;
3056
3057 Standard_Integer numIntervals = 10 ;
208e6839 3058 Standard_Integer textHeight = 16;
7fd59977 3059 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
3060 Standard_Real X = 0., Y = 0. ;
3061
3062 if ( argc < 9 )
3063 {
3064 if( argc > 3 )
3065 {
91322f44 3066 minRange = Draw::Atof( argv[1] );
3067 maxRange = Draw::Atof( argv[2] );
3068 numIntervals = Draw::Atoi( argv[3] );
7fd59977 3069 }
3070 if ( argc > 4 )
91322f44 3071 textHeight = Draw::Atoi( argv[4] );
7fd59977 3072 if ( argc > 5 )
91322f44 3073 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
7fd59977 3074 if ( argc > 7 )
3075 {
91322f44 3076 X = Draw::Atof( argv[6] );
3077 Y = Draw::Atof( argv[7] );
7fd59977 3078 }
3079 }
3080 Handle(V3d_View) curView = ViewerTest::CurrentView( );
3081 if ( curView.IsNull( ) )
3082 return 1;
3083 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
3084 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
3085 if( ! aCS.IsNull( ) )
3086 {
3087 aCS->SetPosition( X , Y );
3088 aCS->SetHeight( 0.95) ;
3089 aCS->SetTextHeight( textHeight );
3090 aCS->SetRange( minRange , maxRange );
3091 aCS->SetNumberOfIntervals( numIntervals );
3092 aCS->SetLabelPosition( position );
3093 if( !curView->ColorScaleIsDisplayed() )
3094 curView->ColorScaleDisplay( );
3095 }
3096 return 0;
3097}
3098
3099//==============================================================================
3100//function : VGraduatedTrihedron
3101//purpose : Displays a graduated trihedron
3102//==============================================================================
13a22457
S
3103
3104static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
3105{
3106 const char *str = arg;
3107 while (*str)
3108 {
3109 unsigned short c1 = *str++;
3110 unsigned short c2 = *str++;
3111 if (!c1 || !c2) break;
3112 name += (Standard_ExtCharacter)((c1 << 8) | c2);
3113 }
3114}
3115
7fd59977 3116static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3117{
13a22457
S
3118 // Check arguments
3119 if (argc != 2 && argc < 5)
3120 {
3121 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3122 di<<"Usage: type help "<<argv[0]<<"\n";
3123 return 1; //TCL_ERROR
3124 }
7fd59977 3125
13a22457
S
3126 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3127
3128 // Create 3D view if it doesn't exist
3129 if ( aV3dView.IsNull() )
7fd59977 3130 {
4fe56619 3131 ViewerTest::ViewerInit();
13a22457
S
3132 aV3dView = ViewerTest::CurrentView();
3133 if( aV3dView.IsNull() )
3134 {
3135 di << "Error: Cannot create a 3D view\n";
3136 return 1; //TCL_ERROR
3137 }
7fd59977 3138 }
3139
13a22457 3140 // Erase (==0) or display (!=0)
91322f44 3141 const int display = Draw::Atoi(argv[1]);
7fd59977 3142
13a22457 3143 if (display)
7fd59977 3144 {
13a22457
S
3145 // Text font
3146 TCollection_AsciiString font;
3147 if (argc < 6)
3148 font.AssignCat("Courier");
3149 else
3150 font.AssignCat(argv[5]);
3151
3152 // Text is multibyte
91322f44 3153 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
13a22457
S
3154
3155 // Set axis names
3156 TCollection_ExtendedString xname, yname, zname;
3157 if (argc >= 5)
3158 {
3159 if (isMultibyte)
7fd59977 3160 {
13a22457
S
3161 AddMultibyteString(xname, argv[2]);
3162 AddMultibyteString(yname, argv[3]);
3163 AddMultibyteString(zname, argv[4]);
7fd59977 3164 }
13a22457
S
3165 else
3166 {
3167 xname += argv[2];
3168 yname += argv[3];
3169 zname += argv[4];
3170 }
3171 }
3172 else
3173 {
3174 xname += "X (mm)";
3175 yname += "Y (mm)";
3176 zname += "Z (mm)";
3177 }
7fd59977 3178
13a22457
S
3179 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3180 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3181 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3182 Standard_True/*drawgrid*/,
3183 Standard_True/*drawaxes*/,
3184 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3185 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3186 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3187 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3188 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3189 Quantity_NOC_WHITE/*gridcolor*/,
3190 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3191 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3192 }
7fd59977 3193 else
13a22457 3194 aV3dView->GraduatedTrihedronErase();
7fd59977 3195
3196 ViewerTest::GetAISContext()->UpdateCurrentViewer();
13a22457
S
3197 aV3dView->Redraw();
3198
7fd59977 3199 return 0;
3200}
3201
7edf74fd
A
3202//==============================================================================
3203//function : VPrintView
3204//purpose : Test printing algorithm, print the view to image file with given
3205// width and height. Printing implemented only for WNT.
3206//==============================================================================
4fe56619 3207static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
7edf74fd
A
3208 const char** argv)
3209{
3210#ifndef WNT
3211 di << "Printing implemented only for wnt!\n";
b5ac8292 3212 return 0;
7edf74fd
A
3213#else
3214
3215 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3216 Handle(V3d_View) aView = NULL;
3217 aContextAIS = ViewerTest::GetAISContext();
3218 if (!aContextAIS.IsNull())
3219 {
3220 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3221 Vwr->InitActiveViews();
3222 if(Vwr->MoreActiveViews())
3223 aView = Vwr->ActiveView();
3224 }
3225
3226 // check for errors
3227 if (aView.IsNull())
3228 {
3229 di << "Call vinit before!\n";
3230 return 1;
3231 }
3232 else if (argc < 4)
3233 {
3234 di << "Use: " << argv[0];
b5ac8292 3235 di << " width height filename [print algo=0] [tile_width tile_height]\n";
7edf74fd
A
3236 di << "width, height of the intermediate buffer for operation\n";
3237 di << "algo : {0|1}\n";
3238 di << " 0 - stretch algorithm\n";
3239 di << " 1 - tile algorithm\n";
3240 di << "test printing algorithms into an intermediate buffer\n";
b5ac8292 3241 di << "using specific tile size if provided\n";
7edf74fd
A
3242 di << "with saving output to an image file\n";
3243 return 1;
3244 }
3245
3246 // get the input params
91322f44 3247 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3248 Standard_Integer aHeight = Draw::Atoi (argv[2]);
7edf74fd
A
3249 Standard_Integer aMode = 0;
3250 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
b5ac8292 3251 if (argc >= 5)
91322f44 3252 aMode = Draw::Atoi (argv[4]);
7edf74fd 3253
b5ac8292 3254 Standard_Integer aTileWidth = 0;
3255 Standard_Integer aTileHeight = 0;
3256 Standard_Boolean isTileSizeProvided = Standard_False;
3257 if (argc == 7)
3258 {
3259 isTileSizeProvided = Standard_True;
3260 aTileWidth = Draw::Atoi (argv[5]);
3261 aTileHeight = Draw::Atoi (argv[6]);
3262 }
3263
7edf74fd
A
3264 // check the input parameters
3265 if (aWidth <= 0 || aHeight <= 0)
3266 {
3267 di << "Width and height must be positive values!\n";
3268 return 1;
3269 }
3270 if (aMode != 0 && aMode != 1)
3271 aMode = 0;
3272
7edf74fd 3273 // define compatible bitmap
692613e5 3274 HDC anDC = CreateCompatibleDC(0);
7edf74fd
A
3275 BITMAPINFO aBitmapData;
3276 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3277 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3278 aBitmapData.bmiHeader.biWidth = aWidth ;
3279 aBitmapData.bmiHeader.biHeight = aHeight;
3280 aBitmapData.bmiHeader.biPlanes = 1;
3281 aBitmapData.bmiHeader.biBitCount = 24;
3282 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3283 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3284 aBitmapData.bmiHeader.biClrUsed = 0;
3285 aBitmapData.bmiHeader.biClrImportant = 0;
3286 aBitmapData.bmiHeader.biCompression = BI_RGB;
3287 aBitmapData.bmiHeader.biSizeImage = 0;
3288
3289 // Create Device Independent Bitmap
692613e5 3290 void* aBitsOut = NULL;
7edf74fd 3291 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
692613e5 3292 &aBitsOut, NULL, 0);
7edf74fd
A
3293 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3294
3295 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
692613e5 3296 if (aBitsOut != NULL)
4fe56619 3297 {
7edf74fd
A
3298 if (aMode == 0)
3299 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3300 else
b5ac8292 3301 {
3302 if (isTileSizeProvided)
3303 {
3304 Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
3305 Graphic3d_PtrFrameBuffer anOldBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
3306 aCView->ptrFBO = aView->View()->FBOCreate (aTileWidth, aTileHeight);
3307
3308 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
3309
3310 Graphic3d_PtrFrameBuffer aNewBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
3311 aView->View()->FBORelease (aNewBuffer);
3312 aCView->ptrFBO = anOldBuffer;
3313 }
3314 else
3315 {
3316 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
3317 }
3318 }
7edf74fd
A
3319
3320 // succesfully printed into an intermediate buffer
3321 if (isPrinted)
3322 {
692613e5 3323 Image_PixMap aWrapper;
3324 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3325 aWrapper.SetTopDown (false);
3326
3327 Image_AlienPixMap anImageBitmap;
3328 anImageBitmap.InitCopy (aWrapper);
3329 isSaved = anImageBitmap.Save (aFileName);
7edf74fd
A
3330 }
3331 else
3332 {
3333 di << "Print operation failed due to printing errors or\n";
3334 di << "insufficient memory available\n";
3335 di << "Please, try to use smaller dimensions for this test\n";
3336 di << "command, as it allocates intermediate buffer for storing\n";
3337 di << "the result\n";
3338 }
3339 }
3340 else
3341 {
3342 di << "Can't allocate memory for intermediate buffer\n";
3343 di << "Please use smaller dimensions\n";
3344 }
3345
3346 if (aMemoryBitmap)
3347 {
3348 SelectObject (anDC, anOldBitmap);
3349 DeleteObject (aMemoryBitmap);
3350 DeleteDC(anDC);
3351 }
3352
3353 if (!isSaved)
3354 {
3355 di << "Save to file operation failed. This operation may fail\n";
3356 di << "if you don't have enough available memory, then you can\n";
3357 di << "use smaller dimensions for the output file\n";
3358 return 1;
3359 }
3360
3361 return 0;
3362
3363#endif
3364}
3365
59f45b7c 3366//==============================================================================
3367//function : VZLayer
3368//purpose : Test z layer operations for v3d viewer
3369//==============================================================================
3370static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3371{
3372 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3373 if (aContextAIS.IsNull())
3374 {
3375 di << "Call vinit before!\n";
3376 return 1;
3377 }
3378 else if (argc < 2)
3379 {
3380 di << "Use: vzlayer " << argv[0];
3381 di << " add/del/get [id]\n";
3382 di << " add - add new z layer to viewer and print its id\n";
3383 di << " del - del z layer by its id\n";
3384 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3385 di << "id - the layer identificator value defined when removing z layer\n";
3386 return 1;
3387 }
3388
3389 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3390 if (aViewer.IsNull())
3391 {
3392 di << "No active viewer!\n";
3393 return 1;
3394 }
3395
3396 // perform operation
3397 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3398 if (anOp == "add")
3399 {
3400 Standard_Integer aNewId;
3401 if (!aViewer->AddZLayer (aNewId))
3402 {
3403 di << "Impossible to add new z layer!\n";
3404 return 1;
3405 }
3406
3407 di << "New z layer added with index: " << aNewId << "\n";
3408 }
3409 else if (anOp == "del")
3410 {
3411 if (argc < 3)
3412 {
3413 di << "Please also provide as argument id of z layer to remove\n";
3414 return 1;
3415 }
3416
91322f44 3417 Standard_Integer aDelId = Draw::Atoi (argv[2]);
59f45b7c 3418 if (!aViewer->RemoveZLayer (aDelId))
3419 {
3420 di << "Impossible to remove the z layer or invalid id!\n";
3421 return 1;
3422 }
3423
3424 di << "Z layer " << aDelId << " has been removed\n";
3425 }
3426 else if (anOp == "get")
3427 {
3428 TColStd_SequenceOfInteger anIds;
3429 aViewer->GetAllZLayers (anIds);
3430 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3431 {
3432 di << anIds.Value (aSeqIdx) << " ";
3433 }
3434
3435 di << "\n";
3436 }
3437 else
3438 {
3439 di << "Invalid operation, please use { add / del / get }\n";
3440 return 1;
3441 }
3442
3443 return 0;
3444}
3445
25289ec1 3446DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3447
3448// this class provides a presentation of text item in v3d view under-/overlayer
3449class V3d_TextItem : public Visual3d_LayerItem
3450{
3451public:
3452
3453 // CASCADE RTTI
3454 DEFINE_STANDARD_RTTI(V3d_TextItem)
3455
3456 // constructor
3457 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3458 const Standard_Real theX1,
3459 const Standard_Real theY1,
3460 const Standard_Real theHeight,
3461 const TCollection_AsciiString& theFontName,
3462 const Quantity_Color& theColor,
3463 const Quantity_Color& theSubtitleColor,
3464 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3465 const Handle(Visual3d_Layer)& theLayer);
3466
3467 // redraw method
3468 Standard_EXPORT void RedrawLayerPrs();
3469
3470private:
3471
3472 Standard_Real myX1;
3473 Standard_Real myY1;
25289ec1 3474 TCollection_AsciiString myText;
eafb234b 3475 Standard_Real myHeight;
3476 Handle(Visual3d_Layer) myLayer;
25289ec1 3477 Quantity_Color myColor;
3478 Quantity_Color mySubtitleColor;
3479 Aspect_TypeOfDisplayText myType;
eafb234b 3480 TCollection_AsciiString myFontName;
25289ec1 3481};
3482
3483IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3484IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3485
3486// create and add to display the text item
3487V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3488 const Standard_Real theX1,
3489 const Standard_Real theY1,
3490 const Standard_Real theHeight,
3491 const TCollection_AsciiString& theFontName,
3492 const Quantity_Color& theColor,
3493 const Quantity_Color& theSubtitleColor,
3494 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3495 const Handle(Visual3d_Layer)& theLayer)
3496 : myX1 (theX1), myY1 (theY1),
3497 myText (theText),
3498 myHeight (theHeight),
3499 myLayer (theLayer),
3500 myColor (theColor),
3501 mySubtitleColor (theSubtitleColor),
3502 myType (theTypeOfDisplay),
3503 myFontName (theFontName)
3504{
3505 if (!myLayer.IsNull ())
3506 myLayer->AddLayerItem (this);
3507}
3508
3509// render item
3510void V3d_TextItem::RedrawLayerPrs ()
4fe56619 3511{
25289ec1 3512 if (myLayer.IsNull ())
3513 return;
3514
3515 myLayer->SetColor (myColor);
3516 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3517 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3518}
3519
20637bd2 3520DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3521
3522// The Visual3d_LayerItem line item for "vlayerline" command
4fe56619 3523// it provides a presentation of line with user-defined
20637bd2 3524// linewidth, linetype and transparency.
4fe56619 3525class V3d_LineItem : public Visual3d_LayerItem
20637bd2 3526{
3527public:
3528 // CASCADE RTTI
4fe56619 3529 DEFINE_STANDARD_RTTI(V3d_LineItem)
3530
20637bd2 3531 // constructor
3532 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3533 Standard_Real X2, Standard_Real Y2,
3534 V3d_LayerMgrPointer theLayerMgr,
3535 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3536 Standard_Real theWidth = 0.5,
3537 Standard_Real theTransp = 1.0);
3538
3539 // redraw method
3540 Standard_EXPORT void RedrawLayerPrs();
3541
3542private:
3543
3544 Standard_Real myX1, myY1, myX2, myY2;
eafb234b 3545 V3d_LayerMgrPointer myLayerMgr;
3546 Aspect_TypeOfLine myType;
20637bd2 3547 Standard_Real myWidth;
3548 Standard_Real myTransparency;
20637bd2 3549};
3550
3551IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3552IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3553
3554// default constructor for line item
4fe56619 3555V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
20637bd2 3556 Standard_Real X2, Standard_Real Y2,
3557 V3d_LayerMgrPointer theLayerMgr,
3558 Aspect_TypeOfLine theType,
3559 Standard_Real theWidth,
3560 Standard_Real theTransp) :
3561 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3562 myType(theType), myWidth(theWidth), myTransparency(theTransp)
3563{
9e4c2fbb 3564 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
20637bd2 3565 myLayerMgr->Overlay()->AddLayerItem (this);
3566}
3567
3568// render line
3569void V3d_LineItem::RedrawLayerPrs ()
3570{
3571 Handle (Visual3d_Layer) aOverlay;
4fe56619 3572
20637bd2 3573 if (myLayerMgr)
3574 aOverlay = myLayerMgr->Overlay();
3575
3576 if (!aOverlay.IsNull())
3577 {
3578 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3579 aOverlay->SetColor(aColor);
3580 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3581 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3582 aOverlay->BeginPolyline();
3583 aOverlay->AddVertex(myX1, myY1);
3584 aOverlay->AddVertex(myX2, myY2);
3585 aOverlay->ClosePrimitive();
3586 }
3587}
3588
3589//=============================================================================
3590//function : VLayerLine
3591//purpose : Draws line in the v3d view layer with given attributes: linetype,
3592// : linewidth, transparency coefficient
3593//============================================================================
3594static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3595{
3596 // get the active view
3597 Handle(V3d_View) aView = ViewerTest::CurrentView();
3598 if (aView.IsNull())
3599 {
3600 di << "Call vinit before!\n";
3601 return 1;
3602 }
3603 else if (argc < 5)
3604 {
3605 di << "Use: " << argv[0];
3606 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3607 di << " linetype : { 0 | 1 | 2 | 3 } \n";
3608 di << " 0 - solid \n";
3609 di << " 1 - dashed \n";
3610 di << " 2 - dot \n";
3611 di << " 3 - dashdot\n";
3612 di << " transparency : { 0.0 - 1.0 } \n";
3613 di << " 0.0 - transparent\n";
3614 di << " 1.0 - visible \n";
3615 return 1;
3616 }
3617
3618 // get the input params
91322f44 3619 Standard_Real X1 = Draw::Atof(argv[1]);
3620 Standard_Real Y1 = Draw::Atof(argv[2]);
3621 Standard_Real X2 = Draw::Atof(argv[3]);
3622 Standard_Real Y2 = Draw::Atof(argv[4]);
20637bd2 3623
3624 Standard_Real aWidth = 0.5;
3625 Standard_Integer aType = 0;
3626 Standard_Real aTransparency = 1.0;
3627
3628 // has width
3629 if (argc > 5)
91322f44 3630 aWidth = Draw::Atof(argv[5]);
20637bd2 3631
3632 // has type
3633 if (argc > 6)
91322f44 3634 aType = (Standard_Integer) Draw::Atoi(argv[6]);
20637bd2 3635
3636 // has transparency
3637 if (argc > 7)
3638 {
91322f44 3639 aTransparency = Draw::Atof(argv[7]);
4fe56619 3640 if (aTransparency < 0 || aTransparency > 1.0)
20637bd2 3641 aTransparency = 1.0;
3642 }
3643
3644 // select appropriate line type
3645 Aspect_TypeOfLine aLineType;
3646 switch (aType)
3647 {
3648 case 1:
3649 aLineType = Aspect_TOL_DASH;
3650 break;
3651
3652 case 2:
3653 aLineType = Aspect_TOL_DOT;
3654 break;
3655
3656 case 3:
3657 aLineType = Aspect_TOL_DOTDASH;
3658 break;
3659
3660 default:
3661 aLineType = Aspect_TOL_SOLID;
3662 }
3663
3664 // replace layer manager
3665 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3666 aView->SetLayerMgr(aMgr);
3667
3668 // add line item
4fe56619 3669 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
20637bd2 3670 aMgr.operator->(),
4fe56619 3671 aLineType, aWidth,
20637bd2 3672 aTransparency);
3673
3674 // update view
3675 aView->MustBeResized();
3676 aView->Redraw();
3677
3678 return 0;
3679}
3680
25289ec1 3681//=======================================================================
3682//function : VOverlayText
3683//purpose : Test text displaying in view overlay
3684//=======================================================================
3685static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3686{
3687 // get the active view
3688 Handle(V3d_View) aView = ViewerTest::CurrentView();
3689 if (aView.IsNull())
3690 {
3691 di << "No active view. Please call vinit.\n";
3692 return 1;
3693 }
3694 else if (argc < 4 || argc > 13)
3695 {
3696 di << "Use: " << argv[0];
3697 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3698 di << "[background_color: R G B]\n";
3699 di << " height - pixel height of the text (default=10.0)\n";
3700 di << " font_name - name of font (default=courier)\n";
3701 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
a6eb515f 3702 di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n";
25289ec1 3703 di << " background_color- R G B values used for subtitle and decal text\n";
3704 di << "(default=255.0 255.0 255.0)\n";
3705 return 1;
3706 }
4fe56619 3707
25289ec1 3708 TCollection_AsciiString aText (argv[1]);
91322f44 3709 Standard_Real aPosX = Draw::Atof(argv[2]);
3710 Standard_Real aPosY = Draw::Atof(argv[3]);
3711 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
25289ec1 3712
3713 // font name
3714 TCollection_AsciiString aFontName = "Courier";
3715 if (argc >= 6)
3716 aFontName = TCollection_AsciiString (argv[5]);
3717
3718 // text colors
3719 Quantity_Parameter aColorRed = 1.0;
3720 Quantity_Parameter aColorGreen = 1.0;
3721 Quantity_Parameter aColorBlue = 1.0;
3722 if (argc >= 9)
3723 {
91322f44 3724 aColorRed = Draw::Atof (argv[6])/255.;
3725 aColorGreen = Draw::Atof (argv[7])/255.;
3726 aColorBlue = Draw::Atof (argv[8])/255.;
25289ec1 3727 }
3728
3729 // display type
3730 TCollection_AsciiString aDispStr;
3731 if (argc >= 10)
3732 aDispStr = TCollection_AsciiString (argv[9]);
3733
3734 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3735 if (aDispStr.IsEqual ("subtitle"))
3736 aTextType = Aspect_TODT_SUBTITLE;
3737 else if (aDispStr.IsEqual ("decal"))
3738 aTextType = Aspect_TODT_DEKALE;
3739 else if (aDispStr.IsEqual ("blend"))
3740 aTextType = Aspect_TODT_BLEND;
a6eb515f 3741 else if (aDispStr.IsEqual ("dimension"))
3742 aTextType = Aspect_TODT_DIMENSION;
25289ec1 3743
3744 // subtitle color
3745 Quantity_Parameter aSubRed = 1.0;
3746 Quantity_Parameter aSubGreen = 1.0;
3747 Quantity_Parameter aSubBlue = 1.0;
3748 if (argc == 13)
3749 {
91322f44 3750 aSubRed = Draw::Atof (argv[10])/255.;
3751 aSubGreen = Draw::Atof (argv[11])/255.;
3752 aSubBlue = Draw::Atof (argv[12])/255.;
25289ec1 3753 }
3754
3755 // check fo current overlay
3756 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
3757 if (anOverlay.IsNull ())
3758 {
3759 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
3760 anOverlay = aMgr->Overlay ();
3761 aView->SetLayerMgr (aMgr);
3762 }
3763
4fe56619 3764 Quantity_Color aTextColor (aColorRed, aColorGreen,
25289ec1 3765 aColorBlue, Quantity_TOC_RGB);
4fe56619 3766 Quantity_Color aSubtColor (aSubRed, aSubGreen,
25289ec1 3767 aSubBlue, Quantity_TOC_RGB);
3768
3769 // add text item
3770 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
3771 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
3772
3773 // update view
3774 aView->MustBeResized();
3775 aView->Redraw();
3776
3777 return 0;
3778}
3779
2bd4c032 3780//==============================================================================
3781//function : VGrid
3782//purpose :
3783//==============================================================================
3784
35e08fe8 3785static int VGrid (Draw_Interpretor& /*theDI*/,
2bd4c032 3786 Standard_Integer theArgNb,
3787 const char** theArgVec)
3788{
3789 // get the active view
3790 Handle(V3d_View) aView = ViewerTest::CurrentView();
3791 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3792 if (aView.IsNull() || aViewer.IsNull())
3793 {
3794 std::cerr << "No active view. Please call vinit.\n";
3795 return 1;
3796 }
3797
3798 Aspect_GridType aType = aViewer->GridType();
3799 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
3800
3801 Standard_Integer anIter = 1;
3802 for (; anIter < theArgNb; ++anIter)
3803 {
3804 const char* aValue = theArgVec[anIter];
3805 if (*aValue == 'r')
3806 {
3807 aType = Aspect_GT_Rectangular;
3808 }
3809 else if (*aValue == 'c')
3810 {
3811 aType = Aspect_GT_Circular;
3812 }
3813 else if (*aValue == 'l')
3814 {
3815 aMode = Aspect_GDM_Lines;
3816 }
3817 else if (*aValue == 'p')
3818 {
3819 aMode = Aspect_GDM_Points;
3820 }
3821 else if (strcmp (aValue, "off" ) == 0)
3822 {
3823 aViewer->DeactivateGrid();
3824 return 0;
3825 }
3826 else
3827 {
3828 break;
3829 }
3830 }
3831
3832 Standard_Integer aTail = (theArgNb - anIter);
3833 if (aTail == 0)
3834 {
3835 aViewer->ActivateGrid (aType, aMode);
3836 return 0;
3837 }
3838 else if (aTail != 2 && aTail != 5)
3839 {
3840 std::cerr << "Incorrect arguments number! Usage:\n"
3841 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
3842 return 1;
3843 }
3844
3845 Quantity_Length anOriginX, anOriginY;
3846 Quantity_PlaneAngle aRotAngle;
3847 if (aType == Aspect_GT_Rectangular)
3848 {
3849 Quantity_Length aRStepX, aRStepY;
3850 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3851
91322f44 3852 anOriginX = Draw::Atof (theArgVec[anIter++]);
3853 anOriginY = Draw::Atof (theArgVec[anIter++]);
2bd4c032 3854 if (aTail == 5)
3855 {
91322f44 3856 aRStepX = Draw::Atof (theArgVec[anIter++]);
3857 aRStepY = Draw::Atof (theArgVec[anIter++]);
3858 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2bd4c032 3859 }
3860 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3861 aViewer->ActivateGrid (aType, aMode);
3862 }
3863 else if (aType == Aspect_GT_Circular)
3864 {
3865 Quantity_Length aRadiusStep;
3866 Standard_Integer aDivisionNumber;
3867 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3868
91322f44 3869 anOriginX = Draw::Atof (theArgVec[anIter++]);
3870 anOriginY = Draw::Atof (theArgVec[anIter++]);
2bd4c032 3871 if (aTail == 5)
3872 {
91322f44 3873 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
3874 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
3875 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2bd4c032 3876 }
3877
3878 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3879 aViewer->ActivateGrid (aType, aMode);
3880 }
3881
3882 return 0;
3883}
3884
208e6839 3885//==============================================================================
3886//function : VFps
3887//purpose :
3888//==============================================================================
3889
3890static int VFps (Draw_Interpretor& theDI,
3891 Standard_Integer theArgNb,
3892 const char** theArgVec)
3893{
3894 // get the active view
3895 Handle(V3d_View) aView = ViewerTest::CurrentView();
3896 if (aView.IsNull())
3897 {
3898 std::cerr << "No active view. Please call vinit.\n";
3899 return 1;
3900 }
3901
91322f44 3902 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
208e6839 3903 if (aFramesNb <= 0)
3904 {
3905 std::cerr << "Incorrect arguments!\n";
3906 return 1;
3907 }
3908
3909 // the time is meaningless for first call
3910 // due to async OpenGl rendering
3911 aView->Redraw();
3912
3913 // redraw view in loop to estimate average values
3914 OSD_Timer aTimer;
3915 aTimer.Start();
3916 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
3917 {
3918 aView->Redraw();
3919 }
3920 aTimer.Stop();
3921 Standard_Real aCpu;
3922 const Standard_Real aTime = aTimer.ElapsedTime();
3923 aTimer.OSD_Chronometer::Show (aCpu);
3924
3925 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
3926 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
3927
3928 // return statistics
3929 theDI << "FPS: " << aFpsAver << "\n"
3930 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
3931
3932 return 0;
3933}
3934
58655684 3935//==============================================================================
3936//function : VGlDebug
3937//purpose :
3938//==============================================================================
3939
3940static int VGlDebug (Draw_Interpretor& theDI,
3941 Standard_Integer theArgNb,
3942 const char** theArgVec)
3943{
3944 if (theArgNb < 2)
3945 {
3946 Handle(V3d_View) aView = ViewerTest::CurrentView();
3947 if (aView.IsNull())
3948 {
3949 std::cerr << "No active view. Please call vinit.\n";
3950 return 0;
3951 }
3952
3953 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
3954 "GL_ARB_debug_output");
3955 std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
3956 theDI << (isActive ? "1" : "0");
3957 return 0;
3958 }
3959
3960 ViewerTest_myDefaultCaps.contextDebug = Draw::Atoi (theArgVec[1]) != 0;
3961 return 0;
3962}
208e6839 3963
3964//==============================================================================
3965//function : VVbo
3966//purpose :
3967//==============================================================================
3968
58655684 3969static int VVbo (Draw_Interpretor& theDI,
208e6839 3970 Standard_Integer theArgNb,
3971 const char** theArgVec)
3972{
58655684 3973 const Standard_Boolean toSet = (theArgNb > 1);
3974 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
3975 if (toSet)
208e6839 3976 {
58655684 3977 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
208e6839 3978 }
3979
58655684 3980 // get the context
3981 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3982 if (aContextAIS.IsNull())
208e6839 3983 {
58655684 3984 if (!toSet)
3985 {
3986 std::cerr << "No active view!\n";
3987 }
208e6839 3988 return 1;
3989 }
58655684 3990 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3991 if (!aDriver.IsNull())
208e6839 3992 {
58655684 3993 if (!toSet)
3994 {
3995 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
3996 }
3997 else
3998 {
3999 aDriver->ChangeOptions().vboDisable = toUseVbo;
4000 }
208e6839 4001 }
4002
208e6839 4003 return 0;
4004}
4005
a577aaab 4006//==============================================================================
4007//function : VCaps
4008//purpose :
4009//==============================================================================
4010
4011static int VCaps (Draw_Interpretor& theDI,
4012 Standard_Integer theArgNb,
4013 const char** theArgVec)
4014{
4015 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
4016 Handle(OpenGl_GraphicDriver) aDriver;
4017 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4018 if (!aContextAIS.IsNull())
4019 {
4020 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
4021 aCaps = &aDriver->ChangeOptions();
4022 }
4023
4024 if (theArgNb < 2)
4025 {
4026 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
4027 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
abe46077 4028 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
a577aaab 4029 return 0;
4030 }
4031
4032 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4033 {
4034 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
4035 if (anArg.Search ("vbo=") > -1)
4036 {
4037 aCaps->vboDisable = anArg.Token ("=", 2).IntegerValue() == 0;
4038 }
4039 else if (anArg.Search ("sprites=") > -1)
4040 {
4041 aCaps->pntSpritesDisable = anArg.Token ("=", 2).IntegerValue() == 0;
4042 }
abe46077 4043 else if (anArg.Search ("soft=") > -1)
4044 {
4045 aCaps->contextNoAccel = anArg.Token ("=", 2).IntegerValue() != 0;
4046 }
a577aaab 4047 else
4048 {
4049 std::cerr << "Unknown argument: " << anArg << "\n";
4050 }
4051 }
4052 if (aCaps != &ViewerTest_myDefaultCaps)
4053 {
4054 ViewerTest_myDefaultCaps = *aCaps;
4055 }
4056 return 0;
4057}
4058
f0430952 4059//==============================================================================
4060//function : VMemGpu
4061//purpose :
4062//==============================================================================
4063
4064static int VMemGpu (Draw_Interpretor& theDI,
4065 Standard_Integer theArgNb,
4066 const char** theArgVec)
4067{
4068 // get the context
4069 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4070 if (aContextAIS.IsNull())
4071 {
4072 std::cerr << "No active view. Please call vinit.\n";
4073 return 1;
4074 }
4075
dc3fe572 4076 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
f0430952 4077 if (aDriver.IsNull())
4078 {
4079 std::cerr << "Graphic driver not available.\n";
4080 return 1;
4081 }
4082
4083 Standard_Size aFreeBytes = 0;
4084 TCollection_AsciiString anInfo;
4085 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
4086 {
4087 std::cerr << "Information not available.\n";
4088 return 1;
4089 }
4090
4091 if (theArgNb > 1 && *theArgVec[1] == 'f')
4092 {
4093 theDI << Standard_Real (aFreeBytes);
4094 }
4095 else
4096 {
4097 theDI << anInfo;
4098 }
4099
4100 return 0;
4101}
4102
85e096c3 4103// ==============================================================================
4104// function : VReadPixel
4105// purpose :
4106// ==============================================================================
4107static int VReadPixel (Draw_Interpretor& theDI,
4108 Standard_Integer theArgNb,
4109 const char** theArgVec)
4110{
4111 // get the active view
4112 Handle(V3d_View) aView = ViewerTest::CurrentView();
4113 if (aView.IsNull())
4114 {
4115 std::cerr << "No active view. Please call vinit.\n";
4116 return 1;
4117 }
4118 else if (theArgNb < 3)
4119 {
4120 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
4121 return 1;
4122 }
4123
692613e5 4124 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4125 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
4126
85e096c3 4127 Standard_Integer aWidth, aHeight;
4128 aView->Window()->Size (aWidth, aHeight);
91322f44 4129 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
4130 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
85e096c3 4131 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
4132 {
4133 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
4134 return 1;
4135 }
4136
4137 Standard_Boolean toShowName = Standard_False;
4138 Standard_Boolean toShowHls = Standard_False;
4139 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
4140 {
29cb310a 4141 const char* aParam = theArgVec[anIter];
4142 if ( strcasecmp( aParam, "rgb" ) == 0 )
85e096c3 4143 {
692613e5 4144 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4145 aBufferType = Graphic3d_BT_RGB;
85e096c3 4146 }
29cb310a 4147 else if ( strcasecmp( aParam, "hls" ) == 0 )
85e096c3 4148 {
692613e5 4149 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4150 aBufferType = Graphic3d_BT_RGB;
85e096c3 4151 toShowHls = Standard_True;
4152 }
29cb310a 4153 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
85e096c3 4154 {
692613e5 4155 aFormat = Image_PixMap::ImgRGBF;
4156 aBufferType = Graphic3d_BT_RGB;
85e096c3 4157 }
29cb310a 4158 else if ( strcasecmp( aParam, "rgba" ) == 0 )
85e096c3 4159 {
692613e5 4160 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4161 aBufferType = Graphic3d_BT_RGBA;
85e096c3 4162 }
29cb310a 4163 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
85e096c3 4164 {
692613e5 4165 aFormat = Image_PixMap::ImgRGBAF;
4166 aBufferType = Graphic3d_BT_RGBA;
85e096c3 4167 }
29cb310a 4168 else if ( strcasecmp( aParam, "depth" ) == 0 )
85e096c3 4169 {
692613e5 4170 aFormat = Image_PixMap::ImgGrayF;
4171 aBufferType = Graphic3d_BT_Depth;
85e096c3 4172 }
29cb310a 4173 else if ( strcasecmp( aParam, "name" ) == 0 )
85e096c3 4174 {
4175 toShowName = Standard_True;
4176 }
4177 }
4178
692613e5 4179 Image_PixMap anImage;
4180 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
4181 {
4182 std::cerr << "Image allocation failed\n";
4183 return 1;
4184 }
4185 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
85e096c3 4186 {
4187 std::cerr << "Image dump failed\n";
4188 return 1;
4189 }
4190
4191 Quantity_Parameter anAlpha;
692613e5 4192 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
85e096c3 4193 if (toShowName)
4194 {
692613e5 4195 if (aBufferType == Graphic3d_BT_RGBA)
85e096c3 4196 {
64c759f8 4197 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
85e096c3 4198 }
4199 else
4200 {
64c759f8 4201 theDI << Quantity_Color::StringName (aColor.Name());
85e096c3 4202 }
4203 }
4204 else
4205 {
4206 switch (aBufferType)
4207 {
4208 default:
692613e5 4209 case Graphic3d_BT_RGB:
85e096c3 4210 {
4211 if (toShowHls)
4212 {
64c759f8 4213 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
85e096c3 4214 }
4215 else
4216 {
64c759f8 4217 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
85e096c3 4218 }
4219 break;
4220 }
692613e5 4221 case Graphic3d_BT_RGBA:
85e096c3 4222 {
64c759f8 4223 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
85e096c3 4224 break;
4225 }
692613e5 4226 case Graphic3d_BT_Depth:
85e096c3 4227 {
64c759f8 4228 theDI << aColor.Red();
85e096c3 4229 break;
4230 }
4231 }
4232 }
4233
4234 return 0;
4235}
4236
692613e5 4237//==============================================================================
4238//function : VDiffImage
4239//purpose : The draw-command compares two images.
4240//==============================================================================
4241
4242static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4243{
4244 if (theArgNb < 6)
4245 {
4246 theDI << "Not enough arguments.\n";
4247 return 1;
4248 }
4249
4250 // image file names
4251 const char* anImgPathRef = theArgVec[1];
4252 const char* anImgPathNew = theArgVec[2];
4253
4254 // get string tolerance and check its validity
91322f44 4255 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
692613e5 4256 if (aTolColor < 0.0)
4257 aTolColor = 0.0;
4258 if (aTolColor > 1.0)
4259 aTolColor = 1.0;
4260
91322f44 4261 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
4262 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
692613e5 4263
4264 // image file of difference
4265 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
4266
4267 // compare the images
4268 Image_Diff aComparer;
4269 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
4270 {
4271 return 1;
4272 }
4273
4274 aComparer.SetColorTolerance (aTolColor);
4275 aComparer.SetBorderFilterOn (isBorderFilterOn);
4276 Standard_Integer aDiffColorsNb = aComparer.Compare();
4277 theDI << aDiffColorsNb << "\n";
4278
4279 // save image of difference
4280 if (aDiffImagePath != NULL)
4281 {
4282 aComparer.SaveDiffImage (aDiffImagePath);
4283 }
4284
4285 return 0;
4286}
4287
4754e164 4288//=======================================================================
4289//function : VSelect
4290//purpose : Emulates different types of selection by mouse:
4291// 1) single click selection
4292// 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
4293// 3) selection with polygon having corners at
dc3fe572 4294// pixel positions (x1,y1),...,(xn,yn)
4754e164 4295// 4) any of these selections with shift button pressed
4296//=======================================================================
4297static Standard_Integer VSelect (Draw_Interpretor& di,
4298 Standard_Integer argc,
4299 const char ** argv)
4300{
dc3fe572 4301 if(argc < 3)
4754e164 4302 {
4303 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
4304 return 1;
4305 }
4306
4307 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
dc3fe572 4308 if(myAIScontext.IsNull())
4754e164 4309 {
4310 di << "use 'vinit' command before " << argv[0] << "\n";
4311 return 1;
4312 }
4313 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
4314 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
4315 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
4316 if(argc <= 4)
4317 {
4318 if(isShiftSelection)
4319 aCurrentEventManager->ShiftSelect();
4320 else
4321 aCurrentEventManager->Select();
4322 }
4323 else if(argc <= 6)
4324 {
4325 if(isShiftSelection)
4326 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4327 else
4328 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4329 }
4330 else
4331 {
4332 Standard_Integer anUpper = 0;
4333
4334 if(isShiftSelection)
4335 anUpper = (argc-1)/2;
4336 else
4337 anUpper = argc/2;
4338 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
4339
4340 for(Standard_Integer i=1;i<=anUpper;++i)
4341 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
4342
4343 if(isShiftSelection)
4344 aCurrentEventManager->ShiftSelect(aPolyline);
4345 else
4346 aCurrentEventManager->Select(aPolyline);
4347 }
4348 return 0;
4349}
4350
4351//=======================================================================
4352//function : VMoveTo
dc3fe572 4353//purpose : Emulates cursor movement to defined pixel position
4754e164 4354//=======================================================================
4355static Standard_Integer VMoveTo (Draw_Interpretor& di,
4356 Standard_Integer argc,
4357 const char ** argv)
4358{
dc3fe572 4359 if(argc != 3)
4754e164 4360 {
4361 di << "Usage : " << argv[0] << " x y" << "\n";
4362 return 1;
4363 }
4364
4365 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
dc3fe572 4366 if(aContext.IsNull())
4754e164 4367 {
4368 di << "use 'vinit' command before " << argv[0] << "\n";
4369 return 1;
4370 }
4371 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
4372 return 0;
4373}
4374
197ac94e 4375//=================================================================================================
4754e164 4376//function : VViewParams
dc3fe572 4377//purpose : Gets or sets AIS View characteristics
197ac94e 4378//=================================================================================================
4379static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4754e164 4380{
197ac94e 4381 Handle(V3d_View) anAISView = ViewerTest::CurrentView();
4382 if (anAISView.IsNull())
4754e164 4383 {
197ac94e 4384 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
4754e164 4385 return 1;
4386 }
197ac94e 4387
4388 if (theArgsNb == 1)
4754e164 4389 {
197ac94e 4390 // print all of the available view parameters
4391 Quantity_Factor anAISViewScale = anAISView->Scale();
4392
4754e164 4393 Standard_Real anAISViewProjX = 0.0;
4394 Standard_Real anAISViewProjY = 0.0;
4395 Standard_Real anAISViewProjZ = 0.0;
197ac94e 4396 anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4397
4754e164 4398 Standard_Real anAISViewUpX = 0.0;
4399 Standard_Real anAISViewUpY = 0.0;
4400 Standard_Real anAISViewUpZ = 0.0;
197ac94e 4401 anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4402
4754e164 4403 Standard_Real anAISViewAtX = 0.0;
4404 Standard_Real anAISViewAtY = 0.0;
4405 Standard_Real anAISViewAtZ = 0.0;
197ac94e 4406 anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4407
4408 Standard_Real anAISViewEyeX = 0.0;
4409 Standard_Real anAISViewEyeY = 0.0;
4410 Standard_Real anAISViewEyeZ = 0.0;
4411 anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ);
4412
4413 theDi << "Scale of current view: " << anAISViewScale << "\n";
4414 theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
4415 theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
4416 theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
4417 theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n";
4418 return 0;
4754e164 4419 }
197ac94e 4420
4421 // -------------------------
4422 // Parse options and values
4423 // -------------------------
4424
900f7229 4425 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues;
197ac94e 4426 TCollection_AsciiString aParseKey;
4427 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
4428 {
4429 TCollection_AsciiString anArg (theArgVec [anArgIt]);
4430
4431 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
4432 {
4433 aParseKey = anArg;
4434 aParseKey.Remove (1);
4435 aParseKey.UpperCase();
900f7229 4436 aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
197ac94e 4437 continue;
4438 }
4439
3dfe95cd 4440 if (aParseKey.IsEmpty())
4441 {
4442 std::cout << theArgVec[0] << ": values should be passed with key.\n";
4443 std::cout << "Type help for more information.\n";
4444 return 1;
4445 }
4446
900f7229 4447 aMapOfKeysByValues(aParseKey)->Append (anArg);
197ac94e 4448 }
4449
4450 // ---------------------------------------------
4451 // Change or print parameters, order plays role
4452 // ---------------------------------------------
4453
4454 // Check arguments for validity
900f7229 4455 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues);
197ac94e 4456 for (; aMapIt.More(); aMapIt.Next())
4754e164 4457 {
197ac94e 4458 const TCollection_AsciiString& aKey = aMapIt.Key();
900f7229 4459 const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value();
4460
4461 if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty()))
4462 && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty()))
4463 && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty()))
4464 && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty()))
4465 && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty()))
4466 && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty()))
4467 && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2))
197ac94e 4468 {
4469 TCollection_AsciiString aLowerKey;
4470 aLowerKey = "-";
4471 aLowerKey += aKey;
4472 aLowerKey.LowerCase();
4473 std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n";
4474 std::cout << "Type help for more information.\n";
4475 return 1;
4476 }
4754e164 4477 }
197ac94e 4478
900f7229 4479 Handle(TColStd_HSequenceOfAsciiString) aValues;
197ac94e 4480
4481 // Change view parameters in proper order
4482 if (aMapOfKeysByValues.Find ("SCALE", aValues))
4483 {
900f7229 4484 if (aValues->IsEmpty())
197ac94e 4485 {
4486 theDi << "Scale: " << anAISView->Scale() << "\n";
4487 }
4488 else
4489 {
900f7229 4490 anAISView->SetScale (aValues->Value(1).RealValue());
197ac94e 4491 }
4492 }
3dfe95cd 4493 if (aMapOfKeysByValues.Find ("SIZE", aValues))
4494 {
900f7229 4495 if (aValues->IsEmpty())
3dfe95cd 4496 {
4497 Standard_Real aSizeX = 0.0;
4498 Standard_Real aSizeY = 0.0;
4499 anAISView->Size (aSizeX, aSizeY);
4500 theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n";
4501 }
4502 else
4503 {
900f7229 4504 anAISView->SetSize (aValues->Value(1).RealValue());
3dfe95cd 4505 }
4506 }
197ac94e 4507 if (aMapOfKeysByValues.Find ("EYE", aValues))
4508 {
900f7229 4509 if (aValues->IsEmpty())
197ac94e 4510 {
4511 Standard_Real anEyeX = 0.0;
4512 Standard_Real anEyeY = 0.0;
4513 Standard_Real anEyeZ = 0.0;
4514 anAISView->Eye (anEyeX, anEyeY, anEyeZ);
4515 theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n";
4516 }
4517 else
4518 {
900f7229 4519 anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
197ac94e 4520 }
4521 }
4522 if (aMapOfKeysByValues.Find ("AT", aValues))
4523 {
900f7229 4524 if (aValues->IsEmpty())
197ac94e 4525 {
4526 Standard_Real anAtX = 0.0;
4527 Standard_Real anAtY = 0.0;
4528 Standard_Real anAtZ = 0.0;
4529 anAISView->At (anAtX, anAtY, anAtZ);
4530 theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n";
4531 }
4532 else
4533 {
900f7229 4534 anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
197ac94e 4535 }
4536 }
4537 if (aMapOfKeysByValues.Find ("PROJ", aValues))
4538 {
900f7229 4539 if (aValues->IsEmpty())
197ac94e 4540 {
4541 Standard_Real aProjX = 0.0;
4542 Standard_Real aProjY = 0.0;
4543 Standard_Real aProjZ = 0.0;
4544 anAISView->Proj (aProjX, aProjY, aProjZ);
4545 theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n";
4546 }
4547 else
4548 {
900f7229 4549 anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
197ac94e 4550 }
4551 }
4552 if (aMapOfKeysByValues.Find ("UP", aValues))
4553 {
900f7229 4554 if (aValues->IsEmpty())
197ac94e 4555 {
4556 Standard_Real anUpX = 0.0;
4557 Standard_Real anUpY = 0.0;
4558 Standard_Real anUpZ = 0.0;
4559 anAISView->Up (anUpX, anUpY, anUpZ);
4560 theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n";
4561 }
4562 else
4563 {
900f7229 4564 anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
197ac94e 4565 }
4566 }
4567 if (aMapOfKeysByValues.Find ("CENTER", aValues))
4568 {
900f7229 4569 anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue());
197ac94e 4570 }
4571
4754e164 4572 return 0;
4573}
4574
4575//=======================================================================
4576//function : VChangeSelected
dc3fe572 4577//purpose : Adds the shape to selection or remove one from it
4754e164 4578//=======================================================================
4579static Standard_Integer VChangeSelected (Draw_Interpretor& di,
4580 Standard_Integer argc,
4581 const char ** argv)
4582{
4583 if(argc != 2)
4584 {
4585 di<<"Usage : " << argv[0] << " shape \n";
4586 return 1;
4587 }
4588 //get AIS_Shape:
4589 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4590 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4591 TCollection_AsciiString aName(argv[1]);
4592 Handle(AIS_InteractiveObject) anAISObject;
4593
4594 if(!aMap.IsBound2(aName))
4595 {
4596 di<<"Use 'vdisplay' before";
4597 return 1;
4598 }
4599 else
4600 {
4601 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
4602 if(anAISObject.IsNull()){
4603 di<<"No interactive object \n";
4604 return 1;
4605 }
4606
4607 if(aContext->HasOpenedContext())
4608 {
4609 aContext->AddOrRemoveSelected(anAISObject);
4610 }
dc3fe572 4611 else
4754e164 4612 {
4613 aContext->AddOrRemoveCurrentObject(anAISObject);
4614 }
4615 }
4616 return 0;
4617}
4618
4619//=======================================================================
4620//function : VZClipping
dc3fe572 4621//purpose : Gets or sets ZClipping mode, width and depth
4754e164 4622//=======================================================================
4623static Standard_Integer VZClipping (Draw_Interpretor& di,
4624 Standard_Integer argc,
4625 const char ** argv)
4626{
dc3fe572 4627 if(argc>4)
4754e164 4628 {
4629 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4630 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4631 return -1;
4632 }
4633 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
dc3fe572 4634 if(aContext.IsNull())
4754e164 4635 {
4636 di << "use 'vinit' command before " << argv[0] << "\n";
4637 return 1;
4638 }
4639 Handle(V3d_View) aView = ViewerTest::CurrentView();
1d47d8d0 4640 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
4754e164 4641 if(argc==1)
4642 {
4643 TCollection_AsciiString aZClippingModeString;
4644 Quantity_Length aDepth, aWidth;
4645 aZClippingMode = aView->ZClipping(aDepth, aWidth);
4646 switch (aZClippingMode)
4647 {
4648 case V3d_OFF:
4649 aZClippingModeString.Copy("OFF");
4650 break;
4651 case V3d_BACK:
4652 aZClippingModeString.Copy("BACK");
4653 break;
4654 case V3d_FRONT:
4655 aZClippingModeString.Copy("FRONT");
4656 break;
4657 case V3d_SLICE:
4658 aZClippingModeString.Copy("SLICE");
4659 break;
4660 default:
4661 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
4662 break;
4663 }
4664 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
4665 << "ZClipping depth = " << aDepth << "\n"
4666 << "ZClipping width = " << aWidth << "\n";
4667 }
4668 else
4669 {
4670 if(argc !=3)
4671 {
4672 Standard_Integer aStatus = 0;
4673 if ( strcmp (argv [1], "OFF") == 0 ) {
4674 aStatus = 1;
4675 aZClippingMode = V3d_OFF;
4676 }
4677 if ( strcmp (argv [1], "BACK") == 0 ) {
4678 aStatus = 1;
4679 aZClippingMode = V3d_BACK;
4680 }
4681 if ( strcmp (argv [1], "FRONT") == 0 ) {
4682 aStatus = 1;
4683 aZClippingMode = V3d_FRONT;
4684 }
4685 if ( strcmp (argv [1], "SLICE") == 0 ) {
4686 aStatus = 1;
4687 aZClippingMode = V3d_SLICE;
4688 }
4689 if (aStatus != 1)
4690 {
4691 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4692 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4693 return 1;
dc3fe572 4694 }
4754e164 4695 aView->SetZClippingType(aZClippingMode);
4696 }
4697 if(argc >2)
4698 {
4699 Quantity_Length aDepth = 0., aWidth = 1.;
4700 if(argc == 3)
4701 {
4702 aDepth = atof(argv[1]);
4703 aWidth = atof(argv[2]);
4704 }
4705 else if(argc == 4)
4706 {
4707 aDepth = atof(argv[2]);
4708 aWidth = atof(argv[3]);
4709 }
dc3fe572 4710
4754e164 4711 if(aDepth<0. || aDepth>1.)
4712 {
4713 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4714 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4715 return 1;
4716 }
4717 if(aWidth<0. || aWidth>1.)
4718 {
4719 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4720 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4721 return 1;
4722 }
4723
4724 aView->SetZClippingDepth(aDepth);
4725 aView->SetZClippingWidth(aWidth);
4726 }
4727 aView->Redraw();
4728 }
4729 return 0;
4730}
4731
4732//=======================================================================
4733//function : VNbSelected
dc3fe572 4734//purpose : Returns number of selected objects
4754e164 4735//=======================================================================
4736static Standard_Integer VNbSelected (Draw_Interpretor& di,
4737 Standard_Integer argc,
4738 const char ** argv)
4739{
4740 if(argc != 1)
4741 {
4742 di << "Usage : " << argv[0] << "\n";
4743 return 1;
4744 }
4745 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4746 if(aContext.IsNull())
4747 {
4748 di << "use 'vinit' command before " << argv[0] << "\n";
4749 return 1;
4750 }
4751 di << aContext->NbSelected() << "\n";
4752 return 0;
4753}
4754
4755//=======================================================================
4756//function : VAntialiasing
dc3fe572 4757//purpose : Switches altialiasing on or off
4754e164 4758//=======================================================================
4759static Standard_Integer VAntialiasing (Draw_Interpretor& di,
4760 Standard_Integer argc,
4761 const char ** argv)
4762{
4763 if(argc > 2)
4764 {
4765 di << "Usage : " << argv[0] << " [1|0]" << "\n";
4766 return 1;
4767 }
4768
4769 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4770 if(aContext.IsNull())
4771 {
4772 di << "use 'vinit' command before " << argv[0] << "\n";
4773 return 1;
4774 }
4775
4776 Handle(V3d_View) aView = ViewerTest::CurrentView();
4777
4778 if((argc == 2) && (atof(argv[1]) == 0))
4779 aView->SetAntialiasingOff();
4780 else
4781 aView->SetAntialiasingOn();
4782 aView->Update();
4783 return 0;
4784}
4785
4786//=======================================================================
4787//function : VPurgeDisplay
dc3fe572 4788//purpose : Switches altialiasing on or off
4754e164 4789//=======================================================================
4790static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
4791 Standard_Integer argc,
4792 const char ** argv)
4793{
eb4320f2 4794 if (argc > 1)
4754e164 4795 {
eb4320f2 4796 di << "Usage : " << argv[0] << "\n";
4754e164 4797 return 1;
4798 }
4754e164 4799 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4800 if (aContext.IsNull())
4801 {
4802 di << "use 'vinit' command before " << argv[0] << "\n";
4803 return 1;
4804 }
4805 aContext->CloseAllContexts(Standard_False);
eb4320f2 4806 di << aContext->PurgeDisplay() << "\n";
4754e164 4807 return 0;
4808}
4809
4810//=======================================================================
4811//function : VSetViewSize
4812//purpose :
4813//=======================================================================
4814static Standard_Integer VSetViewSize (Draw_Interpretor& di,
4815 Standard_Integer argc,
4816 const char ** argv)
4817{
4818 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4819 if(aContext.IsNull())
4820 {
4821 di << "use 'vinit' command before " << argv[0] << "\n";
4822 return 1;
4823 }
4824 if(argc != 2)
4825 {
4826 di<<"Usage : " << argv[0] << " Size\n";
4827 return 1;
4828 }
4829 Standard_Real aSize = atof(argv[1]);
4830 if (aSize <= 0.)
4831 {
4832 di<<"Bad Size value : " << aSize << "\n";
4833 return 1;
4834 }
4835
4836 Handle(V3d_View) aView = ViewerTest::CurrentView();
4837 aView->SetSize(aSize);
4838 return 0;
4839}
4840
4841//=======================================================================
4842//function : VMoveView
4843//purpose :
4844//=======================================================================
4845static Standard_Integer VMoveView (Draw_Interpretor& di,
4846 Standard_Integer argc,
4847 const char ** argv)
4848{
4849 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4850 if(aContext.IsNull())
4851 {
4852 di << "use 'vinit' command before " << argv[0] << "\n";
4853 return 1;
4854 }
4855 if(argc < 4 || argc > 5)
4856 {
4857 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4858 return 1;
4859 }
4860 Standard_Real Dx = atof(argv[1]);
4861 Standard_Real Dy = atof(argv[2]);
4862 Standard_Real Dz = atof(argv[3]);
4863 Standard_Boolean aStart = Standard_True;
4864 if (argc == 5)
4865 {
4866 aStart = (atoi(argv[4]) > 0);
4867 }
4868
4869 Handle(V3d_View) aView = ViewerTest::CurrentView();
4870 aView->Move(Dx,Dy,Dz,aStart);
4871 return 0;
4872}
4873
4874//=======================================================================
4875//function : VTranslateView
4876//purpose :
4877//=======================================================================
4878static Standard_Integer VTranslateView (Draw_Interpretor& di,
4879 Standard_Integer argc,
4880 const char ** argv)
4881{
4882 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4883 if(aContext.IsNull())
4884 {
4885 di << "use 'vinit' command before " << argv[0] << "\n";
4886 return 1;
4887 }
4888 if(argc < 4 || argc > 5)
4889 {
4890 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4891 return 1;
4892 }
4893 Standard_Real Dx = atof(argv[1]);
4894 Standard_Real Dy = atof(argv[2]);
4895 Standard_Real Dz = atof(argv[3]);
4896 Standard_Boolean aStart = Standard_True;
dc3fe572 4897 if (argc == 5)
4754e164 4898 {
4899 aStart = (atoi(argv[4]) > 0);
4900 }
4901
4902 Handle(V3d_View) aView = ViewerTest::CurrentView();
4903 aView->Translate(Dx,Dy,Dz,aStart);
4904 return 0;
4905}
4906
4907//=======================================================================
4908//function : VTurnView
4909//purpose :
4910//=======================================================================
4911static Standard_Integer VTurnView (Draw_Interpretor& di,
4912 Standard_Integer argc,
4913 const char ** argv)
4914{
4915 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4916 if(aContext.IsNull()) {
4917 di << "use 'vinit' command before " << argv[0] << "\n";
4918 return 1;
4919 }
4920 if(argc < 4 || argc > 5){
4921 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
4922 return 1;
4923 }
4924 Standard_Real Ax = atof(argv[1]);
4925 Standard_Real Ay = atof(argv[2]);
4926 Standard_Real Az = atof(argv[3]);
4927 Standard_Boolean aStart = Standard_True;
dc3fe572 4928 if (argc == 5)
4754e164 4929 {
4930 aStart = (atoi(argv[4]) > 0);
4931 }
4932
4933 Handle(V3d_View) aView = ViewerTest::CurrentView();
4934 aView->Turn(Ax,Ay,Az,aStart);
4935 return 0;
4936}
4937
269294d6 4938//==============================================================================
4939//function : VTextureEnv
4940//purpose : ENables or disables environment mapping
4941//==============================================================================
4942class OCC_TextureEnv : public Graphic3d_TextureEnv
4943{
4944public:
4945 OCC_TextureEnv(const Standard_CString FileName);
4946 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
4947 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
4948 const Standard_Boolean theModulateFlag,
4949 const Graphic3d_TypeOfTextureFilter theFilter,
4950 const Standard_ShortReal theXScale,
4951 const Standard_ShortReal theYScale,
4952 const Standard_ShortReal theXShift,
4953 const Standard_ShortReal theYShift,
4954 const Standard_ShortReal theAngle);
4955 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
4956};
4957DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4958IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4959IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
4960
4961OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
4962 : Graphic3d_TextureEnv(theFileName)
4963{
4964}
4965
4966OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
4967 : Graphic3d_TextureEnv(theTexId)
4968{
4969}
4970
4971void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
4972 const Standard_Boolean theModulateFlag,
4973 const Graphic3d_TypeOfTextureFilter theFilter,
4974 const Standard_ShortReal theXScale,
4975 const Standard_ShortReal theYScale,
4976 const Standard_ShortReal theXShift,
4977 const Standard_ShortReal theYShift,
4978 const Standard_ShortReal theAngle)
4979{
4980 myParams->SetRepeat (theRepeatFlag);
4981 myParams->SetModulate (theModulateFlag);
4982 myParams->SetFilter (theFilter);
4983 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
4984 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
4985 myParams->SetRotation (theAngle);
4986}
4987
35e08fe8 4988static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
269294d6 4989{
4990 // get the active view
4991 Handle(V3d_View) aView = ViewerTest::CurrentView();
4992 if (aView.IsNull())
4993 {
4994 std::cerr << "No active view. Please call vinit.\n";
4995 return 1;
4996 }
4997
4998 // Checking the input arguments
4999 Standard_Boolean anEnableFlag = Standard_False;
5000 Standard_Boolean isOk = theArgNb >= 2;
5001 if (isOk)
5002 {
5003 TCollection_AsciiString anEnableOpt(theArgVec[1]);
5004 anEnableFlag = anEnableOpt.IsEqual("on");
5005 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
5006 }
5007 if (anEnableFlag)
5008 {
5009 isOk = (theArgNb == 3 || theArgNb == 11);
5010 if (isOk)
5011 {
5012 TCollection_AsciiString aTextureOpt(theArgVec[2]);
5013 isOk = (!aTextureOpt.IsIntegerValue() ||
5014 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
5015
5016 if (isOk && theArgNb == 11)
5017 {
5018 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
5019 aModulateOpt(theArgVec[4]),
5020 aFilterOpt (theArgVec[5]),
5021 aSScaleOpt (theArgVec[6]),
5022 aTScaleOpt (theArgVec[7]),
5023 aSTransOpt (theArgVec[8]),
5024 aTTransOpt (theArgVec[9]),
5025 anAngleOpt (theArgVec[10]);
5026 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
5027 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
5028 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
5029 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
5030 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
5031 anAngleOpt.IsRealValue());
5032 }
5033 }
5034 }
5035
5036 if (!isOk)
5037 {
5038 std::cerr << "Usage :" << std::endl;
5039 std::cerr << theArgVec[0] << " off" << std::endl;
5040 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;
5041 return 1;
5042 }
5043
5044 if (anEnableFlag)
5045 {
5046 TCollection_AsciiString aTextureOpt(theArgVec[2]);
5047 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
5048 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
5049 new OCC_TextureEnv(theArgVec[2]);
5050
5051 if (theArgNb == 11)
5052 {
5053 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
5054 aTexEnv->SetTextureParameters(
5055 aRepeatOpt. IsEqual("repeat"),
5056 aModulateOpt.IsEqual("modulate"),
5057 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
5058 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
5059 Graphic3d_TOTF_TRILINEAR,
5060 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
5061 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
5062 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
5063 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
5064 (Standard_ShortReal)Draw::Atof(theArgVec[10])
5065 );
5066 }
5067 aView->SetTextureEnv(aTexEnv);
5068 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
5069 }
5070 else // Disabling environment mapping
5071 {
5072 aView->SetSurfaceDetail(V3d_TEX_NONE);
5073 Handle(Graphic3d_TextureEnv) aTexture;
5074 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
5075 }
5076
5077 aView->Redraw();
5078 return 0;
5079}
5080
4269bd1b 5081//===============================================================================================
5082//function : VClipPlane
5083//purpose :
5084//===============================================================================================
5085static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5086{
5087 // use short-cut for created clip planes map of created (or "registered by name") clip planes
5088 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
5089 static MapOfPlanes aRegPlanes;
5090
5091 if (theArgsNb < 2)
5092 {
5093 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
5094 return 1;
5095 }
5096
5097 TCollection_AsciiString aCommand (theArgVec[1]);
5098
5099 // print maximum number of planes for current viewer
5100 if (aCommand == "maxplanes")
5101 {
5102 if (theArgsNb < 3)
5103 {
5104 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
5105 return 1;
5106 }
5107
5108 TCollection_AsciiString aViewName (theArgVec[2]);
5109
5110 if (!ViewerTest_myViews.IsBound1 (aViewName))
5111 {
5112 theDi << theArgVec[0] << ": view is not found.\n";
5113 return 1;
5114 }
5115
5116 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5117
5118 theDi << theArgVec[0] << ": "
5119 << aView->Viewer()->Driver()->InquirePlaneLimit()
5120 << " plane slots provided by driver."
5121 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
5122
5123 return 0;
5124 }
5125
5126 // create / delete plane instance
5127 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
5128 {
5129 if (theArgsNb < 3)
5130 {
5131 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
5132 return 1;
5133 }
5134
5135 Standard_Boolean toCreate = (aCommand == "create");
5136 Standard_Boolean toClone = (aCommand == "clone");
5137 TCollection_AsciiString aPlane (theArgVec[2]);
5138
5139 if (toCreate)
5140 {
5141 if (aRegPlanes.IsBound (aPlane))
5142 {
5143 theDi << theArgVec[0] << ": plane name is in use.\n";
5144 return 1;
5145 }
5146
5147 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
5148 }
5149 else if (toClone) // toClone
5150 {
5151 if (!aRegPlanes.IsBound (aPlane))
5152 {
5153 theDi << theArgVec[0] << ": no such plane.\n";
5154 return 1;
5155 }
5156
5157 if (theArgsNb < 4)
5158 {
5159 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
5160 return 1;
5161 }
5162
5163 TCollection_AsciiString aClone (theArgVec[3]);
5164 if (aRegPlanes.IsBound (aClone))
5165 {
5166 theDi << theArgVec[0] << ": plane name is in use.\n";
5167 return 1;
5168 }
5169
5170 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5171
5172 aRegPlanes.Bind (aClone, aClipPlane->Clone());
5173 }
5174 else// toDelete
5175 {
5176 if (!aRegPlanes.IsBound (aPlane))
5177 {
5178 theDi << theArgVec[0] << ": no such plane.\n";
5179 return 1;
5180 }
5181
5182 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
5183 aRegPlanes.UnBind (aPlane);
5184
5185 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
5186 for (; anIObjIt.More(); anIObjIt.Next())
5187 {
5188 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
5189 aPrs->RemoveClipPlane(aClipPlane);
5190 }
5191
5192 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
5193 for (; aViewIt.More(); aViewIt.Next())
5194 {
5195 const Handle(V3d_View)& aView = aViewIt.Key2();
5196 aView->RemoveClipPlane(aClipPlane);
5197 }
5198
5199 ViewerTest::RedrawAllViews();
5200 }
5201
5202 return 0;
5203 }
5204
5205 // set / unset plane command
5206 if (aCommand == "set" || aCommand == "unset")
5207 {
5208 if (theArgsNb < 4)
5209 {
5210 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5211 return 1;
5212 }
5213
5214 Standard_Boolean toSet = (aCommand == "set");
5215 TCollection_AsciiString aPlane (theArgVec [2]);
5216 if (!aRegPlanes.IsBound (aPlane))
5217 {
5218 theDi << theArgVec[0] << ": no such plane.\n";
5219 return 1;
5220 }
5221
5222 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5223
5224 TCollection_AsciiString aTarget (theArgVec [3]);
5225 if (aTarget != "object" && aTarget != "view")
5226 {
5227 theDi << theArgVec[0] << ": invalid target.\n";
5228 return 1;
5229 }
5230
5231 if (aTarget == "object" || aTarget == "view")
5232 {
5233 if (theArgsNb < 5)
5234 {
5235 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5236 return 1;
5237 }
5238
5239 Standard_Boolean isObject = (aTarget == "object");
5240
5241 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
5242 {
5243 TCollection_AsciiString anEntityName (theArgVec[anIt]);
5244 if (isObject) // to object
5245 {
5246 if (!GetMapOfAIS().IsBound2 (anEntityName))
5247 {
5248 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
5249 continue;
5250 }
5251
5252 Handle(AIS_InteractiveObject) aIObj =
5253 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
5254
5255 if (toSet)
5256 aIObj->AddClipPlane (aClipPlane);
5257 else
5258 aIObj->RemoveClipPlane (aClipPlane);
5259 }
5260 else // to view
5261 {
5262 if (!ViewerTest_myViews.IsBound1 (anEntityName))
5263 {
5264 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
5265 continue;
5266 }
5267
5268 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
5269 if (toSet)
5270 aView->AddClipPlane (aClipPlane);
5271 else
5272 aView->RemoveClipPlane (aClipPlane);
5273 }
5274 }
5275
5276 ViewerTest::RedrawAllViews();
5277 }
5278
5279 return 0;
5280 }
5281
5282 // change plane command
5283 if (aCommand == "change")
5284 {
5285 if (theArgsNb < 4)
5286 {
5287 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5288 return 1;
5289 }
5290
5291 TCollection_AsciiString aPlane (theArgVec [2]);
5292 if (!aRegPlanes.IsBound (aPlane))
5293 {
5294 theDi << theArgVec[0] << ": no such plane.\n";
5295 return 1;
5296 }
5297
5298 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5299
5300 TCollection_AsciiString aChangeArg (theArgVec [3]);
5301 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
5302 {
5303 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5304 return 1;
5305 }
5306
5307 if (aChangeArg == "on" || aChangeArg == "off") // on / off
5308 {
5309 aClipPlane->SetOn (aChangeArg == "on");
5310 }
5311 else if (aChangeArg == "equation") // change equation
5312 {
5313 if (theArgsNb < 8)
5314 {
5315 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5316 return 1;
5317 }
5318
5319 Standard_Real aCoeffA = atof (theArgVec [4]);
5320 Standard_Real aCoeffB = atof (theArgVec [5]);
5321 Standard_Real aCoeffC = atof (theArgVec [6]);
5322 Standard_Real aCoeffD = atof (theArgVec [7]);
5323 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
5324 }
5325 else if (aChangeArg == "capping") // change capping aspects
5326 {
5327 if (theArgsNb < 5)
5328 {
5329 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5330 return 1;
5331 }
5332
5333 TCollection_AsciiString aCappingArg (theArgVec [4]);
5334 if (aCappingArg != "on" && aCappingArg != "off" &&
5335 aCappingArg != "color" && aCappingArg != "texname" &&
5336 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
5337 aCappingArg != "texrotate" && aCappingArg != "hatch")
5338 {
5339 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5340 return 1;
5341 }
5342
5343 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
5344 {
5345 aClipPlane->SetCapping (aCappingArg == "on");
5346 }
5347 else if (aCappingArg == "color") // color aspect for capping
5348 {
5349 if (theArgsNb < 8)
5350 {
5351 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5352 return 1;
5353 }
5354
5355 Standard_Real aRed = atof (theArgVec [5]);
5356 Standard_Real aGrn = atof (theArgVec [6]);
5357 Standard_Real aBlu = atof (theArgVec [7]);
5358
5359 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
5360 aMat.SetColor (Quantity_Color (aRed, aGrn, aBlu, Quantity_TOC_RGB));
5361 aClipPlane->SetCappingMaterial (aMat);
5362 }
5363 else if (aCappingArg == "texname") // texture name
5364 {
5365 if (theArgsNb < 6)
5366 {
5367 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5368 return 1;
5369 }
5370
5371 TCollection_AsciiString aTextureName (theArgVec [5]);
5372
5373 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
5374 if (!aTexture->IsDone ())
5375 {
5376 aClipPlane->SetCappingTexture (NULL);
5377 }
5378 else
5379 {
5380 aTexture->EnableModulate();
5381 aTexture->EnableRepeat();
5382 aClipPlane->SetCappingTexture (aTexture);
5383 }
5384 }
5385 else if (aCappingArg == "texscale") // texture scale
5386 {
5387 if (aClipPlane->CappingTexture().IsNull())
5388 {
5389 theDi << theArgVec[0] << ": no texture is set.\n";
5390 return 1;
5391 }
5392
5393 if (theArgsNb < 7)
5394 {
5395 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5396 return 1;
5397 }
5398
5399 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
5400 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
5401
5402 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
5403 }
5404 else if (aCappingArg == "texorigin") // texture origin
5405 {
5406 if (aClipPlane->CappingTexture().IsNull())
5407 {
5408 theDi << theArgVec[0] << ": no texture is set.\n";
5409 return 1;
5410 }
5411
5412 if (theArgsNb < 7)
5413 {
5414 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5415 return 1;
5416 }
5417
5418 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
5419 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
5420
5421 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
5422 }
5423 else if (aCappingArg == "texrotate") // texture rotation
5424 {
5425 if (aClipPlane->CappingTexture().IsNull())
5426 {
5427 theDi << theArgVec[0] << ": no texture is set.\n";
5428 return 1;
5429 }
5430
5431 if (theArgsNb < 6)
5432 {
5433 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5434 return 1;
5435 }
5436
5437 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
5438
5439 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
5440 }
5441 else if (aCappingArg == "hatch") // hatch style
5442 {
5443 if (theArgsNb < 6)
5444 {
5445 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5446 return 1;
5447 }
5448
5449 TCollection_AsciiString aHatchStr (theArgVec [5]);
5450 if (aHatchStr == "on")
5451 {
5452 aClipPlane->SetCappingHatchOn();
5453 }
5454 else if (aHatchStr == "off")
5455 {
5456 aClipPlane->SetCappingHatchOff();
5457 }
5458 else
5459 {
5460 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
5461 }
5462 }
5463 }
5464
5465 ViewerTest::RedrawAllViews();
5466
5467 return 0;
5468 }
5469
5470 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
5471 return 1;
5472}
5473
5474//===============================================================================================
5475//function : VSetTextureMode
5476//purpose :
5477//===============================================================================================
5478static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5479{
5480 if (theArgsNb < 3)
5481 {
5482 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
5483 return 1;
5484 }
5485
5486 TCollection_AsciiString aViewName (theArgVec[1]);
5487 if (!ViewerTest_myViews.IsBound1 (aViewName))
5488 {
5489 theDi << theArgVec[0] << ": view is not found.\n";
5490 return 1;
5491 }
5492
5493 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5494 switch (atoi (theArgVec[2]))
5495 {
5496 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
5497 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
5498 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
5499 default:
5500 theDi << theArgVec[0] << ": invalid mode.\n";
5501 return 1;
5502 }
5503
5504 aView->Redraw();
5505 return 0;
5506}
5507
b5ac8292 5508//===============================================================================================
5509//function : VZRange
5510//purpose :
5511//===============================================================================================
5512static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5513{
197ac94e 5514 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
5515
5516 if (aCurrentView.IsNull())
b5ac8292 5517 {
197ac94e 5518 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
b5ac8292 5519 return 1;
5520 }
5521
197ac94e 5522 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
b5ac8292 5523
5524 if (theArgsNb < 2)
5525 {
5526 theDi << "ZNear: " << aCamera->ZNear() << "\n";
5527 theDi << "ZFar: " << aCamera->ZFar() << "\n";
5528 return 0;
5529 }
5530
5531 if (theArgsNb == 3)
5532 {
5533 Standard_Real aNewZNear = atof (theArgVec[1]);
5534 Standard_Real aNewZFar = atof (theArgVec[2]);
197ac94e 5535
5536 if (aNewZNear >= aNewZFar)
5537 {
5538 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
5539 return 1;
5540 }
5541
5542 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
5543 {
5544 std::cout << theArgVec[0] << ": invalid arguments: ";
5545 std::cout << "znear, zfar should be positive for perspective camera.\n";
5546 return 1;
5547 }
5548
5549 aCamera->SetZRange (aNewZNear, aNewZFar);
b5ac8292 5550 }
5551 else
5552 {
197ac94e 5553 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
b5ac8292 5554 return 1;
5555 }
5556
197ac94e 5557 aCurrentView->Redraw();
5558
b5ac8292 5559 return 0;
5560}
5561
5562//===============================================================================================
5563//function : VAutoZFit
5564//purpose :
5565//===============================================================================================
5566static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5567{
197ac94e 5568 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
5569
5570 if (aCurrentView.IsNull())
b5ac8292 5571 {
197ac94e 5572 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
b5ac8292 5573 return 1;
5574 }
5575
197ac94e 5576 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
5577
5578 if (theArgsNb > 3)
b5ac8292 5579 {
197ac94e 5580 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
5581 return 1;
b5ac8292 5582 }
5583
197ac94e 5584 if (theArgsNb < 2)
b5ac8292 5585 {
197ac94e 5586 theDi << "Auto z-fit mode: " << "\n"
5587 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
5588 << "Scale: " << aScale << "\n";
5589 return 0;
b5ac8292 5590 }
197ac94e 5591
5592 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
5593
5594 if (theArgsNb >= 3)
b5ac8292 5595 {
197ac94e 5596 aScale = Draw::Atoi (theArgVec[2]);
b5ac8292 5597 }
5598
197ac94e 5599 aCurrentView->SetAutoZFitMode (isOn, aScale);
5600 aCurrentView->AutoZFit();
5601 aCurrentView->Redraw();
5602
b5ac8292 5603 return 0;
5604}
5605
5606//===============================================================================================
5607//function : VChangeCamera
5608//purpose :
5609//===============================================================================================
5610static int VChangeCamera (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5611{
5612 if (ViewerTest::CurrentView().IsNull())
5613 {
5614 theDi << theArgVec[0] << ": Call vinit before this command, please.\n";
5615 return 1;
5616 }
5617
5618 const char anErrorMessage[] = ": wrong command arguments. Type help for more information.\n";
5619 if (theArgsNb < 3)
5620 {
5621 theDi << theArgVec[0] << anErrorMessage;
5622 return 1;
5623 }
5624
5625 Handle(Graphic3d_Camera) aCamera = ViewerTest::CurrentView()->Camera();
5626
5627 TCollection_AsciiString aCommand (theArgVec[1]);
5628 TCollection_AsciiString aValue (theArgVec[2]);
5629
5630 aCommand.LowerCase();
5631 aValue.LowerCase();
5632
5633 if (aCommand == "proj")
5634 {
5635 if (aValue == "ortho")
5636 {
5637 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
5638 }
5639 else if (aValue == "persp")
5640 {
5641 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
5642 }
5643 else if (aValue == "left")
5644 {
5645 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
5646 }
5647 else if (aValue == "right")
5648 {
5649 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
5650 }
5651 else if (aValue == "stereo")
5652 {
5653 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
5654 }
5655 else
5656 {
5657 theDi << theArgVec[0] << anErrorMessage;
5658 return 1;
5659 }
b5ac8292 5660 }
5661 else if (aCommand == "dist")
5662 {
5663 aCamera->SetDistance (aValue.RealValue());
b5ac8292 5664 }
5665 else if (aCommand == "iod")
5666 {
5667 aCamera->SetIOD (aCamera->GetIODType(), aValue.RealValue());
5668 }
5669 else if (aCommand == "zfocus")
5670 {
5671 aCamera->SetZFocus (aCamera->ZFocusType(), aValue.RealValue());
5672 }
5673 else if (aCommand == "fov")
5674 {
5675 aCamera->SetFOVy (aValue.RealValue());
5676 }
5677 else if (aCommand == "zfocustype")
5678 {
5679 if (aValue == "absolute")
5680 {
5681 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
5682 }
5683 else if (aValue == "relative")
5684 {
5685 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
5686 }
5687 else
5688 {
5689 theDi << theArgVec[0] << anErrorMessage;
5690 return 1;
5691 }
5692 }
5693 else if (aCommand == "iodtype")
5694 {
5695 if (aValue == "absolute")
5696 {
5697 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
5698 }
5699 else if (aValue == "relative")
5700 {
5701 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
5702 }
5703 else
5704 {
5705 theDi << theArgVec[0] << anErrorMessage;
5706 return 1;
5707 }
5708 }
5709 else
5710 {
5711 theDi << theArgVec[0] << anErrorMessage;
5712 return 1;
5713 }
5714
197ac94e 5715 ViewerTest::CurrentView()->AutoZFit();
b5ac8292 5716 ViewerTest::CurrentView()->Redraw();
5717
5718 return 0;
5719}
5720
5721//==============================================================================
5722//function : VStereo
5723//purpose :
5724//==============================================================================
5725
5726static int VStereo (Draw_Interpretor& theDI,
5727 Standard_Integer theArgNb,
5728 const char** theArgVec)
5729{
5730 if (theArgNb < 2)
5731 {
5732 Handle(V3d_View) aView = ViewerTest::CurrentView();
5733 if (aView.IsNull())
5734 {
5735 std::cerr << "No active view. Please call vinit.\n";
5736 return 0;
5737 }
5738
5739 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
5740 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
5741 return 0;
5742 }
5743
5744 ViewerTest_myDefaultCaps.contextStereo = Draw::Atoi (theArgVec[1]) != 0;
5745 return 0;
5746}
5747
392ac980 5748//===============================================================================================
5749//function : VDefaults
5750//purpose :
5751//===============================================================================================
5752static int VDefaults (Draw_Interpretor& theDi,
5753 Standard_Integer theArgsNb,
5754 const char** theArgVec)
5755{
5756 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5757 if (aCtx.IsNull())
5758 {
5759 std::cerr << "No active viewer!\n";
5760 return 1;
5761 }
5762
5763 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
5764 if (theArgsNb < 2)
5765 {
5766 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
5767 {
5768 theDi << "DeflType: relative\n"
5769 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
5770 }
5771 else
5772 {
5773 theDi << "DeflType: absolute\n"
5774 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
5775 }
5776 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
5777 return 0;
5778 }
5779
5780 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5781 {
5782 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5783 TCollection_AsciiString aKey, aValue;
1d7ca641 5784 if (!ViewerTest::SplitParameter (anArg, aKey, aValue)
392ac980 5785 || aValue.IsEmpty())
5786 {
5787 std::cerr << "Error, wrong syntax at: '" << anArg.ToCString() << "'!\n";
5788 return 1;
5789 }
5790
5791 aKey.UpperCase();
5792 if (aKey == "ABSDEFL"
5793 || aKey == "ABSOLUTEDEFLECTION"
5794 || aKey == "DEFL"
5795 || aKey == "DEFLECTION")
5796 {
5797 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
5798 aDefParams->SetMaximalChordialDeviation (aValue.RealValue());
5799 }
5800 else if (aKey == "RELDEFL"
5801 || aKey == "RELATIVEDEFLECTION"
5802 || aKey == "DEVCOEFF"
5803 || aKey == "DEVIATIONCOEFF"
5804 || aKey == "DEVIATIONCOEFFICIENT")
5805 {
5806 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
5807 aDefParams->SetDeviationCoefficient (aValue.RealValue());
5808 }
5809 else if (aKey == "ANGDEFL"
5810 || aKey == "ANGULARDEFL"
5811 || aKey == "ANGULARDEFLECTION")
5812 {
5813 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
5814 aDefParams->SetHLRAngle (M_PI * aValue.RealValue() / 180.0);
5815 }
5816 else
5817 {
5818 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
5819 }
5820 }
5821
5822 return 0;
5823}
5824
12381341 5825//! Auxiliary method
5826inline void addLight (const Handle(V3d_Light)& theLightNew,
5827 const Standard_Boolean theIsGlobal)
5828{
5829 if (theLightNew.IsNull())
5830 {
5831 return;
5832 }
5833
5834 if (theIsGlobal)
5835 {
5836 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
5837 }
5838 else
5839 {
5840 ViewerTest::CurrentView()->SetLightOn (theLightNew);
5841 }
5842}
5843
5844//! Auxiliary method
5845inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
5846{
5847 TCollection_AsciiString anArgNextCase (theArgNext);
5848 anArgNextCase.UpperCase();
5849 if (anArgNextCase.Length() > 5
5850 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
5851 {
5852 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
5853 }
5854 else
5855 {
5856 return theArgNext.IntegerValue();
5857 }
5858}
5859
5860//===============================================================================================
5861//function : VLight
5862//purpose :
5863//===============================================================================================
5864static int VLight (Draw_Interpretor& theDi,
5865 Standard_Integer theArgsNb,
5866 const char** theArgVec)
5867{
5868 Handle(V3d_View) aView = ViewerTest::CurrentView();
5869 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5870 if (aView.IsNull()
5871 || aViewer.IsNull())
5872 {
5873 std::cerr << "No active viewer!\n";
5874 return 1;
5875 }
5876
5877 Standard_Real anXYZ[3];
5878 Quantity_Coefficient anAtten[2];
5879 if (theArgsNb < 2)
5880 {
5881 // print lights info
5882 Standard_Integer aLightId = 0;
5883 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
5884 {
5885 Handle(V3d_Light) aLight = aView->ActiveLight();
5886 const Quantity_Color aColor = aLight->Color();
5887 theDi << "Light" << aLightId << "\n";
5888 switch (aLight->Type())
5889 {
5890 case V3d_AMBIENT:
5891 {
5892 theDi << " Type: Ambient\n";
5893 break;
5894 }
5895 case V3d_DIRECTIONAL:
5896 {
5897 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
5898 theDi << " Type: Directional\n";
5899 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5900 if (!aLightDir.IsNull())
5901 {
5902 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5903 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5904 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
5905 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5906 }
5907 break;
5908 }
5909 case V3d_POSITIONAL:
5910 {
5911 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
5912 theDi << " Type: Positional\n";
5913 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5914 if (!aLightPos.IsNull())
5915 {
5916 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5917 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5918 aLightPos->Attenuation (anAtten[0], anAtten[1]);
5919 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
5920 }
5921 break;
5922 }
5923 case V3d_SPOT:
5924 {
5925 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
5926 theDi << " Type: Spot\n";
5927 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
5928 if (!aLightSpot.IsNull())
5929 {
5930 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
5931 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5932 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
5933 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
5934 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
5935 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
5936 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
5937 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
5938 }
5939 break;
5940 }
5941 default:
5942 {
5943 theDi << " Type: UNKNOWN\n";
5944 break;
5945 }
5946 }
5947 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
5948 }
5949 }
5950
5951 Handle(V3d_Light) aLightNew;
5952 Handle(V3d_Light) aLightOld;
5953 Standard_Boolean isGlobal = Standard_True;
5954 Standard_Boolean toCreate = Standard_False;
5955 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5956 {
5957 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
5958 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
5959 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
5960 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
5961 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
5962
5963 TCollection_AsciiString aName, aValue;
5964 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
5965 TCollection_AsciiString anArgCase (anArg);
5966 anArgCase.UpperCase();
5967 if (anArgCase.IsEqual ("NEW")
5968 || anArgCase.IsEqual ("ADD")
5969 || anArgCase.IsEqual ("CREATE"))
5970 {
5971 toCreate = Standard_True;
5972 }
5973 else if (anArgCase.IsEqual ("GLOB")
5974 || anArgCase.IsEqual ("GLOBAL"))
5975 {
5976 isGlobal = Standard_True;
5977 }
5978 else if (anArgCase.IsEqual ("LOC")
5979 || anArgCase.IsEqual ("LOCAL"))
5980 {
5981 isGlobal = Standard_False;
5982 }
4fe9ad57 5983 else if (anArgCase.IsEqual ("DEF")
5984 || anArgCase.IsEqual ("DEFAULTS"))
5985 {
5986 toCreate = Standard_False;
5987 aViewer->SetDefaultLights();
5988 }
5989 else if (anArgCase.IsEqual ("CLR")
5990 || anArgCase.IsEqual ("CLEAR"))
5991 {
5992 toCreate = Standard_False;
5993 aView->InitActiveLights();
5994 while (aView->MoreActiveLights())
5995 {
5996 aViewer->DelLight (aView->ActiveLight());
5997 aView->InitActiveLights();
5998 }
5999 }
12381341 6000 else if (anArgCase.IsEqual ("AMB")
6001 || anArgCase.IsEqual ("AMBIENT")
6002 || anArgCase.IsEqual ("AMBLIGHT"))
6003 {
6004 addLight (aLightNew, isGlobal);
6005 if (!toCreate)
6006 {
6007 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6008 return 1;
6009 }
6010 toCreate = Standard_False;
6011 aLightNew = new V3d_AmbientLight (aViewer);
6012 }
6013 else if (anArgCase.IsEqual ("DIRECTIONAL")
6014 || anArgCase.IsEqual ("DIRLIGHT"))
6015 {
6016 addLight (aLightNew, isGlobal);
6017 if (!toCreate)
6018 {
6019 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6020 return 1;
6021 }
6022 toCreate = Standard_False;
6023 aLightNew = new V3d_DirectionalLight (aViewer);
6024 }
6025 else if (anArgCase.IsEqual ("SPOT")
6026 || anArgCase.IsEqual ("SPOTLIGHT"))
6027 {
6028 addLight (aLightNew, isGlobal);
6029 if (!toCreate)
6030 {
6031 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6032 return 1;
6033 }
6034 toCreate = Standard_False;
6035 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
6036 }
6037 else if (anArgCase.IsEqual ("POSLIGHT")
6038 || anArgCase.IsEqual ("POSITIONAL"))
6039 {
6040 addLight (aLightNew, isGlobal);
6041 if (!toCreate)
6042 {
6043 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6044 return 1;
6045 }
6046 toCreate = Standard_False;
6047 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
6048 }
6049 else if (anArgCase.IsEqual ("CHANGE"))
6050 {
6051 addLight (aLightNew, isGlobal);
6052 aLightNew.Nullify();
6053 if (++anArgIt >= theArgsNb)
6054 {
6055 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6056 return 1;
6057 }
6058
6059 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
6060 Standard_Integer aLightIt = 0;
6061 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
6062 {
6063 if (aLightIt == aLightId)
6064 {
6065 aLightOld = aView->ActiveLight();
6066 break;
6067 }
6068 }
6069
6070 if (aLightOld.IsNull())
6071 {
6072 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
6073 return 1;
6074 }
6075 }
6076 else if (anArgCase.IsEqual ("DEL")
6077 || anArgCase.IsEqual ("DELETE"))
6078 {
6079 Handle(V3d_Light) aLightDel;
6080 if (++anArgIt >= theArgsNb)
6081 {
6082 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6083 return 1;
6084 }
6085
6086 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
6087 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
6088 Standard_Integer aLightIt = 0;
6089 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
6090 {
6091 aLightDel = aView->ActiveLight();
6092 if (aLightIt == aLightDelId)
6093 {
6094 break;
6095 }
6096 }
6097 if (!aLightDel.IsNull())
6098 {
6099 aViewer->DelLight (aLightDel);
6100 }
6101 }
6102 else if (anArgCase.IsEqual ("COLOR")
6103 || anArgCase.IsEqual ("COLOUR"))
6104 {
6105 if (++anArgIt >= theArgsNb)
6106 {
6107 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6108 return 1;
6109 }
6110
6111 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
6112 anArgNext.UpperCase();
6113 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
6114 if (!aLightCurr.IsNull())
6115 {
6116 aLightCurr->SetColor (aColor);
6117 }
6118 }
6119 else if (anArgCase.IsEqual ("POS")
6120 || anArgCase.IsEqual ("POSITION"))
6121 {
6122 if ((anArgIt + 3) >= theArgsNb)
6123 {
6124 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6125 return 1;
6126 }
6127
6128 anXYZ[0] = Atof (theArgVec[++anArgIt]);
6129 anXYZ[1] = Atof (theArgVec[++anArgIt]);
6130 anXYZ[2] = Atof (theArgVec[++anArgIt]);
6131 if (!aLightDir.IsNull())
6132 {
6133 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
6134 }
6135 else if (!aLightPos.IsNull())
6136 {
6137 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
6138 }
6139 else if (!aLightSpot.IsNull())
6140 {
6141 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
6142 }
6143 else
6144 {
6145 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6146 return 1;
6147 }
6148 }
6149 else if (anArgCase.IsEqual ("DIR")
6150 || anArgCase.IsEqual ("DIRECTION"))
6151 {
6152 if ((anArgIt + 3) >= theArgsNb)
6153 {
6154 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6155 return 1;
6156 }
6157
6158 anXYZ[0] = Atof (theArgVec[++anArgIt]);
6159 anXYZ[1] = Atof (theArgVec[++anArgIt]);
6160 anXYZ[2] = Atof (theArgVec[++anArgIt]);
6161 if (!aLightDir.IsNull())
6162 {
6163 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
6164 }
6165 else if (!aLightSpot.IsNull())
6166 {
6167 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
6168 }
6169 else
6170 {
6171 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6172 return 1;
6173 }
6174 }
4fe9ad57 6175 else if (anArgCase.IsEqual ("ANG")
6176 || anArgCase.IsEqual ("ANGLE"))
6177 {
6178 if (++anArgIt >= theArgsNb)
6179 {
6180 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6181 return 1;
6182 }
6183
6184 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
6185
6186 if (!aLightSpot.IsNull())
6187 {
6188 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
6189 }
6190 }
12381341 6191 else if (anArgCase.IsEqual ("CONSTATTEN")
6192 || anArgCase.IsEqual ("CONSTATTENUATION"))
6193 {
6194 if (++anArgIt >= theArgsNb)
6195 {
6196 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6197 return 1;
6198 }
6199
6200 if (!aLightPos.IsNull())
6201 {
6202 aLightPos->Attenuation (anAtten[0], anAtten[1]);
6203 anAtten[0] = Atof (theArgVec[anArgIt]);
6204 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
6205 }
6206 else if (!aLightSpot.IsNull())
6207 {
6208 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
6209 anAtten[0] = Atof (theArgVec[anArgIt]);
6210 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
6211 }
6212 else
6213 {
6214 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6215 return 1;
6216 }
6217 }
6218 else if (anArgCase.IsEqual ("LINATTEN")
6219 || anArgCase.IsEqual ("LINEARATTEN")
6220 || anArgCase.IsEqual ("LINEARATTENUATION"))
6221 {
6222 if (++anArgIt >= theArgsNb)
6223 {
6224 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6225 return 1;
6226 }
6227
6228 if (!aLightPos.IsNull())
6229 {
6230 aLightPos->Attenuation (anAtten[0], anAtten[1]);
6231 anAtten[1] = Atof (theArgVec[anArgIt]);
6232 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
6233 }
6234 else if (!aLightSpot.IsNull())
6235 {
6236 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
6237 anAtten[1] = Atof (theArgVec[anArgIt]);
6238 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
6239 }
6240 else
6241 {
6242 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6243 return 1;
6244 }
6245 }
6246 else if (anArgCase.IsEqual ("EXP")
6247 || anArgCase.IsEqual ("EXPONENT")
6248 || anArgCase.IsEqual ("SPOTEXP")
6249 || anArgCase.IsEqual ("SPOTEXPONENT"))
6250 {
6251 if (++anArgIt >= theArgsNb)
6252 {
6253 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6254 return 1;
6255 }
6256
6257 if (!aLightSpot.IsNull())
6258 {
6259 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
6260 }
6261 else
6262 {
6263 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6264 return 1;
6265 }
6266 }
6267 else if (anArgCase.IsEqual ("HEAD")
6268 || anArgCase.IsEqual ("HEADLIGHT"))
6269 {
6270 if (++anArgIt >= theArgsNb)
6271 {
6272 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6273 return 1;
6274 }
6275
6276 if (aLightAmb.IsNull()
6277 && !aLightCurr.IsNull())
6278 {
6279 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
6280 }
6281 else
6282 {
6283 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6284 return 1;
6285 }
6286 }
6287 else
6288 {
6289 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
6290 }
6291 }
6292
6293 addLight (aLightNew, isGlobal);
6294 aViewer->UpdateLights();
6295
6296 return 0;
6297}
6298
6299
6300
e276548b 6301//==============================================================================
6302//function : VClInfo
6303//purpose : Prints info about active OpenCL device
6304//==============================================================================
6305
7ae4a307 6306static Standard_Integer VClInfo (Draw_Interpretor& theDi,
e276548b 6307 Standard_Integer,
6308 const char**)
6309{
e276548b 6310 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
e276548b 6311 if (aContextAIS.IsNull())
6312 {
7ae4a307 6313 std::cerr << "Call vinit before!\n";
e276548b 6314 return 1;
6315 }
6316
6317 Handle(OpenGl_GraphicDriver) aDrv = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
7ae4a307 6318 Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
e276548b 6319 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> anInfo;
7ae4a307 6320 if (aDrv.IsNull()
6321 || aCView == NULL
6322 || !aDrv->GetOpenClDeviceInfo (*aCView, anInfo))
e276548b 6323 {
7ae4a307 6324 theDi << "OpenCL device info is unavailable!\n";
e276548b 6325 return 0;
6326 }
e276548b 6327
7ae4a307 6328 theDi << "OpenCL device info:\n";
6329 for (NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>::Iterator anIter (anInfo);
6330 anIter.More(); anIter.Next())
e276548b 6331 {
7ae4a307 6332 theDi << anIter.Key() << ": \t" << anIter.Value() << "\n";
e276548b 6333 }
e276548b 6334 return 0;
6335}
6336
6337//=======================================================================
6338//function : VRaytrace
6339//purpose : Enables/disables OpenCL-based ray-tracing
6340//=======================================================================
6341
7ae4a307 6342static Standard_Integer VRaytrace (Draw_Interpretor& ,
6343 Standard_Integer theArgNb,
6344 const char** theArgVec)
e276548b 6345{
7ae4a307 6346 Handle(V3d_View) aView = ViewerTest::CurrentView();
6347 if (aView.IsNull())
e276548b 6348 {
6349 std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
6350 return 1;
6351 }
6352
7ae4a307 6353 if (theArgNb < 2
6354 || Draw::Atoi (theArgVec[1]))
e276548b 6355 {
e276548b 6356 aView->SetRaytracingMode();
7ae4a307 6357 }
e276548b 6358 else
7ae4a307 6359 {
e276548b 6360 aView->SetRasterizationMode();
7ae4a307 6361 }
e276548b 6362 aView->Redraw();
e276548b 6363 return 0;
6364}
6365
e276548b 6366//=======================================================================
6367//function : VSetRaytraceMode
6368//purpose : Enables/disables features of OpenCL-based ray-tracing
6369//=======================================================================
6370
e276548b 6371static Standard_Integer VSetRaytraceMode (Draw_Interpretor&,
6372 Standard_Integer theArgNb,
6373 const char ** theArgVec)
6374{
7ae4a307 6375 Handle(V3d_View) aView = ViewerTest::CurrentView();
6376 if (aView.IsNull())
e276548b 6377 {
6378 std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
6379 return 1;
6380 }
7ae4a307 6381 else if (theArgNb < 2)
e276548b 6382 {
6383 std::cerr << "Usage : " << theArgVec[0] << " [shad=0|1] [refl=0|1] [aa=0|1]\n";
6384 return 1;
6385 }
6386
e276548b 6387 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6388 {
6389 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
6390
6391 if (anArg.Search ("shad=") > -1)
6392 {
6393 if (anArg.Token ("=", 2).IntegerValue() != 0)
6394 aView->EnableRaytracedShadows();
6395 else
6396 aView->DisableRaytracedShadows();
6397 }
6398 else if (anArg.Search ("refl=") > -1)
6399 {
6400 if (anArg.Token ("=", 2).IntegerValue() != 0)
6401 aView->EnableRaytracedReflections();
6402 else
6403 aView->DisableRaytracedReflections();
6404 }
6405 else if (anArg.Search ("aa=") > -1)
6406 {
6407 if (anArg.Token ("=", 2).IntegerValue() != 0)
6408 aView->EnableRaytracedAntialiasing();
6409 else
6410 aView->DisableRaytracedAntialiasing();
6411 }
6412 else
6413 {
6414 std::cerr << "Unknown argument: " << anArg << "\n";
6415 }
6416 }
6417
6418 aView->Redraw();
e276548b 6419 return 0;
6420}
6421
7fd59977 6422//=======================================================================
6423//function : ViewerCommands
6424//purpose :
6425//=======================================================================
6426
6427void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
6428{
6429
6430 const char *group = "ZeViewer";
18d715bd 6431 theCommands.Add("vinit",
6432#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
6433 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
6434#else
6435 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
6436#endif
6437 " - Creates new View window with specified name view_name.\n"
6438 "By default the new view is created in the viewer and in"
6439 " graphic driver shared with active view.\n"
6440 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
6441 "If driverName isn't specified the driver will be shared with active view.\n"
6442 "If viewerName isn't specified the viewer will be shared with active view.\n"
6443#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
6444 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
6445 "is used in creation of graphic driver\n"
6446#endif
6447 " - l, t: pixel position of left top corner of the window\n"
6448 " - w,h: width and heigth of window respectively.\n"
6449 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
7fd59977 6450 __FILE__,VInit,group);
18d715bd 6451 theCommands.Add("vclose" ,
d0cc1cb7 6452 "[view_id [keep_context=0|1]]\n"
18d715bd 6453 "or vclose ALL - to remove all created views\n"
6454 " - removes view(viewer window) defined by its view_id.\n"
6455 " - keep_context: by default 0; if 1 and the last view is deleted"
6456 " the current context is not removed.",
6457 __FILE__,VClose,group);
6458 theCommands.Add("vactivate" ,
6459 "view_id"
6460 " - activates view(viewer window) defined by its view_id",
6461 __FILE__,VActivate,group);
6462 theCommands.Add("vviewlist",
6463 "vviewlist [format={tree, long}]"
6464 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
6465 " - format: format of result output, if tree the output is a tree view;"
6466 "otherwise it's a list of full view names. By default format = tree",
6467 __FILE__,VViewList,group);
7fd59977 6468 theCommands.Add("vhelp" ,
6469 "vhelp : display help on the viewer commands",
6470 __FILE__,VHelp,group);
6471 theCommands.Add("vtop" ,
44b8f2d6 6472 "vtop or <T> : Top view" ,
7fd59977 6473 __FILE__,VTop,group);
44b8f2d6 6474 theCommands.Add("vbottom" ,
6475 "vbottom : Bottom view" ,
6476 __FILE__,VBottom,group);
6477 theCommands.Add("vleft" ,
6478 "vleft : Left view" ,
6479 __FILE__,VLeft,group);
6480 theCommands.Add("vright" ,
6481 "vright : Right view" ,
6482 __FILE__,VRight,group);
7fd59977 6483 theCommands.Add("vaxo" ,
6484 " vaxo or <A> : Axonometric view ",
6485 __FILE__,VAxo,group);
44b8f2d6 6486 theCommands.Add("vfront" ,
6487 "vfront : Front view" ,
6488 __FILE__,VFront,group);
6489 theCommands.Add("vback" ,
6490 "vback : Back view" ,
6491 __FILE__,VBack,group);
7fd59977 6492 theCommands.Add("vpick" ,
6493 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
6494 VPick,group);
6495 theCommands.Add("vfit" ,
6496 "vfit or <F> : vfit",
6497 __FILE__,VFit,group);
197ac94e 6498 theCommands.Add ("vzfit", "vzfit [scale]\n"
6499 " Matches Z near, Z far view volume planes to the displayed objects.\n"
6500 " \"scale\" - specifies factor to scale computed z range.\n",
6501 __FILE__, VZFit, group);
7fd59977 6502 theCommands.Add("vrepaint",
6503 "vrepaint : vrepaint, force redraw",
6504 __FILE__,VRepaint,group);
6505 theCommands.Add("vclear",
6506 "vclear : vclear",
6507 __FILE__,VClear,group);
6508 theCommands.Add("vsetbg",
6509 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
6510 __FILE__,VSetBg,group);
f8b2ed36 6511 theCommands.Add("vsetbgmode",
6512 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
6513 __FILE__,VSetBgMode,group);
7fd59977 6514 theCommands.Add("vsetgradientbg",
f8b2ed36 6515 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
7fd59977 6516 __FILE__,VSetGradientBg,group);
f8b2ed36 6517 theCommands.Add("vsetgrbgmode",
6518 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
6519 __FILE__,VSetGradientBgMode,group);
6520 theCommands.Add("vsetcolorbg",
6521 "vsetcolorbg : vsetcolorbg r g b : Set background color",
6522 __FILE__,VSetColorBg,group);
7fd59977 6523 theCommands.Add("vscale",
6524 "vscale : vscale X Y Z",
6525 __FILE__,VScale,group);
6526 theCommands.Add("vzbufftrihedron",
7c8a8fcc 6527 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
6528 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
6529 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
7fd59977 6530 __FILE__,VTestZBuffTrihedron,group);
6531 theCommands.Add("vrotate",
6532 "vrotate : vrotate AX AY AZ [X Y Z]",
6533 __FILE__,VRotate,group);
6534 theCommands.Add("vzoom",
6535 "vzoom : vzoom coef",
6536 __FILE__,VZoom,group);
6537 theCommands.Add("vpan",
6538 "vpan : vpan dx dy",
6539 __FILE__,VPan,group);
6540 theCommands.Add("vexport",
5cedc27f
K
6541 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
6542 " : exports the view to a vector file of a given format"
6543 " : notice that EMF format requires patched gl2ps",
7fd59977 6544 __FILE__,VExport,group);
6545 theCommands.Add("vcolorscale",
6546 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
6547 __FILE__,VColorScale,group);
6548 theCommands.Add("vgraduatedtrihedron",
13a22457 6549 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
7fd59977 6550 __FILE__,VGraduatedTrihedron,group);
7edf74fd 6551 theCommands.Add("vprintview" ,
b5ac8292 6552 "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
7edf74fd 6553 __FILE__,VPrintView,group);
59f45b7c 6554 theCommands.Add("vzlayer",
6555 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
6556 __FILE__,VZLayer,group);
25289ec1 6557 theCommands.Add("voverlaytext",
6558 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
6559 " : height - pixel height of the text (default=10.0)"
6560 " : font_name - name of font (default=courier)"
6561 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
6562 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
6563 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
6564 __FILE__,VOverlayText,group);
20637bd2 6565 theCommands.Add("vlayerline",
6566 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
6567 __FILE__,VLayerLine,group);
2bd4c032 6568 theCommands.Add ("vgrid",
6569 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
6570 " : Mode - rectangular or circular"
6571 " : Type - lines or points",
6572 __FILE__, VGrid, group);
208e6839 6573 theCommands.Add ("vfps",
6574 "vfps [framesNb=100] : estimate average frame rate for active view",
6575 __FILE__, VFps, group);
58655684 6576 theCommands.Add ("vgldebug",
6577 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
6578 " : this function is implemented only for Windows\n"
6579 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
6580 __FILE__, VGlDebug, group);
208e6839 6581 theCommands.Add ("vvbo",
58655684 6582 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
208e6839 6583 __FILE__, VVbo, group);
b5ac8292 6584 theCommands.Add ("vstereo",
6585 "\nvstereo [{0|1}] : turn stereo usage On/Off; affects only newly displayed objects",
6586 __FILE__, VStereo, group);
a577aaab 6587 theCommands.Add ("vcaps",
abe46077 6588 "vcaps [vbo={0|1}] [sprites={0|1}] [soft={0|1}] : modify particular graphic driver options",
a577aaab 6589 __FILE__, VCaps, group);
f0430952 6590 theCommands.Add ("vmemgpu",
6591 "vmemgpu [f]: print system-dependent GPU memory information if available;"
6592 " with f option returns free memory in bytes",
6593 __FILE__, VMemGpu, group);
85e096c3 6594 theCommands.Add ("vreadpixel",
6595 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
6596 " : Read pixel value for active view",
6597 __FILE__, VReadPixel, group);
692613e5 6598 theCommands.Add("diffimage",
6599 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
6600 __FILE__, VDiffImage, group);
4754e164 6601 theCommands.Add ("vselect",
6602 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
6603 "- emulates different types of selection:\n"
6604 "- 1) single click selection\n"
6605 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
6606 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
6607 "- 4) any of these selections with shift button pressed",
6608 __FILE__, VSelect, group);
6609 theCommands.Add ("vmoveto",
6610 "vmoveto x y"
6611 "- emulates cursor movement to pixel postion (x,y)",
6612 __FILE__, VMoveTo, group);
197ac94e 6613 theCommands.Add ("vviewparams", "vviewparams usage:\n"
6614 "- vviewparams\n"
6615 "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n"
3dfe95cd 6616 " [-proj [x y z]] [-center x y] [-size sx]\n"
197ac94e 6617 "- Gets or sets current view parameters.\n"
6618 "- If called without arguments, all view parameters are printed.\n"
6619 "- The options are:\n"
3dfe95cd 6620 " -scale [s] : prints or sets viewport relative scale.\n"
197ac94e 6621 " -eye [x y z] : prints or sets eye location.\n"
6622 " -at [x y z] : prints or sets center of look.\n"
6623 " -up [x y z] : prints or sets direction of up vector.\n"
6624 " -proj [x y z] : prints or sets direction of look.\n"
3dfe95cd 6625 " -center x y : sets location of center of the screen in pixels.\n"
6626 " -size [sx] : prints viewport projection width and height sizes\n"
6627 " : or changes the size of its maximum dimension.\n",
197ac94e 6628 __FILE__, VViewParams, group);
4754e164 6629 theCommands.Add("vchangeselected",
dc3fe572 6630 "vchangeselected shape"
4754e164 6631 "- adds to shape to selection or remove one from it",
6632 __FILE__, VChangeSelected, group);
6633 theCommands.Add("vzclipping",
6634 "vzclipping [mode] [depth width]\n"
6635 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
6636 "- gets or sets ZClipping mode, width and depth",
6637 __FILE__,VZClipping,group);
6638 theCommands.Add ("vnbselected",
6639 "vnbselected", __FILE__, VNbSelected, group);
b5ac8292 6640 theCommands.Add ("vchangecamera",
6641 " changes camera parameters \n"
6642 "- vchangecamera [param_type] [value]\n"
6643 "- vchangecamera proj {ortho/persp/left/right/stereo}\n"
6644 " Projection type including left and right stereo parts.\n"
6645 "- vchangecamera dist [real]\n"
6646 " Sets distance from target point to camera eye (moving eye).\n"
6647 "- vchangecamera iod [real]\n"
6648 " Intraocular distance value.\n"
6649 "- vchangecamera zfocus [real]\n"
6650 " Stereographic focus value.\n"
6651 "- vchangecamera fov [real]\n"
6652 " Field Of View value (in degrees).\n"
6653 "- vchangecamera zfocustype {absolute/relative}\n"
6654 " Stereographic focus definition type (absolute value or coefficient).\n"
6655 "- vchangecamera iodtype {absolute/relative}\n"
6656 " Intraocular distance definition type (absolute value or coefficient).\n",
6657 __FILE__, VChangeCamera, group);
6658 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
197ac94e 6659 "- vautozfit [on={1|0}] [scale]\n"
6660 " Prints or changes parameters of automatic z-fit mode:\n"
6661 " \"on\" - turns automatic z-fit on or off\n"
6662 " \"scale\" - specifies factor to scale computed z range.\n",
6663 __FILE__, VAutoZFit, group);
b5ac8292 6664 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
6665 " vzrange - without parameters shows current values\n"
6666 " vzrange [znear] [zfar] - applies provided values to view",
6667 __FILE__,VZRange, group);
4754e164 6668 theCommands.Add("vantialiasing",
6669 "vantialiasing 1|0",
6670 __FILE__,VAntialiasing,group);
6671 theCommands.Add ("vpurgedisplay",
eb4320f2 6672 "vpurgedisplay"
4754e164 6673 "- removes structures which don't belong to objects displayed in neutral point",
6674 __FILE__, VPurgeDisplay, group);
6675 theCommands.Add("vsetviewsize",
6676 "vsetviewsize size",
6677 __FILE__,VSetViewSize,group);
6678 theCommands.Add("vmoveview",
6679 "vmoveview Dx Dy Dz [Start = 1|0]",
6680 __FILE__,VMoveView,group);
6681 theCommands.Add("vtranslateview",
6682 "vtranslateview Dx Dy Dz [Start = 1|0)]",
6683 __FILE__,VTranslateView,group);
6684 theCommands.Add("vturnview",
6685 "vturnview Ax Ay Az [Start = 1|0]",
6686 __FILE__,VTurnView,group);
269294d6 6687 theCommands.Add("vtextureenv",
6688 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
6689 "or user-defined file and optionally applying texture mapping parameters\n"
6690 " Usage:\n"
6691 " vtextureenv off - disables environment mapping\n"
6692 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
6693 " std_texture = (0..7)\n"
6694 " rep = {clamp|repeat}\n"
6695 " mod = {decal|modulate}\n"
6696 " flt = {nearest|bilinear|trilinear}\n"
6697 " ss, st - scale factors for s and t texture coordinates\n"
6698 " ts, tt - translation for s and t texture coordinates\n"
6699 " rot - texture rotation angle in degrees",
6700 __FILE__, VTextureEnv, group);
0a768f56 6701 theCommands.Add("vhlr" ,
e9224045 6702 "is_enabled={on|off} [show_hidden={1|0}]"
0a768f56 6703 " - Hidden line removal algorithm:"
e9224045 6704 " - is_enabled: if is on HLR algorithm is applied\n"
6705 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
0a768f56 6706 __FILE__,VHLR,group);
6707 theCommands.Add("vhlrtype" ,
6708 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
6709 " - Changes the type of HLR algorithm using for shapes."
6710 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
6711 " if equals to polyalgo, polygonal HLR algorithm is applied."
6712 "If shapes are not given HLR algoithm of given type is applied"
6713 " to all shapes in the view\n",
6714 __FILE__,VHLRType,group);
4269bd1b 6715 theCommands.Add("vclipplane", "vclipplane usage: \n"
6716 " maxplanes <view_name> - get plane limit for view.\n"
6717 " create <plane_name> - create new plane.\n"
6718 " delete <plane_name> - delete plane.\n"
6719 " clone <source_plane> <plane_name> - clone the plane definition.\n"
6720 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
6721 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
6722 " change <plane_name> on/off - turn clipping on/off.\n"
6723 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
6724 " change <plane_name> capping on/off - turn capping on/off.\n"
6725 " change <plane_name> capping color <r> <g> <b> - set color.\n"
6726 " change <plane name> capping texname <texture> - set texture.\n"
6727 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
6728 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
6729 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
6730 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
6731 " please use VSetTextureMode command to enable texture rendering in view.\n"
6732 , __FILE__, VClipPlane, group);
6733 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
6734 " mode can be:\n"
6735 " 0 - no textures enabled in view.\n"
6736 " 1 - only environment textures enabled.\n"
6737 " 2 - all textures enabled.\n"
6738 " this command sets texture details mode for the specified view.\n"
6739 , __FILE__, VSetTextureMode, group);
392ac980 6740 theCommands.Add("vdefaults",
6741 "vdefaults [absDefl=value] [devCoeff=value] [angDefl=value]",
6742 __FILE__, VDefaults, group);
12381341 6743 theCommands.Add("vlight",
816d03ee 6744 "tool to manage light sources, without arguments shows list of lights."
6745 "\n Main commands: "
6746 "\n 'clear' to clear lights"
6747 "\n '{def}aults' to load deafault lights"
6748 "\n 'add' (or 'new') <type> to add any light source"
6749 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
6750 "\n 'change' <lightId> to edit light source with specified lightId"
6751 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
6752 "\n {pos}ition X Y Z"
6753 "\n {dir}ection X Y Z (for directional light or for spotlight)"
6754 "\n color colorName"
6755 "\n {head}light 0|1"
6756 "\n {constAtten}uation value"
6757 "\n {linearAtten}uation value"
6758 "\n angle angleDeg"
6759 "\n {spotexp}onent value"
6760 "\n local|global"
6761 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
6762 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
12381341 6763 __FILE__, VLight, group);
e276548b 6764 theCommands.Add("vraytrace",
6765 "vraytrace 0|1",
6766 __FILE__,VRaytrace,group);
6767 theCommands.Add("vclinfo",
6768 "vclinfo",
6769 __FILE__,VClInfo,group);
6770 theCommands.Add("vsetraytracemode",
6771 "vsetraytracemode [shad=0|1] [refl=0|1] [aa=0|1]",
6772 __FILE__,VSetRaytraceMode,group);
7fd59977 6773}