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