Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-27 08:38:53

0001 // Created on: 1996-12-20
0002 // Created by: Robert COUBLANC
0003 // Copyright (c) 1996-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _AIS_Shape_HeaderFile
0018 #define _AIS_Shape_HeaderFile
0019 
0020 #include <AIS_DisplayMode.hxx>
0021 #include <AIS_InteractiveObject.hxx>
0022 #include <Bnd_Box.hxx>
0023 #include <TopoDS_Shape.hxx>
0024 #include <Prs3d_Drawer.hxx>
0025 #include <Prs3d_TypeOfHLR.hxx>
0026 
0027 //! A framework to manage presentation and selection of shapes.
0028 //! AIS_Shape is the interactive object which is used the
0029 //! most by   applications. There are standard functions
0030 //! available which allow you to prepare selection
0031 //! operations on the constituent elements of shapes -
0032 //! vertices, edges, faces etc - in an open local context.
0033 //! The selection modes specific to "Shape" type objects
0034 //! are referred to as Standard Activation Mode. These
0035 //! modes are only taken into account in open local
0036 //! context and only act on Interactive Objects which
0037 //! have redefined the virtual method
0038 //! AcceptShapeDecomposition so that it returns true.
0039 //! Several advanced functions are also available. These
0040 //! include functions to manage deviation angle and
0041 //! deviation coefficient - both HLR and non-HLR - of
0042 //! an inheriting shape class. These services allow you to
0043 //! select one type of shape interactive object for higher
0044 //! precision drawing. When you do this, the
0045 //! Prs3d_Drawer::IsOwn... functions corresponding to the
0046 //! above deviation angle and coefficient functions return
0047 //! true indicating that there is a local setting available
0048 //! for the specific object.
0049 //!
0050 //! This class allows to map textures on shapes using native UV parametric space of underlying
0051 //! surface of each Face (this means that texture will be visually duplicated on all Faces). To
0052 //! generate texture coordinates, appropriate shading attribute should be set before computing
0053 //! presentation in AIS_Shaded display mode:
0054 //! @code
0055 //!   Handle(AIS_Shape) aPrs = new AIS_Shape();
0056 //!   aPrs->Attributes()->SetupOwnShadingAspect();
0057 //!   aPrs->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
0058 //!   aPrs->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (new Graphic3d_Texture2Dmanual
0059 //!   (Graphic3d_NOT_2D_ALUMINUM));
0060 //! @endcode
0061 //! The texture itself is parametrized in (0,1)x(0,1).
0062 class AIS_Shape : public AIS_InteractiveObject
0063 {
0064   DEFINE_STANDARD_RTTIEXT(AIS_Shape, AIS_InteractiveObject)
0065 public:
0066   //! Initializes construction of the shape shap from wires,
0067   //! edges and vertices.
0068   Standard_EXPORT AIS_Shape(const TopoDS_Shape& shap);
0069 
0070   //! Returns index 0. This value refers to SHAPE from TopAbs_ShapeEnum
0071   virtual Standard_Integer Signature() const Standard_OVERRIDE { return 0; }
0072 
0073   //! Returns Object as the type of Interactive Object.
0074   virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE
0075   {
0076     return AIS_KindOfInteractive_Shape;
0077   }
0078 
0079   //! Returns true if the Interactive Object accepts shape decomposition.
0080   virtual Standard_Boolean AcceptShapeDecomposition() const Standard_OVERRIDE
0081   {
0082     return Standard_True;
0083   }
0084 
0085   //! Return true if specified display mode is supported.
0086   virtual Standard_Boolean AcceptDisplayMode(const Standard_Integer theMode) const Standard_OVERRIDE
0087   {
0088     return theMode >= 0 && theMode <= 2;
0089   }
0090 
0091   //! Returns this shape object.
0092   const TopoDS_Shape& Shape() const { return myshape; }
0093 
0094   //! Constructs an instance of the shape object theShape.
0095   void SetShape(const TopoDS_Shape& theShape)
0096   {
0097     myshape  = theShape;
0098     myCompBB = Standard_True;
0099   }
0100 
0101   //! Alias for ::SetShape().
0102   void Set(const TopoDS_Shape& theShape) { SetShape(theShape); }
0103 
0104   //! Sets a local value for deviation coefficient for this specific shape.
0105   Standard_EXPORT Standard_Boolean SetOwnDeviationCoefficient();
0106 
0107   //! Sets a local value for deviation angle for this specific shape.
0108   Standard_EXPORT Standard_Boolean SetOwnDeviationAngle();
0109 
0110   //! Sets a local value for deviation coefficient for this specific shape.
0111   Standard_EXPORT void SetOwnDeviationCoefficient(const Standard_Real aCoefficient);
0112 
0113   //! this compute a new angle and Deviation from the value anAngle
0114   //! and set the values stored in myDrawer with these that become local to the shape
0115   Standard_EXPORT void SetAngleAndDeviation(const Standard_Real anAngle);
0116 
0117   //! gives back the angle initial value put by the User.
0118   Standard_EXPORT Standard_Real UserAngle() const;
0119 
0120   //! sets myOwnDeviationAngle field in Prs3d_Drawer & recomputes presentation
0121   Standard_EXPORT void SetOwnDeviationAngle(const Standard_Real anAngle);
0122 
0123   //! Returns true and the values of the deviation
0124   //! coefficient aCoefficient and the previous deviation
0125   //! coefficient aPreviousCoefficient. If these values are
0126   //! not already set, false is returned.
0127   Standard_EXPORT Standard_Boolean
0128     OwnDeviationCoefficient(Standard_Real& aCoefficient, Standard_Real& aPreviousCoefficient) const;
0129 
0130   //! Returns true and the values of the deviation angle
0131   //! anAngle and the previous deviation angle aPreviousAngle.
0132   //! If these values are not already set, false is returned.
0133   Standard_EXPORT Standard_Boolean OwnDeviationAngle(Standard_Real& anAngle,
0134                                                      Standard_Real& aPreviousAngle) const;
0135 
0136   //! Sets the type of HLR algorithm used by the shape
0137   void SetTypeOfHLR(const Prs3d_TypeOfHLR theTypeOfHLR) { myDrawer->SetTypeOfHLR(theTypeOfHLR); }
0138 
0139   //! Gets the type of HLR algorithm
0140   Prs3d_TypeOfHLR TypeOfHLR() const { return myDrawer->TypeOfHLR(); }
0141 
0142   //! Sets the color aColor in the reconstructed
0143   //! compound shape. Acts via the Drawer methods below on the appearance of:
0144   //! -   free boundaries:
0145   //! Prs3d_Drawer_FreeBoundaryAspect,
0146   //! -   isos: Prs3d_Drawer_UIsoAspect,
0147   //! Prs3dDrawer_VIsoAspect,
0148   //! -   shared boundaries:
0149   //! Prs3d_Drawer_UnFreeBoundaryAspect,
0150   //! -   shading: Prs3d_Drawer_ShadingAspect,
0151   //! -   visible line color in hidden line mode:
0152   //! Prs3d_Drawer_SeenLineAspect
0153   //! -   hidden line color in hidden line mode:
0154   //! Prs3d_Drawer_HiddenLineAspect.
0155   Standard_EXPORT virtual void SetColor(const Quantity_Color& theColor) Standard_OVERRIDE;
0156 
0157   //! Removes settings for color in the reconstructed compound shape.
0158   Standard_EXPORT virtual void UnsetColor() Standard_OVERRIDE;
0159 
0160   //! Sets the value aValue for line width in the reconstructed compound shape.
0161   //! Changes line aspects for lines presentation.
0162   Standard_EXPORT virtual void SetWidth(const Standard_Real aValue) Standard_OVERRIDE;
0163 
0164   //! Removes the setting for line width in the reconstructed compound shape.
0165   Standard_EXPORT virtual void UnsetWidth() Standard_OVERRIDE;
0166 
0167   //! Allows you to provide settings for the material aName
0168   //! in the reconstructed compound shape.
0169   Standard_EXPORT virtual void SetMaterial(const Graphic3d_MaterialAspect& aName) Standard_OVERRIDE;
0170 
0171   //! Removes settings for material in the reconstructed compound shape.
0172   Standard_EXPORT virtual void UnsetMaterial() Standard_OVERRIDE;
0173 
0174   //! Sets the value aValue for transparency in the reconstructed compound shape.
0175   Standard_EXPORT virtual void SetTransparency(const Standard_Real aValue = 0.6) Standard_OVERRIDE;
0176 
0177   //! Removes the setting for transparency in the reconstructed compound shape.
0178   Standard_EXPORT virtual void UnsetTransparency() Standard_OVERRIDE;
0179 
0180   //! Constructs a bounding box with which to reconstruct
0181   //! compound topological shapes for presentation.
0182   Standard_EXPORT virtual const Bnd_Box& BoundingBox();
0183 
0184   //! AIS_InteractiveObject defines another virtual method BoundingBox,
0185   //! which is not the same as above; keep it visible.
0186   using AIS_InteractiveObject::BoundingBox;
0187 
0188   //! Returns the Color attributes of the shape accordingly to
0189   //! the current facing model;
0190   Standard_EXPORT virtual void Color(Quantity_Color& aColor) const Standard_OVERRIDE;
0191 
0192   //! Returns the NameOfMaterial attributes of the shape accordingly to
0193   //! the current facing model;
0194   Standard_EXPORT virtual Graphic3d_NameOfMaterial Material() const Standard_OVERRIDE;
0195 
0196   //! Returns the transparency attributes of the shape accordingly to
0197   //! the current facing model;
0198   Standard_EXPORT virtual Standard_Real Transparency() const Standard_OVERRIDE;
0199 
0200   //! Return shape type for specified selection mode.
0201   static TopAbs_ShapeEnum SelectionType(const Standard_Integer theSelMode)
0202   {
0203     switch (theSelMode)
0204     {
0205       case 1:
0206         return TopAbs_VERTEX;
0207       case 2:
0208         return TopAbs_EDGE;
0209       case 3:
0210         return TopAbs_WIRE;
0211       case 4:
0212         return TopAbs_FACE;
0213       case 5:
0214         return TopAbs_SHELL;
0215       case 6:
0216         return TopAbs_SOLID;
0217       case 7:
0218         return TopAbs_COMPSOLID;
0219       case 8:
0220         return TopAbs_COMPOUND;
0221       case 0:
0222         return TopAbs_SHAPE;
0223     }
0224     return TopAbs_SHAPE;
0225   }
0226 
0227   //! Return selection mode for specified shape type.
0228   static Standard_Integer SelectionMode(const TopAbs_ShapeEnum theShapeType)
0229   {
0230     switch (theShapeType)
0231     {
0232       case TopAbs_VERTEX:
0233         return 1;
0234       case TopAbs_EDGE:
0235         return 2;
0236       case TopAbs_WIRE:
0237         return 3;
0238       case TopAbs_FACE:
0239         return 4;
0240       case TopAbs_SHELL:
0241         return 5;
0242       case TopAbs_SOLID:
0243         return 6;
0244       case TopAbs_COMPSOLID:
0245         return 7;
0246       case TopAbs_COMPOUND:
0247         return 8;
0248       case TopAbs_SHAPE:
0249         return 0;
0250     }
0251     return 0;
0252   }
0253 
0254 public: //! @name methods to alter texture mapping properties
0255   //! Return texture repeat UV values; (1, 1) by default.
0256   const gp_Pnt2d& TextureRepeatUV() const { return myUVRepeat; }
0257 
0258   //! Sets the number of occurrences of the texture on each face. The texture itself is
0259   //! parameterized in (0,1) by (0,1). Each face of the shape to be textured is parameterized in UV
0260   //! space (Umin,Umax) by (Vmin,Vmax).
0261   void SetTextureRepeatUV(const gp_Pnt2d& theRepeatUV) { myUVRepeat = theRepeatUV; }
0262 
0263   //! Return texture origin UV position; (0, 0) by default.
0264   const gp_Pnt2d& TextureOriginUV() const { return myUVOrigin; }
0265 
0266   //! Use this method to change the origin of the texture.
0267   //! The texel (0,0) will be mapped to the surface (myUVOrigin.X(), myUVOrigin.Y()).
0268   void SetTextureOriginUV(const gp_Pnt2d& theOriginUV) { myUVOrigin = theOriginUV; }
0269 
0270   //! Return scale factor for UV coordinates; (1, 1) by default.
0271   const gp_Pnt2d& TextureScaleUV() const { return myUVScale; }
0272 
0273   //! Use this method to scale the texture (percent of the face).
0274   //! You can specify a scale factor for both U and V.
0275   //! Example: if you set ScaleU and ScaleV to 0.5 and you enable texture repeat,
0276   //!          the texture will appear twice on the face in each direction.
0277   void SetTextureScaleUV(const gp_Pnt2d& theScaleUV) { myUVScale = theScaleUV; }
0278 
0279 protected:
0280   //! Compute normal presentation.
0281   Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager)& thePrsMgr,
0282                                        const Handle(Prs3d_Presentation)&         thePrs,
0283                                        const Standard_Integer theMode) Standard_OVERRIDE;
0284 
0285   //! Compute projected presentation.
0286   virtual void computeHLR(const Handle(Graphic3d_Camera)&   theProjector,
0287                           const Handle(TopLoc_Datum3D)&     theTrsf,
0288                           const Handle(Prs3d_Presentation)& thePrs) Standard_OVERRIDE
0289   {
0290     if (!theTrsf.IsNull() && theTrsf->Form() != gp_Identity)
0291     {
0292       const TopLoc_Location& aLoc   = myshape.Location();
0293       const TopoDS_Shape     aShape = myshape.Located(TopLoc_Location(theTrsf->Trsf()) * aLoc);
0294       computeHlrPresentation(theProjector, thePrs, aShape, myDrawer);
0295     }
0296     else
0297     {
0298       computeHlrPresentation(theProjector, thePrs, myshape, myDrawer);
0299     }
0300   }
0301 
0302   //! Compute selection.
0303   Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
0304                                                 const Standard_Integer theMode) Standard_OVERRIDE;
0305 
0306   //! Create own aspects (if they do not exist) and set color to them.
0307   //! @return TRUE if new aspects have been created
0308   Standard_EXPORT bool setColor(const Handle(Prs3d_Drawer)& theDrawer,
0309                                 const Quantity_Color&       theColor) const;
0310 
0311   //! Create own aspects (if they do not exist) and set width to them.
0312   //! @return TRUE if new aspects have been created
0313   Standard_EXPORT bool setWidth(const Handle(Prs3d_Drawer)& theDrawer,
0314                                 const Standard_Real         theWidth) const;
0315 
0316   Standard_EXPORT void setTransparency(const Handle(Prs3d_Drawer)& theDrawer,
0317                                        const Standard_Real         theValue) const;
0318 
0319   Standard_EXPORT void setMaterial(const Handle(Prs3d_Drawer)&     theDrawer,
0320                                    const Graphic3d_MaterialAspect& theMaterial,
0321                                    const Standard_Boolean          theToKeepColor,
0322                                    const Standard_Boolean          theToKeepTransp) const;
0323 
0324   //! Replace aspects of already computed groups from drawer link by the new own value.
0325   Standard_EXPORT void replaceWithNewOwnAspects();
0326 
0327 public:
0328   //! Compute HLR presentation for specified shape.
0329   Standard_EXPORT static void computeHlrPresentation(const Handle(Graphic3d_Camera)&   theProjector,
0330                                                      const Handle(Prs3d_Presentation)& thePrs,
0331                                                      const TopoDS_Shape&               theShape,
0332                                                      const Handle(Prs3d_Drawer)&       theDrawer);
0333 
0334   //! Dumps the content of me into the stream
0335   Standard_EXPORT virtual void DumpJson(Standard_OStream& theOStream,
0336                                         Standard_Integer  theDepth = -1) const Standard_OVERRIDE;
0337 
0338 protected:
0339   TopoDS_Shape     myshape;    //!< shape to display
0340   Bnd_Box          myBB;       //!< cached bounding box of the shape
0341   gp_Pnt2d         myUVOrigin; //!< UV origin vector for generating texture coordinates
0342   gp_Pnt2d         myUVRepeat; //!< UV repeat vector for generating texture coordinates
0343   gp_Pnt2d         myUVScale;  //!< UV scale  vector for generating texture coordinates
0344   Standard_Real    myInitAng;
0345   Standard_Boolean myCompBB; //!< if TRUE, then bounding box should be recomputed
0346 };
0347 
0348 DEFINE_STANDARD_HANDLE(AIS_Shape, AIS_InteractiveObject)
0349 
0350 #endif // _AIS_Shape_HeaderFile