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