0030611: Coding Rules - eliminate GCC compiler warnings -Wcatch-value
[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
e084dbbc 1267//! Make the view active
1268void ActivateView (const TCollection_AsciiString& theViewName,
1269 Standard_Boolean theToUpdate = Standard_True)
18d715bd 1270{
1271 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
e084dbbc 1272 if (aView.IsNull())
18d715bd 1273 {
e084dbbc 1274 return;
1275 }
18d715bd 1276
e084dbbc 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());
18d715bd 1284 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
e084dbbc 1285 }
1286
1287 ViewerTest::CurrentView (aView);
1288 ViewerTest::SetAISContext (anAISContext);
1289 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)";
1290 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1eeef710 1291#if defined(_WIN32)
e084dbbc 1292 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
18d715bd 1293#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
e084dbbc 1294 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
18d715bd 1295#else
e084dbbc 1296 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
18d715bd 1297#endif
e084dbbc 1298 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1299 if (theToUpdate)
1300 {
18d715bd 1301 ViewerTest::CurrentView()->Redraw();
1302 }
1303 }
1304}
1305
1306//==============================================================================
1307//function : RemoveView
0e93d9e5 1308//purpose :
1309//==============================================================================
1310void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1311 const Standard_Boolean theToRemoveContext)
1312{
1313 if (!ViewerTest_myViews.IsBound2 (theView))
1314 {
1315 return;
1316 }
1317
1318 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1319 RemoveView (aViewName, theToRemoveContext);
1320}
1321
1322//==============================================================================
1323//function : RemoveView
18d715bd 1324//purpose : Close and remove view from display, clear maps if neccessary
1325//==============================================================================
1326void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1327{
1328 if (!ViewerTest_myViews.IsBound1(theViewName))
1329 {
1330 cout << "Wrong view name\n";
1331 return;
1332 }
1333
1334 // Activate another view if it's active now
1335 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1336 {
1337 if (ViewerTest_myViews.Extent() > 1)
1338 {
1339 TCollection_AsciiString aNewViewName;
c48e2889 1340 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1341 anIter.More(); anIter.Next())
1342 {
18d715bd 1343 if (anIter.Key1() != theViewName)
1344 {
1345 aNewViewName = anIter.Key1();
1346 break;
1347 }
c48e2889 1348 }
1349 ActivateView (aNewViewName);
18d715bd 1350 }
1351 else
1352 {
e084dbbc 1353 VT_GetWindow().Nullify();
1354 ViewerTest::CurrentView (Handle(V3d_View)());
18d715bd 1355 if (isContextRemoved)
1356 {
1357 Handle(AIS_InteractiveContext) anEmptyContext;
1358 ViewerTest::SetAISContext(anEmptyContext);
1359 }
1360 }
1361 }
1362
1363 // Delete view
1364 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1365 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1366
1367 // Remove view resources
18d715bd 1368 ViewerTest_myViews.UnBind1(theViewName);
851dacdb 1369 aView->Window()->Unmap();
18d715bd 1370 aView->Remove();
1371
1372#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1373 XFlush (GetDisplayConnection()->GetDisplay());
1374#endif
1375
1376 // Keep context opened only if the closed view is last to avoid
1377 // unused empty contexts
1378 if (!aCurrentContext.IsNull())
1379 {
1380 // Check if there are more difined views in the viewer
1381 aCurrentContext->CurrentViewer()->InitDefinedViews();
1382 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1383 {
1384 // Remove driver if there is no viewers that use it
1385 Standard_Boolean isRemoveDriver = Standard_True;
1386 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1387 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1388 {
1389 if (aCurrentContext != anIter.Key2() &&
1390 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1391 {
1392 isRemoveDriver = Standard_False;
1393 break;
1394 }
1395 }
2ec85268 1396
1397 aCurrentContext->RemoveAll (Standard_False);
18d715bd 1398 if(isRemoveDriver)
1399 {
1400 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1401 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1402 #if TCL_MAJOR_VERSION < 8
1403 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1404 #else
1405 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1406 #endif
1407 #endif
1408 }
1409
1410 ViewerTest_myContexts.UnBind2(aCurrentContext);
1411 }
1412 }
1413 cout << "3D View - " << theViewName << " was deleted.\n";
fd3f6bd0 1414 if (Draw_ToExitOnCloseView)
1415 {
1416 Draw_Interprete ("exit");
1417 }
18d715bd 1418}
1419
1420//==============================================================================
1421//function : VClose
1422//purpose : Remove the view defined by its name
1423//==============================================================================
1424
d0cc1cb7 1425static int VClose (Draw_Interpretor& /*theDi*/,
1426 Standard_Integer theArgsNb,
1427 const char** theArgVec)
18d715bd 1428{
18d715bd 1429 NCollection_List<TCollection_AsciiString> aViewList;
d0cc1cb7 1430 if (theArgsNb > 1)
18d715bd 1431 {
d0cc1cb7 1432 TCollection_AsciiString anArg (theArgVec[1]);
1433 anArg.UpperCase();
1434 if (anArg.IsEqual ("ALL")
1435 || anArg.IsEqual ("*"))
1436 {
1437 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1438 anIter.More(); anIter.Next())
1439 {
1440 aViewList.Append (anIter.Key1());
1441 }
1442 if (aViewList.IsEmpty())
1443 {
1444 std::cout << "No view to close\n";
1445 return 0;
1446 }
1447 }
1448 else
18d715bd 1449 {
d0cc1cb7 1450 ViewerTest_Names aViewName (theArgVec[1]);
1451 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1452 {
1453 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1454 return 1;
1455 }
1456 aViewList.Append (aViewName.GetViewName());
18d715bd 1457 }
1458 }
1459 else
1460 {
d0cc1cb7 1461 // close active view
1462 if (ViewerTest::CurrentView().IsNull())
1463 {
1464 std::cerr << "No active view!\n";
1465 return 1;
1466 }
1467 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
18d715bd 1468 }
1469
d0cc1cb7 1470 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
18d715bd 1471 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1472 anIter.More(); anIter.Next())
1473 {
d0cc1cb7 1474 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
18d715bd 1475 }
1476
1477 return 0;
1478}
1479
1480//==============================================================================
1481//function : VActivate
1482//purpose : Activate the view defined by its ID
1483//==============================================================================
1484
1485static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1486{
e084dbbc 1487 if (theArgsNb == 1)
18d715bd 1488 {
1489 theDi.Eval("vviewlist");
1490 return 0;
1491 }
1492
e084dbbc 1493 TCollection_AsciiString aNameString;
1494 Standard_Boolean toUpdate = Standard_True;
1495 Standard_Boolean toActivate = Standard_True;
1496 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
18d715bd 1497 {
e084dbbc 1498 TCollection_AsciiString anArg (theArgVec[anArgIter]);
1499 anArg.LowerCase();
1500 if (toUpdate
1501 && anArg == "-noupdate")
1502 {
1503 toUpdate = Standard_False;
1504 }
1505 else if (toActivate
1506 && aNameString.IsEmpty()
1507 && anArg == "none")
1508 {
1509 TCollection_AsciiString aTitle("3D View - ");
1510 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1511 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1512 VT_GetWindow().Nullify();
1513 ViewerTest::CurrentView (Handle(V3d_View)());
1514 ViewerTest::ResetEventManager();
1515 theDi << theArgVec[0] << ": all views are inactive\n";
1516 toActivate = Standard_False;
1517 }
1518 else if (toActivate
1519 && aNameString.IsEmpty())
1520 {
1521 aNameString = theArgVec[anArgIter];
1522 }
1523 else
1524 {
1525 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
1526 return 1;
1527 }
18d715bd 1528 }
1529
e084dbbc 1530 if (!toActivate)
1531 {
1532 return 0;
1533 }
1534 else if (aNameString.IsEmpty())
1535 {
1536 std::cout << "Syntax error: wrong number of arguments\n";
1537 return 1;
1538 }
18d715bd 1539
1540 // Check if this view exists in the viewer with the driver
e084dbbc 1541 ViewerTest_Names aViewNames (aNameString);
18d715bd 1542 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1543 {
e084dbbc 1544 theDi << "Syntax error: wrong view name '" << aNameString << "'\n";
18d715bd 1545 return 1;
1546 }
1547
1548 // Check if it is active already
1549 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1550 {
1551 theDi << theArgVec[0] << ": the view is active already\n";
1552 return 0;
1553 }
1554
e084dbbc 1555 ActivateView (aViewNames.GetViewName(), toUpdate);
18d715bd 1556 return 0;
1557}
1558
1559//==============================================================================
1560//function : VViewList
1561//purpose : Print current list of views per viewer and graphic driver ID
1562// shared between viewers
1563//==============================================================================
1564
1565static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1566{
1567 if (theArgsNb > 2)
1568 {
1569 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
29cb310a 1570 << "Usage: " << theArgVec[0] << " name";
18d715bd 1571 return 1;
1572 }
1573 if (ViewerTest_myContexts.Size() < 1)
1574 return 0;
1575
18d715bd 1576 Standard_Boolean isTreeView =
29cb310a 1577 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
18d715bd 1578
1579 if (isTreeView)
c48e2889 1580 {
18d715bd 1581 theDi << theArgVec[0] <<":\n";
c48e2889 1582 }
18d715bd 1583
c48e2889 1584 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
1585 aDriverIter.More(); aDriverIter.Next())
1586 {
1587 if (isTreeView)
1588 theDi << aDriverIter.Key1() << ":\n";
18d715bd 1589
c48e2889 1590 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1591 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1592 {
1593 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
18d715bd 1594 {
c48e2889 1595 if (isTreeView)
18d715bd 1596 {
c48e2889 1597 TCollection_AsciiString aContextName(aContextIter.Key1());
1598 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1599 }
18d715bd 1600
c48e2889 1601 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
1602 aViewIter.More(); aViewIter.Next())
1603 {
1604 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
18d715bd 1605 {
c48e2889 1606 TCollection_AsciiString aViewName(aViewIter.Key1());
1607 if (isTreeView)
18d715bd 1608 {
c48e2889 1609 if (aViewIter.Value() == ViewerTest::CurrentView())
1610 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
18d715bd 1611 else
c48e2889 1612 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1613 }
1614 else
1615 {
1616 theDi << aViewName << " ";
18d715bd 1617 }
1618 }
1619 }
1620 }
1621 }
c48e2889 1622 }
18d715bd 1623 return 0;
1624}
1625
1626//==============================================================================
4fe56619 1627//function : VT_ProcessKeyPress
7fd59977 1628//purpose : Handle KeyPress event from a CString
1629//==============================================================================
4fe56619 1630void VT_ProcessKeyPress (const char* buf_ret)
7fd59977 1631{
1632 //cout << "KeyPress" << endl;
1633 const Handle(V3d_View) aView = ViewerTest::CurrentView();
7fd59977 1634 // Letter in alphabetic order
1635
2e93433e 1636 if (!strcasecmp (buf_ret, "A")
1637 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1638 {
7fd59977 1639 // AXO
1640 aView->SetProj(V3d_XposYnegZpos);
1641 }
2e93433e 1642 else if (!strcasecmp (buf_ret, "D")
1643 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1644 {
7fd59977 1645 // Reset
1646 aView->Reset();
1647 }
b514beda 1648 else if (!strcasecmp (buf_ret, "F"))
1649 {
b586500b 1650 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1651 {
1652 ViewerTest::GetAISContext()->FitSelected (aView);
1653 }
1654 else
1655 {
1656 // FitAll
1657 aView->FitAll();
1658 }
7fd59977 1659 }
b514beda 1660 else if (!strcasecmp (buf_ret, "H"))
1661 {
7fd59977 1662 // HLR
1eeef710 1663 std::cout << "HLR" << std::endl;
de75ed09 1664 aView->SetComputedMode (!aView->ComputedMode());
1eeef710 1665 aView->Redraw();
7fd59977 1666 }
b514beda 1667 else if (!strcasecmp (buf_ret, "P"))
1668 {
0a768f56 1669 // Type of HLR
1670 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1671 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1672 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1673 else
1674 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
c3282ec1 1675 if (aContext->NbSelected()==0)
0a768f56 1676 {
1677 AIS_ListOfInteractive aListOfShapes;
1678 aContext->DisplayedObjects(aListOfShapes);
1679 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1680 anIter.More(); anIter.Next())
1681 {
1682 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1683 if (aShape.IsNull())
1684 continue;
1685 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1686 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1687 else
1688 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
36132a2e 1689 aContext->Redisplay (aShape, Standard_False);
0a768f56 1690 }
1691 }
1692 else
1693 {
c3282ec1 1694 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
0a768f56 1695 {
c3282ec1 1696 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
0a768f56 1697 if (aShape.IsNull())
1698 continue;
1699 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1700 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1701 else
1702 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
36132a2e 1703 aContext->Redisplay (aShape, Standard_False);
0a768f56 1704 }
1705 }
1706
1707 aContext->UpdateCurrentViewer();
4269bd1b 1708
0a768f56 1709 }
b514beda 1710 else if (!strcasecmp (buf_ret, "S"))
1711 {
1712 std::cout << "setup Shaded display mode" << std::endl;
4fe56619 1713
7fd59977 1714 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
c3282ec1 1715 if(Ctx->NbSelected()==0)
0577ae8c 1716 Ctx->SetDisplayMode (AIS_Shaded, Standard_True);
7fd59977 1717 else{
c3282ec1 1718 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1719 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
7fd59977 1720 Ctx->UpdateCurrentViewer();
1721 }
1722 }
b514beda 1723 else if (!strcasecmp (buf_ret, "U"))
1724 {
41811896 1725 // Unset display mode
b514beda 1726 std::cout << "reset display mode to defaults" << std::endl;
4fe56619 1727
7fd59977 1728 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
c3282ec1 1729 if(Ctx->NbSelected()==0)
0577ae8c 1730 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
7fd59977 1731 else{
c3282ec1 1732 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1733 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
7fd59977 1734 Ctx->UpdateCurrentViewer();
1735 }
1736
1737 }
2e93433e 1738 else if (!strcasecmp (buf_ret, "T")
1739 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1740 {
7fd59977 1741 // Top
1742 aView->SetProj(V3d_Zpos);
1743 }
2e93433e 1744 else if (!strcasecmp (buf_ret, "B")
1745 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1746 {
41811896 1747 // Bottom
7fd59977 1748 aView->SetProj(V3d_Zneg);
1749 }
2e93433e 1750 else if (!strcasecmp (buf_ret, "L")
1751 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1752 {
41811896 1753 // Left
7fd59977 1754 aView->SetProj(V3d_Xneg);
1755 }
2e93433e 1756 else if (!strcasecmp (buf_ret, "R")
1757 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
b514beda 1758 {
41811896 1759 // Right
7fd59977 1760 aView->SetProj(V3d_Xpos);
1761 }
b514beda 1762 else if (!strcasecmp (buf_ret, "W"))
1763 {
1764 std::cout << "setup WireFrame display mode" << std::endl;
7fd59977 1765 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
c3282ec1 1766 if(Ctx->NbSelected()==0)
0577ae8c 1767 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
7fd59977 1768 else{
c3282ec1 1769 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1770 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
7fd59977 1771 Ctx->UpdateCurrentViewer();
1772 }
1773 }
b514beda 1774 else if (!strcasecmp (buf_ret, ","))
1775 {
7fd59977 1776 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
7fd59977 1777 }
b514beda 1778 else if (!strcasecmp (buf_ret, "."))
1779 {
7fd59977 1780 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1781 }
f978241f 1782 else if (!strcasecmp (buf_ret, "/"))
1783 {
1784 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1785 if (aCamera->IsStereo())
1786 {
1787 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1788 aView->Redraw();
1789 }
1790 }
1791 else if (!strcasecmp (buf_ret, "*"))
1792 {
1793 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1794 if (aCamera->IsStereo())
1795 {
1796 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1797 aView->Redraw();
1798 }
1799 }
b514beda 1800 else if (*buf_ret == THE_KEY_DELETE)
1801 {
1802 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1803 if (!aCtx.IsNull()
b514beda 1804 && aCtx->NbSelected() > 0)
1805 {
1806 Draw_Interprete ("verase");
1807 }
1808 }
fd3f6bd0 1809 else if (*buf_ret == THE_KEY_ESCAPE)
1810 {
1811 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1812 if (!aCtx.IsNull()
1813 && Draw_ToCloseViewOnEsc)
1814 {
1815 Draw_Interprete (Draw_ToExitOnCloseView ? "exit" : "vclose");
1816 }
1817 }
b514beda 1818 else
1819 {
1820 // Number
8c088c52 1821 const Standard_Integer aSelMode = Draw::Atoi(buf_ret);
1822 if (aSelMode >= 0 && aSelMode <= 7)
1823 {
1824 bool toEnable = true;
1825 if (const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext())
1826 {
1827 AIS_ListOfInteractive aPrsList;
1828 aCtx->DisplayedObjects (aPrsList);
1829 for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More() && toEnable; aPrsIter.Next())
1830 {
1831 TColStd_ListOfInteger aModes;
1832 aCtx->ActivatedModes (aPrsIter.Value(), aModes);
1833 for (TColStd_ListOfInteger::Iterator aModeIter (aModes); aModeIter.More() && toEnable; aModeIter.Next())
1834 {
1835 if (aModeIter.Value() == aSelMode)
1836 {
1837 toEnable = false;
1838 }
1839 }
1840 }
1841 }
1842 TCollection_AsciiString aCmd = TCollection_AsciiString ("vselmode ") + aSelMode + (toEnable ? " 1" : " 0");
1843 Draw_Interprete (aCmd.ToCString());
1844 }
7fd59977 1845 }
1846}
1847
1848//==============================================================================
4fe56619 1849//function : VT_ProcessExpose
7fd59977 1850//purpose : Redraw the View on an Expose Event
1851//==============================================================================
4fe56619 1852void VT_ProcessExpose()
1853{
1854 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1855 if (!aView3d.IsNull())
1856 {
1857 aView3d->Redraw();
1858 }
7fd59977 1859}
1860
1861//==============================================================================
4fe56619 1862//function : VT_ProcessConfigure
7fd59977 1863//purpose : Resize the View on an Configure Event
1864//==============================================================================
4fe56619 1865void VT_ProcessConfigure()
7fd59977 1866{
4fe56619 1867 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1868 if (aView3d.IsNull())
1869 {
1870 return;
1871 }
1872
1873 aView3d->MustBeResized();
1874 aView3d->Update();
1875 aView3d->Redraw();
7fd59977 1876}
1877
1878//==============================================================================
4fe56619 1879//function : VT_ProcessButton1Press
7fd59977 1880//purpose : Picking
1881//==============================================================================
e79a94b9 1882Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1883 const char** theArgVec,
1884 Standard_Boolean theToPick,
1885 Standard_Boolean theIsShift)
7fd59977 1886{
1beb58d7 1887 if (TheIsAnimating)
1888 {
1889 TheIsAnimating = Standard_False;
1890 return Standard_False;
1891 }
1892
e79a94b9 1893 if (theToPick)
1894 {
7fd59977 1895 Standard_Real X, Y, Z;
e79a94b9 1896 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
7fd59977 1897
e79a94b9 1898 Draw::Set (theArgVec[1], X);
1899 Draw::Set (theArgVec[2], Y);
1900 Draw::Set (theArgVec[3], Z);
1901 }
7fd59977 1902
e79a94b9 1903 if (theIsShift)
1904 {
1905 ViewerTest::CurrentEventManager()->ShiftSelect();
1906 }
7fd59977 1907 else
e79a94b9 1908 {
1909 ViewerTest::CurrentEventManager()->Select();
1910 }
7fd59977 1911
e79a94b9 1912 return Standard_False;
7fd59977 1913}
1914
1915//==============================================================================
4fe56619 1916//function : VT_ProcessButton1Release
1917//purpose : End selecting
7fd59977 1918//==============================================================================
4fe56619 1919void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1920{
1921 if (IsDragged)
1922 {
1923 IsDragged = Standard_False;
1924 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1925 if (theIsShift)
1926 {
2157d6ac 1927 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1928 X_Motion, Y_Motion);
4fe56619 1929 }
1930 else
1931 {
2157d6ac 1932 EM->Select (X_ButtonPress, Y_ButtonPress,
1933 X_Motion, Y_Motion);
4fe56619 1934 }
1935 }
1936}
7fd59977 1937
4fe56619 1938//==============================================================================
1939//function : VT_ProcessButton3Press
1940//purpose : Start Rotation
1941//==============================================================================
1942void VT_ProcessButton3Press()
1943{
2e93433e 1944 if (ViewerTest_V3dView::IsCurrentViewIn2DMode())
1945 {
1946 return;
1947 }
1948
7fd59977 1949 Start_Rot = 1;
1eeef710 1950 HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode();
1951 if (HasHlrOnBeforeRotation)
de75ed09 1952 {
1953 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1954 }
7fd59977 1955 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
7fd59977 1956}
4fe56619 1957
7fd59977 1958//==============================================================================
4fe56619 1959//function : VT_ProcessButton3Release
1960//purpose : End rotation
7fd59977 1961//==============================================================================
4fe56619 1962void VT_ProcessButton3Release()
1963{
1964 if (Start_Rot)
1965 {
7fd59977 1966 Start_Rot = 0;
1eeef710 1967 if (HasHlrOnBeforeRotation)
de75ed09 1968 {
1eeef710 1969 HasHlrOnBeforeRotation = Standard_False;
de75ed09 1970 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1eeef710 1971 ViewerTest::CurrentView()->Redraw();
de75ed09 1972 }
7fd59977 1973 }
7fd59977 1974}
1975
1976//==============================================================================
7fd59977 1977//function : ProcessControlButton1Motion
1978//purpose : Zoom
1979//==============================================================================
1980
900f7229 1981#if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 1982static void ProcessControlButton1Motion()
1983{
1984 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1985
1986 X_ButtonPress = X_Motion;
1987 Y_ButtonPress = Y_Motion;
1988}
900f7229 1989#endif
7fd59977 1990
1991//==============================================================================
4fe56619 1992//function : VT_ProcessControlButton2Motion
1993//purpose : Panning
7fd59977 1994//==============================================================================
4fe56619 1995void VT_ProcessControlButton2Motion()
7fd59977 1996{
197ac94e 1997 Standard_Integer aDx = X_Motion - X_ButtonPress;
1998 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
7fd59977 1999
197ac94e 2000 aDy = -aDy; // Xwindow Y axis is from top to Bottom
7fd59977 2001
197ac94e 2002 ViewerTest::CurrentView()->Pan (aDx, aDy);
7fd59977 2003
2004 X_ButtonPress = X_Motion;
2005 Y_ButtonPress = Y_Motion;
2006}
2007
2008//==============================================================================
4fe56619 2009//function : VT_ProcessControlButton3Motion
7fd59977 2010//purpose : Rotation
2011//==============================================================================
4fe56619 2012void VT_ProcessControlButton3Motion()
7fd59977 2013{
4fe56619 2014 if (Start_Rot)
2015 {
2016 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
2017 }
7fd59977 2018}
2019
2020//==============================================================================
4fe56619 2021//function : VT_ProcessMotion
2022//purpose :
7fd59977 2023//==============================================================================
4fe56619 2024void VT_ProcessMotion()
7fd59977 2025{
2026 //pre-hilights detected objects at mouse position
2027
2028 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
2029 EM->MoveTo(X_Motion, Y_Motion);
2030}
2031
2032
2033void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
2034{
2035 Xpix = X_Motion;Ypix=Y_Motion;
2036}
2037
2038//==============================================================================
44b8f2d6 2039//function : ViewProject: implements VAxo, VTop, VLeft, ...
2040//purpose : Switches to an axonometric, top, left and other views
2041//==============================================================================
2042
2043static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
2044{
4fe56619 2045 if ( ViewerTest::CurrentView().IsNull() )
44b8f2d6 2046 {
586db386 2047 di<<"Call vinit before this command, please\n";
44b8f2d6 2048 return 1;
2049 }
2050
2051 ViewerTest::CurrentView()->SetProj(ori);
2052 return 0;
2053}
2054
2055//==============================================================================
7fd59977 2056//function : VAxo
2057//purpose : Switch to an Axonometric view
2058//Draw arg : No args
2059//==============================================================================
2060
2061static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
44b8f2d6 2062{
2063 return ViewProject(di, V3d_XposYnegZpos);
7fd59977 2064}
2065
2066//==============================================================================
2067//function : VTop
2068//purpose : Switch to a Top View
2069//Draw arg : No args
2070//==============================================================================
2071
2072static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
2073{
44b8f2d6 2074 return ViewProject(di, V3d_Zpos);
2075}
7fd59977 2076
44b8f2d6 2077//==============================================================================
2078//function : VBottom
2079//purpose : Switch to a Bottom View
2080//Draw arg : No args
2081//==============================================================================
7fd59977 2082
44b8f2d6 2083static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
2084{
2085 return ViewProject(di, V3d_Zneg);
2086}
7fd59977 2087
44b8f2d6 2088//==============================================================================
2089//function : VLeft
2090//purpose : Switch to a Left View
2091//Draw arg : No args
2092//==============================================================================
2093
2094static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
2095{
27af3052 2096 return ViewProject(di, V3d_Xneg);
44b8f2d6 2097}
2098
2099//==============================================================================
2100//function : VRight
2101//purpose : Switch to a Right View
2102//Draw arg : No args
2103//==============================================================================
2104
2105static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
2106{
27af3052 2107 return ViewProject(di, V3d_Xpos);
44b8f2d6 2108}
7fd59977 2109
44b8f2d6 2110//==============================================================================
2111//function : VFront
2112//purpose : Switch to a Front View
2113//Draw arg : No args
2114//==============================================================================
2115
2116static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
2117{
27af3052 2118 return ViewProject(di, V3d_Yneg);
44b8f2d6 2119}
2120
2121//==============================================================================
2122//function : VBack
2123//purpose : Switch to a Back View
2124//Draw arg : No args
2125//==============================================================================
2126
2127static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
2128{
27af3052 2129 return ViewProject(di, V3d_Ypos);
7fd59977 2130}
2131
2132//==============================================================================
2133//function : VHelp
2134//purpose : Dsiplay help on viewer Keyboead and mouse commands
2135//Draw arg : No args
2136//==============================================================================
2137
2138static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
2139{
2140
586db386 2141 di << "Q : Quit the application\n";
2142
2143 di << "=========================\n";
2144 di << "F : FitAll\n";
2145 di << "T : TopView\n";
2146 di << "B : BottomView\n";
2147 di << "R : RightView\n";
2148 di << "L : LeftView\n";
2149 di << "A : AxonometricView\n";
2150 di << "D : ResetView\n";
2151
2152 di << "=========================\n";
2153 di << "S : Shading\n";
2154 di << "W : Wireframe\n";
2155 di << "H : HidelLineRemoval\n";
2156 di << "U : Unset display mode\n";
2157 di << "Delete : Remove selection from viewer\n";
2158
2159 di << "=========================\n";
2160 di << "Selection mode \n";
2161 di << "0 : Shape\n";
2162 di << "1 : Vertex\n";
2163 di << "2 : Edge\n";
2164 di << "3 : Wire\n";
2165 di << "4 : Face\n";
2166 di << "5 : Shell\n";
2167 di << "6 : Solid\n";
2168 di << "7 : Compound\n";
2169
2170 di << "=========================\n";
2171 di << "Z : Switch Z clipping On/Off\n";
2172 di << ", : Hilight next detected\n";
2173 di << ". : Hilight previous detected\n";
7fd59977 2174
2175 return 0;
2176}
2177
57c28b61 2178#ifdef _WIN32
7fd59977 2179
2180static Standard_Boolean Ppick = 0;
2181static Standard_Integer Pargc = 0;
2182static const char** Pargv = NULL;
2183
2184
2185static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
2186 UINT Msg,
2187 WPARAM wParam,
2188 LPARAM lParam )
2189{
18d715bd 2190 if (!ViewerTest_myViews.IsEmpty()) {
7fd59977 2191
2192 WPARAM fwKeys = wParam;
2193
2194 switch( Msg ) {
18d715bd 2195 case WM_CLOSE:
2196 {
2197 // Delete view from map of views
2198 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
2199 return 0;
2200 }
2201 break;
2202 case WM_ACTIVATE:
2203 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
2204 || ViewerTest::CurrentView().IsNull())
2205 {
2206 // Activate inactive window
2207 if(GetWindowHandle(VT_GetWindow()) != hwnd)
2208 {
2209 ActivateView (FindViewIdByWindowHandle(hwnd));
2210 }
2211 }
2212 break;
625e1958 2213
7fd59977 2214 case WM_LBUTTONUP:
625e1958 2215 if (IsDragged && !DragFirst)
7fd59977 2216 {
625e1958 2217 if (!GetActiveAISManipulator().IsNull())
2218 {
2219 GetActiveAISManipulator()->StopTransform();
0577ae8c 2220 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
625e1958 2221 }
2222
b12e1c7b 2223 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2224 {
2225 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2226 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2227 }
2228
dde68833 2229 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
7fd59977 2230 }
8abada55 2231 IsDragged = Standard_False;
7fd59977 2232 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2233
625e1958 2234 case WM_RBUTTONUP:
2235 if (IsDragged && !DragFirst)
2236 {
2237 if (!GetActiveAISManipulator().IsNull())
2238 {
2239 GetActiveAISManipulator()->StopTransform (Standard_False);
0577ae8c 2240 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
625e1958 2241 }
2242 IsDragged = Standard_False;
2243 }
2244 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
2245
7fd59977 2246 case WM_LBUTTONDOWN:
625e1958 2247 if (!GetActiveAISManipulator().IsNull())
2248 {
2249 IsDragged = ( fwKeys == MK_LBUTTON );
2250 }
2251 else
2252 {
2253 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
2254 }
2255
2256 if (IsDragged)
7fd59977 2257 {
7fd59977 2258 DragFirst = Standard_True;
4fe56619 2259 X_ButtonPress = LOWORD(lParam);
2260 Y_ButtonPress = HIWORD(lParam);
7fd59977 2261 }
2262 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2263
7fd59977 2264 case WM_MOUSEMOVE:
b12e1c7b 2265 if (IsDragged)
7fd59977 2266 {
b12e1c7b 2267 X_Motion = LOWORD (lParam);
2268 Y_Motion = HIWORD (lParam);
625e1958 2269 if (!GetActiveAISManipulator().IsNull())
b12e1c7b 2270 {
625e1958 2271 if (DragFirst)
2272 {
2273 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
2274 }
2275 else
2276 {
2277 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
2278 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
2279 }
69adb9ce 2280 }
625e1958 2281 else
69adb9ce 2282 {
625e1958 2283 bool toRedraw = false;
2284 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2285 {
2286 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2287 toRedraw = true;
2288 }
2289
2290 RECT aRect;
2291 if (GetClientRect (hwnd, &aRect))
2292 {
2293 int aHeight = aRect.bottom - aRect.top;
2294 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
68dcee02 2295 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
625e1958 2296 toRedraw = true;
2297 }
2298 if (toRedraw)
2299 {
2300 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2301 }
b12e1c7b 2302 }
625e1958 2303
2304 DragFirst = Standard_False;
7fd59977 2305 }
2306 else
2307 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2308 break;
2309
2310 default:
2311 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2312 }
2313 return 0;
2314 }
2315 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2316}
2317
2318
2319static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
2320 UINT Msg,
2321 WPARAM wParam,
2322 LPARAM lParam )
2323{
7fd59977 2324 static int Up = 1;
f978241f 2325 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2326 if (aView.IsNull())
2327 {
ad03c234 2328 return DefWindowProcW (hwnd, Msg, wParam, lParam);
f978241f 2329 }
7fd59977 2330
7fd59977 2331 PAINTSTRUCT ps;
2332
2333 switch( Msg ) {
7fd59977 2334 case WM_PAINT:
7fd59977 2335 BeginPaint(hwnd, &ps);
2336 EndPaint(hwnd, &ps);
4fe56619 2337 VT_ProcessExpose();
7fd59977 2338 break;
2339
2340 case WM_SIZE:
4fe56619 2341 VT_ProcessConfigure();
7fd59977 2342 break;
f978241f 2343 case WM_MOVE:
2344 case WM_MOVING:
2345 case WM_SIZING:
2346 switch (aView->RenderingParams().StereoMode)
2347 {
2348 case Graphic3d_StereoMode_RowInterlaced:
2349 case Graphic3d_StereoMode_ColumnInterlaced:
2350 case Graphic3d_StereoMode_ChessBoard:
2351 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2352 break;
2353 default:
2354 break;
2355 }
2356 break;
7fd59977 2357
2358 case WM_KEYDOWN:
4fe56619 2359 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2360 {
7fd59977 2361 char c[2];
2362 c[0] = (char) wParam;
2363 c[1] = '\0';
b514beda 2364 if (wParam == VK_DELETE)
2365 {
2366 c[0] = THE_KEY_DELETE;
2367 }
fd3f6bd0 2368 else if (wParam == VK_ESCAPE)
2369 {
2370 c[0] = THE_KEY_ESCAPE;
2371 }
4ca4bbe8 2372 // comma
2373 else if (wParam == VK_OEM_COMMA)
2374 {
2375 c[0] = ',';
2376 }
2377 // dot
2378 else if (wParam == VK_OEM_PERIOD)
2379 {
2380 c[0] = '.';
2381 }
f978241f 2382 else if (wParam == VK_DIVIDE)
2383 {
2384 c[0] = '/';
2385 }
2386 // dot
2387 else if (wParam == VK_MULTIPLY)
2388 {
2389 c[0] = '*';
2390 }
4fe56619 2391 VT_ProcessKeyPress (c);
7fd59977 2392 }
2393 break;
2394
2395 case WM_LBUTTONUP:
2396 case WM_MBUTTONUP:
2397 case WM_RBUTTONUP:
7fd59977 2398 Up = 1;
4fe56619 2399 VT_ProcessButton3Release();
7fd59977 2400 break;
2401
2402 case WM_LBUTTONDOWN:
2403 case WM_MBUTTONDOWN:
2404 case WM_RBUTTONDOWN:
2405 {
7fd59977 2406 WPARAM fwKeys = wParam;
2407
2408 Up = 0;
2409
2410 X_ButtonPress = LOWORD(lParam);
2411 Y_ButtonPress = HIWORD(lParam);
2412
4fe56619 2413 if (Msg == WM_LBUTTONDOWN)
2414 {
dde68833 2415 if ((fwKeys & MK_CONTROL) != 0)
4fe56619 2416 {
dde68833 2417 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
4fe56619 2418 }
2419 else
2420 {
dde68833 2421 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
4fe56619 2422 }
7fd59977 2423 }
4fe56619 2424 else if (Msg == WM_RBUTTONDOWN)
2425 {
7fd59977 2426 // Start rotation
4fe56619 2427 VT_ProcessButton3Press();
7fd59977 2428 }
2429 }
2430 break;
2431
f978241f 2432 case WM_MOUSEWHEEL:
2433 {
2434 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2435 if (wParam & MK_CONTROL)
2436 {
2437 if (aView->Camera()->IsStereo())
2438 {
2439 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2440 if (aFocus > 0.2
2441 && aFocus < 2.0)
2442 {
2443 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2444 aView->Redraw();
2445 }
2446 }
2447 }
2448 else
2449 {
2450 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2451 }
2452 break;
2453 }
2454
7fd59977 2455 case WM_MOUSEMOVE:
2456 {
2457 //cout << "\t WM_MOUSEMOVE" << endl;
2458 WPARAM fwKeys = wParam;
2459 X_Motion = LOWORD(lParam);
2460 Y_Motion = HIWORD(lParam);
2461
2462 if ( Up &&
dde68833 2463 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
2464 {
7fd59977 2465 Up = 0;
2466 X_ButtonPress = LOWORD(lParam);
2467 Y_ButtonPress = HIWORD(lParam);
2468
dde68833 2469 if ((fwKeys & MK_RBUTTON) != 0) {
7fd59977 2470 // Start rotation
4fe56619 2471 VT_ProcessButton3Press();
7fd59977 2472 }
2473 }
2474
dde68833 2475 if ((fwKeys & MK_CONTROL) != 0)
2476 {
2477 if ((fwKeys & MK_LBUTTON) != 0)
2478 {
7fd59977 2479 ProcessControlButton1Motion();
2480 }
dde68833 2481 else if ((fwKeys & MK_MBUTTON) != 0
2482 || ((fwKeys & MK_LBUTTON) != 0
2483 && (fwKeys & MK_RBUTTON) != 0))
2484 {
2485 VT_ProcessControlButton2Motion();
2486 }
2487 else if ((fwKeys & MK_RBUTTON) != 0)
2488 {
4fe56619 2489 VT_ProcessControlButton3Motion();
7fd59977 2490 }
2491 }
08398024 2492 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2493 {
89a929ea 2494 VT_ProcessMotion();
08398024 2495 }
7fd59977 2496 }
2497 break;
2498
2499 default:
ad03c234 2500 return DefWindowProcW (hwnd, Msg, wParam, lParam);
7fd59977 2501 }
2502 return 0L;
7fd59977 2503}
2504
7fd59977 2505//==============================================================================
2506//function : ViewerMainLoop
2507//purpose : Get a Event on the view and dispatch it
2508//==============================================================================
2509
2510
8263fcd3 2511int ViewerMainLoop(Standard_Integer argc, const char** argv)
7fd59977 2512{
7fd59977 2513 Ppick = (argc > 0)? 1 : 0;
2514 Pargc = argc;
2515 Pargv = argv;
2516
2517 if ( Ppick ) {
2518 MSG msg;
2519 msg.wParam = 1;
2520
2521 cout << "Start picking" << endl;
2522
7fd59977 2523 while ( Ppick == 1 ) {
4fe56619 2524 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
ad03c234 2525 if (GetMessageW (&msg, NULL, 0, 0))
2526 {
2527 TranslateMessage (&msg);
2528 DispatchMessageW (&msg);
7fd59977 2529 }
2530 }
2531
2532 cout << "Picking done" << endl;
2533 }
2534
2535 return Ppick;
2536}
2537
4fe56619 2538#elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 2539
2540int min( int a, int b )
2541{
2542 if( a<b )
2543 return a;
2544 else
2545 return b;
2546}
2547
2548int max( int a, int b )
2549{
2550 if( a>b )
2551 return a;
2552 else
2553 return b;
2554}
2555
2556int ViewerMainLoop(Standard_Integer argc, const char** argv)
2557
4269bd1b 2558{
18d715bd 2559 static XEvent aReport;
2560 Standard_Boolean pick = argc > 0;
2561 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2562 XNextEvent (aDisplay, &aReport);
7fd59977 2563
18d715bd 2564 // Handle event for the chosen display connection
2565 switch (aReport.type) {
2566 case ClientMessage:
2567 {
eb1ebea4 2568 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
18d715bd 2569 {
2570 // Close the window
2571 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2572 }
2573 }
2574 return 0;
2575 case FocusIn:
2576 {
2577 // Activate inactive view
2578 Window aWindow = GetWindowHandle(VT_GetWindow());
2579 if(aWindow != aReport.xfocus.window)
2580 {
2581 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2582 }
2583 }
2584 break;
7fd59977 2585 case Expose:
2586 {
4fe56619 2587 VT_ProcessExpose();
7fd59977 2588 }
2589 break;
2590 case ConfigureNotify:
2591 {
4fe56619 2592 VT_ProcessConfigure();
7fd59977 2593 }
2594 break;
2595 case KeyPress:
2596 {
2597
2598 KeySym ks_ret ;
2599 char buf_ret[11] ;
2600 int ret_len ;
2601 XComposeStatus status_in_out;
2602
18d715bd 2603 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
7fd59977 2604 (char *) buf_ret , 10 ,
2605 &ks_ret , &status_in_out ) ;
2606
2607
2608 buf_ret[ret_len] = '\0' ;
2609
4fe56619 2610 if (ret_len)
2611 {
2612 VT_ProcessKeyPress (buf_ret);
7fd59977 2613 }
2614 }
2615 break;
2616 case ButtonPress:
7fd59977 2617 {
18d715bd 2618 X_ButtonPress = aReport.xbutton.x;
2619 Y_ButtonPress = aReport.xbutton.y;
7fd59977 2620
18d715bd 2621 if (aReport.xbutton.button == Button1)
4fe56619 2622 {
18d715bd 2623 if (aReport.xbutton.state & ControlMask)
4fe56619 2624 {
18d715bd 2625 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
4fe56619 2626 }
7fd59977 2627 else
2628 {
2629 IsDragged = Standard_True;
7fd59977 2630 DragFirst = Standard_True;
2631 }
4fe56619 2632 }
18d715bd 2633 else if (aReport.xbutton.button == Button3)
4fe56619 2634 {
7fd59977 2635 // Start rotation
4fe56619 2636 VT_ProcessButton3Press();
2637 }
7fd59977 2638 }
2639 break;
2640 case ButtonRelease:
2641 {
7fd59977 2642 if( IsDragged )
2643 {
2644 if( !DragFirst )
2645 {
b12e1c7b 2646 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2647 {
2648 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2649 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2650 }
7fd59977 2651 }
2652
2653 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2654 if( aContext.IsNull() )
2655 {
2656 cout << "The context is null. Please use vinit before createmesh" << endl;
2657 return 0;
2658 }
2659
18d715bd 2660 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2661 if( aReport.xbutton.button==1 )
7fd59977 2662 if( DragFirst )
2663 if( ShiftPressed )
2664 {
0577ae8c 2665 aContext->ShiftSelect (Standard_True);
7fd59977 2666 }
2667 else
2668 {
0577ae8c 2669 aContext->Select (Standard_True);
7fd59977 2670 }
2671 else
2672 if( ShiftPressed )
2673 {
0577ae8c 2674 aContext->ShiftSelect(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2675 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2676 ViewerTest::CurrentView(), Standard_True);
7fd59977 2677 }
2678 else
2679 {
0577ae8c 2680 aContext->Select(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2681 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2682 ViewerTest::CurrentView(), Standard_True);
7fd59977 2683 }
2684 else
4fe56619 2685 VT_ProcessButton3Release();
7fd59977 2686
2687 IsDragged = Standard_False;
2688 }
2689 else
4fe56619 2690 VT_ProcessButton3Release();
7fd59977 2691 }
2692 break;
2693 case MotionNotify:
2694 {
08398024 2695 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2696 {
2697 break;
2698 }
7fd59977 2699 if( IsDragged )
2700 {
7fd59977 2701 if( !DragFirst )
b12e1c7b 2702 {
2703 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2704 {
2705 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
b12e1c7b 2706 }
2707 }
7fd59977 2708
18d715bd 2709 X_Motion = aReport.xmotion.x;
2710 Y_Motion = aReport.xmotion.y;
7fd59977 2711 DragFirst = Standard_False;
2712
b12e1c7b 2713 Window aWindow = GetWindowHandle(VT_GetWindow());
2714 Window aRoot;
2715 int anX, anY;
2716 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2717 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2718 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
68dcee02 2719 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
b12e1c7b 2720 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
7fd59977 2721 }
2722 else
2723 {
18d715bd 2724 X_Motion = aReport.xmotion.x;
2725 Y_Motion = aReport.xmotion.y;
7fd59977 2726
18d715bd 2727 // remove all the ButtonMotionMaskr
2728 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
7fd59977 2729
18d715bd 2730 if ( aReport.xmotion.state & ControlMask ) {
2731 if ( aReport.xmotion.state & Button1Mask ) {
7fd59977 2732 ProcessControlButton1Motion();
2733 }
18d715bd 2734 else if ( aReport.xmotion.state & Button2Mask ) {
4fe56619 2735 VT_ProcessControlButton2Motion();
7fd59977 2736 }
18d715bd 2737 else if ( aReport.xmotion.state & Button3Mask ) {
4fe56619 2738 VT_ProcessControlButton3Motion();
7fd59977 2739 }
2740 }
4fe56619 2741 else
2742 {
2743 VT_ProcessMotion();
7fd59977 2744 }
2745 }
2746 }
2747 break;
2748}
7fd59977 2749return pick;
2750}
2751
2752//==============================================================================
2753//function : VProcessEvents
2754//purpose : call by Tk_CreateFileHandler() to be able to manage the
2755// event in the Viewer window
2756//==============================================================================
2757
2758static void VProcessEvents(ClientData,int)
2759{
18d715bd 2760 NCollection_Vector<int> anEventNumbers;
2761 // Get number of messages from every display
2762 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2763 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2764 {
2765 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
4269bd1b 2766 }
18d715bd 2767 // Handle events for every display
2768 int anEventIter = 0;
2769 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2770 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2771 {
4269bd1b 2772 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
18d715bd 2773 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2774 {
2775 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2776 int anEventResult = ViewerMainLoop( 0, NULL);
2777 // If window is closed or context was not found finish current event processing loop
2778 if (!anEventResult)
2779 return;
2780 }
7fd59977 2781 }
4269bd1b 2782
18d715bd 2783 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
4269bd1b 2784
7fd59977 2785}
2786#endif
2787
2788//==============================================================================
2789//function : OSWindowSetup
2790//purpose : Setup for the X11 window to be able to cath the event
2791//==============================================================================
2792
2793
2794static void OSWindowSetup()
2795{
4fe56619 2796#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 2797 // X11
2798
2799 Window window = VT_GetWindow()->XWindow();
18d715bd 2800 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2801 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2802 XSynchronize(aDisplay, 1);
7fd59977 2803
2804 // X11 : For keyboard on SUN
2805 XWMHints wmhints;
2806 wmhints.flags = InputHint;
2807 wmhints.input = 1;
2808
18d715bd 2809 XSetWMHints( aDisplay, window, &wmhints);
7fd59977 2810
18d715bd 2811 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
7fd59977 2812 ButtonPressMask | ButtonReleaseMask |
2813 StructureNotifyMask |
2814 PointerMotionMask |
2815 Button1MotionMask | Button2MotionMask |
18d715bd 2816 Button3MotionMask | FocusChangeMask
7fd59977 2817 );
18d715bd 2818 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2819 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
7fd59977 2820
18d715bd 2821 XSynchronize(aDisplay, 0);
7fd59977 2822
2823#else
57c28b61 2824 // _WIN32
7fd59977 2825#endif
2826
2827}
2828
7fd59977 2829//==============================================================================
2830//function : VFit
1beb58d7 2831//purpose :
7fd59977 2832//==============================================================================
2833
1beb58d7 2834static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
7fd59977 2835{
1beb58d7 2836 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2837 if (aView.IsNull())
b586500b 2838 {
1beb58d7 2839 std::cout << "Error: no active viewer!\n";
2840 return 1;
b586500b 2841 }
2842
1beb58d7 2843 Standard_Boolean toFit = Standard_True;
2844 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2845 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
b586500b 2846 {
1beb58d7 2847 TCollection_AsciiString anArg (theArgv[anArgIter]);
b586500b 2848 anArg.LowerCase();
1beb58d7 2849 if (anUpdateTool.parseRedrawMode (anArg))
b586500b 2850 {
1beb58d7 2851 continue;
2852 }
2853 else if (anArg == "-selected")
2854 {
2855 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
2856 toFit = Standard_False;
2857 }
2858 else
2859 {
2860 std::cout << "Syntax error at '" << anArg << "'\n";
b586500b 2861 }
2862 }
2863
1beb58d7 2864 if (toFit)
2865 {
2866 aView->FitAll (0.01, Standard_False);
7fd59977 2867 }
2868 return 0;
2869}
2870
6262a303 2871//=======================================================================
2872//function : VFitArea
2873//purpose : Fit view to show area located between two points
2874// : given in world 2D or 3D coordinates.
2875//=======================================================================
2876static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2877{
2878 Handle(V3d_View) aView = ViewerTest::CurrentView();
2879 if (aView.IsNull())
2880 {
2881 std::cerr << theArgVec[0] << "Error: No active view.\n";
2882 return 1;
2883 }
2884
2885 // Parse arguments.
2886 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2887 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2888
2889 if (theArgNb == 5)
2890 {
2891 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2892 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2893 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2894 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2895 }
2896 else if (theArgNb == 7)
2897 {
2898 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2899 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2900 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2901 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2902 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2903 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2904 }
2905 else
2906 {
2907 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2908 theDI.PrintHelp(theArgVec[0]);
2909 return 1;
2910 }
2911
2912 // Convert model coordinates to view space
2913 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2914 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2915 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2916
2917 // Determine fit area
2918 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2919 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2920
2921 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2922
2923 if (aDiagonal < Precision::Confusion())
2924 {
2925 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2926 return 1;
2927 }
2928
2929 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2930 return 0;
2931}
2932
7fd59977 2933//==============================================================================
2934//function : VZFit
2935//purpose : ZFitall, no DRAW arguments
2936//Draw arg : No args
2937//==============================================================================
197ac94e 2938static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 2939{
197ac94e 2940 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2941
2942 if (aCurrentView.IsNull())
2943 {
2944 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2945 return 1;
2946 }
2947
2948 if (theArgsNb == 1)
2949 {
c357e426 2950 aCurrentView->ZFitAll();
197ac94e 2951 aCurrentView->Redraw();
2952 return 0;
2953 }
2954
2955 Standard_Real aScale = 1.0;
2956
2957 if (theArgsNb >= 2)
2958 {
2959 aScale = Draw::Atoi (theArgVec[1]);
2960 }
2961
c357e426 2962 aCurrentView->ZFitAll (aScale);
197ac94e 2963 aCurrentView->Redraw();
7fd59977 2964
197ac94e 2965 return 0;
2966}
7fd59977 2967
197ac94e 2968//==============================================================================
2969//function : VRepaint
2970//purpose :
2971//==============================================================================
56689b27 2972static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
7fd59977 2973{
56689b27 2974 Handle(V3d_View) aView = ViewerTest::CurrentView();
2975 if (aView.IsNull())
2976 {
2977 std::cout << "Error: no active viewer!\n";
2978 return 1;
2979 }
2980
2981 Standard_Boolean isImmediateUpdate = Standard_False;
2982 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2983 {
2984 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2985 anArg.LowerCase();
2986 if (anArg == "-immediate")
2987 {
2988 isImmediateUpdate = Standard_True;
2989 if (anArgIter + 1 < theArgNb
2990 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
2991 {
2992 ++anArgIter;
2993 }
2994 }
2995 else
2996 {
2997 std::cout << "Syntax error at '" << anArg << "'\n";
2998 }
2999 }
3000
3001 if (isImmediateUpdate)
3002 {
3003 aView->RedrawImmediate();
3004 }
3005 else
3006 {
3007 aView->Redraw();
3008 }
3009 return 0;
7fd59977 3010}
3011
7fd59977 3012//==============================================================================
3013//function : VClear
3014//purpose : Remove all the object from the viewer
3015//Draw arg : No args
3016//==============================================================================
3017
3018static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
3019{
3020 Handle(V3d_View) V = ViewerTest::CurrentView();
3021 if(!V.IsNull())
3022 ViewerTest::Clear();
3023 return 0;
3024}
3025
3026//==============================================================================
3027//function : VPick
3028//purpose :
3029//==============================================================================
3030
3031static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3032{ if (ViewerTest::CurrentView().IsNull() ) return 1;
3033
3034if ( argc < 4 ) {
586db386 3035 di << argv[0] << "Invalid number of arguments\n";
7fd59977 3036 return 1;
3037}
3038
3039while (ViewerMainLoop( argc, argv)) {
3040}
3041
3042return 0;
3043}
3044
7fd59977 3045//==============================================================================
7fd59977 3046//function : VSetBg
3047//purpose : Load image as background
3048//==============================================================================
3049
3050static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3051{
3052 if (argc < 2 || argc > 3)
3053 {
586db386 3054 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
3055 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
7fd59977 3056 return 1;
3057 }
3058
3059 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3060 if(AISContext.IsNull())
3061 {
3062 di << "use 'vinit' command before " << argv[0] << "\n";
3063 return 1;
3064 }
3065
3066 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
3067 if (argc == 3)
3068 {
3069 const char* szType = argv[2];
3070 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3071 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3072 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3073 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3074 else
3075 {
3076 di << "Wrong fill type : " << szType << "\n";
586db386 3077 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
7fd59977 3078 return 1;
3079 }
3080 }
3081
3082 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3083 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
3084
3085 return 0;
3086}
3087
3088//==============================================================================
f8b2ed36 3089//function : VSetBgMode
3090//purpose : Change background image fill type
3091//==============================================================================
3092
3093static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3094{
3095 if (argc != 2)
3096 {
586db386 3097 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
3098 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
f8b2ed36 3099 return 1;
3100 }
3101
3102 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3103 if(AISContext.IsNull())
3104 {
3105 di << "use 'vinit' command before " << argv[0] << "\n";
3106 return 1;
3107 }
1d47d8d0 3108 Aspect_FillMethod aFillType = Aspect_FM_NONE;
3109 const char* szType = argv[1];
3110 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3111 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3112 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3113 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3114 else
f8b2ed36 3115 {
1d47d8d0 3116 di << "Wrong fill type : " << szType << "\n";
586db386 3117 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
1d47d8d0 3118 return 1;
f8b2ed36 3119 }
f8b2ed36 3120 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3121 V3dView->SetBgImageStyle(aFillType, Standard_True);
f8b2ed36 3122 return 0;
3123}
3124
3125//==============================================================================
7fd59977