From 71f9f4824f41acca27c98244036ab43f5fe3fbe7 Mon Sep 17 00:00:00 2001 From: Eivind Kvedalen Date: Sat, 25 Nov 2017 19:39:57 +0100 Subject: [PATCH] Sketcher: Fixed regression in fix for issue #3245. --- .../Sketcher/App/PropertyConstraintList.cpp | 26 ++++++++-------- src/Mod/Sketcher/TestSketcherApp.py | 30 +++++++++++++++++++ 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/Mod/Sketcher/App/PropertyConstraintList.cpp b/src/Mod/Sketcher/App/PropertyConstraintList.cpp index 4c761982f5..61e59dec10 100644 --- a/src/Mod/Sketcher/App/PropertyConstraintList.cpp +++ b/src/Mod/Sketcher/App/PropertyConstraintList.cpp @@ -185,18 +185,16 @@ 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) ) { - App::ObjectIdentifier oid(makePath(i, lValue[i])); - renamed[makePath(j->second, _lValueList[j->second] )] = oid; - - /* Keep track of new paths */ - newRenamedPaths.insert(oid); + App::ObjectIdentifier old_oid(makePath(j->second, _lValueList[j->second] )); + App::ObjectIdentifier new_oid(makePath(i, lValue[i])); + + renamed[old_oid] = new_oid; } } @@ -205,24 +203,24 @@ void PropertyConstraintList::applyValues(const std::vector& lValue) for (std::size_t i = 0; i < lValue.size(); i++) valueMap[lValue[i]->tag] = i; - /* Signal renames */ - if (renamed.size() > 0) - signalConstraintsRenamed(renamed); - /* 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 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()) + /* If not found in new values, place it in the set to be removed */ + if (j == valueMap.end()) removed.insert(oid); } - /* Signal removes */ + /* Signal removes first, in case renamed values below have the same names as some of the removed ones. */ if (removed.size() > 0) signalConstraintsRemoved(removed); + /* Signal renames */ + if (renamed.size() > 0) + signalConstraintsRenamed(renamed); + /* Resize array to new size */ _lValueList.resize(lValue.size()); diff --git a/src/Mod/Sketcher/TestSketcherApp.py b/src/Mod/Sketcher/TestSketcherApp.py index 5729ece97e..fae88b195c 100644 --- a/src/Mod/Sketcher/TestSketcherApp.py +++ b/src/Mod/Sketcher/TestSketcherApp.py @@ -180,6 +180,36 @@ class SketcherSolverTestCases(unittest.TestCase): self.failUnless(values['Constraints[4]'] == u'60') self.failUnless(values['Constraints[5]'] == u'65') FreeCAD.closeDocument("Issue3245") + + def testIssue3245_2(self): + self.Doc2 = FreeCAD.newDocument("Issue3245") + ActiveSketch = self.Doc2.addObject('Sketcher::SketchObject','Sketch') + ActiveSketch.Placement = App.Placement(App.Vector(0.000000,0.000000,0.000000),App.Rotation(0.000000,0.000000,0.000000,1.000000)) + ActiveSketch.MapMode = "Deactivated" + geoList = [] + geoList.append(Part.LineSegment(App.Vector(-23.574591,42.399727,0),App.Vector(81.949776,42.399727,0))) + geoList.append(Part.LineSegment(App.Vector(81.949776,42.399727,0),App.Vector(81.949776,-19.256901,0))) + geoList.append(Part.LineSegment(App.Vector(81.949776,-19.256901,0),App.Vector(-23.574591,-19.256901,0))) + geoList.append(Part.LineSegment(App.Vector(-23.574591,-19.256901,0),App.Vector(-23.574591,42.399727,0))) + ActiveSketch.addGeometry(geoList,False) + conList = [] + conList.append(Sketcher.Constraint('Coincident',0,2,1,1)) + conList.append(Sketcher.Constraint('Coincident',1,2,2,1)) + conList.append(Sketcher.Constraint('Coincident',2,2,3,1)) + conList.append(Sketcher.Constraint('Coincident',3,2,0,1)) + conList.append(Sketcher.Constraint('Horizontal',0)) + conList.append(Sketcher.Constraint('Horizontal',2)) + conList.append(Sketcher.Constraint('Vertical',1)) + conList.append(Sketcher.Constraint('Vertical',3)) + ActiveSketch.addConstraint(conList) + ActiveSketch.addConstraint(Sketcher.Constraint('DistanceX',0,1,0,2,105.524367)) + ActiveSketch.setExpression('Constraints[8]', u'10 + 10') + ActiveSketch.addConstraint(Sketcher.Constraint('DistanceY',3,1,3,2,61.656628)) + ActiveSketch.setDatum(9,App.Units.Quantity('5.000000 mm')) + ActiveSketch.delConstraint(8) + values = d = {key: value for (key, value) in self.Doc2.Sketch.ExpressionEngine} + self.Doc2.recompute() + self.failUnless(len(values) == 0) def tearDown(self): #closing doc