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