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