0023872: Remove outdated classes OpenGl_Polygon and OpenGl_Polyline
[occt.git] / src / OpenGl / OpenGl_Structure.cxx
index 8ef32fc..9545e17 100644 (file)
 // purpose or non-infringement. Please see the License for the specific terms
 // and conditions governing the rights and limitations under the License.
 
-
 #include <OpenGl_GlCore11.hxx>
 
 #include <OpenGl_Structure.hxx>
 
-#include <OpenGl_Polyline.hxx>
 #include <OpenGl_Workspace.hxx>
+#include <OpenGl_Vec.hxx>
 #include <OpenGl_View.hxx>
 
 #include <OpenGl_telem_util.hxx>
 
+//! Auxiliary class for bounding box presentation
+class OpenGl_BndBoxPrs : public OpenGl_Element
+{
+
+public:
+
+  //! Main constructor
+  OpenGl_BndBoxPrs (const CALL_DEF_BOUNDBOX& theBndBox)
+  {
+    const float Xm = theBndBox.Pmin.x;
+    const float Ym = theBndBox.Pmin.y;
+    const float Zm = theBndBox.Pmin.z;
+    const float XM = theBndBox.Pmax.x;
+    const float YM = theBndBox.Pmax.y;
+    const float ZM = theBndBox.Pmax.z;
+    myVerts[0]  = OpenGl_Vec3 (Xm, Ym, Zm);
+    myVerts[1]  = OpenGl_Vec3 (Xm, Ym, ZM);
+    myVerts[2]  = OpenGl_Vec3 (Xm, YM, ZM);
+    myVerts[3]  = OpenGl_Vec3 (Xm, YM, Zm);
+    myVerts[4]  = OpenGl_Vec3 (Xm, Ym, Zm);
+    myVerts[5]  = OpenGl_Vec3 (XM, Ym, Zm);
+    myVerts[6]  = OpenGl_Vec3 (XM, Ym, ZM);
+    myVerts[7]  = OpenGl_Vec3 (XM, YM, ZM);
+    myVerts[8]  = OpenGl_Vec3 (XM, YM, Zm);
+    myVerts[9]  = OpenGl_Vec3 (XM, Ym, Zm);
+    myVerts[10] = OpenGl_Vec3 (XM, YM, Zm);
+    myVerts[11] = OpenGl_Vec3 (Xm, YM, Zm);
+    myVerts[12] = OpenGl_Vec3 (Xm, YM, ZM);
+    myVerts[13] = OpenGl_Vec3 (XM, YM, ZM);
+    myVerts[14] = OpenGl_Vec3 (XM, Ym, ZM);
+    myVerts[15] = OpenGl_Vec3 (Xm, Ym, ZM);
+  }
+
+  //! Render presentation
+  virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const
+  {
+    // Apply line aspect
+    const OpenGl_AspectLine*     anAspectLine = theWorkspace->AspectLine (Standard_True);
+    const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture();
+
+    glDisable (GL_LIGHTING);
+    if ((theWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0)
+    {
+      glDepthMask (GL_FALSE);
+    }
+
+    // Use highlight colors
+    glColor3fv ((theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) ? theWorkspace->HighlightColor->rgb : anAspectLine->Color().rgb);
+
+    glEnableClientState (GL_VERTEX_ARRAY);
+    glVertexPointer (3, GL_FLOAT, 0, (GLfloat* )&myVerts);
+    glDrawArrays (GL_LINE_STRIP, 0, 16);
+    glDisableClientState (GL_VERTEX_ARRAY);
+
+    // restore aspects
+    if (!aPrevTexture.IsNull())
+    {
+      theWorkspace->EnableTexture (aPrevTexture);
+    }
+  }
+
+  //! Release graphical resources
+  virtual void Release (const Handle(OpenGl_Context)& )
+  {
+    //
+  }
+
+protected:
+
+  //! Protected destructor
+  virtual ~OpenGl_BndBoxPrs() {}
+
+private:
+
+  OpenGl_Vec3 myVerts[16]; //!< vertices array
+
+public:
+
+  DEFINE_STANDARD_ALLOC
+
+};
 
 /*----------------------------------------------------------------------*/
 
@@ -147,34 +227,8 @@ void OpenGl_Structure::SetHighlightBox (const Handle(OpenGl_Context)& theGlCtx,
   aContextLine.Width    = 1.0f;
   myHighlightBox->SetAspectLine (aContextLine);
 
-#define CALL_MAX_BOUNDBOXSIZE 16
-
-  Graphic3d_Array1OfVertex aPoints (1, CALL_MAX_BOUNDBOXSIZE);
-  const float Xm = theBoundBox.Pmin.x;
-  const float Ym = theBoundBox.Pmin.y;
-  const float Zm = theBoundBox.Pmin.z;
-  const float XM = theBoundBox.Pmax.x;
-  const float YM = theBoundBox.Pmax.y;
-  const float ZM = theBoundBox.Pmax.z;
-  aPoints( 1).SetCoord (Xm, Ym, Zm);
-  aPoints( 2).SetCoord (Xm, Ym, ZM);
-  aPoints( 3).SetCoord (Xm, YM, ZM);
-  aPoints( 4).SetCoord (Xm, YM, Zm);
-  aPoints( 5).SetCoord (Xm, Ym, Zm);
-  aPoints( 6).SetCoord (XM, Ym, Zm);
-  aPoints( 7).SetCoord (XM, Ym, ZM);
-  aPoints( 8).SetCoord (XM, YM, ZM);
-  aPoints( 9).SetCoord (XM, YM, Zm);
-  aPoints(10).SetCoord (XM, Ym, Zm);
-  aPoints(11).SetCoord (XM, YM, Zm);
-  aPoints(12).SetCoord (Xm, YM, Zm);
-  aPoints(13).SetCoord (Xm, YM, ZM);
-  aPoints(14).SetCoord (XM, YM, ZM);
-  aPoints(15).SetCoord (XM, Ym, ZM);
-  aPoints(16).SetCoord (Xm, Ym, ZM);
-
-  OpenGl_Polyline* aPolyline = new OpenGl_Polyline (aPoints);
-  myHighlightBox->AddElement (TelPolyline, aPolyline);
+  OpenGl_BndBoxPrs* aBndBoxPrs = new OpenGl_BndBoxPrs (theBoundBox);
+  myHighlightBox->AddElement (TelParray, aBndBoxPrs);
 }
 
 /*----------------------------------------------------------------------*/