From 2ff2d29f02607ca789e3e256523a1cbda74e31d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Sat, 8 Aug 2015 10:36:03 +0200 Subject: [PATCH] Fix crossreference handling --- src/Mod/PartDesign/Gui/Command.cpp | 45 ++++++++++++++++++---- src/Mod/PartDesign/Gui/TaskFeaturePick.cpp | 21 ++++++---- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 3ba23610c..5778568eb 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -263,7 +263,7 @@ void CmdPartDesignShapeBinder::activated(int iMsg) PartDesign::Body *pcActiveBody = PartDesignGui::getBody(/*messageIfNot = */true); if (pcActiveBody == 0) return; - + std::string FeatName = getUniqueObjectName("ShapeBinder"); std::string tmp = std::string("Create ShapeBinder"); @@ -409,14 +409,21 @@ 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); - if(oBody) + + std::string sub; + if(FaceFilter.match()) + sub = FaceFilter.Result[0][0].getSubNames()[0]; + auto copy = PartDesignGui::TaskFeaturePick::makeCopy(obj, sub, dlg.radioIndependent->isChecked()); + + if(pcActiveBody) pcActiveBody->addFeature(copy); - else + else if (pcActivePart) pcActivePart->addObject(copy); + + if(PlaneFilter.match()) + supportString = std::string("(App.activeDocument().") + copy->getNameInDocument() + ", '')"; + else + supportString = std::string("(App.activeDocument().") + copy->getNameInDocument() + ", '" + sub +"')"; } } } @@ -788,6 +795,30 @@ void prepareSketchBased(Gui::Command* cmd, const std::string& which, } } + if(!bNoSketchWasSelected && ext) { + + auto* pcActivePart = PartDesignGui::getPartFor(pcActiveBody, false); + + QDialog* dia = new QDialog; + Ui_Dialog dlg; + dlg.setupUi(dia); + dia->setModal(true); + int result = dia->exec(); + if(result == QDialog::DialogCode::Rejected) + return; + else if(!dlg.radioXRef->isChecked()) { + + auto copy = PartDesignGui::TaskFeaturePick::makeCopy(sketches[0], "", dlg.radioIndependent->isChecked()); + auto oBody = PartDesignGui::getBodyFor(sketches[0], false); + if(oBody) + pcActiveBody->addFeature(copy); + else + pcActivePart->addObject(copy); + + sketches[0] = copy; + } + } + // If there is more than one selection/possibility, show dialog and let user pick sketch if ((bNoSketchWasSelected && validSketches > 1) || (!bNoSketchWasSelected && sketches.size() > 1)) { diff --git a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp index 2e95df81d..a3ac9298a 100644 --- a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp +++ b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp @@ -321,9 +321,9 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::st else { auto name = std::string("Reference") + std::string(obj->getNameInDocument()); - const char* entity = std::string("").c_str(); + std::string entity; if(!sub.empty()) - entity = sub.c_str(); + entity = sub; Part::PropertyPartShape* shapeProp = nullptr; @@ -352,11 +352,11 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::st // TODO Recheck this. This looks strange in case of independent copy (2015-10-31, Fat-Zer) if(!independent) { - datumCopy->Support.setValue(obj, entity); + datumCopy->Support.setValue(obj, entity.c_str()); datumCopy->MapMode.setValue(mode); } - else if(strcmp(entity,"") != 0) { - datumCopy->Shape.setValue(static_cast(obj)->Shape.getShape().getSubShape(entity)); + else if(!entity.empty()) { + datumCopy->Shape.setValue(static_cast(obj)->Shape.getShape().getSubShape(entity.c_str())); } else { datumCopy->Shape.setValue(static_cast(obj)->Shape.getValue()); } @@ -366,7 +366,7 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::st copy = App::GetApplication().getActiveDocument()->addObject("PartDesign::ShapeBinder2D", name.c_str()); if(!independent) - static_cast(copy)->Support.setValue(obj, entity); + static_cast(copy)->Support.setValue(obj, entity.c_str()); else shapeProp = &static_cast(copy)->Shape; } @@ -376,10 +376,17 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::st copy = App::GetApplication().getActiveDocument()->addObject("PartDesign::ShapeBinder", name.c_str()); if(!independent) - static_cast(copy)->Support.setValue(obj, entity); + static_cast(copy)->Support.setValue(obj, entity.c_str()); else shapeProp = &static_cast(copy)->Shape; } + + if(independent && shapeProp) { + if(entity.empty()) + shapeProp->setValue(static_cast(obj)->Shape.getValue()); + else + shapeProp->setValue(static_cast(obj)->Shape.getShape().getSubShape(entity.c_str())); + } } return copy;