diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 6f4d955d6..3ba23610c 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -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 &sub = FaceFilter.Result[0][0].getSubNames(); auto copy = PartDesignGui::TaskFeaturePick::makeCopy(obj, sub[0], dlg.radioIndependent->isChecked()); auto oBody = PartDesignGui::getBodyFor(obj, false); diff --git a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp index 798a9f037..2e95df81d 100644 --- a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp +++ b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include using namespace PartDesignGui; @@ -272,7 +273,9 @@ std::vector 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(copy)->delConstraintsToExternal(); } - - if(!sub.empty() && copy && - copy->isDerivedFrom(Part::Feature::getClassTypeId()) && obj->isDerivedFrom(Part::Feature::getClassTypeId())) - static_cast(copy)->Shape.setValue(static_cast(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(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(obj)->Shape.getShape().getSubShape(entity)); + } else { + datumCopy->Shape.setValue(static_cast(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(copy)->Support.setValue(obj, entity); + + if(!independent) + static_cast(copy)->Support.setValue(obj, entity); + else + shapeProp = &static_cast(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(copy)->Support.setValue(obj, entity); + + if(!independent) + static_cast(copy)->Support.setValue(obj, entity); + else + shapeProp = &static_cast(copy)->Shape; } }