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