From 2e2c12219bf1c411787b3a0fce59f50faf4dfcd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Sat, 18 Feb 2017 12:26:23 +0100 Subject: [PATCH] Partially fix PartDesign move test --- src/Mod/PartDesign/App/Body.cpp | 17 +++-- src/Mod/PartDesign/App/Body.h | 1 + src/Mod/PartDesign/Gui/CommandBody.cpp | 34 ++++++--- src/Mod/PartDesign/TestPartDesignGui.py | 94 ++++++++++++------------- 4 files changed, 87 insertions(+), 59 deletions(-) diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index ca713c5571..7e4f67b644 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -271,12 +271,12 @@ std::vector Body::addObject(App::DocumentObject *feature) throw Base::Exception("Body: object is not allowed"); //TODO: features should not add all links - /* - //only one group per object + + //only one group per object. If it is in a body the single feature will be removed auto *group = App::GroupExtension::getGroupOfObject(feature); if(group && group != getExtendedObject()) - group->getExtensionByType()->removeObject(feature); - */ + group->getExtensionByType()->removeObject(feature); + insertObject (feature, getNextSolidFeature (), /*after = */ false); // Move the Tip if we added a solid @@ -288,6 +288,15 @@ std::vector Body::addObject(App::DocumentObject *feature) return result; } +std::vector< App::DocumentObject* > Body::addObjects(std::vector< App::DocumentObject* > objs) { + + for(auto obj : objs) + addObject(obj); + + return objs; +} + + void Body::insertObject(App::DocumentObject* feature, App::DocumentObject* target, bool after) { diff --git a/src/Mod/PartDesign/App/Body.h b/src/Mod/PartDesign/App/Body.h index 04efa9a88b..f623bce196 100644 --- a/src/Mod/PartDesign/App/Body.h +++ b/src/Mod/PartDesign/App/Body.h @@ -69,6 +69,7 @@ public: * The insertion poin is the before next solid after the Tip feature */ virtual std::vector addObject(App::DocumentObject*) override; + virtual std::vector< DocumentObject* > addObjects(std::vector< DocumentObject* > obj) override; /** * Insert the feature into the body after the given feature. diff --git a/src/Mod/PartDesign/Gui/CommandBody.cpp b/src/Mod/PartDesign/Gui/CommandBody.cpp index 4b1df7b51c..cc890c44c1 100644 --- a/src/Mod/PartDesign/Gui/CommandBody.cpp +++ b/src/Mod/PartDesign/Gui/CommandBody.cpp @@ -614,10 +614,7 @@ CmdPartDesignMoveFeature::CmdPartDesignMoveFeature() } void CmdPartDesignMoveFeature::activated(int iMsg) -{ - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Features moving is diabled"), - QObject::tr("Moving features is currently disabled as there is no way of handling origin connected moves")); - /* +{ Q_UNUSED(iMsg); std::vector features = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); if (features.empty()) return; @@ -644,6 +641,15 @@ void CmdPartDesignMoveFeature::activated(int iMsg) PartDesign::Body* source = PartDesign::Body::findBodyOf(feat); source_bodies.insert(static_cast(source)); } + + if(source_bodies.size() != 1) { + //show messagebox and cancel + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Features cannot be moved"), + QObject::tr("Only features of a single source Body can be moved")); + return; + } + + auto source_body = *source_bodies.begin(); std::vector target_bodies; for (auto body : bodies) { @@ -675,8 +681,20 @@ void CmdPartDesignMoveFeature::activated(int iMsg) PartDesign::Body* target = static_cast(target_bodies[index]); openCommand("Move an object"); - - for (auto feat: features) { + + std::stringstream stream; + stream << "features_ = [App.ActiveDocument." << features.back()->getNameInDocument(); + features.pop_back(); + + for (auto feat: features) + stream << ", App.ActiveDocument." << feat->getNameInDocument(); + + stream << "]"; + doCommand(Doc, stream.str().c_str()); + doCommand(Doc, "App.ActiveDocument.%s.removeObjects(features_)", source_body->getNameInDocument()); + doCommand(Doc, "App.ActiveDocument.%s.addObjects(features_)", target->getNameInDocument()); + /* + // Find body of this feature Part::BodyBase* source = PartDesign::Body::findBodyOf(feat); bool featureWasTip = false; @@ -732,9 +750,9 @@ void CmdPartDesignMoveFeature::activated(int iMsg) //relink origin for sketches and datums (coordinates) PartDesignGui::relinkToOrigin(feat, target); - } + }*/ - updateActive();*/ + updateActive(); } bool CmdPartDesignMoveFeature::isActive(void) diff --git a/src/Mod/PartDesign/TestPartDesignGui.py b/src/Mod/PartDesign/TestPartDesignGui.py index 5daa2d4db0..87e5b6769e 100644 --- a/src/Mod/PartDesign/TestPartDesignGui.py +++ b/src/Mod/PartDesign/TestPartDesignGui.py @@ -146,61 +146,61 @@ class PartDesignGuiTestCases(unittest.TestCase): #self.assertEqual(len(self.BodySource.Group), 3, "Source body feature count is wrong") #self.assertEqual(len(self.BodyTarget.Group), 0, "Target body feature count is wrong") - #def testMoveSingleFeature(self): - #FreeCAD.Console.PrintMessage('Testing moving one feature from one body to another\n') - #self.BodySource = self.Doc.addObject('PartDesign::Body','Body') - #Gui.activeView().setActiveObject('pdbody', self.BodySource) + def testMoveSingleFeature(self): + FreeCAD.Console.PrintMessage('Testing moving one feature from one body to another\n') + self.BodySource = self.Doc.addObject('PartDesign::Body','Body') + Gui.activeView().setActiveObject('pdbody', self.BodySource) - #self.Sketch = self.Doc.addObject('Sketcher::SketchObject','Sketch') - #self.BodySource.addObject(self.Sketch) - #self.Sketch.Support = (self.BodySource.Origin.OriginFeatures[3], ['']) - #self.Sketch.MapMode = 'FlatFace' + self.Sketch = self.Doc.addObject('Sketcher::SketchObject','Sketch') + self.BodySource.addObject(self.Sketch) + self.Sketch.Support = (self.BodySource.Origin.OriginFeatures[3], ['']) + self.Sketch.MapMode = 'FlatFace' - #geoList = [] - #geoList.append(Part.LineSegment(App.Vector(-10.000000,10.000000,0),App.Vector(10.000000,10.000000,0))) - #geoList.append(Part.LineSegment(App.Vector(10.000000,10.000000,0),App.Vector(10.000000,-10.000000,0))) - #geoList.append(Part.LineSegment(App.Vector(10.000000,-10.000000,0),App.Vector(-10.000000,-10.000000,0))) - #geoList.append(Part.LineSegment(App.Vector(-10.000000,-10.000000,0),App.Vector(-10.000000,10.000000,0))) - #self.Sketch.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)) - #self.Sketch.addConstraint(conList) + geoList = [] + geoList.append(Part.LineSegment(App.Vector(-10.000000,10.000000,0),App.Vector(10.000000,10.000000,0))) + geoList.append(Part.LineSegment(App.Vector(10.000000,10.000000,0),App.Vector(10.000000,-10.000000,0))) + geoList.append(Part.LineSegment(App.Vector(10.000000,-10.000000,0),App.Vector(-10.000000,-10.000000,0))) + geoList.append(Part.LineSegment(App.Vector(-10.000000,-10.000000,0),App.Vector(-10.000000,10.000000,0))) + self.Sketch.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)) + self.Sketch.addConstraint(conList) - #self.Pad = self.Doc.addObject("PartDesign::Pad","Pad") - #self.BodySource.addObject(self.Pad) - #self.Pad.Profile = self.Sketch - #self.Pad.Length = 10.000000 - #self.Pad.Length2 = 100.000000 - #self.Pad.Type = 0 - #self.Pad.UpToFace = None - #self.Pad.Reversed = 0 - #self.Pad.Midplane = 0 - #self.Pad.Offset = 0.000000 + self.Pad = self.Doc.addObject("PartDesign::Pad","Pad") + self.BodySource.addObject(self.Pad) + self.Pad.Profile = self.Sketch + self.Pad.Length = 10.000000 + self.Pad.Length2 = 100.000000 + self.Pad.Type = 0 + self.Pad.UpToFace = None + self.Pad.Reversed = 0 + self.Pad.Midplane = 0 + self.Pad.Offset = 0.000000 - #self.Doc.recompute() - #Gui.SendMsgToActiveView("ViewFit") + self.Doc.recompute() + Gui.SendMsgToActiveView("ViewFit") - #self.BodyTarget = self.Doc.addObject('PartDesign::Body','Body') + self.BodyTarget = self.Doc.addObject('PartDesign::Body','Body') - #Gui.Selection.addSelection(App.ActiveDocument.Pad) - #cobj = CallableComboBox(self) - #QtCore.QTimer.singleShot(500, cobj) - #Gui.runCommand('PartDesign_MoveFeature') - ##assert depenedencies of the Sketch - #self.Doc.recompute() + Gui.Selection.addSelection(App.ActiveDocument.Pad) + cobj = CallableComboBox(self) + QtCore.QTimer.singleShot(500, cobj) + Gui.runCommand('PartDesign_MoveFeature') + #assert depenedencies of the Sketch + self.Doc.recompute() - #self.assertFalse(self.Sketch.Support[0][0] in self.BodySource.Origin.OriginFeatures) - #self.assertTrue(self.Sketch.Support[0][0] in self.BodyTarget.Origin.OriginFeatures) - #self.assertEqual(len(self.BodySource.Group), 0, "Source body feature count is wrong") - #self.assertEqual(len(self.BodyTarget.Group), 2, "Target body feature count is wrong") + self.assertFalse(self.Sketch.Support[0][0] in self.BodySource.Origin.OriginFeatures) + self.assertTrue(self.Sketch.Support[0][0] in self.BodyTarget.Origin.OriginFeatures) + self.assertEqual(len(self.BodySource.Group), 0, "Source body feature count is wrong") + self.assertEqual(len(self.BodyTarget.Group), 2, "Target body feature count is wrong") def tearDown(self): FreeCAD.closeDocument("SketchGuiTest")