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