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