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