From b273b7ff758a2500866b5e97e26db1b324811684 Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 7 Feb 2020 10:23:44 +0300 Subject: [PATCH] Issue #3132: number DOF differs after dump/load script Fix the naming while trim/split an ellipse --- src/SketchAPI/SketchAPI_SketchEntity.cpp | 3 +- src/SketchPlugin/CMakeLists.txt | 1 + src/SketchPlugin/SketchPlugin_Split.cpp | 12 ++++- src/SketchPlugin/SketchPlugin_Tools.cpp | 11 ++++ src/SketchPlugin/SketchPlugin_Tools.h | 3 ++ src/SketchPlugin/SketchPlugin_Trim.cpp | 8 ++- src/SketchPlugin/Test/Test3132.py | 67 ++++++++++++++++++++++++ 7 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 src/SketchPlugin/Test/Test3132.py diff --git a/src/SketchAPI/SketchAPI_SketchEntity.cpp b/src/SketchAPI/SketchAPI_SketchEntity.cpp index fa56e6a5c..189c1f6e0 100644 --- a/src/SketchAPI/SketchAPI_SketchEntity.cpp +++ b/src/SketchAPI/SketchAPI_SketchEntity.cpp @@ -86,7 +86,8 @@ bool SketchAPI_SketchEntity::isCopy() const { // check the feature is a copy of another entity AttributeBooleanPtr isCopy = feature()->boolean(SketchPlugin_SketchEntity::COPY_ID()); - return isCopy.get() && isCopy->value(); + AttributeReferencePtr hasParent = feature()->reference(SketchPlugin_SketchEntity::PARENT_ID()); + return (isCopy.get() && isCopy->value()) || (hasParent && hasParent->value()); } std::list > diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index e68cdd0c4..c6e85fba3 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -220,6 +220,7 @@ ADD_UNIT_TESTS( Test3019.py Test3087_1.py Test3087_2.py + Test3132.py TestArcBehavior.py TestBSplineAddPole.py TestChangeSketchPlane1.py diff --git a/src/SketchPlugin/SketchPlugin_Split.cpp b/src/SketchPlugin/SketchPlugin_Split.cpp index b0a5658ff..62dad8c5f 100644 --- a/src/SketchPlugin/SketchPlugin_Split.cpp +++ b/src/SketchPlugin/SketchPlugin_Split.cpp @@ -1164,8 +1164,16 @@ FeaturePtr SketchPlugin_Split::splitClosed(FeaturePtr& theSplitFeature, aRefsToParent.push_back(*aRef); } for (std::list::iterator aRef = aRefsToParent.begin(); - aRef != aRefsToParent.end(); ++aRef) - std::dynamic_pointer_cast(*aRef)->setValue(theSplitFeature); + aRef != aRefsToParent.end(); ++aRef) { + std::dynamic_pointer_cast(*aRef)->setValue( + theBaseFeatureModified); + + FeaturePtr anOwner = ModelAPI_Feature::feature((*aRef)->owner()); + SketchPlugin_Tools::replaceInName(anOwner, + aBaseFeature->name(), theBaseFeatureModified->name()); + SketchPlugin_Tools::replaceInName(anOwner->lastResult(), + aBaseFeature->name(), theBaseFeatureModified->name()); + } } theCreatedFeatures.insert(theBaseFeatureModified); diff --git a/src/SketchPlugin/SketchPlugin_Tools.cpp b/src/SketchPlugin/SketchPlugin_Tools.cpp index 0147ba521..df8e35cf6 100644 --- a/src/SketchPlugin/SketchPlugin_Tools.cpp +++ b/src/SketchPlugin/SketchPlugin_Tools.cpp @@ -563,6 +563,17 @@ 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) +{ + std::string 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()); + theObject->data()->setName(aNewName); + } +} + } // namespace SketchPlugin_Tools diff --git a/src/SketchPlugin/SketchPlugin_Tools.h b/src/SketchPlugin/SketchPlugin_Tools.h index a45ecf05a..1a12945c9 100644 --- a/src/SketchPlugin/SketchPlugin_Tools.h +++ b/src/SketchPlugin/SketchPlugin_Tools.h @@ -146,6 +146,9 @@ void customizeFeaturePrs(const AISObjectPtr& thePrs, bool isAxiliary); void setDimensionColor(const AISObjectPtr& theDimPrs); +/// Replace string in the name of object +void replaceInName(ObjectPtr theObject, const std::string& theSource, const std::string& theDest); + }; // namespace SketchPlugin_Tools namespace SketchPlugin_SegmentationTools diff --git a/src/SketchPlugin/SketchPlugin_Trim.cpp b/src/SketchPlugin/SketchPlugin_Trim.cpp index 2957e0315..1b56a1884 100644 --- a/src/SketchPlugin/SketchPlugin_Trim.cpp +++ b/src/SketchPlugin/SketchPlugin_Trim.cpp @@ -1065,8 +1065,14 @@ FeaturePtr SketchPlugin_Trim::trimClosed(const std::shared_ptr& t aRefsToParent.push_back(*aRef); } for (std::list::iterator aRef = aRefsToParent.begin(); - aRef != aRefsToParent.end(); ++aRef) + aRef != aRefsToParent.end(); ++aRef) { std::dynamic_pointer_cast(*aRef)->setValue(anNewFeature); + + FeaturePtr anOwner = ModelAPI_Feature::feature((*aRef)->owner()); + SketchPlugin_Tools::replaceInName(anOwner, aBaseFeature->name(), anNewFeature->name()); + SketchPlugin_Tools::replaceInName(anOwner->lastResult(), + aBaseFeature->name(), anNewFeature->name()); + } } const std::string& aStartAttrName = anNewFeature->getKind() == SketchPlugin_Arc::ID() ? diff --git a/src/SketchPlugin/Test/Test3132.py b/src/SketchPlugin/Test/Test3132.py new file mode 100644 index 000000000..7dbba3259 --- /dev/null +++ b/src/SketchPlugin/Test/Test3132.py @@ -0,0 +1,67 @@ +# Copyright (C) 2020 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 +# + +from salome.shaper import model +from GeomAPI import * +import math + +ELL_CENTER_X = 10 +ELL_CENTER_Y = 10 +ELL_MAJOR_RAD = 30 +ELL_MINOR_RAD = 15 +DOF_1 = 5 +DOF_2 = 9 + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchEllipse_1 = Sketch_1.addEllipse(ELL_CENTER_X, ELL_CENTER_Y, ELL_CENTER_X + math.sqrt(ELL_MAJOR_RAD**2 + ELL_MINOR_RAD**2), ELL_CENTER_Y, ELL_MINOR_RAD) +[SketchPoint_1, SketchPoint_2, SketchPoint_3, SketchPoint_4, SketchPoint_5, SketchPoint_6, SketchPoint_7, SketchLine_1, SketchLine_2] = SketchEllipse_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux") +model.do() +assert(model.dof(Sketch_1) == DOF_1) + +# trim the ellipse +ANGLE = math.pi/4 +Sketch_1.addTrim(SketchEllipse_1.feature(), GeomAPI_Pnt2d(ELL_CENTER_X + ELL_MAJOR_RAD * math.cos(ANGLE), ELL_CENTER_Y + ELL_MINOR_RAD * math.sin(ANGLE))) +model.do() +assert(model.dof(Sketch_1) == DOF_1) + +Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchEllipse_2 = Sketch_2.addEllipse(ELL_CENTER_X, ELL_CENTER_Y, ELL_CENTER_X + math.sqrt(ELL_MAJOR_RAD**2 + ELL_MINOR_RAD**2), ELL_CENTER_Y, ELL_MINOR_RAD) +[SketchPoint_8, SketchPoint_9, SketchPoint_10, SketchPoint_11, SketchPoint_12, SketchPoint_13, SketchPoint_14, SketchLine_3, SketchLine_4] = SketchEllipse_2.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux") +SketchLine_5 = Sketch_2.addLine(15.23538168732762, 24.77570901315218, 37.44845404222143, 43.05543771157006) +SketchConstraintCoincidence_3 = Sketch_2.setCoincident(SketchLine_5.startPoint(), SketchEllipse_2.result()) +SketchLine_6 = Sketch_2.addLine(37.44845404222143, 43.05543771157006, 37.66137837703927, 15.83721541173749) +SketchConstraintCoincidence_4 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintCoincidence_5 = Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchEllipse_2.result()) +model.do() +assert(model.dof(Sketch_2) == DOF_2) + +# split the ellipse +Sketch_2.addSplit(SketchEllipse_2.feature(), GeomAPI_Pnt2d(ELL_CENTER_X + ELL_MAJOR_RAD * math.cos(ANGLE), ELL_CENTER_Y + ELL_MINOR_RAD * math.sin(ANGLE))) +DOF_2 += 3 +model.do() +assert(model.dof(Sketch_2) == DOF_2) + + +model.end() + +assert(model.checkPythonDump()) -- 2.39.2