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