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 <AIS_KindOfInteractive.hxx>
19 #include <Aspect_TypeOfLine.hxx>
20 #include <Aspect_TypeOfMarker.hxx>
21 #include <Draw_Interpretor.hxx>
22 #include <Graphic3d_TypeOfShadingModel.hxx>
23 #include <Graphic3d_ZLayerId.hxx>
24 #include <TCollection_AsciiString.hxx>
25 #include <TColStd_HArray1OfTransient.hxx>
26 #include <TopTools_ListOfShape.hxx>
27 #include <TopTools_HArray1OfShape.hxx>
28 #include <Quantity_ColorRGBA.hxx>
30 class AIS_InteractiveContext;
31 class AIS_InteractiveObject;
35 class ViewerTest_EventManager;
44 //! Loads all Draw commands of V2d & V3d. Used for plugin.
45 Standard_EXPORT static void Factory (Draw_Interpretor& theDI);
47 //! Creates view with default or custom name
48 //! and adds this name in map to manage multiple views.
49 //! Implemented in ViewerTest_ViewerCommands.cxx.
50 //! @param thePxLeft left position of newly created window
51 //! @param thePxTop top position of newly created window
52 //! @param thePxWidth width of newly created window
53 //! @param thePxHeight height of newly created window
54 //! @param theViewName name of newly created View
55 //! @oaram theDisplayName display name
56 //! @param theViewToClone when specified, the new View will copy properties of existing one
57 Standard_EXPORT static TCollection_AsciiString ViewerInit (const Standard_Integer thePxLeft = 0,
58 const Standard_Integer thePxTop = 0,
59 const Standard_Integer thePxWidth = 0,
60 const Standard_Integer thePxHeight = 0,
61 const TCollection_AsciiString& theViewName = "",
62 const TCollection_AsciiString& theDisplayName = "",
63 const Handle(V3d_View)& theViewToClone = Handle(V3d_View)());
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 Standard_EXPORT static void Commands (Draw_Interpretor& theCommands);
108 Standard_EXPORT static void ViewerCommands (Draw_Interpretor& theCommands);
110 Standard_EXPORT static void MyCommands (Draw_Interpretor& theCommands);
112 Standard_EXPORT static void RelationCommands (Draw_Interpretor& theCommands);
114 Standard_EXPORT static void ObjectCommands (Draw_Interpretor& theCommands);
116 Standard_EXPORT static void FilletCommands (Draw_Interpretor& theCommands);
118 Standard_EXPORT static void OpenGlCommands (Draw_Interpretor& theCommands);
120 Standard_EXPORT static void GetMousePosition (Standard_Integer& xpix, Standard_Integer& ypix);
122 Standard_EXPORT static Handle(V3d_Viewer) GetViewerFromContext();
124 Standard_EXPORT static Handle(V3d_Viewer) GetCollectorFromContext();
126 Standard_EXPORT static const Handle(AIS_InteractiveContext)& GetAISContext();
128 Standard_EXPORT static void SetAISContext (const Handle(AIS_InteractiveContext)& aContext);
130 Standard_EXPORT static const Handle(V3d_View)& CurrentView();
132 Standard_EXPORT static void CurrentView (const Handle(V3d_View)& aViou);
134 Standard_EXPORT static void Clear();
136 //! puts theMgr as current eventmanager (the move,select,...will be applied to theMgr)
137 Standard_EXPORT static void SetEventManager (const Handle(ViewerTest_EventManager)& theMgr);
139 //! removes the last EventManager from the list.
140 Standard_EXPORT static void UnsetEventManager();
142 //! clear the list of EventManagers and
143 //! sets the default EventManager as current
144 Standard_EXPORT static void ResetEventManager();
146 Standard_EXPORT static Handle(ViewerTest_EventManager) CurrentEventManager();
148 Standard_EXPORT static void RemoveSelected();
150 Standard_EXPORT static Quantity_NameOfColor GetColorFromName (const Standard_CString name);
152 //! Parses RGB(A) color argument(s) specified within theArgVec[0], theArgVec[1], theArgVec[2] and theArgVec[3].
153 //! Handles either color specified by name (single argument)
154 //! or by RGB(A) components (3-4 arguments) in range 0..1.
155 //! The result is stored in theColor on success.
156 //! Returns number of handled arguments (1, 3 or 4) or 0 on syntax error.
157 static Standard_Integer ParseColor (Standard_Integer theArgNb,
158 const char** theArgVec,
159 Quantity_ColorRGBA& theColor)
161 return parseColor (theArgNb, theArgVec, theColor, true);
164 //! Parses RGB color argument(s).
165 //! Returns number of handled arguments (1 or 3) or 0 on syntax error.
166 static Standard_Integer ParseColor (Standard_Integer theArgNb,
167 const char** theArgVec,
168 Quantity_Color& theColor)
170 Quantity_ColorRGBA anRgba;
171 Standard_Integer aNbParsed = parseColor (theArgNb, theArgVec, anRgba, false);
174 theColor = anRgba.GetRGB();
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);
197 //! Parses line type argument.
198 //! Handles either enumeration (integer) value or string constant.
199 Standard_EXPORT static Standard_Boolean ParseLineType (Standard_CString theArg,
200 Aspect_TypeOfLine& theType);
202 //! Parses marker type argument.
203 //! Handles either enumeration (integer) value or string constant.
204 Standard_EXPORT static Standard_Boolean ParseMarkerType (Standard_CString theArg,
205 Aspect_TypeOfMarker& theType,
206 Handle(Image_PixMap)& theImage);
208 //! Parses shading model argument.
209 //! Handles either enumeration (integer) value or string constant.
210 Standard_EXPORT static Standard_Boolean ParseShadingModel (Standard_CString theArg,
211 Graphic3d_TypeOfShadingModel& theModel);
213 //! Parses ZLayer name.
214 //! @param theArg [in] layer name or enumeration alias
215 //! @param theLayer [out] layer index
216 //! @return TRUE if layer has been identified, note that Graphic3d_ZLayerId_UNKNOWN is also valid value
217 static Standard_Boolean ParseZLayerName (Standard_CString theArg,
218 Graphic3d_ZLayerId& theLayer)
220 return parseZLayer (theArg, false, theLayer);
223 //! Parses ZLayer name.
224 //! @param theArg [in] layer name, enumeration alias or index (of existing Layer)
225 //! @param theLayer [out] layer index
226 //! @return TRUE if layer has been identified, note that Graphic3d_ZLayerId_UNKNOWN is also valid value
227 static Standard_Boolean ParseZLayer (Standard_CString theArg,
228 Graphic3d_ZLayerId& theLayer)
230 return parseZLayer (theArg, true, theLayer);
235 //! Parses RGB(A) color argument(s) specified within theArgVec[0], theArgVec[1], theArgVec[2] and theArgVec[3].
236 //! Handles either color specified by name (single argument)
237 //! or by RGB(A) components (3-4 arguments) in range 0..1.
238 //! The result is stored in theColor on success.
239 //! Returns number of handled arguments (1, 3 or 4) or 0 on syntax error.
240 Standard_EXPORT static Standard_Integer parseColor (Standard_Integer theArgNb,
241 const char** theArgVec,
242 Quantity_ColorRGBA& theColor,
243 bool theToParseAlpha);
245 //! Parses ZLayer name.
246 //! @param theArg [in] layer name, enumeration alias or index (of existing Layer)
247 //! @param theToAllowInteger [in] when TRUE, the argument will be checked for existing layer index
248 //! @param theLayer [out] layer index
249 //! @return TRUE if layer has been identified, note that Graphic3d_ZLayerId_UNKNOWN is also valid value
250 Standard_EXPORT static Standard_Boolean parseZLayer (Standard_CString theArg,
251 Standard_Boolean theToAllowInteger,
252 Graphic3d_ZLayerId& theLayer);
254 //! Returns a window class that implements standard behavior of
255 //! all windows of the ViewerTest. This includes usual Open CASCADE
256 //! view conventions for mouse buttons (e.g. Ctrl+MB1 for zoom,
257 //! Ctrl+MB2 for pan, etc) and keyboard shortcuts.
258 //! This method is relevant for MS Windows only and respectively
259 //! returns WNT_WClass handle.
260 static const Handle(Standard_Transient)& WClass();
263 #endif // _ViewerTest_HeaderFile