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