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