Partially fix PartDesign move test

This commit is contained in:
Stefan Tröger
2017-02-18 12:26:23 +01:00
committed by wmayer
parent da866e5b4d
commit bfb95e3d12
4 changed files with 87 additions and 59 deletions

View File

@@ -271,12 +271,12 @@ std::vector<App::DocumentObject*> 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<App::GroupExtension>()->removeObject(feature);
*/
group->getExtensionByType<GroupExtension>()->removeObject(feature);
insertObject (feature, getNextSolidFeature (), /*after = */ false);
// Move the Tip if we added a solid
@@ -288,6 +288,15 @@ std::vector<App::DocumentObject*> 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)
{

View File

@@ -69,6 +69,7 @@ public:
* The insertion poin is the before next solid after the Tip feature
*/
virtual std::vector<App::DocumentObject*> addObject(App::DocumentObject*) override;
virtual std::vector< DocumentObject* > addObjects(std::vector< DocumentObject* > obj) override;
/**
* Insert the feature into the body after the given feature.

View File

@@ -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<App::DocumentObject*> 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<App::DocumentObject*>(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<App::DocumentObject*> target_bodies;
for (auto body : bodies) {
@@ -675,8 +681,20 @@ void CmdPartDesignMoveFeature::activated(int iMsg)
PartDesign::Body* target = static_cast<PartDesign::Body*>(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)

View File

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