Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-11 09:18:50

0001 // Created on: 2011-08-01
0002 // Created by: Sergey ZERCHANINOV
0003 // Copyright (c) 2011-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef OpenGl_Structure_HeaderFile
0017 #define OpenGl_Structure_HeaderFile
0018 
0019 #include <Graphic3d_CStructure.hxx>
0020 
0021 #include <OpenGl_GraphicDriver.hxx>
0022 #include <OpenGl_Group.hxx>
0023 #include <OpenGl_Workspace.hxx>
0024 
0025 #include <NCollection_List.hxx>
0026 
0027 //! Implementation of low-level graphic structure.
0028 class OpenGl_Structure : public Graphic3d_CStructure
0029 {
0030   friend class OpenGl_Group;
0031   DEFINE_STANDARD_RTTIEXT(OpenGl_Structure, Graphic3d_CStructure)
0032 public:
0033   //! Auxiliary wrapper to iterate OpenGl_Structure sequence.
0034   typedef SubclassStructIterator<OpenGl_Structure> StructIterator;
0035 
0036   //! Auxiliary wrapper to iterate OpenGl_Group sequence.
0037   typedef SubclassGroupIterator<OpenGl_Group> GroupIterator;
0038 
0039 public:
0040   //! Create empty structure
0041   Standard_EXPORT OpenGl_Structure(const occ::handle<Graphic3d_StructureManager>& theManager);
0042 
0043   //! Setup structure graphic state
0044   Standard_EXPORT void OnVisibilityChanged() override;
0045 
0046   //! Clear graphic data
0047   Standard_EXPORT void Clear() override;
0048 
0049   //! Connect other structure to this one
0050   Standard_EXPORT void Connect(Graphic3d_CStructure& theStructure) override;
0051 
0052   //! Disconnect other structure to this one
0053   Standard_EXPORT void Disconnect(Graphic3d_CStructure& theStructure) override;
0054 
0055   //! Synchronize structure transformation
0056   Standard_EXPORT void SetTransformation(const occ::handle<TopLoc_Datum3D>& theTrsf) override;
0057 
0058   //! Set transformation persistence.
0059   Standard_EXPORT void SetTransformPersistence(
0060     const occ::handle<Graphic3d_TransformPers>& theTrsfPers) override;
0061 
0062   //! Set z layer ID to display the structure in specified layer
0063   Standard_EXPORT void SetZLayer(const Graphic3d_ZLayerId theLayerIndex) override;
0064 
0065   //! Highlights structure according to the given style and updates corresponding class fields
0066   //! (highlight status and style)
0067   Standard_EXPORT void GraphicHighlight(
0068     const occ::handle<Graphic3d_PresentationAttributes>& theStyle) override;
0069 
0070   //! Unighlights structure and updates corresponding class fields (highlight status and style)
0071   Standard_EXPORT void GraphicUnhighlight() override;
0072 
0073   //! Create shadow link to this structure
0074   Standard_EXPORT occ::handle<Graphic3d_CStructure> ShadowLink(
0075     const occ::handle<Graphic3d_StructureManager>& theManager) const override;
0076 
0077   //! Create new group within this structure
0078   Standard_EXPORT occ::handle<Graphic3d_Group> NewGroup(
0079     const occ::handle<Graphic3d_Structure>& theStruct) override;
0080 
0081   //! Remove group from this structure
0082   Standard_EXPORT void RemoveGroup(const occ::handle<Graphic3d_Group>& theGroup) override;
0083 
0084 public:
0085   //! Access graphic driver
0086   OpenGl_GraphicDriver* GlDriver() const
0087   {
0088     return (OpenGl_GraphicDriver*)myGraphicDriver.operator->();
0089   }
0090 
0091   Standard_EXPORT void Clear(const occ::handle<OpenGl_Context>& theGlCtx);
0092 
0093   //! Renders the structure.
0094   Standard_EXPORT virtual void Render(const occ::handle<OpenGl_Workspace>& theWorkspace) const;
0095 
0096   //! Releases structure resources.
0097   Standard_EXPORT virtual void Release(const occ::handle<OpenGl_Context>& theGlCtx);
0098 
0099   //! This method releases GL resources without actual elements destruction.
0100   //! As result structure could be correctly destroyed layer without GL context
0101   //! (after last window was closed for example).
0102   //!
0103   //! Notice however that reusage of this structure after calling this method is incorrect
0104   //! and will lead to broken visualization due to loosed data.
0105   Standard_EXPORT void ReleaseGlResources(const occ::handle<OpenGl_Context>& theGlCtx);
0106 
0107   //! Returns instanced OpenGL structure.
0108   const OpenGl_Structure* InstancedStructure() const { return myInstancedStructure; }
0109 
0110   //! Returns structure modification state (for ray-tracing).
0111   size_t ModificationState() const { return myModificationState; }
0112 
0113   //! Resets structure modification state (for ray-tracing).
0114   void ResetModificationState() const { myModificationState = 0; }
0115 
0116   //! Is the structure ray-tracable (contains ray-tracable elements)?
0117   bool IsRaytracable() const;
0118 
0119   //! Update render transformation matrix.
0120   Standard_EXPORT void updateLayerTransformation() override;
0121 
0122   //! Dumps the content of me into the stream
0123   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const override;
0124 
0125 protected:
0126   Standard_EXPORT ~OpenGl_Structure() override;
0127 
0128   //! Updates ray-tracable status for structure and its parents.
0129   void UpdateStateIfRaytracable(const bool toCheck = true) const;
0130 
0131   //! Renders groups of structure without applying any attributes (i.e. transform, material etc).
0132   //! @param theWorkspace current workspace
0133   //! @param theHasClosed flag will be set to TRUE if structure contains at least one group of
0134   //! closed primitives
0135   Standard_EXPORT void renderGeometry(const occ::handle<OpenGl_Workspace>& theWorkspace,
0136                                       bool&                                theHasClosed) const;
0137 
0138   //! Render the bounding box.
0139   Standard_EXPORT void renderBoundingBox(const occ::handle<OpenGl_Workspace>& theWorkspace) const;
0140 
0141   //! Apply transformation into context.
0142   //! @param theWorkspace current workspace
0143   //! @param theTrsf transformation
0144   //! @param toEnable flag to switch ON/OFF transformation
0145   Standard_EXPORT void applyTransformation(const occ::handle<OpenGl_Context>& theContext,
0146                                            const gp_Trsf&                     theTrsf,
0147                                            const bool                         toEnable) const;
0148 
0149   //! Apply transform persistence into context.
0150   //! It disables shadows on non-3d objects when toEnable is true and restores otherwise.
0151   //! @param[in]  theCtx current context
0152   //! @param[in]  theTrsfPers transform persistence
0153   //! @param[in]  theIsLocal specifies if transform persistence is defined locally or to entire
0154   //! presentation
0155   //! @param[out] theOldCastShadows state of the previous cast shadows state
0156   Standard_EXPORT void applyPersistence(
0157     const occ::handle<OpenGl_Context>&          theCtx,
0158     const occ::handle<Graphic3d_TransformPers>& theTrsfPersistence,
0159     const bool                                  theIsLocal,
0160     bool&                                       theOldCastShadows) const;
0161 
0162   //! Restore context from transform persistence changes.
0163   //! @param[in] theCtx current context
0164   //! @param[in] theTrsfPers transform persistence
0165   //! @param[in] theIsLocal specifies if transform persistence is defined locally or to entire
0166   //! presentation
0167   //! @param[in] theOldCastShadows state of the previous cast shadows state
0168   Standard_EXPORT void revertPersistence(
0169     const occ::handle<OpenGl_Context>&          theCtx,
0170     const occ::handle<Graphic3d_TransformPers>& theTrsfPersistence,
0171     const bool                                  theIsLocal,
0172     const bool                                  theOldCastShadows) const;
0173 
0174 protected:
0175   OpenGl_Structure* myInstancedStructure;
0176   // clang-format off
0177   NCollection_Mat4<float>             myRenderTrsf; //!< transformation, actually used for rendering (includes Local Origin shift)
0178 
0179   mutable bool   myIsRaytracable;
0180   mutable size_t      myModificationState;
0181 
0182   bool           myIsMirrored; //!< Used to tell OpenGl to interpret polygons in clockwise order.
0183   // clang-format on
0184 };
0185 
0186 #endif // OpenGl_Structure_Header