Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/opencascade/ViewerTest.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (c) 1997-1999 Matra Datavision
0002 // Copyright (c) 1999-2015 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef _ViewerTest_HeaderFile
0016 #define _ViewerTest_HeaderFile
0017 
0018 #include <Aspect_TypeOfLine.hxx>
0019 #include <Aspect_TypeOfMarker.hxx>
0020 #include <Aspect_TypeOfTriedronPosition.hxx>
0021 #include <Draw_Interpretor.hxx>
0022 #include <Graphic3d_TypeOfShadingModel.hxx>
0023 #include <NCollection_Vec2.hxx>
0024 #include <Standard_TypeDef.hxx>
0025 #include <Graphic3d_ZLayerId.hxx>
0026 #include <Standard_Transient.hxx>
0027 #include <NCollection_Array1.hxx>
0028 #include <NCollection_HArray1.hxx>
0029 #include <TopoDS_Shape.hxx>
0030 #include <NCollection_List.hxx>
0031 #include <Quantity_ColorRGBA.hxx>
0032 
0033 class AIS_InteractiveContext;
0034 class AIS_InteractiveObject;
0035 class Image_PixMap;
0036 class V3d_View;
0037 class V3d_Viewer;
0038 class ViewerTest_EventManager;
0039 class TopoDS_Shape;
0040 class WNT_WClass;
0041 
0042 //! Parameters for creating new view.
0043 struct ViewerTest_VinitParams
0044 {
0045   TCollection_AsciiString       ViewName;
0046   TCollection_AsciiString       DisplayName;
0047   occ::handle<V3d_View>         ViewToClone;
0048   occ::handle<V3d_View>         ParentView;
0049   NCollection_Vec2<double>      Offset;
0050   NCollection_Vec2<double>      Size;
0051   Aspect_TypeOfTriedronPosition Corner;
0052   NCollection_Vec2<int>         SubviewMargins;
0053   bool                          IsVirtual;
0054   bool                          IsComposer;
0055 
0056   ViewerTest_VinitParams()
0057       : Corner(Aspect_TOTP_LEFT_UPPER),
0058         IsVirtual(false),
0059         IsComposer(false)
0060   {
0061   }
0062 };
0063 
0064 class ViewerTest
0065 {
0066 public:
0067   DEFINE_STANDARD_ALLOC
0068 
0069   //! Loads all Draw commands of V2d & V3d. Used for plugin.
0070   Standard_EXPORT static void Factory(Draw_Interpretor& theDI);
0071 
0072   //! Creates view with default or custom name and adds this name in map to manage multiple views.
0073   //! Implemented in ViewerTest_ViewerCommands.cxx.
0074   Standard_EXPORT static TCollection_AsciiString ViewerInit(
0075     const ViewerTest_VinitParams& theParams);
0076 
0077   //! Creates view.
0078   static TCollection_AsciiString ViewerInit(const TCollection_AsciiString& theViewName = "")
0079   {
0080     ViewerTest_VinitParams aParams;
0081     aParams.ViewName = theViewName;
0082     return ViewerInit(aParams);
0083   }
0084 
0085   //! Creates view.
0086   static TCollection_AsciiString ViewerInit(
0087     const int                      thePxLeft,
0088     const int                      thePxTop,
0089     const int                      thePxWidth,
0090     const int                      thePxHeight,
0091     const TCollection_AsciiString& theViewName,
0092     const TCollection_AsciiString& theDisplayName = "",
0093     const occ::handle<V3d_View>&   theViewToClone = occ::handle<V3d_View>(),
0094     const bool                     theIsVirtual   = false)
0095   {
0096     ViewerTest_VinitParams aParams;
0097     aParams.Offset.SetValues((float)thePxLeft, (float)thePxTop);
0098     aParams.Size.SetValues((float)thePxWidth, (float)thePxHeight);
0099     aParams.ViewName    = theViewName;
0100     aParams.DisplayName = theDisplayName;
0101     aParams.ViewToClone = theViewToClone;
0102     aParams.IsVirtual   = theIsVirtual;
0103     return ViewerInit(aParams);
0104   }
0105 
0106   Standard_EXPORT static void RemoveViewName(const TCollection_AsciiString& theName);
0107 
0108   Standard_EXPORT static void InitViewName(const TCollection_AsciiString& theName,
0109                                            const occ::handle<V3d_View>&   theView);
0110 
0111   Standard_EXPORT static TCollection_AsciiString GetCurrentViewName();
0112 
0113   //! Make the view active
0114   Standard_EXPORT static void ActivateView(const occ::handle<V3d_View>& theView, bool theToUpdate);
0115 
0116   //! Removes view and clear all maps
0117   //! with information about its resources if necessary
0118   Standard_EXPORT static void RemoveView(const TCollection_AsciiString& theViewName,
0119                                          const bool                     theToRemoveContext = true);
0120 
0121   //! Removes view and clear all maps
0122   //! with information about its resources if necessary
0123   Standard_EXPORT static void RemoveView(const occ::handle<V3d_View>& theView,
0124                                          const bool                   theToRemoveContext = true);
0125 
0126   //! Display AIS object in active Viewer and register it in the map of Interactive Objects with
0127   //! specified name.
0128   //! @param theName            key to be associated to displayed interactive object
0129   //! @param theObject          object to display
0130   //! @param theToUpdate        redraw viewer after displaying object
0131   //! @param theReplaceIfExists replace the object assigned to specified key
0132   //! @return true if new object has been displayed
0133   Standard_EXPORT static bool Display(const TCollection_AsciiString&            theName,
0134                                       const occ::handle<AIS_InteractiveObject>& theObject,
0135                                       const bool                                theToUpdate = true,
0136                                       const bool theReplaceIfExists                         = true);
0137 
0138   //! waits until a shape of type <aType> is picked in the AIS Viewer and returns it.
0139   //! if <aType> == TopAbs_Shape, any shape can be picked...
0140   //! MaxPick is the Max number before exiting, if no pick is successful
0141   Standard_EXPORT static TopoDS_Shape PickShape(const TopAbs_ShapeEnum aType,
0142                                                 const int              MaxPick = 5);
0143 
0144   //! wait until the array is filled with picked shapes.
0145   //! returns True if the array is filled.
0146   //! exit if number of unsuccessful picks = <MaxPick>
0147   Standard_EXPORT static bool PickShapes(const TopAbs_ShapeEnum                          aType,
0148                                          occ::handle<NCollection_HArray1<TopoDS_Shape>>& thepicked,
0149                                          const int MaxPick = 5);
0150 
0151   Standard_EXPORT static void Commands(Draw_Interpretor& theCommands);
0152 
0153   Standard_EXPORT static void ViewerCommands(Draw_Interpretor& theCommands);
0154 
0155   Standard_EXPORT static void RelationCommands(Draw_Interpretor& theCommands);
0156 
0157   Standard_EXPORT static void ObjectCommands(Draw_Interpretor& theCommands);
0158 
0159   Standard_EXPORT static void FilletCommands(Draw_Interpretor& theCommands);
0160 
0161   Standard_EXPORT static void OpenGlCommands(Draw_Interpretor& theCommands);
0162 
0163   Standard_EXPORT static void GetMousePosition(int& xpix, int& ypix);
0164 
0165   Standard_EXPORT static occ::handle<V3d_Viewer> GetViewerFromContext();
0166 
0167   Standard_EXPORT static occ::handle<V3d_Viewer> GetCollectorFromContext();
0168 
0169   Standard_EXPORT static const occ::handle<AIS_InteractiveContext>& GetAISContext();
0170 
0171   Standard_EXPORT static void SetAISContext(const occ::handle<AIS_InteractiveContext>& aContext);
0172 
0173   Standard_EXPORT static const occ::handle<V3d_View>& CurrentView();
0174 
0175   Standard_EXPORT static void CurrentView(const occ::handle<V3d_View>& aViou);
0176 
0177   Standard_EXPORT static void Clear();
0178 
0179   //! puts theMgr as current eventmanager (the move,select,...will be applied to theMgr)
0180   Standard_EXPORT static void SetEventManager(const occ::handle<ViewerTest_EventManager>& theMgr);
0181 
0182   //! removes the last EventManager from the list.
0183   Standard_EXPORT static void UnsetEventManager();
0184 
0185   //! clear the list of EventManagers and
0186   //! sets the default EventManager as current
0187   Standard_EXPORT static void ResetEventManager();
0188 
0189   Standard_EXPORT static occ::handle<ViewerTest_EventManager> CurrentEventManager();
0190 
0191   Standard_EXPORT static void RemoveSelected();
0192 
0193   //! redraws all defined views.
0194   Standard_EXPORT static void RedrawAllViews();
0195 
0196   //! Splits "parameter=value" string into separate
0197   //! parameter and value strings.
0198   //! @return TRUE if the string matches pattern "<string>=<empty or string>"
0199   Standard_EXPORT static bool SplitParameter(const TCollection_AsciiString& theString,
0200                                              TCollection_AsciiString&       theName,
0201                                              TCollection_AsciiString&       theValue);
0202 
0203   //! Returns list of selected shapes.
0204   Standard_EXPORT static void GetSelectedShapes(NCollection_List<TopoDS_Shape>& theShapes);
0205 
0206   //! Parses line type argument.
0207   //! Handles either enumeration (integer) value or string constant.
0208   Standard_EXPORT static bool ParseLineType(const char*        theArg,
0209                                             Aspect_TypeOfLine& theType,
0210                                             uint16_t&          thePattern);
0211 
0212   //! Parses line type argument.
0213   //! Handles either enumeration (integer) value or string constant.
0214   static bool ParseLineType(const char* theArg, Aspect_TypeOfLine& theType)
0215   {
0216     uint16_t aPattern = 0xFFFF;
0217     return ParseLineType(theArg, theType, aPattern);
0218   }
0219 
0220   //! Parses marker type argument.
0221   //! Handles either enumeration (integer) value or string constant.
0222   Standard_EXPORT static bool ParseMarkerType(const char*                theArg,
0223                                               Aspect_TypeOfMarker&       theType,
0224                                               occ::handle<Image_PixMap>& theImage);
0225 
0226   //! Parses shading model argument.
0227   //! Handles either enumeration (integer) value or string constant.
0228   Standard_EXPORT static bool ParseShadingModel(const char*                   theArg,
0229                                                 Graphic3d_TypeOfShadingModel& theModel);
0230 
0231   //! Parses ZLayer name.
0232   //! @param[in] theArg  layer name or enumeration alias
0233   //! @param[out] theLayer  layer index
0234   //! @return TRUE if layer has been identified, note that Graphic3d_ZLayerId_UNKNOWN is also valid
0235   //! value
0236   static bool ParseZLayerName(const char* theArg, Graphic3d_ZLayerId& theLayer)
0237   {
0238     return parseZLayer(theArg, false, theLayer);
0239   }
0240 
0241   //! Parses ZLayer name.
0242   //! @param[in] theArg  layer name, enumeration alias or index (of existing Layer)
0243   //! @param[out] theLayer  layer index
0244   //! @return TRUE if layer has been identified, note that Graphic3d_ZLayerId_UNKNOWN is also valid
0245   //! value
0246   static bool ParseZLayer(const char* theArg, Graphic3d_ZLayerId& theLayer)
0247   {
0248     return parseZLayer(theArg, true, theLayer);
0249   }
0250 
0251   //! Auxiliary method to parse transformation persistence flags
0252   Standard_EXPORT static bool ParseCorner(const char*                    theArg,
0253                                           Aspect_TypeOfTriedronPosition& theCorner);
0254 
0255 public: //! @name deprecated methods
0256   //! Parses RGB(A) color argument(s) specified within theArgVec[0], theArgVec[1], theArgVec[2] and
0257   //! theArgVec[3].
0258   Standard_DEPRECATED("Method has been moved to Draw::ParseColor()")
0259   Standard_EXPORT static int ParseColor(const int                theArgNb,
0260                                         const char* const* const theArgVec,
0261                                         Quantity_ColorRGBA&      theColor);
0262 
0263   //! Parses RGB color argument(s).
0264   //! Returns number of handled arguments (1 or 3) or 0 on syntax error.
0265   Standard_DEPRECATED("Method has been moved to Draw::ParseColor()")
0266   Standard_EXPORT static int ParseColor(const int                theArgNb,
0267                                         const char* const* const theArgVec,
0268                                         Quantity_Color&          theColor);
0269 
0270   //! Parses boolean argument.
0271   //! Handles either flag specified by 0|1 or on|off.
0272   Standard_DEPRECATED("Method has been moved to Draw::ParseOnOff()")
0273   Standard_EXPORT static bool ParseOnOff(const char* theArg, bool& theIsOn);
0274 
0275   Standard_DEPRECATED("Method has been moved to Quantity_Color::ColorFromName()")
0276   Standard_EXPORT static Quantity_NameOfColor GetColorFromName(const char* const name);
0277 
0278 private:
0279   //! Parses ZLayer name.
0280   //! @param[in] theArg  layer name, enumeration alias or index (of existing Layer)
0281   //! @param[in] theToAllowInteger  when TRUE, the argument will be checked for existing layer index
0282   //! @param[out] theLayer  layer index
0283   //! @return TRUE if layer has been identified, note that Graphic3d_ZLayerId_UNKNOWN is also valid
0284   //! value
0285   Standard_EXPORT static bool parseZLayer(const char*         theArg,
0286                                           bool                theToAllowInteger,
0287                                           Graphic3d_ZLayerId& theLayer);
0288 
0289   //! Returns a window class that implements standard behavior of
0290   //! all windows of the ViewerTest. This includes usual Open CASCADE
0291   //! view conventions for mouse buttons (e.g. Ctrl+MB1 for zoom,
0292   //! Ctrl+MB2 for pan, etc) and keyboard shortcuts.
0293   //! This method is relevant for MS Windows only and respectively
0294   //! returns WNT_WClass handle.
0295   static const occ::handle<WNT_WClass>& WClass();
0296 };
0297 
0298 #endif // _ViewerTest_HeaderFile