Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:31

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