]> OCCT Git - occt.git/commitdiff
0028035: Visualization - V3d_Trihedron::compute() endlessly creates new graphic groups
authorkgv <kgv@opencascade.com>
Tue, 1 Nov 2016 12:14:35 +0000 (15:14 +0300)
committerapn <apn@opencascade.com>
Tue, 8 Nov 2016 12:15:16 +0000 (15:15 +0300)
V3d_Trihedron::compute() now reuses existing groups in the structure
and resets the flag myToCompute.

src/OpenGl/OpenGl_View.cxx
src/V3d/V3d_Trihedron.cxx

index af43b672dcbeca6a06ac1003bb4734455d714ea4..c60c68452caa2f2c9b14a36f1b8ce436ae0ccad8 100644 (file)
@@ -493,7 +493,8 @@ void OpenGl_View::InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayer
   }
   else
   {
-    for (Standard_Integer aLayerId = Graphic3d_ZLayerId_Default; aLayerId < ZLayerMax(); ++aLayerId)
+    const Standard_Integer aLayerMax = ZLayerMax();
+    for (Standard_Integer aLayerId = Graphic3d_ZLayerId_Default; aLayerId < aLayerMax; ++aLayerId)
     {
       if (myZLayers.LayerIDs().IsBound (aLayerId))
       {
index ca6e2ada0f35e7834d5470c8a7657e331cca2001..a777e571a22ddc9293b8158765efeab89b26e983 100644 (file)
@@ -40,6 +40,23 @@ namespace
   static const Standard_ShortReal THE_CYLINDER_LENGTH      = 0.75f;
   static const Standard_Integer   THE_CIRCLE_SERMENTS_NB   = 24;
   static const Standard_Real      THE_CIRCLE_SEGMENT_ANGLE = 2.0 * M_PI / THE_CIRCLE_SERMENTS_NB;
+
+  //! Create new or return existing group in the structure at specified position.
+  //! @param theStruct     [in]     structure holding graphic groups
+  //! @param theGroupIndex [in/out] group position, will be incremented as output
+  static Handle(Graphic3d_Group) addGroup (const Handle(Graphic3d_Structure)& theStruct,
+                                           Standard_Integer& theGroupIter)
+  {
+    const Graphic3d_SequenceOfGroup& aGroups = theStruct->Groups();
+    const Standard_Integer aGroupIndex = theGroupIter++;
+    if (!aGroups.IsEmpty()
+      && aGroupIndex <= aGroups.Upper())
+    {
+      return aGroups.Value (aGroupIndex);
+    }
+
+    return theStruct->NewGroup();
+  }
 }
 
 //! Dummy implementation of Graphic3d_Structure overriding ::Compute() method for handling Device Lost.
@@ -203,6 +220,7 @@ void V3d_Trihedron::Display (const V3d_View& theView)
     myStructure->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity();
     myStructure->CStructure()->ViewAffinity->SetVisible (Standard_False);
     myStructure->CStructure()->ViewAffinity->SetVisible (theView.View()->Identification(), true);
+    myToCompute = Standard_True;
   }
   if (myToCompute)
   {
@@ -251,6 +269,7 @@ void V3d_Trihedron::SetPosition (const Aspect_TypeOfTriedronPosition thePosition
 // ============================================================================
 void V3d_Trihedron::compute()
 {
+  myToCompute = Standard_False;
   myStructure->GraphicClear (Standard_False);
 
   // Create trihedron.
@@ -261,8 +280,9 @@ void V3d_Trihedron::compute()
   const Standard_Real aConeLength     = aScale * (1.0 - THE_CYLINDER_LENGTH);
   const Standard_Real aSphereRadius   = aCylinderRadius * 2.0;
   const Standard_Real aRayon          = aScale / 30.0;
+  Standard_Integer aGroupIter = myStructure->Groups().Lower();
   {
-    Handle(Graphic3d_Group) aSphereGroup = myStructure->NewGroup();
+    Handle(Graphic3d_Group) aSphereGroup = addGroup (myStructure, aGroupIter);
 
     // Display origin.
     if (myIsWireframe)
@@ -292,7 +312,7 @@ void V3d_Trihedron::compute()
     const gp_Ax1 anAxes[3] = { gp::OX(), gp::OY(), gp::OZ() };
     for (Standard_Integer anIter = 0; anIter < 3; ++anIter)
     {
-      Handle(Graphic3d_Group) anAxisGroup = myStructure->NewGroup();
+      Handle(Graphic3d_Group) anAxisGroup = addGroup (myStructure, aGroupIter);
       if (myIsWireframe)
       {
         // create a tube
@@ -317,7 +337,7 @@ void V3d_Trihedron::compute()
 
   // Display labels.
   {
-    Handle(Graphic3d_Group) aLabelGroup = myStructure->NewGroup();
+    Handle(Graphic3d_Group) aLabelGroup = addGroup (myStructure, aGroupIter);
     const TCollection_ExtendedString aLabels[3] = { "X", "Y", "Z" };
     const gp_Pnt aPoints[3] = { gp_Pnt (aScale + 2.0 * aRayon,                   0.0,               -aRayon),
                                 gp_Pnt (               aRayon, aScale + 3.0 * aRayon,          2.0 * aRayon),