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