X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_Tools.cpp;h=ef885ec1e3ab7390ae9c86fd8edab3eee20da1a7;hb=cdbbde4803e9c320204d537d22af4ac7ef024962;hp=6209b788d14ee0e2bd5e11ebbed34e2ae0085a04;hpb=4dd10dddeec6b5861d90ee784aaa18129638ce36;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_Tools.cpp b/src/SketchPlugin/SketchPlugin_Tools.cpp index 6209b788d..ef885ec1e 100644 --- a/src/SketchPlugin/SketchPlugin_Tools.cpp +++ b/src/SketchPlugin/SketchPlugin_Tools.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 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 @@ -20,6 +20,7 @@ #include "SketchPlugin_Tools.h" #include "SketchPlugin_Arc.h" +#include "SketchPlugin_BSpline.h" #include "SketchPlugin_Circle.h" #include "SketchPlugin_ConstraintCoincidence.h" #include "SketchPlugin_ConstraintCoincidenceInternal.h" @@ -36,8 +37,11 @@ #include +#include + #include #include +#include #include #include @@ -61,17 +65,17 @@ namespace SketchPlugin_Tools { void clearExpressions(AttributeDoublePtr theAttribute) { - theAttribute->setText(std::string()); + theAttribute->setText(std::wstring()); } void clearExpressions(AttributePointPtr theAttribute) { - theAttribute->setText(std::string(), std::string(), std::string()); + theAttribute->setText(std::wstring(), std::wstring(), std::wstring()); } void clearExpressions(AttributePoint2DPtr theAttribute) { - theAttribute->setText(std::string(), std::string()); + theAttribute->setText(std::wstring(), std::wstring()); } void clearExpressions(AttributePtr theAttribute) @@ -150,8 +154,8 @@ void findCoincidences(const FeaturePtr theStartCoin, std::set::const_iterator aCIt = aCoincidences.begin(); for (; aCIt != aCoincidences.end(); ++aCIt) { FeaturePtr aConstrFeature = *aCIt; - std::shared_ptr aPnt = getCoincidencePoint(aConstrFeature); - if(aPnt.get() && aOrig->isEqual(aPnt)) { + std::shared_ptr aPnt2d = getCoincidencePoint(aConstrFeature); + if(aPnt2d.get() && aOrig->isEqual(aPnt2d)) { findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A(), theList, theIsAttrOnly); findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B(), @@ -227,26 +231,39 @@ public: } } - void coincidentPoints(const AttributePoint2DPtr& thePoint, - std::set& thePoints, - std::map& thePointsInArray) + std::set coincidentPoints(const AttributePoint2DPtr& thePoint) { collectCoincidentPoints(thePoint); + std::set aCoincPoints; auto aFound = find(thePoint, THE_DEFAULT_INDEX); if (aFound != myCoincidentPoints.end()) { for (auto it = aFound->begin(); it != aFound->end(); ++it) { AttributePoint2DPtr aPoint = std::dynamic_pointer_cast(it->first); if (aPoint) - thePoints.insert(aPoint); + aCoincPoints.insert(aPoint); else { AttributePoint2DArrayPtr aPointArray = std::dynamic_pointer_cast(it->first); - if (aPointArray) - thePointsInArray[aPointArray] = *it->second.begin(); + if (aPointArray) { + // this is a B-spline feature, the connection is possible + // to the first or the last point + FeaturePtr anOwner = ModelAPI_Feature::feature(aPointArray->owner()); + if (it->second.find(0) != it->second.end()) { + AttributePoint2DPtr aFirstPoint = std::dynamic_pointer_cast( + anOwner->attribute(SketchPlugin_BSpline::START_ID())); + aCoincPoints.insert(aFirstPoint); + } + if (it->second.find(aPointArray->size() - 1) != it->second.end()) { + AttributePoint2DPtr aFirstPoint = std::dynamic_pointer_cast( + anOwner->attribute(SketchPlugin_BSpline::END_ID())); + aCoincPoints.insert(aFirstPoint); + } + } } } } + return aCoincPoints; } private: @@ -259,14 +276,15 @@ private: std::set aCoincToRes = SketchPlugin_Tools::findCoincidentConstraints(theFeature->lastResult()); aCoincidences.insert(aCoincToRes.begin(), aCoincToRes.end()); - } std::set::const_iterator aCIt = aCoincidences.begin(); + } + std::set::const_iterator aCIt = aCoincidences.begin(); for (; aCIt != aCoincidences.end(); ++aCIt) { if (theCoincidences.find(*aCIt) != theCoincidences.end()) continue; // already processed theCoincidences.insert(*aCIt); // iterate on coincident attributes - for (int i = 0, aPtInd = 0; i < CONSTRAINT_ATTR_SIZE; ++i) { + for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) { AttributeRefAttrPtr aRefAttr = (*aCIt)->refattr(SketchPlugin_Constraint::ATTRIBUTE(i)); if (!aRefAttr) continue; @@ -339,6 +357,22 @@ private: if (aFound != aSeek->end() && aFound->second.find(theIndex) != aFound->second.end()) return aSeek; } + // nothing is found, but if the point is a B-spline boundary point, lets check it as poles array + FeaturePtr anOwner = ModelAPI_Feature::feature(thePoint->owner()); + if (anOwner->getKind() == SketchPlugin_BSpline::ID()) { + AttributePtr aPointsArray; + int anIndex = -1; + if (thePoint->id() == SketchPlugin_BSpline::START_ID()) { + aPointsArray = anOwner->attribute(SketchPlugin_BSpline::POLES_ID()); + anIndex = 0; + } + else if (thePoint->id() == SketchPlugin_BSpline::END_ID()) { + aPointsArray = anOwner->attribute(SketchPlugin_BSpline::POLES_ID()); + anIndex = std::dynamic_pointer_cast(aPointsArray)->size() - 1; + } + if (aPointsArray) + return find(aPointsArray, anIndex); + } return myCoincidentPoints.end(); } @@ -347,19 +381,9 @@ private: }; std::set findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint) -{ - std::set aPoints; - std::map aPointsInArray; - findPointsCoincidentToPoint(thePoint, aPoints, aPointsInArray); - return aPoints; -} - -void findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint, - std::set& thePoints, - std::map& thePointsInArray) { CoincidentPoints aCoincidentPoints; - aCoincidentPoints.coincidentPoints(thePoint, thePoints, thePointsInArray); + return aCoincidentPoints.coincidentPoints(thePoint); } @@ -524,7 +548,8 @@ void createAuxiliaryPointOnEllipse(const FeaturePtr& theEllipseFeature, aCoord->setValue(anElPoint->x(), anElPoint->y()); aPointFeature->execute(); - std::string aName = theEllipseFeature->name() + "_" + theEllipsePoint; + std::wstring aName = theEllipseFeature->name() + L"_" + + Locale::Convert::toWString(theEllipsePoint); aPointFeature->data()->setName(aName); aPointFeature->lastResult()->data()->setName(aName); @@ -557,8 +582,8 @@ void createAuxiliaryAxisOfEllipse(const FeaturePtr& theEllipseFeature, aLineEnd->setValue(aEndPoint->x(), aEndPoint->y()); aLineFeature->execute(); - std::string aName = theEllipseFeature->name() + "_" + - (theStartPoint == SketchPlugin_Ellipse::MAJOR_AXIS_START_ID() ? "major_axis" : "minor_axis"); + std::wstring aName = theEllipseFeature->name() + L"_" + + (theStartPoint == SketchPlugin_Ellipse::MAJOR_AXIS_START_ID() ? L"major_axis" : L"minor_axis"); aLineFeature->data()->setName(aName); aLineFeature->lastResult()->data()->setName(aName); @@ -625,13 +650,13 @@ void setDimensionColor(const AISObjectPtr& theDimPrs) theDimPrs->setColor(aColor[0], aColor[1], aColor[2]); } -void replaceInName(ObjectPtr theObject, const std::string& theSource, const std::string& theDest) +void replaceInName(ObjectPtr theObject, const std::wstring& theSource, const std::wstring& theDest) { - std::string aName = theObject->data()->name(); + std::wstring aName = theObject->data()->name(); size_t aPos = aName.find(theSource); - if (aPos != std::string::npos) { - std::string aNewName = aName.substr(0, aPos) + theDest - + aName.substr(aPos + theSource.size()); + if (aPos != std::wstring::npos) { + std::wstring aNewName = aName.substr(0, aPos) + theDest + + aName.substr(aPos + theSource.size()); theObject->data()->setName(aNewName); } } @@ -661,6 +686,10 @@ void SketchPlugin_SegmentationTools::getFeaturePoints(const FeaturePtr& theFeatu aStartAttributeName = SketchPlugin_EllipticArc::START_POINT_ID(); anEndAttributeName = SketchPlugin_EllipticArc::END_POINT_ID(); } + else if (aFeatureKind == SketchPlugin_BSpline::ID()) { + aStartAttributeName = SketchPlugin_BSpline::START_ID(); + anEndAttributeName = SketchPlugin_BSpline::END_ID(); + } if (!aStartAttributeName.empty() && !anEndAttributeName.empty()) { theStartPointAttr = std::dynamic_pointer_cast( theFeature->attribute(aStartAttributeName)); @@ -822,9 +851,9 @@ void SketchPlugin_SegmentationTools::fillObjectShapes( // collect all intersection points with other edges for Trim operation only std::list aFeatures; for (int i = 0; i < aSketch->numberOfSubs(); i++) { - FeaturePtr aFeature = aSketch->subFeature(i); - if (aFeature.get() && aFeature->getKind() != SketchPlugin_Projection::ID()) - aFeatures.push_back(aFeature); + FeaturePtr aSubFeature = aSketch->subFeature(i); + if (aSubFeature.get() && aSubFeature->getKind() != SketchPlugin_Projection::ID()) + aFeatures.push_back(aSubFeature); } ModelGeomAlgo_Point2D::getPointsIntersectedShape(aFeature, aFeatures, aPoints); }