From 36301ff67b6e165bddbabe5b63be0d90dd296cde Mon Sep 17 00:00:00 2001 From: Eivind Kvedalen Date: Mon, 6 Nov 2017 19:30:05 +0100 Subject: [PATCH] Sketcher: Fix for issue #3245, including regression test. --- .../Sketcher/App/PropertyConstraintList.cpp | 16 ++++++++--- src/Mod/Sketcher/TestSketcherApp.py | 28 ++++++++++++++++++- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/Mod/Sketcher/App/PropertyConstraintList.cpp b/src/Mod/Sketcher/App/PropertyConstraintList.cpp index e43c3b555c..4c761982f5 100644 --- a/src/Mod/Sketcher/App/PropertyConstraintList.cpp +++ b/src/Mod/Sketcher/App/PropertyConstraintList.cpp @@ -185,13 +185,19 @@ void PropertyConstraintList::applyValues(const std::vector& lValue) std::vector oldVals(_lValueList); std::map renamed; std::set removed; + std::set newRenamedPaths; /* Check for renames */ for (unsigned int i = 0; i < lValue.size(); i++) { boost::unordered_map::const_iterator j = valueMap.find(lValue[i]->tag); - if (j != valueMap.end() && (i != j->second || _lValueList[j->second]->Name != lValue[i]->Name) ) - renamed[makePath(j->second, _lValueList[j->second] )] = makePath(i, lValue[i]); + if (j != valueMap.end() && (i != j->second || _lValueList[j->second]->Name != lValue[i]->Name) ) { + App::ObjectIdentifier oid(makePath(i, lValue[i])); + renamed[makePath(j->second, _lValueList[j->second] )] = oid; + + /* Keep track of new paths */ + newRenamedPaths.insert(oid); + } } /* Update value map with new tags from new array */ @@ -206,9 +212,11 @@ void PropertyConstraintList::applyValues(const std::vector& lValue) /* Collect info about removed elements */ for (std::size_t i = 0; i < oldVals.size(); i++) { boost::unordered_map::const_iterator j = valueMap.find(oldVals[i]->tag); + App::ObjectIdentifier oid(makePath(i, oldVals[i])); - if (j == valueMap.end()) - removed.insert(makePath(i, oldVals[i])); + /* If not found in new values or a renamed expression takes its place, place it in the set to be removed */ + if (j == valueMap.end() && newRenamedPaths.find(oid) == newRenamedPaths.end()) + removed.insert(oid); } /* Signal removes */ diff --git a/src/Mod/Sketcher/TestSketcherApp.py b/src/Mod/Sketcher/TestSketcherApp.py index 9ed6c0ccf1..5729ece97e 100644 --- a/src/Mod/Sketcher/TestSketcherApp.py +++ b/src/Mod/Sketcher/TestSketcherApp.py @@ -153,7 +153,33 @@ class SketcherSolverTestCases(unittest.TestCase): CreateSlotPlateInnerSet(self.Slot) self.Doc.recompute() self.failUnless(len(self.Slot.Shape.Edges) == 9) - + + def testIssue3245(self): + self.Doc2 = FreeCAD.newDocument("Issue3245") + self.Doc2.addObject('Sketcher::SketchObject','Sketch') + self.Doc2.Sketch.Placement = App.Placement(App.Vector(0.000000,0.000000,0.000000),App.Rotation(0.000000,0.000000,0.000000,1.000000)) + self.Doc2.Sketch.MapMode = "Deactivated" + self.Doc2.Sketch.addGeometry(Part.LineSegment(App.Vector(-1.195999,56.041161,0),App.Vector(60.654316,56.382877,0)),False) + self.Doc2.Sketch.addConstraint(Sketcher.Constraint('PointOnObject',0,1,-2)) + self.Doc2.Sketch.addConstraint(Sketcher.Constraint('Horizontal',0)) + self.Doc2.Sketch.addGeometry(Part.LineSegment(App.Vector(0.512583,32.121155,0),App.Vector(60.654316,31.779440,0)),False) + self.Doc2.Sketch.addConstraint(Sketcher.Constraint('Horizontal',1)) + self.Doc2.Sketch.addGeometry(Part.LineSegment(App.Vector(0.170867,13.326859,0),App.Vector(61.679455,13.326859,0)),False) + self.Doc2.Sketch.addConstraint(Sketcher.Constraint('PointOnObject',2,1,-2)) + self.Doc2.Sketch.addConstraint(Sketcher.Constraint('Horizontal',2)) + self.Doc2.Sketch.addConstraint(Sketcher.Constraint('PointOnObject',1,1,-2)) + self.Doc2.Sketch.addConstraint(Sketcher.Constraint('DistanceX',0,1,0,2,60.654316)) + self.Doc2.Sketch.setExpression('Constraints[6]', u'60') + self.Doc2.Sketch.addConstraint(Sketcher.Constraint('DistanceX',1,1,1,2,60.654316)) + self.Doc2.Sketch.setExpression('Constraints[7]', u'65') + self.Doc2.Sketch.addConstraint(Sketcher.Constraint('DistanceX',2,1,2,2,61.679455)) + self.Doc2.Sketch.setExpression('Constraints[8]', u'70') + self.Doc2.recompute() + self.Doc2.Sketch.delGeometry(2) + values = d = {key: value for (key, value) in self.Doc2.Sketch.ExpressionEngine} + self.failUnless(values['Constraints[4]'] == u'60') + self.failUnless(values['Constraints[5]'] == u'65') + FreeCAD.closeDocument("Issue3245") def tearDown(self): #closing doc