0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / AIS / AIS_Plane.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 63e6e8c..64fd3e1
@@ -1,51 +1,58 @@
-// File:       AIS_Plane.cxx
-// Created:    Wed Aug  2 16:20:31 1995
-// Author:     Arnaud BOUZY/Odile Olivier
-//             <adn>
-
-#define GER61351               //GG_171199     Enable to set an object RGB color
-//                                               instead a restricted object NameOfColor.
-
-#include <AIS_Plane.ixx>
-
-#include <TColgp_Array1OfPnt.hxx>
-#include <TColgp_HArray1OfPnt.hxx>
-
-#include <Precision.hxx>
-#include <gp_Pnt.hxx>
+// Created on: 1995-08-02
+// Created by: Arnaud BOUZY/Odile Olivier
+// Copyright (c) 1995-1999 Matra Datavision
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// 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.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+
+#include <AIS_InteractiveContext.hxx>
+#include <AIS_Plane.hxx>
+#include <Aspect_TypeOfLine.hxx>
+#include <DsgPrs_ShadedPlanePresentation.hxx>
+#include <DsgPrs_XYZPlanePresentation.hxx>
 #include <ElSLib.hxx>
-
-#include <Graphic3d_Array1OfVertex.hxx>
+#include <Geom_Axis2Placement.hxx>
+#include <Geom_Plane.hxx>
+#include <Geom_Transformation.hxx>
+#include <GeomAdaptor_Surface.hxx>
+#include <gp_Pnt.hxx>
+#include <Graphic3d_ArrayOfQuadrangles.hxx>
+#include <Graphic3d_AspectFillArea3d.hxx>
+#include <Graphic3d_AspectLine3d.hxx>
 #include <Graphic3d_Group.hxx>
+#include <Graphic3d_MaterialAspect.hxx>
+#include <Graphic3d_Structure.hxx>
+#include <Poly_Triangulation.hxx>
+#include <Precision.hxx>
+#include <Prs3d_DatumAspect.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d_LineAspect.hxx>
 #include <Prs3d_PlaneAspect.hxx>
-#include <Prs3d_DatumAspect.hxx>
+#include <Prs3d_Presentation.hxx>
+#include <Prs3d_Projector.hxx>
 #include <Prs3d_ShadingAspect.hxx>
-#include <StdPrs_Plane.hxx>
-#include <StdPrs_ShadedSurface.hxx>
-
-#include <Geom_Plane.hxx>
-#include <GeomAdaptor_Surface.hxx>
-
-#include <Aspect_TypeOfLine.hxx>
-#include <Graphic3d_AspectLine3d.hxx>
-#include <Graphic3d_Structure.hxx>
-#include <Graphic3d_MaterialAspect.hxx>
-#include <Graphic3d_AspectFillArea3d.hxx>
-
-#include <DsgPrs_XYZPlanePresentation.hxx>
-#include <DsgPrs_ShadedPlanePresentation.hxx>
-#include <UnitsAPI.hxx>
-
+#include <Quantity_Color.hxx>
+#include <Select3D_SensitiveTriangulation.hxx>
 #include <SelectBasics_EntityOwner.hxx>
 #include <SelectMgr_EntityOwner.hxx>
-#include <Select3D_SensitiveFace.hxx>
+#include <Standard_Type.hxx>
+#include <StdPrs_Plane.hxx>
 #include <StdPrs_ShadedShape.hxx>
-
-#include <AIS_Drawer.hxx>
-
+#include <StdPrs_ShadedSurface.hxx>
+#include <TColgp_Array1OfPnt.hxx>
+#include <TColgp_HArray1OfPnt.hxx>
 #include <TCollection_AsciiString.hxx>
+#include <UnitsAPI.hxx>
 
 //=======================================================================
 //function : AIS_Plane
@@ -58,7 +65,8 @@ myCenter(gp_Pnt(0.,0.,0.)),
 myCurrentMode(aCurrentMode),
 myAutomaticPosition(Standard_True),
 myTypeOfPlane(AIS_TOPL_Unknown),
-myIsXYZPlane(Standard_False)
+myIsXYZPlane(Standard_False),
+myTypeOfSensitivity (Select3D_TOS_BOUNDARY)
 {
   InitDrawerAttributes();
 }
@@ -75,7 +83,8 @@ myCenter(aCenter),
 myCurrentMode(aCurrentMode),
 myAutomaticPosition(Standard_True),
 myTypeOfPlane(AIS_TOPL_Unknown),
-myIsXYZPlane(Standard_False)
+myIsXYZPlane(Standard_False),
+myTypeOfSensitivity (Select3D_TOS_BOUNDARY)
 {
   InitDrawerAttributes();
 }
@@ -96,7 +105,8 @@ myPmax(aPmax),
 myCurrentMode(aCurrentMode),
 myAutomaticPosition(Standard_False),
 myTypeOfPlane(AIS_TOPL_Unknown),
-myIsXYZPlane(Standard_False)
+myIsXYZPlane(Standard_False),
+myTypeOfSensitivity (Select3D_TOS_BOUNDARY)
 {
   InitDrawerAttributes();
   SetHilightMode(0);
@@ -113,7 +123,8 @@ myAx2(aComponent),
 myCurrentMode(aCurrentMode),
 myAutomaticPosition(Standard_True),
 myTypeOfPlane(aPlaneType),
-myIsXYZPlane(Standard_True)
+myIsXYZPlane(Standard_True),
+myTypeOfSensitivity (Select3D_TOS_BOUNDARY)
 {
   InitDrawerAttributes();
   ComputeFields();
@@ -229,104 +240,115 @@ void AIS_Plane::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
 
   ComputeFields();
   aPresentation->SetInfiniteState(myInfiniteState);
-  if (myCurrentMode) 
-    myDrawer->PlaneAspect()->EdgesAspect()->SetWidth(3);
-  else 
-    myDrawer->PlaneAspect()->EdgesAspect()->SetWidth(1);
-  if(aMode == 0){
-    if (!myIsXYZPlane){
-      ComputeFrame();
-      const Handle(Geom_Plane)& pl = myComponent;
-      const Handle(Geom_Plane)& thegoodpl = Handle(Geom_Plane)::DownCast
-       (pl->Translated(pl->Location(),myCenter));
-      GeomAdaptor_Surface surf(thegoodpl);
-      StdPrs_Plane::Add(aPresentation,surf,myDrawer);
-    }
-    else {
-      DsgPrs_XYZPlanePresentation::Add(aPresentation,myDrawer,myCenter,myPmin,myPmax);
+  myDrawer->PlaneAspect()->EdgesAspect()->SetWidth(myCurrentMode == 0? 1 : 3);
+
+  switch (aMode)
+  {
+    case 0:
+    {
+      if (!myIsXYZPlane)
+      {
+        ComputeFrame();
+        const Handle(Geom_Plane)& pl = myComponent;
+        Handle(Geom_Plane) thegoodpl (Handle(Geom_Plane)::DownCast(pl->Translated(pl->Location(),myCenter)));
+        GeomAdaptor_Surface surf(thegoodpl);
+        StdPrs_Plane::Add(aPresentation,surf,myDrawer);
+      }
+      else
+        DsgPrs_XYZPlanePresentation::Add(aPresentation,myDrawer,myCenter,myPmin,myPmax);
+      break;
     }
-  }
-  else if (aMode == 1){
-    if (!myIsXYZPlane){
-      ComputeFrame();
-      Handle(Prs3d_PlaneAspect) theaspect = myDrawer->PlaneAspect();
-      Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
-      gp_Pnt p1;
-      Standard_Real Xmax,Ymax;
-      Xmax = Standard_Real(theaspect->PlaneXLength())/2.;
-      Ymax = Standard_Real(theaspect->PlaneYLength())/2.;
-      static Graphic3d_Array1OfVertex vertices(1,5);
-      TheGroup->SetPrimitivesAspect(myDrawer->ShadingAspect()->Aspect());
-      myComponent->D0(-Xmax,Ymax,p1);
-      vertices(1).SetCoord(p1.X(),p1.Y(),p1.Z());
-      vertices(5).SetCoord(p1.X(),p1.Y(),p1.Z());
-      myComponent->D0(Xmax,Ymax,p1);
-      vertices(2).SetCoord(p1.X(),p1.Y(),p1.Z());
-      myComponent->D0(Xmax,-Ymax,p1);
-      vertices(3).SetCoord(p1.X(),p1.Y(),p1.Z());
-      myComponent->D0(-Xmax,-Ymax,p1);
-      vertices(4).SetCoord(p1.X(),p1.Y(),p1.Z());
-      TheGroup->Polygon(vertices);
-       
+    case 1:
+    {
+      if (!myIsXYZPlane)
+      {
+        ComputeFrame();
+        Handle(Prs3d_PlaneAspect) theaspect = myDrawer->PlaneAspect();
+        Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
+        TheGroup->SetPrimitivesAspect(myDrawer->ShadingAspect()->Aspect());
+        gp_Pnt p1;
+        const Standard_Real Xmax = 0.5*Standard_Real(theaspect->PlaneXLength());
+        const Standard_Real Ymax = 0.5*Standard_Real(theaspect->PlaneYLength());
+
+        Handle(Graphic3d_ArrayOfQuadrangles) aQuads = new Graphic3d_ArrayOfQuadrangles(4);
+
+        myComponent->D0(-Xmax,Ymax,p1);
+        aQuads->AddVertex(p1);
+        myComponent->D0(Xmax,Ymax,p1);
+        aQuads->AddVertex(p1);
+        myComponent->D0(Xmax,-Ymax,p1);
+        aQuads->AddVertex(p1);
+        myComponent->D0(-Xmax,-Ymax,p1);
+        aQuads->AddVertex(p1);
+
+        TheGroup->AddPrimitiveArray(aQuads);
       }
-    else{
-      DsgPrs_ShadedPlanePresentation::Add(aPresentation,myDrawer,myCenter,myPmin,myPmax);
-      
+      else
+        DsgPrs_ShadedPlanePresentation::Add(aPresentation,myDrawer,myCenter,myPmin,myPmax);
+      break;
     }
   }
-
 }
 
-void AIS_Plane::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
+void AIS_Plane::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
 {
-// Standard_NotImplemented::Raise("AIS_Plane::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
- PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
+  PrsMgr_PresentableObject::Compute(aProjector, aTransformation, aPresentation);
 }
 
 //=======================================================================
 //function : ComputeSelection
 //purpose  : 
 //=======================================================================
-void AIS_Plane::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
-                                   const Standard_Integer)
+void AIS_Plane::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, const Standard_Integer /*theMode*/)
 {
-  aSelection->Clear();
-  Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,10);
-  Handle(Select3D_SensitiveFace) sfac;
-
-  if (!myIsXYZPlane){
-
-    Handle(TColgp_HArray1OfPnt) harr = new TColgp_HArray1OfPnt(1,5);
-    TColgp_Array1OfPnt& arr = harr->ChangeArray1();
-    Standard_Real lx = myDrawer->PlaneAspect()->PlaneXLength()/2.;
-    Standard_Real ly = myDrawer->PlaneAspect()->PlaneYLength()/2.;
-    const Handle(Geom_Plane)& pl = myComponent;
-    const Handle(Geom_Plane)& thegoodpl = Handle(Geom_Plane)::DownCast(pl->Translated(pl->Location(),myCenter));
-    
-    thegoodpl->D0(lx,ly,arr(1));
-    thegoodpl->D0(lx,-ly,arr(2));
-    thegoodpl->D0(-lx,-ly,arr(3));
-    thegoodpl->D0(-lx,ly,arr(4));
-    arr(5) = arr(1);
-    sfac = new Select3D_SensitiveFace(eown,harr,Select3D_TOS_BOUNDARY);
-
+  theSelection->Clear();
+  Handle(SelectMgr_EntityOwner) aSensitiveOwner = new SelectMgr_EntityOwner (this, 10);
+  Handle(Poly_Triangulation) aSensitivePoly;
+
+  if (!myIsXYZPlane)
+  {
+    // plane representing rectangle
+    Standard_Real aLengthX = myDrawer->PlaneAspect()->PlaneXLength() / 2.0;
+    Standard_Real aLengthY = myDrawer->PlaneAspect()->PlaneYLength() / 2.0;
+    Handle(Geom_Plane) aPlane = 
+      Handle(Geom_Plane)::DownCast (myComponent->Translated (myComponent->Location(), myCenter));
+
+    TColgp_Array1OfPnt aRectanglePoints (1, 4);
+    aPlane->D0 ( aLengthX,  aLengthY, aRectanglePoints.ChangeValue (1));
+    aPlane->D0 ( aLengthX, -aLengthY, aRectanglePoints.ChangeValue (2));
+    aPlane->D0 (-aLengthX, -aLengthY, aRectanglePoints.ChangeValue (3));
+    aPlane->D0 (-aLengthX,  aLengthY, aRectanglePoints.ChangeValue (4));
+
+    Poly_Array1OfTriangle aTriangles (1, 2);
+    aTriangles.ChangeValue (1) = Poly_Triangle (1, 2, 3);
+    aTriangles.ChangeValue (2) = Poly_Triangle (1, 3, 4);
+
+    aSensitivePoly = new Poly_Triangulation (aRectanglePoints, aTriangles);
   }
-  else {
-    Handle(TColgp_HArray1OfPnt) harr1 = new TColgp_HArray1OfPnt(1,4);
-    TColgp_Array1OfPnt& arr1 = harr1->ChangeArray1();
-    
-    arr1(1) = myCenter;
-    arr1(2) = myPmin;
-    arr1(3) = myPmax;
-    arr1(4) = myCenter;
-    sfac = new Select3D_SensitiveFace(eown,harr1,Select3D_TOS_BOUNDARY);
-
+  else
+  {
+    // plane representing triangle
+    TColgp_Array1OfPnt aTrianglePoints (1, 3);
+    aTrianglePoints.ChangeValue (1) = myCenter;
+    aTrianglePoints.ChangeValue (2) = myPmin;
+    aTrianglePoints.ChangeValue (3) = myPmax;
+
+    Poly_Array1OfTriangle aTriangles (1, 1);
+    aTriangles.ChangeValue (1) = Poly_Triangle(1, 2, 3);
+
+    aSensitivePoly = new Poly_Triangulation (aTrianglePoints, aTriangles);
   }
-    aSelection->Add(sfac);
-}
 
+  Standard_Boolean isSensitiveInterior = myTypeOfSensitivity == Select3D_TOS_INTERIOR;
 
+  Handle(Select3D_SensitiveTriangulation) aSensitive =
+    new Select3D_SensitiveTriangulation (aSensitiveOwner,
+                                         aSensitivePoly,
+                                         TopLoc_Location(),
+                                         isSensitiveInterior);
 
+  theSelection->Add(aSensitive);
+}
 
 //=======================================================================
 //function : SetSize
@@ -350,10 +372,10 @@ void AIS_Plane::SetSize(const Standard_Real aXLength,
   DA = myDrawer->DatumAspect();
 
   Standard_Boolean yenavaitPA(Standard_True),yenavaitDA(Standard_True);
-  if(myDrawer->Link()->PlaneAspect() == PA){
+  if(myDrawer->HasLink() && myDrawer->Link()->PlaneAspect() == PA){
     yenavaitPA = Standard_False;
     PA = new Prs3d_PlaneAspect();}
-  if(myDrawer->Link()->DatumAspect() == DA){
+  if(myDrawer->HasLink() && myDrawer->Link()->DatumAspect() == DA){
     yenavaitDA = Standard_False;
     DA = new Prs3d_DatumAspect();
   }
@@ -381,13 +403,16 @@ void AIS_Plane::UnsetSize()
 {
   
   if(!myHasOwnSize) return;
-  if(!hasOwnColor){
-    myDrawer->PlaneAspect().Nullify();
-    myDrawer->DatumAspect().Nullify();
+  if(!hasOwnColor)
+  {
+    myDrawer->SetPlaneAspect (Handle(Prs3d_PlaneAspect)());
+    myDrawer->SetDatumAspect (Handle(Prs3d_DatumAspect)());
   }
   else{
-    const Handle(Prs3d_PlaneAspect)& PA = myDrawer->Link()->PlaneAspect();
-    const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
+    const Handle(Prs3d_PlaneAspect) PA = myDrawer->HasLink() ? myDrawer->Link()->PlaneAspect() :
+                                                               new Prs3d_PlaneAspect();
+    const Handle(Prs3d_DatumAspect) DA = myDrawer->HasLink() ? myDrawer->Link()->DatumAspect() :
+                                                               new Prs3d_DatumAspect();
 
     myDrawer->PlaneAspect()->SetPlaneLength(PA->PlaneXLength(),PA->PlaneYLength());
     myDrawer->DatumAspect()->SetAxisLength(DA->FirstAxisLength(),
@@ -421,13 +446,11 @@ Standard_Boolean AIS_Plane::Size(Standard_Real& X,Standard_Real& Y) const
 
 
 void AIS_Plane::SetColor(const Quantity_NameOfColor aCol)
-#ifdef GER61351
 {
   SetColor(Quantity_Color(aCol));
 }
 
 void AIS_Plane::SetColor(const Quantity_Color &aCol)
-#endif
 {
   // if the plane already has its proper size, there is an already created planeaspect 
 //  Standard_Boolean yenadeja = hasOwnColor || myHasOwnSize;
@@ -438,10 +461,10 @@ void AIS_Plane::SetColor(const Quantity_Color &aCol)
   DA = myDrawer->DatumAspect();
 
   Standard_Boolean yenavaitPA(Standard_True),yenavaitDA(Standard_True);
-  if(myDrawer->Link()->PlaneAspect() == PA){
+  if(myDrawer->HasLink() && myDrawer->Link()->PlaneAspect() == PA){
     yenavaitPA = Standard_False;
     PA = new Prs3d_PlaneAspect();}
-  if(myDrawer->Link()->DatumAspect() == DA){
+  if(myDrawer->HasLink() && myDrawer->Link()->DatumAspect() == DA){
     yenavaitDA = Standard_False;
     DA = new Prs3d_DatumAspect();
   }
@@ -468,12 +491,14 @@ void AIS_Plane::SetColor(const Quantity_Color &aCol)
 void AIS_Plane::UnsetColor()
 {
   if(!hasOwnColor) return;
-  if(!myHasOwnSize){
-    myDrawer->PlaneAspect().Nullify();
-    myDrawer->DatumAspect().Nullify();
+  if(!myHasOwnSize)
+  {
+    myDrawer->SetPlaneAspect (Handle(Prs3d_PlaneAspect)());
+    myDrawer->SetDatumAspect (Handle(Prs3d_DatumAspect)());
   }
   else{
-    const Handle(Prs3d_PlaneAspect)& PA = myDrawer->Link()->PlaneAspect();
+    const Handle(Prs3d_PlaneAspect) PA = myDrawer->HasLink() ? myDrawer->Link()->PlaneAspect() :
+                                                               new Prs3d_PlaneAspect();
 //    const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
     Quantity_Color C;Aspect_TypeOfLine T;Standard_Real W;
     PA->EdgesAspect()->Aspect()->Values(C,T,W);
@@ -505,8 +530,7 @@ void AIS_Plane::ComputeFrame()
     pl->D0 (U, V, myCenter);     
   }
   else {
-    const Handle(Geom_Plane)& thegoodpl = 
-      Handle(Geom_Plane)::DownCast(pl->Translated(pl->Location(),myCenter));
+    Handle(Geom_Plane) thegoodpl (Handle(Geom_Plane)::DownCast(pl->Translated(pl->Location(),myCenter)));
     ElSLib::Parameters(thegoodpl->Pln(),myPmin,U,V);
     
     U = 2.4*Abs(U);
@@ -518,16 +542,6 @@ void AIS_Plane::ComputeFrame()
   }
 }
 
-//=======================================================================
-//function : Compute
-//purpose  : to avoid warning
-//=======================================================================
-void AIS_Plane::Compute(const Handle(PrsMgr_PresentationManager2d)&, 
-                          const Handle(Graphic2d_GraphicObject)&,
-                          const Standard_Integer)
-{
-}
-
 //=======================================================================
 //function : Compute
 //purpose  : to avoid warning