0024023: Revamp the OCCT Handle -- general
[occt.git] / src / V3d / V3d_Plane.cxx
index 64d55ed..6d45440 100755 (executable)
 // Created by: GG
 // Copyright (c) 1991-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
+// Copyright (c) 1999-2013 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.
-
-
-
-//-Version
-
-//-Design
-
-//-Warning
-
-//-References
-
-//-Language     C++ 2.1
-
-#include <V3d.hxx>
-#include <V3d_Plane.ixx>
-#include <Viewer_BadValue.hxx>
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
+#include <V3d_Plane.hxx>
 #include <Graphic3d_Group.hxx>
-#include <Graphic3d_ArrayOfQuadrangles.hxx>
 #include <Graphic3d_AspectFillArea3d.hxx>
+#include <Graphic3d_ArrayOfQuadrangles.hxx>
+#include <Visual3d_ViewManager.hxx>
 #include <gp_Pln.hxx>
 
-//-Constructors
 
-V3d_Plane::V3d_Plane(const Standard_Real A, const Standard_Real B, const Standard_Real C, const Standard_Real D)
+// =======================================================================
+// function : V3d_Plane
+// purpose  :
+// =======================================================================
+V3d_Plane::V3d_Plane (const Standard_Real theA,
+                      const Standard_Real theB,
+                      const Standard_Real theC,
+                      const Standard_Real theD)
+: myGraphicStructure(),
+  myPlane (new Graphic3d_ClipPlane (gp_Pln (theA, theB, theC, theD)))
 {
-  Viewer_BadValue_Raise_if( sqrt(A*A + B*B + C*C) <= 0., "V3d_Plane::V3d_Plane, bad plane coefficients");
-
-  MyPlane = new Visual3d_ClipPlane(A,B,C,D) ;
 }
 
-//-Methods, in order
-
-void V3d_Plane::SetPlane(const Standard_Real A, const Standard_Real B, const Standard_Real C, const Standard_Real D)
+// =======================================================================
+// function : V3d_Plane
+// purpose  :
+// =======================================================================
+void V3d_Plane::SetPlane (const Standard_Real theA,
+                          const Standard_Real theB,
+                          const Standard_Real theC,
+                          const Standard_Real theD)
 {
-  Viewer_BadValue_Raise_if( sqrt(A*A + B*B + C*C) <= 0., "V3d_Plane::SetPlane, bad plane coefficients");
-
-  MyPlane->SetPlane(A,B,C,D) ;
-  if( IsDisplayed() )
+  myPlane->SetEquation (gp_Pln (theA, theB, theC, theD));
+  if (IsDisplayed())
+  {
     Update();
+  }
 }
 
-void V3d_Plane::Display(const Handle(V3d_View)& aView,
-                        const Quantity_Color& aColor)
+// =======================================================================
+// function : Display
+// purpose  :
+// =======================================================================
+void V3d_Plane::Display (const Handle(V3d_View)& theView,
+                         const Quantity_Color& theColor)
 {
-  Handle(V3d_Viewer) theViewer = aView->Viewer();
-  if (!MyGraphicStructure.IsNull())
-    MyGraphicStructure->Clear();
+  Handle(V3d_Viewer) aViewer = theView->Viewer();
+  if (!myGraphicStructure.IsNull())
+  {
+    myGraphicStructure->Clear();
+  }
 
-  MyGraphicStructure = new Graphic3d_Structure(theViewer->Viewer());
-  Handle(Graphic3d_Group) group = new Graphic3d_Group(MyGraphicStructure);
-  Handle(Graphic3d_AspectFillArea3d) aspect = new Graphic3d_AspectFillArea3d();
-  Graphic3d_MaterialAspect plastic(Graphic3d_NOM_PLASTIC);
-  plastic.SetColor(aColor);
-  plastic.SetTransparency(0.5);
-  aView->SetTransparency(Standard_True);
-  aspect->SetFrontMaterial(plastic);
-  aspect->SetInteriorStyle (Aspect_IS_HATCH);
-  aspect->SetHatchStyle (Aspect_HS_GRID_DIAGONAL_WIDE);
-  MyGraphicStructure->SetPrimitivesAspect(aspect);
+  myGraphicStructure = new Graphic3d_Structure (aViewer->Viewer());
+  Handle(Graphic3d_Group)            aGroup = myGraphicStructure->NewGroup();
+  Handle(Graphic3d_AspectFillArea3d) anAsp  = new Graphic3d_AspectFillArea3d();
+  Graphic3d_MaterialAspect aPlastic (Graphic3d_NOM_PLASTIC);
+  aPlastic.SetColor (theColor);
+  aPlastic.SetTransparency (0.5);
+  anAsp->SetFrontMaterial (aPlastic);
+  anAsp->SetInteriorStyle (Aspect_IS_HATCH);
+  anAsp->SetHatchStyle (Aspect_HS_GRID_DIAGONAL_WIDE);
+  myGraphicStructure->SetPrimitivesAspect (anAsp);
 
-  const Standard_ShortReal size = (Standard_ShortReal)(0.5*theViewer->DefaultViewSize());
-  const Standard_ShortReal offset = size/5000.F;
+  const Standard_ShortReal aSize = (Standard_ShortReal)(0.5*aViewer->DefaultViewSize());
+  const Standard_ShortReal anOffset = aSize/5000.0f;
 
   Handle(Graphic3d_ArrayOfQuadrangles) aPrims = new Graphic3d_ArrayOfQuadrangles(4);
-  aPrims->AddVertex(-size,-size,offset);
-  aPrims->AddVertex(-size, size,offset);
-  aPrims->AddVertex( size, size,offset);
-  aPrims->AddVertex( size,-size,offset);
-  group->AddPrimitiveArray(aPrims);
-
-  MyGraphicStructure->Display(0);
+  aPrims->AddVertex (-aSize,-aSize, anOffset);
+  aPrims->AddVertex (-aSize, aSize, anOffset);
+  aPrims->AddVertex ( aSize, aSize, anOffset);
+  aPrims->AddVertex ( aSize,-aSize, anOffset);
+  aGroup->AddPrimitiveArray(aPrims);
+
+  myGraphicStructure->SetDisplayPriority (0);
+  myGraphicStructure->Display();
   Update();
 }
 
+// =======================================================================
+// function : Erase
+// purpose  :
+// =======================================================================
 void V3d_Plane::Erase()
 {
-  if (!MyGraphicStructure.IsNull()) MyGraphicStructure->Erase();
-}
-
-void V3d_Plane::Plane(Standard_Real& A, Standard_Real& B, Standard_Real& C, Standard_Real& D) const
-{
-  MyPlane->Plane(A,B,C,D) ;
+  if (!myGraphicStructure.IsNull())
+  {
+    myGraphicStructure->Erase();
+  }
 }
 
-Handle(Visual3d_ClipPlane) V3d_Plane::Plane()const
+// =======================================================================
+// function : Plane
+// purpose  :
+// =======================================================================
+void V3d_Plane::Plane (Standard_Real& theA, Standard_Real& theB, Standard_Real& theC, Standard_Real& theD) const
 {
-  return MyPlane;
+  const Graphic3d_ClipPlane::Equation& anEquation = myPlane->GetEquation();
+  theA = anEquation[0];
+  theB = anEquation[1];
+  theC = anEquation[2];
+  theD = anEquation[3];
 }
 
+// =======================================================================
+// function : IsDisplayed
+// purpose  :
+// =======================================================================
 Standard_Boolean V3d_Plane::IsDisplayed() const
 {
-  if( MyGraphicStructure.IsNull() ) return Standard_False;
-  return MyGraphicStructure->IsDisplayed();
+  if (myGraphicStructure.IsNull())
+  {
+    return Standard_False;
+  }
+
+  return myGraphicStructure->IsDisplayed();
 }
 
+// =======================================================================
+// function : Update
+// purpose  :
+// =======================================================================
 void V3d_Plane::Update()
 {
-  if( !MyGraphicStructure.IsNull() ) {
-    TColStd_Array2OfReal matrix(1,4,1,4);
-    Standard_Real A,B,C,D;
-    MyPlane->Plane(A,B,C,D) ;
-    gp_Pln plan(A,B,C,D);
-    gp_Trsf trsf;
-    trsf.SetTransformation(plan.Position());
-    trsf.Invert();
-    for (Standard_Integer i=1; i<=3; i++){
-      for (Standard_Integer j=1; j<=4; j++){
-        matrix.SetValue(i,j,trsf.Value(i,j));
+  if(!myGraphicStructure.IsNull())
+  {
+    TColStd_Array2OfReal aMatrix (1, 4, 1, 4);
+    Standard_Real theA, theB, theC, theD;
+    this->Plane(theA, theB, theC, theD);
+    gp_Pln aGeomPln (theA, theB, theC, theD);
+    gp_Trsf aTransform;
+    aTransform.SetTransformation (aGeomPln.Position());
+    aTransform.Invert();
+    for (Standard_Integer i = 1; i <= 3; i++)
+    {
+      for (Standard_Integer j = 1; j <= 4; j++)
+      {
+        aMatrix.SetValue (i, j, aTransform.Value (i,j));
       }
     }
-    matrix.SetValue(4,1,0.);
-    matrix.SetValue(4,2,0.);
-    matrix.SetValue(4,3,0.);
-    matrix.SetValue(4,4,1.);
-    MyGraphicStructure->SetTransform(matrix,Graphic3d_TOC_REPLACE);
+
+    aMatrix.SetValue (4,1,0.);
+    aMatrix.SetValue (4,2,0.);
+    aMatrix.SetValue (4,3,0.);
+    aMatrix.SetValue (4,4,1.);
+    myGraphicStructure->SetTransform (aMatrix, Graphic3d_TOC_REPLACE);
   }
 }