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;
45 //! Loads all Draw commands of V2d & V3d. Used for plugin.
46 Standard_EXPORT static void Factory (Draw_Interpretor& theDI);
48 //! Creates view with default or custom name
49 //! and adds this name in map to manage multiple views.
50 //! Implemented in ViewerTest_ViewerCommands.cxx.
51 //! @param thePxLeft left position of newly created window
52 //! @param thePxTop top position of newly created window
53 //! @param thePxWidth width of newly created window
54 //! @param thePxHeight height of newly created window
55 //! @param theViewName name of newly created View
56 //! @oaram theDisplayName display name
57 //! @param theViewToClone when specified, the new View will copy properties of existing one
58 //! @param theIsVirtual force creation of virtual off-screen window within interactive session
59 Standard_EXPORT static TCollection_AsciiString ViewerInit (const Standard_Integer thePxLeft = 0,
60 const Standard_Integer thePxTop = 0,
61 const Standard_Integer thePxWidth = 0,
62 const Standard_Integer thePxHeight = 0,
63 const TCollection_AsciiString& theViewName = "",
64 const TCollection_AsciiString& theDisplayName = "",
65 const Handle(V3d_View)& theViewToClone = Handle(V3d_View)(),
66 const Standard_Boolean theIsVirtual = false);
68 Standard_EXPORT static void RemoveViewName (const TCollection_AsciiString& theName);
70 Standard_EXPORT static void InitViewName (const TCollection_AsciiString& theName,
71 const Handle(V3d_View)& theView);
73 Standard_EXPORT static TCollection_AsciiString GetCurrentViewName();
75 //! Removes view and clear all maps
76 //! with information about its resources if necessary
77 Standard_EXPORT static void RemoveView (const TCollection_AsciiString& theViewName,
78 const Standard_Boolean theToRemoveContext = Standard_True);
80 //! Removes view and clear all maps
81 //! with information about its resources if necessary
82 Standard_EXPORT static void RemoveView (const Handle(V3d_View)& theView,
83 const Standard_Boolean theToRemoveContext = Standard_True);
85 //! Display AIS object in active Viewer and register it in the map of Interactive Objects with specified name.
86 //! @param theName key to be associated to displayed interactive object
87 //! @param theObject object to display
88 //! @param theToUpdate redraw viewer after displaying object
89 //! @param theReplaceIfExists replace the object assigned to specified key
90 //! @return true if new object has been displayed
91 Standard_EXPORT static Standard_Boolean Display (const TCollection_AsciiString& theName,
92 const Handle(AIS_InteractiveObject)& theObject,
93 const Standard_Boolean theToUpdate = Standard_True,
94 const Standard_Boolean theReplaceIfExists = Standard_True);
96 //! waits until a shape of type <aType> is picked in the AIS Viewer and returns it.
97 //! if <aType> == TopAbs_Shape, any shape can be picked...
98 //! MaxPick is the Max number before exiting, if no pick is successful
99 Standard_EXPORT static TopoDS_Shape PickShape (const TopAbs_ShapeEnum aType,
100 const Standard_Integer MaxPick = 5);
102 //! wait until the array is filled with picked shapes.
103 //! returns True if the array is filled.
104 //! exit if number of unsuccessful picks = <MaxPick>
105 Standard_EXPORT static Standard_Boolean PickShapes (const TopAbs_ShapeEnum aType,
106 Handle(TopTools_HArray1OfShape)& thepicked,
107 const Standard_Integer MaxPick = 5);
109 Standard_EXPORT static void Commands (Draw_Interpretor& theCommands);
111 Standard_EXPORT static void ViewerCommands (Draw_Interpretor& theCommands);
113 Standard_EXPORT static void RelationCommands (Draw_Interpretor& theCommands);
115 Standard_EXPORT static void ObjectCommands (Draw_Interpretor& theCommands);
117 Standard_EXPORT static void FilletCommands (Draw_Interpretor& theCommands);
119 Standard_EXPORT static void OpenGlCommands (Draw_Interpretor& theCommands);
121 Standard_EXPORT static void GetMousePosition (Standard_Integer& xpix, Standard_Integer& ypix);
123 Standard_EXPORT static Handle(V3d_Viewer) GetViewerFromContext();
125 Standard_EXPORT static Handle(V3d_Viewer) GetCollectorFromContext();
127 Standard_EXPORT static const Handle(AIS_InteractiveContext)& GetAISContext();
129 Standard_EXPORT static void SetAISContext (const Handle(AIS_InteractiveContext)& aContext);
131 Standard_EXPORT static const Handle(V3d_View)& CurrentView();
133 Standard_EXPORT static void CurrentView (const Handle(V3d_View)& aViou);
135 Standard_EXPORT static void Clear();
137 //! puts theMgr as current eventmanager (the move,select,...will be applied to theMgr)
138 Standard_EXPORT static void SetEventManager (const Handle(ViewerTest_EventManager)& theMgr);
140 //! removes the last EventManager from the list.
141 Standard_EXPORT static void UnsetEventManager();
143 //! clear the list of EventManagers and
144 //! sets the default EventManager as current
145 Standard_EXPORT static void ResetEventManager();
147 Standard_EXPORT static Handle(ViewerTest_EventManager) CurrentEventManager();
149 Standard_EXPORT static void RemoveSelected();
151 //! redraws all defined views.
152 Standard_EXPORT static void RedrawAllViews();
154 //! Splits "parameter=value" string into separate
155 //! parameter and value strings.
156 //! @return TRUE if the string matches pattern "<string>=<empty or string>"
157 Standard_EXPORT static Standard_Boolean SplitParameter (const TCollection_AsciiString& theString,
158 TCollection_AsciiString& theName,
159 TCollection_AsciiString& theValue);
161 //! Returns list of selected shapes.
162 Standard_EXPORT static void GetSelectedShapes (TopTools_ListOfShape& theShapes);
164 //! Parses line type argument.
165 //! Handles either enumeration (integer) value or string constant.
166 Standard_EXPORT static Standard_Boolean ParseLineType (Standard_CString theArg,
167 Aspect_TypeOfLine& theType,
168 uint16_t& thePattern);
170 //! Parses line type argument.
171 //! Handles either enumeration (integer) value or string constant.
172 static Standard_Boolean ParseLineType (Standard_CString theArg,
173 Aspect_TypeOfLine& theType)
175 uint16_t aPattern = 0xFFFF;
176 return ParseLineType (theArg, theType, aPattern);
179 //! Parses marker type argument.
180 //! Handles either enumeration (integer) value or string constant.
181 Standard_EXPORT static Standard_Boolean ParseMarkerType (Standard_CString theArg,
182 Aspect_TypeOfMarker& theType,
183 Handle(Image_PixMap)& theImage);
185 //! Parses shading model argument.
186 //! Handles either enumeration (integer) value or string constant.
187 Standard_EXPORT static Standard_Boolean ParseShadingModel (Standard_CString theArg,
188 Graphic3d_TypeOfShadingModel& theModel);
190 //! Parses ZLayer name.
191 //! @param theArg [in] layer name or enumeration alias
192 //! @param theLayer [out] layer index
193 //! @return TRUE if layer has been identified, note that Graphic3d_ZLayerId_UNKNOWN is also valid value
194 static Standard_Boolean ParseZLayerName (Standard_CString theArg,
195 Graphic3d_ZLayerId& theLayer)
197 return parseZLayer (theArg, false, theLayer);
200 //! Parses ZLayer name.
201 //! @param theArg [in] layer name, enumeration alias or index (of existing Layer)
202 //! @param theLayer [out] layer index
203 //! @return TRUE if layer has been identified, note that Graphic3d_ZLayerId_UNKNOWN is also valid value
204 static Standard_Boolean ParseZLayer (Standard_CString theArg,
205 Graphic3d_ZLayerId& theLayer)
207 return parseZLayer (theArg, true, theLayer);
210 public: //! @name deprecated methods
212 //! Parses RGB(A) color argument(s) specified within theArgVec[0], theArgVec[1], theArgVec[2] and theArgVec[3].
213 Standard_DEPRECATED("Method has been moved to Draw::ParseColor()")
214 Standard_EXPORT static Standard_Integer ParseColor (const Standard_Integer theArgNb,
215 const char* const* const theArgVec,
216 Quantity_ColorRGBA& theColor);
218 //! Parses RGB color argument(s).
219 //! Returns number of handled arguments (1 or 3) or 0 on syntax error.
220 Standard_DEPRECATED("Method has been moved to Draw::ParseColor()")
221 Standard_EXPORT static Standard_Integer ParseColor (const Standard_Integer theArgNb,
222 const char* const* const theArgVec,
223 Quantity_Color& theColor);
225 //! Parses boolean argument.
226 //! Handles either flag specified by 0|1 or on|off.
227 Standard_DEPRECATED("Method has been moved to Draw::ParseOnOff()")
228 Standard_EXPORT static Standard_Boolean ParseOnOff (Standard_CString theArg,
229 Standard_Boolean& theIsOn);
231 Standard_DEPRECATED("Method has been moved to Quantity_Color::ColorFromName()")
232 Standard_EXPORT static Quantity_NameOfColor GetColorFromName (const Standard_CString name);
236 //! Parses ZLayer name.
237 //! @param theArg [in] layer name, enumeration alias or index (of existing Layer)
238 //! @param theToAllowInteger [in] when TRUE, the argument will be checked for existing layer index
239 //! @param theLayer [out] layer index
240 //! @return TRUE if layer has been identified, note that Graphic3d_ZLayerId_UNKNOWN is also valid value
241 Standard_EXPORT static Standard_Boolean parseZLayer (Standard_CString theArg,
242 Standard_Boolean theToAllowInteger,
243 Graphic3d_ZLayerId& theLayer);
245 //! Returns a window class that implements standard behavior of
246 //! all windows of the ViewerTest. This includes usual Open CASCADE
247 //! view conventions for mouse buttons (e.g. Ctrl+MB1 for zoom,
248 //! Ctrl+MB2 for pan, etc) and keyboard shortcuts.
249 //! This method is relevant for MS Windows only and respectively
250 //! returns WNT_WClass handle.
251 static const Handle(WNT_WClass)& WClass();
254 #endif // _ViewerTest_HeaderFile