0024023: Revamp the OCCT Handle -- downcast (automatic)
[occt.git] / src / AIS / AIS_IdenticRelation.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 9378ce0..3b6cbcc
@@ -1,8 +1,18 @@
-// File:       AIS_IdenticRelation.cxx
-// Created:    Mon Mar  3 17:21:37 1997
-// Author:     Jean-Pierre COMBE
-//             <jpr>
-
+// Created on: 1997-03-03
+// Created by: Jean-Pierre COMBE
+// Copyright (c) 1997-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 <Standard_NotImplemented.hxx>
 
@@ -10,7 +20,6 @@
 
 #include <AIS.hxx>
 #include <AIS_Shape.hxx>
-#include <AIS_Drawer.hxx>
 
 #include <BRep_Tool.hxx>
 
@@ -31,6 +40,7 @@
 #include <Select3D_SensitiveCurve.hxx>
 #include <Select3D_SensitiveSegment.hxx>
 #include <SelectMgr_EntityOwner.hxx>
+#include <SelectMgr_Selection.hxx>
 
 #include <TColStd_ListIteratorOfListOfTransient.hxx>
 
@@ -58,8 +68,8 @@
 
 static Standard_Real Modulo2PI(const Standard_Real ANGLE)
 {
-  if ( ANGLE < 0 )          return Modulo2PI(ANGLE + 2*PI);
-  else if ( ANGLE >= 2*PI ) return Modulo2PI(ANGLE - 2*PI);
+  if ( ANGLE < 0 )          return Modulo2PI(ANGLE + 2*M_PI);
+  else if ( ANGLE >= 2*M_PI ) return Modulo2PI(ANGLE - 2*M_PI);
   return ANGLE;
 }
 
@@ -68,7 +78,7 @@ static Standard_Boolean IsEqual2PI(const Standard_Real angle1,
 {
   Standard_Real diff = Abs(angle1-angle2);
   if ( diff < precision )                return Standard_True;
-  else if ( Abs(diff-2*PI) < precision ) return Standard_True;
+  else if ( Abs(diff-2*M_PI) < precision ) return Standard_True;
   return Standard_False;
 }
 // jfa 15/10/2000 end
@@ -187,18 +197,18 @@ static Standard_Boolean ComputeAttach(const gp_Circ& thecirc,
   Standard_Real deltap = pSAttachM - pFAttach;
   if ( deltap < 0 )
     {
-      deltap += 2*Standard_PI;
-      pSAttachM += 2*Standard_PI;
+      deltap += 2 * M_PI;
+      pSAttachM += 2 * M_PI;
     }
   pSAttachM -= pFAttach;
 
-  Standard_Real pmiddleout = pSAttachM/2.0 + Standard_PI;
+  Standard_Real pmiddleout = pSAttachM/2.0 + M_PI;
 
   Standard_Real pcurpos1 = pcurpos;
   // define where curpos lays
   if ( pcurpos1 < pFAttach )
     {
-      pcurpos1 = pcurpos1 + 2*Standard_PI - pFAttach;
+      pcurpos1 = pcurpos1 + 2 * M_PI - pFAttach;
       if ( pcurpos1 > pSAttachM ) // out
        {
          if ( pcurpos1 > pmiddleout ) pcurpos = pFAttach;
@@ -255,18 +265,18 @@ static Standard_Boolean ComputeAttach(const gp_Elips& theEll,
   Standard_Real deltap = pSAttachM - pFAttach;
   if ( deltap < 0 )
     {
-      deltap += 2*Standard_PI;
-      pSAttachM += 2*Standard_PI;
+      deltap += 2 * M_PI;
+      pSAttachM += 2 * M_PI;
     }
   pSAttachM -= pFAttach;
 
-  Standard_Real pmiddleout = pSAttachM/2.0 + Standard_PI;
+  Standard_Real pmiddleout = pSAttachM/2.0 + M_PI;
 
   Standard_Real pcurpos1 = pcurpos;
   // define where curpos lays
   if ( pcurpos1 < pFAttach )
     {
-      pcurpos1 = pcurpos1 + 2*Standard_PI - pFAttach;
+      pcurpos1 = pcurpos1 + 2 * M_PI - pFAttach;
       if ( pcurpos1 > pSAttachM ) // out
        {
          if ( pcurpos1 > pmiddleout ) pcurpos = pFAttach;
@@ -363,21 +373,9 @@ void AIS_IdenticRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
  PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
 }
 
-//=======================================================================
-//function : Compute
-//purpose  : 
-//=======================================================================
-void AIS_IdenticRelation::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager2d, 
-                                 const Handle(Graphic2d_GraphicObject)& aGraphicObject, 
-                                 const Standard_Integer anInteger)
-{
-// Standard_NotImplemented::Raise("AIS_IdenticRelation::Compute(const Handle(PrsMgr_PresentationManager2d)&,const Handle(Graphic2d_GraphicObject)&,const Standard_Integer)");
- PrsMgr_PresentableObject::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ; 
-}
-
-void AIS_IdenticRelation::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
+void AIS_IdenticRelation::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
 {
-// Standard_NotImplemented::Raise("AIS_IdenticRelation::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
+// Standard_NotImplemented::Raise("AIS_IdenticRelation::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
  PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
 }
 
@@ -387,7 +385,7 @@ void AIS_IdenticRelation::Compute(const Handle_Prs3d_Projector& aProjector, cons
 //           "identic" presentation
 // note    : if we are in the case of lines, we create a segment between
 //           myFAttach and mySAttach. In the case of Circles, we create
-//           an arc of circle between the sames points.We Add a segment
+//           an arc of circle between the sames points. We Add a segment
 //           to link Position to its projection on the curve described
 //           before.
 //=======================================================================
@@ -422,7 +420,7 @@ void AIS_IdenticRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aS
 
          if ( isCircle ) // case of Circles
            {
-             Handle(Geom_Circle) thecirc = (Handle(Geom_Circle)&) curv1;
+             Handle(Geom_Circle) thecirc = Handle(Geom_Circle)::DownCast (curv1);
              Standard_Real udeb = ElCLib::Parameter(thecirc->Circ(),myFAttach);
              Standard_Real ufin = ElCLib::Parameter(thecirc->Circ(),mySAttach);
              Handle(Geom_TrimmedCurve) thecu = new Geom_TrimmedCurve(thecirc,udeb,ufin);
@@ -435,7 +433,7 @@ void AIS_IdenticRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aS
            }
          else if ( curv1->IsInstance(STANDARD_TYPE(Geom_Ellipse)) ) // case of ellipses
            {
-             Handle(Geom_Ellipse) theEll = (Handle(Geom_Ellipse)&) curv1;
+             Handle(Geom_Ellipse) theEll = Handle(Geom_Ellipse)::DownCast (curv1);
 
              Standard_Real udeb = ElCLib::Parameter(theEll->Elips(),myFAttach);
              Standard_Real ufin = ElCLib::Parameter(theEll->Elips(),mySAttach);
@@ -452,7 +450,7 @@ void AIS_IdenticRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aS
              seg = new Select3D_SensitiveSegment(own, myFAttach, mySAttach);
              aSelection->Add(seg);
              
-             //attach = projection de Position() sur la curve;
+             //attach = projection of Position() on the curve;
              gp_Vec v1 (myFAttach, mySAttach);
              gp_Vec v2 (myFAttach, myPosition);
              if ( v1.IsParallel(v2, Precision::Angular()) )
@@ -512,17 +510,17 @@ void AIS_IdenticRelation::ComputeTwoEdgesPresentation(const Handle(Prs3d_Present
   if ( curv1->IsInstance(STANDARD_TYPE(Geom_Line)) && curv2->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
     // we take the line curv1 like support
     Handle(Geom_Line) thelin;
-    if (isInfinite1 && !isInfinite2) thelin = (Handle(Geom_Line)&) curv2;
-    else if (!isInfinite1 && isInfinite2) thelin = (Handle(Geom_Line)&) curv1;
-    else thelin = (Handle(Geom_Line)&) curv1;
+    if (isInfinite1 && !isInfinite2) thelin = Handle(Geom_Line)::DownCast (curv2);
+    else if (!isInfinite1 && isInfinite2) thelin = Handle(Geom_Line)::DownCast (curv1);
+    else thelin = Handle(Geom_Line)::DownCast (curv1);
     ComputeTwoLinesPresentation(aPrs, thelin, firstp1, lastp1, firstp2, lastp2, isInfinite1, isInfinite2);
   }
 
   //  Treatement of the case of circles
   else if ( curv1->IsInstance(STANDARD_TYPE(Geom_Circle)) && curv2->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
     //gp_Pnt curpos;
-    isCircle = Standard_True; // usefull for ComputeSelection
-    const Handle(Geom_Circle)& thecirc = (Handle(Geom_Circle)&) curv1;
+    isCircle = Standard_True; // useful for ComputeSelection
+    Handle(Geom_Circle) thecirc (Handle(Geom_Circle)::DownCast (curv1));
     ComputeTwoCirclesPresentation(aPrs, thecirc, firstp1, lastp1, firstp2, lastp2);
   }
 
@@ -530,14 +528,14 @@ void AIS_IdenticRelation::ComputeTwoEdgesPresentation(const Handle(Prs3d_Present
   //  Treatement of the case of ellipses
   else if ( curv1->IsInstance(STANDARD_TYPE(Geom_Ellipse)) && curv2->IsInstance(STANDARD_TYPE(Geom_Ellipse)) )
       {
-       const Handle(Geom_Ellipse)& theEll = (Handle(Geom_Ellipse)&) curv1;
+       Handle(Geom_Ellipse) theEll (Handle(Geom_Ellipse)::DownCast (curv1));
        ComputeTwoEllipsesPresentation(aPrs, theEll, firstp1, lastp1, firstp2, lastp2);
       }
   // jfa 10/10/2000 end
   else
     return;
 
- // Calcul de la presentation des edges projettees
+ // Calculate presentation of projected edges
  if ( (myExtShape != 0) &&  !extCurv.IsNull()) {
    if (myExtShape == 1 )
      ComputeProjEdgePresentation(aPrs, TopoDS::Edge(myFShape), curv1, firstp1, lastp1);
@@ -746,7 +744,7 @@ void AIS_IdenticRelation::ComputeTwoCirclesPresentation(const Handle(Prs3d_Prese
     
   myCenter = thecirc->Location();
   Standard_Real aSegSize = thecirc->Radius()/5.0;
-  Standard_Real rad = Standard_PI/5.0;
+  Standard_Real rad = M_PI / 5.0;
     
   // I. Case of 2 complete circles
   if ( circ1complete && circ2complete )
@@ -984,7 +982,7 @@ void AIS_IdenticRelation::ComputeAutoArcPresentation(const Handle(Geom_Circle)&
                                                     const Standard_Boolean isstatic)
 {
   Standard_Real aSegSize = thecirc->Radius()/5.0;
-  Standard_Real rad = Standard_PI/5.0;
+  Standard_Real rad = M_PI / 5.0;
 
   Standard_Real pFA = ElCLib::Parameter(thecirc->Circ(),firstp);
   Standard_Real pSA = ElCLib::Parameter(thecirc->Circ(),lastp);
@@ -1027,7 +1025,7 @@ void AIS_IdenticRelation::ComputeNotAutoCircPresentation(const Handle(Geom_Circl
       curpos.Translate(vprec*1e-5);
     }
   
-  Standard_Real rad = Standard_PI/5.0;
+  Standard_Real rad = M_PI / 5.0;
   Standard_Real pcurpos = ElCLib::Parameter(cirNotAuto->Circ(),curpos);
   Standard_Real pFAttach = pcurpos - rad;
   Standard_Real pSAttach = pcurpos + rad;
@@ -1055,7 +1053,7 @@ void AIS_IdenticRelation::ComputeNotAutoArcPresentation(const Handle(Geom_Circle
   Standard_Real pSPnt = ElCLib::Parameter(cirNotAuto, pntlast);
   Standard_Real deltap = Modulo2PI(pSPnt - pFPnt)/2.0;
 
-  Standard_Real rad = Standard_PI/5;
+  Standard_Real rad = M_PI / 5;
   if ( deltap < rad )
     {
       myFAttach = pntfirst;
@@ -1101,7 +1099,7 @@ void AIS_IdenticRelation::ComputeTwoEllipsesPresentation(const Handle(Prs3d_Pres
     
   myCenter = theEll->Location();
   Standard_Real aSegSize = theEll->MajorRadius()/5.0;
-  Standard_Real rad = Standard_PI/5.0;
+  Standard_Real rad = M_PI / 5.0;
     
   // I. Case of 2 complete ellipses
   if ( circ1complete && circ2complete )
@@ -1338,7 +1336,7 @@ void AIS_IdenticRelation::ComputeAutoArcPresentation(const Handle(Geom_Ellipse)&
                                                     const Standard_Boolean isstatic)
 {
   Standard_Real aSegSize = theEll->MajorRadius()/5.0;
-  Standard_Real rad = Standard_PI/5.0;
+  Standard_Real rad = M_PI / 5.0;
 
   gp_Elips anEll = theEll->Elips();
   
@@ -1383,7 +1381,7 @@ void AIS_IdenticRelation::ComputeNotAutoElipsPresentation(const Handle(Geom_Elli
       curpos.Translate(vprec*1e-5);
     }
   
-  Standard_Real rad = Standard_PI/5.0;
+  Standard_Real rad = M_PI / 5.0;
 //  Standard_Real pcurpos = ElCLib::Parameter(anEll,curpos);
   GeomAPI_ProjectPointOnCurve aProj (curpos, theEll);
   Standard_Real pcurpos  = aProj.LowerDistanceParameter();
@@ -1414,7 +1412,7 @@ void AIS_IdenticRelation::ComputeNotAutoArcPresentation(const Handle(Geom_Ellips
   Standard_Real pSPnt = ElCLib::Parameter(anEll, pntlast);
   Standard_Real deltap = Modulo2PI(pSPnt - pFPnt)/2.0;
 
-  Standard_Real rad = Standard_PI/5;
+  Standard_Real rad = M_PI / 5;
   if ( deltap < rad )
     {
       myFAttach = pntfirst;
@@ -1479,7 +1477,7 @@ void AIS_IdenticRelation::ComputeTwoVerticesPresentation(const Handle(Prs3d_Pres
       TColStd_ListIteratorOfListOfTransient it(Users());
       if (it.More())
        {
-         const Handle(AIS_Shape)& USER = Handle(AIS_Shape)::DownCast(it.Value());
+         Handle(AIS_Shape) USER (Handle(AIS_Shape)::DownCast(it.Value()));
          if (!USER.IsNull())
            {
              const TopoDS_Shape& SH =USER->Shape();
@@ -1529,7 +1527,7 @@ void AIS_IdenticRelation::ComputeTwoVerticesPresentation(const Handle(Prs3d_Pres
                                  vals,
                                  myFAttach,
                                  curpos);
-  // Calcul de la projection du vertex
+  // Calculate the projection of vertex
   if ( myExtShape == 1)
     ComputeProjVertexPresentation(aPrs,FVertex,myFAttach);
   else if ( myExtShape == 2)
@@ -1551,7 +1549,7 @@ Standard_Real AIS_IdenticRelation::ComputeSegSize() const
 //function : ComputeDirection
 //purpose  : Compute a direction according to the different geometric
 //           elements connected to the vertex <VERT>, in way to not have
-//            overlap between the symbol and them.
+//           overlap between the symbol and them.
 //=======================================================================
 Standard_Boolean AIS_IdenticRelation::ComputeDirection(const TopoDS_Wire& aWire, 
                                                       const TopoDS_Vertex& VERT, 
@@ -1578,19 +1576,19 @@ Standard_Boolean AIS_IdenticRelation::ComputeDirection(const TopoDS_Wire& aWire,
 
     gp_Dir d1, d2;
     if ( curv1->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
-      d1 = ComputeCircleDirection((Handle(Geom_Circle)&) curv1, VERT);
+      d1 = ComputeCircleDirection(Handle(Geom_Circle)::DownCast (curv1), VERT);
     }
     else if (curv1->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
-      d1 = ComputeLineDirection((Handle(Geom_Line)&) curv1, firstp1);
+      d1 = ComputeLineDirection(Handle(Geom_Line)::DownCast (curv1), firstp1);
     }
     else 
       return Standard_False;
     
     if ( curv2->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
-      d2 = ComputeCircleDirection( (Handle(Geom_Circle)&) curv2, VERT);
+      d2 = ComputeCircleDirection( Handle(Geom_Circle)::DownCast (curv2), VERT);
     }
     else if (curv2->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
-      d2 =ComputeLineDirection( (Handle(Geom_Line)&) curv2, firstp2);
+      d2 =ComputeLineDirection( Handle(Geom_Line)::DownCast (curv2), firstp2);
     }
     else 
       return Standard_False;
@@ -1615,10 +1613,10 @@ Standard_Boolean AIS_IdenticRelation::ComputeDirection(const TopoDS_Wire& aWire,
     if ( !AIS::ComputeGeometry(VEdge, curv1, firstp1, lastp1) )
       return Standard_False; 
     if ( curv1->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
-      dF = ComputeCircleDirection( (Handle(Geom_Circle)&) curv1, VERT);
+      dF = ComputeCircleDirection( Handle(Geom_Circle)::DownCast (curv1), VERT);
     }
     else if (curv1->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
-      dF = ComputeLineDirection( (Handle(Geom_Line)&) curv1, firstp1);
+      dF = ComputeLineDirection( Handle(Geom_Line)::DownCast (curv1), firstp1);
     }
     else
       return Standard_False;
@@ -1665,12 +1663,12 @@ void AIS_IdenticRelation::ComputeOneEdgeOVertexPresentation(const Handle(Prs3d_P
   if (myFShape.ShapeType() == TopAbs_VERTEX) {
     V = TopoDS::Vertex(myFShape);
     E = TopoDS::Edge(mySShape);
-    numedge = 2;// edge = 2 iem shape
+    numedge = 2;// edge = 2nd shape
   }
   else {
     V = TopoDS::Vertex(mySShape);
     E   = TopoDS::Edge(myFShape);
-    numedge = 1;  // edge = 1 ere shape
+    numedge = 1;  // edge = 1st shape
   }
   gp_Pnt ptonedge1,ptonedge2;
   Handle(Geom_Curve) aCurve;
@@ -1682,7 +1680,7 @@ void AIS_IdenticRelation::ComputeOneEdgeOVertexPresentation(const Handle(Prs3d_P
   aPrs->SetInfiniteState(isInfinite);
   AIS::ComputeGeometry(V, myFAttach, myPlane, isOnPlanVertex);
 
-  // on considere que seule la courbe peut etre projetee 
+  // only the curve can be projected 
   if (!isOnPlanEdge && !isOnPlanVertex) return;
 
   if (!isOnPlanEdge) {
@@ -1706,16 +1704,16 @@ void AIS_IdenticRelation::ComputeOneEdgeOVertexPresentation(const Handle(Prs3d_P
     // we take the median of the edges connected to vertices
     gp_Dir myDir;
     if ( aCurve->IsKind(STANDARD_TYPE(Geom_Line))) {
-      myDir = ((Handle(Geom_Line)&) aCurve)->Lin().Direction();
+      myDir = Handle(Geom_Line)::DownCast (aCurve)->Lin().Direction();
       myDir.Cross(myPlane->Pln().Axis().Direction());
     }
     else if (aCurve->IsKind(STANDARD_TYPE(Geom_Circle))) {
-      Handle(Geom_Circle) CIR = (Handle(Geom_Circle)&) aCurve;
+      Handle(Geom_Circle) CIR = Handle(Geom_Circle)::DownCast (aCurve);
       myDir.SetXYZ(myFAttach.XYZ() - CIR->Location().XYZ());
     }
     // jfa 10/10/2000
     else if (aCurve->IsKind(STANDARD_TYPE(Geom_Ellipse))) {
-      Handle(Geom_Ellipse) CIR = (Handle(Geom_Ellipse)&) aCurve;
+      Handle(Geom_Ellipse) CIR = Handle(Geom_Ellipse)::DownCast (aCurve);
       myDir.SetXYZ(myFAttach.XYZ() - CIR->Location().XYZ());
     }
     // jfa 10/10/2000 end
@@ -1736,8 +1734,8 @@ void AIS_IdenticRelation::ComputeOneEdgeOVertexPresentation(const Handle(Prs3d_P
                                  myFAttach,
                                  curpos);
   if (myExtShape != 0) {
-    if (!extCurv.IsNull()) { // c'est l'edge qui n'est pas dans le WP
-     ComputeProjEdgePresentation(aPrs,E,(Handle(Geom_Line)&) aCurve,ptonedge1,ptonedge2);
+    if (!extCurv.IsNull()) { // the edge is not in the WP
+     ComputeProjEdgePresentation(aPrs,E,Handle(Geom_Line)::DownCast (aCurve),ptonedge1,ptonedge2);
     }
   }
 }