0030483: Visualization, Path Tracing - make Tile Size configurable
[occt.git] / src / ViewerTest / ViewerTest_ViewerCommands.cxx
CommitLineData
b311480e 1// Created on: 1998-09-01
2// Created by: Robert COUBLANC
3// Copyright (c) 1998-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
58655684 17#include <OpenGl_GlCore20.hxx>
1beb58d7 18
19#include <AIS_Animation.hxx>
20#include <AIS_AnimationCamera.hxx>
21#include <AIS_AnimationObject.hxx>
30a1b24e 22#include <AIS_CameraFrustum.hxx>
7a324550 23#include <AIS_ColorScale.hxx>
625e1958 24#include <AIS_Manipulator.hxx>
b12e1c7b 25#include <AIS_RubberBand.hxx>
0a768f56 26#include <AIS_Shape.hxx>
0a768f56 27#include <AIS_InteractiveObject.hxx>
28#include <AIS_ListOfInteractive.hxx>
29#include <AIS_ListIteratorOfListOfInteractive.hxx>
8a590580 30#include <Aspect_Grid.hxx>
0a768f56 31#include <DBRep.hxx>
08f8a185 32#include <Draw_ProgressIndicator.hxx>
61b0191c 33#include <Graphic3d_ArrayOfPolylines.hxx>
2bd4c032 34#include <Graphic3d_AspectMarker3d.hxx>
269294d6 35#include <Graphic3d_NameOfTextureEnv.hxx>
a79f67f8 36#include <Graphic3d_GraduatedTrihedron.hxx>
269294d6 37#include <Graphic3d_TextureEnv.hxx>
38#include <Graphic3d_TextureParams.hxx>
39#include <Graphic3d_TypeOfTextureFilter.hxx>
4269bd1b 40#include <Graphic3d_AspectFillArea3d.hxx>
7fd59977 41#include <ViewerTest.hxx>
8625ef7e 42#include <ViewerTest_AutoUpdater.hxx>
7fd59977 43#include <ViewerTest_EventManager.hxx>
4754e164 44#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
4269bd1b 45#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
625e1958 46#include <ViewerTest_CmdParser.hxx>
12381341 47#include <V3d_AmbientLight.hxx>
48#include <V3d_DirectionalLight.hxx>
12381341 49#include <V3d_PositionalLight.hxx>
50#include <V3d_SpotLight.hxx>
08f8a185 51#include <Message_ProgressSentry.hxx>
18d715bd 52#include <NCollection_DoubleMap.hxx>
53#include <NCollection_List.hxx>
54#include <NCollection_Vector.hxx>
7fd59977 55#include <AIS_InteractiveContext.hxx>
56#include <Draw_Interpretor.hxx>
57#include <Draw.hxx>
58#include <Draw_Appli.hxx>
692613e5 59#include <Image_AlienPixMap.hxx>
08f8a185 60#include <Image_VideoRecorder.hxx>
58655684 61#include <OpenGl_GraphicDriver.hxx>
208e6839 62#include <OSD_Timer.hxx>
900f7229 63#include <TColStd_HSequenceOfAsciiString.hxx>
59f45b7c 64#include <TColStd_SequenceOfInteger.hxx>
4754e164 65#include <TColStd_HSequenceOfReal.hxx>
66#include <TColgp_Array1OfPnt2d.hxx>
197ac94e 67#include <TColStd_MapOfAsciiString.hxx>
20637bd2 68#include <Aspect_TypeOfLine.hxx>
692613e5 69#include <Image_Diff.hxx>
dc3fe572 70#include <Aspect_DisplayConnection.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>
6262338c 79#include <Prs3d_Drawer.hxx>
61b0191c 80#include <Prs3d_LineAspect.hxx>
81#include <Prs3d_Root.hxx>
fd3f6bd0 82#include <Prs3d_Text.hxx>
83#include <Select3D_SensitivePrimitiveArray.hxx>
7fd59977 84
57c28b61 85#ifdef _WIN32
25289ec1 86#undef DrawText
87#endif
88
692613e5 89#include <cstdlib>
25289ec1 90
58655684 91#if defined(_WIN32)
4fe56619 92 #include <WNT_WClass.hxx>
93 #include <WNT_Window.hxx>
4fe56619 94#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
4fe56619 95 #include <Cocoa_Window.hxx>
7fd59977 96#else
4fe56619 97 #include <Xw_Window.hxx>
98 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
99 #include <X11/Xutil.h>
100 #include <tk.h>
7fd59977 101#endif
102
b514beda 103// Auxiliary definitions
104static const char THE_KEY_DELETE = 127;
fd3f6bd0 105static const char THE_KEY_ESCAPE = 27;
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);
4754e164 115extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
7fd59977 116
b514beda 117extern int VErase (Draw_Interpretor& theDI,
118 Standard_Integer theArgNb,
119 const char** theArgVec);
120
58655684 121#if defined(_WIN32)
7fd59977 122static Handle(WNT_Window)& VT_GetWindow() {
123 static Handle(WNT_Window) WNTWin;
124 return WNTWin;
125}
4fe56619 126#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
4fe56619 127static Handle(Cocoa_Window)& VT_GetWindow()
128{
129 static Handle(Cocoa_Window) aWindow;
130 return aWindow;
131}
132extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
18d715bd 133extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
134extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
135
7fd59977 136#else
7fd59977 137static Handle(Xw_Window)& VT_GetWindow(){
138 static Handle(Xw_Window) XWWin;
139 return XWWin;
140}
7fd59977 141
142static void VProcessEvents(ClientData,int);
143#endif
144
18d715bd 145static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
146{
147 static Handle(Aspect_DisplayConnection) aDisplayConnection;
148 return aDisplayConnection;
149}
150
151static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
152{
153 GetDisplayConnection() = theDisplayConnection;
154}
155
58655684 156#if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
18d715bd 157Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
dc3fe572 158{
0ebaa4db 159 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
58655684 160#if defined(_WIN32)
18d715bd 161 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
162 if (!aWindow.IsNull())
163 return aWindow->HWindow();
164#elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
165 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
166 if (!aWindow.IsNull())
167 return aWindow->XWindow();
168#endif
169 return aWindowHandle;
dc3fe572 170}
18d715bd 171#endif
dc3fe572 172
2e93433e 173//! Setting additional flag to store 2D mode of the View to avoid scene rotation by mouse/key events
174class ViewerTest_V3dView : public V3d_View
175{
176 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_V3dView, V3d_View)
177public:
178 //! Initializes the view.
179 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType = V3d_ORTHOGRAPHIC,
180 bool theIs2dMode = false)
181 : V3d_View (theViewer, theType), myIs2dMode (theIs2dMode) {}
182
183 //! Initializes the view by copying.
184 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView)
185 : V3d_View (theViewer, theView), myIs2dMode (false)
186 {
187 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (theView))
188 {
189 myIs2dMode = aV3dView->IsViewIn2DMode();
190 }
191 }
192
193 //! Returns true if 2D mode is set for the view
194 bool IsViewIn2DMode() const { return myIs2dMode; }
195
196 //! Sets 2D mode for the view
197 void SetView2DMode (bool the2dMode) { myIs2dMode = the2dMode; }
198
199public:
200
201 //! Returns true if active view in 2D mode.
202 static bool IsCurrentViewIn2DMode()
203 {
204 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
205 {
206 return aV3dView->IsViewIn2DMode();
207 }
208 return false;
209 }
210
211 //! Set if active view in 2D mode.
212 static void SetCurrentView2DMode (bool theIs2d)
213 {
214 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
215 {
216 aV3dView->SetView2DMode (theIs2d);
217 }
218 }
219
220private:
221
222 Standard_Boolean myIs2dMode; //!< 2D mode flag
223
224};
225
18d715bd 226NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
58655684 227static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
18d715bd 228static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
58655684 229static OpenGl_Caps ViewerTest_myDefaultCaps;
18d715bd 230
7fd59977 231static void OSWindowSetup();
232
f42753ed 233static struct
234{
235 Quantity_Color FlatColor;
236 Quantity_Color GradientColor1;
237 Quantity_Color GradientColor2;
238 Aspect_GradientFillMethod FillMethod;
239} ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
240
7fd59977 241//==============================================================================
242// EVENT GLOBAL VARIABLES
243//==============================================================================
244
245static int Start_Rot = 0;
1eeef710 246Standard_Boolean HasHlrOnBeforeRotation = Standard_False;
4fe56619 247int X_Motion = 0; // Current cursor position
248int Y_Motion = 0;
249int X_ButtonPress = 0; // Last ButtonPress position
250int Y_ButtonPress = 0;
251Standard_Boolean IsDragged = Standard_False;
8abada55 252Standard_Boolean DragFirst = Standard_False;
1beb58d7 253Standard_Boolean TheIsAnimating = Standard_False;
fd3f6bd0 254Standard_Boolean Draw_ToExitOnCloseView = Standard_False;
255Standard_Boolean Draw_ToCloseViewOnEsc = Standard_False;
7fd59977 256
b12e1c7b 257
258Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
259{
260 static Handle(AIS_RubberBand) aBand;
261 if (aBand.IsNull())
262 {
69adb9ce 263 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
264 aBand->SetDisplayMode (0);
b12e1c7b 265 }
266 return aBand;
267}
268
625e1958 269typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
270
271Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
272{
273 static ViewerTest_MapOfAISManipulators aMap;
274 return aMap;
275}
276
277Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
278{
279 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
280 for (; anIt.More(); anIt.Next())
281 {
282 if (anIt.Value()->HasActiveMode())
283 {
284 return anIt.Value();
285 }
286 }
287 return NULL;
288}
289
7fd59977 290//==============================================================================
291
57c28b61 292#ifdef _WIN32
7fd59977 293static LRESULT WINAPI ViewerWindowProc(
294 HWND hwnd,
295 UINT uMsg,
296 WPARAM wParam,
297 LPARAM lParam );
298static LRESULT WINAPI AdvViewerWindowProc(
299 HWND hwnd,
300 UINT uMsg,
301 WPARAM wParam,
302 LPARAM lParam );
303#endif
304
305
306//==============================================================================
307//function : WClass
308//purpose :
309//==============================================================================
310
ad03c234 311const Handle(Standard_Transient)& ViewerTest::WClass()
7fd59977 312{
ad03c234 313 static Handle(Standard_Transient) theWClass;
58655684 314#if defined(_WIN32)
4fe56619 315 if (theWClass.IsNull())
316 {
7c65581d 317 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
ad03c234 318 CS_VREDRAW | CS_HREDRAW, 0, 0,
c85a994a 319 ::LoadCursor (NULL, IDC_ARROW));
7fd59977 320 }
321#endif
322 return theWClass;
323}
324
325//==============================================================================
18d715bd 326//function : CreateName
327//purpose : Create numerical name for new object in theMap
328//==============================================================================
329template <typename ObjectType>
330TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
331 const TCollection_AsciiString& theDefaultString)
332{
333 if (theObjectMap.IsEmpty())
334 return theDefaultString + TCollection_AsciiString(1);
335
336 Standard_Integer aNextKey = 1;
337 Standard_Boolean isFound = Standard_False;
338 while (!isFound)
339 {
340 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
341 // Look for objects with default names
342 if (theObjectMap.IsBound1(aStringKey))
343 {
344 aNextKey++;
345 }
346 else
347 isFound = Standard_True;
348 }
349
350 return theDefaultString + TCollection_AsciiString(aNextKey);
351}
352
353//==============================================================================
354//structure : ViewerTest_Names
355//purpose : Allow to operate with full view name: driverName/viewerName/viewName
356//==============================================================================
357struct ViewerTest_Names
358{
359private:
360 TCollection_AsciiString myDriverName;
361 TCollection_AsciiString myViewerName;
362 TCollection_AsciiString myViewName;
363
364public:
365
366 const TCollection_AsciiString& GetDriverName () const
367 {
368 return myDriverName;
369 }
370 void SetDriverName (const TCollection_AsciiString& theDriverName)
371 {
372 myDriverName = theDriverName;
373 }
374 const TCollection_AsciiString& GetViewerName () const
375 {
376 return myViewerName;
377 }
378 void SetViewerName (const TCollection_AsciiString& theViewerName)
379 {
380 myViewerName = theViewerName;
381 }
382 const TCollection_AsciiString& GetViewName () const
383 {
384 return myViewName;
385 }
386 void SetViewName (const TCollection_AsciiString& theViewName)
387 {
388 myViewName = theViewName;
389 }
390
391 //===========================================================================
392 //function : Constructor for ViewerTest_Names
393 //purpose : Get view, viewer, driver names from custom string
394 //===========================================================================
395
396 ViewerTest_Names (const TCollection_AsciiString& theInputString)
397 {
398 TCollection_AsciiString aName(theInputString);
399 if (theInputString.IsEmpty())
400 {
401 // Get current configuration
402 if (ViewerTest_myDrivers.IsEmpty())
403 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
404 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
405 else
406 myDriverName = ViewerTest_myDrivers.Find2
407 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
408
409 if(ViewerTest_myContexts.IsEmpty())
410 {
411 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
412 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
413 }
414 else
c48e2889 415 {
18d715bd 416 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
c48e2889 417 }
18d715bd 418
c48e2889 419 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
18d715bd 420 }
421 else
422 {
423 // There is at least view name
424 Standard_Integer aParserNumber = 0;
425 for (Standard_Integer i = 0; i < 3; ++i)
426 {
427 Standard_Integer aParserPos = aName.SearchFromEnd("/");
428 if(aParserPos != -1)
429 {
430 aParserNumber++;
431 aName.Split(aParserPos-1);
432 }
433 else
434 break;
435 }
436 if (aParserNumber == 0)
437 {
438 // Only view name
439 if (!ViewerTest::GetAISContext().IsNull())
440 {
441 myDriverName = ViewerTest_myDrivers.Find2
442 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
443 myViewerName = ViewerTest_myContexts.Find2
444 (ViewerTest::GetAISContext());
445 }
446 else
447 {
448 // There is no opened contexts here, need to create names for viewer and driver
449 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
450 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
451
452 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
453 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
454 }
455 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
456 }
457 else if (aParserNumber == 1)
458 {
459 // Here is viewerName/viewName
460 if (!ViewerTest::GetAISContext().IsNull())
461 myDriverName = ViewerTest_myDrivers.Find2
462 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
463 else
464 {
465 // There is no opened contexts here, need to create name for driver
466 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
467 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
468 }
469 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
470
471 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
472 }
473 else
474 {
475 //Here is driverName/viewerName/viewName
476 myDriverName = TCollection_AsciiString(aName);
477
478 TCollection_AsciiString aViewerName(theInputString);
479 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
480 myViewerName = TCollection_AsciiString(aViewerName);
481
482 myViewName = TCollection_AsciiString(theInputString);
483 }
484 }
485 }
486};
487
488//==============================================================================
489//function : FindContextByView
490//purpose : Find AIS_InteractiveContext by View
491//==============================================================================
492
493Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
494{
495 Handle(AIS_InteractiveContext) anAISContext;
496
497 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
498 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
499 {
500 if (anIter.Value()->CurrentViewer() == theView->Viewer())
501 return anIter.Key2();
502 }
503 return anAISContext;
504}
505
506
507//==============================================================================
508//function : SetWindowTitle
509//purpose : Set window title
510//==============================================================================
511
512void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
513 Standard_CString theTitle)
514{
58655684 515#if defined(_WIN32)
ad03c234 516 const TCollection_ExtendedString theTitleW (theTitle);
517 SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString());
18d715bd 518#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
519 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
520#else
521 if(GetDisplayConnection()->GetDisplay())
522 {
523 Window aWindow =
524 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
525 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
526 }
527#endif
528}
529
530//==============================================================================
531//function : IsWindowOverlapped
532//purpose : Check if theWindow overlapp another view
533//==============================================================================
534
535Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
536 const Standard_Integer thePxTop,
537 const Standard_Integer thePxRight,
538 const Standard_Integer thePxBottom,
539 TCollection_AsciiString& theViewId)
540{
541 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
542 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
543 {
544 Standard_Integer aTop = 0,
545 aLeft = 0,
546 aRight = 0,
547 aBottom = 0;
548 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
549 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
550 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
551 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
552 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
553 {
554 theViewId = anIter.Key1();
555 return Standard_True;
556 }
557 }
558 return Standard_False;
559}
560
561// Workaround: to create and delete non-orthographic views outside ViewerTest
562void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
563{
564 ViewerTest_myViews.UnBind1 (theName);
565}
566
567void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
568 const Handle(V3d_View)& theView)
569{
570 ViewerTest_myViews.Bind (theName, theView);
571}
572
573TCollection_AsciiString ViewerTest::GetCurrentViewName ()
574{
575 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
576}
577//==============================================================================
7fd59977 578//function : ViewerInit
579//purpose : Create the window viewer and initialize all the global variable
580//==============================================================================
581
18d715bd 582TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
583 const Standard_Integer thePxTop,
584 const Standard_Integer thePxWidth,
585 const Standard_Integer thePxHeight,
9e04ccdc 586 const TCollection_AsciiString& theViewName,
587 const TCollection_AsciiString& theDisplayName,
588 const Handle(V3d_View)& theViewToClone)
7fd59977 589{
8c3c9904 590 // Default position and dimension of the viewer window.
4fe56619 591 // Note that left top corner is set to be sufficiently small to have
8c3c9904 592 // window fit in the small screens (actual for remote desktops, see #23003).
4fe56619 593 // The position corresponds to the window's client area, thus some
8c3c9904 594 // gap is added for window frame to be visible.
595 Standard_Integer aPxLeft = 20;
596 Standard_Integer aPxTop = 40;
7fd59977 597 Standard_Integer aPxWidth = 409;
598 Standard_Integer aPxHeight = 409;
18d715bd 599 Standard_Boolean toCreateViewer = Standard_False;
9e04ccdc 600 if (!theViewToClone.IsNull())
601 {
602 theViewToClone->Window()->Size (aPxWidth, aPxHeight);
603 }
18d715bd 604
58655684 605 Handle(OpenGl_GraphicDriver) aGraphicDriver;
18d715bd 606 ViewerTest_Names aViewNames(theViewName);
607 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
608 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
609
610 if (thePxLeft != 0)
611 aPxLeft = thePxLeft;
612 if (thePxTop != 0)
613 aPxTop = thePxTop;
614 if (thePxWidth != 0)
615 aPxWidth = thePxWidth;
616 if (thePxHeight != 0)
7fd59977 617 aPxHeight = thePxHeight;
4269bd1b 618
18d715bd 619 // Get graphic driver (create it or get from another view)
620 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
621 {
622 // Get connection string
58655684 623 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
18d715bd 624 TCollection_AsciiString aDisplayName(theDisplayName);
498ce76b 625 if (!aDisplayName.IsEmpty())
18d715bd 626 SetDisplayConnection (new Aspect_DisplayConnection ());
627 else
628 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
18d715bd 629 #else
498ce76b 630 (void)theDisplayName; // avoid warning on unused argument
18d715bd 631 SetDisplayConnection (new Aspect_DisplayConnection ());
632 #endif
14cb22a1 633
634 if (Draw_VirtualWindows)
635 {
636 // don't waste the time waiting for VSync when window is not displayed on the screen
637 ViewerTest_myDefaultCaps.swapInterval = 0;
638 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
639 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
640 }
65993a95 641 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
58655684 642 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
14cb22a1 643
18d715bd 644 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
645 toCreateViewer = Standard_True;
646 }
647 else
648 {
58655684 649 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
7fd59977 650 }
651
18d715bd 652 //Dispose the window if input parameters are default
653 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
7fd59977 654 {
18d715bd 655 Standard_Integer aTop = 0,
656 aLeft = 0,
657 aRight = 0,
658 aBottom = 0,
659 aScreenWidth = 0,
660 aScreenHeight = 0;
661
662 // Get screen resolution
663#if defined(_WIN32) || defined(__WIN32__)
664 RECT aWindowSize;
665 GetClientRect(GetDesktopWindow(), &aWindowSize);
666 aScreenHeight = aWindowSize.bottom;
667 aScreenWidth = aWindowSize.right;
668#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
669 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
670#else
671 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
672 aScreenWidth = WidthOfScreen(aScreen);
673 aScreenHeight = HeightOfScreen(aScreen);
674#endif
675
676 TCollection_AsciiString anOverlappedViewId("");
773f53f1 677
678 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
dc3fe572 679 {
18d715bd 680 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
681
682 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
683 && aRight + 2*aPxWidth + 40 > aScreenWidth)
684 {
685 if (aBottom + aPxHeight + 40 > aScreenHeight)
686 {
687 aPxLeft = 20;
688 aPxTop = 40;
689 break;
690 }
691 aPxLeft = 20;
692 aPxTop = aBottom + 40;
693 }
694 else
695 aPxLeft = aRight + 20;
dc3fe572 696 }
18d715bd 697 }
698
699 // Get viewer name
700 TCollection_AsciiString aTitle("3D View - ");
701 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
702
703 // Change name of current active window
704 if (!ViewerTest::CurrentView().IsNull())
705 {
51740958 706 TCollection_AsciiString anActiveWindowTitle("3D View - ");
707 anActiveWindowTitle = anActiveWindowTitle
18d715bd 708 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
51740958 709 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
18d715bd 710 }
711
712 // Create viewer
eb4320f2 713 Handle(V3d_Viewer) a3DViewer;
18d715bd 714 // If it's the single view, we first look for empty context
715 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
716 {
717 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
718 anIter(ViewerTest_myContexts);
719 if (anIter.More())
720 ViewerTest::SetAISContext (anIter.Value());
721 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
18d715bd 722 }
723 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
724 {
725 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
726 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
18d715bd 727 }
eb4320f2 728 else if (a3DViewer.IsNull())
18d715bd 729 {
730 toCreateViewer = Standard_True;
6a24c6de 731 a3DViewer = new V3d_Viewer(aGraphicDriver);
f42753ed 732 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
733 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
734 ViewerTest_DefaultBackground.GradientColor2,
735 ViewerTest_DefaultBackground.FillMethod);
18d715bd 736 }
737
738 // AIS context setup
739 if (ViewerTest::GetAISContext().IsNull() ||
740 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
741 {
e79a94b9 742 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
18d715bd 743 ViewerTest::SetAISContext (aContext);
744 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
745 }
746 else
e79a94b9 747 {
18d715bd 748 ViewerTest::ResetEventManager();
e79a94b9 749 }
18d715bd 750
751 // Create window
e79a94b9 752#if defined(_WIN32)
753 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
754 Handle(WNT_WClass)::DownCast (WClass()),
62e1beed 755 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
e79a94b9 756 aPxLeft, aPxTop,
757 aPxWidth, aPxHeight,
758 Quantity_NOC_BLACK);
4fe56619 759#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
e79a94b9 760 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
761 aPxLeft, aPxTop,
762 aPxWidth, aPxHeight);
763 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
7fd59977 764#else
e79a94b9 765 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
766 aTitle.ToCString(),
767 aPxLeft, aPxTop,
768 aPxWidth, aPxHeight);
7fd59977 769#endif
18d715bd 770 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
7fd59977 771
d09dda09 772 // View setup
9e04ccdc 773 Handle(V3d_View) aView;
774 if (!theViewToClone.IsNull())
775 {
2e93433e 776 aView = new ViewerTest_V3dView (a3DViewer, theViewToClone);
9e04ccdc 777 }
778 else
779 {
2e93433e 780 aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView());
9e04ccdc 781 }
782
d09dda09 783 aView->SetWindow (VT_GetWindow());
c3282ec1 784 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
4269bd1b 785
18d715bd 786 ViewerTest::CurrentView(aView);
787 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
7fd59977 788
18d715bd 789 // Setup for X11 or NT
790 OSWindowSetup();
7fd59977 791
18d715bd 792 // Set parameters for V3d_View and V3d_Viewer
793 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
794 aV3dView->SetComputedMode(Standard_False);
7fd59977 795
18d715bd 796 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
797 if (toCreateViewer)
798 {
7fd59977 799 a3DViewer->SetDefaultLights();
800 a3DViewer->SetLightOn();
18d715bd 801 }
7fd59977 802
e79a94b9 803 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
4fe56619 804 #if TCL_MAJOR_VERSION < 8
18d715bd 805 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 806 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
4fe56619 807 #else
18d715bd 808 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 809 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
4fe56619 810 #endif
811 #endif
7fd59977 812
7fd59977 813 VT_GetWindow()->Map();
4269bd1b 814
18d715bd 815 // Set the handle of created view in the event manager
816 ViewerTest::ResetEventManager();
817
4fe56619 818 ViewerTest::CurrentView()->Redraw();
18d715bd 819
820 aView.Nullify();
821 a3DViewer.Nullify();
18d715bd 822
823 return aViewNames.GetViewName();
824}
825
826//==============================================================================
4269bd1b 827//function : RedrawAllViews
828//purpose : Redraw all created views
829//==============================================================================
830void ViewerTest::RedrawAllViews()
831{
832 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
833 for (; aViewIt.More(); aViewIt.Next())
834 {
835 const Handle(V3d_View)& aView = aViewIt.Key2();
836 aView->Redraw();
837 }
838}
839
840//==============================================================================
7fd59977 841//function : Vinit
842//purpose : Create the window viewer and initialize all the global variable
e79a94b9 843// Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
7fd59977 844//==============================================================================
845
18d715bd 846static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 847{
e79a94b9 848 TCollection_AsciiString aViewName, aDisplayName;
849 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
9e04ccdc 850 Handle(V3d_View) aCopyFrom;
e79a94b9 851 TCollection_AsciiString aName, aValue;
2e93433e 852 int is2dMode = -1;
e79a94b9 853 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
18d715bd 854 {
e79a94b9 855 const TCollection_AsciiString anArg = theArgVec[anArgIt];
856 TCollection_AsciiString anArgCase = anArg;
fd3f6bd0 857 anArgCase.LowerCase();
858 if (anArgIt + 1 < theArgsNb
859 && anArgCase == "-name")
860 {
861 aViewName = theArgVec[++anArgIt];
862 }
863 else if (anArgIt + 1 < theArgsNb
864 && (anArgCase == "-left"
865 || anArgCase == "-l"))
866 {
867 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
868 }
869 else if (anArgIt + 1 < theArgsNb
870 && (anArgCase == "-top"
871 || anArgCase == "-t"))
872 {
873 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
874 }
875 else if (anArgIt + 1 < theArgsNb
876 && (anArgCase == "-width"
877 || anArgCase == "-w"))
878 {
879 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
880 }
881 else if (anArgIt + 1 < theArgsNb
882 && (anArgCase == "-height"
883 || anArgCase == "-h"))
18d715bd 884 {
fd3f6bd0 885 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
886 }
887 else if (anArgCase == "-exitonclose")
888 {
889 Draw_ToExitOnCloseView = true;
890 if (anArgIt + 1 < theArgsNb
891 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToExitOnCloseView))
892 {
893 ++anArgIt;
894 }
895 }
896 else if (anArgCase == "-closeonescape"
897 || anArgCase == "-closeonesc")
898 {
899 Draw_ToCloseViewOnEsc = true;
900 if (anArgIt + 1 < theArgsNb
901 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToCloseViewOnEsc))
902 {
903 ++anArgIt;
904 }
905 }
2e93433e 906 else if (anArgCase == "-2d_mode"
907 || anArgCase == "-2dmode"
908 || anArgCase == "-2d")
909 {
910 bool toEnable = true;
911 if (anArgIt + 1 < theArgsNb
912 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable))
913 {
914 ++anArgIt;
915 }
916 is2dMode = toEnable ? 1 : 0;
917 }
fd3f6bd0 918 else if (anArgIt + 1 < theArgsNb
919 && (anArgCase == "-disp"
920 || anArgCase == "-display"))
921 {
922 aDisplayName = theArgVec[++anArgIt];
923 }
9e04ccdc 924 else if (!ViewerTest::CurrentView().IsNull()
925 && aCopyFrom.IsNull()
926 && (anArgCase == "-copy"
927 || anArgCase == "-clone"
928 || anArgCase == "-cloneactive"
929 || anArgCase == "-cloneactiveview"))
930 {
931 aCopyFrom = ViewerTest::CurrentView();
932 }
fd3f6bd0 933 // old syntax
934 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
935 {
936 aName.LowerCase();
937 if (aName == "name")
18d715bd 938 {
939 aViewName = aValue;
940 }
fd3f6bd0 941 else if (aName == "l"
942 || aName == "left")
e79a94b9 943 {
18d715bd 944 aPxLeft = aValue.IntegerValue();
e79a94b9 945 }
fd3f6bd0 946 else if (aName == "t"
947 || aName == "top")
e79a94b9 948 {
18d715bd 949 aPxTop = aValue.IntegerValue();
e79a94b9 950 }
fd3f6bd0 951 else if (aName == "disp"
952 || aName == "display")
e79a94b9 953 {
18d715bd 954 aDisplayName = aValue;
e79a94b9 955 }
fd3f6bd0 956 else if (aName == "w"
957 || aName == "width")
e79a94b9 958 {
18d715bd 959 aPxWidth = aValue.IntegerValue();
e79a94b9 960 }
fd3f6bd0 961 else if (aName == "h"
962 || aName == "height")
e79a94b9 963 {
18d715bd 964 aPxHeight = aValue.IntegerValue();
e79a94b9 965 }
18d715bd 966 else
967 {
fd3f6bd0 968 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
969 return 1;
18d715bd 970 }
971 }
e79a94b9 972 else if (aViewName.IsEmpty())
973 {
974 aViewName = anArg;
975 }
976 else
977 {
fd3f6bd0 978 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
979 return 1;
e79a94b9 980 }
18d715bd 981 }
982
fd3f6bd0 983#if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
984 if (!aDisplayName.IsEmpty())
985 {
986 aDisplayName.Clear();
987 std::cout << "Warning: display parameter will be ignored.\n";
988 }
989#endif
990
18d715bd 991 ViewerTest_Names aViewNames (aViewName);
e79a94b9 992 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
18d715bd 993 {
e79a94b9 994 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
995 theDi.Eval (aCommand.ToCString());
2e93433e 996 if (is2dMode != -1)
997 {
998 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
999 }
18d715bd 1000 return 0;
1001 }
1002
1003 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
9e04ccdc 1004 aViewName, aDisplayName, aCopyFrom);
2e93433e 1005 if (is2dMode != -1)
1006 {
1007 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
1008 }
e79a94b9 1009 theDi << aViewId;
7fd59977 1010 return 0;
1011}
1012
1eeef710 1013//! Parse HLR algo type.
1014static Standard_Boolean parseHlrAlgoType (const char* theName,
1015 Prs3d_TypeOfHLR& theType)
1016{
1017 TCollection_AsciiString aName (theName);
1018 aName.LowerCase();
1019 if (aName == "polyalgo")
1020 {
1021 theType = Prs3d_TOH_PolyAlgo;
1022 }
1023 else if (aName == "algo")
1024 {
1025 theType = Prs3d_TOH_Algo;
1026 }
1027 else
1028 {
1029 return Standard_False;
1030 }
1031 return Standard_True;
1032}
1033
7fd59977 1034//==============================================================================
0a768f56 1035//function : VHLR
1036//purpose : hidden lines removal algorithm
1037//==============================================================================
1038
1039static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1040{
1eeef710 1041 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1042 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1043 if (aView.IsNull())
0a768f56 1044 {
1eeef710 1045 std::cerr << "Error: No opened viewer!\n";
0a768f56 1046 return 1;
1047 }
1048
1eeef710 1049 Standard_Boolean hasHlrOnArg = Standard_False;
1050 Standard_Boolean hasShowHiddenArg = Standard_False;
1051 Standard_Boolean isHLROn = Standard_False;
1052 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
1053 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1054 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1055 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
0a768f56 1056 {
1eeef710 1057 TCollection_AsciiString anArg (argv[anArgIter]);
1058 anArg.LowerCase();
1059 if (anUpdateTool.parseRedrawMode (anArg))
1060 {
1061 continue;
1062 }
1063 else if (anArg == "-showhidden"
1064 && anArgIter + 1 < argc
1065 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
1066 {
1067 ++anArgIter;
1068 hasShowHiddenArg = Standard_True;
1069 continue;
1070 }
1071 else if ((anArg == "-type"
1072 || anArg == "-algo"
1073 || anArg == "-algotype")
1074 && anArgIter + 1 < argc
1075 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1076 {
1077 ++anArgIter;
1078 continue;
1079 }
1080 else if (!hasHlrOnArg
1081 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
1082 {
1083 hasHlrOnArg = Standard_True;
1084 continue;
1085 }
1086 // old syntax
1087 else if (!hasShowHiddenArg
1088 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
1089 {
1090 hasShowHiddenArg = Standard_True;
1091 continue;
1092 }
1093 else
1094 {
1095 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
1096 return 1;
1097 }
0a768f56 1098 }
1eeef710 1099 if (!hasHlrOnArg)
0a768f56 1100 {
1eeef710 1101 di << "HLR: " << aView->ComputedMode() << "\n";
1102 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
1103 di << "HlrAlgo: ";
1104 switch (aCtx->DefaultDrawer()->TypeOfHLR())
1105 {
1106 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
1107 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
1108 case Prs3d_TOH_Algo: di << "Algo\n"; break;
1109 }
1110 anUpdateTool.Invalidate();
1111 return 0;
0a768f56 1112 }
1113
1eeef710 1114 Standard_Boolean toRecompute = Standard_False;
1115 if (aTypeOfHLR != Prs3d_TOH_NotSet
1116 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
e9224045 1117 {
1eeef710 1118 toRecompute = Standard_True;
1119 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1120 }
1121 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
1122 {
1123 toRecompute = Standard_True;
1124 if (toShowHidden)
e9224045 1125 {
1eeef710 1126 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
e9224045 1127 }
1128 else
1129 {
1eeef710 1130 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
e9224045 1131 }
1eeef710 1132 }
e9224045 1133
1eeef710 1134 // redisplay shapes
1135 if (aView->ComputedMode() && isHLROn && toRecompute)
1136 {
1137 AIS_ListOfInteractive aListOfShapes;
1138 aCtx->DisplayedObjects (aListOfShapes);
1139 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
e9224045 1140 {
1eeef710 1141 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
e9224045 1142 {
1eeef710 1143 aCtx->Redisplay (aShape, Standard_False);
e9224045 1144 }
1145 }
1146 }
0a768f56 1147
1eeef710 1148 aView->SetComputedMode (isHLROn);
0a768f56 1149 return 0;
1150}
1151
1152//==============================================================================
1153//function : VHLRType
1154//purpose : change type of using HLR algorithm
1155//==============================================================================
1156
1eeef710 1157static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
0a768f56 1158{
1eeef710 1159 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1160 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1161 if (aView.IsNull())
0a768f56 1162 {
1eeef710 1163 std::cerr << "Error: No opened viewer!\n";
0a768f56 1164 return 1;
1165 }
1166
1eeef710 1167 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1168 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1169 AIS_ListOfInteractive aListOfShapes;
1170 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
0a768f56 1171 {
1eeef710 1172 TCollection_AsciiString anArg (argv[anArgIter]);
1173 anArg.LowerCase();
1174 if (anUpdateTool.parseRedrawMode (anArg))
0a768f56 1175 {
1eeef710 1176 continue;
0a768f56 1177 }
1eeef710 1178 else if ((anArg == "-type"
1179 || anArg == "-algo"
1180 || anArg == "-algotype")
1181 && anArgIter + 1 < argc
1182 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1183 {
1184 ++anArgIter;
1185 continue;
1186 }
1187 // old syntax
1188 else if (aTypeOfHLR == Prs3d_TOH_NotSet
1189 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
1190 {
1191 continue;
1192 }
1193 else
0a768f56 1194 {
1195 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1eeef710 1196 TCollection_AsciiString aName (argv[anArgIter]);
0a768f56 1197 if (!aMap.IsBound2 (aName))
1198 {
1eeef710 1199 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
1200 return 1;
0a768f56 1201 }
1eeef710 1202
1203 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
1204 if (aShape.IsNull())
1205 {
1206 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
1207 return 1;
1208 }
1209 aListOfShapes.Append (aShape);
1210 continue;
0a768f56 1211 }
1eeef710 1212 }
1213 if (aTypeOfHLR == Prs3d_TOH_NotSet)
1214 {
1215 std::cout << "Syntax error: wrong number of arguments!\n";
1216 return 1;
1217 }
1218
1219 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
1220 if (isGlobal)
1221 {
1222 aCtx->DisplayedObjects (aListOfShapes);
1223 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
0a768f56 1224 }
1225
1eeef710 1226 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
1227 {
1228 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1229 if (aShape.IsNull())
1230 {
1231 continue;
1232 }
1233
1234 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
1235 && aView->ComputedMode();
1236 if (!isGlobal
1237 || aShape->TypeOfHLR() != aTypeOfHLR)
1238 {
1239 aShape->SetTypeOfHLR (aTypeOfHLR);
1240 }
1241 if (toUpdateShape)
1242 {
1243 aCtx->Redisplay (aShape, Standard_False);
1244 }
1245 }
0a768f56 1246 return 0;
1247}
1248
1249//==============================================================================
18d715bd 1250//function : FindViewIdByWindowHandle
1251//purpose : Find theView Id in the map of views by window handle
1252//==============================================================================
1253#if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1254TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
1255{
1256 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
1257 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1258 {
1259 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
1260 if (aWindowHandle == theWindowHandle)
1261 return anIter.Key1();
1262 }
1263 return TCollection_AsciiString("");
1264}
1265#endif
1266
1267//==============================================================================
1268//function : ActivateView
1269//purpose : Make the view active
1270//==============================================================================
1271
1272void ActivateView (const TCollection_AsciiString& theViewName)
1273{
1274 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1275 if (!aView.IsNull())
1276 {
1277 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1278 if (!anAISContext.IsNull())
1279 {
1280 if (!ViewerTest::CurrentView().IsNull())
1281 {
1282 TCollection_AsciiString aTitle("3D View - ");
1283 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1284 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1285 }
1286
1287 ViewerTest::CurrentView (aView);
18d715bd 1288 ViewerTest::SetAISContext (anAISContext);
1eeef710 1289 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)";
18d715bd 1290 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1eeef710 1291#if defined(_WIN32)
18d715bd 1292 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1293#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1294 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1295#else
1296 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1297#endif
1298 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1299 ViewerTest::CurrentView()->Redraw();
1300 }
1301 }
1302}
1303
1304//==============================================================================
1305//function : RemoveView
0e93d9e5 1306//purpose :
1307//==============================================================================
1308void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1309 const Standard_Boolean theToRemoveContext)
1310{
1311 if (!ViewerTest_myViews.IsBound2 (theView))
1312 {
1313 return;
1314 }
1315
1316 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1317 RemoveView (aViewName, theToRemoveContext);
1318}
1319
1320//==============================================================================
1321//function : RemoveView
18d715bd 1322//purpose : Close and remove view from display, clear maps if neccessary
1323//==============================================================================
1324void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1325{
1326 if (!ViewerTest_myViews.IsBound1(theViewName))
1327 {
1328 cout << "Wrong view name\n";
1329 return;
1330 }
1331
1332 // Activate another view if it's active now
1333 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1334 {
1335 if (ViewerTest_myViews.Extent() > 1)
1336 {
1337 TCollection_AsciiString aNewViewName;
c48e2889 1338 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1339 anIter.More(); anIter.Next())
1340 {
18d715bd 1341 if (anIter.Key1() != theViewName)
1342 {
1343 aNewViewName = anIter.Key1();
1344 break;
1345 }
c48e2889 1346 }
1347 ActivateView (aNewViewName);
18d715bd 1348 }
1349 else
1350 {
1351 Handle(V3d_View) anEmptyView;
1352#if defined(_WIN32) || defined(__WIN32__)
1353 Handle(WNT_Window) anEmptyWindow;
1354#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1355 Handle(Cocoa_Window) anEmptyWindow;
1356#else
1357 Handle(Xw_Window) anEmptyWindow;
1358#endif
1359 VT_GetWindow() = anEmptyWindow;
1360 ViewerTest::CurrentView (anEmptyView);
1361 if (isContextRemoved)
1362 {
1363 Handle(AIS_InteractiveContext) anEmptyContext;
1364 ViewerTest::SetAISContext(anEmptyContext);
1365 }
1366 }
1367 }
1368
1369 // Delete view
1370 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1371 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1372
1373 // Remove view resources
18d715bd 1374 ViewerTest_myViews.UnBind1(theViewName);
851dacdb 1375 aView->Window()->Unmap();
18d715bd 1376 aView->Remove();
1377
1378#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1379 XFlush (GetDisplayConnection()->GetDisplay());
1380#endif
1381
1382 // Keep context opened only if the closed view is last to avoid
1383 // unused empty contexts
1384 if (!aCurrentContext.IsNull())
1385 {
1386 // Check if there are more difined views in the viewer
1387 aCurrentContext->CurrentViewer()->InitDefinedViews();
1388 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1389 {
1390 // Remove driver if there is no viewers that use it
1391 Standard_Boolean isRemoveDriver = Standard_True;
1392 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1393 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1394 {
1395 if (aCurrentContext != anIter.Key2() &&
1396 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1397 {
1398 isRemoveDriver = Standard_False;
1399 break;
1400 }
1401 }
2ec85268 1402
1403 aCurrentContext->RemoveAll (Standard_False);
18d715bd 1404 if(isRemoveDriver)
1405 {
1406 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1407 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1408 #if TCL_MAJOR_VERSION < 8
1409 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1410 #else
1411 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1412 #endif
1413 #endif
1414 }
1415
1416 ViewerTest_myContexts.UnBind2(aCurrentContext);
1417 }
1418 }
1419 cout << "3D View - " << theViewName << " was deleted.\n";
fd3f6bd0 1420 if (Draw_ToExitOnCloseView)
1421 {
1422 Draw_Interprete ("exit");
1423 }
18d715bd 1424}
1425
1426//==============================================================================
1427//function : VClose
1428//purpose : Remove the view defined by its name
1429//==============================================================================
1430
d0cc1cb7 1431static int VClose (Draw_Interpretor& /*theDi*/,
1432 Standard_Integer theArgsNb,
1433 const char** theArgVec)
18d715bd 1434{
18d715bd 1435 NCollection_List<TCollection_AsciiString> aViewList;
d0cc1cb7 1436 if (theArgsNb > 1)
18d715bd 1437 {
d0cc1cb7 1438 TCollection_AsciiString anArg (theArgVec[1]);
1439 anArg.UpperCase();
1440 if (anArg.IsEqual ("ALL")
1441 || anArg.IsEqual ("*"))
1442 {
1443 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1444 anIter.More(); anIter.Next())
1445 {
1446 aViewList.Append (anIter.Key1());
1447 }
1448 if (aViewList.IsEmpty())
1449 {
1450 std::cout << "No view to close\n";
1451 return 0;
1452 }
1453 }
1454 else
18d715bd 1455 {
d0cc1cb7 1456 ViewerTest_Names aViewName (theArgVec[1]);
1457 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1458 {
1459 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1460 return 1;
1461 }
1462 aViewList.Append (aViewName.GetViewName());
18d715bd 1463 }
1464 }
1465 else
1466 {
d0cc1cb7 1467 // close active view
1468 if (ViewerTest::CurrentView().IsNull())
1469 {
1470 std::cerr << "No active view!\n";
1471 return 1;
1472 }
1473 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
18d715bd 1474 }
1475
d0cc1cb7 1476 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
18d715bd 1477 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1478 anIter.More(); anIter.Next())
1479 {
d0cc1cb7 1480 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
18d715bd 1481 }
1482
1483 return 0;
1484}
1485
1486//==============================================================================
1487//function : VActivate
1488//purpose : Activate the view defined by its ID
1489//==============================================================================
1490
1491static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1492{
1493 if (theArgsNb > 2)
1494 {
1495 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1496 << "Usage: " << theArgVec[0] << " ViewID\n";
1497 return 1;
1498 }
1499 if(theArgsNb == 1)
1500 {
1501 theDi.Eval("vviewlist");
1502 return 0;
1503 }
1504
1505 TCollection_AsciiString aNameString(theArgVec[1]);
29cb310a 1506 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
18d715bd 1507 {
1508 TCollection_AsciiString aTitle("3D View - ");
1509 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1510 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1511 Handle(V3d_View) anEmptyView;
1512#if defined(_WIN32) || defined(__WIN32__)
1513 Handle(WNT_Window) anEmptyWindow;
1514#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1515 Handle(Cocoa_Window) anEmptyWindow;
1516#else
1517 Handle(Xw_Window) anEmptyWindow;
1518#endif
1519 VT_GetWindow() = anEmptyWindow;
1520 ViewerTest::CurrentView (anEmptyView);
1521 ViewerTest::ResetEventManager();
1522 theDi << theArgVec[0] << ": all views are inactive\n";
1523 return 0;
1524 }
1525
1526 ViewerTest_Names aViewNames(aNameString);
1527
1528 // Check if this view exists in the viewer with the driver
1529 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1530 {
1531 theDi << "Wrong view name\n";
1532 return 1;
1533 }
1534
1535 // Check if it is active already
1536 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1537 {
1538 theDi << theArgVec[0] << ": the view is active already\n";
1539 return 0;
1540 }
1541
1542 ActivateView (aViewNames.GetViewName());
1543 return 0;
1544}
1545
1546//==============================================================================
1547//function : VViewList
1548//purpose : Print current list of views per viewer and graphic driver ID
1549// shared between viewers
1550//==============================================================================
1551
1552static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1553{
1554 if (theArgsNb > 2)
1555 {
1556 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
29cb310a 1557 << "Usage: " << theArgVec[0] << " name";
18d715bd 1558 return 1;
1559 }
1560 if (ViewerTest_myContexts.Size() < 1)
1561 return 0;
1562
18d715bd 1563 Standard_Boolean isTreeView =
29cb310a 1564 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
18d715bd 1565
1566 if (isTreeView)
c48e2889 1567 {
18d715bd 1568 theDi << theArgVec[0] <<":\n";
c48e2889 1569 }
18d715bd 1570
c48e2889 1571 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
1572 aDriverIter.More(); aDriverIter.Next())
1573 {
1574 if (isTreeView)
1575 theDi << aDriverIter.Key1() << ":\n";
18d715bd 1576
c48e2889 1577 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1578 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1579 {
1580 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
18d715bd 1581 {
c48e2889 1582 if (isTreeView)
18d715bd 1583 {
c48e2889 1584 TCollection_AsciiString aContextName(aContextIter.Key1());
1585 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1586 }
18d715bd 1587
c48e2889 1588 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
1589 aViewIter.More(); aViewIter.Next())
1590 {
1591 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
18d715bd 1592 {
c48e2889 1593 TCollection_AsciiString aViewName(aViewIter.Key1());
1594 if (isTreeView)
18d715bd 1595 {
c48e2889 1596 if (aViewIter.Value() == ViewerTest::CurrentView())
1597 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
18d715bd 1598 else
c48e2889 1599 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1600 }
1601 else
1602 {
1603 theDi << aViewName << " ";
18d715bd 1604 }
1605 }
1606 }
1607 }
1608 }
c48e2889 1609 }
18d715bd 1610 return 0;
1611}
1612
1613//==============================================================================
4fe56619 1614//function : VT_ProcessKeyPress
7fd59977 1615//purpose : Handle KeyPress event from a CString
1616//==============================================================================
4fe56619 1617void VT_ProcessKeyPress (const char* buf_ret)
7fd59977 1618{
1619 //cout << "KeyPress" << endl;
1620 const Handle(V3d_View) aView = ViewerTest::CurrentView();
7fd59977 1621 // Letter in alphabetic order
1622
2e93433e 1623 if (!strcasecmp (buf_ret, "A")
1624 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1625 {
7fd59977 1626 // AXO
1627 aView->SetProj(V3d_XposYnegZpos);
1628 }
2e93433e 1629 else if (!strcasecmp (buf_ret, "D")
1630 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1631 {
7fd59977 1632 // Reset
1633 aView->Reset();
1634 }
b514beda 1635 else if (!strcasecmp (buf_ret, "F"))
1636 {
b586500b 1637 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1638 {
1639 ViewerTest::GetAISContext()->FitSelected (aView);
1640 }
1641 else
1642 {
1643 // FitAll
1644 aView->FitAll();
1645 }
7fd59977 1646 }
b514beda 1647 else if (!strcasecmp (buf_ret, "H"))
1648 {
7fd59977 1649 // HLR
1eeef710 1650 std::cout << "HLR" << std::endl;
de75ed09 1651 aView->SetComputedMode (!aView->ComputedMode());
1eeef710 1652 aView->Redraw();
7fd59977 1653 }
b514beda 1654 else if (!strcasecmp (buf_ret, "P"))
1655 {
0a768f56 1656 // Type of HLR
1657 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1658 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1659 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1660 else
1661 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
c3282ec1 1662 if (aContext->NbSelected()==0)
0a768f56 1663 {
1664 AIS_ListOfInteractive aListOfShapes;
1665 aContext->DisplayedObjects(aListOfShapes);
1666 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1667 anIter.More(); anIter.Next())
1668 {
1669 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1670 if (aShape.IsNull())
1671 continue;
1672 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1673 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1674 else
1675 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
36132a2e 1676 aContext->Redisplay (aShape, Standard_False);
0a768f56 1677 }
1678 }
1679 else
1680 {
c3282ec1 1681 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
0a768f56 1682 {
c3282ec1 1683 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
0a768f56 1684 if (aShape.IsNull())
1685 continue;
1686 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1687 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1688 else
1689 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
36132a2e 1690 aContext->Redisplay (aShape, Standard_False);
0a768f56 1691 }
1692 }
1693
1694 aContext->UpdateCurrentViewer();
4269bd1b 1695
0a768f56 1696 }
b514beda 1697 else if (!strcasecmp (buf_ret, "S"))
1698 {
1699 std::cout << "setup Shaded display mode" << std::endl;
4fe56619 1700
7fd59977 1701 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
c3282ec1 1702 if(Ctx->NbSelected()==0)
0577ae8c 1703 Ctx->SetDisplayMode (AIS_Shaded, Standard_True);
7fd59977 1704 else{
c3282ec1 1705 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1706 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
7fd59977 1707 Ctx->UpdateCurrentViewer();
1708 }
1709 }
b514beda 1710 else if (!strcasecmp (buf_ret, "U"))
1711 {
41811896 1712 // Unset display mode
b514beda 1713 std::cout << "reset display mode to defaults" << std::endl;
4fe56619 1714
7fd59977 1715 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
c3282ec1 1716 if(Ctx->NbSelected()==0)
0577ae8c 1717 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
7fd59977 1718 else{
c3282ec1 1719 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1720 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
7fd59977 1721 Ctx->UpdateCurrentViewer();
1722 }
1723
1724 }
2e93433e 1725 else if (!strcasecmp (buf_ret, "T")
1726 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1727 {
7fd59977 1728 // Top
1729 aView->SetProj(V3d_Zpos);
1730 }
2e93433e 1731 else if (!strcasecmp (buf_ret, "B")
1732 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1733 {
41811896 1734 // Bottom
7fd59977 1735 aView->SetProj(V3d_Zneg);
1736 }
2e93433e 1737 else if (!strcasecmp (buf_ret, "L")
1738 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1739 {
41811896 1740 // Left
7fd59977 1741 aView->SetProj(V3d_Xneg);
1742 }
2e93433e 1743 else if (!strcasecmp (buf_ret, "R")
1744 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1745 {
41811896 1746 // Right
7fd59977 1747 aView->SetProj(V3d_Xpos);
1748 }
b514beda 1749 else if (!strcasecmp (buf_ret, "W"))
1750 {
1751 std::cout << "setup WireFrame display mode" << std::endl;
7fd59977 1752 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
c3282ec1 1753 if(Ctx->NbSelected()==0)
0577ae8c 1754 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
7fd59977 1755 else{
c3282ec1 1756 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1757 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
7fd59977 1758 Ctx->UpdateCurrentViewer();
1759 }
1760 }
b514beda 1761 else if (!strcasecmp (buf_ret, ","))
1762 {
7fd59977 1763 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
7fd59977 1764 }
b514beda 1765 else if (!strcasecmp (buf_ret, "."))
1766 {
7fd59977 1767 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1768 }
f978241f 1769 else if (!strcasecmp (buf_ret, "/"))
1770 {
1771 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1772 if (aCamera->IsStereo())
1773 {
1774 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1775 aView->Redraw();
1776 }
1777 }
1778 else if (!strcasecmp (buf_ret, "*"))
1779 {
1780 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1781 if (aCamera->IsStereo())
1782 {
1783 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1784 aView->Redraw();
1785 }
1786 }
b514beda 1787 else if (*buf_ret == THE_KEY_DELETE)
1788 {
1789 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1790 if (!aCtx.IsNull()
b514beda 1791 && aCtx->NbSelected() > 0)
1792 {
1793 Draw_Interprete ("verase");
1794 }
1795 }
fd3f6bd0 1796 else if (*buf_ret == THE_KEY_ESCAPE)
1797 {
1798 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1799 if (!aCtx.IsNull()
1800 && Draw_ToCloseViewOnEsc)
1801 {
1802 Draw_Interprete (Draw_ToExitOnCloseView ? "exit" : "vclose");
1803 }
1804 }
b514beda 1805 else
1806 {
1807 // Number
8c088c52 1808 const Standard_Integer aSelMode = Draw::Atoi(buf_ret);
1809 if (aSelMode >= 0 && aSelMode <= 7)
1810 {
1811 bool toEnable = true;
1812 if (const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext())
1813 {
1814 AIS_ListOfInteractive aPrsList;
1815 aCtx->DisplayedObjects (aPrsList);
1816 for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More() && toEnable; aPrsIter.Next())
1817 {
1818 TColStd_ListOfInteger aModes;
1819 aCtx->ActivatedModes (aPrsIter.Value(), aModes);
1820 for (TColStd_ListOfInteger::Iterator aModeIter (aModes); aModeIter.More() && toEnable; aModeIter.Next())
1821 {
1822 if (aModeIter.Value() == aSelMode)
1823 {
1824 toEnable = false;
1825 }
1826 }
1827 }
1828 }
1829 TCollection_AsciiString aCmd = TCollection_AsciiString ("vselmode ") + aSelMode + (toEnable ? " 1" : " 0");
1830 Draw_Interprete (aCmd.ToCString());
1831 }
7fd59977 1832 }
1833}
1834
1835//==============================================================================
4fe56619 1836//function : VT_ProcessExpose
7fd59977 1837//purpose : Redraw the View on an Expose Event
1838//==============================================================================
4fe56619 1839void VT_ProcessExpose()
1840{
1841 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1842 if (!aView3d.IsNull())
1843 {
1844 aView3d->Redraw();
1845 }
7fd59977 1846}
1847
1848//==============================================================================
4fe56619 1849//function : VT_ProcessConfigure
7fd59977 1850//purpose : Resize the View on an Configure Event
1851//==============================================================================
4fe56619 1852void VT_ProcessConfigure()
7fd59977 1853{
4fe56619 1854 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1855 if (aView3d.IsNull())
1856 {
1857 return;
1858 }
1859
1860 aView3d->MustBeResized();
1861 aView3d->Update();
1862 aView3d->Redraw();
7fd59977 1863}
1864
1865//==============================================================================
4fe56619 1866//function : VT_ProcessButton1Press
7fd59977 1867//purpose : Picking
1868//==============================================================================
e79a94b9 1869Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1870 const char** theArgVec,
1871 Standard_Boolean theToPick,
1872 Standard_Boolean theIsShift)
7fd59977 1873{
1beb58d7 1874 if (TheIsAnimating)
1875 {
1876 TheIsAnimating = Standard_False;
1877 return Standard_False;
1878 }
1879
e79a94b9 1880 if (theToPick)
1881 {
7fd59977 1882 Standard_Real X, Y, Z;
e79a94b9 1883 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
7fd59977 1884
e79a94b9 1885 Draw::Set (theArgVec[1], X);
1886 Draw::Set (theArgVec[2], Y);
1887 Draw::Set (theArgVec[3], Z);
1888 }
7fd59977 1889
e79a94b9 1890 if (theIsShift)
1891 {
1892 ViewerTest::CurrentEventManager()->ShiftSelect();
1893 }
7fd59977 1894 else
e79a94b9 1895 {
1896 ViewerTest::CurrentEventManager()->Select();
1897 }
7fd59977 1898
e79a94b9 1899 return Standard_False;
7fd59977 1900}
1901
1902//==============================================================================
4fe56619 1903//function : VT_ProcessButton1Release
1904//purpose : End selecting
7fd59977 1905//==============================================================================
4fe56619 1906void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1907{
1908 if (IsDragged)
1909 {
1910 IsDragged = Standard_False;
1911 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1912 if (theIsShift)
1913 {
2157d6ac 1914 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1915 X_Motion, Y_Motion);
4fe56619 1916 }
1917 else
1918 {
2157d6ac 1919 EM->Select (X_ButtonPress, Y_ButtonPress,
1920 X_Motion, Y_Motion);
4fe56619 1921 }
1922 }
1923}
7fd59977 1924
4fe56619 1925//==============================================================================
1926//function : VT_ProcessButton3Press
1927//purpose : Start Rotation
1928//==============================================================================
1929void VT_ProcessButton3Press()
1930{
2e93433e 1931 if (ViewerTest_V3dView::IsCurrentViewIn2DMode())
1932 {
1933 return;
1934 }
1935
7fd59977 1936 Start_Rot = 1;
1eeef710 1937 HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode();
1938 if (HasHlrOnBeforeRotation)
de75ed09 1939 {
1940 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1941 }
7fd59977 1942 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
7fd59977 1943}
4fe56619 1944
7fd59977 1945//==============================================================================
4fe56619 1946//function : VT_ProcessButton3Release
1947//purpose : End rotation
7fd59977 1948//==============================================================================
4fe56619 1949void VT_ProcessButton3Release()
1950{
1951 if (Start_Rot)
1952 {
7fd59977 1953 Start_Rot = 0;
1eeef710 1954 if (HasHlrOnBeforeRotation)
de75ed09 1955 {
1eeef710 1956 HasHlrOnBeforeRotation = Standard_False;
de75ed09 1957 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1eeef710 1958 ViewerTest::CurrentView()->Redraw();
de75ed09 1959 }
7fd59977 1960 }
7fd59977 1961}
1962
1963//==============================================================================
7fd59977 1964//function : ProcessControlButton1Motion
1965//purpose : Zoom
1966//==============================================================================
1967
900f7229 1968#if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 1969static void ProcessControlButton1Motion()
1970{
1971 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1972
1973 X_ButtonPress = X_Motion;
1974 Y_ButtonPress = Y_Motion;
1975}
900f7229 1976#endif
7fd59977 1977
1978//==============================================================================
4fe56619 1979//function : VT_ProcessControlButton2Motion
1980//purpose : Panning
7fd59977 1981//==============================================================================
4fe56619 1982void VT_ProcessControlButton2Motion()
7fd59977 1983{
197ac94e 1984 Standard_Integer aDx = X_Motion - X_ButtonPress;
1985 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
7fd59977 1986
197ac94e 1987 aDy = -aDy; // Xwindow Y axis is from top to Bottom
7fd59977 1988
197ac94e 1989 ViewerTest::CurrentView()->Pan (aDx, aDy);
7fd59977 1990
1991 X_ButtonPress = X_Motion;
1992 Y_ButtonPress = Y_Motion;
1993}
1994
1995//==============================================================================
4fe56619 1996//function : VT_ProcessControlButton3Motion
7fd59977 1997//purpose : Rotation
1998//==============================================================================
4fe56619 1999void VT_ProcessControlButton3Motion()
7fd59977 2000{
4fe56619 2001 if (Start_Rot)
2002 {
2003 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
2004 }
7fd59977 2005}
2006
2007//==============================================================================
4fe56619 2008//function : VT_ProcessMotion
2009//purpose :
7fd59977 2010//==============================================================================
4fe56619 2011void VT_ProcessMotion()
7fd59977 2012{
2013 //pre-hilights detected objects at mouse position
2014
2015 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
2016 EM->MoveTo(X_Motion, Y_Motion);
2017}
2018
2019
2020void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
2021{
2022 Xpix = X_Motion;Ypix=Y_Motion;
2023}
2024
2025//==============================================================================
44b8f2d6 2026//function : ViewProject: implements VAxo, VTop, VLeft, ...
2027//purpose : Switches to an axonometric, top, left and other views
2028//==============================================================================
2029
2030static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
2031{
4fe56619 2032 if ( ViewerTest::CurrentView().IsNull() )
44b8f2d6 2033 {
586db386 2034 di<<"Call vinit before this command, please\n";
44b8f2d6 2035 return 1;
2036 }
2037
2038 ViewerTest::CurrentView()->SetProj(ori);
2039 return 0;
2040}
2041
2042//==============================================================================
7fd59977 2043//function : VAxo
2044//purpose : Switch to an Axonometric view
2045//Draw arg : No args
2046//==============================================================================
2047
2048static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
44b8f2d6 2049{
2050 return ViewProject(di, V3d_XposYnegZpos);
7fd59977 2051}
2052
2053//==============================================================================
2054//function : VTop
2055//purpose : Switch to a Top View
2056//Draw arg : No args
2057//==============================================================================
2058
2059static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
2060{
44b8f2d6 2061 return ViewProject(di, V3d_Zpos);
2062}
7fd59977 2063
44b8f2d6 2064//==============================================================================
2065//function : VBottom
2066//purpose : Switch to a Bottom View
2067//Draw arg : No args
2068//==============================================================================
7fd59977 2069
44b8f2d6 2070static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
2071{
2072 return ViewProject(di, V3d_Zneg);
2073}
7fd59977 2074
44b8f2d6 2075//==============================================================================
2076//function : VLeft
2077//purpose : Switch to a Left View
2078//Draw arg : No args
2079//==============================================================================
2080
2081static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
2082{
27af3052 2083 return ViewProject(di, V3d_Xneg);
44b8f2d6 2084}
2085
2086//==============================================================================
2087//function : VRight
2088//purpose : Switch to a Right View
2089//Draw arg : No args
2090//==============================================================================
2091
2092static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
2093{
27af3052 2094 return ViewProject(di, V3d_Xpos);
44b8f2d6 2095}
7fd59977 2096
44b8f2d6 2097//==============================================================================
2098//function : VFront
2099//purpose : Switch to a Front View
2100//Draw arg : No args
2101//==============================================================================
2102
2103static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
2104{
27af3052 2105 return ViewProject(di, V3d_Yneg);
44b8f2d6 2106}
2107
2108//==============================================================================
2109//function : VBack
2110//purpose : Switch to a Back View
2111//Draw arg : No args
2112//==============================================================================
2113
2114static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
2115{
27af3052 2116 return ViewProject(di, V3d_Ypos);
7fd59977 2117}
2118
2119//==============================================================================
2120//function : VHelp
2121//purpose : Dsiplay help on viewer Keyboead and mouse commands
2122//Draw arg : No args
2123//==============================================================================
2124
2125static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
2126{
2127
586db386 2128 di << "Q : Quit the application\n";
2129
2130 di << "=========================\n";
2131 di << "F : FitAll\n";
2132 di << "T : TopView\n";
2133 di << "B : BottomView\n";
2134 di << "R : RightView\n";
2135 di << "L : LeftView\n";
2136 di << "A : AxonometricView\n";
2137 di << "D : ResetView\n";
2138
2139 di << "=========================\n";
2140 di << "S : Shading\n";
2141 di << "W : Wireframe\n";
2142 di << "H : HidelLineRemoval\n";
2143 di << "U : Unset display mode\n";
2144 di << "Delete : Remove selection from viewer\n";
2145
2146 di << "=========================\n";
2147 di << "Selection mode \n";
2148 di << "0 : Shape\n";
2149 di << "1 : Vertex\n";
2150 di << "2 : Edge\n";
2151 di << "3 : Wire\n";
2152 di << "4 : Face\n";
2153 di << "5 : Shell\n";
2154 di << "6 : Solid\n";
2155 di << "7 : Compound\n";
2156
2157 di << "=========================\n";
2158 di << "Z : Switch Z clipping On/Off\n";
2159 di << ", : Hilight next detected\n";
2160 di << ". : Hilight previous detected\n";
7fd59977 2161
2162 return 0;
2163}
2164
57c28b61 2165#ifdef _WIN32
7fd59977 2166
2167static Standard_Boolean Ppick = 0;
2168static Standard_Integer Pargc = 0;
2169static const char** Pargv = NULL;
2170
2171
2172static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
2173 UINT Msg,
2174 WPARAM wParam,
2175 LPARAM lParam )
2176{
18d715bd 2177 if (!ViewerTest_myViews.IsEmpty()) {
7fd59977 2178
2179 WPARAM fwKeys = wParam;
2180
2181 switch( Msg ) {
18d715bd 2182 case WM_CLOSE:
2183 {
2184 // Delete view from map of views
2185 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
2186 return 0;
2187 }
2188 break;
2189 case WM_ACTIVATE:
2190 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
2191 || ViewerTest::CurrentView().IsNull())
2192 {
2193 // Activate inactive window
2194 if(GetWindowHandle(VT_GetWindow()) != hwnd)
2195 {
2196 ActivateView (FindViewIdByWindowHandle(hwnd));
2197 }
2198 }
2199 break;
625e1958 2200
7fd59977 2201 case WM_LBUTTONUP:
625e1958 2202 if (IsDragged && !DragFirst)
7fd59977 2203 {
625e1958 2204 if (!GetActiveAISManipulator().IsNull())
2205 {
2206 GetActiveAISManipulator()->StopTransform();
0577ae8c 2207 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
625e1958 2208 }
2209
b12e1c7b 2210 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2211 {
2212 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2213 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2214 }
2215
dde68833 2216 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
7fd59977 2217 }
8abada55 2218 IsDragged = Standard_False;
7fd59977 2219 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2220
625e1958 2221 case WM_RBUTTONUP:
2222 if (IsDragged && !DragFirst)
2223 {
2224 if (!GetActiveAISManipulator().IsNull())
2225 {
2226 GetActiveAISManipulator()->StopTransform (Standard_False);
0577ae8c 2227 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
625e1958 2228 }
2229 IsDragged = Standard_False;
2230 }
2231 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
2232
7fd59977 2233 case WM_LBUTTONDOWN:
625e1958 2234 if (!GetActiveAISManipulator().IsNull())
2235 {
2236 IsDragged = ( fwKeys == MK_LBUTTON );
2237 }
2238 else
2239 {
2240 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
2241 }
2242
2243 if (IsDragged)
7fd59977 2244 {
7fd59977 2245 DragFirst = Standard_True;
4fe56619 2246 X_ButtonPress = LOWORD(lParam);
2247 Y_ButtonPress = HIWORD(lParam);
7fd59977 2248 }
2249 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2250
7fd59977 2251 case WM_MOUSEMOVE:
b12e1c7b 2252 if (IsDragged)
7fd59977 2253 {
b12e1c7b 2254 X_Motion = LOWORD (lParam);
2255 Y_Motion = HIWORD (lParam);
625e1958 2256 if (!GetActiveAISManipulator().IsNull())
b12e1c7b 2257 {
625e1958 2258 if (DragFirst)
2259 {
2260 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
2261 }
2262 else
2263 {
2264 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
2265 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
2266 }
69adb9ce 2267 }
625e1958 2268 else
69adb9ce 2269 {
625e1958 2270 bool toRedraw = false;
2271 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2272 {
2273 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2274 toRedraw = true;
2275 }
2276
2277 RECT aRect;
2278 if (GetClientRect (hwnd, &aRect))
2279 {
2280 int aHeight = aRect.bottom - aRect.top;
2281 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
68dcee02 2282 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
625e1958 2283 toRedraw = true;
2284 }
2285 if (toRedraw)
2286 {
2287 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2288 }
b12e1c7b 2289 }
625e1958 2290
2291 DragFirst = Standard_False;
7fd59977 2292 }
2293 else
2294 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2295 break;
2296
2297 default:
2298 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2299 }
2300 return 0;
2301 }
2302 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2303}
2304
2305
2306static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
2307 UINT Msg,
2308 WPARAM wParam,
2309 LPARAM lParam )
2310{
7fd59977 2311 static int Up = 1;
f978241f 2312 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2313 if (aView.IsNull())
2314 {
ad03c234 2315 return DefWindowProcW (hwnd, Msg, wParam, lParam);
f978241f 2316 }
7fd59977 2317
7fd59977 2318 PAINTSTRUCT ps;
2319
2320 switch( Msg ) {
7fd59977 2321 case WM_PAINT:
7fd59977 2322 BeginPaint(hwnd, &ps);
2323 EndPaint(hwnd, &ps);
4fe56619 2324 VT_ProcessExpose();
7fd59977 2325 break;
2326
2327 case WM_SIZE:
4fe56619 2328 VT_ProcessConfigure();
7fd59977 2329 break;
f978241f 2330 case WM_MOVE:
2331 case WM_MOVING:
2332 case WM_SIZING:
2333 switch (aView->RenderingParams().StereoMode)
2334 {
2335 case Graphic3d_StereoMode_RowInterlaced:
2336 case Graphic3d_StereoMode_ColumnInterlaced:
2337 case Graphic3d_StereoMode_ChessBoard:
2338 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2339 break;
2340 default:
2341 break;
2342 }
2343 break;
7fd59977 2344
2345 case WM_KEYDOWN:
4fe56619 2346 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2347 {
7fd59977 2348 char c[2];
2349 c[0] = (char) wParam;
2350 c[1] = '\0';
b514beda 2351 if (wParam == VK_DELETE)
2352 {
2353 c[0] = THE_KEY_DELETE;
2354 }
fd3f6bd0 2355 else if (wParam == VK_ESCAPE)
2356 {
2357 c[0] = THE_KEY_ESCAPE;
2358 }
4ca4bbe8 2359 // comma
2360 else if (wParam == VK_OEM_COMMA)
2361 {
2362 c[0] = ',';
2363 }
2364 // dot
2365 else if (wParam == VK_OEM_PERIOD)
2366 {
2367 c[0] = '.';
2368 }
f978241f 2369 else if (wParam == VK_DIVIDE)
2370 {
2371 c[0] = '/';
2372 }
2373 // dot
2374 else if (wParam == VK_MULTIPLY)
2375 {
2376 c[0] = '*';
2377 }
4fe56619 2378 VT_ProcessKeyPress (c);
7fd59977 2379 }
2380 break;
2381
2382 case WM_LBUTTONUP:
2383 case WM_MBUTTONUP:
2384 case WM_RBUTTONUP:
7fd59977 2385 Up = 1;
4fe56619 2386 VT_ProcessButton3Release();
7fd59977 2387 break;
2388
2389 case WM_LBUTTONDOWN:
2390 case WM_MBUTTONDOWN:
2391 case WM_RBUTTONDOWN:
2392 {
7fd59977 2393 WPARAM fwKeys = wParam;
2394
2395 Up = 0;
2396
2397 X_ButtonPress = LOWORD(lParam);
2398 Y_ButtonPress = HIWORD(lParam);
2399
4fe56619 2400 if (Msg == WM_LBUTTONDOWN)
2401 {
dde68833 2402 if ((fwKeys & MK_CONTROL) != 0)
4fe56619 2403 {
dde68833 2404 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
4fe56619 2405 }
2406 else
2407 {
dde68833 2408 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
4fe56619 2409 }
7fd59977 2410 }
4fe56619 2411 else if (Msg == WM_RBUTTONDOWN)
2412 {
7fd59977 2413 // Start rotation
4fe56619 2414 VT_ProcessButton3Press();
7fd59977 2415 }
2416 }
2417 break;
2418
f978241f 2419 case WM_MOUSEWHEEL:
2420 {
2421 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2422 if (wParam & MK_CONTROL)
2423 {
2424 if (aView->Camera()->IsStereo())
2425 {
2426 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2427 if (aFocus > 0.2
2428 && aFocus < 2.0)
2429 {
2430 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2431 aView->Redraw();
2432 }
2433 }
2434 }
2435 else
2436 {
2437 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2438 }
2439 break;
2440 }
2441
7fd59977 2442 case WM_MOUSEMOVE:
2443 {
2444 //cout << "\t WM_MOUSEMOVE" << endl;
2445 WPARAM fwKeys = wParam;
2446 X_Motion = LOWORD(lParam);
2447 Y_Motion = HIWORD(lParam);
2448
2449 if ( Up &&
dde68833 2450 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
2451 {
7fd59977 2452 Up = 0;
2453 X_ButtonPress = LOWORD(lParam);
2454 Y_ButtonPress = HIWORD(lParam);
2455
dde68833 2456 if ((fwKeys & MK_RBUTTON) != 0) {
7fd59977 2457 // Start rotation
4fe56619 2458 VT_ProcessButton3Press();
7fd59977 2459 }
2460 }
2461
dde68833 2462 if ((fwKeys & MK_CONTROL) != 0)
2463 {
2464 if ((fwKeys & MK_LBUTTON) != 0)
2465 {
7fd59977 2466 ProcessControlButton1Motion();
2467 }
dde68833 2468 else if ((fwKeys & MK_MBUTTON) != 0
2469 || ((fwKeys & MK_LBUTTON) != 0
2470 && (fwKeys & MK_RBUTTON) != 0))
2471 {
2472 VT_ProcessControlButton2Motion();
2473 }
2474 else if ((fwKeys & MK_RBUTTON) != 0)
2475 {
4fe56619 2476 VT_ProcessControlButton3Motion();
7fd59977 2477 }
2478 }
08398024 2479 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2480 {
89a929ea 2481 VT_ProcessMotion();
08398024 2482 }
7fd59977 2483 }
2484 break;
2485
2486 default:
ad03c234 2487 return DefWindowProcW (hwnd, Msg, wParam, lParam);
7fd59977 2488 }
2489 return 0L;
7fd59977 2490}
2491
7fd59977 2492//==============================================================================
2493//function : ViewerMainLoop
2494//purpose : Get a Event on the view and dispatch it
2495//==============================================================================
2496
2497
8263fcd3 2498int ViewerMainLoop(Standard_Integer argc, const char** argv)
7fd59977 2499{
7fd59977 2500 Ppick = (argc > 0)? 1 : 0;
2501 Pargc = argc;
2502 Pargv = argv;
2503
2504 if ( Ppick ) {
2505 MSG msg;
2506 msg.wParam = 1;
2507
2508 cout << "Start picking" << endl;
2509
7fd59977 2510 while ( Ppick == 1 ) {
4fe56619 2511 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
ad03c234 2512 if (GetMessageW (&msg, NULL, 0, 0))
2513 {
2514 TranslateMessage (&msg);
2515 DispatchMessageW (&msg);
7fd59977 2516 }
2517 }
2518
2519 cout << "Picking done" << endl;
2520 }
2521
2522 return Ppick;
2523}
2524
4fe56619 2525#elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 2526
2527int min( int a, int b )
2528{
2529 if( a<b )
2530 return a;
2531 else
2532 return b;
2533}
2534
2535int max( int a, int b )
2536{
2537 if( a>b )
2538 return a;
2539 else
2540 return b;
2541}
2542
2543int ViewerMainLoop(Standard_Integer argc, const char** argv)
2544
4269bd1b 2545{
18d715bd 2546 static XEvent aReport;
2547 Standard_Boolean pick = argc > 0;
2548 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2549 XNextEvent (aDisplay, &aReport);
7fd59977 2550
18d715bd 2551 // Handle event for the chosen display connection
2552 switch (aReport.type) {
2553 case ClientMessage:
2554 {
eb1ebea4 2555 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
18d715bd 2556 {
2557 // Close the window
2558 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2559 }
2560 }
2561 return 0;
2562 case FocusIn:
2563 {
2564 // Activate inactive view
2565 Window aWindow = GetWindowHandle(VT_GetWindow());
2566 if(aWindow != aReport.xfocus.window)
2567 {
2568 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2569 }
2570 }
2571 break;
7fd59977 2572 case Expose:
2573 {
4fe56619 2574 VT_ProcessExpose();
7fd59977 2575 }
2576 break;
2577 case ConfigureNotify:
2578 {
4fe56619 2579 VT_ProcessConfigure();
7fd59977 2580 }
2581 break;
2582 case KeyPress:
2583 {
2584
2585 KeySym ks_ret ;
2586 char buf_ret[11] ;
2587 int ret_len ;
2588 XComposeStatus status_in_out;
2589
18d715bd 2590 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
7fd59977 2591 (char *) buf_ret , 10 ,
2592 &ks_ret , &status_in_out ) ;
2593
2594
2595 buf_ret[ret_len] = '\0' ;
2596
4fe56619 2597 if (ret_len)
2598 {
2599 VT_ProcessKeyPress (buf_ret);
7fd59977 2600 }
2601 }
2602 break;
2603 case ButtonPress:
7fd59977 2604 {
18d715bd 2605 X_ButtonPress = aReport.xbutton.x;
2606 Y_ButtonPress = aReport.xbutton.y;
7fd59977 2607
18d715bd 2608 if (aReport.xbutton.button == Button1)
4fe56619 2609 {
18d715bd 2610 if (aReport.xbutton.state & ControlMask)
4fe56619 2611 {
18d715bd 2612 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
4fe56619 2613 }
7fd59977 2614 else
2615 {
2616 IsDragged = Standard_True;
7fd59977 2617 DragFirst = Standard_True;
2618 }
4fe56619 2619 }
18d715bd 2620 else if (aReport.xbutton.button == Button3)
4fe56619 2621 {
7fd59977 2622 // Start rotation
4fe56619 2623 VT_ProcessButton3Press();
2624 }
7fd59977 2625 }
2626 break;
2627 case ButtonRelease:
2628 {
7fd59977 2629 if( IsDragged )
2630 {
2631 if( !DragFirst )
2632 {
b12e1c7b 2633 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2634 {
2635 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2636 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2637 }
7fd59977 2638 }
2639
2640 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2641 if( aContext.IsNull() )
2642 {
2643 cout << "The context is null. Please use vinit before createmesh" << endl;
2644 return 0;
2645 }
2646
18d715bd 2647 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2648 if( aReport.xbutton.button==1 )
7fd59977 2649 if( DragFirst )
2650 if( ShiftPressed )
2651 {
0577ae8c 2652 aContext->ShiftSelect (Standard_True);
7fd59977 2653 }
2654 else
2655 {
0577ae8c 2656 aContext->Select (Standard_True);
7fd59977 2657 }
2658 else
2659 if( ShiftPressed )
2660 {
0577ae8c 2661 aContext->ShiftSelect(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2662 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2663 ViewerTest::CurrentView(), Standard_True);
7fd59977 2664 }
2665 else
2666 {
0577ae8c 2667 aContext->Select(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2668 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2669 ViewerTest::CurrentView(), Standard_True);
7fd59977 2670 }
2671 else
4fe56619 2672 VT_ProcessButton3Release();
7fd59977 2673
2674 IsDragged = Standard_False;
2675 }
2676 else
4fe56619 2677 VT_ProcessButton3Release();
7fd59977 2678 }
2679 break;
2680 case MotionNotify:
2681 {
08398024 2682 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2683 {
2684 break;
2685 }
7fd59977 2686 if( IsDragged )
2687 {
7fd59977 2688 if( !DragFirst )
b12e1c7b 2689 {
2690 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2691 {
2692 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
b12e1c7b 2693 }
2694 }
7fd59977 2695
18d715bd 2696 X_Motion = aReport.xmotion.x;
2697 Y_Motion = aReport.xmotion.y;
7fd59977 2698 DragFirst = Standard_False;
2699
b12e1c7b 2700 Window aWindow = GetWindowHandle(VT_GetWindow());
2701 Window aRoot;
2702 int anX, anY;
2703 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2704 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2705 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
68dcee02 2706 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
b12e1c7b 2707 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
7fd59977 2708 }
2709 else
2710 {
18d715bd 2711 X_Motion = aReport.xmotion.x;
2712 Y_Motion = aReport.xmotion.y;
7fd59977 2713
18d715bd 2714 // remove all the ButtonMotionMaskr
2715 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
7fd59977 2716
18d715bd 2717 if ( aReport.xmotion.state & ControlMask ) {
2718 if ( aReport.xmotion.state & Button1Mask ) {
7fd59977 2719 ProcessControlButton1Motion();
2720 }
18d715bd 2721 else if ( aReport.xmotion.state & Button2Mask ) {
4fe56619 2722 VT_ProcessControlButton2Motion();
7fd59977 2723 }
18d715bd 2724 else if ( aReport.xmotion.state & Button3Mask ) {
4fe56619 2725 VT_ProcessControlButton3Motion();
7fd59977 2726 }
2727 }
4fe56619 2728 else
2729 {
2730 VT_ProcessMotion();
7fd59977 2731 }
2732 }
2733 }
2734 break;
2735}
7fd59977 2736return pick;
2737}
2738
2739//==============================================================================
2740//function : VProcessEvents
2741//purpose : call by Tk_CreateFileHandler() to be able to manage the
2742// event in the Viewer window
2743//==============================================================================
2744
2745static void VProcessEvents(ClientData,int)
2746{
18d715bd 2747 NCollection_Vector<int> anEventNumbers;
2748 // Get number of messages from every display
2749 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2750 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2751 {
2752 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
4269bd1b 2753 }
18d715bd 2754 // Handle events for every display
2755 int anEventIter = 0;
2756 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2757 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2758 {
4269bd1b 2759 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
18d715bd 2760 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2761 {
2762 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2763 int anEventResult = ViewerMainLoop( 0, NULL);
2764 // If window is closed or context was not found finish current event processing loop
2765 if (!anEventResult)
2766 return;
2767 }
7fd59977 2768 }
4269bd1b 2769
18d715bd 2770 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
4269bd1b 2771
7fd59977 2772}
2773#endif
2774
2775//==============================================================================
2776//function : OSWindowSetup
2777//purpose : Setup for the X11 window to be able to cath the event
2778//==============================================================================
2779
2780
2781static void OSWindowSetup()
2782{
4fe56619 2783#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 2784 // X11
2785
2786 Window window = VT_GetWindow()->XWindow();
18d715bd 2787 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2788 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2789 XSynchronize(aDisplay, 1);
7fd59977 2790
2791 // X11 : For keyboard on SUN
2792 XWMHints wmhints;
2793 wmhints.flags = InputHint;
2794 wmhints.input = 1;
2795
18d715bd 2796 XSetWMHints( aDisplay, window, &wmhints);
7fd59977 2797
18d715bd 2798 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
7fd59977 2799 ButtonPressMask | ButtonReleaseMask |
2800 StructureNotifyMask |
2801 PointerMotionMask |
2802 Button1MotionMask | Button2MotionMask |
18d715bd 2803 Button3MotionMask | FocusChangeMask
7fd59977 2804 );
18d715bd 2805 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2806 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
7fd59977 2807
18d715bd 2808 XSynchronize(aDisplay, 0);
7fd59977 2809
2810#else
57c28b61 2811 // _WIN32
7fd59977 2812#endif
2813
2814}
2815
7fd59977 2816//==============================================================================
2817//function : VFit
1beb58d7 2818//purpose :
7fd59977 2819//==============================================================================
2820
1beb58d7 2821static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
7fd59977 2822{
1beb58d7 2823 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2824 if (aView.IsNull())
b586500b 2825 {
1beb58d7 2826 std::cout << "Error: no active viewer!\n";
2827 return 1;
b586500b 2828 }
2829
1beb58d7 2830 Standard_Boolean toFit = Standard_True;
2831 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2832 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
b586500b 2833 {
1beb58d7 2834 TCollection_AsciiString anArg (theArgv[anArgIter]);
b586500b 2835 anArg.LowerCase();
1beb58d7 2836 if (anUpdateTool.parseRedrawMode (anArg))
b586500b 2837 {
1beb58d7 2838 continue;
2839 }
2840 else if (anArg == "-selected")
2841 {
2842 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
2843 toFit = Standard_False;
2844 }
2845 else
2846 {
2847 std::cout << "Syntax error at '" << anArg << "'\n";
b586500b 2848 }
2849 }
2850
1beb58d7 2851 if (toFit)
2852 {
2853 aView->FitAll (0.01, Standard_False);
7fd59977 2854 }
2855 return 0;
2856}
2857
6262a303 2858//=======================================================================
2859//function : VFitArea
2860//purpose : Fit view to show area located between two points
2861// : given in world 2D or 3D coordinates.
2862//=======================================================================
2863static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2864{
2865 Handle(V3d_View) aView = ViewerTest::CurrentView();
2866 if (aView.IsNull())
2867 {
2868 std::cerr << theArgVec[0] << "Error: No active view.\n";
2869 return 1;
2870 }
2871
2872 // Parse arguments.
2873 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2874 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2875
2876 if (theArgNb == 5)
2877 {
2878 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2879 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2880 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2881 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2882 }
2883 else if (theArgNb == 7)
2884 {
2885 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2886 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2887 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2888 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2889 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2890 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2891 }
2892 else
2893 {
2894 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2895 theDI.PrintHelp(theArgVec[0]);
2896 return 1;
2897 }
2898
2899 // Convert model coordinates to view space
2900 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2901 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2902 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2903
2904 // Determine fit area
2905 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2906 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2907
2908 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2909
2910 if (aDiagonal < Precision::Confusion())
2911 {
2912 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2913 return 1;
2914 }
2915
2916 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2917 return 0;
2918}
2919
7fd59977 2920//==============================================================================
2921//function : VZFit
2922//purpose : ZFitall, no DRAW arguments
2923//Draw arg : No args
2924//==============================================================================
197ac94e 2925static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 2926{
197ac94e 2927 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2928
2929 if (aCurrentView.IsNull())
2930 {
2931 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2932 return 1;
2933 }
2934
2935 if (theArgsNb == 1)
2936 {
c357e426 2937 aCurrentView->ZFitAll();
197ac94e 2938 aCurrentView->Redraw();
2939 return 0;
2940 }
2941
2942 Standard_Real aScale = 1.0;
2943
2944 if (theArgsNb >= 2)
2945 {
2946 aScale = Draw::Atoi (theArgVec[1]);
2947 }
2948
c357e426 2949 aCurrentView->ZFitAll (aScale);
197ac94e 2950 aCurrentView->Redraw();
7fd59977 2951
197ac94e 2952 return 0;
2953}
7fd59977 2954
197ac94e 2955//==============================================================================
2956//function : VRepaint
2957//purpose :
2958//==============================================================================
56689b27 2959static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
7fd59977 2960{
56689b27 2961 Handle(V3d_View) aView = ViewerTest::CurrentView();
2962 if (aView.IsNull())
2963 {
2964 std::cout << "Error: no active viewer!\n";
2965 return 1;
2966 }
2967
2968 Standard_Boolean isImmediateUpdate = Standard_False;
2969 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2970 {
2971 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2972 anArg.LowerCase();
2973 if (anArg == "-immediate")
2974 {
2975 isImmediateUpdate = Standard_True;
2976 if (anArgIter + 1 < theArgNb
2977 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
2978 {
2979 ++anArgIter;
2980 }
2981 }
2982 else
2983 {
2984 std::cout << "Syntax error at '" << anArg << "'\n";
2985 }
2986 }
2987
2988 if (isImmediateUpdate)
2989 {
2990 aView->RedrawImmediate();
2991 }
2992 else
2993 {
2994 aView->Redraw();
2995 }
2996 return 0;
7fd59977 2997}
2998
7fd59977 2999//==============================================================================
3000//function : VClear
3001//purpose : Remove all the object from the viewer
3002//Draw arg : No args
3003//==============================================================================
3004
3005static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
3006{
3007 Handle(V3d_View) V = ViewerTest::CurrentView();
3008 if(!V.IsNull())
3009 ViewerTest::Clear();
3010 return 0;
3011}
3012
3013//==============================================================================
3014//function : VPick
3015//purpose :
3016//==============================================================================
3017
3018static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3019{ if (ViewerTest::CurrentView().IsNull() ) return 1;
3020
3021if ( argc < 4 ) {
586db386 3022 di << argv[0] << "Invalid number of arguments\n";
7fd59977 3023 return 1;
3024}
3025
3026while (ViewerMainLoop( argc, argv)) {
3027}
3028
3029return 0;
3030}
3031
7fd59977 3032//==============================================================================
7fd59977 3033//function : VSetBg
3034//purpose : Load image as background
3035//==============================================================================
3036
3037static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3038{
3039 if (argc < 2 || argc > 3)
3040 {
586db386 3041 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
3042 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
7fd59977 3043 return 1;
3044 }
3045
3046 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3047 if(AISContext.IsNull())
3048 {
3049 di << "use 'vinit' command before " << argv[0] << "\n";
3050 return 1;
3051 }
3052
3053 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
3054 if (argc == 3)
3055 {
3056 const char* szType = argv[2];
3057 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3058 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3059 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3060 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3061 else
3062 {
3063 di << "Wrong fill type : " << szType << "\n";
586db386 3064 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
7fd59977 3065 return 1;
3066 }
3067 }
3068
3069 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3070 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
3071
3072 return 0;
3073}
3074
3075//==============================================================================
f8b2ed36 3076//function : VSetBgMode
3077//purpose : Change background image fill type
3078//==============================================================================
3079
3080static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3081{
3082 if (argc != 2)
3083 {
586db386 3084 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
3085 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
f8b2ed36 3086 return 1;
3087 }
3088
3089 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3090 if(AISContext.IsNull())
3091 {
3092 di << "use 'vinit' command before " << argv[0] << "\n";
3093 return 1;
3094 }
1d47d8d0 3095 Aspect_FillMethod aFillType = Aspect_FM_NONE;
3096 const char* szType = argv[1];
3097 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3098 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3099 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3100 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3101 else
f8b2ed36 3102 {
1d47d8d0 3103 di << "Wrong fill type : " << szType << "\n";
586db386 3104 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
1d47d8d0 3105 return 1;
f8b2ed36 3106 }
f8b2ed36 3107 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3108 V3dView->SetBgImageStyle(aFillType, Standard_True);
f8b2ed36 3109 return 0;
3110}
3111
3112//==============================================================================
7fd59977 3113//function : VSetGradientBg
3114//purpose : Mount gradient background
3115//==============================================================================
3116static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3117{
3118 if (argc != 8 )
3119 {
586db386 3120 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n";
3121 di << "R1,G1,B1,R2,G2,B2 = [0..255]\n";
3122 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3123 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
7fd59977 3124 return 1;
3125 }
3126
3127 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3128 if(AISContext.IsNull())
3129 {
3130 di << "use 'vinit' command before " << argv[0] << "\n";
3131 return 1;
3132 }
3133 if (argc == 8)
3134 {
3135
91322f44 3136 Standard_Real R1 = Draw::Atof(argv[1])/255.;
3137 Standard_Real G1 = Draw::Atof(argv[2])/255.;
3138 Standard_Real B1 = Draw::Atof(argv[3])/255.;
7fd59977 3139 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
3140