0032154: Tests - include vglinfo into Tests Summary
[occt.git] / src / ViewerTest / ViewerTest.hxx
1 // Copyright (c) 1997-1999 Matra Datavision
2 // Copyright (c) 1999-2015 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef _ViewerTest_HeaderFile
16 #define _ViewerTest_HeaderFile
17
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>
29
30 class AIS_InteractiveContext;
31 class AIS_InteractiveObject;
32 class Image_PixMap;
33 class V3d_View;
34 class V3d_Viewer;
35 class ViewerTest_EventManager;
36 class TopoDS_Shape;
37 class WNT_WClass;
38
39 class ViewerTest
40 {
41 public:
42
43   DEFINE_STANDARD_ALLOC
44
45   //! Loads all Draw commands of  V2d & V3d. Used for plugin.
46   Standard_EXPORT static void Factory (Draw_Interpretor& theDI);
47
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);
67
68   Standard_EXPORT static void RemoveViewName (const TCollection_AsciiString& theName);
69
70   Standard_EXPORT static void InitViewName (const TCollection_AsciiString& theName,
71                                             const Handle(V3d_View)&        theView);
72
73   Standard_EXPORT static TCollection_AsciiString GetCurrentViewName();
74
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);
79
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);
84
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);
95
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);
101
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);
108
109   Standard_EXPORT static void Commands (Draw_Interpretor& theCommands);
110
111   Standard_EXPORT static void ViewerCommands (Draw_Interpretor& theCommands);
112
113   Standard_EXPORT static void MyCommands (Draw_Interpretor& theCommands);
114
115   Standard_EXPORT static void RelationCommands (Draw_Interpretor& theCommands);
116
117   Standard_EXPORT static void ObjectCommands (Draw_Interpretor& theCommands);
118
119   Standard_EXPORT static void FilletCommands (Draw_Interpretor& theCommands);
120
121   Standard_EXPORT static void OpenGlCommands (Draw_Interpretor& theCommands);
122
123   Standard_EXPORT static void GetMousePosition (Standard_Integer& xpix, Standard_Integer& ypix);
124
125   Standard_EXPORT static Handle(V3d_Viewer) GetViewerFromContext();
126
127   Standard_EXPORT static Handle(V3d_Viewer) GetCollectorFromContext();
128
129   Standard_EXPORT static const Handle(AIS_InteractiveContext)& GetAISContext();
130
131   Standard_EXPORT static void SetAISContext (const Handle(AIS_InteractiveContext)& aContext);
132
133   Standard_EXPORT static const Handle(V3d_View)& CurrentView();
134
135   Standard_EXPORT static void CurrentView (const Handle(V3d_View)& aViou);
136
137   Standard_EXPORT static void Clear();
138
139   //! puts theMgr as current eventmanager (the move,select,...will be applied to theMgr)
140   Standard_EXPORT static void SetEventManager (const Handle(ViewerTest_EventManager)& theMgr);
141
142   //! removes the last EventManager from the list.
143   Standard_EXPORT static void UnsetEventManager();
144
145   //! clear the list of EventManagers and
146   //! sets the default EventManager as current
147   Standard_EXPORT static void ResetEventManager();
148
149   Standard_EXPORT static Handle(ViewerTest_EventManager) CurrentEventManager();
150
151   Standard_EXPORT static void RemoveSelected();
152
153   //! redraws all defined views.
154   Standard_EXPORT static void RedrawAllViews();
155
156   //! Splits "parameter=value" string into separate
157   //! parameter and value strings.
158   //! @return TRUE if the string matches pattern "<string>=<empty or string>"
159   Standard_EXPORT static Standard_Boolean SplitParameter (const TCollection_AsciiString& theString,
160                                                           TCollection_AsciiString&       theName,
161                                                           TCollection_AsciiString&       theValue);
162
163   //! Returns list of selected shapes.
164   Standard_EXPORT static void GetSelectedShapes (TopTools_ListOfShape& theShapes);
165
166   //! Parses line type argument.
167   //! Handles either enumeration (integer) value or string constant.
168   Standard_EXPORT static Standard_Boolean ParseLineType (Standard_CString theArg,
169                                                          Aspect_TypeOfLine& theType,
170                                                          uint16_t& thePattern);
171
172   //! Parses line type argument.
173   //! Handles either enumeration (integer) value or string constant.
174   static Standard_Boolean ParseLineType (Standard_CString theArg,
175                                          Aspect_TypeOfLine& theType)
176   {
177     uint16_t aPattern = 0xFFFF;
178     return ParseLineType (theArg, theType, aPattern);
179   }
180
181   //! Parses marker type argument.
182   //! Handles either enumeration (integer) value or string constant.
183   Standard_EXPORT static Standard_Boolean ParseMarkerType (Standard_CString theArg,
184                                                            Aspect_TypeOfMarker& theType,
185                                                            Handle(Image_PixMap)& theImage);
186
187   //! Parses shading model argument.
188   //! Handles either enumeration (integer) value or string constant.
189   Standard_EXPORT static Standard_Boolean ParseShadingModel (Standard_CString              theArg,
190                                                              Graphic3d_TypeOfShadingModel& theModel);
191
192   //! Parses ZLayer name.
193   //! @param theArg [in] layer name or enumeration alias
194   //! @param theLayer [out] layer index
195   //! @return TRUE if layer has been identified, note that Graphic3d_ZLayerId_UNKNOWN is also valid value
196   static Standard_Boolean ParseZLayerName (Standard_CString theArg,
197                                            Graphic3d_ZLayerId& theLayer)
198   {
199     return parseZLayer (theArg, false, theLayer);
200   }
201
202   //! Parses ZLayer name.
203   //! @param theArg [in] layer name, enumeration alias or index (of existing Layer)
204   //! @param theLayer [out] layer index
205   //! @return TRUE if layer has been identified, note that Graphic3d_ZLayerId_UNKNOWN is also valid value
206   static Standard_Boolean ParseZLayer (Standard_CString theArg,
207                                        Graphic3d_ZLayerId& theLayer)
208   {
209     return parseZLayer (theArg, true, theLayer);
210   }
211
212 public: //! @name deprecated methods
213
214   //! Parses RGB(A) color argument(s) specified within theArgVec[0], theArgVec[1], theArgVec[2] and theArgVec[3].
215   Standard_DEPRECATED("Method has been moved to Draw::ParseColor()")
216   Standard_EXPORT static Standard_Integer ParseColor (const Standard_Integer   theArgNb,
217                                                       const char* const* const theArgVec,
218                                                       Quantity_ColorRGBA&      theColor);
219
220   //! Parses RGB color argument(s).
221   //! Returns number of handled arguments (1 or 3) or 0 on syntax error.
222   Standard_DEPRECATED("Method has been moved to Draw::ParseColor()")
223   Standard_EXPORT static Standard_Integer ParseColor (const Standard_Integer   theArgNb,
224                                                       const char* const* const theArgVec,
225                                                       Quantity_Color&          theColor);
226
227   //! Parses boolean argument.
228   //! Handles either flag specified by 0|1 or on|off.
229   Standard_DEPRECATED("Method has been moved to Draw::ParseOnOff()")
230   Standard_EXPORT static Standard_Boolean ParseOnOff (Standard_CString  theArg,
231                                                       Standard_Boolean& theIsOn);
232
233   Standard_DEPRECATED("Method has been moved to Quantity_Color::ColorFromName()")
234   Standard_EXPORT static Quantity_NameOfColor GetColorFromName (const Standard_CString name);
235
236 private:
237
238   //! Parses ZLayer name.
239   //! @param theArg [in] layer name, enumeration alias or index (of existing Layer)
240   //! @param theToAllowInteger [in] when TRUE, the argument will be checked for existing layer index
241   //! @param theLayer [out] layer index
242   //! @return TRUE if layer has been identified, note that Graphic3d_ZLayerId_UNKNOWN is also valid value
243   Standard_EXPORT static Standard_Boolean parseZLayer (Standard_CString theArg,
244                                                        Standard_Boolean theToAllowInteger,
245                                                        Graphic3d_ZLayerId& theLayer);
246
247   //! Returns a window class that implements standard behavior of
248   //! all windows of the ViewerTest. This includes usual Open CASCADE
249   //! view conventions for mouse buttons (e.g. Ctrl+MB1 for zoom,
250   //! Ctrl+MB2 for pan, etc) and keyboard shortcuts.
251   //! This method is relevant for MS Windows only and respectively
252   //! returns WNT_WClass handle.
253   static const Handle(WNT_WClass)& WClass();
254 };
255
256 #endif // _ViewerTest_HeaderFile