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