X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAPI%2FGeomAPI_Curve.cpp;h=2ffc946464537d2a2ac5a92a46c5ef42dd23ff9b;hb=ea593bc59e7e9461f6c4e2afd3f24d621edb1011;hp=77bf7d9a2660842d0fee494d689961fbe6b57106;hpb=cc917b5dfaca1fcba1a25c1e54d6bd1ef0b4c057;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_Curve.cpp b/src/GeomAPI/GeomAPI_Curve.cpp index 77bf7d9a2..2ffc94646 100644 --- a/src/GeomAPI/GeomAPI_Curve.cpp +++ b/src/GeomAPI/GeomAPI_Curve.cpp @@ -1,34 +1,55 @@ -// File: GeomAPI_Curve.cpp -// Created: 04 Sep 2014 -// Author: Mikhail PONIKAROV +// 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include +#include #include +#include #include +#include #include -#include +#include +#include #include #include #include +#include -#define MY_CURVE (*(static_cast(myImpl))) +#define MY_CURVE (*(implPtr())) GeomAPI_Curve::GeomAPI_Curve() - : GeomAPI_Interface(new Handle_Geom_Curve()) + : GeomAPI_Interface(new Handle_Geom_Curve()), + myStart(-Precision::Infinite()), + myEnd(Precision::Infinite()) { } -GeomAPI_Curve::GeomAPI_Curve(const boost::shared_ptr& theShape) +GeomAPI_Curve::GeomAPI_Curve(const std::shared_ptr& theShape) : GeomAPI_Interface(new Handle_Geom_Curve()) // initially it is null { const TopoDS_Shape& aShape = theShape->impl(); TopoDS_Edge anEdge = TopoDS::Edge(aShape); if (!anEdge.IsNull()) { - Standard_Real aStart, anEnd; - Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aStart, anEnd); + Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, myStart, myEnd); if (!aCurve.IsNull()) { - setImpl(&aCurve); + setImpl(new Handle(Geom_Curve)(aCurve)); } } } @@ -38,12 +59,108 @@ bool GeomAPI_Curve::isNull() const return MY_CURVE.IsNull() == Standard_True; } +static bool isCurveType(const Handle(Geom_Curve)& theCurve, const Handle(Standard_Type)& theType) +{ + if (theCurve.IsNull()) + return false; + Handle(Geom_Curve) aCurve = theCurve; + if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) + aCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve)->BasisCurve(); + return aCurve->DynamicType() == theType; +} + bool GeomAPI_Curve::isLine() const { - return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Line); + return isCurveType(MY_CURVE, STANDARD_TYPE(Geom_Line)); } bool GeomAPI_Curve::isCircle() const { - return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Circle); + return isCurveType(MY_CURVE, STANDARD_TYPE(Geom_Circle)); +} + +bool GeomAPI_Curve::isEllipse() const +{ + return isCurveType(MY_CURVE, STANDARD_TYPE(Geom_Ellipse)); +} + +double GeomAPI_Curve::startParam() +{ + if (Precision::IsInfinite(myStart)) { + if (isTrimmed()) { + myStart = Handle(Geom_TrimmedCurve)::DownCast(MY_CURVE)->FirstParameter(); + } + else if (MY_CURVE->IsClosed() && MY_CURVE->IsPeriodic()) + myStart = 0.0; + } + return myStart; +} + +double GeomAPI_Curve::endParam() +{ + if (Precision::IsInfinite(myEnd)) { + if (isTrimmed()) { + myEnd = Handle(Geom_TrimmedCurve)::DownCast(MY_CURVE)->LastParameter(); + } + else if (MY_CURVE->IsClosed() && MY_CURVE->IsPeriodic()) + myEnd = MY_CURVE->Period(); + } + return myEnd; +} + +std::shared_ptr GeomAPI_Curve::getPoint(double theParam) +{ + GeomAdaptor_Curve aAdaptor(MY_CURVE, myStart, myEnd); + gp_Pnt aPnt = aAdaptor.Value(theParam); + return std::shared_ptr(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z())); +} + +bool GeomAPI_Curve::isEqual(const std::shared_ptr& theOther) const +{ + return MY_CURVE == theOther->impl(); +} + +bool GeomAPI_Curve::isTrimmed() const +{ + return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve); +} + +GeomCurvePtr GeomAPI_Curve::basisCurve() const +{ + Handle(Geom_Curve) aCurve = MY_CURVE; + if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) + aCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve)->BasisCurve(); + + GeomCurvePtr aNewCurve(new GeomAPI_Curve); + aNewCurve->setImpl(new Handle(Geom_Curve)(aCurve)); + return aNewCurve; +} + + +const std::shared_ptr GeomAPI_Curve::project( + const std::shared_ptr& thePoint) const +{ + std::shared_ptr aResult; + if (MY_CURVE.IsNull()) + return aResult; + + const gp_Pnt& aPoint = thePoint->impl(); + + GeomAPI_ProjectPointOnCurve aProj(aPoint, MY_CURVE); + Standard_Integer aNbPoint = aProj.NbPoints(); + if (aNbPoint > 0) { + gp_Pnt aNearest = aProj.NearestPoint(); + aResult = GeomPointPtr(new GeomAPI_Pnt(aNearest.X(), aNearest.Y(), aNearest.Z())); + } + return aResult; +} + +// ================================================================================================ + +bool GeomAPI_Curve::Comparator::operator()(const GeomCurvePtr& theCurve1, + const GeomCurvePtr& theCurve2) const +{ + const Handle(Geom_Curve)& aCurve1 = theCurve1->impl(); + const Handle(Geom_Curve)& aCurve2 = theCurve2->impl(); + return aCurve1.get() < aCurve2.get(); }