Sketcher: Fix for issue #3245, including regression test.

This commit is contained in:
Eivind Kvedalen
2017-11-06 19:30:05 +01:00
committed by wmayer
parent 9c4b31a4aa
commit 36301ff67b
2 changed files with 39 additions and 5 deletions

View File

@@ -185,13 +185,19 @@ void PropertyConstraintList::applyValues(const std::vector<Constraint*>& lValue)
std::vector<Constraint*> oldVals(_lValueList);
std::map<App::ObjectIdentifier, App::ObjectIdentifier> renamed;
std::set<App::ObjectIdentifier> removed;
std::set<App::ObjectIdentifier> newRenamedPaths;
/* Check for renames */
for (unsigned int i = 0; i < lValue.size(); i++) {
boost::unordered_map<boost::uuids::uuid, std::size_t>::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<Constraint*>& lValue)
/* Collect info about removed elements */
for (std::size_t i = 0; i < oldVals.size(); i++) {
boost::unordered_map<boost::uuids::uuid, std::size_t>::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 */

View File

@@ -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