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