X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_Tools.cpp;h=710c6fd18d3a6ceedf4b9a5153fabec1b1f9fc5f;hb=06e7f5859095193fc7f498bd89a7d28009794f53;hp=fd1475aca007fa4337207f0003accc4b7143d286;hpb=1691723a716b1f00c2307fbf1ac65dbe89fa5e2f;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_Tools.cpp b/src/SketchPlugin/SketchPlugin_Tools.cpp index fd1475aca..710c6fd18 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-2023 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -37,6 +37,8 @@ #include +#include + #include #include #include @@ -63,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) @@ -152,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(), @@ -229,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: @@ -269,7 +284,7 @@ private: 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; @@ -342,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(); } @@ -350,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); } @@ -528,7 +549,7 @@ void createAuxiliaryPointOnEllipse(const FeaturePtr& theEllipseFeature, aPointFeature->execute(); std::wstring aName = theEllipseFeature->name() + L"_" + - ModelAPI_Tools::toWString(theEllipsePoint); + Locale::Convert::toWString(theEllipsePoint); aPointFeature->data()->setName(aName); aPointFeature->lastResult()->data()->setName(aName); @@ -633,9 +654,9 @@ void replaceInName(ObjectPtr theObject, const std::wstring& theSource, const std { std::wstring aName = theObject->data()->name(); size_t aPos = aName.find(theSource); - if (aPos != std::string::npos) { + if (aPos != std::wstring::npos) { std::wstring aNewName = aName.substr(0, aPos) + theDest - + aName.substr(aPos + theSource.size()); + + aName.substr(aPos + theSource.size()); theObject->data()->setName(aNewName); } } @@ -830,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); }