X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketcherPrs%2FSketcherPrs_PositionMgr.cpp;h=1581533d32eafeeb7e13ecbf1ec8241729dacbd1;hb=a36923e4ef2c8bdfe3ff3fdf6692b2cb181dbc72;hp=b3c76ddef320ec77e5fe21837c2a03de4cd08419;hpb=53a5c770b43256db1191dda004fce23a2ab0a39d;p=modules%2Fshaper.git diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp index b3c76ddef..1581533d3 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2021 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,30 +12,31 @@ // // 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 "SketcherPrs_PositionMgr.h" #include "SketcherPrs_Tools.h" -#include -#include -#include -#include #include #include +#include +#include +#include +#include #include +#include #include -#include -#include #include -#include +#include +#include +#include #include +#include #include #include @@ -61,7 +62,6 @@ SketcherPrs_PositionMgr::SketcherPrs_PositionMgr() { } - int SketcherPrs_PositionMgr::getPositionIndex(ObjectPtr theLine, const SketcherPrs_SymbolPrs* thePrs) { @@ -89,17 +89,8 @@ int SketcherPrs_PositionMgr::getPositionIndex(ObjectPtr theLine, bool SketcherPrs_PositionMgr::isPntConstraint(const std::string& theName) { - static std::list aConstraints; - if (aConstraints.size() == 0) { - aConstraints.push_back(SketchPlugin_ConstraintTangent::ID()); - aConstraints.push_back(SketchPlugin_ConstraintPerpendicular::ID()); - } - std::list::const_iterator aIt; - for (aIt = aConstraints.cbegin(); aIt != aConstraints.cend(); ++aIt) { - if ((*aIt) == theName) - return true; - } - return false; + return ((theName == SketchPlugin_ConstraintTangent::ID()) || + (theName == SketchPlugin_ConstraintPerpendicular::ID())); } bool containsPoint(const FeaturePtr& theFeature, GeomPnt2dPtr thePnt2d, GeomPointPtr thePos) @@ -156,31 +147,30 @@ const std::array& SketcherPrs_PositionMgr::getPositionIndex(GeomPointPtr for (int i = 0; i < aNbSubs; i++) { FeaturePtr aFeature = aOwner->subFeature(i); - if (myPntShapes.count(aFeature.get()) == 1) { - myPntShapes[aFeature.get()][0] = aId; - aId++; - aFeaList.push_back(aFeature.get()); - } else { - if (isPntConstraint(aFeature->getKind())) { - DataPtr aData = aFeature->data(); - AttributeRefAttrPtr aObjRef = aData->refattr(SketchPlugin_Constraint::ENTITY_A()); - FeaturePtr aObj = ModelAPI_Feature::feature(aObjRef->object()); - bool aContains = false; - if (containsPoint(aObj, aPnt2d, thePos)) { - aContains = true; - } else { - aObjRef = aData->refattr(SketchPlugin_Constraint::ENTITY_B()); + bool aUseFeature = ((myPntShapes.count(aFeature.get()) == 1) || + (isPntConstraint(aFeature->getKind()))); + if (aUseFeature) { + DataPtr aData = aFeature->data(); + AttributeRefAttrPtr aObjRef = aData->refattr(SketchPlugin_Constraint::ENTITY_A()); + FeaturePtr aObj; + if (aObjRef) + aObj = ModelAPI_Feature::feature(aObjRef->object()); + bool aContains = false; + if (aObj && containsPoint(aObj, aPnt2d, thePos)) { + aContains = true; + } else { + aObjRef = aData->refattr(SketchPlugin_Constraint::ENTITY_B()); + if (aObjRef) aObj = ModelAPI_Feature::feature(aObjRef->object()); - if (containsPoint(aObj, aPnt2d, thePos)) { - aContains = true; - } - } - if (aContains) { - myPntShapes[aFeature.get()][0] = aId; - aId++; - aFeaList.push_back(aFeature.get()); + if (aObj && containsPoint(aObj, aPnt2d, thePos)) { + aContains = true; } } + if (aContains) { + myPntShapes[aFeature.get()][0] = aId; + aId++; + aFeaList.push_back(aFeature.get()); + } } } int aSize = (int) aFeaList.size(); @@ -198,15 +188,31 @@ gp_Vec getVector(ObjectPtr theShape, GeomDirPtr theDir, gp_Pnt theP) gp_Vec aVec; std::shared_ptr aShape = SketcherPrs_Tools::getShape(theShape); if (aShape->isEdge()) { + std::shared_ptr anEdge = aShape->edge(); std::shared_ptr aCurve = std::shared_ptr(new GeomAPI_Curve(aShape)); - if (aCurve->isCircle()) { + if (anEdge->isClosed()) { + double aPeriod = aCurve->endParam() - aCurve->startParam(); Handle(Geom_Curve) aCurv = aCurve->impl(); GeomAPI_ProjectPointOnCurve anExtr(theP, aCurv); double aParam = anExtr.LowerDistanceParameter(); gp_Pnt aP; aCurv->D1(aParam, aP, aVec); + // 2458: check correct orientation of the vector + if (aVec.SquareMagnitude() > Precision::Confusion()) { + std::shared_ptr aCircEdge(new GeomAPI_Edge(aShape)); + double aFirstParam, aLastParam; + aCircEdge->getRange(aFirstParam, aLastParam); + // if parameter is near the LastParam, make the vector go inside (reverse) + double aDelta = aLastParam - aParam; + while (aDelta < -Precision::Confusion()) + aDelta += aPeriod; + while (aDelta > aPeriod + Precision::Confusion()) + aDelta -= aPeriod; + if (fabs(aDelta) < Precision::Confusion()) + aVec.Reverse(); + } } else { GeomPointPtr aPnt1 = aCurve->getPoint(aCurve->endParam()); GeomPointPtr aPnt2 = aCurve->getPoint(aCurve->startParam()); @@ -254,7 +260,8 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, // Compute shifting vector for a one symbol gp_Vec aShift = aVec1.Crossed(thePrs->plane()->normal()->impl()); - aShift.Normalize(); + if (aShift.SquareMagnitude() > Precision::SquareConfusion()) + aShift.Normalize(); aShift.Multiply(theStep * 0.8); // Shift the position coordinate according to position index @@ -301,8 +308,8 @@ std::list getCurves(const GeomPointPtr& thePnt, const SketcherPrs_Sym int aNbSubs = aOwner->numberOfSubs(); for (int i = 0; i < aNbSubs; i++) { FeaturePtr aFeature = aOwner->subFeature(i); - if (!aFeature->firstResult().get()) // There is no result - continue; + if (!aFeature->firstResult().get() || aFeature->firstResult()->isDisabled()) + continue; // There is no result if (aFeature->getKind() == SketchPlugin_Line::ID()) { AttributePoint2DPtr aSPnt1 = std::dynamic_pointer_cast( @@ -313,7 +320,8 @@ std::list getCurves(const GeomPointPtr& thePnt, const SketcherPrs_Sym GeomPnt2dPtr aPnt1 = aSPnt1->pnt(); GeomPnt2dPtr aPnt2 = aSPnt2->pnt(); - if (aPnt1->isEqual(aPnt2d) || aPnt2->isEqual(aPnt2d)) { + if (aPnt1->distance(aPnt2d) <= Precision::Confusion() || + aPnt2->distance(aPnt2d) <= Precision::Confusion()) { // a point corresponds to one of the line end GeomShapePtr aShp = SketcherPrs_Tools::getShape(aFeature->firstResult()); GeomCurvePtr aCurv = std::shared_ptr(new GeomAPI_Curve(aShp)); @@ -325,8 +333,7 @@ std::list getCurves(const GeomPointPtr& thePnt, const SketcherPrs_Sym if (aDist <= Precision::Confusion()) aList.push_back(aFeature->firstResult()); } - } else if ((aFeature->getKind() == SketchPlugin_Circle::ID()) || - (aFeature->getKind() == SketchPlugin_Arc::ID())) { + } else { GeomCurvePtr aCurve; ObjectPtr aResObj; std::list aResults = aFeature->results(); @@ -340,11 +347,19 @@ std::list getCurves(const GeomPointPtr& thePnt, const SketcherPrs_Sym } } if (aCurve.get()) { - double aStart = aCurve->startParam(); - double aEnd = aCurve->endParam(); - GeomCirclePtr aCircle = GeomCirclePtr(new GeomAPI_Circ(aCurve)); - GeomPointPtr aProjPnt = aCircle->project(thePnt); - if (thePnt->distance(aProjPnt) <= Precision::Confusion()) + GeomPointPtr aProjPnt; + if (aFeature->getKind() == SketchPlugin_Circle::ID() || + aFeature->getKind() == SketchPlugin_Arc::ID()) { + GeomCirclePtr aCircle = GeomCirclePtr(new GeomAPI_Circ(aCurve)); + aProjPnt = aCircle->project(thePnt); + } + else if (aFeature->getKind() == SketchPlugin_Ellipse::ID()) { + GeomEllipsePtr anEllipse = GeomEllipsePtr(new GeomAPI_Ellipse(aCurve)); + aProjPnt = anEllipse->project(thePnt); + } + else + aProjPnt = aCurve->project(thePnt); + if (aProjPnt && thePnt->distance(aProjPnt) <= Precision::Confusion()) aList.push_back(aResObj); } } @@ -358,6 +373,8 @@ gp_Pnt SketcherPrs_PositionMgr::getPointPosition( double theStep, GeomPointPtr thePnt) { gp_Pnt aP = thePnt->impl(); + if (!thePrs->plane().get()) + return aP; GeomDirPtr aNormal = thePrs->plane()->normal(); gp_Dir aNormDir = aNormal->impl(); @@ -407,7 +424,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPointPosition( gp_Vec aVecPos; // If number of angle less then number of symbols then each symbol can be placed // directly inside of the angle - if (aAngles.size() >= aPos[1]) { + if ((int)aAngles.size() >= aPos[1] && !aVectors.empty()) { int aId = aPos[0]; aVecPos = *(std::next(aVectors.begin(), aId)); @@ -422,9 +439,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPointPosition( double aAng; std::list::const_iterator aItAng; - double aAngPos; bool aHasPlace = false; - //int aIntId = 0; // a position inside a one sector while (aPosCount < aPos[1]) { for (aItAng = aAngles.cbegin(), aItVec = aVectors.cbegin(); aItAng != aAngles.cend(); ++aItAng, ++aItVec) { @@ -434,9 +449,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPointPosition( if ((!aHasPlace) && (aPosCount >= (aPos[0] + 1))) { aHasPlace = true; - aAngPos = (*aItAng); aVecPos = (*aItVec); - //aIntId = aPos[0] - (aPosCount - Nb); } } if (aPosCount < aPos[1]) { @@ -474,10 +487,10 @@ void SketcherPrs_PositionMgr::deleteConstraint(const SketcherPrs_SymbolPrs* theP aToDel.push_back(aIt->first); else { // Reindex objects positions in order to avoid spaces - PositionsMap::iterator aIt; + PositionsMap::iterator aPMIt; int i = 0; - for (aIt = aPosMap.begin(); aIt != aPosMap.end(); aIt++, i++) - aIt->second = i; + for (aPMIt = aPosMap.begin(); aPMIt != aPosMap.end(); aPMIt++, i++) + aPMIt->second = i; } } }