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