0024739: TKOpenGl - port ray-tracing from OpenCL to GLSL for better integration and...
[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
7fd59977 17#ifdef HAVE_CONFIG_H
e276548b 18 #include <config.h>
7fd59977 19#endif
20
58655684 21#include <OpenGl_GlCore20.hxx>
0a768f56 22#include <AIS_Shape.hxx>
23#include <AIS_Drawer.hxx>
24#include <AIS_InteractiveObject.hxx>
25#include <AIS_ListOfInteractive.hxx>
26#include <AIS_ListIteratorOfListOfInteractive.hxx>
27#include <DBRep.hxx>
2bd4c032 28#include <Graphic3d_AspectMarker3d.hxx>
7fd59977 29#include <Graphic3d_ExportFormat.hxx>
269294d6 30#include <Graphic3d_NameOfTextureEnv.hxx>
31#include <Graphic3d_TextureEnv.hxx>
32#include <Graphic3d_TextureParams.hxx>
33#include <Graphic3d_TypeOfTextureFilter.hxx>
4269bd1b 34#include <Graphic3d_AspectFillArea3d.hxx>
7fd59977 35#include <ViewerTest.hxx>
36#include <ViewerTest_EventManager.hxx>
4754e164 37#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
4269bd1b 38#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
7fd59977 39#include <Visual3d_View.hxx>
25289ec1 40#include <Visual3d_ViewManager.hxx>
12381341 41#include <V3d_AmbientLight.hxx>
42#include <V3d_DirectionalLight.hxx>
25289ec1 43#include <V3d_LayerMgr.hxx>
12381341 44#include <V3d_LayerMgrPointer.hxx>
45#include <V3d_PositionalLight.hxx>
46#include <V3d_SpotLight.hxx>
18d715bd 47#include <NCollection_DoubleMap.hxx>
48#include <NCollection_List.hxx>
49#include <NCollection_Vector.hxx>
7fd59977 50#include <NIS_View.hxx>
51#include <NIS_Triangulated.hxx>
52#include <NIS_InteractiveContext.hxx>
53#include <AIS_InteractiveContext.hxx>
54#include <Draw_Interpretor.hxx>
55#include <Draw.hxx>
56#include <Draw_Appli.hxx>
7edf74fd 57#include <Aspect_PrintAlgo.hxx>
692613e5 58#include <Image_AlienPixMap.hxx>
58655684 59#include <OpenGl_GraphicDriver.hxx>
208e6839 60#include <OSD_Timer.hxx>
900f7229 61#include <TColStd_HSequenceOfAsciiString.hxx>
59f45b7c 62#include <TColStd_SequenceOfInteger.hxx>
4754e164 63#include <TColStd_HSequenceOfReal.hxx>
64#include <TColgp_Array1OfPnt2d.hxx>
197ac94e 65#include <TColStd_MapOfAsciiString.hxx>
20637bd2 66#include <Visual3d_LayerItem.hxx>
20637bd2 67#include <Aspect_TypeOfLine.hxx>
692613e5 68#include <Image_Diff.hxx>
dc3fe572 69#include <Aspect_DisplayConnection.hxx>
70#include <Graphic3d.hxx>
4269bd1b 71#include <gp_Pnt.hxx>
72#include <gp_Dir.hxx>
73#include <gp_Pln.hxx>
74#include <PrsMgr_PresentableObject.hxx>
75#include <Graphic3d_ClipPlane.hxx>
76#include <NCollection_DataMap.hxx>
77#include <Graphic3d_Texture2Dmanual.hxx>
78#include <Prs3d_ShadingAspect.hxx>
7fd59977 79
25289ec1 80#ifdef WNT
81#undef DrawText
82#endif
83
84#include <Visual3d_Layer.hxx>
692613e5 85#include <cstdlib>
25289ec1 86
58655684 87#if defined(_WIN32)
4fe56619 88 #include <WNT_WClass.hxx>
89 #include <WNT_Window.hxx>
90
91 #if defined(_MSC_VER)
92 #define _CRT_SECURE_NO_DEPRECATE
93 #pragma warning (disable:4996)
94 #endif
95#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
4fe56619 96 #include <Cocoa_Window.hxx>
7fd59977 97#else
4fe56619 98 #include <Xw_Window.hxx>
99 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
100 #include <X11/Xutil.h>
101 #include <tk.h>
7fd59977 102#endif
103
b514beda 104// Auxiliary definitions
105static const char THE_KEY_DELETE = 127;
7fd59977 106
107//==============================================================================
108// VIEWER GLOBAL VARIABLES
109//==============================================================================
110
111Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
b514beda 112Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
7fd59977 113
114Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
115extern const Handle(NIS_InteractiveContext)& TheNISContext();
4754e164 116extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
7fd59977 117
b514beda 118extern int VErase (Draw_Interpretor& theDI,
119 Standard_Integer theArgNb,
120 const char** theArgVec);
121
58655684 122#if defined(_WIN32)
7fd59977 123static Handle(WNT_Window)& VT_GetWindow() {
124 static Handle(WNT_Window) WNTWin;
125 return WNTWin;
126}
4fe56619 127#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
4fe56619 128static Handle(Cocoa_Window)& VT_GetWindow()
129{
130 static Handle(Cocoa_Window) aWindow;
131 return aWindow;
132}
133extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
18d715bd 134extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
135extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
136
7fd59977 137#else
7fd59977 138static Handle(Xw_Window)& VT_GetWindow(){
139 static Handle(Xw_Window) XWWin;
140 return XWWin;
141}
7fd59977 142
143static void VProcessEvents(ClientData,int);
144#endif
145
18d715bd 146static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
147{
148 static Handle(Aspect_DisplayConnection) aDisplayConnection;
149 return aDisplayConnection;
150}
151
152static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
153{
154 GetDisplayConnection() = theDisplayConnection;
155}
156
58655684 157#if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
18d715bd 158Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
dc3fe572 159{
0ebaa4db 160 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
58655684 161#if defined(_WIN32)
18d715bd 162 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
163 if (!aWindow.IsNull())
164 return aWindow->HWindow();
165#elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
166 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
167 if (!aWindow.IsNull())
168 return aWindow->XWindow();
169#endif
170 return aWindowHandle;
dc3fe572 171}
18d715bd 172#endif
dc3fe572 173
de75ed09 174static Standard_Boolean MyHLRIsOn = Standard_False;
7fd59977 175
18d715bd 176NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
58655684 177static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
18d715bd 178static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
58655684 179static OpenGl_Caps ViewerTest_myDefaultCaps;
18d715bd 180
7fd59977 181#define ZCLIPWIDTH 1.
182
183static void OSWindowSetup();
184
185//==============================================================================
186// EVENT GLOBAL VARIABLES
187//==============================================================================
188
189static int Start_Rot = 0;
190static int ZClipIsOn = 0;
4fe56619 191int X_Motion = 0; // Current cursor position
192int Y_Motion = 0;
193int X_ButtonPress = 0; // Last ButtonPress position
194int Y_ButtonPress = 0;
195Standard_Boolean IsDragged = Standard_False;
8abada55 196Standard_Boolean DragFirst = Standard_False;
7fd59977 197
198//==============================================================================
199
200#ifdef WNT
201static LRESULT WINAPI ViewerWindowProc(
202 HWND hwnd,
203 UINT uMsg,
204 WPARAM wParam,
205 LPARAM lParam );
206static LRESULT WINAPI AdvViewerWindowProc(
207 HWND hwnd,
208 UINT uMsg,
209 WPARAM wParam,
210 LPARAM lParam );
211#endif
212
213
214//==============================================================================
215//function : WClass
216//purpose :
217//==============================================================================
218
219const Handle(MMgt_TShared)& ViewerTest::WClass()
220{
221 static Handle(MMgt_TShared) theWClass;
58655684 222#if defined(_WIN32)
4fe56619 223 if (theWClass.IsNull())
224 {
7fd59977 225 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
226 CS_VREDRAW | CS_HREDRAW, 0, 0,
227 ::LoadCursor (NULL, IDC_ARROW));
228 }
229#endif
230 return theWClass;
231}
232
233//==============================================================================
18d715bd 234//function : CreateName
235//purpose : Create numerical name for new object in theMap
236//==============================================================================
237template <typename ObjectType>
238TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
239 const TCollection_AsciiString& theDefaultString)
240{
241 if (theObjectMap.IsEmpty())
242 return theDefaultString + TCollection_AsciiString(1);
243
244 Standard_Integer aNextKey = 1;
245 Standard_Boolean isFound = Standard_False;
246 while (!isFound)
247 {
248 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
249 // Look for objects with default names
250 if (theObjectMap.IsBound1(aStringKey))
251 {
252 aNextKey++;
253 }
254 else
255 isFound = Standard_True;
256 }
257
258 return theDefaultString + TCollection_AsciiString(aNextKey);
259}
260
261//==============================================================================
262//structure : ViewerTest_Names
263//purpose : Allow to operate with full view name: driverName/viewerName/viewName
264//==============================================================================
265struct ViewerTest_Names
266{
267private:
268 TCollection_AsciiString myDriverName;
269 TCollection_AsciiString myViewerName;
270 TCollection_AsciiString myViewName;
271
272public:
273
274 const TCollection_AsciiString& GetDriverName () const
275 {
276 return myDriverName;
277 }
278 void SetDriverName (const TCollection_AsciiString& theDriverName)
279 {
280 myDriverName = theDriverName;
281 }
282 const TCollection_AsciiString& GetViewerName () const
283 {
284 return myViewerName;
285 }
286 void SetViewerName (const TCollection_AsciiString& theViewerName)
287 {
288 myViewerName = theViewerName;
289 }
290 const TCollection_AsciiString& GetViewName () const
291 {
292 return myViewName;
293 }
294 void SetViewName (const TCollection_AsciiString& theViewName)
295 {
296 myViewName = theViewName;
297 }
298
299 //===========================================================================
300 //function : Constructor for ViewerTest_Names
301 //purpose : Get view, viewer, driver names from custom string
302 //===========================================================================
303
304 ViewerTest_Names (const TCollection_AsciiString& theInputString)
305 {
306 TCollection_AsciiString aName(theInputString);
307 if (theInputString.IsEmpty())
308 {
309 // Get current configuration
310 if (ViewerTest_myDrivers.IsEmpty())
311 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
312 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
313 else
314 myDriverName = ViewerTest_myDrivers.Find2
315 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
316
317 if(ViewerTest_myContexts.IsEmpty())
318 {
319 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
320 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
321 }
322 else
323 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
324
325 myViewName = CreateName <Handle(V3d_View)>
326 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
327 }
328 else
329 {
330 // There is at least view name
331 Standard_Integer aParserNumber = 0;
332 for (Standard_Integer i = 0; i < 3; ++i)
333 {
334 Standard_Integer aParserPos = aName.SearchFromEnd("/");
335 if(aParserPos != -1)
336 {
337 aParserNumber++;
338 aName.Split(aParserPos-1);
339 }
340 else
341 break;
342 }
343 if (aParserNumber == 0)
344 {
345 // Only view name
346 if (!ViewerTest::GetAISContext().IsNull())
347 {
348 myDriverName = ViewerTest_myDrivers.Find2
349 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
350 myViewerName = ViewerTest_myContexts.Find2
351 (ViewerTest::GetAISContext());
352 }
353 else
354 {
355 // There is no opened contexts here, need to create names for viewer and driver
356 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
357 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
358
359 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
360 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
361 }
362 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
363 }
364 else if (aParserNumber == 1)
365 {
366 // Here is viewerName/viewName
367 if (!ViewerTest::GetAISContext().IsNull())
368 myDriverName = ViewerTest_myDrivers.Find2
369 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
370 else
371 {
372 // There is no opened contexts here, need to create name for driver
373 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
374 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
375 }
376 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
377
378 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
379 }
380 else
381 {
382 //Here is driverName/viewerName/viewName
383 myDriverName = TCollection_AsciiString(aName);
384
385 TCollection_AsciiString aViewerName(theInputString);
386 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
387 myViewerName = TCollection_AsciiString(aViewerName);
388
389 myViewName = TCollection_AsciiString(theInputString);
390 }
391 }
392 }
393};
394
395//==============================================================================
396//function : FindContextByView
397//purpose : Find AIS_InteractiveContext by View
398//==============================================================================
399
400Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
401{
402 Handle(AIS_InteractiveContext) anAISContext;
403
404 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
405 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
406 {
407 if (anIter.Value()->CurrentViewer() == theView->Viewer())
408 return anIter.Key2();
409 }
410 return anAISContext;
411}
412
413
414//==============================================================================
415//function : SetWindowTitle
416//purpose : Set window title
417//==============================================================================
418
419void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
420 Standard_CString theTitle)
421{
58655684 422#if defined(_WIN32)
18d715bd 423 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
424 theTitle);
425#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
426 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
427#else
428 if(GetDisplayConnection()->GetDisplay())
429 {
430 Window aWindow =
431 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
432 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
433 }
434#endif
435}
436
437//==============================================================================
438//function : IsWindowOverlapped
439//purpose : Check if theWindow overlapp another view
440//==============================================================================
441
442Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
443 const Standard_Integer thePxTop,
444 const Standard_Integer thePxRight,
445 const Standard_Integer thePxBottom,
446 TCollection_AsciiString& theViewId)
447{
448 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
449 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
450 {
451 Standard_Integer aTop = 0,
452 aLeft = 0,
453 aRight = 0,
454 aBottom = 0;
455 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
456 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
457 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
458 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
459 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
460 {
461 theViewId = anIter.Key1();
462 return Standard_True;
463 }
464 }
465 return Standard_False;
466}
467
468// Workaround: to create and delete non-orthographic views outside ViewerTest
469void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
470{
471 ViewerTest_myViews.UnBind1 (theName);
472}
473
474void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
475 const Handle(V3d_View)& theView)
476{
477 ViewerTest_myViews.Bind (theName, theView);
478}
479
480TCollection_AsciiString ViewerTest::GetCurrentViewName ()
481{
482 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
483}
484//==============================================================================
7fd59977 485//function : ViewerInit
486//purpose : Create the window viewer and initialize all the global variable
487//==============================================================================
488
18d715bd 489TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
490 const Standard_Integer thePxTop,
491 const Standard_Integer thePxWidth,
492 const Standard_Integer thePxHeight,
493 Standard_CString theViewName,
494 Standard_CString theDisplayName)
7fd59977 495{
8c3c9904 496 // Default position and dimension of the viewer window.
4fe56619 497 // Note that left top corner is set to be sufficiently small to have
8c3c9904 498 // window fit in the small screens (actual for remote desktops, see #23003).
4fe56619 499 // The position corresponds to the window's client area, thus some
8c3c9904 500 // gap is added for window frame to be visible.
501 Standard_Integer aPxLeft = 20;
502 Standard_Integer aPxTop = 40;
7fd59977 503 Standard_Integer aPxWidth = 409;
504 Standard_Integer aPxHeight = 409;
18d715bd 505 Standard_Boolean toCreateViewer = Standard_False;
506
58655684 507 Handle(OpenGl_GraphicDriver) aGraphicDriver;
18d715bd 508 ViewerTest_Names aViewNames(theViewName);
509 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
510 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
511
512 if (thePxLeft != 0)
513 aPxLeft = thePxLeft;
514 if (thePxTop != 0)
515 aPxTop = thePxTop;
516 if (thePxWidth != 0)
517 aPxWidth = thePxWidth;
518 if (thePxHeight != 0)
7fd59977 519 aPxHeight = thePxHeight;
4269bd1b 520
18d715bd 521 // Get graphic driver (create it or get from another view)
522 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
523 {
524 // Get connection string
58655684 525 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
18d715bd 526 TCollection_AsciiString aDisplayName(theDisplayName);
498ce76b 527 if (!aDisplayName.IsEmpty())
18d715bd 528 SetDisplayConnection (new Aspect_DisplayConnection ());
529 else
530 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
18d715bd 531 #else
498ce76b 532 (void)theDisplayName; // avoid warning on unused argument
18d715bd 533 SetDisplayConnection (new Aspect_DisplayConnection ());
534 #endif
65993a95 535 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
58655684 536 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
18d715bd 537 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
538 toCreateViewer = Standard_True;
539 }
540 else
541 {
58655684 542 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
7fd59977 543 }
544
18d715bd 545 //Dispose the window if input parameters are default
546 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
7fd59977 547 {
18d715bd 548 Standard_Integer aTop = 0,
549 aLeft = 0,
550 aRight = 0,
551 aBottom = 0,
552 aScreenWidth = 0,
553 aScreenHeight = 0;
554
555 // Get screen resolution
556#if defined(_WIN32) || defined(__WIN32__)
557 RECT aWindowSize;
558 GetClientRect(GetDesktopWindow(), &aWindowSize);
559 aScreenHeight = aWindowSize.bottom;
560 aScreenWidth = aWindowSize.right;
561#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
562 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
563#else
564 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
565 aScreenWidth = WidthOfScreen(aScreen);
566 aScreenHeight = HeightOfScreen(aScreen);
567#endif
568
569 TCollection_AsciiString anOverlappedViewId("");
773f53f1 570
571 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
dc3fe572 572 {
18d715bd 573 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
574
575 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
576 && aRight + 2*aPxWidth + 40 > aScreenWidth)
577 {
578 if (aBottom + aPxHeight + 40 > aScreenHeight)
579 {
580 aPxLeft = 20;
581 aPxTop = 40;
582 break;
583 }
584 aPxLeft = 20;
585 aPxTop = aBottom + 40;
586 }
587 else
588 aPxLeft = aRight + 20;
dc3fe572 589 }
18d715bd 590 }
591
592 // Get viewer name
593 TCollection_AsciiString aTitle("3D View - ");
594 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
595
596 // Change name of current active window
597 if (!ViewerTest::CurrentView().IsNull())
598 {
599 TCollection_AsciiString aTitle("3D View - ");
600 aTitle = aTitle
601 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
602 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
603 }
604
605 // Create viewer
eb4320f2 606 Handle(V3d_Viewer) a3DViewer;
18d715bd 607 // If it's the single view, we first look for empty context
608 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
609 {
610 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
611 anIter(ViewerTest_myContexts);
612 if (anIter.More())
613 ViewerTest::SetAISContext (anIter.Value());
614 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
18d715bd 615 }
616 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
617 {
618 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
619 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
18d715bd 620 }
eb4320f2 621 else if (a3DViewer.IsNull())
18d715bd 622 {
623 toCreateViewer = Standard_True;
624 TCollection_ExtendedString NameOfWindow("Viewer3D");
625 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
626
627 NameOfWindow = TCollection_ExtendedString("Collector");
18d715bd 628
629 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
18d715bd 630 }
631
632 // AIS context setup
633 if (ViewerTest::GetAISContext().IsNull() ||
634 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
635 {
e79a94b9 636 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
18d715bd 637 ViewerTest::SetAISContext (aContext);
638 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
639 }
640 else
e79a94b9 641 {
18d715bd 642 ViewerTest::ResetEventManager();
e79a94b9 643 }
18d715bd 644
645 // Create window
e79a94b9 646#if defined(_WIN32)
647 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
648 Handle(WNT_WClass)::DownCast (WClass()),
649 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
650 aPxLeft, aPxTop,
651 aPxWidth, aPxHeight,
652 Quantity_NOC_BLACK);
4fe56619 653#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
e79a94b9 654 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
655 aPxLeft, aPxTop,
656 aPxWidth, aPxHeight);
657 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
7fd59977 658#else
e79a94b9 659 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
660 aTitle.ToCString(),
661 aPxLeft, aPxTop,
662 aPxWidth, aPxHeight);
7fd59977 663#endif
18d715bd 664 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
7fd59977 665
18d715bd 666 // NIS setup
667 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
4269bd1b 668
18d715bd 669 ViewerTest::CurrentView(aView);
670 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
671 TheNISContext()->AttachView (aView);
7fd59977 672
18d715bd 673 // Setup for X11 or NT
674 OSWindowSetup();
7fd59977 675
18d715bd 676 // Set parameters for V3d_View and V3d_Viewer
677 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
678 aV3dView->SetComputedMode(Standard_False);
679 MyHLRIsOn = aV3dView->ComputedMode();
680 aV3dView->SetZClippingDepth(0.5);
681 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
7fd59977 682
18d715bd 683 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
684 if (toCreateViewer)
685 {
7fd59977 686 a3DViewer->SetDefaultLights();
687 a3DViewer->SetLightOn();
18d715bd 688 }
7fd59977 689
e79a94b9 690 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
4fe56619 691 #if TCL_MAJOR_VERSION < 8
18d715bd 692 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 693 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
4fe56619 694 #else
18d715bd 695 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 696 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
4fe56619 697 #endif
698 #endif
7fd59977 699
7fd59977 700 VT_GetWindow()->Map();
4269bd1b 701
18d715bd 702 // Set the handle of created view in the event manager
703 ViewerTest::ResetEventManager();
704
4fe56619 705 ViewerTest::CurrentView()->Redraw();
18d715bd 706
707 aView.Nullify();
708 a3DViewer.Nullify();
18d715bd 709
710 return aViewNames.GetViewName();
711}
712
713//==============================================================================
4269bd1b 714//function : RedrawAllViews
715//purpose : Redraw all created views
716//==============================================================================
717void ViewerTest::RedrawAllViews()
718{
719 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
720 for (; aViewIt.More(); aViewIt.Next())
721 {
722 const Handle(V3d_View)& aView = aViewIt.Key2();
723 aView->Redraw();
724 }
725}
726
727//==============================================================================
7fd59977 728//function : Vinit
729//purpose : Create the window viewer and initialize all the global variable
e79a94b9 730// Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
7fd59977 731//==============================================================================
732
18d715bd 733static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 734{
e79a94b9 735 if (theArgsNb > 9)
18d715bd 736 {
e79a94b9 737 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
738 << "Type help for more information.\n";
18d715bd 739 return 1;
740 }
18d715bd 741
e79a94b9 742 TCollection_AsciiString aViewName, aDisplayName;
743 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
744 TCollection_AsciiString aName, aValue;
745 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
18d715bd 746 {
e79a94b9 747 const TCollection_AsciiString anArg = theArgVec[anArgIt];
748 TCollection_AsciiString anArgCase = anArg;
749 anArgCase.UpperCase();
1d7ca641 750 if (ViewerTest::SplitParameter (anArg, aName, aValue))
18d715bd 751 {
e79a94b9 752 aName.UpperCase();
753 if (aName.IsEqual ("NAME"))
18d715bd 754 {
755 aViewName = aValue;
756 }
e79a94b9 757 else if (aName.IsEqual ("L")
758 || aName.IsEqual ("LEFT"))
759 {
18d715bd 760 aPxLeft = aValue.IntegerValue();
e79a94b9 761 }
762 else if (aName.IsEqual ("T")
763 || aName.IsEqual ("TOP"))
764 {
18d715bd 765 aPxTop = aValue.IntegerValue();
e79a94b9 766 }
767 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
768 else if (aName.IsEqual ("DISP")
769 || aName.IsEqual ("DISPLAY"))
770 {
18d715bd 771 aDisplayName = aValue;
e79a94b9 772 }
773 #endif
774 else if (aName.IsEqual ("W")
775 || aName.IsEqual ("WIDTH"))
776 {
18d715bd 777 aPxWidth = aValue.IntegerValue();
e79a94b9 778 }
779 else if (aName.IsEqual ("H")
780 || aName.IsEqual ("HEIGHT"))
781 {
18d715bd 782 aPxHeight = aValue.IntegerValue();
e79a94b9 783 }
18d715bd 784 else
785 {
e79a94b9 786 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
18d715bd 787 }
788 }
e79a94b9 789 else if (aViewName.IsEmpty())
790 {
791 aViewName = anArg;
792 }
793 else
794 {
795 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
796 }
18d715bd 797 }
798
799 ViewerTest_Names aViewNames (aViewName);
e79a94b9 800 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
18d715bd 801 {
e79a94b9 802 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
803 theDi.Eval (aCommand.ToCString());
18d715bd 804 return 0;
805 }
806
807 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
808 aViewName.ToCString(),
809 aDisplayName.ToCString());
e79a94b9 810 theDi << aViewId;
7fd59977 811 return 0;
812}
813
814//==============================================================================
0a768f56 815//function : VHLR
816//purpose : hidden lines removal algorithm
e9224045 817//draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
0a768f56 818//==============================================================================
819
820static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
821{
822 if (ViewerTest::CurrentView().IsNull())
823 {
824 di << argv[0] << ": Call vinit before this command, please.\n";
825 return 1;
826 }
827
e9224045 828 if (argc < 2)
0a768f56 829 {
830 di << argv[0] << ": Wrong number of command arguments.\n"
831 << "Type help " << argv[0] << " for more information.\n";
832 return 1;
833 }
834
e9224045 835 // Enable or disable HLR mode.
0a768f56 836 Standard_Boolean isHLROn =
837 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
838
e9224045 839 if (isHLROn != MyHLRIsOn)
0a768f56 840 {
e9224045 841 MyHLRIsOn = isHLROn;
842 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
0a768f56 843 }
844
e9224045 845 // Show or hide hidden lines in HLR mode.
846 Standard_Boolean isCurrentShowHidden
847 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
848
849 Standard_Boolean isShowHidden =
850 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
851 : isCurrentShowHidden;
852
853
854 if (isShowHidden != isCurrentShowHidden)
855 {
856 if (isShowHidden)
857 {
858 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
859 }
860 else
861 {
862 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
863 }
864
865 // Redisplay shapes.
866 if (MyHLRIsOn)
867 {
868 AIS_ListOfInteractive aListOfShapes;
869 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
870
871 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
872 {
873 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
874 if (aShape.IsNull())
875 {
876 continue;
877 }
878 aShape->Redisplay();
879 }
880 }
881 }
0a768f56 882
e9224045 883 ViewerTest::CurrentView()->Update();
0a768f56 884 return 0;
885}
886
887//==============================================================================
888//function : VHLRType
889//purpose : change type of using HLR algorithm
890//==============================================================================
891
892static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
893{
894 if (ViewerTest::CurrentView().IsNull())
895 {
896 di << argv[0] << ": Call vinit before this command, please.\n";
897 return 1;
898 }
899
900 if (argc < 2)
901 {
902 di << argv[0] << ": Wrong number of command arguments.\n"
903 << "Type help " << argv[0] << " for more information.\n";
904 return 1;
905 }
906
907 Prs3d_TypeOfHLR aTypeOfHLR =
908 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
909
910 if (argc == 2)
911 {
912 AIS_ListOfInteractive aListOfShapes;
913 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
914 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
915 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
916 anIter.More(); anIter.Next())
917 {
918 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
919 if (aShape.IsNull())
920 continue;
921 if (aShape->TypeOfHLR() != aTypeOfHLR)
922 aShape->SetTypeOfHLR (aTypeOfHLR);
923 if (MyHLRIsOn)
924 aShape->Redisplay();
925 }
926 ViewerTest::CurrentView()->Update();
927 return 0;
928 }
929 else
930 {
931 for (Standard_Integer i = 2; i < argc; ++i)
932 {
933 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
934 TCollection_AsciiString aName (argv[i]);
935
936 if (!aMap.IsBound2 (aName))
937 {
938 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
939 continue;
940 }
941 Handle(AIS_Shape) anAISObject =
942 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
943 if (anAISObject.IsNull())
944 continue;
945 anAISObject->SetTypeOfHLR (aTypeOfHLR);
946 if (MyHLRIsOn)
947 anAISObject->Redisplay();
948 }
949 ViewerTest::CurrentView()->Update();
950 }
951
952 return 0;
953}
954
955//==============================================================================
18d715bd 956//function : FindViewIdByWindowHandle
957//purpose : Find theView Id in the map of views by window handle
958//==============================================================================
959#if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
960TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
961{
962 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
963 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
964 {
965 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
966 if (aWindowHandle == theWindowHandle)
967 return anIter.Key1();
968 }
969 return TCollection_AsciiString("");
970}
971#endif
972
973//==============================================================================
974//function : ActivateView
975//purpose : Make the view active
976//==============================================================================
977
978void ActivateView (const TCollection_AsciiString& theViewName)
979{
980 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
981 if (!aView.IsNull())
982 {
983 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
984 if (!anAISContext.IsNull())
985 {
986 if (!ViewerTest::CurrentView().IsNull())
987 {
988 TCollection_AsciiString aTitle("3D View - ");
989 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
990 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
991 }
992
993 ViewerTest::CurrentView (aView);
994 // Update degenerate mode
995 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
996 ViewerTest::SetAISContext (anAISContext);
997 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
998 aTitle = aTitle + theViewName + "(*)";
999 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1000#if defined(_WIN32) || defined(__WIN32__)
1001 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1002#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1003 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1004#else
1005 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1006#endif
1007 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1008 ViewerTest::CurrentView()->Redraw();
1009 }
1010 }
1011}
1012
1013//==============================================================================
1014//function : RemoveView
1015//purpose : Close and remove view from display, clear maps if neccessary
1016//==============================================================================
1017void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1018{
1019 if (!ViewerTest_myViews.IsBound1(theViewName))
1020 {
1021 cout << "Wrong view name\n";
1022 return;
1023 }
1024
1025 // Activate another view if it's active now
1026 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1027 {
1028 if (ViewerTest_myViews.Extent() > 1)
1029 {
1030 TCollection_AsciiString aNewViewName;
1031 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1032 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1033 if (anIter.Key1() != theViewName)
1034 {
1035 aNewViewName = anIter.Key1();
1036 break;
1037 }
1038 ActivateView (aNewViewName);
1039 }
1040 else
1041 {
1042 Handle(V3d_View) anEmptyView;
1043#if defined(_WIN32) || defined(__WIN32__)
1044 Handle(WNT_Window) anEmptyWindow;
1045#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1046 Handle(Cocoa_Window) anEmptyWindow;
1047#else
1048 Handle(Xw_Window) anEmptyWindow;
1049#endif
1050 VT_GetWindow() = anEmptyWindow;
1051 ViewerTest::CurrentView (anEmptyView);
1052 if (isContextRemoved)
1053 {
1054 Handle(AIS_InteractiveContext) anEmptyContext;
1055 ViewerTest::SetAISContext(anEmptyContext);
1056 }
1057 }
1058 }
1059
1060 // Delete view
1061 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1062 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1063
1064 // Remove view resources
1065 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1066 ViewerTest_myViews.UnBind1(theViewName);
1067 aView->Remove();
1068
1069#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1070 XFlush (GetDisplayConnection()->GetDisplay());
1071#endif
1072
1073 // Keep context opened only if the closed view is last to avoid
1074 // unused empty contexts
1075 if (!aCurrentContext.IsNull())
1076 {
1077 // Check if there are more difined views in the viewer
1078 aCurrentContext->CurrentViewer()->InitDefinedViews();
1079 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1080 {
1081 // Remove driver if there is no viewers that use it
1082 Standard_Boolean isRemoveDriver = Standard_True;
1083 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1084 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1085 {
1086 if (aCurrentContext != anIter.Key2() &&
1087 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1088 {
1089 isRemoveDriver = Standard_False;
1090 break;
1091 }
1092 }
1093 if(isRemoveDriver)
1094 {
1095 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1096 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1097 #if TCL_MAJOR_VERSION < 8
1098 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1099 #else
1100 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1101 #endif
1102 #endif
1103 }
1104
1105 ViewerTest_myContexts.UnBind2(aCurrentContext);
1106 }
1107 }
1108 cout << "3D View - " << theViewName << " was deleted.\n";
1109
1110}
1111
1112//==============================================================================
1113//function : VClose
1114//purpose : Remove the view defined by its name
1115//==============================================================================
1116
d0cc1cb7 1117static int VClose (Draw_Interpretor& /*theDi*/,
1118 Standard_Integer theArgsNb,
1119 const char** theArgVec)
18d715bd 1120{
18d715bd 1121 NCollection_List<TCollection_AsciiString> aViewList;
d0cc1cb7 1122 if (theArgsNb > 1)
18d715bd 1123 {
d0cc1cb7 1124 TCollection_AsciiString anArg (theArgVec[1]);
1125 anArg.UpperCase();
1126 if (anArg.IsEqual ("ALL")
1127 || anArg.IsEqual ("*"))
1128 {
1129 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1130 anIter.More(); anIter.Next())
1131 {
1132 aViewList.Append (anIter.Key1());
1133 }
1134 if (aViewList.IsEmpty())
1135 {
1136 std::cout << "No view to close\n";
1137 return 0;
1138 }
1139 }
1140 else
18d715bd 1141 {
d0cc1cb7 1142 ViewerTest_Names aViewName (theArgVec[1]);
1143 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1144 {
1145 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1146 return 1;
1147 }
1148 aViewList.Append (aViewName.GetViewName());
18d715bd 1149 }
1150 }
1151 else
1152 {
d0cc1cb7 1153 // close active view
1154 if (ViewerTest::CurrentView().IsNull())
1155 {
1156 std::cerr << "No active view!\n";
1157 return 1;
1158 }
1159 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
18d715bd 1160 }
1161
d0cc1cb7 1162 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
18d715bd 1163 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1164 anIter.More(); anIter.Next())
1165 {
d0cc1cb7 1166 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
18d715bd 1167 }
1168
1169 return 0;
1170}
1171
1172//==============================================================================
1173//function : VActivate
1174//purpose : Activate the view defined by its ID
1175//==============================================================================
1176
1177static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1178{
1179 if (theArgsNb > 2)
1180 {
1181 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1182 << "Usage: " << theArgVec[0] << " ViewID\n";
1183 return 1;
1184 }
1185 if(theArgsNb == 1)
1186 {
1187 theDi.Eval("vviewlist");
1188 return 0;
1189 }
1190
1191 TCollection_AsciiString aNameString(theArgVec[1]);
29cb310a 1192 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
18d715bd 1193 {
1194 TCollection_AsciiString aTitle("3D View - ");
1195 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1196 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1197 Handle(V3d_View) anEmptyView;
1198#if defined(_WIN32) || defined(__WIN32__)
1199 Handle(WNT_Window) anEmptyWindow;
1200#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1201 Handle(Cocoa_Window) anEmptyWindow;
1202#else
1203 Handle(Xw_Window) anEmptyWindow;
1204#endif
1205 VT_GetWindow() = anEmptyWindow;
1206 ViewerTest::CurrentView (anEmptyView);
1207 ViewerTest::ResetEventManager();
1208 theDi << theArgVec[0] << ": all views are inactive\n";
1209 return 0;
1210 }
1211
1212 ViewerTest_Names aViewNames(aNameString);
1213
1214 // Check if this view exists in the viewer with the driver
1215 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1216 {
1217 theDi << "Wrong view name\n";
1218 return 1;
1219 }
1220
1221 // Check if it is active already
1222 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1223 {
1224 theDi << theArgVec[0] << ": the view is active already\n";
1225 return 0;
1226 }
1227
1228 ActivateView (aViewNames.GetViewName());
1229 return 0;
1230}
1231
1232//==============================================================================
1233//function : VViewList
1234//purpose : Print current list of views per viewer and graphic driver ID
1235// shared between viewers
1236//==============================================================================
1237
1238static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1239{
1240 if (theArgsNb > 2)
1241 {
1242 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
29cb310a 1243 << "Usage: " << theArgVec[0] << " name";
18d715bd 1244 return 1;
1245 }
1246 if (ViewerTest_myContexts.Size() < 1)
1247 return 0;
1248
18d715bd 1249 Standard_Boolean isTreeView =
29cb310a 1250 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
18d715bd 1251
1252 if (isTreeView)
1253 theDi << theArgVec[0] <<":\n";
1254
1255 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1256 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1257 {
1258 if (isTreeView)
1259 theDi << aDriverIter.Key1() << ":\n";
1260
1261 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1262 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1263 {
1264 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1265 {
1266 if (isTreeView)
1267 {
1268 TCollection_AsciiString aContextName(aContextIter.Key1());
1269 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1270 }
1271
1272 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1273 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1274 {
1275 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1276 {
1277 TCollection_AsciiString aViewName(aViewIter.Key1());
1278 if (isTreeView)
1279 {
1280 if (aViewIter.Value() == ViewerTest::CurrentView())
1281 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1282 else
1283 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1284 }
1285 else
1286 {
1287 theDi << aViewName << " ";
1288 }
1289 }
1290 }
1291 }
1292 }
1293 }
1294 return 0;
1295}
1296
1297//==============================================================================
4fe56619 1298//function : VT_ProcessKeyPress
7fd59977 1299//purpose : Handle KeyPress event from a CString
1300//==============================================================================
4fe56619 1301void VT_ProcessKeyPress (const char* buf_ret)
7fd59977 1302{
1303 //cout << "KeyPress" << endl;
1304 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1305 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1306 // Letter in alphabetic order
1307
b514beda 1308 if (!strcasecmp (buf_ret, "A"))
1309 {
7fd59977 1310 // AXO
1311 aView->SetProj(V3d_XposYnegZpos);
1312 }
b514beda 1313 else if (!strcasecmp (buf_ret, "D"))
1314 {
7fd59977 1315 // Reset
1316 aView->Reset();
1317 }
b514beda 1318 else if (!strcasecmp (buf_ret, "F"))
1319 {
7fd59977 1320 // FitAll
1321 if (aNisView.IsNull())
1322 aView->FitAll();
1323 else
1324 aNisView->FitAll3d();
1325 }
b514beda 1326 else if (!strcasecmp (buf_ret, "H"))
1327 {
7fd59977 1328 // HLR
1329 cout << "HLR" << endl;
de75ed09 1330 aView->SetComputedMode (!aView->ComputedMode());
1331 MyHLRIsOn = aView->ComputedMode();
7fd59977 1332 }
b514beda 1333 else if (!strcasecmp (buf_ret, "P"))
1334 {
0a768f56 1335 // Type of HLR
1336 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1337 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1338 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1339 else
1340 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1341 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1342 {
1343 AIS_ListOfInteractive aListOfShapes;
1344 aContext->DisplayedObjects(aListOfShapes);
1345 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1346 anIter.More(); anIter.Next())
1347 {
1348 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1349 if (aShape.IsNull())
1350 continue;
1351 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1352 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1353 else
1354 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1355 aShape->Redisplay();
1356 }
1357 }
1358 else
1359 {
1360 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1361 {
1362 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1363 if (aShape.IsNull())
1364 continue;
1365 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1366 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1367 else
1368 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1369 aShape->Redisplay();
1370 }
1371 }
1372
1373 aContext->UpdateCurrentViewer();
4269bd1b 1374
0a768f56 1375 }
b514beda 1376 else if (!strcasecmp (buf_ret, "S"))
1377 {
1378 std::cout << "setup Shaded display mode" << std::endl;
4fe56619 1379
7fd59977 1380 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1381 if(Ctx->NbCurrents()==0 ||
1382 Ctx->NbSelected()==0)
1383 Ctx->SetDisplayMode(AIS_Shaded);
1384 else{
1385 if(Ctx->HasOpenedContext()){
1386 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1387 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1388 }
1389 else{
1390 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1391 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1392 }
1393 Ctx->UpdateCurrentViewer();
1394 }
1395 }
b514beda 1396 else if (!strcasecmp (buf_ret, "U"))
1397 {
41811896 1398 // Unset display mode
b514beda 1399 std::cout << "reset display mode to defaults" << std::endl;
4fe56619 1400
7fd59977 1401 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1402 if(Ctx->NbCurrents()==0 ||
1403 Ctx->NbSelected()==0)
1404 Ctx->SetDisplayMode(AIS_WireFrame);
1405 else{
1406 if(Ctx->HasOpenedContext()){
1407 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1408 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1409 }
1410 else{
1411 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1412 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1413 }
1414 Ctx->UpdateCurrentViewer();
1415 }
1416
1417 }
b514beda 1418 else if (!strcasecmp (buf_ret, "T"))
1419 {
7fd59977 1420 // Top
1421 aView->SetProj(V3d_Zpos);
1422 }
b514beda 1423 else if (!strcasecmp (buf_ret, "B"))
1424 {
41811896 1425 // Bottom
7fd59977 1426 aView->SetProj(V3d_Zneg);
1427 }
b514beda 1428 else if (!strcasecmp (buf_ret, "L"))
1429 {
41811896 1430 // Left
7fd59977 1431 aView->SetProj(V3d_Xneg);
1432 }
b514beda 1433 else if (!strcasecmp (buf_ret, "R"))
1434 {
41811896 1435 // Right
7fd59977 1436 aView->SetProj(V3d_Xpos);
1437 }
b514beda 1438 else if (!strcasecmp (buf_ret, "W"))
1439 {
1440 std::cout << "setup WireFrame display mode" << std::endl;
7fd59977 1441 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1442 if(Ctx->NbCurrents()==0 ||
1443 Ctx->NbSelected()==0)
1444 Ctx->SetDisplayMode(AIS_WireFrame);
1445 else{
1446 if(Ctx->HasOpenedContext()){
1447 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1448 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1449 }
1450 else{
1451 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1452 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1453 }
1454 Ctx->UpdateCurrentViewer();
1455 }
1456 }
b514beda 1457 else if (!strcasecmp (buf_ret, "Z"))
1458 {
7fd59977 1459 // ZCLIP
7fd59977 1460 if ( ZClipIsOn ) {
1461 cout << "ZClipping OFF" << endl;
1462 ZClipIsOn = 0;
1463
1464 aView->SetZClippingType(V3d_OFF);
1465 aView->Redraw();
1466 }
1467 else {
1468 cout << "ZClipping ON" << endl;
1469 ZClipIsOn = 1;
1470
1471 aView->SetZClippingType(V3d_FRONT);
1472 aView->Redraw();
1473 }
1474 }
b514beda 1475 else if (!strcasecmp (buf_ret, ","))
1476 {
7fd59977 1477 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
7fd59977 1478 }
b514beda 1479 else if (!strcasecmp (buf_ret, "."))
1480 {
7fd59977 1481 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1482 }
b514beda 1483 else if (*buf_ret == THE_KEY_DELETE)
1484 {
1485 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1486 if (!aCtx.IsNull()
1487 && aCtx->NbCurrents() > 0
1488 && aCtx->NbSelected() > 0)
1489 {
1490 Draw_Interprete ("verase");
1491 }
1492 }
1493 else
1494 {
1495 // Number
91322f44 1496 Standard_Integer Num = Draw::Atoi(buf_ret);
7fd59977 1497 if(Num>=0 && Num<=7)
1498 ViewerTest::StandardModeActivation(Num);
1499 }
1500}
1501
1502//==============================================================================
4fe56619 1503//function : VT_ProcessExpose
7fd59977 1504//purpose : Redraw the View on an Expose Event
1505//==============================================================================
4fe56619 1506void VT_ProcessExpose()
1507{
1508 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1509 if (!aView3d.IsNull())
1510 {
1511 aView3d->Redraw();
1512 }
7fd59977 1513}
1514
1515//==============================================================================
4fe56619 1516//function : VT_ProcessConfigure
7fd59977 1517//purpose : Resize the View on an Configure Event
1518//==============================================================================
4fe56619 1519void VT_ProcessConfigure()
7fd59977 1520{
4fe56619 1521 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1522 if (aView3d.IsNull())
1523 {
1524 return;
1525 }
1526
1527 aView3d->MustBeResized();
1528 aView3d->Update();
1529 aView3d->Redraw();
7fd59977 1530}
1531
1532//==============================================================================
4fe56619 1533//function : VT_ProcessButton1Press
7fd59977 1534//purpose : Picking
1535//==============================================================================
e79a94b9 1536Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1537 const char** theArgVec,
1538 Standard_Boolean theToPick,
1539 Standard_Boolean theIsShift)
7fd59977 1540{
e79a94b9 1541 if (theToPick)
1542 {
7fd59977 1543 Standard_Real X, Y, Z;
e79a94b9 1544 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
7fd59977 1545
e79a94b9 1546 Draw::Set (theArgVec[1], X);
1547 Draw::Set (theArgVec[2], Y);
1548 Draw::Set (theArgVec[3], Z);
1549 }
7fd59977 1550
e79a94b9 1551 if (theIsShift)
1552 {
1553 ViewerTest::CurrentEventManager()->ShiftSelect();
1554 }
7fd59977 1555 else
e79a94b9 1556 {
1557 ViewerTest::CurrentEventManager()->Select();
1558 }
7fd59977 1559
e79a94b9 1560 return Standard_False;
7fd59977 1561}
1562
1563//==============================================================================
4fe56619 1564//function : VT_ProcessButton1Release
1565//purpose : End selecting
7fd59977 1566//==============================================================================
4fe56619 1567void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1568{
1569 if (IsDragged)
1570 {
1571 IsDragged = Standard_False;
1572 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1573 if (theIsShift)
1574 {
1575 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1576 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1577 }
1578 else
1579 {
1580 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1581 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1582 }
1583 }
1584}
7fd59977 1585
4fe56619 1586//==============================================================================
1587//function : VT_ProcessButton3Press
1588//purpose : Start Rotation
1589//==============================================================================
1590void VT_ProcessButton3Press()
1591{
7fd59977 1592 Start_Rot = 1;
de75ed09 1593 if (MyHLRIsOn)
1594 {
1595 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1596 }
7fd59977 1597 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
7fd59977 1598}
4fe56619 1599
7fd59977 1600//==============================================================================
4fe56619 1601//function : VT_ProcessButton3Release
1602//purpose : End rotation
7fd59977 1603//==============================================================================
4fe56619 1604void VT_ProcessButton3Release()
1605{
1606 if (Start_Rot)
1607 {
7fd59977 1608 Start_Rot = 0;
de75ed09 1609 if (MyHLRIsOn)
1610 {
1611 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1612 }
7fd59977 1613 }
7fd59977 1614}
1615
1616//==============================================================================
1617//function : ProcessZClipMotion
1618//purpose : Zoom
1619//==============================================================================
1620
1621void ProcessZClipMotion()
1622{
1623 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1624 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1625 static Standard_Real CurZPos = 0.;
1626
1627 //Quantity_Length VDX, VDY;
1628 //a3DView->Size(VDX,VDY);
1629 //Standard_Real VDZ = a3DView->ZSize();
1630 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1631
1632 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1633
1634 // Front = Depth + width/2.
1635 Standard_Real D = 0.5;
1636 Standard_Real W = 0.1;
1637
1638 CurZPos += (dx);
1639
1640 D += CurZPos;
1641
1642 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1643
1644 a3DView->SetZClippingType(V3d_OFF);
1645 a3DView->SetZClippingDepth(D);
1646 a3DView->SetZClippingWidth(W);
1647 a3DView->SetZClippingType(V3d_FRONT);
1648
1649 a3DView->Redraw();
1650
1651 X_ButtonPress = X_Motion;
1652 Y_ButtonPress = Y_Motion;
1653 }
1654}
1655
1656//==============================================================================
1657//function : ProcessControlButton1Motion
1658//purpose : Zoom
1659//==============================================================================
1660
900f7229 1661#if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 1662static void ProcessControlButton1Motion()
1663{
1664 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1665
1666 X_ButtonPress = X_Motion;
1667 Y_ButtonPress = Y_Motion;
1668}
900f7229 1669#endif
7fd59977 1670
1671//==============================================================================
4fe56619 1672//function : VT_ProcessControlButton2Motion
1673//purpose : Panning
7fd59977 1674//==============================================================================
4fe56619 1675void VT_ProcessControlButton2Motion()
7fd59977 1676{
197ac94e 1677 Standard_Integer aDx = X_Motion - X_ButtonPress;
1678 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
7fd59977 1679
197ac94e 1680 aDy = -aDy; // Xwindow Y axis is from top to Bottom
7fd59977 1681
197ac94e 1682 ViewerTest::CurrentView()->Pan (aDx, aDy);
7fd59977 1683
1684 X_ButtonPress = X_Motion;
1685 Y_ButtonPress = Y_Motion;
1686}
1687
1688//==============================================================================
4fe56619 1689//function : VT_ProcessControlButton3Motion
7fd59977 1690//purpose : Rotation
1691//==============================================================================
4fe56619 1692void VT_ProcessControlButton3Motion()
7fd59977 1693{
4fe56619 1694 if (Start_Rot)
1695 {
1696 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1697 }
7fd59977 1698}
1699
1700//==============================================================================
4fe56619 1701//function : VT_ProcessMotion
1702//purpose :
7fd59977 1703//==============================================================================
4fe56619 1704void VT_ProcessMotion()
7fd59977 1705{
1706 //pre-hilights detected objects at mouse position
1707
1708 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1709 EM->MoveTo(X_Motion, Y_Motion);
1710}
1711
1712
1713void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1714{
1715 Xpix = X_Motion;Ypix=Y_Motion;
1716}
1717
1718//==============================================================================
44b8f2d6 1719//function : ViewProject: implements VAxo, VTop, VLeft, ...
1720//purpose : Switches to an axonometric, top, left and other views
1721//==============================================================================
1722
1723static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1724{
4fe56619 1725 if ( ViewerTest::CurrentView().IsNull() )
44b8f2d6 1726 {
1727 di<<"Call vinit before this command, please"<<"\n";
1728 return 1;
1729 }
1730
1731 ViewerTest::CurrentView()->SetProj(ori);
1732 return 0;
1733}
1734
1735//==============================================================================
7fd59977 1736//function : VAxo
1737//purpose : Switch to an Axonometric view
1738//Draw arg : No args
1739//==============================================================================
1740
1741static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
44b8f2d6 1742{
1743 return ViewProject(di, V3d_XposYnegZpos);
7fd59977 1744}
1745
1746//==============================================================================
1747//function : VTop
1748//purpose : Switch to a Top View
1749//Draw arg : No args
1750//==============================================================================
1751
1752static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1753{
44b8f2d6 1754 return ViewProject(di, V3d_Zpos);
1755}
7fd59977 1756
44b8f2d6 1757//==============================================================================
1758//function : VBottom
1759//purpose : Switch to a Bottom View
1760//Draw arg : No args
1761//==============================================================================
7fd59977 1762
44b8f2d6 1763static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1764{
1765 return ViewProject(di, V3d_Zneg);
1766}
7fd59977 1767
44b8f2d6 1768//==============================================================================
1769//function : VLeft
1770//purpose : Switch to a Left View
1771//Draw arg : No args
1772//==============================================================================
1773
1774static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1775{
1776 return ViewProject(di, V3d_Ypos);
1777}
1778
1779//==============================================================================
1780//function : VRight
1781//purpose : Switch to a Right View
1782//Draw arg : No args
1783//==============================================================================
1784
1785static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1786{
1787 return ViewProject(di, V3d_Yneg);
1788}
7fd59977 1789
44b8f2d6 1790//==============================================================================
1791//function : VFront
1792//purpose : Switch to a Front View
1793//Draw arg : No args
1794//==============================================================================
1795
1796static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1797{
1798 return ViewProject(di, V3d_Xpos);
1799}
1800
1801//==============================================================================
1802//function : VBack
1803//purpose : Switch to a Back View
1804//Draw arg : No args
1805//==============================================================================
1806
1807static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1808{
1809 return ViewProject(di, V3d_Xneg);
7fd59977 1810}
1811
1812//==============================================================================
1813//function : VHelp
1814//purpose : Dsiplay help on viewer Keyboead and mouse commands
1815//Draw arg : No args
1816//==============================================================================
1817
1818static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1819{
1820
1821 di << "Q : Quit the application" << "\n";
1822
1823 di << "========================="<<"\n";
1824 di << "F : FitAll" << "\n";
1825 di << "T : TopView" << "\n";
41811896 1826 di << "B : BottomView" << "\n";
1827 di << "R : RightView" << "\n";
1828 di << "L : LeftView" << "\n";
7fd59977 1829 di << "A : AxonometricView" << "\n";
41811896 1830 di << "D : ResetView" << "\n";
7fd59977 1831
1832 di << "========================="<<"\n";
1833 di << "S : Shading" << "\n";
1834 di << "W : Wireframe" << "\n";
1835 di << "H : HidelLineRemoval" << "\n";
41811896 1836 di << "U : Unset display mode" << "\n";
b514beda 1837 di << "Delete : Remove selection from viewer" << "\n";
7fd59977 1838
1839 di << "========================="<<"\n";
1840 di << "Selection mode "<<"\n";
1841 di << "0 : Shape" <<"\n";
1842 di << "1 : Vertex" <<"\n";
1843 di << "2 : Edge" <<"\n";
1844 di << "3 : Wire" <<"\n";
1845 di << "4 : Face" <<"\n";
1846 di << "5 : Shell" <<"\n";
1847 di << "6 : Solid" <<"\n";
1848 di << "7 : Compound" <<"\n";
1849
41811896 1850 di << "========================="<<"\n";
1851 di << "Z : Switch Z clipping On/Off" << "\n";
1852 di << ", : Hilight next detected" << "\n";
1853 di << ". : Hilight previous detected" << "\n";
7fd59977 1854
1855 return 0;
1856}
1857
7fd59977 1858#ifdef WNT
1859
1860static Standard_Boolean Ppick = 0;
1861static Standard_Integer Pargc = 0;
1862static const char** Pargv = NULL;
1863
1864
1865static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1866 UINT Msg,
1867 WPARAM wParam,
1868 LPARAM lParam )
1869{
18d715bd 1870 if (!ViewerTest_myViews.IsEmpty()) {
7fd59977 1871
1872 WPARAM fwKeys = wParam;
1873
1874 switch( Msg ) {
18d715bd 1875 case WM_CLOSE:
1876 {
1877 // Delete view from map of views
1878 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1879 return 0;
1880 }
1881 break;
1882 case WM_ACTIVATE:
1883 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1884 || ViewerTest::CurrentView().IsNull())
1885 {
1886 // Activate inactive window
1887 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1888 {
1889 ActivateView (FindViewIdByWindowHandle(hwnd));
1890 }
1891 }
1892 break;
7fd59977 1893 case WM_LBUTTONUP:
8abada55 1894 if (!DragFirst)
7fd59977 1895 {
1896 HDC hdc = GetDC( hwnd );
7fd59977 1897 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1898 SetROP2( hdc, R2_NOT );
4fe56619 1899 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 1900 ReleaseDC( hwnd, hdc );
8abada55 1901 VT_ProcessButton1Release (fwKeys & MK_SHIFT);
7fd59977 1902 }
8abada55 1903 IsDragged = Standard_False;
7fd59977 1904 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1905
1906 case WM_LBUTTONDOWN:
1907 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1908 {
1909 IsDragged = Standard_True;
1910 DragFirst = Standard_True;
4fe56619 1911 X_ButtonPress = LOWORD(lParam);
1912 Y_ButtonPress = HIWORD(lParam);
7fd59977 1913 }
1914 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1915
1916 break;
1917
1918 case WM_MOUSEMOVE:
1919 if( IsDragged )
1920 {
1921 HDC hdc = GetDC( hwnd );
1922
1923 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1924 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1925 SetROP2( hdc, R2_NOT );
1926
1927 if( !DragFirst )
4fe56619 1928 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 1929
1930 DragFirst = Standard_False;
4fe56619 1931 X_Motion = LOWORD(lParam);
1932 Y_Motion = HIWORD(lParam);
7fd59977 1933
4fe56619 1934 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 1935
1936 SelectObject( hdc, anObj );
1937
1938 ReleaseDC( hwnd, hdc );
1939 }
1940 else
1941 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1942 break;
1943
1944 default:
1945 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1946 }
1947 return 0;
1948 }
1949 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1950}
1951
1952
1953static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1954 UINT Msg,
1955 WPARAM wParam,
1956 LPARAM lParam )
1957{
7fd59977 1958 static int Up = 1;
1959
1960 if ( !ViewerTest::CurrentView().IsNull() ) {
1961 PAINTSTRUCT ps;
1962
1963 switch( Msg ) {
7fd59977 1964 case WM_PAINT:
7fd59977 1965 BeginPaint(hwnd, &ps);
1966 EndPaint(hwnd, &ps);
4fe56619 1967 VT_ProcessExpose();
7fd59977 1968 break;
1969
1970 case WM_SIZE:
4fe56619 1971 VT_ProcessConfigure();
7fd59977 1972 break;
1973
1974 case WM_KEYDOWN:
4fe56619 1975 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1976 {
7fd59977 1977 char c[2];
1978 c[0] = (char) wParam;
1979 c[1] = '\0';
b514beda 1980 if (wParam == VK_DELETE)
1981 {
1982 c[0] = THE_KEY_DELETE;
1983 }
4fe56619 1984 VT_ProcessKeyPress (c);
7fd59977 1985 }
1986 break;
1987
1988 case WM_LBUTTONUP:
1989 case WM_MBUTTONUP:
1990 case WM_RBUTTONUP:
7fd59977 1991 Up = 1;
4fe56619 1992 VT_ProcessButton3Release();
7fd59977 1993 break;
1994
1995 case WM_LBUTTONDOWN:
1996 case WM_MBUTTONDOWN:
1997 case WM_RBUTTONDOWN:
1998 {
7fd59977 1999 WPARAM fwKeys = wParam;
2000
2001 Up = 0;
2002
2003 X_ButtonPress = LOWORD(lParam);
2004 Y_ButtonPress = HIWORD(lParam);
2005
4fe56619 2006 if (Msg == WM_LBUTTONDOWN)
2007 {
2008 if (fwKeys & MK_CONTROL)
2009 {
2010 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2011 }
2012 else
2013 {
2014 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2015 }
7fd59977 2016 }
4fe56619 2017 else if (Msg == WM_RBUTTONDOWN)
2018 {
7fd59977 2019 // Start rotation
4fe56619 2020 VT_ProcessButton3Press();
7fd59977 2021 }
2022 }
2023 break;
2024
2025 case WM_MOUSEMOVE:
2026 {
2027 //cout << "\t WM_MOUSEMOVE" << endl;
2028 WPARAM fwKeys = wParam;
2029 X_Motion = LOWORD(lParam);
2030 Y_Motion = HIWORD(lParam);
2031
2032 if ( Up &&
2033 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2034 Up = 0;
2035 X_ButtonPress = LOWORD(lParam);
2036 Y_ButtonPress = HIWORD(lParam);
2037
2038 if ( fwKeys & MK_RBUTTON ) {
2039 // Start rotation
4fe56619 2040 VT_ProcessButton3Press();
7fd59977 2041 }
2042 }
2043
2044 if ( fwKeys & MK_CONTROL ) {
2045 if ( fwKeys & MK_LBUTTON ) {
2046 ProcessControlButton1Motion();
2047 }
2048 else if ( fwKeys & MK_MBUTTON ||
2049 ((fwKeys&MK_LBUTTON) &&
2050 (fwKeys&MK_RBUTTON) ) ){
4fe56619 2051 VT_ProcessControlButton2Motion();
7fd59977 2052 }
2053 else if ( fwKeys & MK_RBUTTON ) {
4fe56619 2054 VT_ProcessControlButton3Motion();
7fd59977 2055 }
2056 }
2057#ifdef BUG
2058 else if ( fwKeys & MK_SHIFT ) {
2059 if ( fwKeys & MK_MBUTTON ||
2060 ((fwKeys&MK_LBUTTON) &&
2061 (fwKeys&MK_RBUTTON) ) ) {
2062 cout << "ProcessZClipMotion()" << endl;
2063 ProcessZClipMotion();
2064 }
2065 }
2066#endif
08398024 2067 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2068 {
4fe56619 2069 if ((fwKeys & MK_MBUTTON
2070 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2071 {
7fd59977 2072 ProcessZClipMotion();
2073 }
4fe56619 2074 else
2075 {
2076 VT_ProcessMotion();
7fd59977 2077 }
08398024 2078 }
7fd59977 2079 }
2080 break;
2081
2082 default:
2083 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2084 }
2085 return 0L;
2086 }
2087
2088 return DefWindowProc( hwnd, Msg, wParam, lParam );
2089}
2090
2091
2092
2093
2094//==============================================================================
2095//function : ViewerMainLoop
2096//purpose : Get a Event on the view and dispatch it
2097//==============================================================================
2098
2099
8263fcd3 2100int ViewerMainLoop(Standard_Integer argc, const char** argv)
7fd59977 2101{
7fd59977 2102 Ppick = (argc > 0)? 1 : 0;
2103 Pargc = argc;
2104 Pargv = argv;
2105
2106 if ( Ppick ) {
2107 MSG msg;
2108 msg.wParam = 1;
2109
2110 cout << "Start picking" << endl;
2111
7fd59977 2112 while ( Ppick == 1 ) {
4fe56619 2113 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
7fd59977 2114 if (GetMessage(&msg, NULL, 0, 0) ) {
2115 TranslateMessage(&msg);
2116 DispatchMessage(&msg);
2117 }
2118 }
2119
2120 cout << "Picking done" << endl;
2121 }
2122
2123 return Ppick;
2124}
2125
4fe56619 2126#elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 2127
2128int min( int a, int b )
2129{
2130 if( a<b )
2131 return a;
2132 else
2133 return b;
2134}
2135
2136int max( int a, int b )
2137{
2138 if( a>b )
2139 return a;
2140 else
2141 return b;
2142}
2143
2144int ViewerMainLoop(Standard_Integer argc, const char** argv)
2145
4269bd1b 2146{
18d715bd 2147 static XEvent aReport;
2148 Standard_Boolean pick = argc > 0;
2149 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2150 XNextEvent (aDisplay, &aReport);
7fd59977 2151
18d715bd 2152 // Handle event for the chosen display connection
2153 switch (aReport.type) {
2154 case ClientMessage:
2155 {
2156 if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2157 {
2158 // Close the window
2159 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2160 }
2161 }
2162 return 0;
2163 case FocusIn:
2164 {
2165 // Activate inactive view
2166 Window aWindow = GetWindowHandle(VT_GetWindow());
2167 if(aWindow != aReport.xfocus.window)
2168 {
2169 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2170 }
2171 }
2172 break;
7fd59977 2173 case Expose:
2174 {
4fe56619 2175 VT_ProcessExpose();
7fd59977 2176 }
2177 break;
2178 case ConfigureNotify:
2179 {
4fe56619 2180 VT_ProcessConfigure();
7fd59977 2181 }
2182 break;
2183 case KeyPress:
2184 {
2185
2186 KeySym ks_ret ;
2187 char buf_ret[11] ;
2188 int ret_len ;
2189 XComposeStatus status_in_out;
2190
18d715bd 2191 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
7fd59977 2192 (char *) buf_ret , 10 ,
2193 &ks_ret , &status_in_out ) ;
2194
2195
2196 buf_ret[ret_len] = '\0' ;
2197
4fe56619 2198 if (ret_len)
2199 {
2200 VT_ProcessKeyPress (buf_ret);
7fd59977 2201 }
2202 }
2203 break;
2204 case ButtonPress:
7fd59977 2205 {
18d715bd 2206 X_ButtonPress = aReport.xbutton.x;
2207 Y_ButtonPress = aReport.xbutton.y;
7fd59977 2208
18d715bd 2209 if (aReport.xbutton.button == Button1)
4fe56619 2210 {
18d715bd 2211 if (aReport.xbutton.state & ControlMask)
4fe56619 2212 {
18d715bd 2213 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
4fe56619 2214 }
7fd59977 2215 else
2216 {
2217 IsDragged = Standard_True;
7fd59977 2218 DragFirst = Standard_True;
2219 }
4fe56619 2220 }
18d715bd 2221 else if (aReport.xbutton.button == Button3)
4fe56619 2222 {
7fd59977 2223 // Start rotation
4fe56619 2224 VT_ProcessButton3Press();
2225 }
7fd59977 2226 }
2227 break;
2228 case ButtonRelease:
2229 {
7fd59977 2230 if( IsDragged )
2231 {
2232 if( !DragFirst )
2233 {
2234 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
18d715bd 2235 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2236 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 2237 }
2238
2239 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2240 if( aContext.IsNull() )
2241 {
2242 cout << "The context is null. Please use vinit before createmesh" << endl;
2243 return 0;
2244 }
2245
18d715bd 2246 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2247 if( aReport.xbutton.button==1 )
7fd59977 2248 if( DragFirst )
2249 if( ShiftPressed )
2250 {
2251 aContext->ShiftSelect();
7fd59977 2252 }
2253 else
2254 {
2255 aContext->Select();
7fd59977 2256 }
2257 else
2258 if( ShiftPressed )
2259 {
4fe56619 2260 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2261 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
7fd59977 2262 ViewerTest::CurrentView());
7fd59977 2263 }
2264 else
2265 {
4fe56619 2266 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2267 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
7fd59977 2268 ViewerTest::CurrentView() );
7fd59977 2269 }
2270 else
4fe56619 2271 VT_ProcessButton3Release();
7fd59977 2272
2273 IsDragged = Standard_False;
2274 }
2275 else
4fe56619 2276 VT_ProcessButton3Release();
7fd59977 2277 }
2278 break;
2279 case MotionNotify:
2280 {
08398024 2281 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2282 {
2283 break;
2284 }
7fd59977 2285 if( IsDragged )
2286 {
2287 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
18d715bd 2288 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2289 XSetFunction( aDisplay, gc, GXinvert );
7fd59977 2290
2291 if( !DragFirst )
18d715bd 2292 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 2293
18d715bd 2294 X_Motion = aReport.xmotion.x;
2295 Y_Motion = aReport.xmotion.y;
7fd59977 2296 DragFirst = Standard_False;
2297
18d715bd 2298 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 2299 }
2300 else
2301 {
18d715bd 2302 X_Motion = aReport.xmotion.x;
2303 Y_Motion = aReport.xmotion.y;
7fd59977 2304
18d715bd 2305 // remove all the ButtonMotionMaskr
2306 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
7fd59977 2307
18d715bd 2308 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
7fd59977 2309 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2310
2311 Quantity_Length VDX, VDY;
2312
2313 ViewerTest::CurrentView()->Size(VDX,VDY);
2314 Standard_Real VDZ =0 ;
2315 VDZ = ViewerTest::CurrentView()->ZSize();
2316
7fd59977 2317 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2318
2319 Quantity_Length dx = 0 ;
2320 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2321
2322 cout << dx << endl;
2323
2324 dx = dx / VDX * VDZ;
2325
2326 cout << dx << endl;
2327
7fd59977 2328 ViewerTest::CurrentView()->Redraw();
2329 }
2330 }
2331
18d715bd 2332 if ( aReport.xmotion.state & ControlMask ) {
2333 if ( aReport.xmotion.state & Button1Mask ) {
7fd59977 2334 ProcessControlButton1Motion();
2335 }
18d715bd 2336 else if ( aReport.xmotion.state & Button2Mask ) {
4fe56619 2337 VT_ProcessControlButton2Motion();
7fd59977 2338 }
18d715bd 2339 else if ( aReport.xmotion.state & Button3Mask ) {
4fe56619 2340 VT_ProcessControlButton3Motion();
7fd59977 2341 }
2342 }
4fe56619 2343 else
2344 {
2345 VT_ProcessMotion();
7fd59977 2346 }
2347 }
2348 }
2349 break;
2350}
7fd59977 2351return pick;
2352}
2353
2354//==============================================================================
2355//function : VProcessEvents
2356//purpose : call by Tk_CreateFileHandler() to be able to manage the
2357// event in the Viewer window
2358//==============================================================================
2359
2360static void VProcessEvents(ClientData,int)
2361{
18d715bd 2362 NCollection_Vector<int> anEventNumbers;
2363 // Get number of messages from every display
2364 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2365 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2366 {
2367 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
4269bd1b 2368 }
18d715bd 2369 // Handle events for every display
2370 int anEventIter = 0;
2371 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2372 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2373 {
4269bd1b 2374 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
18d715bd 2375 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2376 {
2377 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2378 int anEventResult = ViewerMainLoop( 0, NULL);
2379 // If window is closed or context was not found finish current event processing loop
2380 if (!anEventResult)
2381 return;
2382 }
7fd59977 2383 }
4269bd1b 2384
18d715bd 2385 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
4269bd1b 2386
7fd59977 2387}
2388#endif
2389
2390//==============================================================================
2391//function : OSWindowSetup
2392//purpose : Setup for the X11 window to be able to cath the event
2393//==============================================================================
2394
2395
2396static void OSWindowSetup()
2397{
4fe56619 2398#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 2399 // X11
2400
2401 Window window = VT_GetWindow()->XWindow();
18d715bd 2402 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2403 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2404 XSynchronize(aDisplay, 1);
7fd59977 2405
2406 // X11 : For keyboard on SUN
2407 XWMHints wmhints;
2408 wmhints.flags = InputHint;
2409 wmhints.input = 1;
2410
18d715bd 2411 XSetWMHints( aDisplay, window, &wmhints);
7fd59977 2412
18d715bd 2413 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
7fd59977 2414 ButtonPressMask | ButtonReleaseMask |
2415 StructureNotifyMask |
2416 PointerMotionMask |
2417 Button1MotionMask | Button2MotionMask |
18d715bd 2418 Button3MotionMask | FocusChangeMask
7fd59977 2419 );
18d715bd 2420 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2421 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
7fd59977 2422
18d715bd 2423 XSynchronize(aDisplay, 0);
7fd59977 2424
2425#else
2426 // WNT
2427#endif
2428
2429}
2430
2431
2432//==============================================================================
2433//function : VFit
2434
2435//purpose : Fitall, no DRAW arguments
2436//Draw arg : No args
2437//==============================================================================
2438
2439static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2440{
2441 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2442 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2443 if (V.IsNull() == Standard_False) {
2444 V->FitAll3d();
2445 } else if (aView.IsNull() == Standard_False) {
2446 aView->FitAll();
2447 }
2448 return 0;
2449}
2450
2451//==============================================================================
2452//function : VZFit
2453//purpose : ZFitall, no DRAW arguments
2454//Draw arg : No args
2455//==============================================================================
197ac94e 2456static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 2457{
197ac94e 2458 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2459
2460 if (aCurrentView.IsNull())
2461 {
2462 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2463 return 1;
2464 }
2465
2466 if (theArgsNb == 1)
2467 {
2468 aCurrentView->ZFitAll();
2469 aCurrentView->Redraw();
2470 return 0;
2471 }
2472
2473 Standard_Real aScale = 1.0;
2474
2475 if (theArgsNb >= 2)
2476 {
2477 aScale = Draw::Atoi (theArgVec[1]);
2478 }
2479
2480 aCurrentView->ZFitAll (aScale);
2481 aCurrentView->Redraw();
7fd59977 2482
197ac94e 2483 return 0;
2484}
7fd59977 2485
197ac94e 2486//==============================================================================
2487//function : VRepaint
2488//purpose :
2489//==============================================================================
2490static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
7fd59977 2491{
2492 Handle(V3d_View) V = ViewerTest::CurrentView();
2493 if ( !V.IsNull() ) V->Redraw(); return 0;
2494}
2495
7fd59977 2496//==============================================================================
2497//function : VClear
2498//purpose : Remove all the object from the viewer
2499//Draw arg : No args
2500//==============================================================================
2501
2502static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2503{
2504 Handle(V3d_View) V = ViewerTest::CurrentView();
2505 if(!V.IsNull())
2506 ViewerTest::Clear();
2507 return 0;
2508}
2509
2510//==============================================================================
2511//function : VPick
2512//purpose :
2513//==============================================================================
2514
2515static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2516{ if (ViewerTest::CurrentView().IsNull() ) return 1;
2517
2518if ( argc < 4 ) {
2519 di << argv[0] << "Invalid number of arguments" << "\n";
2520 return 1;
2521}
2522
2523while (ViewerMainLoop( argc, argv)) {
2524}
2525
2526return 0;
2527}
2528
7fd59977 2529//==============================================================================
2530//function : InitViewerTest
2531//purpose : initialisation de toutes les variables static de ViewerTest (dp)
2532//==============================================================================
2533
18d715bd 2534void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
7fd59977 2535{
18d715bd 2536 Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2537 ViewerTest::SetAISContext(theContext);
2538 aViewer->InitActiveViews();
2539 Handle(V3d_View) aView = aViewer->ActiveView();
2540 if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
7fd59977 2541 ViewerTest::ResetEventManager();
18d715bd 2542 Handle(Aspect_Window) aWindow = aView->Window();
4fe56619 2543#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 2544 // X11
18d715bd 2545 VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
7fd59977 2546 OSWindowSetup();
18d715bd 2547 static int aFirst = 1;
2548 if ( aFirst ) {
7fd59977 2549#if TCL_MAJOR_VERSION < 8
18d715bd 2550 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 2551 TK_READABLE, VProcessEvents, (ClientData) 0);
2552#else
18d715bd 2553 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 2554 TK_READABLE, VProcessEvents, (ClientData) 0);
2555#endif
18d715bd 2556 aFirst = 0;
7fd59977 2557 }
2558#endif
2559}
2560
7fd59977 2561//==============================================================================
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
7fd59977 2871 V3dView->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