| 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 <Standard_Integer.hxx> |
| 24 | #include <Standard_CString.hxx> |
| 25 | #include <Standard_DefineAlloc.hxx> |
| 26 | #include <Standard_Macro.hxx> |
| 27 | #include <TCollection_AsciiString.hxx> |
| 28 | #include <TColStd_HArray1OfTransient.hxx> |
| 29 | #include <TopTools_ListOfShape.hxx> |
| 30 | #include <TopTools_HArray1OfShape.hxx> |
| 31 | #include <Quantity_ColorRGBA.hxx> |
| 32 | |
| 33 | class AIS_InteractiveContext; |
| 34 | class AIS_InteractiveObject; |
| 35 | class Image_PixMap; |
| 36 | class V3d_View; |
| 37 | class V3d_Viewer; |
| 38 | class ViewerTest_EventManager; |
| 39 | class TopoDS_Shape; |
| 40 | |
| 41 | class ViewerTest |
| 42 | { |
| 43 | public: |
| 44 | |
| 45 | DEFINE_STANDARD_ALLOC |
| 46 | |
| 47 | //! Loads all Draw commands of V2d & V3d. Used for plugin. |
| 48 | Standard_EXPORT static void Factory (Draw_Interpretor& theDI); |
| 49 | |
| 50 | //! Creates view with default or custom name |
| 51 | //! and adds this name in map to manage multiple views. |
| 52 | //! Implemented in ViewerTest_ViewerCommands.cxx. |
| 53 | //! @param thePxLeft left position of newly created window |
| 54 | //! @param thePxTop top position of newly created window |
| 55 | //! @param thePxWidth width of newly created window |
| 56 | //! @param thePxHeight height of newly created window |
| 57 | //! @param theViewName name of newly created View |
| 58 | //! @oaram theDisplayName display name |
| 59 | //! @param theViewToClone when specified, the new View will copy properties of existing one |
| 60 | Standard_EXPORT static TCollection_AsciiString ViewerInit (const Standard_Integer thePxLeft = 0, |
| 61 | const Standard_Integer thePxTop = 0, |
| 62 | const Standard_Integer thePxWidth = 0, |
| 63 | const Standard_Integer thePxHeight = 0, |
| 64 | const TCollection_AsciiString& theViewName = "", |
| 65 | const TCollection_AsciiString& theDisplayName = "", |
| 66 | const Handle(V3d_View)& theViewToClone = Handle(V3d_View)()); |
| 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 | Standard_EXPORT static Quantity_NameOfColor GetColorFromName (const Standard_CString name); |
| 154 | |
| 155 | //! Parses RGB(A) color argument(s) specified within theArgVec[0], theArgVec[1], theArgVec[2] and theArgVec[3]. |
| 156 | //! Handles either color specified by name (single argument) |
| 157 | //! or by RGB(A) components (3-4 arguments) in range 0..1. |
| 158 | //! The result is stored in theColor on success. |
| 159 | //! Returns number of handled arguments (1, 3 or 4) or 0 on syntax error. |
| 160 | static Standard_Integer ParseColor (Standard_Integer theArgNb, |
| 161 | const char** theArgVec, |
| 162 | Quantity_ColorRGBA& theColor) |
| 163 | { |
| 164 | return parseColor (theArgNb, theArgVec, theColor, true); |
| 165 | } |
| 166 | |
| 167 | //! Parses RGB color argument(s). |
| 168 | //! Returns number of handled arguments (1 or 3) or 0 on syntax error. |
| 169 | static Standard_Integer ParseColor (Standard_Integer theArgNb, |
| 170 | const char** theArgVec, |
| 171 | Quantity_Color& theColor) |
| 172 | { |
| 173 | Quantity_ColorRGBA anRgba; |
| 174 | Standard_Integer aNbParsed = parseColor (theArgNb, theArgVec, anRgba, false); |
| 175 | if (aNbParsed != 0) |
| 176 | { |
| 177 | theColor = anRgba.GetRGB(); |
| 178 | } |
| 179 | return aNbParsed; |
| 180 | } |
| 181 | |
| 182 | //! redraws all defined views. |
| 183 | Standard_EXPORT static void RedrawAllViews(); |
| 184 | |
| 185 | //! Splits "parameter=value" string into separate |
| 186 | //! parameter and value strings. |
| 187 | //! @return TRUE if the string matches pattern "<string>=<empty or string>" |
| 188 | Standard_EXPORT static Standard_Boolean SplitParameter (const TCollection_AsciiString& theString, |
| 189 | TCollection_AsciiString& theName, |
| 190 | TCollection_AsciiString& theValue); |
| 191 | |
| 192 | //! Parses boolean argument. |
| 193 | //! Handles either flag specified by 0|1 or on|off. |
| 194 | Standard_EXPORT static Standard_Boolean ParseOnOff (Standard_CString theArg, |
| 195 | Standard_Boolean& theIsOn); |
| 196 | |
| 197 | //! Returns list of selected shapes. |
| 198 | Standard_EXPORT static void GetSelectedShapes (TopTools_ListOfShape& theShapes); |
| 199 | |
| 200 | //! Parses line type argument. |
| 201 | //! Handles either enumeration (integer) value or string constant. |
| 202 | Standard_EXPORT static Standard_Boolean ParseLineType (Standard_CString theArg, |
| 203 | Aspect_TypeOfLine& theType); |
| 204 | |
| 205 | //! Parses marker type argument. |
| 206 | //! Handles either enumeration (integer) value or string constant. |
| 207 | Standard_EXPORT static Standard_Boolean ParseMarkerType (Standard_CString theArg, |
| 208 | Aspect_TypeOfMarker& theType, |
| 209 | Handle(Image_PixMap)& theImage); |
| 210 | |
| 211 | //! Parses shading model argument. |
| 212 | //! Handles either enumeration (integer) value or string constant. |
| 213 | Standard_EXPORT static Standard_Boolean ParseShadingModel (Standard_CString theArg, |
| 214 | Graphic3d_TypeOfShadingModel& theModel); |
| 215 | |
| 216 | private: |
| 217 | |
| 218 | //! Parses RGB(A) color argument(s) specified within theArgVec[0], theArgVec[1], theArgVec[2] and theArgVec[3]. |
| 219 | //! Handles either color specified by name (single argument) |
| 220 | //! or by RGB(A) components (3-4 arguments) in range 0..1. |
| 221 | //! The result is stored in theColor on success. |
| 222 | //! Returns number of handled arguments (1, 3 or 4) or 0 on syntax error. |
| 223 | Standard_EXPORT static Standard_Integer parseColor (Standard_Integer theArgNb, |
| 224 | const char** theArgVec, |
| 225 | Quantity_ColorRGBA& theColor, |
| 226 | bool theToParseAlpha); |
| 227 | |
| 228 | //! Returns a window class that implements standard behavior of |
| 229 | //! all windows of the ViewerTest. This includes usual Open CASCADE |
| 230 | //! view conventions for mouse buttons (e.g. Ctrl+MB1 for zoom, |
| 231 | //! Ctrl+MB2 for pan, etc) and keyboard shortcuts. |
| 232 | //! This method is relevant for MS Windows only and respectively |
| 233 | //! returns WNT_WClass handle. |
| 234 | static const Handle(Standard_Transient)& WClass(); |
| 235 | }; |
| 236 | |
| 237 | #endif // _ViewerTest_HeaderFile |