Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:35

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 
0028 DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
0029 typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure;
0030 
0031 //! Implementation of low-level graphic structure.
0032 class OpenGl_Structure : public Graphic3d_CStructure
0033 {
0034   friend class OpenGl_Group;
0035   DEFINE_STANDARD_RTTIEXT(OpenGl_Structure, Graphic3d_CStructure)
0036 public:
0037 
0038   //! Auxiliary wrapper to iterate OpenGl_Structure sequence.
0039   typedef SubclassStructIterator<OpenGl_Structure> StructIterator;
0040 
0041   //! Auxiliary wrapper to iterate OpenGl_Group sequence.
0042   typedef SubclassGroupIterator<OpenGl_Group> GroupIterator;
0043 
0044 public:
0045 
0046   //! Create empty structure
0047   Standard_EXPORT OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager);
0048 
0049   //! Setup structure graphic state
0050   Standard_EXPORT virtual void OnVisibilityChanged() Standard_OVERRIDE;
0051 
0052   //! Clear graphic data
0053   Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
0054 
0055   //! Connect other structure to this one
0056   Standard_EXPORT virtual void Connect    (Graphic3d_CStructure& theStructure) Standard_OVERRIDE;
0057 
0058   //! Disconnect other structure to this one
0059   Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE;
0060 
0061   //! Synchronize structure transformation
0062   Standard_EXPORT virtual void SetTransformation (const Handle(TopLoc_Datum3D)& theTrsf) Standard_OVERRIDE;
0063 
0064   //! Set transformation persistence.
0065   Standard_EXPORT virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) Standard_OVERRIDE;
0066 
0067   //! Set z layer ID to display the structure in specified layer
0068   Standard_EXPORT virtual void SetZLayer(const Graphic3d_ZLayerId theLayerIndex) Standard_OVERRIDE;
0069 
0070   //! Highlights structure according to the given style and updates corresponding class fields
0071   //! (highlight status and style)
0072   Standard_EXPORT virtual void GraphicHighlight (const Handle(Graphic3d_PresentationAttributes)& theStyle) Standard_OVERRIDE;
0073 
0074   //! Unighlights structure and updates corresponding class fields (highlight status and style)
0075   Standard_EXPORT virtual void GraphicUnhighlight() Standard_OVERRIDE;
0076 
0077   //! Create shadow link to this structure
0078   Standard_EXPORT virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const Standard_OVERRIDE;
0079 
0080   //! Create new group within this structure
0081   Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct) Standard_OVERRIDE;
0082 
0083   //! Remove group from this structure
0084   Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup) Standard_OVERRIDE;
0085 
0086 public:
0087 
0088   //! Access graphic driver
0089   OpenGl_GraphicDriver* GlDriver() const
0090   {
0091     return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
0092   }
0093 
0094   Standard_EXPORT void Clear (const Handle(OpenGl_Context)& theGlCtx);
0095 
0096   //! Renders the structure.
0097   Standard_EXPORT virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const;
0098 
0099   //! Releases structure resources.
0100   Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
0101 
0102   //! This method releases GL resources without actual elements destruction.
0103   //! As result structure could be correctly destroyed layer without GL context
0104   //! (after last window was closed for example).
0105   //!
0106   //! Notice however that reusage of this structure after calling this method is incorrect
0107   //! and will lead to broken visualization due to loosed data.
0108   Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx);
0109 
0110   //! Returns instanced OpenGL structure.
0111   const OpenGl_Structure* InstancedStructure() const { return myInstancedStructure; }
0112 
0113   //! Returns structure modification state (for ray-tracing).
0114   Standard_Size ModificationState() const { return myModificationState; }
0115 
0116   //! Resets structure modification state (for ray-tracing).
0117   void ResetModificationState() const { myModificationState = 0; }
0118 
0119   //! Is the structure ray-tracable (contains ray-tracable elements)?
0120   Standard_Boolean IsRaytracable() const;
0121 
0122   //! Update render transformation matrix.
0123   Standard_EXPORT virtual void updateLayerTransformation() Standard_OVERRIDE;
0124 
0125   //! Dumps the content of me into the stream
0126   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
0127 
0128 protected:
0129 
0130   Standard_EXPORT virtual ~OpenGl_Structure();
0131 
0132   //! Updates ray-tracable status for structure and its parents.
0133   void UpdateStateIfRaytracable (const Standard_Boolean toCheck = Standard_True) const;
0134 
0135   //! Renders groups of structure without applying any attributes (i.e. transform, material etc).
0136   //! @param theWorkspace current workspace
0137   //! @param theHasClosed flag will be set to TRUE if structure contains at least one group of closed primitives
0138   Standard_EXPORT void renderGeometry (const Handle(OpenGl_Workspace)& theWorkspace,
0139                                        bool&                           theHasClosed) const;
0140 
0141   //! Render the bounding box.
0142   Standard_EXPORT void renderBoundingBox(const Handle(OpenGl_Workspace)& theWorkspace) const;
0143 
0144   //! Apply transform persistence into context.
0145   //! It disables shadows on non-3d objects when toEnable is true and restores otherwise.
0146   //! @param[in]  theCtx current context
0147   //! @param[in]  theTrsfPers transform persistence
0148   //! @param[in]  theIsLocal specifies if transform persistence is defined locally or to entire presentation
0149   //! @param[out] theOldCastShadows state of the previous cast shadows state
0150   Standard_EXPORT void applyPersistence (const Handle(OpenGl_Context)& theCtx,
0151                                          const Handle(Graphic3d_TransformPers)& theTrsfPersistence,
0152                                          const Standard_Boolean theIsLocal,
0153                                          Standard_Boolean& theOldCastShadows) const;
0154 
0155   //! Restore context from transform persistence changes.
0156   //! @param[in] theCtx current context
0157   //! @param[in] theTrsfPers transform persistence
0158   //! @param[in] theIsLocal specifies if transform persistence is defined locally or to entire presentation
0159   //! @param[in] theOldCastShadows state of the previous cast shadows state
0160   Standard_EXPORT void revertPersistence (const Handle(OpenGl_Context)& theCtx,
0161                                           const Handle(Graphic3d_TransformPers)& theTrsfPersistence,
0162                                           const Standard_Boolean theIsLocal,
0163                                           const Standard_Boolean theOldCastShadows) const;
0164 
0165 protected:
0166 
0167   OpenGl_Structure*          myInstancedStructure;
0168   Graphic3d_Mat4             myRenderTrsf; //!< transformation, actually used for rendering (includes Local Origin shift)
0169 
0170   mutable Standard_Boolean   myIsRaytracable;
0171   mutable Standard_Size      myModificationState;
0172 
0173   Standard_Boolean           myIsMirrored; //!< Used to tell OpenGl to interpret polygons in clockwise order.
0174 
0175 };
0176 
0177 #endif // OpenGl_Structure_Header