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