Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:20:20

0001 // Copyright (c) 1995-1999 Matra Datavision
0002 // Copyright (c) 1999-2014 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 _Graphic3d_CStructure_HeaderFile
0016 #define _Graphic3d_CStructure_HeaderFile
0017 
0018 #include <Graphic3d_DisplayPriority.hxx>
0019 #include <Graphic3d_PresentationAttributes.hxx>
0020 #include <Graphic3d_Group.hxx>
0021 #include <NCollection_Sequence.hxx>
0022 #include <Graphic3d_SequenceOfHClipPlane.hxx>
0023 #include <Graphic3d_ViewAffinity.hxx>
0024 #include <Graphic3d_TransformPers.hxx>
0025 #include <Graphic3d_ZLayerId.hxx>
0026 #include <TopLoc_Datum3D.hxx>
0027 #include <NCollection_IndexedMap.hxx>
0028 
0029 class Graphic3d_GraphicDriver;
0030 class Graphic3d_StructureManager;
0031 
0032 //! Low-level graphic structure interface
0033 class Graphic3d_CStructure : public Standard_Transient
0034 {
0035   DEFINE_STANDARD_RTTIEXT(Graphic3d_CStructure, Standard_Transient)
0036 protected:
0037   //! Auxiliary wrapper to iterate through structure list.
0038   template <class Struct_t>
0039   class SubclassStructIterator
0040   {
0041   public:
0042     SubclassStructIterator(const NCollection_IndexedMap<const Graphic3d_CStructure*>& theStructs)
0043         : myIter(theStructs)
0044     {
0045     }
0046 
0047     bool More() const { return myIter.More(); }
0048 
0049     void Next() { myIter.Next(); }
0050 
0051     const Struct_t* Value() const { return (const Struct_t*)(myIter.Value()); }
0052 
0053     Struct_t* ChangeValue() { return (Struct_t*)(myIter.Value()); }
0054 
0055   private:
0056     NCollection_IndexedMap<const Graphic3d_CStructure*>::Iterator myIter;
0057   };
0058 
0059   //! Auxiliary wrapper to iterate through group sequence.
0060   template <class Group_t>
0061   class SubclassGroupIterator
0062   {
0063   public:
0064     SubclassGroupIterator(const NCollection_Sequence<occ::handle<Graphic3d_Group>>& theGroups)
0065         : myIter(theGroups)
0066     {
0067     }
0068 
0069     bool More() const { return myIter.More(); }
0070 
0071     void Next() { myIter.Next(); }
0072 
0073     const Group_t* Value() const { return (const Group_t*)(myIter.Value().get()); }
0074 
0075     Group_t* ChangeValue() { return (Group_t*)(myIter.ChangeValue().get()); }
0076 
0077   private:
0078     NCollection_Sequence<occ::handle<Graphic3d_Group>>::Iterator myIter;
0079   };
0080 
0081 public:
0082   //! @return graphic driver created this structure
0083   const occ::handle<Graphic3d_GraphicDriver>& GraphicDriver() const { return myGraphicDriver; }
0084 
0085   //! @return graphic groups
0086   const NCollection_Sequence<occ::handle<Graphic3d_Group>>& Groups() const { return myGroups; }
0087 
0088   //! Return transformation.
0089   const occ::handle<TopLoc_Datum3D>& Transformation() const { return myTrsf; }
0090 
0091   //! Assign transformation.
0092   virtual void SetTransformation(const occ::handle<TopLoc_Datum3D>& theTrsf) { myTrsf = theTrsf; }
0093 
0094   //! Return transformation persistence.
0095   const occ::handle<Graphic3d_TransformPers>& TransformPersistence() const { return myTrsfPers; }
0096 
0097   //! Set transformation persistence.
0098   virtual void SetTransformPersistence(const occ::handle<Graphic3d_TransformPers>& theTrsfPers)
0099   {
0100     myTrsfPers = theTrsfPers;
0101   }
0102 
0103   //! Return TRUE if some groups might have transform persistence; FALSE by default.
0104   bool HasGroupTransformPersistence() const { return myHasGroupTrsf; }
0105 
0106   //! Set if some groups might have transform persistence.
0107   void SetGroupTransformPersistence(bool theValue) { myHasGroupTrsf = theValue; }
0108 
0109   //! Return TRUE if some groups might have flipping options; FALSE by default.
0110   bool HasGroupFlipping() const { return myHasGroupFlipping; }
0111 
0112   //! Set if some groups might have flipping options.
0113   void SetGroupFlipping(bool theValue) { myHasGroupFlipping = theValue; }
0114 
0115   //! @return associated clip planes
0116   const occ::handle<Graphic3d_SequenceOfHClipPlane>& ClipPlanes() const { return myClipPlanes; }
0117 
0118   //! Pass clip planes to the associated graphic driver structure
0119   void SetClipPlanes(const occ::handle<Graphic3d_SequenceOfHClipPlane>& thePlanes)
0120   {
0121     myClipPlanes = thePlanes;
0122   }
0123 
0124   //! @return bounding box of this presentation
0125   const Graphic3d_BndBox3d& BoundingBox() const { return myBndBox; }
0126 
0127   //! @return bounding box of this presentation
0128   //! without transformation matrix applied
0129   Graphic3d_BndBox3d& ChangeBoundingBox() { return myBndBox; }
0130 
0131   //! Return structure visibility flag
0132   bool IsVisible() const { return visible != 0; }
0133 
0134   //! Return structure visibility considering both View Affinity and global visibility state.
0135   bool IsVisible(const int theViewId) const
0136   {
0137     return visible != 0 && (ViewAffinity.IsNull() || ViewAffinity->IsVisible(theViewId));
0138   }
0139 
0140   //! Set z layer ID to display the structure in specified layer
0141   virtual void SetZLayer(const Graphic3d_ZLayerId theLayerIndex) { myZLayer = theLayerIndex; }
0142 
0143   //! Get z layer ID
0144   Graphic3d_ZLayerId ZLayer() const { return myZLayer; }
0145 
0146   //! Returns valid handle to highlight style of the structure in case if
0147   //! highlight flag is set to true
0148   const occ::handle<Graphic3d_PresentationAttributes>& HighlightStyle() const
0149   {
0150     return myHighlightStyle;
0151   }
0152 
0153   //! Return structure id (generated by Graphic3d_GraphicDriver::NewIdentification() during
0154   //! structure construction).
0155   int Identification() const { return myId; }
0156 
0157   //! Return structure display priority.
0158   Graphic3d_DisplayPriority Priority() const { return myPriority; }
0159 
0160   //! Set structure display priority.
0161   void SetPriority(Graphic3d_DisplayPriority thePriority) { myPriority = thePriority; }
0162 
0163   //! Return previous structure display priority.
0164   Graphic3d_DisplayPriority PreviousPriority() const { return myPreviousPriority; }
0165 
0166   //! Set previous structure display priority.
0167   void SetPreviousPriority(Graphic3d_DisplayPriority thePriority)
0168   {
0169     myPreviousPriority = thePriority;
0170   }
0171 
0172 public:
0173   //! Returns FALSE if the structure hits the current view volume, otherwise returns TRUE.
0174   bool IsCulled() const { return myIsCulled; }
0175 
0176   //! Marks structure as culled/not culled - note that IsAlwaysRendered() is ignored here!
0177   void SetCulled(bool theIsCulled) const { myIsCulled = theIsCulled; }
0178 
0179   //! Marks structure as overlapping the current view volume one.
0180   //! The method is called during traverse of BVH tree.
0181   void MarkAsNotCulled() const { myIsCulled = false; }
0182 
0183   //! Returns whether check of object's bounding box clipping is enabled before drawing of object;
0184   //! TRUE by default.
0185   bool BndBoxClipCheck() const { return myBndBoxClipCheck; }
0186 
0187   //! Enable/disable check of object's bounding box clipping before drawing of object.
0188   void SetBndBoxClipCheck(bool theBndBoxClipCheck) { myBndBoxClipCheck = theBndBoxClipCheck; }
0189 
0190   //! Checks if the structure should be included into BVH tree or not.
0191   bool IsAlwaysRendered() const
0192   {
0193     return IsInfinite || IsForHighlight || IsMutable || Is2dText
0194            || (!myTrsfPers.IsNull() && myTrsfPers->IsTrihedronOr2d());
0195   }
0196 
0197 public:
0198   //! Update structure visibility state
0199   virtual void OnVisibilityChanged() = 0;
0200 
0201   //! Clear graphic data
0202   virtual void Clear() = 0;
0203 
0204   //! Connect other structure to this one
0205   virtual void Connect(Graphic3d_CStructure& theStructure) = 0;
0206 
0207   //! Disconnect other structure to this one
0208   virtual void Disconnect(Graphic3d_CStructure& theStructure) = 0;
0209 
0210   //! Highlights structure with the given style
0211   virtual void GraphicHighlight(const occ::handle<Graphic3d_PresentationAttributes>& theStyle) = 0;
0212 
0213   //! Unhighlights the structure and invalidates pointer to structure's highlight style
0214   virtual void GraphicUnhighlight() = 0;
0215 
0216   //! Create shadow link to this structure
0217   virtual occ::handle<Graphic3d_CStructure> ShadowLink(
0218     const occ::handle<Graphic3d_StructureManager>& theManager) const = 0;
0219 
0220   //! Create new group within this structure
0221   virtual occ::handle<Graphic3d_Group> NewGroup(
0222     const occ::handle<Graphic3d_Structure>& theStruct) = 0;
0223 
0224   //! Remove group from this structure
0225   virtual void RemoveGroup(const occ::handle<Graphic3d_Group>& theGroup) = 0;
0226 
0227   //! Update render transformation matrix.
0228   virtual void updateLayerTransformation() {}
0229 
0230   //! Dumps the content of me into the stream
0231   Standard_EXPORT virtual void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const;
0232 
0233 public:
0234   occ::handle<Graphic3d_ViewAffinity> ViewAffinity; //!< view affinity mask
0235 
0236 protected:
0237   //! Create empty structure.
0238   Standard_EXPORT Graphic3d_CStructure(const occ::handle<Graphic3d_StructureManager>& theManager);
0239 
0240 protected:
0241   occ::handle<Graphic3d_GraphicDriver>               myGraphicDriver;
0242   NCollection_Sequence<occ::handle<Graphic3d_Group>> myGroups;
0243   Graphic3d_BndBox3d                                 myBndBox;
0244   occ::handle<TopLoc_Datum3D>                        myTrsf;
0245   occ::handle<Graphic3d_TransformPers>               myTrsfPers;
0246   occ::handle<Graphic3d_SequenceOfHClipPlane>        myClipPlanes;
0247   // clang-format off
0248   occ::handle<Graphic3d_PresentationAttributes> myHighlightStyle; //! Current highlight style; is set only if highlight flag is true
0249 
0250   int          myId;
0251   Graphic3d_ZLayerId        myZLayer;
0252   Graphic3d_DisplayPriority myPriority;
0253   Graphic3d_DisplayPriority myPreviousPriority;
0254 
0255   mutable bool myIsCulled; //!< A status specifying is structure needs to be rendered after BVH tree traverse
0256   bool myBndBoxClipCheck;  //!< Flag responsible for checking of bounding box clipping before drawing of object
0257 
0258   bool myHasGroupTrsf;     //!< flag specifying that some groups might have transform persistence
0259   bool myHasGroupFlipping; //!< flag specifying that some groups might have flipping options
0260 
0261 public:
0262 
0263   unsigned IsInfinite     : 1;
0264   unsigned stick          : 1; //!< displaying state - should be set when structure has been added to scene graph (but can be in hidden state)
0265   unsigned highlight      : 1;
0266   unsigned visible        : 1; //!< visibility flag - can be used to suppress structure while leaving it in the scene graph
0267   // clang-format on
0268   unsigned HLRValidation : 1;
0269   unsigned IsForHighlight : 1;
0270   unsigned IsMutable : 1;
0271   unsigned Is2dText : 1;
0272 };
0273 
0274 #endif // _Graphic3d_CStructure_HeaderFile