| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
|
|
| #include <QMessageBox>
|
| #include <Standard_Failure.hxx>
|
|
|
|
|
| #include <App/DocumentObject.h>
|
| #include <App/Origin.h>
|
| #include <App/Part.h>
|
| #include <Gui/MainWindow.h>
|
| #include <Gui/ViewProvider.h>
|
| #include <Gui/Selection/Selection.h>
|
| #include <Mod/Part/App/DatumFeature.h>
|
| #include <Mod/PartDesign/App/Body.h>
|
|
|
| #include <ui_DlgReference.h>
|
|
|
| #include "TaskDatumParameters.h"
|
| #include "ReferenceSelection.h"
|
| #include "TaskFeaturePick.h"
|
| #include "Utils.h"
|
|
|
| using namespace PartDesignGui;
|
| using namespace Gui;
|
| using namespace Attacher;
|
|
|
|
|
|
|
| TaskDatumParameters::TaskDatumParameters(ViewProviderDatum* ViewProvider, QWidget* parent)
|
| : PartGui::TaskAttacher(
|
| ViewProvider,
|
| parent,
|
| QStringLiteral("PartDesign_") + ViewProvider->datumType,
|
| ViewProvider->datumMenuText
|
| )
|
| {
|
| Gui::Selection().addSelectionGate(new NoDependentsSelection(ViewProvider->getObject()));
|
| ViewProvider->setPickable(false);
|
| }
|
|
|
| TaskDatumParameters::~TaskDatumParameters()
|
| {
|
| if (this->ViewProvider && this->ViewProvider->isDerivedFrom<ViewProviderDatum>()) {
|
| static_cast<ViewProviderDatum*>(this->ViewProvider)->setPickable(true);
|
| }
|
| Gui::Selection().rmvSelectionGate();
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| TaskDlgDatumParameters::TaskDlgDatumParameters(ViewProviderDatum* ViewProvider)
|
| : TaskDlgAttacher(ViewProvider, false)
|
| {
|
| assert(ViewProvider);
|
| parameter = new TaskDatumParameters(ViewProvider);
|
| Content.push_back(parameter);
|
| }
|
|
|
| TaskDlgDatumParameters::~TaskDlgDatumParameters() = default;
|
|
|
| bool TaskDlgDatumParameters::reject()
|
| {
|
|
|
| return PartGui::TaskDlgAttacher::reject();
|
| }
|
|
|
|
|
| bool TaskDlgDatumParameters::accept()
|
| {
|
|
|
| Part::Datum* pcDatum = ViewProvider->getObject<Part::Datum>();
|
| auto pcActiveBody = PartDesignGui::getBodyFor(pcDatum, false);
|
| auto pcActivePart = PartDesignGui::getPartFor(pcActiveBody, false);
|
| std::vector<App::DocumentObject*> copies;
|
|
|
|
|
| if (parameter->getActiveMapMode() == mmDeactivated) {
|
| QMessageBox msg(Gui::getMainWindow());
|
| msg.setWindowTitle(tr("Incompatible Reference Set"));
|
| msg.setText(
|
| tr("There is no attachment mode that fits the current set"
|
| " of references. If you choose to continue, the feature will remain where"
|
| " it is now, and will not be moved as the references change."
|
| " Continue?")
|
| );
|
| msg.addButton(QMessageBox::Yes);
|
| auto btNo = msg.addButton(QMessageBox::No);
|
| msg.setDefaultButton(btNo);
|
| msg.setIcon(QMessageBox::Warning);
|
| msg.exec();
|
| if (msg.buttonRole(msg.clickedButton()) == QMessageBox::NoRole) {
|
| return false;
|
| }
|
| }
|
|
|
|
|
|
|
|
|
| bool extReference = false;
|
| for (App::DocumentObject* obj : pcDatum->AttachmentSupport.getValues()) {
|
| if (pcActiveBody && !pcActiveBody->hasObject(obj)
|
| && !pcActiveBody->getOrigin()->hasObject(obj)) {
|
| extReference = true;
|
| }
|
| }
|
|
|
| if (extReference) {
|
|
|
| QDialog dia(Gui::getMainWindow());
|
| PartDesignGui::Ui_DlgReference 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<App::DocumentObject*> copyObjects;
|
| std::vector<std::string> copySubValues;
|
| std::vector<std::string> subs = pcDatum->AttachmentSupport.getSubValues();
|
| int index = 0;
|
| for (App::DocumentObject* obj : pcDatum->AttachmentSupport.getValues()) {
|
| if (pcActiveBody && !pcActiveBody->hasObject(obj)
|
| && !pcActiveBody->getOrigin()->hasObject(obj)) {
|
| auto* copy = PartDesignGui::TaskFeaturePick::makeCopy(
|
| obj,
|
| subs[index],
|
| dlg.radioIndependent->isChecked()
|
| );
|
| if (copy) {
|
| copyObjects.push_back(copy);
|
| copies.push_back(copyObjects.back());
|
| copySubValues.emplace_back();
|
| }
|
| }
|
| else {
|
| copyObjects.push_back(obj);
|
| copySubValues.push_back(subs[index]);
|
| }
|
|
|
| index++;
|
| }
|
|
|
| pcDatum->AttachmentSupport.setValues(copyObjects, copySubValues);
|
| }
|
| }
|
|
|
| if (!PartGui::TaskDlgAttacher::accept()) {
|
| return false;
|
| }
|
|
|
|
|
|
|
| for (auto obj : copies) {
|
| if (pcActiveBody) {
|
| pcActiveBody->addObject(obj);
|
| }
|
| else if (pcActivePart) {
|
| pcActivePart->addObject(obj);
|
| }
|
| }
|
|
|
| return true;
|
| }
|
|
|
| #include "moc_TaskDatumParameters.cpp"
|
|
|