0024837: Visualization - revise design and implementation of connected Interactive...
[occt.git] / src / OpenGl / OpenGl_Structure.hxx
index 04eb21f..d603cea 100644 (file)
@@ -1,27 +1,23 @@
 // Created on: 2011-08-01
 // Created by: Sergey ZERCHANINOV
-// Copyright (c) 2011-2012 OPEN CASCADE SAS
+// Copyright (c) 2011-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 #ifndef OpenGl_Structure_Header
 #define OpenGl_Structure_Header
 
-#include <NCollection_List.hxx>
-#include <InterfaceGraphic_Graphic3d.hxx>
+#include <Graphic3d_CStructure.hxx>
+#include <Graphic3d_SequenceOfHClipPlane.hxx>
 
 #include <OpenGl_AspectLine.hxx>
 #include <OpenGl_AspectFace.hxx>
 #include <OpenGl_Group.hxx>
 #include <OpenGl_Matrix.hxx>
 #include <OpenGl_NamedStatus.hxx>
+#include <OpenGl_Vec.hxx>
+#include <OpenGl_Workspace.hxx>
 
-#include <Graphic3d_SequenceOfHClipPlane.hxx>
+#include <NCollection_List.hxx>
+#include <InterfaceGraphic_Graphic3d.hxx>
 
 class OpenGl_Structure;
+class OpenGl_GraphicDriver;
 
 typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure;
 
-class OpenGl_Structure : public OpenGl_Element
+//! Implementation of low-level graphic structure.
+class OpenGl_Structure : public Graphic3d_CStructure
 {
   friend class OpenGl_Group;
 
 public:
 
-  OpenGl_Structure();
+  //! Auxiliary wrapper to iterate OpenGl_Group sequence.
+  class GroupIterator
+  {
+
+  public:
+    GroupIterator (const Graphic3d_SequenceOfGroup& theGroups) : myIter (theGroups) {}
+    Standard_Boolean More() const     { return myIter.More(); }
+    void Next()                       { myIter.Next(); }
+    const OpenGl_Group* Value() const { return (const OpenGl_Group* )(myIter.Value().operator->()); }
+    OpenGl_Group*       ChangeValue() { return (OpenGl_Group* )(myIter.ChangeValue().operator->()); }
+
+  private:
+    Graphic3d_SequenceOfGroup::Iterator myIter;
+
+  };
+
+public:
+
+  //! Create empty structure
+  Standard_EXPORT OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager);
+
+  //! Setup structure graphic state
+  Standard_EXPORT virtual void UpdateNamedStatus();
+
+  //! Clear graphic data
+  Standard_EXPORT virtual void Clear();
+
+  //! Connect other structure to this one
+  Standard_EXPORT virtual void Connect    (Graphic3d_CStructure& theStructure);
+
+  //! Disconnect other structure to this one
+  Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure);
+
+  //! Synchronize structure aspects
+  Standard_EXPORT virtual void UpdateAspects();
+
+  //! Synchronize structure transformation
+  Standard_EXPORT virtual void UpdateTransformation();
+
+  //! Highlight entire structure with color
+  Standard_EXPORT virtual void HighlightWithColor (const Graphic3d_Vec3&  theColor,
+                                                   const Standard_Boolean theToCreate);
+
+  //! Highlight structure using boundary box
+  Standard_EXPORT virtual void HighlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct,
+                                                    const Standard_Boolean             theToCreate);
+
+  //! Create shadow link to this structure
+  Standard_EXPORT virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const;
 
-  void SetTransformation (const float *AMatrix);
+  //! Create new group within this structure
+  Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct);
+
+  //! Remove group from this structure
+  Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup);
+
+public:
+
+  //! @return graphic groups
+  virtual const Graphic3d_SequenceOfGroup& DrawGroups() const
+  {
+    return myGroups;
+  }
+
+  //! Access graphic driver
+  OpenGl_GraphicDriver* GlDriver() const
+  {
+    return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
+  }
 
   void SetTransformPersistence (const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers);
 
@@ -55,40 +122,59 @@ public:
   void SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect);
   void SetAspectText   (const CALL_DEF_CONTEXTTEXT &theAspect);
 
-  void SetHighlightBox (const Handle(OpenGl_Context)& theGlCtx,
-                        const CALL_DEF_BOUNDBOX& theBoundBox);
+  void clearHighlightBox (const Handle(OpenGl_Context)& theGlCtx);
 
-  void ClearHighlightBox (const Handle(OpenGl_Context)& theGlCtx);
+  void setHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
+                          const Graphic3d_Vec3&         theColor);
 
-  void SetHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
-                          const Standard_ShortReal R,
-                          const Standard_ShortReal G,
-                          const Standard_ShortReal B);
-
-  void ClearHighlightColor (const Handle(OpenGl_Context)& theGlCtx);
-
-  void SetNamedStatus (const Standard_Integer aStatus);
+  void clearHighlightColor (const Handle(OpenGl_Context)& theGlCtx);
 
   Standard_Boolean IsVisible() const { return !(myNamedStatus & OPENGL_NS_HIDE); }
 
-  void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes) { myClipPlanes = thePlanes; }
-
-  void Connect (const OpenGl_Structure *astructure);
-  void Disconnect (const OpenGl_Structure *astructure);
-
-  OpenGl_Group* AddGroup();
-  void RemoveGroup (const Handle(OpenGl_Context)& theGlCtx,
-                    const OpenGl_Group*           theGroup);
-  void Clear (const Handle(OpenGl_Context)& theGlCtx);
+  Standard_EXPORT void Clear (const Handle(OpenGl_Context)& theGlCtx);
 
   //! Set z layer ID to display the structure in specified layer
-  void SetZLayer (const Standard_Integer theLayerIndex);
+  Standard_EXPORT void SetZLayer (const Standard_Integer theLayerIndex);
 
   //! Get z layer ID
-  Standard_Integer GetZLayer () const;
+  Standard_EXPORT Standard_Integer GetZLayer() const;
+
+  //! Renders groups of structure without applying any attributes (i.e. transform, material etc).
+  virtual void RenderGeometry  (const Handle(OpenGl_Workspace)& theWorkspace) const;
 
+  //! Renders the structure.
   virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const;
-  virtual void Release (const Handle(OpenGl_Context)&   theGlCtx);
+
+  //! Releases structure resources.
+  virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
+
+  //! Marks structure as not overlapping view volume (as it is by default).
+  void ResetCullingStatus() const
+  {
+    if (!IsAlwaysRendered())
+    {
+      myIsCulled = Standard_True;
+    }
+  }
+
+  //! Marks structure as overlapping the current view volume one.
+  //! The method is called during traverse of BVH tree.
+  void MarkAsNotCulled() const { myIsCulled = Standard_False; }
+
+  //! Returns Standard_False if the structure hits the current view volume, otherwise
+  //! returns Standard_True. The default value for all structures before each traverse
+  //! of BVH tree is Standard_True.
+  Standard_Boolean IsCulled() const { return myIsCulled; }
+
+  //! Checks if the structure should be included into BVH tree or not.
+  const Standard_Boolean IsAlwaysRendered() const
+  {
+    return IsInfinite
+        || IsForHighlight
+        || IsMutable
+        || Is2dText
+        || TransformPersistence.Flag != 0;
+  }
 
   //! This method releases GL resources without actual elements destruction.
   //! As result structure could be correctly destroyed layer without GL context
@@ -96,10 +182,7 @@ public:
   //!
   //! Notice however that reusage of this structure after calling this method is incorrect
   //! and will lead to broken visualization due to loosed data.
-  void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx);
-
-  //! Returns list of OpenGL groups.
-  const OpenGl_ListOfGroup& Groups() const { return myGroups; }
+  Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx);
 
   //! Returns list of connected OpenGL structures.
   const OpenGl_ListOfStructure& ConnectedStructures() const { return myConnected; }
@@ -113,8 +196,6 @@ public:
   //! Returns OpenGL persistent translation.
   const TEL_TRANSFORM_PERSISTENCE* PersistentTranslation() const { return myTransPers; }
 
-#ifdef HAVE_OPENCL
-
   //! Returns structure modification state (for ray-tracing).
   Standard_Size ModificationState() const { return myModificationState; }
 
@@ -124,13 +205,9 @@ public:
   //! Is the structure ray-tracable (contains ray-tracable elements)?
   Standard_Boolean IsRaytracable() const { return myIsRaytracable; }
 
-#endif
-
 protected:
 
-  virtual ~OpenGl_Structure();
-
-#ifdef HAVE_OPENCL
+  Standard_EXPORT virtual ~OpenGl_Structure();
 
   //! Registers ancestor connected structure (for updating ray-tracing state).
   void RegisterAncestorStructure (const OpenGl_Structure* theStructure) const;
@@ -150,39 +227,35 @@ protected:
   //! Sets ray-tracable status for structure and its parents.
   void SetRaytracableWithAncestorStructures() const;
 
-#endif
-
 protected:
 
-  //Structure_LABBegin
   OpenGl_Matrix*             myTransformation;
   TEL_TRANSFORM_PERSISTENCE* myTransPers;
   OpenGl_AspectLine*         myAspectLine;
   OpenGl_AspectFace*         myAspectFace;
   OpenGl_AspectMarker*       myAspectMarker;
   OpenGl_AspectText*         myAspectText;
-  //Structure_LABHighlight
-  OpenGl_Group*              myHighlightBox;
+
+  Handle(OpenGl_Group)       myHighlightBox;
   TEL_COLOUR*                myHighlightColor;
-  //Structure_LABVisibility
-  //Structure_LABPick
-  int                        myNamedStatus; //Structure_LABNameSet
+
+  int                        myNamedStatus;
   int                        myZLayer;
 
   OpenGl_ListOfStructure           myConnected;
-  OpenGl_ListOfGroup               myGroups;
-  Graphic3d_SequenceOfHClipPlane   myClipPlanes;
 
-#ifdef HAVE_OPENCL
   mutable OpenGl_ListOfStructure   myAncestorStructures;
   mutable Standard_Boolean         myIsRaytracable;
   mutable Standard_Size            myModificationState;
-#endif
+
+  mutable Standard_Boolean         myIsCulled; //!< A status specifying is structure needs to be rendered after BVH tree traverse.
 
 public:
 
-  DEFINE_STANDARD_ALLOC
+  DEFINE_STANDARD_RTTI(OpenGl_Structure) // Type definition
 
 };
 
-#endif //OpenGl_Structure_Header
+DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
+
+#endif // OpenGl_Structure_Header