Skip to content
This repository was archived by the owner on Mar 1, 2025. It is now read-only.

Commit 6bb0a2e

Browse files
committed
PartDesign NewSketch: Add a parameter to use attachment dialog instead of feature pick
1 parent 5a4f9a8 commit 6bb0a2e

File tree

5 files changed

+89
-22
lines changed

5 files changed

+89
-22
lines changed

src/Mod/Part/Gui/TaskAttacher.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,9 @@ void TaskAttacher::visibilityAutomation(bool opening_not_closing)
12241224
// TaskDialog
12251225
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12261226

1227-
TaskDlgAttacher::TaskDlgAttacher(Gui::ViewProviderDocumentObject* ViewProvider, bool createBox)
1228-
: TaskDialog(), ViewProvider(ViewProvider), parameter(nullptr)
1227+
TaskDlgAttacher::TaskDlgAttacher(Gui::ViewProviderDocumentObject* ViewProvider, bool createBox,
1228+
std::function<void()> onAccept, std::function<void()> onReject)
1229+
: TaskDialog(), ViewProvider(ViewProvider), parameter(nullptr), onAccept(onAccept), onReject(onReject), accepted(false)
12291230
{
12301231
assert(ViewProvider);
12311232
setDocumentName(ViewProvider->getDocument()->getDocument()->getName());
@@ -1236,7 +1237,15 @@ TaskDlgAttacher::TaskDlgAttacher(Gui::ViewProviderDocumentObject* ViewProvider,
12361237
}
12371238
}
12381239

1239-
TaskDlgAttacher::~TaskDlgAttacher() = default;
1240+
TaskDlgAttacher::~TaskDlgAttacher()
1241+
{
1242+
if (accepted && onAccept) {
1243+
onAccept();
1244+
}
1245+
else if (onReject) {
1246+
onReject();
1247+
}
1248+
};
12401249

12411250
//==== calls from the TaskView ===============================================================
12421251

@@ -1283,13 +1292,16 @@ bool TaskDlgAttacher::accept()
12831292
Gui::cmdAppObject(obj, "recompute()");
12841293

12851294
Gui::cmdGuiDocument(obj, "resetEdit()");
1295+
12861296
Gui::Command::commitCommand();
12871297
}
12881298
catch (const Base::Exception& e) {
12891299
QMessageBox::warning(parameter, tr("Datum dialog: Input error"), QCoreApplication::translate("Exception", e.what()));
12901300
return false;
12911301
}
12921302

1303+
accepted = true;
1304+
12931305
return true;
12941306
}
12951307

@@ -1304,6 +1316,8 @@ bool TaskDlgAttacher::reject()
13041316
Gui::Command::doCommand(Gui::Command::Doc,"%s.recompute()", doc.getAppDocumentPython().c_str());
13051317
}
13061318

1319+
accepted = false;
1320+
13071321
return true;
13081322
}
13091323

src/Mod/Part/Gui/TaskAttacher.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class PartGuiExport TaskDlgAttacher : public Gui::TaskView::TaskDialog
160160
Q_OBJECT
161161

162162
public:
163-
explicit TaskDlgAttacher(Gui::ViewProviderDocumentObject *ViewProvider, bool createBox = true);
163+
explicit TaskDlgAttacher(Gui::ViewProviderDocumentObject *ViewProvider, bool createBox = true, std::function<void()> onAccept = {}, std::function<void()> onReject = {});
164164
~TaskDlgAttacher() override;
165165

166166
Gui::ViewProviderDocumentObject* getViewProvider() const
@@ -188,6 +188,10 @@ class PartGuiExport TaskDlgAttacher : public Gui::TaskView::TaskDialog
188188
Gui::ViewProviderDocumentObject *ViewProvider;
189189

190190
TaskAttacher *parameter;
191+
192+
std::function<void()> onAccept;
193+
std::function<void()> onReject;
194+
bool accepted;
191195
};
192196

193197
} //namespace PartDesignGui

src/Mod/Part/Gui/ViewProviderAttachExtension.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,27 +111,13 @@ void ViewProviderAttachExtension::extensionSetupContextMenu(QMenu* menu, QObject
111111
}
112112
}
113113

114-
void ViewProviderAttachExtension::showAttachmentEditor()
114+
void ViewProviderAttachExtension::showAttachmentEditor(std::function<void()> onAccept, std::function<void()> onReject)
115115
{
116116
if (Gui::Control().activeDialog()) {
117117
Gui::Control().closeDialog();
118118
}
119119

120-
// See PropertyEnumAttacherItem::openTask()
121-
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
122-
TaskDlgAttacher* task;
123-
task = qobject_cast<TaskDlgAttacher*>(dlg);
124-
125-
if (dlg && !task) {
126-
// there is already another task dialog which must be closed first
127-
Gui::Control().showDialog(dlg);
128-
return;
129-
}
130-
131-
if (!task) {
132-
task = new TaskDlgAttacher(getExtendedViewProvider());
133-
}
134-
120+
TaskDlgAttacher* task = new TaskDlgAttacher(getExtendedViewProvider(), true, onAccept, onReject);
135121
Gui::Control().showDialog(task);
136122
}
137123

src/Mod/Part/Gui/ViewProviderAttachExtension.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class PartGuiExport ViewProviderAttachExtension : public Gui::ViewProviderExtens
4444
void extensionUpdateData(const App::Property*) override;
4545
void extensionSetupContextMenu(QMenu*, QObject*, const char*) override;
4646

47-
void showAttachmentEditor();
47+
void showAttachmentEditor(std::function<void()> onAccept = {}, std::function<void()> onReject = {});
4848
};
4949

5050
using ViewProviderAttachExtensionPython = Gui::ViewProviderExtensionPythonT<PartGui::ViewProviderAttachExtension>;

src/Mod/PartDesign/Gui/SketchWorkflow.cpp

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <Mod/PartDesign/App/ShapeBinder.h>
4444
#include <Mod/Part/App/Attacher.h>
4545
#include <Mod/Part/App/TopoShape.h>
46+
#include <Mod/Sketcher/Gui/ViewProviderSketch.h>
4647

4748
#include <App/Document.h>
4849
#include <App/Link.h>
@@ -502,7 +503,16 @@ class SketchRequestSelection
502503
void tryFindSupport()
503504
{
504505
createBodyOrThrow();
505-
findAndSelectPlane();
506+
507+
bool useAttachment = App::GetApplication()
508+
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/PartDesign")
509+
->GetBool("NewSketchUseAttachmentDialog", false);
510+
if (useAttachment) {
511+
createSketchAndShowAttachment();
512+
}
513+
else {
514+
findAndSelectPlane();
515+
}
506516
}
507517

508518
void createBodyOrThrow()
@@ -527,6 +537,59 @@ class SketchRequestSelection
527537
}
528538
}
529539

540+
void setOriginTemporaryVisibility()
541+
{
542+
auto* origin = activeBody->getOrigin();
543+
auto* vpo = dynamic_cast<Gui::ViewProviderCoordinateSystem*>(
544+
Gui::Application::Instance->getViewProvider(origin));
545+
if (vpo) {
546+
vpo->setTemporaryVisibility(true, true);
547+
vpo->setTemporaryScale(3.0); // NOLINT
548+
vpo->setPlaneLabelVisibility(true);
549+
}
550+
}
551+
552+
void createSketchAndShowAttachment()
553+
{
554+
setOriginTemporaryVisibility();
555+
556+
// Create sketch
557+
App::Document* doc = activeBody->getDocument();
558+
std::string FeatName = doc->getUniqueObjectName("Sketch");
559+
FCMD_OBJ_CMD(activeBody, "newObject('Sketcher::SketchObject','" << FeatName << "')");
560+
auto sketch = doc->getObject(FeatName.c_str());
561+
562+
PartDesign::Body* partDesignBody = activeBody;
563+
auto onAccept = [partDesignBody, sketch]() {
564+
SketchRequestSelection::resetOriginVisibility(partDesignBody);
565+
566+
Gui::Selection().clearSelection();
567+
568+
PartDesignGui::setEdit(sketch, partDesignBody);
569+
};
570+
auto onReject = [partDesignBody, sketch]() {
571+
SketchRequestSelection::resetOriginVisibility(partDesignBody);
572+
};
573+
574+
Gui::Selection().clearSelection();
575+
576+
// Open attachment dialog
577+
auto* vps = dynamic_cast<SketcherGui::ViewProviderSketch*>(Gui::Application::Instance->getViewProvider(sketch));
578+
vps->showAttachmentEditor(onAccept, onReject);
579+
}
580+
581+
static void resetOriginVisibility(PartDesign::Body* partDesignBody)
582+
{
583+
auto* origin = partDesignBody->getOrigin();
584+
auto* vpo = dynamic_cast<Gui::ViewProviderCoordinateSystem*>(
585+
Gui::Application::Instance->getViewProvider(origin));
586+
if (vpo) {
587+
vpo->resetTemporaryVisibility();
588+
vpo->resetTemporarySize();
589+
vpo->setPlaneLabelVisibility(false);
590+
}
591+
}
592+
530593
void findAndSelectPlane()
531594
{
532595
App::Document* appdocument = guidocument->getDocument();

0 commit comments

Comments
 (0)