0024070: OpenGL capped object-level clipping planes
[occt.git] / src / Graphic3d / Graphic3d_Structure.cxx
index 781c557..702c686 100755 (executable)
@@ -53,8 +53,6 @@
 //      30/11/98 ; FMN : S4069. Textes always visible.
 //      22/03/04 ; SAN : OCC4895 High-level interface for controlling polygon offsets
 
-#define G003    //EUG 26/01/00 Degeneration management
-
 #define BUC60918        //GG 31/05/01 A transparente structure priority must have the
 //                      MAX_PRIORITY value so, the highlighted structure must have
 //                      MAX_PRIORITY-1 value.
@@ -90,7 +88,6 @@
 #include <Graphic3d_Structure.ixx>
 #include <Graphic3d_Structure.pxx>
 
-#include <Graphic3d_GraphicDevice.hxx>
 #include <Graphic3d_GraphicDriver.hxx>
 #include <Graphic3d_MaterialAspect.hxx>
 
 //-Constructors
 
 Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& AManager):
-MyGroupGenId (Group_IDMIN, Group_IDMAX),
 MyAncestors (),
 MyDescendants (),
 MyGroups (),
@@ -171,9 +167,6 @@ MyHighlightColor (Quantity_NOC_WHITE)
   MyCStructure.IsInfinite         = 0,
   MyCStructure.HLRValidation      = 0;
 
-  MyCStructure.GroupBegin = Structure_GROUPBEGIN;
-  MyCStructure.GroupEnd   = Structure_GROUPEND;
-
   MyCStructure.ContextLine.IsDef         = 1,
   MyCStructure.ContextFillArea.IsDef     = 1,
   MyCStructure.ContextMarker.IsDef       = 1,
@@ -195,11 +188,8 @@ MyHighlightColor (Quantity_NOC_WHITE)
   MyCStructure.TransformPersistence.Point.y = 0.0;
   MyCStructure.TransformPersistence.Point.z = 0.0;
   /* ABD 29/10/04  Transform Persistence of Presentation( pan, zoom, rotate ) */
-  Handle(Aspect_GraphicDriver) agd =
-    (AManager->GraphicDevice ())->GraphicDriver ();
-
-  MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd;
 
+  MyGraphicDriver = AManager->GraphicDriver();
   MyGraphicDriver->Structure (MyCStructure);
 
 #ifdef TRACE
@@ -236,10 +226,7 @@ void Graphic3d_Structure::Clear (const Standard_Boolean WithDestruction)
 
   // only then remove group references
   if (WithDestruction)
-  {
-    MyGroupGenId.Free();
     MyGroups.Clear();
-  }
 
   MyStructureManager->Clear (this, WithDestruction);
 
@@ -726,12 +713,6 @@ void Graphic3d_Structure::GraphicClear (const Standard_Boolean WithDestruction)
 
   if (WithDestruction)
   {
-    /*
-    * void Prs3d_Presentation::Clear () {
-    *   Graphic3d_Structure::Clear ();
-    *   myCurrentGroup = new Graphic3d_Group (this);
-    * }
-    */
     while (!MyGroups.IsEmpty())
     {
       Handle(Graphic3d_Group) aGroup = MyGroups.First();
@@ -742,18 +723,14 @@ void Graphic3d_Structure::GraphicClear (const Standard_Boolean WithDestruction)
   }
 }
 
-void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& ADaughter) {
-
-  MyGraphicDriver->Connect
-    (MyCStructure, *((CALL_DEF_STRUCTURE *)ADaughter->CStructure()));
-
+void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter)
+{
+  MyGraphicDriver->Connect (MyCStructure, theDaughter->MyCStructure);
 }
 
-void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& ADaughter) {
-
-  MyGraphicDriver->Disconnect
-    (MyCStructure, *((CALL_DEF_STRUCTURE *)ADaughter->CStructure()));
-
+void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter)
+{
+  MyGraphicDriver->Disconnect (MyCStructure, theDaughter->MyCStructure);
 }
 
 Handle(Graphic3d_AspectLine3d) Graphic3d_Structure::Line3dAspect () const {
@@ -818,7 +795,7 @@ Handle(Graphic3d_AspectMarker3d) Graphic3d_Structure::Marker3dAspect () const {
   G       = Standard_Real (MyCStructure.ContextMarker.Color.g);
   B       = Standard_Real (MyCStructure.ContextMarker.Color.b);
   AColor.SetValues (R, G, B, Quantity_TOC_RGB);
-  AMType  = Aspect_TypeOfMarker (MyCStructure.ContextMarker.MarkerType);
+  AMType  = MyCStructure.ContextMarker.MarkerType;
   AScale  = Standard_Real (MyCStructure.ContextMarker.Scale);
 
   Handle(Graphic3d_AspectMarker3d) CTXM =
@@ -996,20 +973,15 @@ Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT;
   else
     CTXF->AllowBackFace ();
   // Texture
-  // Pb sur les textures
-  //if (MyCStructure.ContextFillArea.Texture.TexId == -1)
-  //else
+  CTXF->SetTextureMap (MyCStructure.ContextFillArea.Texture.TextureMap);
   if (MyCStructure.ContextFillArea.Texture.doTextureMap == 1)
-    CTXF->SetTextureMapOn ();
+  {
+    CTXF->SetTextureMapOn();
+  }
   else
-    CTXF->SetTextureMapOff ();
-#ifdef G003
-  Aspect_TypeOfDegenerateModel dMode = Aspect_TypeOfDegenerateModel(
-    MyCStructure.ContextFillArea.DegenerationMode);
-  Quantity_Ratio dRatio =
-    MyCStructure.ContextFillArea.SkipRatio;
-  CTXF->SetDegenerateModel(dMode,dRatio);
-#endif  // G003
+  {
+    CTXF->SetTextureMapOff();
+  }
 
   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
   CTXF->SetPolygonOffsets(MyCStructure.ContextFillArea.PolygonOffsetMode,
@@ -1100,12 +1072,6 @@ void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFill
   MyCStructure.ContextFillArea.LineType           = int (ALType);
   MyCStructure.ContextFillArea.Width              = float (AWidth);
   MyCStructure.ContextFillArea.Hatch              = int (CTX->HatchStyle ());
-#ifdef G003
-  Quantity_Ratio ratio;
-  MyCStructure.ContextFillArea.DegenerationMode =
-    int (CTX->DegenerateModel(ratio));
-  MyCStructure.ContextFillArea.SkipRatio = float (ratio);
-#endif  // G003
 
   /*** Front and Back face ***/
   MyCStructure.ContextFillArea.Distinguish        = CTX->Distinguish () ? 1:0;
@@ -1245,27 +1211,19 @@ void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFill
 
   MyCStructure.ContextFillArea.IsDef      = 1; // Definition material ok
 
-  Handle(Graphic3d_TextureMap) TempTextureMap = CTX->TextureMap();
-  if (! TempTextureMap.IsNull() )
-    MyCStructure.ContextFillArea.Texture.TexId = TempTextureMap->TextureId();
-  else
-    MyCStructure.ContextFillArea.Texture.TexId = -1;
-
-  MyCStructure.ContextFillArea.Texture.doTextureMap = CTX->TextureMapState() ? 1:0;
+  MyCStructure.ContextFillArea.Texture.TextureMap   = CTX->TextureMap();
+  MyCStructure.ContextFillArea.Texture.doTextureMap = CTX->TextureMapState() ? 1 : 0;
 
   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
   Standard_Integer aPolyMode;
   Standard_ShortReal    aPolyFactor, aPolyUnits;
   CTX->PolygonOffsets(aPolyMode, aPolyFactor, aPolyUnits);
   MyCStructure.ContextFillArea.PolygonOffsetMode   = aPolyMode;
-  MyCStructure.ContextFillArea.PolygonOffsetFactor = aPolyFactor;
-  MyCStructure.ContextFillArea.PolygonOffsetUnits  = aPolyUnits;
+  MyCStructure.ContextFillArea.PolygonOffsetFactor = (Standard_ShortReal)aPolyFactor;
+  MyCStructure.ContextFillArea.PolygonOffsetUnits  = (Standard_ShortReal)aPolyUnits;
   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
 
   MyGraphicDriver->ContextStructure (MyCStructure);
-#ifdef G003
-  MyGraphicDriver -> DegenerateStructure (MyCStructure);
-#endif
 
   // CAL 14/04/95
   // Attributes are "IsSet" during the first update
@@ -1313,7 +1271,7 @@ void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectText
   MyCStructure.ContextText.ColorSubTitle.b  = float (Bs);
   MyCStructure.ContextText.TextZoomable     = ATextZoomable;
   MyCStructure.ContextText.TextAngle        = float (ATextAngle);
-  MyCStructure.ContextText.TextFontAspect   = (int)ATextFontAspect;
+  MyCStructure.ContextText.TextFontAspect   = int (ATextFontAspect);
 
   MyCStructure.ContextText.IsDef          = 1;
 
@@ -1345,7 +1303,7 @@ void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectMark
   MyCStructure.ContextMarker.Color.r      = float (R);
   MyCStructure.ContextMarker.Color.g      = float (G);
   MyCStructure.ContextMarker.Color.b      = float (B);
-  MyCStructure.ContextMarker.MarkerType   = int (AMType);
+  MyCStructure.ContextMarker.MarkerType   = AMType;
   MyCStructure.ContextMarker.Scale        = float (AScale);
   MyCStructure.ContextMarker.IsDef        = 1;
 
@@ -1750,13 +1708,6 @@ void Graphic3d_Structure::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin
   }
 }
 
-void Graphic3d_Structure::GroupLabels (Standard_Integer& LB, Standard_Integer& LE) {
-
-  LB      = MyGroupGenId.Next ();
-  LE      = MyGroupGenId.Next ();
-
-}
-
 Standard_Integer Graphic3d_Structure::Identification () const {
 
   Standard_Integer Result = MyCStructure.Id;
@@ -1849,20 +1800,14 @@ void Graphic3d_Structure::Remove (const Standard_Address APtr, const Graphic3d_T
 
 void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& AGroup) {
 
-  Standard_Integer index = 0;
-  Standard_Integer Length = MyGroups.Length ();
-  for (Standard_Integer i=1; i<=Length && index==0; i++)
-    if (MyGroups.Value (i) == AGroup) index = i;
-
+  const Standard_Integer Length = MyGroups.Length ();
   // Search in Groups
-  if (index != 0) {
-    Standard_Integer GroupLabelBegin, GroupLabelEnd;
-    AGroup->Labels (GroupLabelBegin, GroupLabelEnd);
-    MyGroupGenId.Free (GroupLabelBegin);
-    MyGroupGenId.Free (GroupLabelEnd);
-    MyGroups.Remove (index);
-  }
-
+  for (Standard_Integer i=1; i<=Length; i++)
+    if (MyGroups.Value (i) == AGroup)
+    {
+      MyGroups.Remove (i);
+      return;
+    }
 }
 
 Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager () const {
@@ -1894,11 +1839,11 @@ void Graphic3d_Structure::MinMaxCoord (Standard_Real& XMin, Standard_Real& YMin,
           (MyGroups.Value (i))->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM);
           Graphic3d_Vertex vertex1(Xm, Ym, Zm);
           Graphic3d_Vertex vertex2(XM, YM, ZM);
-          Standard_Real distance = vertex1.Distance( vertex1,vertex2 );
+          const Standard_Real distance = vertex1.Distance( vertex2 );
           if( distance >= 500000.0){
-            XMin = XMax = (Xm+ XM)/2.0;
-            YMin = YMax = (Ym+ YM)/2.0;
-            ZMin = ZMax = (Zm+ ZM)/2.0;
+            XMin = XMax = 0.5*(Xm+ XM);
+            YMin = YMax = 0.5*(Ym+ YM);
+            ZMin = ZMax = 0.5*(Zm+ ZM);
             return;
           }
         }
@@ -2131,7 +2076,7 @@ void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)&
   MyCStructure.ContextMarker.Color.r      = float (R);
   MyCStructure.ContextMarker.Color.g      = float (G);
   MyCStructure.ContextMarker.Color.b      = float (B);
-  MyCStructure.ContextMarker.MarkerType   = int (AMType);
+  MyCStructure.ContextMarker.MarkerType   = AMType;
   MyCStructure.ContextMarker.Scale        = float (AScale);
 
   CTXT->Values (AColor, AFont, AnExpansion, ASpace,AStyleT,ADisplayType,AColorSubTitle,ATextZoomable,ATextAngle,ATextFontAspect);
@@ -2151,7 +2096,7 @@ void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)&
   MyCStructure.ContextText.ColorSubTitle.b  = float (Bs);
   MyCStructure.ContextText.TextZoomable     = ATextZoomable;
   MyCStructure.ContextText.TextAngle        = float (ATextAngle);
-  MyCStructure.ContextText.TextFontAspect   = (int)ATextFontAspect;
+  MyCStructure.ContextText.TextFontAspect   = int (ATextFontAspect);
 
 
 
@@ -2179,13 +2124,6 @@ void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)&
   MyCStructure.ContextFillArea.LineType           = int (ALType);
   MyCStructure.ContextFillArea.Width              = float (AWidth);
   MyCStructure.ContextFillArea.Hatch              = int (CTXF->HatchStyle ());
-#ifdef G003
-  Quantity_Ratio ratio;
-  MyCStructure.ContextFillArea.DegenerationMode =
-    int (CTXF->DegenerateModel(ratio));
-  MyCStructure.ContextFillArea.SkipRatio = float (ratio);
-#endif  // G003
-
 
   /*** Front and Back face ***/
   MyCStructure.ContextFillArea.Distinguish = CTXF->Distinguish () ? 1:0;
@@ -2322,21 +2260,16 @@ void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)&
   MyCStructure.ContextFillArea.Front.EnvReflexion =
     float ((CTXF->FrontMaterial ()).EnvReflexion());
 
-  Handle(Graphic3d_TextureMap) TempTextureMap = CTXF->TextureMap();
-  if (! TempTextureMap.IsNull() )
-    MyCStructure.ContextFillArea.Texture.TexId = TempTextureMap->TextureId();
-  else
-    MyCStructure.ContextFillArea.Texture.TexId = -1;
-
-  MyCStructure.ContextFillArea.Texture.doTextureMap = CTXF->TextureMapState() ? 1:0;
+  MyCStructure.ContextFillArea.Texture.TextureMap   = CTXF->TextureMap();
+  MyCStructure.ContextFillArea.Texture.doTextureMap = CTXF->TextureMapState() ? 1 : 0;
 
   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
   Standard_Integer aPolyMode;
   Standard_ShortReal    aPolyFactor, aPolyUnits;
   CTXF->PolygonOffsets(aPolyMode, aPolyFactor, aPolyUnits);
   MyCStructure.ContextFillArea.PolygonOffsetMode   = aPolyMode;
-  MyCStructure.ContextFillArea.PolygonOffsetFactor = aPolyFactor;
-  MyCStructure.ContextFillArea.PolygonOffsetUnits  = aPolyUnits;
+  MyCStructure.ContextFillArea.PolygonOffsetFactor = (Standard_ShortReal)aPolyFactor;
+  MyCStructure.ContextFillArea.PolygonOffsetUnits  = (Standard_ShortReal)aPolyUnits;
   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
 }
 
@@ -2445,8 +2378,14 @@ void Graphic3d_Structure::Plot (const Handle(Graphic3d_Plotter)& ) {
 
 }
 
-void Graphic3d_Structure::SetManager (const Handle(Graphic3d_StructureManager)& AManager, const Standard_Boolean WithPropagation) {
+void Graphic3d_Structure::SetManager (const Handle(Graphic3d_StructureManager)& AManager, 
+                                      const Standard_Boolean 
+                                      #ifdef IMPLEMENTED
+                                        WithPropagation
+                                      #endif
+                                      )
 
+{
   // All connected structures should follow ?
 #ifdef IMPLEMENTED
   if (WithPropagation) {
@@ -2517,17 +2456,19 @@ Standard_Boolean Graphic3d_Structure::HLRValidation () const {
 
 }
 
-Standard_Address Graphic3d_Structure::CStructure () const {
-
-  return Standard_Address (&MyCStructure);
-
+//=======================================================================
+//function : CStructure
+//purpose  :
+//=======================================================================
+Graphic3d_CStructure* Graphic3d_Structure::CStructure()
+{
+  return &MyCStructure;
 }
 
 //=======================================================================
 //function : SetZLayer
 //purpose  :
 //=======================================================================
-
 void Graphic3d_Structure::SetZLayer (const Standard_Integer theLayerId)
 {
   // if the structure is not displayed, unable to change its display layer
@@ -2541,8 +2482,26 @@ void Graphic3d_Structure::SetZLayer (const Standard_Integer theLayerId)
 //function : GetZLayer
 //purpose  :
 //=======================================================================
-
 Standard_Integer Graphic3d_Structure::GetZLayer () const
 {
   return MyStructureManager->GetZLayer (this);
 }
+
+//=======================================================================
+//function : SetClipPlanes
+//purpose  :
+//=======================================================================
+void Graphic3d_Structure::SetClipPlanes (const Graphic3d_SetOfHClipPlane& thePlanes)
+{
+  MyCStructure.ClipPlanes = thePlanes;
+  MyGraphicDriver->SetClipPlanes (MyCStructure);
+}
+
+//=======================================================================
+//function : GetClipPlanes
+//purpose  :
+//=======================================================================
+const Graphic3d_SetOfHClipPlane& Graphic3d_Structure::GetClipPlanes() const
+{
+  return MyCStructure.ClipPlanes;
+}