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