From: azv Date: Mon, 5 Sep 2016 04:50:00 +0000 (+0300) Subject: Fixed Placement centering of faces (issue #1714) X-Git-Tag: V_2.5.0~63 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fea65cc1c8e35809be630fb1ab2adcd4fd27cc1e;p=modules%2Fshaper.git Fixed Placement centering of faces (issue #1714) --- diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp index fb139dd8e..de553626b 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp @@ -19,8 +19,10 @@ #include #include +#include #include #include +#include #include GeomAlgoAPI_Placement::GeomAlgoAPI_Placement(const std::shared_ptr theSourceSolid, @@ -52,15 +54,20 @@ void GeomAlgoAPI_Placement::build(const std::shared_ptr& theSourc bool hasDirection[aNbObjects]; std::shared_ptr aShapes[aNbObjects] = {theSourceShape, theDestShape}; + GProp_GProps aProps; + static const double aPropEps = 1.e-4; for (int i = 0; i < aNbObjects; i++) { if (aShapes[i]->isFace()) { std::shared_ptr aFace(new GeomAPI_Face(aShapes[i])); std::shared_ptr aPlane = aFace->getPlane(); std::shared_ptr aDir = aPlane->direction(); - std::shared_ptr aLoc = aPlane->location(); - aSrcDstPoints[i].SetCoord(aLoc->x(), aLoc->y(), aLoc->z()); aSrcDstNormals[i].SetCoord(aDir->x(), aDir->y(), aDir->z()); - } else if (aShapes[i]->isEdge()) { + + BRepGProp::SurfaceProperties(aFace->impl(), aProps, aPropEps); + gp_Pnt aLoc = aProps.CentreOfMass(); + aSrcDstPoints[i].SetCoord(aLoc.X(), aLoc.Y(), aLoc.Z()); + } + else if (aShapes[i]->isEdge()) { std::shared_ptr anEdge(new GeomAPI_Edge(aShapes[i])); std::shared_ptr aLine = anEdge->line(); std::shared_ptr aDir = aLine->direction(); @@ -69,7 +76,8 @@ void GeomAlgoAPI_Placement::build(const std::shared_ptr& theSourc std::shared_ptr aLoc = aFirstPnt->xyz()->added(aLastPnt->xyz())->multiplied(0.5); aSrcDstPoints[i].SetCoord(aLoc->x(), aLoc->y(), aLoc->z()); aSrcDstDirections[i].SetCoord(aDir->x(), aDir->y(), aDir->z()); - } else if (aShapes[i]->isVertex()) { + } + else if (aShapes[i]->isVertex()) { std::shared_ptr aVertex(new GeomAPI_Vertex(aShapes[i])); std::shared_ptr aPnt = aVertex->point(); aSrcDstPoints[i].SetCoord(aPnt->x(), aPnt->y(), aPnt->z());