diff --git a/src/Mod/PartDesign/Gui/CommandBody.cpp b/src/Mod/PartDesign/Gui/CommandBody.cpp index ed86fb7f8999..85536c42f3f9 100644 --- a/src/Mod/PartDesign/Gui/CommandBody.cpp +++ b/src/Mod/PartDesign/Gui/CommandBody.cpp @@ -587,48 +587,48 @@ void CmdPartDesignMoveFeature::activated(int iMsg) std::vector features = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); if (features.empty()) return; - // Check if all features are valid to move - if (std::any_of(std::begin(features), std::end(features), [](App::DocumentObject* obj){return !PartDesignGui::isFeatureMovable(obj); })) - { - //show messagebox and cancel - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Features cannot be moved"), - QObject::tr("Some of the selected features have dependencies in the source body")); - return; - } - - // Collect dependenies of the selected features - std::vector dependencies = PartDesignGui::collectMovableDependencies(features); - if (!dependencies.empty()) - features.insert(std::end(features), std::begin(dependencies), std::end(dependencies)); + // Check if all features are valid to move + if (std::any_of(std::begin(features), std::end(features), [](App::DocumentObject* obj){return !PartDesignGui::isFeatureMovable(obj); })) + { + //show messagebox and cancel + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Features cannot be moved"), + QObject::tr("Some of the selected features have dependencies in the source body")); + return; + } + + // Collect dependenies of the selected features + std::vector dependencies = PartDesignGui::collectMovableDependencies(features); + if (!dependencies.empty()) + features.insert(std::end(features), std::begin(dependencies), std::end(dependencies)); // Create a list of all bodies in this part std::vector bodies = getDocument()->getObjectsOfType(Part::BodyBase::getClassTypeId()); - - std::set source_bodies; - for (auto feat : features) { - PartDesign::Body* source = PartDesign::Body::findBodyOf(feat); - source_bodies.insert(static_cast(source)); - } - - std::vector target_bodies; - for (auto body : bodies) { - if (!source_bodies.count(body)) - target_bodies.push_back(body); - } - - if (target_bodies.empty()) - { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Features cannot be moved"), - QObject::tr("There are no other bodies to move to")); - return; - } + + std::set source_bodies; + for (auto feat : features) { + PartDesign::Body* source = PartDesign::Body::findBodyOf(feat); + source_bodies.insert(static_cast(source)); + } + + std::vector target_bodies; + for (auto body : bodies) { + if (!source_bodies.count(body)) + target_bodies.push_back(body); + } + + if (target_bodies.empty()) + { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Features cannot be moved"), + QObject::tr("There are no other bodies to move to")); + return; + } // Ask user to select the target body (remove source bodies from list) bool ok; QStringList items; - for (auto body : target_bodies) { - items.push_back(QString::fromUtf8(body->Label.getValue())); - } + for (auto body : target_bodies) { + items.push_back(QString::fromUtf8(body->Label.getValue())); + } QString text = QInputDialog::getItem(Gui::getMainWindow(), qApp->translate("PartDesign_MoveFeature", "Select body"), qApp->translate("PartDesign_MoveFeature", "Select a body from the list"), @@ -637,7 +637,7 @@ void CmdPartDesignMoveFeature::activated(int iMsg) int index = items.indexOf(text); if (index < 0) return; - PartDesign::Body* target = static_cast(target_bodies[index]); + PartDesign::Body* target = static_cast(target_bodies[index]); openCommand("Move an object"); @@ -668,8 +668,8 @@ void CmdPartDesignMoveFeature::activated(int iMsg) // If we removed the tip of the source body, make the new tip visible if ( featureWasTip ) { App::DocumentObject * sourceNewTip = source->Tip.getValue(); - if (sourceNewTip) - doCommand(Gui,"Gui.activeDocument().show(\"%s\")", sourceNewTip->getNameInDocument()); + if (sourceNewTip) + doCommand(Gui,"Gui.activeDocument().show(\"%s\")", sourceNewTip->getNameInDocument()); } // Hide old tip and show new tip (the moved feature) of the target body @@ -695,8 +695,8 @@ void CmdPartDesignMoveFeature::activated(int iMsg) } } - //relink origin for sketches and datums (coordinates) - PartDesignGui::relinkToOrigin(feat, target); + //relink origin for sketches and datums (coordinates) + PartDesignGui::relinkToOrigin(feat, target); } updateActive(); diff --git a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp index a8c8fcdbb546..02ef4fd56f20 100644 --- a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp @@ -715,7 +715,7 @@ bool TaskDlgPipeParameters::accept() //the user has to decide which option we should take if external references are used PartDesign::Pipe* pcPipe = static_cast(getPipeView()->getObject()); auto pcActiveBody = PartDesignGui::getBodyFor(pcPipe, false); - auto pcActivePart = PartDesignGui::getPartFor(pcActiveBody, false); + //auto pcActivePart = PartDesignGui::getPartFor(pcActiveBody, false); std::vector copies; bool ext = false; diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index ddb234a3b3d3..14dbc33ae3e7 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -348,142 +348,142 @@ void relinkToBody (PartDesign::Feature *feature) { bool isFeatureMovable(App::DocumentObject* const feat) { - if (feat->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId())) { - auto prim = static_cast(feat); - App::DocumentObject* bf = prim->BaseFeature.getValue(); - if (bf) - return false; - } - - if (feat->getTypeId().isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId())) { - auto prim = static_cast(feat); - - if (!isFeatureMovable(prim->CoordinateSystem.getValue())) - return false; - } - - if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) { - auto prim = static_cast(feat); - auto sk = prim->getVerifiedSketch(true); - - if (!isFeatureMovable(static_cast(sk))) - return false; - - if (auto prop = static_cast(prim->getPropertyByName("Sections"))) { - if (std::any_of(prop->getValues().begin(), prop->getValues().end(), [](App::DocumentObject* obj){return !isFeatureMovable(obj); })) - return false; - } - - if (auto prop = static_cast(prim->getPropertyByName("ReferenceAxis"))) { - App::DocumentObject* axis = prop->getValue(); - if (!isFeatureMovable(static_cast(axis))) - return false; - } - - if (auto prop = static_cast(prim->getPropertyByName("Spine"))) { - App::DocumentObject* axis = prop->getValue(); - if (!isFeatureMovable(static_cast(axis))) - return false; - } - - if (auto prop = static_cast(prim->getPropertyByName("AuxillerySpine"))) { - App::DocumentObject* axis = prop->getValue(); - if (!isFeatureMovable(static_cast(axis))) - return false; - } - - } - - if (feat->getTypeId().isDerivedFrom(Part::AttachableObject::getClassTypeId())) { - auto attachable = static_cast(feat); - App::DocumentObject* support = attachable->Support.getValue(); - if (support && !support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())) - return false; - } - - return true; + if (feat->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId())) { + auto prim = static_cast(feat); + App::DocumentObject* bf = prim->BaseFeature.getValue(); + if (bf) + return false; + } + + if (feat->getTypeId().isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId())) { + auto prim = static_cast(feat); + + if (!isFeatureMovable(prim->CoordinateSystem.getValue())) + return false; + } + + if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) { + auto prim = static_cast(feat); + auto sk = prim->getVerifiedSketch(true); + + if (!isFeatureMovable(static_cast(sk))) + return false; + + if (auto prop = static_cast(prim->getPropertyByName("Sections"))) { + if (std::any_of(prop->getValues().begin(), prop->getValues().end(), [](App::DocumentObject* obj){return !isFeatureMovable(obj); })) + return false; + } + + if (auto prop = static_cast(prim->getPropertyByName("ReferenceAxis"))) { + App::DocumentObject* axis = prop->getValue(); + if (!isFeatureMovable(static_cast(axis))) + return false; + } + + if (auto prop = static_cast(prim->getPropertyByName("Spine"))) { + App::DocumentObject* axis = prop->getValue(); + if (!isFeatureMovable(static_cast(axis))) + return false; + } + + if (auto prop = static_cast(prim->getPropertyByName("AuxillerySpine"))) { + App::DocumentObject* axis = prop->getValue(); + if (!isFeatureMovable(static_cast(axis))) + return false; + } + + } + + if (feat->getTypeId().isDerivedFrom(Part::AttachableObject::getClassTypeId())) { + auto attachable = static_cast(feat); + App::DocumentObject* support = attachable->Support.getValue(); + if (support && !support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())) + return false; + } + + return true; } std::vector collectMovableDependencies(std::vector& features) { - std::set unique_objs; - - for (auto const &feat : features) - { - // Get coordinate system object - if (feat->getTypeId().isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId())) { - auto prim = static_cast(feat); - App::DocumentObject* cs = prim->CoordinateSystem.getValue(); - if (cs && cs->getTypeId() == PartDesign::CoordinateSystem::getClassTypeId()) - unique_objs.insert(cs); - } - - // Get sketches and datums from profile based features - if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) { - auto prim = static_cast(feat); - Part::Part2DObject* sk = prim->getVerifiedSketch(true); - if (sk) { - unique_objs.insert(static_cast(sk)); - } - if (auto prop = static_cast(prim->getPropertyByName("Sections"))) { - for (App::DocumentObject* obj : prop->getValues()) { - unique_objs.insert(obj); - } - } - if (auto prop = static_cast(prim->getPropertyByName("ReferenceAxis"))) { - App::DocumentObject* axis = prop->getValue(); - if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){ - unique_objs.insert(axis); - } - } - if (auto prop = static_cast(prim->getPropertyByName("Spine"))) { - App::DocumentObject* axis = prop->getValue(); - if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){ - unique_objs.insert(axis); - } - } - if (auto prop = static_cast(prim->getPropertyByName("AuxillerySpine"))) { - App::DocumentObject* axis = prop->getValue(); - if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){ - unique_objs.insert(axis); - } - } - } - } - - std::vector result; - result.reserve(unique_objs.size()); - result.insert(result.begin(), unique_objs.begin(), unique_objs.end()); - - return result; + std::set unique_objs; + + for (auto const &feat : features) + { + // Get coordinate system object + if (feat->getTypeId().isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId())) { + auto prim = static_cast(feat); + App::DocumentObject* cs = prim->CoordinateSystem.getValue(); + if (cs && cs->getTypeId() == PartDesign::CoordinateSystem::getClassTypeId()) + unique_objs.insert(cs); + } + + // Get sketches and datums from profile based features + if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) { + auto prim = static_cast(feat); + Part::Part2DObject* sk = prim->getVerifiedSketch(true); + if (sk) { + unique_objs.insert(static_cast(sk)); + } + if (auto prop = static_cast(prim->getPropertyByName("Sections"))) { + for (App::DocumentObject* obj : prop->getValues()) { + unique_objs.insert(obj); + } + } + if (auto prop = static_cast(prim->getPropertyByName("ReferenceAxis"))) { + App::DocumentObject* axis = prop->getValue(); + if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){ + unique_objs.insert(axis); + } + } + if (auto prop = static_cast(prim->getPropertyByName("Spine"))) { + App::DocumentObject* axis = prop->getValue(); + if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){ + unique_objs.insert(axis); + } + } + if (auto prop = static_cast(prim->getPropertyByName("AuxillerySpine"))) { + App::DocumentObject* axis = prop->getValue(); + if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){ + unique_objs.insert(axis); + } + } + } + } + + std::vector result; + result.reserve(unique_objs.size()); + result.insert(result.begin(), unique_objs.begin(), unique_objs.end()); + + return result; } void relinkToOrigin(App::DocumentObject* feat, PartDesign::Body* targetbody) { - if (feat->getTypeId().isDerivedFrom(Part::AttachableObject::getClassTypeId())) { - auto attachable = static_cast(feat); - App::DocumentObject* support = attachable->Support.getValue(); - if (support && support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())) { - auto originfeat = static_cast(support); - App::OriginFeature* targetOriginFeature = targetbody->getOrigin()->getOriginFeature(originfeat->Role.getValue()); - if (targetOriginFeature) { - attachable->Support.setValue(static_cast(targetOriginFeature), ""); - } - } - } - else if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) { - auto prim = static_cast(feat); - if (auto prop = static_cast(prim->getPropertyByName("ReferenceAxis"))) { - App::DocumentObject* axis = prop->getValue(); - if (axis && axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){ - auto originfeat = static_cast(axis); - App::OriginFeature* targetOriginFeature = targetbody->getOrigin()->getOriginFeature(originfeat->Role.getValue()); - if (targetOriginFeature) { - prop->setValue(static_cast(targetOriginFeature), std::vector(0)); - } - } - } - } + if (feat->getTypeId().isDerivedFrom(Part::AttachableObject::getClassTypeId())) { + auto attachable = static_cast(feat); + App::DocumentObject* support = attachable->Support.getValue(); + if (support && support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())) { + auto originfeat = static_cast(support); + App::OriginFeature* targetOriginFeature = targetbody->getOrigin()->getOriginFeature(originfeat->Role.getValue()); + if (targetOriginFeature) { + attachable->Support.setValue(static_cast(targetOriginFeature), ""); + } + } + } + else if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) { + auto prim = static_cast(feat); + if (auto prop = static_cast(prim->getPropertyByName("ReferenceAxis"))) { + App::DocumentObject* axis = prop->getValue(); + if (axis && axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){ + auto originfeat = static_cast(axis); + App::OriginFeature* targetOriginFeature = targetbody->getOrigin()->getOriginFeature(originfeat->Role.getValue()); + if (targetOriginFeature) { + prop->setValue(static_cast(targetOriginFeature), std::vector(0)); + } + } + } + } } -} /* PartDesignGui */ \ No newline at end of file +} /* PartDesignGui */ diff --git a/src/Mod/PartDesign/TestPartDesignGui.py b/src/Mod/PartDesign/TestPartDesignGui.py index 08144711e32d..33513cbb7f57 100644 --- a/src/Mod/PartDesign/TestPartDesignGui.py +++ b/src/Mod/PartDesign/TestPartDesignGui.py @@ -34,26 +34,26 @@ #timer runs this class in order to access modal dialog class CallableCheckWarning: - def __init__(self, test): - self.test = test - def __call__(self): - diag = QApplication.activeModalWidget() - self.test.assertIsNotNone(diag, "Input dialog box could not be found") - if (diag != None): - QtCore.QTimer.singleShot(0, diag, QtCore.SLOT('accept()')) + def __init__(self, test): + self.test = test + def __call__(self): + diag = QApplication.activeModalWidget() + self.test.assertIsNotNone(diag, "Input dialog box could not be found") + if (diag != None): + QtCore.QTimer.singleShot(0, diag, QtCore.SLOT('accept()')) class CallableComboBox: - def __init__(self, test): - self.test = test - def __call__(self): - diag = QApplication.activeModalWidget() - self.test.assertIsNotNone(diag, "Warning dialog box could not be found") - if (diag != None): - cbox = diag.findChild(QtGui.QComboBox) - self.test.assertIsNotNone(cbox, "ComboBox widget could not be found") - if (cbox != None): - cbox.setCurrentIndex(1) - QtCore.QTimer.singleShot(0, diag, QtCore.SLOT('accept()')) + def __init__(self, test): + self.test = test + def __call__(self): + diag = QApplication.activeModalWidget() + self.test.assertIsNotNone(diag, "Warning dialog box could not be found") + if (diag != None): + cbox = diag.findChild(QtGui.QComboBox) + self.test.assertIsNotNone(cbox, "ComboBox widget could not be found") + if (cbox != None): + cbox.setCurrentIndex(1) + QtCore.QTimer.singleShot(0, diag, QtCore.SLOT('accept()')) App = FreeCAD Gui = FreeCADGui @@ -61,129 +61,129 @@ def __call__(self): # define the test cases to test the FreeCAD PartDesign module #--------------------------------------------------------------------------- class PartDesignGuiTestCases(unittest.TestCase): - def setUp(self): - self.Doc = FreeCAD.newDocument("SketchGuiTest") - - def testRefuseToMoveSingleFeature(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.BoxObj = self.Doc.addObject('PartDesign::AdditiveBox','Box') - self.BoxObj.Length=10.0 - self.BoxObj.Width=10.0 - self.BoxObj.Height=10.0 - self.BodySource.addFeature(self.BoxObj) - - self.BoxCoords = self.Doc.addObject('PartDesign::CoordinateSystem','CoordinateSystem') - self.BodySource.addFeature(self.BoxCoords) - self.BoxObj.CoordinateSystem=(self.BoxCoords) - App.ActiveDocument.recompute() - Gui.activeDocument().hide('CoordinateSystem') - - self.Sketch = self.Doc.addObject('Sketcher::SketchObject','Sketch') - self.Sketch.Support = (self.BoxObj, ('Face3',)) - self.Sketch.MapMode = 'FlatFace' - self.BodySource.addFeature(self.Sketch) - - geoList = [] - geoList.append(Part.Line(App.Vector(2.0,8.0,0),App.Vector(8.0,8.0,0))) - geoList.append(Part.Line(App.Vector(8.0,8.0,0),App.Vector(8.0,2.0,0))) - geoList.append(Part.Line(App.Vector(8.0,2.0,0),App.Vector(2.0,2.0,0))) - geoList.append(Part.Line(App.Vector(2.0,2.0,0),App.Vector(2.0,8.0,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.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.BodySource.addFeature(self.Pad) - - self.Doc.recompute() - Gui.SendMsgToActiveView("ViewFit") - - self.BodyTarget = self.Doc.addObject('PartDesign::Body','Body') - - Gui.Selection.addSelection(App.ActiveDocument.Pad) - cobj = CallableCheckWarning(self) - QtCore.QTimer.singleShot(500, cobj) - Gui.runCommand('PartDesign_MoveFeature') - #assert depenedencies of the Sketch - self.assertEqual(len(self.BodySource.Model), 4, "Source body feature count is wrong") - self.assertEqual(len(self.BodyTarget.Model), 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) - - self.Sketch = self.Doc.addObject('Sketcher::SketchObject','Sketch') - self.Sketch.Support = (self.Doc.XY_Plane, ['']) - self.Sketch.MapMode = 'FlatFace' - self.BodySource.addFeature(self.Sketch) - - geoList = [] - geoList.append(Part.Line(App.Vector(-10.000000,10.000000,0),App.Vector(10.000000,10.000000,0))) - geoList.append(Part.Line(App.Vector(10.000000,10.000000,0),App.Vector(10.000000,-10.000000,0))) - geoList.append(Part.Line(App.Vector(10.000000,-10.000000,0),App.Vector(-10.000000,-10.000000,0))) - geoList.append(Part.Line(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.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.BodySource.addFeature(self.Pad) - - self.Doc.recompute() - Gui.SendMsgToActiveView("ViewFit") - - 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.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.Model), 0, "Source body feature count is wrong") - self.assertEqual(len(self.BodyTarget.Model), 2, "Target body feature count is wrong") - - def tearDown(self): - FreeCAD.closeDocument("SketchGuiTest") + def setUp(self): + self.Doc = FreeCAD.newDocument("SketchGuiTest") + + def testRefuseToMoveSingleFeature(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.BoxObj = self.Doc.addObject('PartDesign::AdditiveBox','Box') + self.BoxObj.Length=10.0 + self.BoxObj.Width=10.0 + self.BoxObj.Height=10.0 + self.BodySource.addFeature(self.BoxObj) + + self.BoxCoords = self.Doc.addObject('PartDesign::CoordinateSystem','CoordinateSystem') + self.BodySource.addFeature(self.BoxCoords) + self.BoxObj.CoordinateSystem=(self.BoxCoords) + App.ActiveDocument.recompute() + Gui.activeDocument().hide('CoordinateSystem') + + self.Sketch = self.Doc.addObject('Sketcher::SketchObject','Sketch') + self.Sketch.Support = (self.BoxObj, ('Face3',)) + self.Sketch.MapMode = 'FlatFace' + self.BodySource.addFeature(self.Sketch) + + geoList = [] + geoList.append(Part.Line(App.Vector(2.0,8.0,0),App.Vector(8.0,8.0,0))) + geoList.append(Part.Line(App.Vector(8.0,8.0,0),App.Vector(8.0,2.0,0))) + geoList.append(Part.Line(App.Vector(8.0,2.0,0),App.Vector(2.0,2.0,0))) + geoList.append(Part.Line(App.Vector(2.0,2.0,0),App.Vector(2.0,8.0,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.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.BodySource.addFeature(self.Pad) + + self.Doc.recompute() + Gui.SendMsgToActiveView("ViewFit") + + self.BodyTarget = self.Doc.addObject('PartDesign::Body','Body') + + Gui.Selection.addSelection(App.ActiveDocument.Pad) + cobj = CallableCheckWarning(self) + QtCore.QTimer.singleShot(500, cobj) + Gui.runCommand('PartDesign_MoveFeature') + #assert depenedencies of the Sketch + self.assertEqual(len(self.BodySource.Model), 4, "Source body feature count is wrong") + self.assertEqual(len(self.BodyTarget.Model), 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) + + self.Sketch = self.Doc.addObject('Sketcher::SketchObject','Sketch') + self.Sketch.Support = (self.Doc.XY_Plane, ['']) + self.Sketch.MapMode = 'FlatFace' + self.BodySource.addFeature(self.Sketch) + + geoList = [] + geoList.append(Part.Line(App.Vector(-10.000000,10.000000,0),App.Vector(10.000000,10.000000,0))) + geoList.append(Part.Line(App.Vector(10.000000,10.000000,0),App.Vector(10.000000,-10.000000,0))) + geoList.append(Part.Line(App.Vector(10.000000,-10.000000,0),App.Vector(-10.000000,-10.000000,0))) + geoList.append(Part.Line(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.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.BodySource.addFeature(self.Pad) + + self.Doc.recompute() + Gui.SendMsgToActiveView("ViewFit") + + 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.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.Model), 0, "Source body feature count is wrong") + self.assertEqual(len(self.BodyTarget.Model), 2, "Target body feature count is wrong") + + def tearDown(self): + FreeCAD.closeDocument("SketchGuiTest") #class PartDesignGuiTestCases(unittest.TestCase): # def setUp(self):