0029729: Visualization, Graphic3d_ClipPlane - add support of clipping plane chains
[occt.git] / src / Graphic3d / Graphic3d_ClipPlane.cxx
index 1524c94..22ac56c 100755 (executable)
@@ -45,8 +45,11 @@ namespace
 // =======================================================================
 Graphic3d_ClipPlane::Graphic3d_ClipPlane()
 : myAspect     (defaultAspect()),
+  myPrevInChain(NULL),
   myPlane      (0.0, 0.0, 1.0, 0.0),
   myEquation   (0.0, 0.0, 1.0, 0.0),
+  myEquationRev(0.0, 0.0,-1.0, 0.0),
+  myChainLenFwd(1),
   myFlags      (Graphic3d_CappingFlags_None),
   myEquationMod(0),
   myAspectMod  (0),
@@ -60,10 +63,13 @@ Graphic3d_ClipPlane::Graphic3d_ClipPlane()
 // function : Graphic3d_ClipPlane
 // purpose  :
 // =======================================================================
-Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Equation& theEquation)
+Graphic3d_ClipPlane::Graphic3d_ClipPlane (const Graphic3d_Vec4d& theEquation)
 : myAspect     (defaultAspect()),
+  myPrevInChain(NULL),
   myPlane      (theEquation.x(), theEquation.y(), theEquation.z(), theEquation.w()),
   myEquation   (theEquation),
+  myEquationRev(0.0, 0.0,-1.0, 0.0),
+  myChainLenFwd(1),
   myFlags      (Graphic3d_CappingFlags_None),
   myEquationMod(0),
   myAspectMod  (0),
@@ -71,6 +77,7 @@ Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Equation& theEquation)
   myIsCapping  (Standard_False)
 {
   makeId();
+  updateInversedPlane();
 }
 
 // =======================================================================
@@ -80,8 +87,11 @@ Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Equation& theEquation)
 Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther)
 : Standard_Transient(theOther),
   myAspect     (defaultAspect()),
+  myPrevInChain(NULL),
   myPlane      (theOther.myPlane),
   myEquation   (theOther.myEquation),
+  myEquationRev(theOther.myEquationRev),
+  myChainLenFwd(1),
   myFlags      (theOther.myFlags),
   myEquationMod(0),
   myAspectMod  (0),
@@ -98,7 +108,9 @@ Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther)
 // =======================================================================
 Graphic3d_ClipPlane::Graphic3d_ClipPlane(const gp_Pln& thePlane)
 : myAspect     (defaultAspect()),
+  myPrevInChain(NULL),
   myPlane      (thePlane),
+  myChainLenFwd(1),
   myFlags      (Graphic3d_CappingFlags_None),
   myEquationMod(0),
   myAspectMod  (0),
@@ -106,6 +118,7 @@ Graphic3d_ClipPlane::Graphic3d_ClipPlane(const gp_Pln& thePlane)
   myIsCapping  (Standard_False)
 {
   thePlane.Coefficients (myEquation[0], myEquation[1], myEquation[2], myEquation[3]);
+  updateInversedPlane();
   makeId();
 }
 
@@ -113,10 +126,11 @@ Graphic3d_ClipPlane::Graphic3d_ClipPlane(const gp_Pln& thePlane)
 // function : SetEquation
 // purpose  :
 // =======================================================================
-void Graphic3d_ClipPlane::SetEquation (const Equation& theEquation)
+void Graphic3d_ClipPlane::SetEquation (const Graphic3d_Vec4d& theEquation)
 {
   myPlane = gp_Pln (theEquation.x(), theEquation.y(), theEquation.z(), theEquation.w());
   myEquation = theEquation;
+  updateInversedPlane();
   myEquationMod++;
 }
 
@@ -127,10 +141,8 @@ void Graphic3d_ClipPlane::SetEquation (const Equation& theEquation)
 void Graphic3d_ClipPlane::SetEquation (const gp_Pln& thePlane)
 {
   myPlane = thePlane;
-  thePlane.Coefficients (myEquation[0],
-                         myEquation[1],
-                         myEquation[2],
-                         myEquation[3]);
+  thePlane.Coefficients (myEquation[0], myEquation[1], myEquation[2], myEquation[3]);
+  updateInversedPlane();
   myEquationMod++;
 }
 
@@ -140,6 +152,10 @@ void Graphic3d_ClipPlane::SetEquation (const gp_Pln& thePlane)
 // =======================================================================
 void Graphic3d_ClipPlane::SetOn (const Standard_Boolean theIsOn)
 {
+  if (myPrevInChain != NULL)
+  {
+    throw Standard_ProgramError ("Graphic3d_ClipPlane::SetOn() - undefined operation for a plane in Union");
+  }
   myIsOn = theIsOn;
 }
 
@@ -276,3 +292,35 @@ void Graphic3d_ClipPlane::makeId()
   myId = TCollection_AsciiString ("Graphic3d_ClipPlane_") //DynamicType()->Name()
        + TCollection_AsciiString (Standard_Atomic_Increment (&THE_CLIP_PLANE_COUNTER));
 }
+
+// =======================================================================
+// function : updateChainLen
+// purpose  :
+// =======================================================================
+void Graphic3d_ClipPlane::updateChainLen()
+{
+  myChainLenFwd = !myNextInChain.IsNull() ? (myNextInChain->myChainLenFwd + 1) : 1;
+  if (myPrevInChain != NULL)
+  {
+    myPrevInChain->updateChainLen();
+  }
+}
+
+// =======================================================================
+// function : SetChainNextPlane
+// purpose  :
+// =======================================================================
+void Graphic3d_ClipPlane::SetChainNextPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
+{
+  ++myEquationMod;
+  if (!myNextInChain.IsNull())
+  {
+    myNextInChain->myPrevInChain = NULL;
+  }
+  myNextInChain = thePlane;
+  if (!myNextInChain.IsNull())
+  {
+    myNextInChain->myPrevInChain = this;
+  }
+  updateChainLen();
+}