1 // Copyright (c) 1997-1999 Matra Datavision
2 // Copyright (c) 1999-2015 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _ViewerTest_HeaderFile
16 #define _ViewerTest_HeaderFile
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Macro.hxx>
22 #include <Draw_Interpretor.hxx>
23 #include <Standard_Integer.hxx>
24 #include <Standard_CString.hxx>
25 #include <Standard_Boolean.hxx>
26 #include <TopAbs_ShapeEnum.hxx>
27 #include <TopTools_HArray1OfShape.hxx>
28 #include <TopTools_ListOfShape.hxx>
29 #include <AIS_KindOfInteractive.hxx>
30 #include <Aspect_TypeOfLine.hxx>
31 #include <TColStd_HArray1OfTransient.hxx>
32 #include <Quantity_NameOfColor.hxx>
35 class TCollection_AsciiString;
39 class AIS_InteractiveObject;
41 class AIS_InteractiveContext;
42 class ViewerTest_EventManager;
43 class ViewerTest_EventManager;
52 //! Loads all Draw commands of V2d & V3d. Used for plugin.
53 Standard_EXPORT static void Factory (Draw_Interpretor& theDI);
55 //! Creates view with default or custom name
56 //! and add this name in map to manage muliple views
57 //! implemented in ViewerTest_ViewerCommands.cxx
58 Standard_EXPORT static TCollection_AsciiString ViewerInit (const Standard_Integer thePxLeft = 0,
59 const Standard_Integer thePxTop = 0,
60 const Standard_Integer thePxWidth = 0,
61 const Standard_Integer thePxHeight = 0,
62 const Standard_CString theViewName = "",
63 const Standard_CString theDisplayName = "");
65 Standard_EXPORT static void RemoveViewName (const TCollection_AsciiString& theName);
67 Standard_EXPORT static void InitViewName (const TCollection_AsciiString& theName,
68 const Handle(V3d_View)& theView);
70 Standard_EXPORT static TCollection_AsciiString GetCurrentViewName();
72 //! Removes view and clear all maps
73 //! with information about its resources if necessary
74 Standard_EXPORT static void RemoveView (const TCollection_AsciiString& theViewName,
75 const Standard_Boolean theToRemoveContext = Standard_True);
77 //! Removes view and clear all maps
78 //! with information about its resources if necessary
79 Standard_EXPORT static void RemoveView (const Handle(V3d_View)& theView,
80 const Standard_Boolean theToRemoveContext = Standard_True);
82 //! Display AIS object in active Viewer and register it in the map of Interactive Objects with specified name.
83 //! @param theName key to be associated to displayed interactive object
84 //! @param theObject object to display
85 //! @param theToUpdate redraw viewer after displaying object
86 //! @param theReplaceIfExists replace the object assigned to specified key
87 //! @return true if new object has been displayed
88 Standard_EXPORT static Standard_Boolean Display (const TCollection_AsciiString& theName,
89 const Handle(AIS_InteractiveObject)& theObject,
90 const Standard_Boolean theToUpdate = Standard_True,
91 const Standard_Boolean theReplaceIfExists = Standard_True);
93 //! waits until a shape of type <aType> is picked in the AIS Viewer and returns it.
94 //! if <aType> == TopAbs_Shape, any shape can be picked...
95 //! MaxPick is the Max number before exiting, if no pick is successful
96 Standard_EXPORT static TopoDS_Shape PickShape (const TopAbs_ShapeEnum aType,
97 const Standard_Integer MaxPick = 5);
99 //! wait until the array is filled with picked shapes.
100 //! returns True if the array is filled.
101 //! exit if number of unsuccessful picks = <MaxPick>
102 Standard_EXPORT static Standard_Boolean PickShapes (const TopAbs_ShapeEnum aType,
103 Handle(TopTools_HArray1OfShape)& thepicked,
104 const Standard_Integer MaxPick = 5);
106 //! waits until an interactive object of a given Type
107 //! and signature is picked (default values authorize
108 //! selection of any Interactive Object)
109 //! exit if number of unsuccessful picks = <MaxPick>
110 Standard_EXPORT static Handle(AIS_InteractiveObject) PickObject (const AIS_KindOfInteractive Type = AIS_KOI_None,
111 const Standard_Integer Signature = -1,
112 const Standard_Integer MaxPick = 5);
114 //! selection of several interactive objects.
115 //! Number is given by the size of <thepicked>
116 //! exit if number of unsuccesfull picks = <MaxPick>
117 Standard_EXPORT static Standard_Boolean PickObjects (Handle(TColStd_HArray1OfTransient)& thepicked,
118 const AIS_KindOfInteractive Type = AIS_KOI_None,
119 const Standard_Integer Signature = -1,
120 const Standard_Integer MaxPick = 5);
122 Standard_EXPORT static void Commands (Draw_Interpretor& theCommands);
124 Standard_EXPORT static void ViewerCommands (Draw_Interpretor& theCommands);
126 Standard_EXPORT static void MyCommands (Draw_Interpretor& theCommands);
128 Standard_EXPORT static void RelationCommands (Draw_Interpretor& theCommands);
130 Standard_EXPORT static void ObjectCommands (Draw_Interpretor& theCommands);
132 Standard_EXPORT static void FilletCommands (Draw_Interpretor& theCommands);
134 Standard_EXPORT static void OpenGlCommands (Draw_Interpretor& theCommands);
136 Standard_EXPORT static void GetMousePosition (Standard_Integer& xpix, Standard_Integer& ypix);
138 Standard_EXPORT static Handle(V3d_Viewer) GetViewerFromContext();
140 Standard_EXPORT static Handle(V3d_Viewer) GetCollectorFromContext();
142 Standard_EXPORT static const Handle(AIS_InteractiveContext)& GetAISContext();
144 Standard_EXPORT static void SetAISContext (const Handle(AIS_InteractiveContext)& aContext);
146 Standard_EXPORT static const Handle(V3d_View)& CurrentView();
148 Standard_EXPORT static void CurrentView (const Handle(V3d_View)& aViou);
150 Standard_EXPORT static void Clear();
152 //! puts theMgr as current eventmanager (the move,select,...will be applied to theMgr)
153 Standard_EXPORT static void SetEventManager (const Handle(ViewerTest_EventManager)& theMgr);
155 //! removes the last EventManager from the list.
156 Standard_EXPORT static void UnsetEventManager();
158 //! clear the list of EventManagers and
159 //! sets the default EventManager as current
160 Standard_EXPORT static void ResetEventManager();
162 Standard_EXPORT static Handle(ViewerTest_EventManager) CurrentEventManager();
164 Standard_EXPORT static void RemoveSelected();
166 Standard_EXPORT static void StandardModeActivation (const Standard_Integer Mode);
168 Standard_EXPORT static Quantity_NameOfColor GetColorFromName (const Standard_CString name);
170 //! Parses color argument(s) specified within theArgVec[0], theArgVec[1] and theArgVec[2].
171 //! Handles either color specified by name (single argument)
172 //! or by RGB components (3 arguments) in range 0..1.
173 //! The result is stored in theColor on success.
174 //! Returns number of handled arguments (1 or 3) or 0 on syntax error.
175 Standard_EXPORT static Standard_Integer ParseColor (Standard_Integer theArgNb,
176 const char** theArgVec,
177 Quantity_Color& theColor);
179 //! redraws all defined views.
180 Standard_EXPORT static void RedrawAllViews();
182 //! Splits "parameter=value" string into separate
183 //! parameter and value strings.
184 //! @return TRUE if the string matches pattern "<string>=<empty or string>"
185 Standard_EXPORT static Standard_Boolean SplitParameter (const TCollection_AsciiString& theString,
186 TCollection_AsciiString& theName,
187 TCollection_AsciiString& theValue);
189 //! Parses boolean argument.
190 //! Handles either flag specified by 0|1 or on|off.
191 Standard_EXPORT static Standard_Boolean ParseOnOff (Standard_CString theArg,
192 Standard_Boolean& theIsOn);
194 //! Returns list of selected shapes.
195 Standard_EXPORT static void GetSelectedShapes (TopTools_ListOfShape& theShapes);
198 //! Parses line type argument.
199 //! Handles either enumeration (integer) value or string constant.
200 Standard_EXPORT static Standard_Boolean ParseLineType (Standard_CString theArg,
201 Aspect_TypeOfLine& theType);
205 //! Returns a window class that implements standard behavior of
206 //! all windows of the ViewerTest. This includes usual Open CASCADE
207 //! view conventions for mouse buttons (e.g. Ctrl+MB1 for zoom,
208 //! Ctrl+MB2 for pan, etc) and keyboard shortcuts.
209 //! This method is relevant for MS Windows only and respectively
210 //! returns WNT_WClass handle.
211 Standard_EXPORT static const Handle(MMgt_TShared)& WClass();
214 #endif // _ViewerTest_HeaderFile