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