1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 // Robert Boehne 30 May 2000 : Dec Osf
32 #include <AIS_Shape.hxx>
33 #include <AIS_Drawer.hxx>
34 #include <AIS_InteractiveObject.hxx>
35 #include <AIS_ListOfInteractive.hxx>
36 #include <AIS_ListIteratorOfListOfInteractive.hxx>
38 #include <Graphic3d_AspectMarker3d.hxx>
39 #include <Graphic3d_GraphicDriver.hxx>
40 #include <Graphic3d_ExportFormat.hxx>
41 #include <Graphic3d_NameOfTextureEnv.hxx>
42 #include <Graphic3d_TextureEnv.hxx>
43 #include <Graphic3d_TextureParams.hxx>
44 #include <Graphic3d_TypeOfTextureFilter.hxx>
45 #include <ViewerTest.hxx>
46 #include <ViewerTest_EventManager.hxx>
47 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
48 #include <Visual3d_View.hxx>
49 #include <Visual3d_ViewManager.hxx>
50 #include <V3d_LayerMgr.hxx>
51 #include <NCollection_DoubleMap.hxx>
52 #include <NCollection_List.hxx>
53 #include <NCollection_Vector.hxx>
54 #include <NIS_View.hxx>
55 #include <NIS_Triangulated.hxx>
56 #include <NIS_InteractiveContext.hxx>
57 #include <AIS_InteractiveContext.hxx>
58 #include <Draw_Interpretor.hxx>
60 #include <Draw_Appli.hxx>
61 #include <Aspect_PrintAlgo.hxx>
62 #include <Image_AlienPixMap.hxx>
63 #include <OSD_Timer.hxx>
64 #include <TColStd_SequenceOfInteger.hxx>
65 #include <TColStd_HSequenceOfReal.hxx>
66 #include <TColgp_Array1OfPnt2d.hxx>
67 #include <Visual3d_LayerItem.hxx>
68 #include <V3d_LayerMgr.hxx>
69 #include <V3d_LayerMgrPointer.hxx>
70 #include <Aspect_TypeOfLine.hxx>
71 #include <Image_Diff.hxx>
72 #include <Aspect_DisplayConnection.hxx>
73 #include <Graphic3d.hxx>
79 #include <Visual3d_Layer.hxx>
82 #if defined(_WIN32) || defined(__WIN32__)
83 #include <WNT_WClass.hxx>
84 #include <WNT_Window.hxx>
87 #define _CRT_SECURE_NO_DEPRECATE
88 #pragma warning (disable:4996)
90 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
91 #include <Cocoa_Window.hxx>
94 #include <Xw_Window.hxx>
95 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
96 #include <X11/Xutil.h>
100 //==============================================================================
102 //==============================================================================
103 // VIEWER GLOBAL VARIABLES
104 //==============================================================================
106 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
108 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
109 extern const Handle(NIS_InteractiveContext)& TheNISContext();
110 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
112 #if defined(_WIN32) || defined(__WIN32__)
113 static Handle(WNT_Window)& VT_GetWindow() {
114 static Handle(WNT_Window) WNTWin;
117 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
118 static Handle(Cocoa_Window)& VT_GetWindow()
120 static Handle(Cocoa_Window) aWindow;
123 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
124 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
125 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
128 static Handle(Xw_Window)& VT_GetWindow(){
129 static Handle(Xw_Window) XWWin;
133 static void VProcessEvents(ClientData,int);
136 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
138 static Handle(Aspect_DisplayConnection) aDisplayConnection;
139 return aDisplayConnection;
142 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
144 GetDisplayConnection() = theDisplayConnection;
147 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
148 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
150 Aspect_Handle aWindowHandle = NULL;
151 #if defined(_WIN32) || defined(__WIN32__)
152 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
153 if (!aWindow.IsNull())
154 return aWindow->HWindow();
155 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
156 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
157 if (!aWindow.IsNull())
158 return aWindow->XWindow();
160 return aWindowHandle;
164 static Standard_Boolean MyHLRIsOn = Standard_False;
166 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
167 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
168 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
171 #define ZCLIPWIDTH 1.
173 static void OSWindowSetup();
175 //==============================================================================
176 // EVENT GLOBAL VARIABLES
177 //==============================================================================
179 static int Start_Rot = 0;
180 static int ZClipIsOn = 0;
181 int X_Motion = 0; // Current cursor position
183 int X_ButtonPress = 0; // Last ButtonPress position
184 int Y_ButtonPress = 0;
185 Standard_Boolean IsDragged = Standard_False;
186 Standard_Boolean DragFirst;
188 //==============================================================================
191 static LRESULT WINAPI ViewerWindowProc(
196 static LRESULT WINAPI AdvViewerWindowProc(
204 //==============================================================================
207 //==============================================================================
209 const Handle(MMgt_TShared)& ViewerTest::WClass()
211 static Handle(MMgt_TShared) theWClass;
212 #if defined(_WIN32) || defined(__WIN32__)
213 if (theWClass.IsNull())
215 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
216 CS_VREDRAW | CS_HREDRAW, 0, 0,
217 ::LoadCursor (NULL, IDC_ARROW));
223 //==============================================================================
224 //function : CreateName
225 //purpose : Create numerical name for new object in theMap
226 //==============================================================================
227 template <typename ObjectType>
228 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
229 const TCollection_AsciiString& theDefaultString)
231 if (theObjectMap.IsEmpty())
232 return theDefaultString + TCollection_AsciiString(1);
234 Standard_Integer aNextKey = 1;
235 Standard_Boolean isFound = Standard_False;
238 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
239 // Look for objects with default names
240 if (theObjectMap.IsBound1(aStringKey))
245 isFound = Standard_True;
248 return theDefaultString + TCollection_AsciiString(aNextKey);
251 //==============================================================================
252 //structure : ViewerTest_Names
253 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
254 //==============================================================================
255 struct ViewerTest_Names
258 TCollection_AsciiString myDriverName;
259 TCollection_AsciiString myViewerName;
260 TCollection_AsciiString myViewName;
264 const TCollection_AsciiString& GetDriverName () const
268 void SetDriverName (const TCollection_AsciiString& theDriverName)
270 myDriverName = theDriverName;
272 const TCollection_AsciiString& GetViewerName () const
276 void SetViewerName (const TCollection_AsciiString& theViewerName)
278 myViewerName = theViewerName;
280 const TCollection_AsciiString& GetViewName () const
284 void SetViewName (const TCollection_AsciiString& theViewName)
286 myViewName = theViewName;
289 //===========================================================================
290 //function : Constructor for ViewerTest_Names
291 //purpose : Get view, viewer, driver names from custom string
292 //===========================================================================
294 ViewerTest_Names (const TCollection_AsciiString& theInputString)
296 TCollection_AsciiString aName(theInputString);
297 if (theInputString.IsEmpty())
299 // Get current configuration
300 if (ViewerTest_myDrivers.IsEmpty())
301 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
302 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
304 myDriverName = ViewerTest_myDrivers.Find2
305 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
307 if(ViewerTest_myContexts.IsEmpty())
309 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
310 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
313 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
315 myViewName = CreateName <Handle(V3d_View)>
316 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
320 // There is at least view name
321 Standard_Integer aParserNumber = 0;
322 for (Standard_Integer i = 0; i < 3; ++i)
324 Standard_Integer aParserPos = aName.SearchFromEnd("/");
328 aName.Split(aParserPos-1);
333 if (aParserNumber == 0)
336 if (!ViewerTest::GetAISContext().IsNull())
338 myDriverName = ViewerTest_myDrivers.Find2
339 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
340 myViewerName = ViewerTest_myContexts.Find2
341 (ViewerTest::GetAISContext());
345 // There is no opened contexts here, need to create names for viewer and driver
346 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
347 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
349 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
350 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
352 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
354 else if (aParserNumber == 1)
356 // Here is viewerName/viewName
357 if (!ViewerTest::GetAISContext().IsNull())
358 myDriverName = ViewerTest_myDrivers.Find2
359 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
362 // There is no opened contexts here, need to create name for driver
363 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
364 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
366 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
368 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
372 //Here is driverName/viewerName/viewName
373 myDriverName = TCollection_AsciiString(aName);
375 TCollection_AsciiString aViewerName(theInputString);
376 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
377 myViewerName = TCollection_AsciiString(aViewerName);
379 myViewName = TCollection_AsciiString(theInputString);
385 //==============================================================================
386 //function : FindContextByView
387 //purpose : Find AIS_InteractiveContext by View
388 //==============================================================================
390 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
392 Handle(AIS_InteractiveContext) anAISContext;
394 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
395 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
397 if (anIter.Value()->CurrentViewer() == theView->Viewer())
398 return anIter.Key2();
404 //==============================================================================
405 //function : SetWindowTitle
406 //purpose : Set window title
407 //==============================================================================
409 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
410 Standard_CString theTitle)
412 #if defined(_WIN32) || defined(__WIN32__)
413 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
415 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
416 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
418 if(GetDisplayConnection()->GetDisplay())
421 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
422 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
427 //==============================================================================
428 //function : IsWindowOverlapped
429 //purpose : Check if theWindow overlapp another view
430 //==============================================================================
432 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
433 const Standard_Integer thePxTop,
434 const Standard_Integer thePxRight,
435 const Standard_Integer thePxBottom,
436 TCollection_AsciiString& theViewId)
438 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
439 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
441 Standard_Integer aTop = 0,
445 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
446 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
447 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
448 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
449 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
451 theViewId = anIter.Key1();
452 return Standard_True;
455 return Standard_False;
458 // Workaround: to create and delete non-orthographic views outside ViewerTest
459 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
461 ViewerTest_myViews.UnBind1 (theName);
464 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
465 const Handle(V3d_View)& theView)
467 ViewerTest_myViews.Bind (theName, theView);
470 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
472 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
474 //==============================================================================
475 //function : ViewerInit
476 //purpose : Create the window viewer and initialize all the global variable
477 //==============================================================================
479 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
480 const Standard_Integer thePxTop,
481 const Standard_Integer thePxWidth,
482 const Standard_Integer thePxHeight,
483 Standard_CString theViewName,
484 Standard_CString theDisplayName)
486 // Default position and dimension of the viewer window.
487 // Note that left top corner is set to be sufficiently small to have
488 // window fit in the small screens (actual for remote desktops, see #23003).
489 // The position corresponds to the window's client area, thus some
490 // gap is added for window frame to be visible.
492 Standard_Integer aPxLeft = 20;
493 Standard_Integer aPxTop = 40;
494 Standard_Integer aPxWidth = 409;
495 Standard_Integer aPxHeight = 409;
496 Standard_Boolean toCreateViewer = Standard_False;
499 Handle(Graphic3d_GraphicDriver) aGraphicDriver;
500 ViewerTest_Names aViewNames(theViewName);
501 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
502 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
509 aPxWidth = thePxWidth;
510 if (thePxHeight != 0)
511 aPxHeight = thePxHeight;
513 // Get graphic driver (create it or get from another view)
514 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
516 // Get connection string
517 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
518 TCollection_AsciiString aDisplayName(theDisplayName);
519 if (aDisplayName.IsEmpty())
520 SetDisplayConnection (new Aspect_DisplayConnection ());
522 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
525 SetDisplayConnection (new Aspect_DisplayConnection ());
527 aGraphicDriver = Graphic3d::InitGraphicDriver (GetDisplayConnection());
528 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
529 toCreateViewer = Standard_True;
533 aGraphicDriver = ViewerTest_myDrivers.Find1(aViewNames.GetDriverName());
536 //Dispose the window if input parameters are default
537 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
539 Standard_Integer aTop = 0,
546 // Get screen resolution
547 #if defined(_WIN32) || defined(__WIN32__)
549 GetClientRect(GetDesktopWindow(), &aWindowSize);
550 aScreenHeight = aWindowSize.bottom;
551 aScreenWidth = aWindowSize.right;
552 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
553 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
555 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
556 aScreenWidth = WidthOfScreen(aScreen);
557 aScreenHeight = HeightOfScreen(aScreen);
560 TCollection_AsciiString anOverlappedViewId("");
562 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
564 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
566 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
567 && aRight + 2*aPxWidth + 40 > aScreenWidth)
569 if (aBottom + aPxHeight + 40 > aScreenHeight)
576 aPxTop = aBottom + 40;
579 aPxLeft = aRight + 20;
584 TCollection_AsciiString aTitle("3D View - ");
585 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
587 // Change name of current active window
588 if (!ViewerTest::CurrentView().IsNull())
590 TCollection_AsciiString aTitle("3D View - ");
592 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
593 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
597 Handle(V3d_Viewer) a3DViewer, a3DCollector;
598 // If it's the single view, we first look for empty context
599 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
601 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
602 anIter(ViewerTest_myContexts);
604 ViewerTest::SetAISContext (anIter.Value());
605 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
606 a3DCollector= ViewerTest::GetAISContext()->Collector();
608 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
610 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
611 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
612 a3DCollector= ViewerTest::GetAISContext()->Collector();
614 else if (a3DViewer.IsNull() || a3DCollector.IsNull())
616 toCreateViewer = Standard_True;
617 TCollection_ExtendedString NameOfWindow("Viewer3D");
618 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
620 NameOfWindow = TCollection_ExtendedString("Collector");
621 a3DCollector = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
623 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
624 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
628 if (ViewerTest::GetAISContext().IsNull() ||
629 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
631 Handle(AIS_InteractiveContext) aContext =
632 new AIS_InteractiveContext(a3DViewer, a3DCollector);
633 ViewerTest::SetAISContext (aContext);
634 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
637 ViewerTest::ResetEventManager();
640 #if defined(_WIN32) || defined(__WIN32__)
641 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
642 Handle(WNT_WClass)::DownCast (WClass()),
647 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
648 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
650 aPxWidth, aPxHeight);
651 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
653 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
656 aPxWidth, aPxHeight);
658 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
661 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
663 ViewerTest::CurrentView(aView);
664 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
665 TheNISContext()->AttachView (aView);
667 // Setup for X11 or NT
670 // Set parameters for V3d_View and V3d_Viewer
671 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
672 aV3dView->SetComputedMode(Standard_False);
673 MyHLRIsOn = aV3dView->ComputedMode();
674 aV3dView->SetZClippingDepth(0.5);
675 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
677 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
680 a3DViewer->SetDefaultLights();
681 a3DViewer->SetLightOn();
684 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
685 #if TCL_MAJOR_VERSION < 8
686 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
687 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
689 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
690 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
694 VT_GetWindow()->Map();
696 // Set the handle of created view in the event manager
697 ViewerTest::ResetEventManager();
699 ViewerTest::CurrentView()->Redraw();
703 a3DCollector.Nullify();
705 return aViewNames.GetViewName();
708 //==============================================================================
709 //function : SplitParameter
710 //purpose : Split parameter string to parameter name an patameter value
711 //==============================================================================
712 Standard_Boolean SplitParameter (const TCollection_AsciiString& theString,
713 TCollection_AsciiString& theName,
714 TCollection_AsciiString& theValue)
716 Standard_Integer aParamNameEnd = theString.FirstLocationInSet("=",1, theString.Length());
717 if (aParamNameEnd == 0)
718 return Standard_False;
719 TCollection_AsciiString aString(theString);
720 if (aParamNameEnd != 0)
722 theValue = aString.Split(aParamNameEnd);
723 aString.Split(aString.Length()-1);
726 return Standard_True;
729 //==============================================================================
731 //purpose : Create the window viewer and initialize all the global variable
732 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
733 //==============================================================================
735 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
739 theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
740 << "Type help for more information.\n";
743 TCollection_AsciiString aViewName (""),
745 Standard_Integer aPxLeft = 0,
750 for (Standard_Integer i = 1; i < theArgsNb; ++i)
752 TCollection_AsciiString aName = "", aValue = "";
753 if(!SplitParameter (TCollection_AsciiString(theArgVec[i]),aName,aValue) && theArgsNb == 2)
755 // In case of syntax: vinit ViewName
756 aViewName = theArgVec[1];
764 else if (aName == "l" || aName == "left")
765 aPxLeft = aValue.IntegerValue();
766 else if (aName == "t" || aName == "top")
767 aPxTop = aValue.IntegerValue();
768 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
769 else if (aName == "display")
770 aDisplayName = aValue;
772 else if (aName == "w" || aName == "width")
773 aPxWidth = aValue.IntegerValue();
774 else if (aName == "h" || aName == "height")
775 aPxHeight = aValue.IntegerValue();
778 theDi << theArgVec[0] << ": Warning: unknown parameter " << aName.ToCString() << ".\n";
783 ViewerTest_Names aViewNames (aViewName);
784 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
786 TCollection_AsciiString aCommand("vactivate ");
787 aCommand = aCommand + aViewNames.GetViewName();
788 theDi.Eval(aCommand.ToCString());
792 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
793 aViewName.ToCString(),
794 aDisplayName.ToCString());
795 cout << theArgVec[0] << ": 3D View - " << aViewId << " was created.\n";
799 //==============================================================================
801 //purpose : hidden lines removal algorithm
802 //==============================================================================
804 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
806 if (ViewerTest::CurrentView().IsNull())
808 di << argv[0] << ": Call vinit before this command, please.\n";
814 di << argv[0] << ": Wrong number of command arguments.\n"
815 << "Type help " << argv[0] << " for more information.\n";
819 Standard_Boolean isHLROn =
820 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
822 if (isHLROn == MyHLRIsOn)
828 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
833 //==============================================================================
834 //function : VHLRType
835 //purpose : change type of using HLR algorithm
836 //==============================================================================
838 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
840 if (ViewerTest::CurrentView().IsNull())
842 di << argv[0] << ": Call vinit before this command, please.\n";
848 di << argv[0] << ": Wrong number of command arguments.\n"
849 << "Type help " << argv[0] << " for more information.\n";
853 Prs3d_TypeOfHLR aTypeOfHLR =
854 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
858 AIS_ListOfInteractive aListOfShapes;
859 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
860 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
861 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
862 anIter.More(); anIter.Next())
864 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
867 if (aShape->TypeOfHLR() != aTypeOfHLR)
868 aShape->SetTypeOfHLR (aTypeOfHLR);
872 ViewerTest::CurrentView()->Update();
877 for (Standard_Integer i = 2; i < argc; ++i)
879 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
880 TCollection_AsciiString aName (argv[i]);
882 if (!aMap.IsBound2 (aName))
884 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
887 Handle(AIS_Shape) anAISObject =
888 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
889 if (anAISObject.IsNull())
891 anAISObject->SetTypeOfHLR (aTypeOfHLR);
893 anAISObject->Redisplay();
895 ViewerTest::CurrentView()->Update();
901 //==============================================================================
902 //function : FindViewIdByWindowHandle
903 //purpose : Find theView Id in the map of views by window handle
904 //==============================================================================
905 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
906 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
908 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
909 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
911 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
912 if (aWindowHandle == theWindowHandle)
913 return anIter.Key1();
915 return TCollection_AsciiString("");
919 //==============================================================================
920 //function : ActivateView
921 //purpose : Make the view active
922 //==============================================================================
924 void ActivateView (const TCollection_AsciiString& theViewName)
926 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
929 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
930 if (!anAISContext.IsNull())
932 if (!ViewerTest::CurrentView().IsNull())
934 TCollection_AsciiString aTitle("3D View - ");
935 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
936 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
939 ViewerTest::CurrentView (aView);
940 // Update degenerate mode
941 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
942 ViewerTest::SetAISContext (anAISContext);
943 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
944 aTitle = aTitle + theViewName + "(*)";
945 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
946 #if defined(_WIN32) || defined(__WIN32__)
947 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
948 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
949 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
951 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
953 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
954 ViewerTest::CurrentView()->Redraw();
959 //==============================================================================
960 //function : RemoveView
961 //purpose : Close and remove view from display, clear maps if neccessary
962 //==============================================================================
963 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
965 if (!ViewerTest_myViews.IsBound1(theViewName))
967 cout << "Wrong view name\n";
971 // Activate another view if it's active now
972 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
974 if (ViewerTest_myViews.Extent() > 1)
976 TCollection_AsciiString aNewViewName;
977 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
978 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
979 if (anIter.Key1() != theViewName)
981 aNewViewName = anIter.Key1();
984 ActivateView (aNewViewName);
988 Handle(V3d_View) anEmptyView;
989 #if defined(_WIN32) || defined(__WIN32__)
990 Handle(WNT_Window) anEmptyWindow;
991 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
992 Handle(Cocoa_Window) anEmptyWindow;
994 Handle(Xw_Window) anEmptyWindow;
996 VT_GetWindow() = anEmptyWindow;
997 ViewerTest::CurrentView (anEmptyView);
998 if (isContextRemoved)
1000 Handle(AIS_InteractiveContext) anEmptyContext;
1001 ViewerTest::SetAISContext(anEmptyContext);
1007 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1008 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1010 // Remove view resources
1011 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1012 ViewerTest_myViews.UnBind1(theViewName);
1015 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1016 XFlush (GetDisplayConnection()->GetDisplay());
1019 // Keep context opened only if the closed view is last to avoid
1020 // unused empty contexts
1021 if (!aCurrentContext.IsNull())
1023 // Check if there are more difined views in the viewer
1024 aCurrentContext->CurrentViewer()->InitDefinedViews();
1025 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1027 // Remove driver if there is no viewers that use it
1028 Standard_Boolean isRemoveDriver = Standard_True;
1029 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1030 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1032 if (aCurrentContext != anIter.Key2() &&
1033 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1035 isRemoveDriver = Standard_False;
1041 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1042 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1043 #if TCL_MAJOR_VERSION < 8
1044 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1046 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1051 ViewerTest_myContexts.UnBind2(aCurrentContext);
1054 cout << "3D View - " << theViewName << " was deleted.\n";
1058 //==============================================================================
1060 //purpose : Remove the view defined by its name
1061 //==============================================================================
1063 static int VClose (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1067 theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
1068 << "Type help " << theArgVec[0] << " for more information.\n";
1072 if (ViewerTest_myViews.IsEmpty())
1074 theDi << theArgVec[0] <<": there is no views to close.\n";
1078 TCollection_AsciiString anInputString(theArgVec[1]);
1080 // Create list to iterate and remove views from the map of views
1081 NCollection_List<TCollection_AsciiString> aViewList;
1082 if (TCollection_AsciiString::ISSIMILAR (anInputString, TCollection_AsciiString("ALL")))
1084 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter(ViewerTest_myViews);
1085 anIter.More(); anIter.Next())
1087 aViewList.Append(anIter.Key1());
1092 ViewerTest_Names aViewNames(anInputString);
1093 aViewList.Append(aViewNames.GetViewName());
1096 Standard_Boolean isContextRemoved = (theArgsNb == 3 && atoi(theArgVec[2])==1) ? Standard_False : Standard_True;
1097 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1098 anIter.More(); anIter.Next())
1100 ViewerTest::RemoveView(anIter.Value(), isContextRemoved);
1106 //==============================================================================
1107 //function : VActivate
1108 //purpose : Activate the view defined by its ID
1109 //==============================================================================
1111 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1115 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1116 << "Usage: " << theArgVec[0] << " ViewID\n";
1121 theDi.Eval("vviewlist");
1125 TCollection_AsciiString aNameString(theArgVec[1]);
1126 if (TCollection_AsciiString::ISSIMILAR (aNameString, TCollection_AsciiString("NONE")))
1128 TCollection_AsciiString aTitle("3D View - ");
1129 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1130 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1131 Handle(V3d_View) anEmptyView;
1132 #if defined(_WIN32) || defined(__WIN32__)
1133 Handle(WNT_Window) anEmptyWindow;
1134 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1135 Handle(Cocoa_Window) anEmptyWindow;
1137 Handle(Xw_Window) anEmptyWindow;
1139 VT_GetWindow() = anEmptyWindow;
1140 ViewerTest::CurrentView (anEmptyView);
1141 ViewerTest::ResetEventManager();
1142 theDi << theArgVec[0] << ": all views are inactive\n";
1146 ViewerTest_Names aViewNames(aNameString);
1148 // Check if this view exists in the viewer with the driver
1149 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1151 theDi << "Wrong view name\n";
1155 // Check if it is active already
1156 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1158 theDi << theArgVec[0] << ": the view is active already\n";
1162 ActivateView (aViewNames.GetViewName());
1166 //==============================================================================
1167 //function : VViewList
1168 //purpose : Print current list of views per viewer and graphic driver ID
1169 // shared between viewers
1170 //==============================================================================
1172 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1176 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1177 << "Usage: " << theArgVec[0];
1180 if (ViewerTest_myContexts.Size() < 1)
1183 TCollection_AsciiString aNameString(theArgsNb==2?theArgVec[1]:"");
1184 Standard_Boolean isTreeView =
1185 TCollection_AsciiString::ISSIMILAR (aNameString, TCollection_AsciiString("long"))?
1186 Standard_False:Standard_True;
1189 theDi << theArgVec[0] <<":\n";
1191 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1192 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1195 theDi << aDriverIter.Key1() << ":\n";
1197 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1198 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1200 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1204 TCollection_AsciiString aContextName(aContextIter.Key1());
1205 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1208 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1209 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1211 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1213 TCollection_AsciiString aViewName(aViewIter.Key1());
1216 if (aViewIter.Value() == ViewerTest::CurrentView())
1217 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1219 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1223 theDi << aViewName << " ";
1233 //==============================================================================
1234 //function : VT_ProcessKeyPress
1235 //purpose : Handle KeyPress event from a CString
1236 //==============================================================================
1237 void VT_ProcessKeyPress (const char* buf_ret)
1239 //cout << "KeyPress" << endl;
1240 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1241 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1242 // Letter in alphabetic order
1244 if ( !strcasecmp(buf_ret, "A") ) {
1246 aView->SetProj(V3d_XposYnegZpos);
1248 else if ( !strcasecmp(buf_ret, "D") ) {
1252 else if ( !strcasecmp(buf_ret, "F") ) {
1254 if (aNisView.IsNull())
1257 aNisView->FitAll3d();
1259 else if ( !strcasecmp(buf_ret, "H") ) {
1261 cout << "HLR" << endl;
1262 aView->SetComputedMode (!aView->ComputedMode());
1263 MyHLRIsOn = aView->ComputedMode();
1265 else if ( !strcasecmp(buf_ret, "P") ) {
1267 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1268 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1269 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1271 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1272 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1274 AIS_ListOfInteractive aListOfShapes;
1275 aContext->DisplayedObjects(aListOfShapes);
1276 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1277 anIter.More(); anIter.Next())
1279 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1280 if (aShape.IsNull())
1282 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1283 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1285 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1286 aShape->Redisplay();
1291 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1293 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1294 if (aShape.IsNull())
1296 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1297 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1299 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1300 aShape->Redisplay();
1304 aContext->UpdateCurrentViewer();
1307 else if ( !strcasecmp(buf_ret, "S") ) {
1309 cout << "passage en mode 1 (shading pour les shapes)" << endl;
1311 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1312 if(Ctx->NbCurrents()==0 ||
1313 Ctx->NbSelected()==0)
1314 Ctx->SetDisplayMode(AIS_Shaded);
1316 if(Ctx->HasOpenedContext()){
1317 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1318 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1321 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1322 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1324 Ctx->UpdateCurrentViewer();
1327 else if ( !strcasecmp(buf_ret, "U") ) {
1328 // Unset display mode
1329 cout<<"passage au mode par defaut"<<endl;
1331 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1332 if(Ctx->NbCurrents()==0 ||
1333 Ctx->NbSelected()==0)
1334 Ctx->SetDisplayMode(AIS_WireFrame);
1336 if(Ctx->HasOpenedContext()){
1337 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1338 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1341 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1342 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1344 Ctx->UpdateCurrentViewer();
1348 else if ( !strcasecmp(buf_ret, "T") ) {
1350 aView->SetProj(V3d_Zpos);
1352 else if ( !strcasecmp(buf_ret, "B") ) {
1354 aView->SetProj(V3d_Zneg);
1356 else if ( !strcasecmp(buf_ret, "L") ) {
1358 aView->SetProj(V3d_Xneg);
1360 else if ( !strcasecmp(buf_ret, "R") ) {
1362 aView->SetProj(V3d_Xpos);
1365 else if ( !strcasecmp(buf_ret, "W") ) {
1367 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
1368 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1369 if(Ctx->NbCurrents()==0 ||
1370 Ctx->NbSelected()==0)
1371 Ctx->SetDisplayMode(AIS_WireFrame);
1373 if(Ctx->HasOpenedContext()){
1374 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1375 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1378 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1379 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1381 Ctx->UpdateCurrentViewer();
1384 else if ( !strcasecmp(buf_ret, "Z") ) {
1388 cout << "ZClipping OFF" << endl;
1391 aView->SetZClippingType(V3d_OFF);
1395 cout << "ZClipping ON" << endl;
1398 aView->SetZClippingType(V3d_FRONT);
1402 else if ( !strcasecmp(buf_ret, ",") ) {
1403 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1407 else if ( !strcasecmp(buf_ret, ".") ) {
1408 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1412 Standard_Integer Num = Draw::Atoi(buf_ret);
1413 if(Num>=0 && Num<=7)
1414 ViewerTest::StandardModeActivation(Num);
1418 //==============================================================================
1419 //function : VT_ProcessExpose
1420 //purpose : Redraw the View on an Expose Event
1421 //==============================================================================
1422 void VT_ProcessExpose()
1424 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1425 if (!aView3d.IsNull())
1431 //==============================================================================
1432 //function : VT_ProcessConfigure
1433 //purpose : Resize the View on an Configure Event
1434 //==============================================================================
1435 void VT_ProcessConfigure()
1437 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1438 if (aView3d.IsNull())
1443 aView3d->MustBeResized();
1448 //==============================================================================
1449 //function : VT_ProcessButton1Press
1451 //==============================================================================
1452 Standard_Boolean VT_ProcessButton1Press(
1455 Standard_Boolean pick,
1456 Standard_Boolean shift)
1458 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1460 Standard_Real X, Y, Z;
1462 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
1464 Draw::Set(argv[1], X);
1465 Draw::Set(argv[2], Y);
1466 Draw::Set(argv[3], Z);}
1477 //==============================================================================
1478 //function : VT_ProcessButton1Release
1479 //purpose : End selecting
1480 //==============================================================================
1481 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1485 IsDragged = Standard_False;
1486 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1489 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1490 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1494 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1495 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1500 //==============================================================================
1501 //function : VT_ProcessButton3Press
1502 //purpose : Start Rotation
1503 //==============================================================================
1504 void VT_ProcessButton3Press()
1509 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1511 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1514 //==============================================================================
1515 //function : VT_ProcessButton3Release
1516 //purpose : End rotation
1517 //==============================================================================
1518 void VT_ProcessButton3Release()
1525 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1530 //==============================================================================
1531 //function : ProcessZClipMotion
1533 //==============================================================================
1535 void ProcessZClipMotion()
1537 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1538 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1539 static Standard_Real CurZPos = 0.;
1541 //Quantity_Length VDX, VDY;
1542 //a3DView->Size(VDX,VDY);
1543 //Standard_Real VDZ = a3DView->ZSize();
1544 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1546 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1548 // Front = Depth + width/2.
1549 Standard_Real D = 0.5;
1550 Standard_Real W = 0.1;
1556 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1558 a3DView->SetZClippingType(V3d_OFF);
1559 a3DView->SetZClippingDepth(D);
1560 a3DView->SetZClippingWidth(W);
1561 a3DView->SetZClippingType(V3d_FRONT);
1565 X_ButtonPress = X_Motion;
1566 Y_ButtonPress = Y_Motion;
1570 //==============================================================================
1571 //function : ProcessControlButton1Motion
1573 //==============================================================================
1575 static void ProcessControlButton1Motion()
1577 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1579 X_ButtonPress = X_Motion;
1580 Y_ButtonPress = Y_Motion;
1583 //==============================================================================
1584 //function : VT_ProcessControlButton2Motion
1586 //==============================================================================
1587 void VT_ProcessControlButton2Motion()
1589 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1590 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
1592 dy = -dy; // Xwindow Y axis is from top to Bottom
1594 ViewerTest::CurrentView()->Panning( dx, dy );
1596 X_ButtonPress = X_Motion;
1597 Y_ButtonPress = Y_Motion;
1600 //==============================================================================
1601 //function : VT_ProcessControlButton3Motion
1602 //purpose : Rotation
1603 //==============================================================================
1604 void VT_ProcessControlButton3Motion()
1608 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1612 //==============================================================================
1613 //function : VT_ProcessMotion
1615 //==============================================================================
1616 void VT_ProcessMotion()
1618 //pre-hilights detected objects at mouse position
1620 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1621 EM->MoveTo(X_Motion, Y_Motion);
1625 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1627 Xpix = X_Motion;Ypix=Y_Motion;
1630 //==============================================================================
1631 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1632 //purpose : Switches to an axonometric, top, left and other views
1633 //==============================================================================
1635 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1637 if ( ViewerTest::CurrentView().IsNull() )
1639 di<<"Call vinit before this command, please"<<"\n";
1643 ViewerTest::CurrentView()->SetProj(ori);
1647 //==============================================================================
1649 //purpose : Switch to an Axonometric view
1650 //Draw arg : No args
1651 //==============================================================================
1653 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1655 return ViewProject(di, V3d_XposYnegZpos);
1658 //==============================================================================
1660 //purpose : Switch to a Top View
1661 //Draw arg : No args
1662 //==============================================================================
1664 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1666 return ViewProject(di, V3d_Zpos);
1669 //==============================================================================
1670 //function : VBottom
1671 //purpose : Switch to a Bottom View
1672 //Draw arg : No args
1673 //==============================================================================
1675 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1677 return ViewProject(di, V3d_Zneg);
1680 //==============================================================================
1682 //purpose : Switch to a Left View
1683 //Draw arg : No args
1684 //==============================================================================
1686 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1688 return ViewProject(di, V3d_Ypos);
1691 //==============================================================================
1693 //purpose : Switch to a Right View
1694 //Draw arg : No args
1695 //==============================================================================
1697 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1699 return ViewProject(di, V3d_Yneg);
1702 //==============================================================================
1704 //purpose : Switch to a Front View
1705 //Draw arg : No args
1706 //==============================================================================
1708 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1710 return ViewProject(di, V3d_Xpos);
1713 //==============================================================================
1715 //purpose : Switch to a Back View
1716 //Draw arg : No args
1717 //==============================================================================
1719 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1721 return ViewProject(di, V3d_Xneg);
1724 //==============================================================================
1726 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1727 //Draw arg : No args
1728 //==============================================================================
1730 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1733 di << "Q : Quit the application" << "\n";
1735 di << "========================="<<"\n";
1736 di << "F : FitAll" << "\n";
1737 di << "T : TopView" << "\n";
1738 di << "B : BottomView" << "\n";
1739 di << "R : RightView" << "\n";
1740 di << "L : LeftView" << "\n";
1741 di << "A : AxonometricView" << "\n";
1742 di << "D : ResetView" << "\n";
1744 di << "========================="<<"\n";
1745 di << "S : Shading" << "\n";
1746 di << "W : Wireframe" << "\n";
1747 di << "H : HidelLineRemoval" << "\n";
1748 di << "U : Unset display mode" << "\n";
1750 di << "========================="<<"\n";
1751 di << "Selection mode "<<"\n";
1752 di << "0 : Shape" <<"\n";
1753 di << "1 : Vertex" <<"\n";
1754 di << "2 : Edge" <<"\n";
1755 di << "3 : Wire" <<"\n";
1756 di << "4 : Face" <<"\n";
1757 di << "5 : Shell" <<"\n";
1758 di << "6 : Solid" <<"\n";
1759 di << "7 : Compound" <<"\n";
1761 di << "========================="<<"\n";
1762 di << "Z : Switch Z clipping On/Off" << "\n";
1763 di << ", : Hilight next detected" << "\n";
1764 di << ". : Hilight previous detected" << "\n";
1771 static Standard_Boolean Ppick = 0;
1772 static Standard_Integer Pargc = 0;
1773 static const char** Pargv = NULL;
1776 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1781 if (!ViewerTest_myViews.IsEmpty()) {
1783 WPARAM fwKeys = wParam;
1788 // Delete view from map of views
1789 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1794 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1795 || ViewerTest::CurrentView().IsNull())
1797 // Activate inactive window
1798 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1800 ActivateView (FindViewIdByWindowHandle(hwnd));
1805 IsDragged = Standard_False;
1808 HDC hdc = GetDC( hwnd );
1809 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1810 SetROP2( hdc, R2_NOT );
1811 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1812 ReleaseDC( hwnd, hdc );
1814 const Handle(ViewerTest_EventManager) EM =
1815 ViewerTest::CurrentEventManager();
1816 if ( fwKeys & MK_SHIFT )
1817 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1818 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1820 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1821 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1823 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1825 case WM_LBUTTONDOWN:
1826 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1828 IsDragged = Standard_True;
1829 DragFirst = Standard_True;
1830 X_ButtonPress = LOWORD(lParam);
1831 Y_ButtonPress = HIWORD(lParam);
1833 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1840 HDC hdc = GetDC( hwnd );
1842 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1843 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1844 SetROP2( hdc, R2_NOT );
1847 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1849 DragFirst = Standard_False;
1850 X_Motion = LOWORD(lParam);
1851 Y_Motion = HIWORD(lParam);
1853 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1855 SelectObject( hdc, anObj );
1857 ReleaseDC( hwnd, hdc );
1860 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1864 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1868 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1872 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1879 if ( !ViewerTest::CurrentView().IsNull() ) {
1884 BeginPaint(hwnd, &ps);
1885 EndPaint(hwnd, &ps);
1890 VT_ProcessConfigure();
1894 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1897 c[0] = (char) wParam;
1899 VT_ProcessKeyPress (c);
1907 VT_ProcessButton3Release();
1910 case WM_LBUTTONDOWN:
1911 case WM_MBUTTONDOWN:
1912 case WM_RBUTTONDOWN:
1914 WPARAM fwKeys = wParam;
1918 X_ButtonPress = LOWORD(lParam);
1919 Y_ButtonPress = HIWORD(lParam);
1921 if (Msg == WM_LBUTTONDOWN)
1923 if (fwKeys & MK_CONTROL)
1925 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1929 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1932 else if (Msg == WM_RBUTTONDOWN)
1935 VT_ProcessButton3Press();
1942 //cout << "\t WM_MOUSEMOVE" << endl;
1943 WPARAM fwKeys = wParam;
1944 X_Motion = LOWORD(lParam);
1945 Y_Motion = HIWORD(lParam);
1948 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
1950 X_ButtonPress = LOWORD(lParam);
1951 Y_ButtonPress = HIWORD(lParam);
1953 if ( fwKeys & MK_RBUTTON ) {
1955 VT_ProcessButton3Press();
1959 if ( fwKeys & MK_CONTROL ) {
1960 if ( fwKeys & MK_LBUTTON ) {
1961 ProcessControlButton1Motion();
1963 else if ( fwKeys & MK_MBUTTON ||
1964 ((fwKeys&MK_LBUTTON) &&
1965 (fwKeys&MK_RBUTTON) ) ){
1966 VT_ProcessControlButton2Motion();
1968 else if ( fwKeys & MK_RBUTTON ) {
1969 VT_ProcessControlButton3Motion();
1973 else if ( fwKeys & MK_SHIFT ) {
1974 if ( fwKeys & MK_MBUTTON ||
1975 ((fwKeys&MK_LBUTTON) &&
1976 (fwKeys&MK_RBUTTON) ) ) {
1977 cout << "ProcessZClipMotion()" << endl;
1978 ProcessZClipMotion();
1983 if ((fwKeys & MK_MBUTTON
1984 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
1986 ProcessZClipMotion();
1996 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2001 return DefWindowProc( hwnd, Msg, wParam, lParam );
2007 //==============================================================================
2008 //function : ViewerMainLoop
2009 //purpose : Get a Event on the view and dispatch it
2010 //==============================================================================
2013 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2015 Ppick = (argc > 0)? 1 : 0;
2023 cout << "Start picking" << endl;
2025 while ( Ppick == 1 ) {
2026 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2027 if (GetMessage(&msg, NULL, 0, 0) ) {
2028 TranslateMessage(&msg);
2029 DispatchMessage(&msg);
2033 cout << "Picking done" << endl;
2039 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2041 int min( int a, int b )
2049 int max( int a, int b )
2057 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2060 static XEvent aReport;
2061 Standard_Boolean pick = argc > 0;
2062 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2063 XNextEvent (aDisplay, &aReport);
2065 // Handle event for the chosen display connection
2066 switch (aReport.type) {
2069 if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2072 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2078 // Activate inactive view
2079 Window aWindow = GetWindowHandle(VT_GetWindow());
2080 if(aWindow != aReport.xfocus.window)
2082 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2091 case ConfigureNotify:
2093 VT_ProcessConfigure();
2102 XComposeStatus status_in_out;
2104 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2105 (char *) buf_ret , 10 ,
2106 &ks_ret , &status_in_out ) ;
2109 buf_ret[ret_len] = '\0' ;
2113 VT_ProcessKeyPress (buf_ret);
2119 X_ButtonPress = aReport.xbutton.x;
2120 Y_ButtonPress = aReport.xbutton.y;
2122 if (aReport.xbutton.button == Button1)
2124 if (aReport.xbutton.state & ControlMask)
2126 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2130 IsDragged = Standard_True;
2131 DragFirst = Standard_True;
2134 else if (aReport.xbutton.button == Button3)
2137 VT_ProcessButton3Press();
2147 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2148 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2149 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2152 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2153 if( aContext.IsNull() )
2155 cout << "The context is null. Please use vinit before createmesh" << endl;
2159 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2160 if( aReport.xbutton.button==1 )
2164 aContext->ShiftSelect();
2173 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2174 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2175 ViewerTest::CurrentView());
2179 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2180 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2181 ViewerTest::CurrentView() );
2184 VT_ProcessButton3Release();
2186 IsDragged = Standard_False;
2189 VT_ProcessButton3Release();
2196 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2197 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2198 XSetFunction( aDisplay, gc, GXinvert );
2201 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2203 X_Motion = aReport.xmotion.x;
2204 Y_Motion = aReport.xmotion.y;
2205 DragFirst = Standard_False;
2207 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2211 X_Motion = aReport.xmotion.x;
2212 Y_Motion = aReport.xmotion.y;
2214 // remove all the ButtonMotionMaskr
2215 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2217 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2218 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2220 Quantity_Length VDX, VDY;
2222 ViewerTest::CurrentView()->Size(VDX,VDY);
2223 Standard_Real VDZ =0 ;
2224 VDZ = ViewerTest::CurrentView()->ZSize();
2226 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2228 Quantity_Length dx = 0 ;
2229 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2233 dx = dx / VDX * VDZ;
2237 ViewerTest::CurrentView()->Redraw();
2241 if ( aReport.xmotion.state & ControlMask ) {
2242 if ( aReport.xmotion.state & Button1Mask ) {
2243 ProcessControlButton1Motion();
2245 else if ( aReport.xmotion.state & Button2Mask ) {
2246 VT_ProcessControlButton2Motion();
2248 else if ( aReport.xmotion.state & Button3Mask ) {
2249 VT_ProcessControlButton3Motion();
2263 //==============================================================================
2264 //function : VProcessEvents
2265 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2266 // event in the Viewer window
2267 //==============================================================================
2269 static void VProcessEvents(ClientData,int)
2271 NCollection_Vector<int> anEventNumbers;
2272 // Get number of messages from every display
2273 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2274 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2276 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2278 // Handle events for every display
2279 int anEventIter = 0;
2280 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2281 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2283 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2284 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2286 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2287 int anEventResult = ViewerMainLoop( 0, NULL);
2288 // If window is closed or context was not found finish current event processing loop
2294 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2299 //==============================================================================
2300 //function : OSWindowSetup
2301 //purpose : Setup for the X11 window to be able to cath the event
2302 //==============================================================================
2305 static void OSWindowSetup()
2307 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2310 Window window = VT_GetWindow()->XWindow();
2311 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2312 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2313 XSynchronize(aDisplay, 1);
2315 // X11 : For keyboard on SUN
2317 wmhints.flags = InputHint;
2320 XSetWMHints( aDisplay, window, &wmhints);
2322 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2323 ButtonPressMask | ButtonReleaseMask |
2324 StructureNotifyMask |
2326 Button1MotionMask | Button2MotionMask |
2327 Button3MotionMask | FocusChangeMask
2329 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2330 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2332 XSynchronize(aDisplay, 0);
2341 //==============================================================================
2344 //purpose : Fitall, no DRAW arguments
2345 //Draw arg : No args
2346 //==============================================================================
2348 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2350 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2351 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2352 if (V.IsNull() == Standard_False) {
2354 } else if (aView.IsNull() == Standard_False) {
2360 //==============================================================================
2362 //purpose : ZFitall, no DRAW arguments
2363 //Draw arg : No args
2364 //==============================================================================
2366 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
2368 Handle(V3d_View) V = ViewerTest::CurrentView();
2369 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
2372 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
2374 Handle(V3d_View) V = ViewerTest::CurrentView();
2375 if ( !V.IsNull() ) V->Redraw(); return 0;
2379 //==============================================================================
2381 //purpose : Remove all the object from the viewer
2382 //Draw arg : No args
2383 //==============================================================================
2385 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2387 Handle(V3d_View) V = ViewerTest::CurrentView();
2389 ViewerTest::Clear();
2393 //==============================================================================
2396 //==============================================================================
2398 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2399 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2402 di << argv[0] << "Invalid number of arguments" << "\n";
2406 while (ViewerMainLoop( argc, argv)) {
2412 //==============================================================================
2413 //function : InitViewerTest
2414 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
2415 //==============================================================================
2417 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
2419 Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2420 ViewerTest::SetAISContext(theContext);
2421 aViewer->InitActiveViews();
2422 Handle(V3d_View) aView = aViewer->ActiveView();
2423 if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
2424 ViewerTest::ResetEventManager();
2425 Handle(Aspect_Window) aWindow = aView->Window();
2426 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2428 VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
2430 static int aFirst = 1;
2432 #if TCL_MAJOR_VERSION < 8
2433 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2434 TK_READABLE, VProcessEvents, (ClientData) 0);
2436 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2437 TK_READABLE, VProcessEvents, (ClientData) 0);
2444 //==============================================================================
2446 //purpose : Load image as background
2447 //==============================================================================
2449 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2451 if (argc < 2 || argc > 3)
2453 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2454 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2458 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2459 if(AISContext.IsNull())
2461 di << "use 'vinit' command before " << argv[0] << "\n";
2465 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2468 const char* szType = argv[2];
2469 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2470 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2471 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2472 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2475 di << "Wrong fill type : " << szType << "\n";
2476 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2481 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2482 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2487 //==============================================================================
2488 //function : VSetBgMode
2489 //purpose : Change background image fill type
2490 //==============================================================================
2492 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2496 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2497 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2501 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2502 if(AISContext.IsNull())
2504 di << "use 'vinit' command before " << argv[0] << "\n";
2508 Aspect_FillMethod aFillType;
2511 const char* szType = argv[1];
2512 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2513 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2514 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2515 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2518 di << "Wrong fill type : " << szType << "\n";
2519 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2524 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2525 V3dView->SetBgImageStyle(aFillType, Standard_True);
2530 //==============================================================================
2531 //function : VSetGradientBg
2532 //purpose : Mount gradient background
2533 //==============================================================================
2534 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2538 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2539 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2540 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2541 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2545 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2546 if(AISContext.IsNull())
2548 di << "use 'vinit' command before " << argv[0] << "\n";
2554 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2555 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2556 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2557 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2559 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2560 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2561 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2563 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2564 int aType = Draw::Atoi(argv[7]);
2565 if( aType < 0 || aType > 8 )
2567 di << "Wrong fill type " << "\n";
2568 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2569 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2573 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2575 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2576 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2582 //==============================================================================
2583 //function : VSetGradientBgMode
2584 //purpose : Change gradient background fill style
2585 //==============================================================================
2586 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2590 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2591 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2592 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2596 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2597 if(AISContext.IsNull())
2599 di << "use 'vinit' command before " << argv[0] << "\n";
2604 int aType = Draw::Atoi(argv[1]);
2605 if( aType < 0 || aType > 8 )
2607 di << "Wrong fill type " << "\n";
2608 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2609 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2613 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2615 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2616 V3dView->SetBgGradientStyle( aMethod, 1 );
2622 //==============================================================================
2623 //function : VSetColorBg
2624 //purpose : Set color background
2625 //==============================================================================
2626 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2630 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2631 di << "R,G,B = [0..255]" << "\n";
2635 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2636 if(AISContext.IsNull())
2638 di << "use 'vinit' command before " << argv[0] << "\n";
2644 Standard_Real R = Draw::Atof(argv[1])/255.;
2645 Standard_Real G = Draw::Atof(argv[2])/255.;
2646 Standard_Real B = Draw::Atof(argv[3])/255.;
2647 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2649 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2650 V3dView->SetBackgroundColor( aColor );
2657 //==============================================================================
2659 //purpose : View Scaling
2660 //==============================================================================
2662 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2664 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2665 if ( V3dView.IsNull() ) return 1;
2668 di << argv[0] << "Invalid number of arguments" << "\n";
2671 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2674 //==============================================================================
2675 //function : VTestZBuffTrihedron
2676 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2677 //==============================================================================
2679 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2681 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2682 if ( V3dView.IsNull() ) return 1;
2684 V3dView->ZBufferTriedronSetup();
2687 // Set up default trihedron parameters
2688 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2692 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2693 const char* aPosType = argv[1];
2695 if ( strcmp(aPosType, "center") == 0 )
2697 aPosition = Aspect_TOTP_CENTER;
2699 if (strcmp(aPosType, "left_lower") == 0)
2701 aPosition = Aspect_TOTP_LEFT_LOWER;
2703 if (strcmp(aPosType, "left_upper") == 0)
2705 aPosition = Aspect_TOTP_LEFT_UPPER;
2707 if (strcmp(aPosType, "right_lower") == 0)
2709 aPosition = Aspect_TOTP_RIGHT_LOWER;
2711 if (strcmp(aPosType, "right_upper") == 0)
2713 aPosition = Aspect_TOTP_RIGHT_UPPER;
2716 di << argv[1] << " Invalid type of alignment" << "\n";
2717 di << "Must be one of [ center, left_lower," << "\n";
2718 di << "left_upper, right_lower, right_upper ]" << "\n";
2722 Standard_Real R = Draw::Atof(argv[2])/255.;
2723 Standard_Real G = Draw::Atof(argv[3])/255.;
2724 Standard_Real B = Draw::Atof(argv[4])/255.;
2725 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2727 Standard_Real aScale = Draw::Atof(argv[5]);
2731 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2735 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2736 const char* aPresType = argv[6];
2738 if ( strcmp(aPresType, "wireframe") == 0 )
2740 aPresentation = V3d_WIREFRAME;
2742 if (strcmp(aPresType, "zbuffer") == 0)
2744 aPresentation = V3d_ZBUFFER;
2747 di << argv[6] << " Invalid type of visualization" << "\n";
2748 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2752 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2756 di << argv[0] << " Invalid number of arguments" << "\n";
2765 //==============================================================================
2766 //function : VRotate
2767 //purpose : Camera Rotating
2768 //==============================================================================
2770 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2771 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2772 if ( V3dView.IsNull() ) {
2777 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2779 } else if ( argc == 7 ) {
2780 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5]), Draw::Atof(argv[6]) );
2783 di << argv[0] << " Invalid number of arguments" << "\n";
2788 //==============================================================================
2790 //purpose : View zoom in / out (relative to current zoom)
2791 //==============================================================================
2793 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2794 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2795 if ( V3dView.IsNull() ) {
2800 Standard_Real coef = Draw::Atof(argv[1]);
2801 if ( coef <= 0.0 ) {
2802 di << argv[1] << "Invalid value" << "\n";
2805 V3dView->SetZoom( Draw::Atof(argv[1]) );
2808 di << argv[0] << " Invalid number of arguments" << "\n";
2813 //==============================================================================
2815 //purpose : View panning (in pixels)
2816 //==============================================================================
2818 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2819 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2820 if ( V3dView.IsNull() ) return 1;
2823 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2826 di << argv[0] << " Invalid number of arguments" << "\n";
2832 //==============================================================================
2833 //function : VExport
2834 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2835 //==============================================================================
2837 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2839 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2840 if (V3dView.IsNull())
2845 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2849 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2850 TCollection_AsciiString aFormatStr;
2852 TCollection_AsciiString aFileName (argv[1]);
2853 Standard_Integer aLen = aFileName.Length();
2857 aFormatStr = TCollection_AsciiString (argv[2]);
2861 if (aFileName.Value (aLen - 2) == '.')
2863 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2865 else if (aFileName.Value (aLen - 3) == '.')
2867 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2871 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2877 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2881 aFormatStr.UpperCase();
2882 if (aFormatStr == "PS")
2883 anExpFormat = Graphic3d_EF_PostScript;
2884 else if (aFormatStr == "EPS")
2885 anExpFormat = Graphic3d_EF_EnhPostScript;
2886 else if (aFormatStr == "TEX")
2887 anExpFormat = Graphic3d_EF_TEX;
2888 else if (aFormatStr == "PDF")
2889 anExpFormat = Graphic3d_EF_PDF;
2890 else if (aFormatStr == "SVG")
2891 anExpFormat = Graphic3d_EF_SVG;
2892 else if (aFormatStr == "PGF")
2893 anExpFormat = Graphic3d_EF_PGF;
2894 else if (aFormatStr == "EMF")
2895 anExpFormat = Graphic3d_EF_EMF;
2898 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2903 if (!V3dView->View()->Export (argv[1], anExpFormat))
2905 di << "Error: export of image to " << aFormatStr << " failed!\n";
2908 catch (Standard_Failure)
2910 di << "Error: export of image to " << aFormatStr << " failed";
2911 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
2916 //==============================================================================
2917 //function : VColorScale
2918 //purpose : representation color scale
2919 //==============================================================================
2920 #include <V3d_ColorScale.hxx>
2922 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2924 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
2926 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
2930 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2931 if(aContext.IsNull()) {
2932 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
2936 Standard_Real minRange = 0. , maxRange = 100. ;
2938 Standard_Integer numIntervals = 10 ;
2939 Standard_Integer textHeight = 16;
2940 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
2941 Standard_Real X = 0., Y = 0. ;
2947 minRange = Draw::Atof( argv[1] );
2948 maxRange = Draw::Atof( argv[2] );
2949 numIntervals = Draw::Atoi( argv[3] );
2952 textHeight = Draw::Atoi( argv[4] );
2954 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
2957 X = Draw::Atof( argv[6] );
2958 Y = Draw::Atof( argv[7] );
2961 Handle(V3d_View) curView = ViewerTest::CurrentView( );
2962 if ( curView.IsNull( ) )
2964 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
2965 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
2966 if( ! aCS.IsNull( ) )
2968 aCS->SetPosition( X , Y );
2969 aCS->SetHeight( 0.95) ;
2970 aCS->SetTextHeight( textHeight );
2971 aCS->SetRange( minRange , maxRange );
2972 aCS->SetNumberOfIntervals( numIntervals );
2973 aCS->SetLabelPosition( position );
2974 if( !curView->ColorScaleIsDisplayed() )
2975 curView->ColorScaleDisplay( );
2980 //==============================================================================
2981 //function : VGraduatedTrihedron
2982 //purpose : Displays a graduated trihedron
2983 //==============================================================================
2985 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
2987 const char *str = arg;
2990 unsigned short c1 = *str++;
2991 unsigned short c2 = *str++;
2992 if (!c1 || !c2) break;
2993 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2997 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3000 if (argc != 2 && argc < 5)
3002 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3003 di<<"Usage: type help "<<argv[0]<<"\n";
3004 return 1; //TCL_ERROR
3007 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3009 // Create 3D view if it doesn't exist
3010 if ( aV3dView.IsNull() )
3012 ViewerTest::ViewerInit();
3013 aV3dView = ViewerTest::CurrentView();
3014 if( aV3dView.IsNull() )
3016 di << "Error: Cannot create a 3D view\n";
3017 return 1; //TCL_ERROR
3021 // Erase (==0) or display (!=0)
3022 const int display = Draw::Atoi(argv[1]);
3027 TCollection_AsciiString font;
3029 font.AssignCat("Courier");
3031 font.AssignCat(argv[5]);
3033 // Text is multibyte
3034 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3037 TCollection_ExtendedString xname, yname, zname;
3042 AddMultibyteString(xname, argv[2]);
3043 AddMultibyteString(yname, argv[3]);
3044 AddMultibyteString(zname, argv[4]);
3060 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3061 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3062 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3063 Standard_True/*drawgrid*/,
3064 Standard_True/*drawaxes*/,
3065 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3066 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3067 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3068 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3069 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3070 Quantity_NOC_WHITE/*gridcolor*/,
3071 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3072 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3075 aV3dView->GraduatedTrihedronErase();
3077 ViewerTest::GetAISContext()->UpdateCurrentViewer();
3083 //==============================================================================
3084 //function : VPrintView
3085 //purpose : Test printing algorithm, print the view to image file with given
3086 // width and height. Printing implemented only for WNT.
3087 //==============================================================================
3088 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3092 di << "Printing implemented only for wnt!\n";
3096 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3097 Handle(V3d_View) aView = NULL;
3098 aContextAIS = ViewerTest::GetAISContext();
3099 if (!aContextAIS.IsNull())
3101 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3102 Vwr->InitActiveViews();
3103 if(Vwr->MoreActiveViews())
3104 aView = Vwr->ActiveView();
3110 di << "Call vinit before!\n";
3115 di << "Use: " << argv[0];
3116 di << " width height filename [print algo=0]\n";
3117 di << "width, height of the intermediate buffer for operation\n";
3118 di << "algo : {0|1}\n";
3119 di << " 0 - stretch algorithm\n";
3120 di << " 1 - tile algorithm\n";
3121 di << "test printing algorithms into an intermediate buffer\n";
3122 di << "with saving output to an image file\n";
3126 // get the input params
3127 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3128 Standard_Integer aHeight = Draw::Atoi (argv[2]);
3129 Standard_Integer aMode = 0;
3130 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3132 aMode = Draw::Atoi (argv[4]);
3134 // check the input parameters
3135 if (aWidth <= 0 || aHeight <= 0)
3137 di << "Width and height must be positive values!\n";
3140 if (aMode != 0 && aMode != 1)
3143 // define compatible bitmap
3144 HDC anDC = CreateCompatibleDC(0);
3145 BITMAPINFO aBitmapData;
3146 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3147 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3148 aBitmapData.bmiHeader.biWidth = aWidth ;
3149 aBitmapData.bmiHeader.biHeight = aHeight;
3150 aBitmapData.bmiHeader.biPlanes = 1;
3151 aBitmapData.bmiHeader.biBitCount = 24;
3152 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3153 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3154 aBitmapData.bmiHeader.biClrUsed = 0;
3155 aBitmapData.bmiHeader.biClrImportant = 0;
3156 aBitmapData.bmiHeader.biCompression = BI_RGB;
3157 aBitmapData.bmiHeader.biSizeImage = 0;
3159 // Create Device Independent Bitmap
3160 void* aBitsOut = NULL;
3161 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3162 &aBitsOut, NULL, 0);
3163 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3165 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3166 if (aBitsOut != NULL)
3169 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3171 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
3173 // succesfully printed into an intermediate buffer
3176 Image_PixMap aWrapper;
3177 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3178 aWrapper.SetTopDown (false);
3180 Image_AlienPixMap anImageBitmap;
3181 anImageBitmap.InitCopy (aWrapper);
3182 isSaved = anImageBitmap.Save (aFileName);
3186 di << "Print operation failed due to printing errors or\n";
3187 di << "insufficient memory available\n";
3188 di << "Please, try to use smaller dimensions for this test\n";
3189 di << "command, as it allocates intermediate buffer for storing\n";
3190 di << "the result\n";
3195 di << "Can't allocate memory for intermediate buffer\n";
3196 di << "Please use smaller dimensions\n";
3201 SelectObject (anDC, anOldBitmap);
3202 DeleteObject (aMemoryBitmap);
3208 di << "Save to file operation failed. This operation may fail\n";
3209 di << "if you don't have enough available memory, then you can\n";
3210 di << "use smaller dimensions for the output file\n";
3219 //==============================================================================
3220 //function : VZLayer
3221 //purpose : Test z layer operations for v3d viewer
3222 //==============================================================================
3223 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3225 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3226 if (aContextAIS.IsNull())
3228 di << "Call vinit before!\n";
3233 di << "Use: vzlayer " << argv[0];
3234 di << " add/del/get [id]\n";
3235 di << " add - add new z layer to viewer and print its id\n";
3236 di << " del - del z layer by its id\n";
3237 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3238 di << "id - the layer identificator value defined when removing z layer\n";
3242 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3243 if (aViewer.IsNull())
3245 di << "No active viewer!\n";
3249 // perform operation
3250 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3253 Standard_Integer aNewId;
3254 if (!aViewer->AddZLayer (aNewId))
3256 di << "Impossible to add new z layer!\n";
3260 di << "New z layer added with index: " << aNewId << "\n";
3262 else if (anOp == "del")
3266 di << "Please also provide as argument id of z layer to remove\n";
3270 Standard_Integer aDelId = Draw::Atoi (argv[2]);
3271 if (!aViewer->RemoveZLayer (aDelId))
3273 di << "Impossible to remove the z layer or invalid id!\n";
3277 di << "Z layer " << aDelId << " has been removed\n";
3279 else if (anOp == "get")
3281 TColStd_SequenceOfInteger anIds;
3282 aViewer->GetAllZLayers (anIds);
3283 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3285 di << anIds.Value (aSeqIdx) << " ";
3292 di << "Invalid operation, please use { add / del / get }\n";
3299 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3301 // this class provides a presentation of text item in v3d view under-/overlayer
3302 class V3d_TextItem : public Visual3d_LayerItem
3307 DEFINE_STANDARD_RTTI(V3d_TextItem)
3310 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3311 const Standard_Real theX1,
3312 const Standard_Real theY1,
3313 const Standard_Real theHeight,
3314 const TCollection_AsciiString& theFontName,
3315 const Quantity_Color& theColor,
3316 const Quantity_Color& theSubtitleColor,
3317 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3318 const Handle(Visual3d_Layer)& theLayer);
3321 Standard_EXPORT void RedrawLayerPrs();
3327 Standard_Real myHeight;
3328 TCollection_AsciiString myText;
3329 TCollection_AsciiString myFontName;
3330 Quantity_Color myColor;
3331 Quantity_Color mySubtitleColor;
3332 Aspect_TypeOfDisplayText myType;
3333 Handle(Visual3d_Layer) myLayer;
3337 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3338 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3340 // create and add to display the text item
3341 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3342 const Standard_Real theX1,
3343 const Standard_Real theY1,
3344 const Standard_Real theHeight,
3345 const TCollection_AsciiString& theFontName,
3346 const Quantity_Color& theColor,
3347 const Quantity_Color& theSubtitleColor,
3348 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3349 const Handle(Visual3d_Layer)& theLayer)
3350 : myX1 (theX1), myY1 (theY1),
3352 myHeight (theHeight),
3355 mySubtitleColor (theSubtitleColor),
3356 myType (theTypeOfDisplay),
3357 myFontName (theFontName)
3359 if (!myLayer.IsNull ())
3360 myLayer->AddLayerItem (this);
3364 void V3d_TextItem::RedrawLayerPrs ()
3366 if (myLayer.IsNull ())
3369 myLayer->SetColor (myColor);
3370 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3371 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3374 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3376 // The Visual3d_LayerItem line item for "vlayerline" command
3377 // it provides a presentation of line with user-defined
3378 // linewidth, linetype and transparency.
3379 class V3d_LineItem : public Visual3d_LayerItem
3383 DEFINE_STANDARD_RTTI(V3d_LineItem)
3386 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3387 Standard_Real X2, Standard_Real Y2,
3388 V3d_LayerMgrPointer theLayerMgr,
3389 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3390 Standard_Real theWidth = 0.5,
3391 Standard_Real theTransp = 1.0);
3394 Standard_EXPORT void RedrawLayerPrs();
3398 Standard_Real myX1, myY1, myX2, myY2;
3399 Standard_Real myWidth;
3400 Standard_Real myTransparency;
3401 Aspect_TypeOfLine myType;
3402 V3d_LayerMgrPointer myLayerMgr;
3405 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3406 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3408 // default constructor for line item
3409 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3410 Standard_Real X2, Standard_Real Y2,
3411 V3d_LayerMgrPointer theLayerMgr,
3412 Aspect_TypeOfLine theType,
3413 Standard_Real theWidth,
3414 Standard_Real theTransp) :
3415 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3416 myType(theType), myWidth(theWidth), myTransparency(theTransp)
3418 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3419 myLayerMgr->Overlay()->AddLayerItem (this);
3423 void V3d_LineItem::RedrawLayerPrs ()
3425 Handle (Visual3d_Layer) aOverlay;
3428 aOverlay = myLayerMgr->Overlay();
3430 if (!aOverlay.IsNull())
3432 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3433 aOverlay->SetColor(aColor);
3434 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3435 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3436 aOverlay->BeginPolyline();
3437 aOverlay->AddVertex(myX1, myY1);
3438 aOverlay->AddVertex(myX2, myY2);
3439 aOverlay->ClosePrimitive();
3443 //=============================================================================
3444 //function : VLayerLine
3445 //purpose : Draws line in the v3d view layer with given attributes: linetype,
3446 // : linewidth, transparency coefficient
3447 //============================================================================
3448 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3450 // get the active view
3451 Handle(V3d_View) aView = ViewerTest::CurrentView();
3454 di << "Call vinit before!\n";
3459 di << "Use: " << argv[0];
3460 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3461 di << " linetype : { 0 | 1 | 2 | 3 } \n";
3462 di << " 0 - solid \n";
3463 di << " 1 - dashed \n";
3464 di << " 2 - dot \n";
3465 di << " 3 - dashdot\n";
3466 di << " transparency : { 0.0 - 1.0 } \n";
3467 di << " 0.0 - transparent\n";
3468 di << " 1.0 - visible \n";
3472 // get the input params
3473 Standard_Real X1 = Draw::Atof(argv[1]);
3474 Standard_Real Y1 = Draw::Atof(argv[2]);
3475 Standard_Real X2 = Draw::Atof(argv[3]);
3476 Standard_Real Y2 = Draw::Atof(argv[4]);
3478 Standard_Real aWidth = 0.5;
3479 Standard_Integer aType = 0;
3480 Standard_Real aTransparency = 1.0;