handle independent copies more gracefully

This commit is contained in:
Stefan Tröger 2015-07-24 06:55:29 +02:00
parent 3bd09ea570
commit 5725dd7721
2 changed files with 42 additions and 15 deletions

View File

@ -269,8 +269,9 @@ void CmdPartDesignShapeBinder::activated(int iMsg)
openCommand(tmp.c_str());
if(support.getValue()->isDerivedFrom(PartDesign::ShapeBinder2D::getClassTypeId()) ||
support.getValue()->isDerivedFrom(Part::Part2DObject::getClassTypeId())) {
if ( support.getValue() &&
( support.getValue()->isDerivedFrom(PartDesign::ShapeBinder2D::getClassTypeId()) ||
support.getValue()->isDerivedFrom(Part::Part2DObject::getClassTypeId()) ) ) {
doCommand(Gui::Command::Doc,"App.activeDocument().addObject('%s','%s')",
"PartDesign::ShapeBinder2D",FeatName.c_str());
} else {
@ -408,7 +409,7 @@ void CmdPartDesignNewSketch::activated(int iMsg)
if(result == QDialog::DialogCode::Rejected)
return;
else if(!dlg.radioXRef->isChecked()) {
// TODO This fails if we had match PlainFilter2 (2015-10-31, Fat-Zer)
const std::vector<std::string> &sub = FaceFilter.Result[0][0].getSubNames();
auto copy = PartDesignGui::TaskFeaturePick::makeCopy(obj, sub[0], dlg.radioIndependent->isChecked());
auto oBody = PartDesignGui::getBodyFor(obj, false);

View File

@ -49,6 +49,7 @@
#include <Mod/PartDesign/App/DatumPoint.h>
#include <Mod/PartDesign/App/DatumLine.h>
#include <Mod/PartDesign/App/DatumPlane.h>
#include <Mod/PartDesign/App/FeaturePrimitive.h>
#include <Mod/Part/App/DatumFeature.h>
using namespace PartDesignGui;
@ -272,7 +273,9 @@ std::vector<App::DocumentObject*> TaskFeaturePick::buildFeatures() {
App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::string sub, bool independent) {
App::DocumentObject* copy = nullptr;
if(independent) {
if( independent &&
(obj->isDerivedFrom(Sketcher::SketchObject::getClassTypeId()) ||
obj->isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId()))) {
//we do know that the created instance is a document object, as obj is one. But we do not know which
//exact type
@ -308,12 +311,12 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::st
}
cprop->Paste(*prop);
//we are a independent copy, therefore no external geometry was copied. WE therefore can delete all
//contraints
if(obj->isDerivedFrom(Sketcher::SketchObject::getClassTypeId()))
static_cast<Sketcher::SketchObject*>(copy)->delConstraintsToExternal();
}
if(!sub.empty() && copy &&
copy->isDerivedFrom(Part::Feature::getClassTypeId()) && obj->isDerivedFrom(Part::Feature::getClassTypeId()))
static_cast<Part::Feature*>(copy)->Shape.setValue(static_cast<Part::Feature*>(obj)->Shape.getShape().getSubShape(sub.c_str()));
}
else {
@ -322,6 +325,8 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::st
if(!sub.empty())
entity = sub.c_str();
Part::PropertyPartShape* shapeProp = nullptr;
// TODO Replace it with commands (2015-09-11, Fat-Zer)
if(obj->isDerivedFrom(Part::Datum::getClassTypeId())) {
copy = App::GetApplication().getActiveDocument()->addObject(
@ -330,29 +335,50 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::st
//we need to reference the individual datums and make again datums. This is important as
//datum adjust their size dependend on the part size, hence simply copying the shape is
//not enough
long int mode = mmDeactivated;
Part::Datum *datumCopy = static_cast<Part::Datum*>(copy);
datumCopy->Support.setValue(obj, entity);
if(obj->getTypeId() == PartDesign::Point::getClassTypeId()) {
datumCopy->MapMode.setValue(mm0Vertex);
mode = mm0Vertex;
}
else if(obj->getTypeId() == PartDesign::Line::getClassTypeId()) {
datumCopy->MapMode.setValue(mm1TwoPoints);
mode = mm1TwoPoints;
}
else if(obj->getTypeId() == PartDesign::Plane::getClassTypeId()) {
datumCopy->MapMode.setValue(mmFlatFace);
mode = mmFlatFace;
}
else
return copy;
// TODO Recheck this. This looks strange in case of independent copy (2015-10-31, Fat-Zer)
if(!independent) {
datumCopy->Support.setValue(obj, entity);
datumCopy->MapMode.setValue(mode);
}
else if(strcmp(entity,"") != 0) {
datumCopy->Shape.setValue(static_cast<Part::Datum*>(obj)->Shape.getShape().getSubShape(entity));
} else {
datumCopy->Shape.setValue(static_cast<Part::Datum*>(obj)->Shape.getValue());
}
}
else if(obj->isDerivedFrom(Part::Part2DObject::getClassTypeId()) ||
obj->getTypeId() == PartDesign::ShapeBinder2D::getClassTypeId()) {
copy = App::GetApplication().getActiveDocument()->addObject("PartDesign::ShapeBinder2D", name.c_str());
static_cast<PartDesign::ShapeBinder2D*>(copy)->Support.setValue(obj, entity);
if(!independent)
static_cast<PartDesign::ShapeBinder2D*>(copy)->Support.setValue(obj, entity);
else
shapeProp = &static_cast<PartDesign::ShapeBinder*>(copy)->Shape;
}
else if(obj->getTypeId() == PartDesign::ShapeBinder::getClassTypeId() ||
obj->isDerivedFrom(Part::Feature::getClassTypeId())) {
copy = App::GetApplication().getActiveDocument()->addObject("PartDesign::ShapeBinder", name.c_str());
static_cast<PartDesign::ShapeBinder*>(copy)->Support.setValue(obj, entity);
if(!independent)
static_cast<PartDesign::ShapeBinder*>(copy)->Support.setValue(obj, entity);
else
shapeProp = &static_cast<PartDesign::ShapeBinder*>(copy)->Shape;
}
}