Salome HOME
Issue #2876: Fix synchronization of objects display on module activation
[modules/shaper.git] / src / GeomAPI / GeomAPI_Face.cpp
index 89e39adfe2cdc3bce1b9740af4983182ac5c5bb6..c17fe87d3ec243f47aa5fd42269f5047be7c1514 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "GeomAPI_Face.h"
@@ -31,6 +30,7 @@
 #include <BOPTools_AlgoTools.hxx>
 #include <BRep_Tool.hxx>
 #include <BRepAdaptor_Surface.hxx>
+#include <BRepGProp_Face.hxx>
 #include <BRepTools.hxx>
 #include <Geom_Surface.hxx>
 #include <Geom_SphericalSurface.hxx>
@@ -97,9 +97,9 @@ bool GeomAPI_Face::isEqual(std::shared_ptr<GeomAPI_Shape> theFace) const
     return false;
 
   Handle(IntTools_Context) aContext = new IntTools_Context();
-  // Double check needed bacause BOPTools_AlgoTools::CheckSameGeom not very smart.
-  Standard_Boolean aRes = BOPTools_AlgoTools::CheckSameGeom(aMyFace, aInFace, aContext)
-    && BOPTools_AlgoTools::CheckSameGeom(aInFace, aMyFace, aContext);
+  // Double check needed because BOPTools_AlgoTools::AreFacesSameDomain not very smart.
+  Standard_Boolean aRes = BOPTools_AlgoTools::AreFacesSameDomain(aMyFace, aInFace, aContext)
+    && BOPTools_AlgoTools::AreFacesSameDomain(aInFace, aMyFace, aContext);
 
   return aRes == Standard_True;
 }
@@ -195,15 +195,17 @@ std::shared_ptr<GeomAPI_Cone> GeomAPI_Face::getCone() const
   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
   if (aSurf->IsKind(STANDARD_TYPE(Geom_ConicalSurface))) {
     gp_Cone aCon = Handle(Geom_ConicalSurface)::DownCast(aSurf)->Cone();
-    const gp_Pnt& aLoc = aCon.Location();
-    const gp_Dir& aDir = aCon.Position().Direction();
-    double aRadius1 = aCon.RefRadius();
+    gp_Pnt aLoc = aCon.Location();
+    gp_Dir aDir = aCon.Position().Direction();
 
     double aUMin, aUMax, aVMin, aVMax;
     BRepTools::UVBounds(aFace, aUMin, aUMax, aVMin, aVMax);
 
     double aSemiAngle = Abs(aCon.SemiAngle());
-    double aRadius2 = aRadius1 - (aVMax - aVMin) * Sin(aSemiAngle);
+    double aRadius1 = Abs(aCon.RefRadius() + aVMin * Sin(aCon.SemiAngle()));
+    double aRadius2 = Abs(aCon.RefRadius() + aVMax * Sin(aCon.SemiAngle()));
+
+    aLoc.ChangeCoord() += aDir.XYZ() * aVMin * Cos(aCon.SemiAngle());
 
     GeomPointPtr aLocation(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
     GeomDirPtr aDirection(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
@@ -231,3 +233,24 @@ std::shared_ptr<GeomAPI_Torus> GeomAPI_Face::getTorus() const
   }
   return aTorus;
 }
+
+GeomPointPtr GeomAPI_Face::middlePoint() const
+{
+  GeomPointPtr anInnerPoint;
+
+  const TopoDS_Face& aFace = impl<TopoDS_Face>();
+  if (aFace.IsNull())
+    return anInnerPoint;
+
+  BRepGProp_Face aProp(aFace);
+  double aUMin, aUMax, aVMin, aVMax;
+  aProp.Bounds(aUMin, aUMax, aVMin, aVMax);
+
+  Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
+  if (aSurf.IsNull())
+    return anInnerPoint;
+
+  gp_Pnt aPnt = aSurf->Value((aUMin + aUMax) * 0.5, (aVMin + aVMax) * 0.5);
+  anInnerPoint = GeomPointPtr(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
+  return anInnerPoint;
+}