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