X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_PointBuilder.cpp;h=7b46a50ff1ed6737d00aa27467175433abe0bdc6;hb=adf26479b37f6238c3fd33b7da5f37dd57b68b00;hp=19796f0a2be92a843e839c3f66d4300f6ac81746;hpb=7074394f8f08413d885f63be01df6bd5007b868c;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp index 19796f0a2..7b46a50ff 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp @@ -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 @@ -12,10 +12,9 @@ // // 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 +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "GeomAlgoAPI_PointBuilder.h" @@ -34,9 +33,11 @@ #include #include #include +#include #include #include #include +#include #include //================================================================================================== @@ -124,75 +125,72 @@ std::shared_ptr GeomAlgoAPI_PointBuilder::vertexOnEdge( //================================================================================================== std::shared_ptr GeomAlgoAPI_PointBuilder::vertexByProjection( - const std::shared_ptr theVertex, - const std::shared_ptr thePlane) + const std::shared_ptr theVertex, + const std::shared_ptr theEdge) { std::shared_ptr aVertex; - if(!theVertex.get() || !thePlane.get() || !thePlane->isPlanar()) { + if (!theVertex.get() || !theEdge.get()) { return aVertex; } std::shared_ptr aProjPnt = theVertex->point(); - std::shared_ptr aProjPln = thePlane->getPlane(); + gp_Pnt aPnt(aProjPnt->x(), aProjPnt->y(), aProjPnt->z()); - std::shared_ptr aPnt = aProjPln->project(aProjPnt); + TopoDS_Edge anEdge = TopoDS::Edge(theEdge->impl()); + double aFirstOnCurve, aLastOnCurve; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirstOnCurve, aLastOnCurve); - if(!aPnt.get()) { + if (aCurve.IsNull()) { return aVertex; } - aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z())); + GeomAPI_ProjectPointOnCurve aProjection(aPnt, aCurve); + + if (aProjection.NbPoints() != 0) { + gp_Pnt aNearestPoint = aProjection.NearestPoint(); + aVertex.reset(new GeomAPI_Vertex(aNearestPoint.X(), aNearestPoint.Y(), aNearestPoint.Z())); + } return aVertex; } //================================================================================================== -std::shared_ptr GeomAlgoAPI_PointBuilder::vertexByIntersection( - const std::shared_ptr theEdge1, - const std::shared_ptr theEdge2) +std::shared_ptr GeomAlgoAPI_PointBuilder::vertexByProjection( + const std::shared_ptr theVertex, + const std::shared_ptr theFace) { std::shared_ptr aVertex; - if(!theEdge1.get() || !theEdge2.get() || !theEdge1->isLine() || !theEdge2->isLine()) { - return aVertex; - } - - std::shared_ptr aLin1 = theEdge1->line(); - std::shared_ptr aLin2 = theEdge2->line(); + if (theVertex.get() && theFace.get() && theFace->isPlanar()) { + std::shared_ptr aProjPnt = theVertex->point(); + std::shared_ptr aProjPln = theFace->getPlane(); - std::shared_ptr aPnt = aLin1->intersect(aLin2); + std::shared_ptr aPnt = aProjPln->project(aProjPnt); - if(!aPnt.get()) { - return aVertex; + if (aPnt.get()) + aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z())); } - aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z())); - return aVertex; } //================================================================================================== std::shared_ptr GeomAlgoAPI_PointBuilder::vertexByIntersection( - const std::shared_ptr theEdge, - const std::shared_ptr theFace) + const std::shared_ptr theEdge1, + const std::shared_ptr theEdge2) { std::shared_ptr aVertex; - if(!theEdge.get() || !theFace.get() || !theEdge->isLine() || !theFace->isPlanar()) { - return aVertex; - } - - std::shared_ptr aLin = theEdge->line(); - std::shared_ptr aPln = theFace->getPlane(); + if (theEdge1.get() && theEdge2.get() && theEdge1->isLine() && theEdge2->isLine()) { + std::shared_ptr aLin1 = theEdge1->line(); + std::shared_ptr aLin2 = theEdge2->line(); - std::shared_ptr aPnt = aPln->intersect(aLin); + std::shared_ptr aPnt = aLin1->intersect(aLin2); - if(!aPnt.get()) { - return aVertex; + if (aPnt.get()) + aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z())); } - aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z())); - return aVertex; }