]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1620: Fixed orientation of revolution
authordbv <dbv@opencascade.com>
Fri, 5 Aug 2016 13:15:54 +0000 (16:15 +0300)
committerdbv <dbv@opencascade.com>
Fri, 5 Aug 2016 13:16:17 +0000 (16:16 +0300)
src/ConstructionPlugin/ConstructionPlugin_Plane.cpp
src/GeomAPI/GeomAPI_Face.cpp
src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h
src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/SketchPlugin/SketchPlugin_Sketch.cpp

index 28b6e8b27b4fff1c79149b652161e98a655ab752..d08fa90dcd8ec462481e6a091f28eea4de664998 100644 (file)
@@ -265,7 +265,7 @@ std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByDistanceFromOth
 
     std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aShape));
 
-    std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_FaceBuilder::plane(aFace);
+    std::shared_ptr<GeomAPI_Pln> aPln = aFace->getPlane();
     std::shared_ptr<GeomAPI_Pnt> aOrig = aPln->location();
     std::shared_ptr<GeomAPI_Dir> aDir = aPln->direction();
 
index ff6eafc601c15eca8f967fb461bcd0ab6bc317eb..096c4bd16821b6eec38a1282082c5703bcb58712 100644 (file)
@@ -16,6 +16,7 @@
 #include <Geom_Surface.hxx>
 #include <Geom_CylindricalSurface.hxx>
 #include <Geom_RectangularTrimmedSurface.hxx>
+#include <GeomLib_IsPlanarSurface.hxx>
 #include <IntTools_Context.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Face.hxx>
@@ -85,31 +86,31 @@ bool GeomAPI_Face::isCylindrical() const
 
 std::shared_ptr<GeomAPI_Pln> GeomAPI_Face::getPlane() const
 {
-  const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
-  BRepAdaptor_Surface aSurfAdapt(TopoDS::Face(aShape));
-
-  if (aSurfAdapt.GetType() != GeomAbs_Plane)
-    return std::shared_ptr<GeomAPI_Pln>();
-
-  // Obtain central point
-  double aUMin, aUMax, aVMin, aVMax;
-  aUMin = aSurfAdapt.FirstUParameter();
-  aUMax = aSurfAdapt.LastUParameter();
-  aVMin = aSurfAdapt.FirstVParameter();
-  aVMax = aSurfAdapt.LastVParameter();
-  gp_Pnt aCentralPnt;
-  gp_Vec aDU, aDV;
-  aSurfAdapt.D1((aUMin+aUMax)*0.5, (aVMin+aVMax)*0.5, aCentralPnt, aDU, aDV);
-  std::shared_ptr<GeomAPI_Pnt> aCenter(
-      new GeomAPI_Pnt(aCentralPnt.X(), aCentralPnt.Y(), aCentralPnt.Z()));
-
-  // Obtain plane direction
-  gp_XYZ aNormalVec = aDU.XYZ().Crossed(aDV.XYZ());
-  if (aNormalVec.SquareModulus() < Precision::Confusion() * Precision::Confusion())
-    return std::shared_ptr<GeomAPI_Pln>();
-  std::shared_ptr<GeomAPI_Dir> aNormal(
-      new GeomAPI_Dir(aNormalVec.X(), aNormalVec.Y(), aNormalVec.Z()));
-
-  std::shared_ptr<GeomAPI_Pln> aResult(new GeomAPI_Pln(aCenter, aNormal));
+  std::shared_ptr<GeomAPI_Pln> aResult;
+  TopoDS_Shape aShape = this->impl<TopoDS_Shape>();
+  if (aShape.IsNull())
+    return aResult;  // null shape
+  if (aShape.ShapeType() != TopAbs_FACE)
+    return aResult;  // not face
+  TopoDS_Face aFace = TopoDS::Face(aShape);
+  if (aFace.IsNull())
+    return aResult;  // not face
+  Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
+  if (aSurf.IsNull())
+    return aResult;  // no surface
+  GeomLib_IsPlanarSurface isPlanar(aSurf);
+  if(!isPlanar.IsPlanar()) {
+    return aResult;
+  }
+  gp_Pln aPln = isPlanar.Plan();
+  double aA, aB, aC, aD;
+  aPln.Coefficients(aA, aB, aC, aD);
+  if (aFace.Orientation() == TopAbs_REVERSED) {
+    aA = -aA;
+    aB = -aB;
+    aC = -aC;
+    aD = -aD;
+  }
+  aResult = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
   return aResult;
 }
index b5c5a4aa771ee07e166c12ae0243d080480766d8..25c0a005ab2151f322556e86b02aa7c77f0e83d2 100644 (file)
@@ -17,7 +17,6 @@
 #include <BRepBuilderAPI_MakeFace.hxx>
 #include <GC_MakePlane.hxx>
 #include <Geom_Plane.hxx>
-#include <GeomLib_IsPlanarSurface.hxx>
 #include <gp_Pln.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Face.hxx>
@@ -123,37 +122,3 @@ std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::planarFaceByFaceAndVertex
   aFace->setImpl(new TopoDS_Face(aMakeFace.Face()));
   return aFace;
 }
-
-//==================================================================================================
-std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(const std::shared_ptr<GeomAPI_Face> theFace)
-{
-  std::shared_ptr<GeomAPI_Pln> aResult;
-  if (!theFace)
-    return aResult;  // bad shape
-  TopoDS_Shape aShape = theFace->impl<TopoDS_Shape>();
-  if (aShape.IsNull())
-    return aResult;  // null shape
-  if (aShape.ShapeType() != TopAbs_FACE)
-    return aResult;  // not face
-  TopoDS_Face aFace = TopoDS::Face(aShape);
-  if (aFace.IsNull())
-    return aResult;  // not face
-  Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
-  if (aSurf.IsNull())
-    return aResult;  // no surface
-  GeomLib_IsPlanarSurface isPlanar(aSurf);
-  if(!isPlanar.IsPlanar()) {
-    return aResult;
-  }
-  gp_Pln aPln = isPlanar.Plan();
-  double aA, aB, aC, aD;
-  aPln.Coefficients(aA, aB, aC, aD);
-  if (aFace.Orientation() == TopAbs_REVERSED) {
-    aA = -aA;
-    aB = -aB;
-    aC = -aC;
-    aD = -aD;
-  }
-  aResult = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
-  return aResult;
-}
\ No newline at end of file
index c33013f02e51d5c102396fcffc3068296b4af604..4b65249299e8aa738cdb3388b674da8d89124fdd 100644 (file)
@@ -50,9 +50,6 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_FaceBuilder
   /// Creates a planar face parallel to theFace and passing through theVertex.
   static std::shared_ptr<GeomAPI_Face> planarFaceByFaceAndVertex(const std::shared_ptr<GeomAPI_Face> theFace,
                                                                  const std::shared_ptr<GeomAPI_Vertex> theVertex);
-
-  /// Returns the plane of the planar face. If it is not planar, returns empty ptr.
-  static std::shared_ptr<GeomAPI_Pln> plane(const std::shared_ptr<GeomAPI_Face> theFace);
 };
 
 #endif
index b6bc188eb31df6716fecf47f466ecd6a0b8ac89f..9ff572fb464e93a4abd85ba5b3b90c13bea4bcfe 100644 (file)
@@ -7,6 +7,7 @@
 #include "GeomAlgoAPI_Revolution.h"
 
 #include <GeomAPI_Face.h>
+#include <GeomAPI_Pln.h>
 #include <GeomAPI_ShapeExplorer.h>
 #include <GeomAlgoAPI_DFLoader.h>
 #include <GeomAlgoAPI_FaceBuilder.h>
@@ -236,8 +237,12 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr&                 theBaseSh
     if(!isFromPlanar.IsPlanar() || !isToPlanar.IsPlanar()) {// non-planar shapes is not supported for revolution bounding
       return;
     }
-    gp_Pln aFromPln = isFromPlanar.Plan();
-    gp_Pln aToPln   = isToPlanar.Plan();
+
+    std::shared_ptr<GeomAPI_Face> aGeomFromFace(new GeomAPI_Face(theFromShape));
+    std::shared_ptr<GeomAPI_Face> aGeomToFace(new GeomAPI_Face(theToShape));
+
+    gp_Pln aFromPln = aGeomFromFace->getPlane()->impl<gp_Pln>();
+    gp_Pln aToPln   = aGeomToFace->getPlane()->impl<gp_Pln>();
 
     // Orienting bounding planes properly so that the center of mass of the base face stays
     // on the result shape after cut.
@@ -323,21 +328,23 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr&                 theBaseSh
     aResult = aRevolBuilder->Shape();
 
     // Getting bounding face.
-    TopoDS_Face aBoundingFace;
     bool isFromFaceSet = false;
+    std::shared_ptr<GeomAPI_Face> aGeomBoundingFace;
     if(theFromShape) {
-      aBoundingFace = TopoDS::Face(theFromShape->impl<TopoDS_Shape>());
+      aGeomBoundingFace.reset(new GeomAPI_Face(theFromShape));
       isFromFaceSet = true;
     } else if(theToShape) {
-      aBoundingFace = TopoDS::Face(theToShape->impl<TopoDS_Shape>());
+      aGeomBoundingFace.reset(new GeomAPI_Face(theToShape));
     }
+    TopoDS_Face aBoundingFace = TopoDS::Face(aGeomBoundingFace->impl<TopoDS_Shape>());
 
     // Getting plane from bounding face.
     GeomLib_IsPlanarSurface isBoundingPlanar(BRep_Tool::Surface(aBoundingFace));
     if(!isBoundingPlanar.IsPlanar()) { // non-planar shapes is not supported for revolution bounding
       return;
     }
-    gp_Pln aBoundingPln = isBoundingPlanar.Plan();
+
+    gp_Pln aBoundingPln = aGeomBoundingFace->getPlane()->impl<gp_Pln>();
 
     // Orienting bounding plane properly so that the center of mass of the base face stays
     // on the result shape after cut.
index 9a94798aad80491d4143caf310f337e0d16beb75..a19b96a37ac9d41fc21da278b5df09ae03e4a416 100644 (file)
@@ -258,7 +258,7 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
   if (aGShape.get() != NULL) {
     // get plane parameters
     std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aGShape));
-    std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aFace);
+    std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
     std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
     gp_XYZ aXYZ = aDir->impl<gp_Dir>().XYZ();
     double aTwist = 0.0;
@@ -489,7 +489,7 @@ std::shared_ptr<GeomAPI_Dir> PartSet_WidgetSketchLabel::setSketchPlane(const Fea
 
   // get plane parameters
   std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aGShape));
-  std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aFace);
+  std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
   if (!aPlane.get())
     return std::shared_ptr<GeomAPI_Dir>();
 
index ef2ef9c691327934c4f4cf171008ffb5fd1b3842..5d1b9d3d23d7ef7b5924f25f818c7f28155f1660 100755 (executable)
@@ -217,7 +217,7 @@ void SketchPlugin_Sketch::attributeChanged(const std::string& theID) {
     if (aSelection) { // update arguments due to the selection value
       // update the sketch plane
       std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aSelection));
-      std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aFace);
+      std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
       if (aPlane) {
         double anA, aB, aC, aD;
         aPlane->coefficients(anA, aB, aC, aD);