Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:55

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 surface of each Face
0051 //! (this means that texture will be visually duplicated on all Faces).
0052 //! To generate texture coordinates, appropriate shading attribute should be set before computing presentation in AIS_Shaded display mode:
0053 //! @code
0054 //!   Handle(AIS_Shape) aPrs = new AIS_Shape();
0055 //!   aPrs->Attributes()->SetupOwnShadingAspect();
0056 //!   aPrs->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
0057 //!   aPrs->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (new Graphic3d_Texture2Dmanual (Graphic3d_NOT_2D_ALUMINUM));
0058 //! @endcode
0059 //! The texture itself is parametrized in (0,1)x(0,1).
0060 class AIS_Shape : public AIS_InteractiveObject
0061 {
0062   DEFINE_STANDARD_RTTIEXT(AIS_Shape, AIS_InteractiveObject)
0063 public:
0064 
0065   //! Initializes construction of the shape shap from wires,
0066   //! edges and vertices.
0067   Standard_EXPORT AIS_Shape(const TopoDS_Shape& shap);
0068 
0069   //! Returns index 0. This value refers to SHAPE from TopAbs_ShapeEnum
0070   virtual Standard_Integer Signature() const Standard_OVERRIDE { return 0; }
0071 
0072   //! Returns Object as the type of Interactive Object.
0073   virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE { return AIS_KindOfInteractive_Shape; }
0074 
0075   //! Returns true if the Interactive Object accepts shape decomposition.
0076   virtual Standard_Boolean AcceptShapeDecomposition() const Standard_OVERRIDE { return Standard_True; }
0077 
0078   //! Return true if specified display mode is supported.
0079   virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode >= 0 && theMode <= 2; }
0080 
0081   //! Returns this shape object.
0082   const TopoDS_Shape& Shape() const { return myshape; }
0083 
0084   //! Constructs an instance of the shape object theShape.
0085   void SetShape (const TopoDS_Shape& theShape)
0086   {
0087     myshape  = theShape;
0088     myCompBB = Standard_True;
0089   }
0090 
0091   //! Alias for ::SetShape().
0092   void Set (const TopoDS_Shape& theShape) { SetShape (theShape); }
0093 
0094   //! Sets a local value for deviation coefficient for this specific shape.
0095   Standard_EXPORT Standard_Boolean SetOwnDeviationCoefficient();
0096 
0097   //! Sets a local value for deviation angle for this specific shape.
0098   Standard_EXPORT Standard_Boolean SetOwnDeviationAngle();
0099   
0100   //! Sets a local value for deviation coefficient for this specific shape.
0101   Standard_EXPORT void SetOwnDeviationCoefficient (const Standard_Real aCoefficient);
0102 
0103   //! this compute a new angle and Deviation from the value anAngle
0104   //! and set the values stored in myDrawer with these that become local to the shape
0105   Standard_EXPORT void SetAngleAndDeviation (const Standard_Real anAngle);
0106   
0107   //! gives back the angle initial value put by the User.
0108   Standard_EXPORT Standard_Real UserAngle() const;
0109   
0110   //! sets myOwnDeviationAngle field in Prs3d_Drawer & recomputes presentation
0111   Standard_EXPORT void SetOwnDeviationAngle (const Standard_Real anAngle);
0112   
0113   //! Returns true and the values of the deviation
0114   //! coefficient aCoefficient and the previous deviation
0115   //! coefficient aPreviousCoefficient. If these values are
0116   //! not already set, false is returned.
0117   Standard_EXPORT Standard_Boolean OwnDeviationCoefficient (Standard_Real& aCoefficient, Standard_Real& aPreviousCoefficient) const;
0118   
0119   //! Returns true and the values of the deviation angle
0120   //! anAngle and the previous deviation angle aPreviousAngle.
0121   //! If these values are not already set, false is returned.
0122   Standard_EXPORT Standard_Boolean OwnDeviationAngle (Standard_Real& anAngle, Standard_Real& aPreviousAngle) const;
0123   
0124   //! Sets the type of HLR algorithm used by the shape
0125   void SetTypeOfHLR (const Prs3d_TypeOfHLR theTypeOfHLR) {  myDrawer->SetTypeOfHLR (theTypeOfHLR); }
0126 
0127   //! Gets the type of HLR algorithm
0128   Prs3d_TypeOfHLR TypeOfHLR() const { return myDrawer->TypeOfHLR(); }
0129 
0130   //! Sets the color aColor in the reconstructed
0131   //! compound shape. Acts via the Drawer methods below on the appearance of:
0132   //! -   free boundaries:
0133   //! Prs3d_Drawer_FreeBoundaryAspect,
0134   //! -   isos: Prs3d_Drawer_UIsoAspect,
0135   //! Prs3dDrawer_VIsoAspect,
0136   //! -   shared boundaries:
0137   //! Prs3d_Drawer_UnFreeBoundaryAspect,
0138   //! -   shading: Prs3d_Drawer_ShadingAspect,
0139   //! -   visible line color in hidden line mode:
0140   //! Prs3d_Drawer_SeenLineAspect
0141   //! -   hidden line color in hidden line mode:
0142   //! Prs3d_Drawer_HiddenLineAspect.
0143   Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
0144 
0145   //! Removes settings for color in the reconstructed compound shape.
0146   Standard_EXPORT virtual void UnsetColor() Standard_OVERRIDE;
0147   
0148   //! Sets the value aValue for line width in the reconstructed compound shape.
0149   //! Changes line aspects for lines presentation.
0150   Standard_EXPORT virtual void SetWidth (const Standard_Real aValue) Standard_OVERRIDE;
0151   
0152   //! Removes the setting for line width in the reconstructed compound shape.
0153   Standard_EXPORT virtual void UnsetWidth() Standard_OVERRIDE;
0154 
0155   //! Allows you to provide settings for the material aName
0156   //! in the reconstructed compound shape.
0157   Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& aName) Standard_OVERRIDE;
0158   
0159   //! Removes settings for material in the reconstructed compound shape.
0160   Standard_EXPORT virtual void UnsetMaterial() Standard_OVERRIDE;
0161   
0162   //! Sets the value aValue for transparency in the reconstructed compound shape.
0163   Standard_EXPORT virtual void SetTransparency (const Standard_Real aValue = 0.6) Standard_OVERRIDE;
0164   
0165   //! Removes the setting for transparency in the reconstructed compound shape.
0166   Standard_EXPORT virtual void UnsetTransparency() Standard_OVERRIDE;
0167   
0168   //! Constructs a bounding box with which to reconstruct
0169   //! compound topological shapes for presentation.
0170   Standard_EXPORT virtual const Bnd_Box& BoundingBox();
0171   
0172   //! AIS_InteractiveObject defines another virtual method BoundingBox,
0173   //! which is not the same as above; keep it visible.
0174   using AIS_InteractiveObject::BoundingBox;
0175 
0176   //! Returns the Color attributes of the shape accordingly to
0177   //! the current facing model;
0178   Standard_EXPORT virtual void Color (Quantity_Color& aColor) const Standard_OVERRIDE;
0179   
0180   //! Returns the NameOfMaterial attributes of the shape accordingly to
0181   //! the current facing model;
0182   Standard_EXPORT virtual Graphic3d_NameOfMaterial Material() const Standard_OVERRIDE;
0183   
0184   //! Returns the transparency attributes of the shape accordingly to
0185   //! the current facing model;
0186   Standard_EXPORT virtual Standard_Real Transparency() const Standard_OVERRIDE;
0187 
0188   //! Return shape type for specified selection mode.
0189   static TopAbs_ShapeEnum SelectionType (const Standard_Integer theSelMode)
0190   {
0191     switch (theSelMode)
0192     {
0193       case 1: return TopAbs_VERTEX;
0194       case 2: return TopAbs_EDGE;
0195       case 3: return TopAbs_WIRE;
0196       case 4: return TopAbs_FACE;
0197       case 5: return TopAbs_SHELL;
0198       case 6: return TopAbs_SOLID;
0199       case 7: return TopAbs_COMPSOLID;
0200       case 8: return TopAbs_COMPOUND;
0201       case 0: return TopAbs_SHAPE;
0202     }
0203     return TopAbs_SHAPE;
0204   }
0205 
0206   //! Return selection mode for specified shape type.
0207   static Standard_Integer SelectionMode (const TopAbs_ShapeEnum theShapeType)
0208   {
0209     switch (theShapeType)
0210     {
0211       case TopAbs_VERTEX:    return 1;
0212       case TopAbs_EDGE:      return 2;
0213       case TopAbs_WIRE:      return 3;
0214       case TopAbs_FACE:      return 4;
0215       case TopAbs_SHELL:     return 5;
0216       case TopAbs_SOLID:     return 6;
0217       case TopAbs_COMPSOLID: return 7;
0218       case TopAbs_COMPOUND:  return 8;
0219       case TopAbs_SHAPE:     return 0;
0220     }
0221     return 0;
0222   }
0223 
0224 public: //! @name methods to alter texture mapping properties
0225 
0226   //! Return texture repeat UV values; (1, 1) by default.
0227   const gp_Pnt2d& TextureRepeatUV() const { return myUVRepeat; }
0228 
0229   //! Sets the number of occurrences of the texture on each face. The texture itself is parameterized in (0,1) by (0,1).
0230   //! Each face of the shape to be textured is parameterized in UV space (Umin,Umax) by (Vmin,Vmax).
0231   void SetTextureRepeatUV (const gp_Pnt2d& theRepeatUV) { myUVRepeat = theRepeatUV; }
0232 
0233   //! Return texture origin UV position; (0, 0) by default.
0234   const gp_Pnt2d& TextureOriginUV() const { return myUVOrigin; }
0235 
0236   //! Use this method to change the origin of the texture.
0237   //! The texel (0,0) will be mapped to the surface (myUVOrigin.X(), myUVOrigin.Y()).
0238   void SetTextureOriginUV (const gp_Pnt2d& theOriginUV) { myUVOrigin = theOriginUV; }
0239 
0240   //! Return scale factor for UV coordinates; (1, 1) by default.
0241   const gp_Pnt2d& TextureScaleUV() const { return myUVScale; }
0242 
0243   //! Use this method to scale the texture (percent of the face).
0244   //! You can specify a scale factor for both U and V.
0245   //! Example: if you set ScaleU and ScaleV to 0.5 and you enable texture repeat,
0246   //!          the texture will appear twice on the face in each direction.
0247   void SetTextureScaleUV (const gp_Pnt2d& theScaleUV) { myUVScale = theScaleUV; }
0248 
0249 protected:
0250 
0251   //! Compute normal presentation.
0252   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
0253                                         const Handle(Prs3d_Presentation)& thePrs,
0254                                         const Standard_Integer theMode) Standard_OVERRIDE;
0255 
0256   //! Compute projected presentation.
0257   virtual void computeHLR (const Handle(Graphic3d_Camera)& theProjector,
0258                            const Handle(TopLoc_Datum3D)& theTrsf,
0259                            const Handle(Prs3d_Presentation)& thePrs) Standard_OVERRIDE
0260   {
0261     if (!theTrsf.IsNull()
0262       && theTrsf->Form() != gp_Identity)
0263     {
0264       const TopLoc_Location& aLoc = myshape.Location();
0265       const TopoDS_Shape aShape = myshape.Located (TopLoc_Location (theTrsf->Trsf()) * aLoc);
0266       computeHlrPresentation (theProjector, thePrs, aShape, myDrawer);
0267     }
0268     else
0269     {
0270       computeHlrPresentation (theProjector, thePrs, myshape, myDrawer);
0271     }
0272   }
0273 
0274   //! Compute selection.
0275   Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
0276                                                  const Standard_Integer theMode) Standard_OVERRIDE;
0277   
0278   //! Create own aspects (if they do not exist) and set color to them.
0279   //! @return TRUE if new aspects have been created
0280   Standard_EXPORT bool setColor (const Handle(Prs3d_Drawer)& theDrawer, const Quantity_Color& theColor) const;
0281   
0282   //! Create own aspects (if they do not exist) and set width to them.
0283   //! @return TRUE if new aspects have been created
0284   Standard_EXPORT bool setWidth (const Handle(Prs3d_Drawer)& theDrawer, const Standard_Real theWidth) const;
0285   
0286   Standard_EXPORT void setTransparency (const Handle(Prs3d_Drawer)& theDrawer, const Standard_Real theValue) const;
0287   
0288   Standard_EXPORT void setMaterial (const Handle(Prs3d_Drawer)& theDrawer, const Graphic3d_MaterialAspect& theMaterial, const Standard_Boolean theToKeepColor, const Standard_Boolean theToKeepTransp) const;
0289 
0290   //! Replace aspects of already computed groups from drawer link by the new own value.
0291   Standard_EXPORT void replaceWithNewOwnAspects();
0292 
0293 public:
0294 
0295   //! Compute HLR presentation for specified shape.
0296   Standard_EXPORT static void computeHlrPresentation (const Handle(Graphic3d_Camera)& theProjector,
0297                                                       const Handle(Prs3d_Presentation)& thePrs,
0298                                                       const TopoDS_Shape& theShape,
0299                                                       const Handle(Prs3d_Drawer)& theDrawer);
0300 
0301   //! Dumps the content of me into the stream
0302   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
0303 
0304 protected:
0305 
0306   TopoDS_Shape     myshape;    //!< shape to display
0307   Bnd_Box          myBB;       //!< cached bounding box of the shape
0308   gp_Pnt2d         myUVOrigin; //!< UV origin vector for generating texture coordinates
0309   gp_Pnt2d         myUVRepeat; //!< UV repeat vector for generating texture coordinates
0310   gp_Pnt2d         myUVScale;  //!< UV scale  vector for generating texture coordinates
0311   Standard_Real    myInitAng;
0312   Standard_Boolean myCompBB;   //!< if TRUE, then bounding box should be recomputed
0313 
0314 };
0315 
0316 DEFINE_STANDARD_HANDLE(AIS_Shape, AIS_InteractiveObject)
0317 
0318 #endif // _AIS_Shape_HeaderFile