0026273: Comments to methods are misplaced in gp_Vec.cdl
[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()),
663 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
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 }
b514beda 1515 else if (*buf_ret == THE_KEY_DELETE)
1516 {
1517 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1518 if (!aCtx.IsNull()
1519 && aCtx->NbCurrents() > 0
1520 && aCtx->NbSelected() > 0)
1521 {
1522 Draw_Interprete ("verase");
1523 }
1524 }
1525 else
1526 {
1527 // Number
91322f44 1528 Standard_Integer Num = Draw::Atoi(buf_ret);
7fd59977 1529 if(Num>=0 && Num<=7)
1530 ViewerTest::StandardModeActivation(Num);
1531 }
1532}
1533
1534//==============================================================================
4fe56619 1535//function : VT_ProcessExpose
7fd59977 1536//purpose : Redraw the View on an Expose Event
1537//==============================================================================
4fe56619 1538void VT_ProcessExpose()
1539{
1540 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1541 if (!aView3d.IsNull())
1542 {
1543 aView3d->Redraw();
1544 }
7fd59977 1545}
1546
1547//==============================================================================
4fe56619 1548//function : VT_ProcessConfigure
7fd59977 1549//purpose : Resize the View on an Configure Event
1550//==============================================================================
4fe56619 1551void VT_ProcessConfigure()
7fd59977 1552{
4fe56619 1553 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1554 if (aView3d.IsNull())
1555 {
1556 return;
1557 }
1558
1559 aView3d->MustBeResized();
1560 aView3d->Update();
1561 aView3d->Redraw();
7fd59977 1562}
1563
1564//==============================================================================
4fe56619 1565//function : VT_ProcessButton1Press
7fd59977 1566//purpose : Picking
1567//==============================================================================
e79a94b9 1568Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1569 const char** theArgVec,
1570 Standard_Boolean theToPick,
1571 Standard_Boolean theIsShift)
7fd59977 1572{
e79a94b9 1573 if (theToPick)
1574 {
7fd59977 1575 Standard_Real X, Y, Z;
e79a94b9 1576 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
7fd59977 1577
e79a94b9 1578 Draw::Set (theArgVec[1], X);
1579 Draw::Set (theArgVec[2], Y);
1580 Draw::Set (theArgVec[3], Z);
1581 }
7fd59977 1582
e79a94b9 1583 if (theIsShift)
1584 {
1585 ViewerTest::CurrentEventManager()->ShiftSelect();
1586 }
7fd59977 1587 else
e79a94b9 1588 {
1589 ViewerTest::CurrentEventManager()->Select();
1590 }
7fd59977 1591
e79a94b9 1592 return Standard_False;
7fd59977 1593}
1594
1595//==============================================================================
4fe56619 1596//function : VT_ProcessButton1Release
1597//purpose : End selecting
7fd59977 1598//==============================================================================
4fe56619 1599void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1600{
1601 if (IsDragged)
1602 {
1603 IsDragged = Standard_False;
1604 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1605 if (theIsShift)
1606 {
2157d6ac 1607 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1608 X_Motion, Y_Motion);
4fe56619 1609 }
1610 else
1611 {
2157d6ac 1612 EM->Select (X_ButtonPress, Y_ButtonPress,
1613 X_Motion, Y_Motion);
4fe56619 1614 }
1615 }
1616}
7fd59977 1617
4fe56619 1618//==============================================================================
1619//function : VT_ProcessButton3Press
1620//purpose : Start Rotation
1621//==============================================================================
1622void VT_ProcessButton3Press()
1623{
7fd59977 1624 Start_Rot = 1;
de75ed09 1625 if (MyHLRIsOn)
1626 {
1627 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1628 }
7fd59977 1629 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
7fd59977 1630}
4fe56619 1631
7fd59977 1632//==============================================================================
4fe56619 1633//function : VT_ProcessButton3Release
1634//purpose : End rotation
7fd59977 1635//==============================================================================
4fe56619 1636void VT_ProcessButton3Release()
1637{
1638 if (Start_Rot)
1639 {
7fd59977 1640 Start_Rot = 0;
de75ed09 1641 if (MyHLRIsOn)
1642 {
1643 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1644 }
7fd59977 1645 }
7fd59977 1646}
1647
1648//==============================================================================
1649//function : ProcessZClipMotion
1650//purpose : Zoom
1651//==============================================================================
1652
1653void ProcessZClipMotion()
1654{
1655 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1656 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
7fd59977 1657
1658 //Quantity_Length VDX, VDY;
1659 //a3DView->Size(VDX,VDY);
1660 //Standard_Real VDZ = a3DView->ZSize();
1661 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1662
58978f9b 1663 Quantity_Length aDx = a3DView->Convert(X_Motion - X_ButtonPress);
7fd59977 1664
1665 // Front = Depth + width/2.
58978f9b 1666 Standard_Real aDepth = 0.5;
1667 Standard_Real aWidth = 0.1;
1668 a3DView->ZClipping(aDepth,aWidth);
7fd59977 1669
58978f9b 1670 aDepth += aDx;
7fd59977 1671
1672 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1673
58978f9b 1674 a3DView->SetZClippingDepth(aDepth);
7fd59977 1675
1676 a3DView->Redraw();
1677
1678 X_ButtonPress = X_Motion;
1679 Y_ButtonPress = Y_Motion;
1680 }
1681}
1682
1683//==============================================================================
1684//function : ProcessControlButton1Motion
1685//purpose : Zoom
1686//==============================================================================
1687
900f7229 1688#if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 1689static void ProcessControlButton1Motion()
1690{
1691 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1692
1693 X_ButtonPress = X_Motion;
1694 Y_ButtonPress = Y_Motion;
1695}
900f7229 1696#endif
7fd59977 1697
1698//==============================================================================
4fe56619 1699//function : VT_ProcessControlButton2Motion
1700//purpose : Panning
7fd59977 1701//==============================================================================
4fe56619 1702void VT_ProcessControlButton2Motion()
7fd59977 1703{
197ac94e 1704 Standard_Integer aDx = X_Motion - X_ButtonPress;
1705 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
7fd59977 1706
197ac94e 1707 aDy = -aDy; // Xwindow Y axis is from top to Bottom
7fd59977 1708
197ac94e 1709 ViewerTest::CurrentView()->Pan (aDx, aDy);
7fd59977 1710
1711 X_ButtonPress = X_Motion;
1712 Y_ButtonPress = Y_Motion;
1713}
1714
1715//==============================================================================
4fe56619 1716//function : VT_ProcessControlButton3Motion
7fd59977 1717//purpose : Rotation
1718//==============================================================================
4fe56619 1719void VT_ProcessControlButton3Motion()
7fd59977 1720{
4fe56619 1721 if (Start_Rot)
1722 {
1723 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1724 }
7fd59977 1725}
1726
1727//==============================================================================
4fe56619 1728//function : VT_ProcessMotion
1729//purpose :
7fd59977 1730//==============================================================================
4fe56619 1731void VT_ProcessMotion()
7fd59977 1732{
1733 //pre-hilights detected objects at mouse position
1734
1735 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1736 EM->MoveTo(X_Motion, Y_Motion);
1737}
1738
1739
1740void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1741{
1742 Xpix = X_Motion;Ypix=Y_Motion;
1743}
1744
1745//==============================================================================
44b8f2d6 1746//function : ViewProject: implements VAxo, VTop, VLeft, ...
1747//purpose : Switches to an axonometric, top, left and other views
1748//==============================================================================
1749
1750static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1751{
4fe56619 1752 if ( ViewerTest::CurrentView().IsNull() )
44b8f2d6 1753 {
1754 di<<"Call vinit before this command, please"<<"\n";
1755 return 1;
1756 }
1757
1758 ViewerTest::CurrentView()->SetProj(ori);
1759 return 0;
1760}
1761
1762//==============================================================================
7fd59977 1763//function : VAxo
1764//purpose : Switch to an Axonometric view
1765//Draw arg : No args
1766//==============================================================================
1767
1768static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
44b8f2d6 1769{
1770 return ViewProject(di, V3d_XposYnegZpos);
7fd59977 1771}
1772
1773//==============================================================================
1774//function : VTop
1775//purpose : Switch to a Top View
1776//Draw arg : No args
1777//==============================================================================
1778
1779static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1780{
44b8f2d6 1781 return ViewProject(di, V3d_Zpos);
1782}
7fd59977 1783
44b8f2d6 1784//==============================================================================
1785//function : VBottom
1786//purpose : Switch to a Bottom View
1787//Draw arg : No args
1788//==============================================================================
7fd59977 1789
44b8f2d6 1790static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1791{
1792 return ViewProject(di, V3d_Zneg);
1793}
7fd59977 1794
44b8f2d6 1795//==============================================================================
1796//function : VLeft
1797//purpose : Switch to a Left View
1798//Draw arg : No args
1799//==============================================================================
1800
1801static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1802{
1803 return ViewProject(di, V3d_Ypos);
1804}
1805
1806//==============================================================================
1807//function : VRight
1808//purpose : Switch to a Right View
1809//Draw arg : No args
1810//==============================================================================
1811
1812static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1813{
1814 return ViewProject(di, V3d_Yneg);
1815}
7fd59977 1816
44b8f2d6 1817//==============================================================================
1818//function : VFront
1819//purpose : Switch to a Front View
1820//Draw arg : No args
1821//==============================================================================
1822
1823static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1824{
1825 return ViewProject(di, V3d_Xpos);
1826}
1827
1828//==============================================================================
1829//function : VBack
1830//purpose : Switch to a Back View
1831//Draw arg : No args
1832//==============================================================================
1833
1834static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1835{
1836 return ViewProject(di, V3d_Xneg);
7fd59977 1837}
1838
1839//==============================================================================
1840//function : VHelp
1841//purpose : Dsiplay help on viewer Keyboead and mouse commands
1842//Draw arg : No args
1843//==============================================================================
1844
1845static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1846{
1847
1848 di << "Q : Quit the application" << "\n";
1849
1850 di << "========================="<<"\n";
1851 di << "F : FitAll" << "\n";
1852 di << "T : TopView" << "\n";
41811896 1853 di << "B : BottomView" << "\n";
1854 di << "R : RightView" << "\n";
1855 di << "L : LeftView" << "\n";
7fd59977 1856 di << "A : AxonometricView" << "\n";
41811896 1857 di << "D : ResetView" << "\n";
7fd59977 1858
1859 di << "========================="<<"\n";
1860 di << "S : Shading" << "\n";
1861 di << "W : Wireframe" << "\n";
1862 di << "H : HidelLineRemoval" << "\n";
41811896 1863 di << "U : Unset display mode" << "\n";
b514beda 1864 di << "Delete : Remove selection from viewer" << "\n";
7fd59977 1865
1866 di << "========================="<<"\n";
1867 di << "Selection mode "<<"\n";
1868 di << "0 : Shape" <<"\n";
1869 di << "1 : Vertex" <<"\n";
1870 di << "2 : Edge" <<"\n";
1871 di << "3 : Wire" <<"\n";
1872 di << "4 : Face" <<"\n";
1873 di << "5 : Shell" <<"\n";
1874 di << "6 : Solid" <<"\n";
1875 di << "7 : Compound" <<"\n";
1876
41811896 1877 di << "========================="<<"\n";
1878 di << "Z : Switch Z clipping On/Off" << "\n";
1879 di << ", : Hilight next detected" << "\n";
1880 di << ". : Hilight previous detected" << "\n";
7fd59977 1881
1882 return 0;
1883}
1884
7fd59977 1885#ifdef WNT
1886
1887static Standard_Boolean Ppick = 0;
1888static Standard_Integer Pargc = 0;
1889static const char** Pargv = NULL;
1890
1891
1892static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1893 UINT Msg,
1894 WPARAM wParam,
1895 LPARAM lParam )
1896{
18d715bd 1897 if (!ViewerTest_myViews.IsEmpty()) {
7fd59977 1898
1899 WPARAM fwKeys = wParam;
1900
1901 switch( Msg ) {
18d715bd 1902 case WM_CLOSE:
1903 {
1904 // Delete view from map of views
1905 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1906 return 0;
1907 }
1908 break;
1909 case WM_ACTIVATE:
1910 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1911 || ViewerTest::CurrentView().IsNull())
1912 {
1913 // Activate inactive window
1914 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1915 {
1916 ActivateView (FindViewIdByWindowHandle(hwnd));
1917 }
1918 }
1919 break;
7fd59977 1920 case WM_LBUTTONUP:
8abada55 1921 if (!DragFirst)
7fd59977 1922 {
1923 HDC hdc = GetDC( hwnd );
7fd59977 1924 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1925 SetROP2( hdc, R2_NOT );
4fe56619 1926 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 1927 ReleaseDC( hwnd, hdc );
8abada55 1928 VT_ProcessButton1Release (fwKeys & MK_SHIFT);
7fd59977 1929 }
8abada55 1930 IsDragged = Standard_False;
7fd59977 1931 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1932
1933 case WM_LBUTTONDOWN:
1934 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1935 {
1936 IsDragged = Standard_True;
1937 DragFirst = Standard_True;
4fe56619 1938 X_ButtonPress = LOWORD(lParam);
1939 Y_ButtonPress = HIWORD(lParam);
7fd59977 1940 }
1941 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1942
1943 break;
1944
1945 case WM_MOUSEMOVE:
1946 if( IsDragged )
1947 {
1948 HDC hdc = GetDC( hwnd );
1949
1950 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1951 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1952 SetROP2( hdc, R2_NOT );
1953
1954 if( !DragFirst )
4fe56619 1955 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 1956
1957 DragFirst = Standard_False;
4fe56619 1958 X_Motion = LOWORD(lParam);
1959 Y_Motion = HIWORD(lParam);
7fd59977 1960
4fe56619 1961 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 1962
1963 SelectObject( hdc, anObj );
1964
1965 ReleaseDC( hwnd, hdc );
1966 }
1967 else
1968 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1969 break;
1970
1971 default:
1972 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1973 }
1974 return 0;
1975 }
1976 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1977}
1978
1979
1980static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1981 UINT Msg,
1982 WPARAM wParam,
1983 LPARAM lParam )
1984{
7fd59977 1985 static int Up = 1;
1986
1987 if ( !ViewerTest::CurrentView().IsNull() ) {
1988 PAINTSTRUCT ps;
1989
1990 switch( Msg ) {
7fd59977 1991 case WM_PAINT:
7fd59977 1992 BeginPaint(hwnd, &ps);
1993 EndPaint(hwnd, &ps);
4fe56619 1994 VT_ProcessExpose();
7fd59977 1995 break;
1996
1997 case WM_SIZE:
4fe56619 1998 VT_ProcessConfigure();
7fd59977 1999 break;
2000
2001 case WM_KEYDOWN:
4fe56619 2002 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2003 {
7fd59977 2004 char c[2];
2005 c[0] = (char) wParam;
2006 c[1] = '\0';
b514beda 2007 if (wParam == VK_DELETE)
2008 {
2009 c[0] = THE_KEY_DELETE;
2010 }
4ca4bbe8 2011 // comma
2012 else if (wParam == VK_OEM_COMMA)
2013 {
2014 c[0] = ',';
2015 }
2016 // dot
2017 else if (wParam == VK_OEM_PERIOD)
2018 {
2019 c[0] = '.';
2020 }
4fe56619 2021 VT_ProcessKeyPress (c);
7fd59977 2022 }
2023 break;
2024
2025 case WM_LBUTTONUP:
2026 case WM_MBUTTONUP:
2027 case WM_RBUTTONUP:
7fd59977 2028 Up = 1;
4fe56619 2029 VT_ProcessButton3Release();
7fd59977 2030 break;
2031
2032 case WM_LBUTTONDOWN:
2033 case WM_MBUTTONDOWN:
2034 case WM_RBUTTONDOWN:
2035 {
7fd59977 2036 WPARAM fwKeys = wParam;
2037
2038 Up = 0;
2039
2040 X_ButtonPress = LOWORD(lParam);
2041 Y_ButtonPress = HIWORD(lParam);
2042
4fe56619 2043 if (Msg == WM_LBUTTONDOWN)
2044 {
2045 if (fwKeys & MK_CONTROL)
2046 {
2047 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2048 }
2049 else
2050 {
2051 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2052 }
7fd59977 2053 }
4fe56619 2054 else if (Msg == WM_RBUTTONDOWN)
2055 {
7fd59977 2056 // Start rotation
4fe56619 2057 VT_ProcessButton3Press();
7fd59977 2058 }
2059 }
2060 break;
2061
2062 case WM_MOUSEMOVE:
2063 {
2064 //cout << "\t WM_MOUSEMOVE" << endl;
2065 WPARAM fwKeys = wParam;
2066 X_Motion = LOWORD(lParam);
2067 Y_Motion = HIWORD(lParam);
2068
2069 if ( Up &&
2070 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2071 Up = 0;
2072 X_ButtonPress = LOWORD(lParam);
2073 Y_ButtonPress = HIWORD(lParam);
2074
2075 if ( fwKeys & MK_RBUTTON ) {
2076 // Start rotation
4fe56619 2077 VT_ProcessButton3Press();
7fd59977 2078 }
2079 }
2080
2081 if ( fwKeys & MK_CONTROL ) {
2082 if ( fwKeys & MK_LBUTTON ) {
2083 ProcessControlButton1Motion();
2084 }
2085 else if ( fwKeys & MK_MBUTTON ||
2086 ((fwKeys&MK_LBUTTON) &&
2087 (fwKeys&MK_RBUTTON) ) ){
4fe56619 2088 VT_ProcessControlButton2Motion();
7fd59977 2089 }
2090 else if ( fwKeys & MK_RBUTTON ) {
4fe56619 2091 VT_ProcessControlButton3Motion();
7fd59977 2092 }
2093 }
2094#ifdef BUG
2095 else if ( fwKeys & MK_SHIFT ) {
2096 if ( fwKeys & MK_MBUTTON ||
2097 ((fwKeys&MK_LBUTTON) &&
2098 (fwKeys&MK_RBUTTON) ) ) {
2099 cout << "ProcessZClipMotion()" << endl;
2100 ProcessZClipMotion();
2101 }
2102 }
2103#endif
08398024 2104 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2105 {
4fe56619 2106 if ((fwKeys & MK_MBUTTON
2107 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2108 {
7fd59977 2109 ProcessZClipMotion();
2110 }
4fe56619 2111 else
2112 {
2113 VT_ProcessMotion();
7fd59977 2114 }
08398024 2115 }
7fd59977 2116 }
2117 break;
2118
2119 default:
2120 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2121 }
2122 return 0L;
2123 }
2124
2125 return DefWindowProc( hwnd, Msg, wParam, lParam );
2126}
2127
2128
2129
2130
2131//==============================================================================
2132//function : ViewerMainLoop
2133//purpose : Get a Event on the view and dispatch it
2134//==============================================================================
2135
2136
8263fcd3 2137int ViewerMainLoop(Standard_Integer argc, const char** argv)
7fd59977 2138{
7fd59977 2139 Ppick = (argc > 0)? 1 : 0;
2140 Pargc = argc;
2141 Pargv = argv;
2142
2143 if ( Ppick ) {
2144 MSG msg;
2145 msg.wParam = 1;
2146
2147 cout << "Start picking" << endl;
2148
7fd59977 2149 while ( Ppick == 1 ) {
4fe56619 2150 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
7fd59977 2151 if (GetMessage(&msg, NULL, 0, 0) ) {
2152 TranslateMessage(&msg);
2153 DispatchMessage(&msg);
2154 }
2155 }
2156
2157 cout << "Picking done" << endl;
2158 }
2159
2160 return Ppick;
2161}
2162
4fe56619 2163#elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 2164
2165int min( int a, int b )
2166{
2167 if( a<b )
2168 return a;
2169 else
2170 return b;
2171}
2172
2173int max( int a, int b )
2174{
2175 if( a>b )
2176 return a;
2177 else
2178 return b;
2179}
2180
2181int ViewerMainLoop(Standard_Integer argc, const char** argv)
2182
4269bd1b 2183{
18d715bd 2184 static XEvent aReport;
2185 Standard_Boolean pick = argc > 0;
2186 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2187 XNextEvent (aDisplay, &aReport);
7fd59977 2188
18d715bd 2189 // Handle event for the chosen display connection
2190 switch (aReport.type) {
2191 case ClientMessage:
2192 {
eb1ebea4 2193 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
18d715bd 2194 {
2195 // Close the window
2196 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2197 }
2198 }
2199 return 0;
2200 case FocusIn:
2201 {
2202 // Activate inactive view
2203 Window aWindow = GetWindowHandle(VT_GetWindow());
2204 if(aWindow != aReport.xfocus.window)
2205 {
2206 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2207 }
2208 }
2209 break;
7fd59977 2210 case Expose:
2211 {
4fe56619 2212 VT_ProcessExpose();
7fd59977 2213 }
2214 break;
2215 case ConfigureNotify:
2216 {
4fe56619 2217 VT_ProcessConfigure();
7fd59977 2218 }
2219 break;
2220 case KeyPress:
2221 {
2222
2223 KeySym ks_ret ;
2224 char buf_ret[11] ;
2225 int ret_len ;
2226 XComposeStatus status_in_out;
2227
18d715bd 2228 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
7fd59977 2229 (char *) buf_ret , 10 ,
2230 &ks_ret , &status_in_out ) ;
2231
2232
2233 buf_ret[ret_len] = '\0' ;
2234
4fe56619 2235 if (ret_len)
2236 {
2237 VT_ProcessKeyPress (buf_ret);
7fd59977 2238 }
2239 }
2240 break;
2241 case ButtonPress:
7fd59977 2242 {
18d715bd 2243 X_ButtonPress = aReport.xbutton.x;
2244 Y_ButtonPress = aReport.xbutton.y;
7fd59977 2245
18d715bd 2246 if (aReport.xbutton.button == Button1)
4fe56619 2247 {
18d715bd 2248 if (aReport.xbutton.state & ControlMask)
4fe56619 2249 {
18d715bd 2250 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
4fe56619 2251 }
7fd59977 2252 else
2253 {
2254 IsDragged = Standard_True;
7fd59977 2255 DragFirst = Standard_True;
2256 }
4fe56619 2257 }
18d715bd 2258 else if (aReport.xbutton.button == Button3)
4fe56619 2259 {
7fd59977 2260 // Start rotation
4fe56619 2261 VT_ProcessButton3Press();
2262 }
7fd59977 2263 }
2264 break;
2265 case ButtonRelease:
2266 {
7fd59977 2267 if( IsDragged )
2268 {
2269 if( !DragFirst )
2270 {
2271 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
18d715bd 2272 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2273 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 2274 }
2275
2276 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2277 if( aContext.IsNull() )
2278 {
2279 cout << "The context is null. Please use vinit before createmesh" << endl;
2280 return 0;
2281 }
2282
18d715bd 2283 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2284 if( aReport.xbutton.button==1 )
7fd59977 2285 if( DragFirst )
2286 if( ShiftPressed )
2287 {
2288 aContext->ShiftSelect();
7fd59977 2289 }
2290 else
2291 {
2292 aContext->Select();
7fd59977 2293 }
2294 else
2295 if( ShiftPressed )
2296 {
4fe56619 2297 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2298 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
7fd59977 2299 ViewerTest::CurrentView());
7fd59977 2300 }
2301 else
2302 {
4fe56619 2303 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2304 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
7fd59977 2305 ViewerTest::CurrentView() );
7fd59977 2306 }
2307 else
4fe56619 2308 VT_ProcessButton3Release();
7fd59977 2309
2310 IsDragged = Standard_False;
2311 }
2312 else
4fe56619 2313 VT_ProcessButton3Release();
7fd59977 2314 }
2315 break;
2316 case MotionNotify:
2317 {
08398024 2318 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2319 {
2320 break;
2321 }
7fd59977 2322 if( IsDragged )
2323 {
2324 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
18d715bd 2325 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2326 XSetFunction( aDisplay, gc, GXinvert );
7fd59977 2327
2328 if( !DragFirst )
18d715bd 2329 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 2330
18d715bd 2331 X_Motion = aReport.xmotion.x;
2332 Y_Motion = aReport.xmotion.y;
7fd59977 2333 DragFirst = Standard_False;
2334
18d715bd 2335 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 2336 }
2337 else
2338 {
18d715bd 2339 X_Motion = aReport.xmotion.x;
2340 Y_Motion = aReport.xmotion.y;
7fd59977 2341
18d715bd 2342 // remove all the ButtonMotionMaskr
2343 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
7fd59977 2344
18d715bd 2345 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
7fd59977 2346 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2347
2348 Quantity_Length VDX, VDY;
2349
2350 ViewerTest::CurrentView()->Size(VDX,VDY);
2351 Standard_Real VDZ =0 ;
2352 VDZ = ViewerTest::CurrentView()->ZSize();
2353
7fd59977 2354 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2355
2356 Quantity_Length dx = 0 ;
2357 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2358
2359 cout << dx << endl;
2360
2361 dx = dx / VDX * VDZ;
2362
2363 cout << dx << endl;
2364
7fd59977 2365 ViewerTest::CurrentView()->Redraw();
2366 }
2367 }
2368
18d715bd 2369 if ( aReport.xmotion.state & ControlMask ) {
2370 if ( aReport.xmotion.state & Button1Mask ) {
7fd59977 2371 ProcessControlButton1Motion();
2372 }
18d715bd 2373 else if ( aReport.xmotion.state & Button2Mask ) {
4fe56619 2374 VT_ProcessControlButton2Motion();
7fd59977 2375 }
18d715bd 2376 else if ( aReport.xmotion.state & Button3Mask ) {
4fe56619 2377 VT_ProcessControlButton3Motion();
7fd59977 2378 }
2379 }
4fe56619 2380 else
2381 {
2382 VT_ProcessMotion();
7fd59977 2383 }
2384 }
2385 }
2386 break;
2387}
7fd59977 2388return pick;
2389}
2390
2391//==============================================================================
2392//function : VProcessEvents
2393//purpose : call by Tk_CreateFileHandler() to be able to manage the
2394// event in the Viewer window
2395//==============================================================================
2396
2397static void VProcessEvents(ClientData,int)
2398{
18d715bd 2399 NCollection_Vector<int> anEventNumbers;
2400 // Get number of messages from every display
2401 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2402 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2403 {
2404 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
4269bd1b 2405 }
18d715bd 2406 // Handle events for every display
2407 int anEventIter = 0;
2408 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2409 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2410 {
4269bd1b 2411 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
18d715bd 2412 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2413 {
2414 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2415 int anEventResult = ViewerMainLoop( 0, NULL);
2416 // If window is closed or context was not found finish current event processing loop
2417 if (!anEventResult)
2418 return;
2419 }
7fd59977 2420 }
4269bd1b 2421
18d715bd 2422 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
4269bd1b 2423
7fd59977 2424}
2425#endif
2426
2427//==============================================================================
2428//function : OSWindowSetup
2429//purpose : Setup for the X11 window to be able to cath the event
2430//==============================================================================
2431
2432
2433static void OSWindowSetup()
2434{
4fe56619 2435#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 2436 // X11
2437
2438 Window window = VT_GetWindow()->XWindow();
18d715bd 2439 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2440 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2441 XSynchronize(aDisplay, 1);
7fd59977 2442
2443 // X11 : For keyboard on SUN
2444 XWMHints wmhints;
2445 wmhints.flags = InputHint;
2446 wmhints.input = 1;
2447
18d715bd 2448 XSetWMHints( aDisplay, window, &wmhints);
7fd59977 2449
18d715bd 2450 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
7fd59977 2451 ButtonPressMask | ButtonReleaseMask |
2452 StructureNotifyMask |
2453 PointerMotionMask |
2454 Button1MotionMask | Button2MotionMask |
18d715bd 2455 Button3MotionMask | FocusChangeMask
7fd59977 2456 );
18d715bd 2457 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2458 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
7fd59977 2459
18d715bd 2460 XSynchronize(aDisplay, 0);
7fd59977 2461
2462#else
2463 // WNT
2464#endif
2465
2466}
2467
7fd59977 2468//==============================================================================
2469//function : VFit
2470
2471//purpose : Fitall, no DRAW arguments
2472//Draw arg : No args
2473//==============================================================================
2474
b586500b 2475static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgc, const char** theArgv)
7fd59977 2476{
b586500b 2477 if (theArgc > 2)
2478 {
2479 std::cout << "Wrong number of arguments! Use: vfit [-selected]" << std::endl;
2480 }
2481
7fd59977 2482 const Handle(V3d_View) aView = ViewerTest::CurrentView();
b586500b 2483
2484 if (theArgc == 2)
2485 {
2486 TCollection_AsciiString anArg (theArgv[1]);
2487 anArg.LowerCase();
2488 if (anArg == "-selected")
2489 {
fb64064b 2490 ViewerTest::GetAISContext()->FitSelected (aView);
b586500b 2491 return 0;
2492 }
2493 }
fb64064b 2494 if (aView.IsNull() == Standard_False) {
b586500b 2495
7fd59977 2496 aView->FitAll();
2497 }
2498 return 0;
2499}
2500
6262a303 2501//=======================================================================
2502//function : VFitArea
2503//purpose : Fit view to show area located between two points
2504// : given in world 2D or 3D coordinates.
2505//=======================================================================
2506static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2507{
2508 Handle(V3d_View) aView = ViewerTest::CurrentView();
2509 if (aView.IsNull())
2510 {
2511 std::cerr << theArgVec[0] << "Error: No active view.\n";
2512 return 1;
2513 }
2514
2515 // Parse arguments.
2516 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2517 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2518
2519 if (theArgNb == 5)
2520 {
2521 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2522 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2523 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2524 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2525 }
2526 else if (theArgNb == 7)
2527 {
2528 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2529 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2530 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2531 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2532 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2533 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2534 }
2535 else
2536 {
2537 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2538 theDI.PrintHelp(theArgVec[0]);
2539 return 1;
2540 }
2541
2542 // Convert model coordinates to view space
2543 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2544 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2545 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2546
2547 // Determine fit area
2548 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2549 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2550
2551 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2552
2553 if (aDiagonal < Precision::Confusion())
2554 {
2555 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2556 return 1;
2557 }
2558
2559 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2560 return 0;
2561}
2562
7fd59977 2563//==============================================================================
2564//function : VZFit
2565//purpose : ZFitall, no DRAW arguments
2566//Draw arg : No args
2567//==============================================================================
197ac94e 2568static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 2569{
197ac94e 2570 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2571
2572 if (aCurrentView.IsNull())
2573 {
2574 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2575 return 1;
2576 }
2577
2578 if (theArgsNb == 1)
2579 {
6bc6a6fc 2580 aCurrentView->View()->ZFitAll();
197ac94e 2581 aCurrentView->Redraw();
2582 return 0;
2583 }
2584
2585 Standard_Real aScale = 1.0;
2586
2587 if (theArgsNb >= 2)
2588 {
2589 aScale = Draw::Atoi (theArgVec[1]);
2590 }
2591
6bc6a6fc 2592 aCurrentView->View()->ZFitAll (aScale);
197ac94e 2593 aCurrentView->Redraw();
7fd59977 2594
197ac94e 2595 return 0;
2596}
7fd59977 2597
197ac94e 2598//==============================================================================
2599//function : VRepaint
2600//purpose :
2601//==============================================================================
2602static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
7fd59977 2603{
2604 Handle(V3d_View) V = ViewerTest::CurrentView();
2605 if ( !V.IsNull() ) V->Redraw(); return 0;
2606}
2607
7fd59977 2608//==============================================================================
2609//function : VClear
2610//purpose : Remove all the object from the viewer
2611//Draw arg : No args
2612//==============================================================================
2613
2614static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2615{
2616 Handle(V3d_View) V = ViewerTest::CurrentView();
2617 if(!V.IsNull())
2618 ViewerTest::Clear();
2619 return 0;
2620}
2621
2622//==============================================================================
2623//function : VPick
2624//purpose :
2625//==============================================================================
2626
2627static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2628{ if (ViewerTest::CurrentView().IsNull() ) return 1;
2629
2630if ( argc < 4 ) {
2631 di << argv[0] << "Invalid number of arguments" << "\n";
2632 return 1;
2633}
2634
2635while (ViewerMainLoop( argc, argv)) {
2636}
2637
2638return 0;
2639}
2640
7fd59977 2641//==============================================================================
7fd59977 2642//function : VSetBg
2643//purpose : Load image as background
2644//==============================================================================
2645
2646static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2647{
2648 if (argc < 2 || argc > 3)
2649 {
2650 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
f8b2ed36 2651 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
7fd59977 2652 return 1;
2653 }
2654
2655 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2656 if(AISContext.IsNull())
2657 {
2658 di << "use 'vinit' command before " << argv[0] << "\n";
2659 return 1;
2660 }
2661
2662 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2663 if (argc == 3)
2664 {
2665 const char* szType = argv[2];
2666 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2667 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2668 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2669 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2670 else
2671 {
2672 di << "Wrong fill type : " << szType << "\n";
2673 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2674 return 1;
2675 }
2676 }
2677
2678 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2679 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2680
2681 return 0;
2682}
2683
2684//==============================================================================
f8b2ed36 2685//function : VSetBgMode
2686//purpose : Change background image fill type
2687//==============================================================================
2688
2689static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2690{
2691 if (argc != 2)
2692 {
2693 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2694 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2695 return 1;
2696 }
2697
2698 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2699 if(AISContext.IsNull())
2700 {
2701 di << "use 'vinit' command before " << argv[0] << "\n";
2702 return 1;
2703 }
1d47d8d0 2704 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2705 const char* szType = argv[1];
2706 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2707 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2708 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2709 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2710 else
f8b2ed36 2711 {
1d47d8d0 2712 di << "Wrong fill type : " << szType << "\n";
2713 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2714 return 1;
f8b2ed36 2715 }
f8b2ed36 2716 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2717 V3dView->SetBgImageStyle(aFillType, Standard_True);
f8b2ed36 2718 return 0;
2719}
2720
2721//==============================================================================
7fd59977 2722//function : VSetGradientBg
2723//purpose : Mount gradient background
2724//==============================================================================
2725static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2726{
2727 if (argc != 8 )
2728 {
2729 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2730 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2731 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2732 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2733 return 1;
2734 }
2735
2736 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2737 if(AISContext.IsNull())
2738 {
2739 di << "use 'vinit' command before " << argv[0] << "\n";
2740 return 1;
2741 }
2742 if (argc == 8)
2743 {
2744
91322f44 2745 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2746 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2747 Standard_Real B1 = Draw::Atof(argv[3])/255.;
7fd59977 2748 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2749
91322f44 2750 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2751 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2752 Standard_Real B2 = Draw::Atof(argv[6])/255.;
7fd59977 2753
2754 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
91322f44 2755 int aType = Draw::Atoi(argv[7]);
7fd59977 2756 if( aType < 0 || aType > 8 )
2757 {
2758 di << "Wrong fill type " << "\n";
2759 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2760 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2761 return 1;
2762 }
2763
2764 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2765
2766 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2767 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2768 }
2769
2770 return 0;
2771}
2772
2773//==============================================================================
f8b2ed36 2774//function : VSetGradientBgMode
2775//purpose : Change gradient background fill style
2776//==============================================================================
2777static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2778{
2779 if (argc != 2 )
2780 {
2781 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2782 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2783 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2784 return 1;
2785 }
2786
2787 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2788 if(AISContext.IsNull())
2789 {
2790 di << "use 'vinit' command before " << argv[0] << "\n";
2791 return 1;
2792 }
2793 if (argc == 2)
2794 {
91322f44 2795 int aType = Draw::Atoi(argv[1]);
f8b2ed36 2796 if( aType < 0 || aType > 8 )
2797 {
2798 di << "Wrong fill type " << "\n";
2799 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2800 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2801 return 1;
2802 }
2803
2804 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2805
2806 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2807 V3dView->SetBgGradientStyle( aMethod, 1 );
2808 }
2809
2810 return 0;
2811}
2812
2813//==============================================================================
2814//function : VSetColorBg
2815//purpose : Set color background
2816//==============================================================================
2817static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2818{
2819 if (argc != 4 )
2820 {
2821 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2822 di << "R,G,B = [0..255]" << "\n";
2823 return 1;
2824 }
2825
2826 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2827 if(AISContext.IsNull())
2828 {
2829 di << "use 'vinit' command before " << argv[0] << "\n";
2830 return 1;
2831 }
2832 if (argc == 4)
2833 {
2834
91322f44 2835 Standard_Real R = Draw::Atof(argv[1])/255.;
2836 Standard_Real G = Draw::Atof(argv[2])/255.;
2837 Standard_Real B = Draw::Atof(argv[3])/255.;
f8b2ed36 2838 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2839
2840 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2841 V3dView->SetBackgroundColor( aColor );
2842 V3dView->Update();
2843 }
2844
2845 return 0;
2846}
2847
2848//==============================================================================
7fd59977 2849//function : VScale
2850//purpose : View Scaling
2851//==============================================================================
2852
2853static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2854{
2855 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2856 if ( V3dView.IsNull() ) return 1;
2857
2858 if ( argc != 4 ) {
2859 di << argv[0] << "Invalid number of arguments" << "\n";
2860 return 1;
2861 }
91322f44 2862 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
7fd59977 2863 return 0;
2864}
2865//==============================================================================
536d98e2 2866//function : VZBuffTrihedron
2867//purpose :
7fd59977 2868//==============================================================================
2869
536d98e2 2870static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
2871 Standard_Integer theArgNb,
2872 const char** theArgVec)
7fd59977 2873{
536d98e2 2874 Handle(V3d_View) aView = ViewerTest::CurrentView();
2875 if (aView.IsNull())
2876 {
2877 std::cout << "Error: no active viewer!\n";
2878 return 1;
2879 }
7fd59977 2880
536d98e2 2881 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7c8a8fcc 2882
536d98e2 2883 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2884 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
2885 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
2886 Quantity_Color anArrowColorX = Quantity_NOC_RED;
2887 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
2888 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
2889 Standard_Real aScale = 0.1;
2890 Standard_Real aSizeRatio = 0.8;
2891 Standard_Real anArrowDiam = 0.05;
2892 Standard_Integer aNbFacets = 12;
2893 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7c8a8fcc 2894 {
536d98e2 2895 Standard_CString anArg = theArgVec[anArgIter];
2896 TCollection_AsciiString aFlag (anArg);
2897 aFlag.LowerCase();
2898 if (anUpdateTool.parseRedrawMode (aFlag))
7c8a8fcc 2899 {
536d98e2 2900 continue;
2901 }
2902 else if (aFlag == "-on")
7c8a8fcc 2903 {
536d98e2 2904 continue;
2905 }
2906 else if (aFlag == "-off")
7c8a8fcc 2907 {
536d98e2 2908 aView->TriedronErase();
2909 return 0;
2910 }
2911 else if (aFlag == "-pos"
2912 || aFlag == "-position"
2913 || aFlag == "-corner")
7c8a8fcc 2914 {
536d98e2 2915 if (++anArgIter >= theArgNb)
2916 {
2917 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2918 return 1;
2919 }
2920
2921 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
2922 aPosName.LowerCase();
2923 if (aPosName == "center")
2924 {
2925 aPosition = Aspect_TOTP_CENTER;
2926 }
2927 else if (aPosName == "left_lower"
2928 || aPosName == "lower_left"
2929 || aPosName == "leftlower"
2930 || aPosName == "lowerleft")
2931 {
2932 aPosition = Aspect_TOTP_LEFT_LOWER;
2933 }
2934 else if (aPosName == "left_upper"
2935 || aPosName == "upper_left"
2936 || aPosName == "leftupper"
2937 || aPosName == "upperleft")
2938 {
2939 aPosition = Aspect_TOTP_LEFT_UPPER;
2940 }
2941 else if (aPosName == "right_lower"
2942 || aPosName == "lower_right"
2943 || aPosName == "rightlower"
2944 || aPosName == "lowerright")
2945 {
2946 aPosition = Aspect_TOTP_RIGHT_LOWER;
2947 }
2948 else if (aPosName == "right_upper"
2949 || aPosName == "upper_right"
2950 || aPosName == "rightupper"
2951 || aPosName == "upperright")
2952 {
2953 aPosition = Aspect_TOTP_RIGHT_UPPER;
2954 }
2955 else
2956 {
2957 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
2958 return 1;
2959 }
2960 }
2961 else if (aFlag == "-type")
7c8a8fcc 2962 {
536d98e2 2963 if (++anArgIter >= theArgNb)
2964 {
2965 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2966 return 1;
2967 }
2968
2969 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
2970 aTypeName.LowerCase();
2971 if (aTypeName == "wireframe"
2972 || aTypeName == "wire")
2973 {
2974 aVisType = V3d_WIREFRAME;
2975 }
2976 else if (aTypeName == "zbuffer"
2977 || aTypeName == "shaded")
2978 {
2979 aVisType = V3d_ZBUFFER;
2980 }
2981 else
2982 {
2983 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
2984 }
2985 }
2986 else if (aFlag == "-scale")
7c8a8fcc 2987 {
536d98e2 2988 if (++anArgIter >= theArgNb)
2989 {
2990 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2991 return 1;
2992 }
2993
2994 aScale = Draw::Atof (theArgVec[anArgIter]);
7c8a8fcc 2995 }
536d98e2 2996 else if (aFlag == "-size"
2997 || aFlag == "-sizeratio")
2998 {
2999 if (++anArgIter >= theArgNb)
3000 {
3001 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3002 return 1;
3003 }
7c8a8fcc 3004
536d98e2 3005 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3006 }
3007 else if (aFlag == "-arrowdiam"
3008 || aFlag == "-arrowdiameter")
3009 {
3010 if (++anArgIter >= theArgNb)
3011 {
3012 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3013 return 1;
3014 }
7c8a8fcc 3015
536d98e2 3016 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3017 }
3018 else if (aFlag == "-nbfacets")
3019 {
3020 if (++anArgIter >= theArgNb)
3021 {
3022 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3023 return 1;
3024 }
7c8a8fcc 3025
536d98e2 3026 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3027 }
3028 else if (aFlag == "-colorlabel"
3029 || aFlag == "-colorlabels")
7c8a8fcc 3030 {
536d98e2 3031 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3032 theArgVec + anArgIter + 1,
3033 aLabelsColor);
3034 if (aNbParsed == 0)
3035 {
3036 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3037 return 1;
3038 }
3039 anArgIter += aNbParsed;
7c8a8fcc 3040 }
536d98e2 3041 else if (aFlag == "-colorarrowx")
7c8a8fcc 3042 {
536d98e2 3043 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3044 theArgVec + anArgIter + 1,
3045 anArrowColorX);
3046 if (aNbParsed == 0)
3047 {
3048 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3049 return 1;
3050 }
3051 anArgIter += aNbParsed;
3052 }
3053 else if (aFlag == "-colorarrowy")
7c8a8fcc 3054 {
536d98e2 3055 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3056 theArgVec + anArgIter + 1,
3057 anArrowColorY);
3058 if (aNbParsed == 0)
3059 {
3060 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3061 return 1;
3062 }
3063 anArgIter += aNbParsed;
3064 }
3065 else if (aFlag == "-colorarrowz")
7c8a8fcc 3066 {
536d98e2 3067 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3068 theArgVec + anArgIter + 1,
3069 anArrowColorZ);
3070 if (aNbParsed == 0)
3071 {
3072 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3073 return 1;
3074 }
3075 anArgIter += aNbParsed;
3076 }
3077 else
3078 {
3079 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
7c8a8fcc 3080 return 1;
3081 }
7c8a8fcc 3082 }
3083
536d98e2 3084 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3085 aSizeRatio, anArrowDiam, aNbFacets);
3086 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3087 aView->View()->ZFitAll();
7fd59977 3088 return 0;
3089}
3090
3091//==============================================================================
3092//function : VRotate
3093//purpose : Camera Rotating
3094//==============================================================================
3095
4af098ba 3096static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3097{
3098 Handle(V3d_View) aView = ViewerTest::CurrentView();
3099 if (aView.IsNull())
3100 {
3101 std::cout << "No active view!\n";
7fd59977 3102 return 1;
3103 }
3104
4af098ba 3105 Standard_Boolean hasFlags = Standard_False;
3106 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3107 {
3108 Standard_CString anArg (theArgVec[anArgIter]);
3109 TCollection_AsciiString aFlag (anArg);
3110 aFlag.LowerCase();
3111 if (aFlag == "-mousestart"
3112 || aFlag == "-mousefrom")
3113 {
3114 hasFlags = Standard_True;
3115 if (anArgIter + 2 >= theArgNb)
3116 {
3117 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3118 return 1;
3119 }
3120
3121 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3122 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3123 aView->StartRotation (anX, anY);
3124 }
3125 else if (aFlag == "-mousemove")
3126 {
3127 hasFlags = Standard_True;
3128 if (anArgIter + 2 >= theArgNb)
3129 {
3130 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3131 return 1;
3132 }
3133
3134 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3135 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3136 aView->Rotation (anX, anY);
3137 }
3138 else if (theArgNb != 4
3139 && theArgNb != 7)
3140 {
3141 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3142 return 1;
3143 }
3144 }
3145
3146 if (hasFlags)
3147 {
7fd59977 3148 return 0;
4af098ba 3149 }
3150 else if (theArgNb == 4)
3151 {
3152 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3153 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3154 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3155 aView->Rotate (anAX, anAY, anAZ);
3156 return 0;
3157 }
3158 else if (theArgNb == 7)
3159 {
3160 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3161 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3162 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3163
3164 Standard_Real anX = Draw::Atof (theArgVec[4]);
3165 Standard_Real anY = Draw::Atof (theArgVec[5]);
3166 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3167
3168 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
7fd59977 3169 return 0;
7fd59977 3170 }
4af098ba 3171
3172 std::cout << "Error: Invalid number of arguments\n";
3173 return 1;
7fd59977 3174}
3175
3176//==============================================================================
3177//function : VZoom
3178//purpose : View zoom in / out (relative to current zoom)
3179//==============================================================================
3180
3181static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3182 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3183 if ( V3dView.IsNull() ) {
3184 return 1;
3185 }
3186
3187 if ( argc == 2 ) {
91322f44 3188 Standard_Real coef = Draw::Atof(argv[1]);
7fd59977 3189 if ( coef <= 0.0 ) {
3190 di << argv[1] << "Invalid value" << "\n";
3191 return 1;
3192 }
91322f44 3193 V3dView->SetZoom( Draw::Atof(argv[1]) );
7fd59977 3194 return 0;
3195 } else {
3196 di << argv[0] << " Invalid number of arguments" << "\n";
3197 return 1;
3198 }
3199}
3200
3201//==============================================================================
3202//function : VPan
3203//purpose : View panning (in pixels)
3204//==============================================================================
3205
3206static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3207 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3208 if ( V3dView.IsNull() ) return 1;
3209
3210 if ( argc == 3 ) {
91322f44 3211 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
7fd59977 3212 return 0;
3213 } else {
3214 di << argv[0] << " Invalid number of arguments" << "\n";
3215 return 1;
3216 }
3217}
3218
49e1a5c7 3219//==============================================================================
3220//function : VPlace
3221//purpose : Place the point (in pixels) at the center of the window
3222//==============================================================================
3223static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3224{
3225 Handle(V3d_View) aView = ViewerTest::CurrentView();
3226 if (aView.IsNull())
3227 {
3228 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3229 return 1;
3230 }
3231
3232 if (theArgNb != 3)
3233 {
3234 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3235 return 1;
3236 }
3237
3238 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3239
3240 return 0;
3241}
7fd59977 3242
3243//==============================================================================
3244//function : VExport