| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #include <QApplication> |
| #include <QMessageBox> |
|
|
|
|
| #include <App/DocumentObserver.h> |
| #include <Gui/Application.h> |
| #include <Gui/CommandT.h> |
| #include <Gui/MainWindow.h> |
| #include <Gui/BitmapFactory.h> |
| #include <Mod/PartDesign/App/Feature.h> |
| #include <Mod/PartDesign/App/Body.h> |
|
|
| #include "ui_TaskPreviewParameters.h" |
|
|
| #include "TaskFeatureParameters.h" |
| #include "TaskSketchBasedParameters.h" |
|
|
| using namespace PartDesignGui; |
| using namespace Gui; |
|
|
| |
| |
| |
|
|
| TaskPreviewParameters::TaskPreviewParameters(ViewProvider* vp, QWidget* parent) |
| : TaskBox(BitmapFactory().pixmap("tree-pre-sel"), tr("Preview"), true, parent) |
| , vp(vp) |
| , ui(std::make_unique<Ui_TaskPreviewParameters>()) |
| { |
| vp->showPreviousFeature(!hGrp->GetBool("ShowFinal", false)); |
| vp->showPreview(hGrp->GetBool("ShowTransparentPreview", true)); |
|
|
| auto* proxy = new QWidget(this); |
| ui->setupUi(proxy); |
|
|
| ui->showFinalCheckBox->setChecked(vp->isVisible()); |
| ui->showTransparentPreviewCheckBox->setChecked(vp->isPreviewEnabled()); |
|
|
| #if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0) |
| connect( |
| ui->showTransparentPreviewCheckBox, |
| &QCheckBox::checkStateChanged, |
| this, |
| &TaskPreviewParameters::onShowPreviewChanged |
| ); |
| connect( |
| ui->showFinalCheckBox, |
| &QCheckBox::checkStateChanged, |
| this, |
| &TaskPreviewParameters::onShowFinalChanged |
| ); |
| #else |
| connect( |
| ui->showTransparentPreviewCheckBox, |
| &QCheckBox::stateChanged, |
| this, |
| &TaskPreviewParameters::onShowPreviewChanged |
| ); |
| connect( |
| ui->showFinalCheckBox, |
| &QCheckBox::stateChanged, |
| this, |
| &TaskPreviewParameters::onShowFinalChanged |
| ); |
| #endif |
|
|
| groupLayout()->addWidget(proxy); |
| } |
|
|
| TaskPreviewParameters::~TaskPreviewParameters() = default; |
|
|
| void TaskPreviewParameters::onShowFinalChanged(bool show) |
| { |
| vp->showPreviousFeature(!show); |
| } |
|
|
| void TaskPreviewParameters::onShowPreviewChanged(bool show) |
| { |
| vp->showPreview(show); |
| } |
|
|
| TaskFeatureParameters::TaskFeatureParameters( |
| PartDesignGui::ViewProvider* vp, |
| QWidget* parent, |
| const std::string& pixmapname, |
| const QString& parname |
| ) |
| : TaskBox(Gui::BitmapFactory().pixmap(pixmapname.c_str()), parname, true, parent) |
| , vp(vp) |
| , blockUpdate(false) |
| { |
| Gui::Document* doc = vp->getDocument(); |
| this->attachDocument(doc); |
| } |
|
|
| void TaskFeatureParameters::slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj) |
| { |
| if (this->vp == &Obj) { |
| this->vp = nullptr; |
| } |
| } |
|
|
| void TaskFeatureParameters::onUpdateView(bool on) |
| { |
| blockUpdate = !on; |
| recomputeFeature(); |
| } |
|
|
| void TaskFeatureParameters::recomputeFeature() |
| { |
| if (!blockUpdate) { |
| auto* feature = getObject<PartDesign::Feature>(); |
| assert(feature); |
|
|
| feature->recomputeFeature(); |
| feature->recomputePreview(); |
| } |
| } |
|
|
| |
| |
| |
| TaskDlgFeatureParameters::TaskDlgFeatureParameters(PartDesignGui::ViewProvider* vp) |
| : preview(new TaskPreviewParameters(vp)) |
| , vp(vp) |
| { |
| assert(vp); |
| } |
|
|
| TaskDlgFeatureParameters::~TaskDlgFeatureParameters() = default; |
|
|
| bool TaskDlgFeatureParameters::accept() |
| { |
| App::DocumentObject* feature = getObject(); |
| bool isUpdateBlocked = false; |
| try { |
| |
| for (QWidget* wgt : Content) { |
| TaskFeatureParameters* param = qobject_cast<TaskFeatureParameters*>(wgt); |
| if (!param) { |
| continue; |
| } |
|
|
| param->saveHistory(); |
| param->apply(); |
| isUpdateBlocked |= param->isUpdateBlocked(); |
| } |
| |
| |
| if (!feature->isDerivedFrom<PartDesign::Feature>()) { |
| throw Base::TypeError("Bad object processed in the feature dialog."); |
| } |
|
|
| if (isUpdateBlocked) { |
| Gui::cmdAppDocument(feature, "recompute()"); |
| } |
| else { |
| |
| Gui::cmdAppDocument(feature, "purgeTouched()"); |
|
|
| if (!feature->isValid()) { |
| throw Base::RuntimeError(getObject()->getStatusString()); |
| } |
|
|
| |
| for (auto obj : feature->getInList()) { |
| obj->touch(); |
| } |
| |
| Gui::cmdAppDocument(feature->getDocument(), "recompute()"); |
| } |
|
|
| if (!feature->isValid()) { |
| throw Base::RuntimeError(getObject()->getStatusString()); |
| } |
|
|
| App::DocumentObject* previous = static_cast<PartDesign::Feature*>(feature)->getBaseObject( |
| true |
| ); |
| Gui::cmdAppObjectHide(previous); |
|
|
| |
| |
| std::vector<QWidget*> subwidgets = getDialogContent(); |
| for (auto it : subwidgets) { |
| TaskSketchBasedParameters* param = qobject_cast<TaskSketchBasedParameters*>(it); |
| if (param) { |
| param->detachSelection(); |
| } |
| } |
|
|
| Gui::cmdGuiDocument(feature, "resetEdit()"); |
| Gui::Command::commitCommand(); |
| } |
| catch (const Base::Exception& e) { |
|
|
| QString errorText = QString::fromUtf8(e.what()); |
| QString statusText = QString::fromUtf8(getObject()->getStatusString()); |
|
|
| |
| if (errorText == QStringLiteral("Error") || errorText.isEmpty()) { |
| if (!statusText.isEmpty() && statusText != QStringLiteral("Error")) { |
| errorText = statusText; |
| } |
| else { |
| errorText = tr( |
| "The feature could not be created with the given parameters.\n" |
| "The geometry may be invalid or the parameters may be incompatible.\n" |
| "Please adjust the parameters and try again." |
| ); |
| } |
| } |
| QMessageBox::warning(Gui::getMainWindow(), tr("Input error"), errorText); |
| return false; |
| } |
| return true; |
| } |
|
|
| bool TaskDlgFeatureParameters::reject() |
| { |
| auto feature = getObject<PartDesign::Feature>(); |
| App::DocumentObjectWeakPtrT weakptr(feature); |
| App::Document* document = feature->getDocument(); |
|
|
| PartDesign::Body* body = PartDesign::Body::findBodyOf(feature); |
|
|
| |
| |
| App::DocumentObject* previous = feature->getBaseObject( true); |
|
|
| |
| |
| std::vector<QWidget*> subwidgets = getDialogContent(); |
| for (auto it : subwidgets) { |
| TaskSketchBasedParameters* param = qobject_cast<TaskSketchBasedParameters*>(it); |
| if (param) { |
| param->detachSelection(); |
| } |
| } |
|
|
| |
| Gui::Command::abortCommand(); |
|
|
| |
| if (weakptr.expired()) { |
| |
| |
| if (previous && Gui::Application::Instance->getViewProvider(previous)) { |
| Gui::Application::Instance->getViewProvider(previous)->show(); |
| } |
| else if (body) { |
| App::DocumentObject* tip = body->Tip.getValue(); |
| if (tip && Gui::Application::Instance->getViewProvider(tip)) { |
| Gui::Application::Instance->getViewProvider(tip)->show(); |
| } |
| } |
| } |
|
|
| Gui::cmdAppDocument(document, "recompute()"); |
| Gui::cmdGuiDocument(document, "resetEdit()"); |
|
|
| return true; |
| } |
|
|
| #include "moc_TaskFeatureParameters.cpp" |
|
|