Salome HOME
Issue #3132: number DOF differs after dump/load script
authorazv <azv@opencascade.com>
Fri, 7 Feb 2020 07:23:44 +0000 (10:23 +0300)
committervsr <vsr@opencascade.com>
Mon, 10 Feb 2020 14:12:02 +0000 (17:12 +0300)
Fix the naming while trim/split an ellipse

src/SketchAPI/SketchAPI_SketchEntity.cpp
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Split.cpp
src/SketchPlugin/SketchPlugin_Tools.cpp
src/SketchPlugin/SketchPlugin_Tools.h
src/SketchPlugin/SketchPlugin_Trim.cpp
src/SketchPlugin/Test/Test3132.py [new file with mode: 0644]

index fa56e6a5c95e1a46f20955d83e6e024390f3811a..189c1f6e080b56c7115540188ce317b75ee18bd4 100644 (file)
@@ -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<std::shared_ptr<SketchAPI_SketchEntity> >
index e68cdd0c42b936eafa64ec383239804ee09df74b..c6e85fba300e5e60c16cee2521294998c538cb40 100644 (file)
@@ -220,6 +220,7 @@ ADD_UNIT_TESTS(
   Test3019.py
   Test3087_1.py
   Test3087_2.py
+  Test3132.py
   TestArcBehavior.py
   TestBSplineAddPole.py
   TestChangeSketchPlane1.py
index b0a5658ffef5145a4ee4c13906f34caa50aed772..62dad8c5fd74ef09b9ba09aaec9dd06b41c06229 100644 (file)
@@ -1164,8 +1164,16 @@ FeaturePtr SketchPlugin_Split::splitClosed(FeaturePtr& theSplitFeature,
         aRefsToParent.push_back(*aRef);
     }
     for (std::list<AttributePtr>::iterator aRef = aRefsToParent.begin();
-         aRef != aRefsToParent.end(); ++aRef)
-      std::dynamic_pointer_cast<ModelAPI_AttributeReference>(*aRef)->setValue(theSplitFeature);
+         aRef != aRefsToParent.end(); ++aRef) {
+      std::dynamic_pointer_cast<ModelAPI_AttributeReference>(*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);
index 0147ba521d38ed1f2be00ff5aa870a3d85f3f6a3..df8e35cf60ccad6dddc455524dc1dda558dbfaac 100644 (file)
@@ -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
 
 
index a45ecf05a85899eeef033f8964028dabdc8e3e9c..1a12945c955a508a0c5a81a82266aa2bea2b9725 100644 (file)
@@ -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
index 2957e031573500609257d190e2295300248c2712..1b56a1884172e56678eabd384099c077a0090e54 100644 (file)
@@ -1065,8 +1065,14 @@ FeaturePtr SketchPlugin_Trim::trimClosed(const std::shared_ptr<GeomAPI_Pnt2d>& t
         aRefsToParent.push_back(*aRef);
     }
     for (std::list<AttributePtr>::iterator aRef = aRefsToParent.begin();
-         aRef != aRefsToParent.end(); ++aRef)
+         aRef != aRefsToParent.end(); ++aRef) {
       std::dynamic_pointer_cast<ModelAPI_AttributeReference>(*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 (file)
index 0000000..7dbba32
--- /dev/null
@@ -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())