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