PartDesign NewSketch: Add a parameter to use attachment dialog instead of feature pick
This commit is contained in:
committed by
Chris Hennes
parent
ddd86bd7b3
commit
a61db12828
@@ -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<void()> onAccept, std::function<void()> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<void()> onAccept = {}, std::function<void()> onReject = {});
|
||||
~TaskDlgAttacher() override;
|
||||
|
||||
Gui::ViewProviderDocumentObject* getViewProvider() const
|
||||
@@ -188,6 +188,10 @@ protected:
|
||||
Gui::ViewProviderDocumentObject *ViewProvider;
|
||||
|
||||
TaskAttacher *parameter;
|
||||
|
||||
std::function<void()> onAccept;
|
||||
std::function<void()> onReject;
|
||||
bool accepted;
|
||||
};
|
||||
|
||||
} //namespace PartDesignGui
|
||||
|
||||
@@ -111,27 +111,13 @@ void ViewProviderAttachExtension::extensionSetupContextMenu(QMenu* menu, QObject
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderAttachExtension::showAttachmentEditor()
|
||||
void ViewProviderAttachExtension::showAttachmentEditor(std::function<void()> onAccept, std::function<void()> onReject)
|
||||
{
|
||||
if (Gui::Control().activeDialog()) {
|
||||
Gui::Control().closeDialog();
|
||||
}
|
||||
|
||||
// See PropertyEnumAttacherItem::openTask()
|
||||
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
|
||||
TaskDlgAttacher* task;
|
||||
task = qobject_cast<TaskDlgAttacher*>(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);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
void extensionUpdateData(const App::Property*) override;
|
||||
void extensionSetupContextMenu(QMenu*, QObject*, const char*) override;
|
||||
|
||||
void showAttachmentEditor();
|
||||
void showAttachmentEditor(std::function<void()> onAccept = {}, std::function<void()> onReject = {});
|
||||
};
|
||||
|
||||
using ViewProviderAttachExtensionPython = Gui::ViewProviderExtensionPythonT<PartGui::ViewProviderAttachExtension>;
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <Mod/PartDesign/App/ShapeBinder.h>
|
||||
#include <Mod/Part/App/Attacher.h>
|
||||
#include <Mod/Part/App/TopoShape.h>
|
||||
#include <Mod/Sketcher/Gui/ViewProviderSketch.h>
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <App/Link.h>
|
||||
@@ -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::ViewProviderCoordinateSystem*>(
|
||||
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<SketcherGui::ViewProviderSketch*>(Gui::Application::Instance->getViewProvider(sketch));
|
||||
vps->showAttachmentEditor(onAccept, onReject);
|
||||
}
|
||||
|
||||
static void resetOriginVisibility(PartDesign::Body* partDesignBody)
|
||||
{
|
||||
auto* origin = partDesignBody->getOrigin();
|
||||
auto* vpo = dynamic_cast<Gui::ViewProviderCoordinateSystem*>(
|
||||
Gui::Application::Instance->getViewProvider(origin));
|
||||
if (vpo) {
|
||||
vpo->resetTemporaryVisibility();
|
||||
vpo->resetTemporarySize();
|
||||
vpo->setPlaneLabelVisibility(false);
|
||||
}
|
||||
}
|
||||
|
||||
void findAndSelectPlane()
|
||||
{
|
||||
App::Document* appdocument = guidocument->getDocument();
|
||||
|
||||
Reference in New Issue
Block a user