From 3bd09ea570d2b26472dc5b3b942ad5722e275b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Fri, 24 Jul 2015 06:15:46 +0200 Subject: [PATCH] change point of reference feedback for datums On datum creation it is better to ask the user on OK than on tool activation, as he might hit cancel (and then the created references are till there) or even more important, he could add additional external references within the dialog. The disadvantae is that if the user sets "cross reference" ge gets asked again every time he opens and leaves the dialog. --- src/Mod/PartDesign/Gui/Command.cpp | 35 ---------- .../PartDesign/Gui/TaskDatumParameters.cpp | 64 +++++++++++++++++-- 2 files changed, 59 insertions(+), 40 deletions(-) diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 0a23c72fb..6f4d955d6 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -104,42 +104,7 @@ void UnifiedDatumCommand(Gui::Command &cmd, Base::Type type, std::string name) auto pcActivePart = PartDesignGui::getPartFor(pcActiveBody, false); // TODO Check how this will work outside of a body (2015-10-20, Fat-Zer) - //check the prerequisites for the selected objects - //the user has to decide which option we should take if external references are used - bool ext = false; - for(App::DocumentObject* obj : support.getValues()) { - if(!pcActiveBody->hasFeature(obj)) - ext = true; - } // TODO rewrite this to be shared with CmdPartDesignNewSketch::activated() (2015-10-20, Fat-Zer) - if(ext) { - 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()) { - - std::vector objs; - std::vector subs = support.getSubValues(); - int index = 0; - for(App::DocumentObject* obj : support.getValues()) { - - objs.push_back(PartDesignGui::TaskFeaturePick::makeCopy(obj, subs[index], dlg.radioIndependent->isChecked())); - auto oBody = PartDesignGui::getBodyFor(obj, false); - if (oBody && pcActiveBody) { - pcActiveBody->addFeature(objs.back()); - } else if (pcActivePart) { - pcActivePart->addObject(objs.back()); - } - - } - } - - }; - std::string FeatName = cmd.getUniqueObjectName(name.c_str()); std::string tmp = std::string("Create ")+name; diff --git a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp index 20020b02e..0c4843b77 100644 --- a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp @@ -32,10 +32,12 @@ #endif #include +#include #include #include #include #include +#include #include #include #include @@ -53,6 +55,7 @@ #include "ui_TaskDatumParameters.h" #include "TaskDatumParameters.h" +#include "TaskFeaturePick.h" using namespace PartDesignGui; using namespace Gui; @@ -284,10 +287,10 @@ void TaskDatumParameters::updateUI(std::string message, bool error) ui->message->setText(QString::fromStdString(message)); if(error) ui->message->setStyleSheet(QString::fromAscii("QLabel{color: red;}")); - else + else ui->message->setStyleSheet(QString::fromAscii("QLabel{color: green;}")); } - + ui->checkBoxFlip->setVisible(false); ui->labelOffset->setVisible(true); @@ -426,7 +429,7 @@ void TaskDatumParameters::onSelectionChanged(const Gui::SelectionChanges& msg) refs.push_back(selObj); refnames.push_back(subname); } - + bool error = false; std::string message("Selection accepted"); try { @@ -864,6 +867,13 @@ void TaskDlgDatumParameters::clicked(int) bool TaskDlgDatumParameters::accept() { + std::string name = DatumView->getObject()->getNameInDocument(); + Datum* pcDatum = static_cast(DatumView->getObject()); + auto pcActiveBody = PartDesignGui::getBodyFor(pcDatum, false); + auto pcActivePart = PartDesignGui::getPartFor(pcActiveBody, false); + std::vector copies; + + //see if we are able to assign a mode bool bIgnoreError = false; if (parameter->getActiveMapMode() == mmDeactivated) { QMessageBox msg; @@ -881,8 +891,44 @@ bool TaskDlgDatumParameters::accept() return false; } - std::string name = DatumView->getObject()->getNameInDocument(); - Datum* pcDatum = static_cast(DatumView->getObject()); + //see what to do with external references + //check the prerequisites for the selected objects + //the user has to decide which option we should take if external references are used + bool ext = false; + for(App::DocumentObject* obj : pcDatum->Support.getValues()) { + if(!pcActiveBody->hasFeature(obj)) + ext = true; + } + if(ext) { + // TODO rewrite this to be shared with CmdPartDesignNewSketch::activated() (2015-10-20, Fat-Zer) + QDialog* dia = new QDialog; + Ui_Dialog dlg; + dlg.setupUi(dia); + dia->setModal(true); + int result = dia->exec(); + if(result == QDialog::DialogCode::Rejected) + return false; + else if(!dlg.radioXRef->isChecked()) { + + std::vector objs; + std::vector subs = pcDatum->Support.getSubValues(); + int index = 0; + for(App::DocumentObject* obj : pcDatum->Support.getValues()) { + + if(!pcActiveBody->hasFeature(obj)) { + objs.push_back(PartDesignGui::TaskFeaturePick::makeCopy(obj, subs[index], dlg.radioIndependent->isChecked())); + copies.push_back(objs.back()); + subs[index] = ""; + } + else + objs.push_back(obj); + + index++; + } + + pcDatum->Support.setValues(objs, subs); + } + } try { Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.superPlacement.Base.z = %f",name.c_str(),parameter->getOffset()); @@ -901,6 +947,14 @@ bool TaskDlgDatumParameters::accept() throw Base::Exception(DatumView->getObject()->getStatusString()); Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); Gui::Command::commitCommand(); + + //we need to add the copied features to the body after the command action, as otherwise freecad crashs unexplainable + for(auto obj : copies) { + if(pcActiveBody) + pcActiveBody->addFeature(obj); + else if (pcActivePart) + pcActivePart->addObject(obj); + } } catch (const Base::Exception& e) { QMessageBox::warning(parameter, tr("Datum dialog: Input error"), QString::fromAscii(e.what()));