diff --git a/src/Mod/Part/Gui/TaskAttacher.cpp b/src/Mod/Part/Gui/TaskAttacher.cpp index 5f3ebe9b77..f01c86756c 100644 --- a/src/Mod/Part/Gui/TaskAttacher.cpp +++ b/src/Mod/Part/Gui/TaskAttacher.cpp @@ -1224,8 +1224,9 @@ void TaskAttacher::visibilityAutomation(bool opening_not_closing) // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgAttacher::TaskDlgAttacher(Gui::ViewProviderDocumentObject* ViewProvider, bool createBox) - : TaskDialog(), ViewProvider(ViewProvider), parameter(nullptr) +TaskDlgAttacher::TaskDlgAttacher(Gui::ViewProviderDocumentObject* ViewProvider, bool createBox, + std::function onAccept, std::function onReject) + : TaskDialog(), ViewProvider(ViewProvider), parameter(nullptr), onAccept(onAccept), onReject(onReject), accepted(false) { assert(ViewProvider); setDocumentName(ViewProvider->getDocument()->getDocument()->getName()); @@ -1236,7 +1237,15 @@ TaskDlgAttacher::TaskDlgAttacher(Gui::ViewProviderDocumentObject* ViewProvider, } } -TaskDlgAttacher::~TaskDlgAttacher() = default; +TaskDlgAttacher::~TaskDlgAttacher() +{ + if (accepted && onAccept) { + onAccept(); + } + else if (onReject) { + onReject(); + } +}; //==== calls from the TaskView =============================================================== @@ -1283,6 +1292,7 @@ bool TaskDlgAttacher::accept() Gui::cmdAppObject(obj, "recompute()"); Gui::cmdGuiDocument(obj, "resetEdit()"); + Gui::Command::commitCommand(); } catch (const Base::Exception& e) { @@ -1290,6 +1300,8 @@ bool TaskDlgAttacher::accept() return false; } + accepted = true; + return true; } @@ -1304,6 +1316,8 @@ bool TaskDlgAttacher::reject() Gui::Command::doCommand(Gui::Command::Doc,"%s.recompute()", doc.getAppDocumentPython().c_str()); } + accepted = false; + return true; } diff --git a/src/Mod/Part/Gui/TaskAttacher.h b/src/Mod/Part/Gui/TaskAttacher.h index ce63d6cc21..360cccefa6 100644 --- a/src/Mod/Part/Gui/TaskAttacher.h +++ b/src/Mod/Part/Gui/TaskAttacher.h @@ -160,7 +160,7 @@ class PartGuiExport TaskDlgAttacher : public Gui::TaskView::TaskDialog Q_OBJECT public: - explicit TaskDlgAttacher(Gui::ViewProviderDocumentObject *ViewProvider, bool createBox = true); + explicit TaskDlgAttacher(Gui::ViewProviderDocumentObject *ViewProvider, bool createBox = true, std::function onAccept = {}, std::function onReject = {}); ~TaskDlgAttacher() override; Gui::ViewProviderDocumentObject* getViewProvider() const @@ -188,6 +188,10 @@ protected: Gui::ViewProviderDocumentObject *ViewProvider; TaskAttacher *parameter; + + std::function onAccept; + std::function onReject; + bool accepted; }; } //namespace PartDesignGui diff --git a/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp b/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp index af287a1ec5..848fa93336 100644 --- a/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp +++ b/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp @@ -111,27 +111,13 @@ void ViewProviderAttachExtension::extensionSetupContextMenu(QMenu* menu, QObject } } -void ViewProviderAttachExtension::showAttachmentEditor() +void ViewProviderAttachExtension::showAttachmentEditor(std::function onAccept, std::function onReject) { if (Gui::Control().activeDialog()) { Gui::Control().closeDialog(); } - // See PropertyEnumAttacherItem::openTask() - Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); - TaskDlgAttacher* task; - task = qobject_cast(dlg); - - if (dlg && !task) { - // there is already another task dialog which must be closed first - Gui::Control().showDialog(dlg); - return; - } - - if (!task) { - task = new TaskDlgAttacher(getExtendedViewProvider()); - } - + TaskDlgAttacher* task = new TaskDlgAttacher(getExtendedViewProvider(), true, onAccept, onReject); Gui::Control().showDialog(task); } diff --git a/src/Mod/Part/Gui/ViewProviderAttachExtension.h b/src/Mod/Part/Gui/ViewProviderAttachExtension.h index 4aaff4ec90..f05b3ffba4 100644 --- a/src/Mod/Part/Gui/ViewProviderAttachExtension.h +++ b/src/Mod/Part/Gui/ViewProviderAttachExtension.h @@ -44,7 +44,7 @@ public: void extensionUpdateData(const App::Property*) override; void extensionSetupContextMenu(QMenu*, QObject*, const char*) override; - void showAttachmentEditor(); + void showAttachmentEditor(std::function onAccept = {}, std::function onReject = {}); }; using ViewProviderAttachExtensionPython = Gui::ViewProviderExtensionPythonT; diff --git a/src/Mod/PartDesign/Gui/SketchWorkflow.cpp b/src/Mod/PartDesign/Gui/SketchWorkflow.cpp index 6e6097f510..403f4da559 100644 --- a/src/Mod/PartDesign/Gui/SketchWorkflow.cpp +++ b/src/Mod/PartDesign/Gui/SketchWorkflow.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -502,7 +503,16 @@ private: void tryFindSupport() { createBodyOrThrow(); - findAndSelectPlane(); + + bool useAttachment = App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/PartDesign") + ->GetBool("NewSketchUseAttachmentDialog", false); + if (useAttachment) { + createSketchAndShowAttachment(); + } + else { + findAndSelectPlane(); + } } void createBodyOrThrow() @@ -527,6 +537,59 @@ private: } } + void setOriginTemporaryVisibility() + { + auto* origin = activeBody->getOrigin(); + auto* vpo = dynamic_cast( + Gui::Application::Instance->getViewProvider(origin)); + if (vpo) { + vpo->setTemporaryVisibility(true, true); + vpo->setTemporaryScale(3.0); // NOLINT + vpo->setPlaneLabelVisibility(true); + } + } + + void createSketchAndShowAttachment() + { + setOriginTemporaryVisibility(); + + // Create sketch + App::Document* doc = activeBody->getDocument(); + std::string FeatName = doc->getUniqueObjectName("Sketch"); + FCMD_OBJ_CMD(activeBody, "newObject('Sketcher::SketchObject','" << FeatName << "')"); + auto sketch = doc->getObject(FeatName.c_str()); + + PartDesign::Body* partDesignBody = activeBody; + auto onAccept = [partDesignBody, sketch]() { + SketchRequestSelection::resetOriginVisibility(partDesignBody); + + Gui::Selection().clearSelection(); + + PartDesignGui::setEdit(sketch, partDesignBody); + }; + auto onReject = [partDesignBody, sketch]() { + SketchRequestSelection::resetOriginVisibility(partDesignBody); + }; + + Gui::Selection().clearSelection(); + + // Open attachment dialog + auto* vps = dynamic_cast(Gui::Application::Instance->getViewProvider(sketch)); + vps->showAttachmentEditor(onAccept, onReject); + } + + static void resetOriginVisibility(PartDesign::Body* partDesignBody) + { + auto* origin = partDesignBody->getOrigin(); + auto* vpo = dynamic_cast( + Gui::Application::Instance->getViewProvider(origin)); + if (vpo) { + vpo->resetTemporaryVisibility(); + vpo->resetTemporarySize(); + vpo->setPlaneLabelVisibility(false); + } + } + void findAndSelectPlane() { App::Document* appdocument = guidocument->getDocument();