Skip to content

Commit fb5476d

Browse files
committed
Fem: Clean up constraint
1 parent 1ccb74f commit fb5476d

19 files changed

+163
-565
lines changed

src/Mod/Fem/Gui/TaskFemConstraint.cpp

-66
Original file line numberDiff line numberDiff line change
@@ -65,45 +65,10 @@ TaskFemConstraint::TaskFemConstraint(ViewProviderFemConstraint* ConstraintView,
6565
, cancelButton(nullptr)
6666
{
6767
selectionMode = selref;
68-
69-
// Setup the dialog inside the Shaft Wizard dialog
70-
if ((ConstraintView->wizardWidget) && (ConstraintView->wizardSubLayout)) {
71-
// Hide the shaft wizard table widget to make more space
72-
ConstraintView->wizardSubLayout->itemAt(0)->widget()->hide();
73-
QGridLayout* buttons = ConstraintView->wizardSubLayout->findChild<QGridLayout*>();
74-
for (int b = 0; b < buttons->count(); b++) {
75-
buttons->itemAt(b)->widget()->hide();
76-
}
77-
78-
// Show this dialog for the FEM constraint
79-
ConstraintView->wizardWidget->addWidget(this);
80-
81-
// Add buttons to finish editing the constraint without closing the shaft wizard dialog
82-
okButton = new QPushButton(QObject::tr("Ok"));
83-
cancelButton = new QPushButton(QObject::tr("Cancel"));
84-
buttonBox = new QDialogButtonBox();
85-
buttonBox->addButton(okButton, QDialogButtonBox::AcceptRole);
86-
buttonBox->addButton(cancelButton, QDialogButtonBox::RejectRole);
87-
QObject::connect(okButton, &QPushButton::clicked, this, &TaskFemConstraint::onButtonWizOk);
88-
QObject::connect(cancelButton,
89-
&QPushButton::clicked,
90-
this,
91-
&TaskFemConstraint::onButtonWizCancel);
92-
ConstraintView->wizardWidget->addWidget(buttonBox);
93-
}
9468
}
9569

9670
void TaskFemConstraint::keyPressEvent(QKeyEvent* ke)
9771
{
98-
if ((ConstraintView->wizardWidget) && (ConstraintView->wizardSubLayout)) {
99-
// Prevent <Enter> from closing this dialog AND the shaft wizard dialog
100-
// TODO: This should trigger an update in the shaft wizard but its difficult to access a
101-
// python dialog from here...
102-
if (ke->key() == Qt::Key_Return) {
103-
return;
104-
}
105-
}
106-
10772
TaskBox::keyPressEvent(ke);
10873
}
10974

@@ -172,37 +137,6 @@ void TaskFemConstraint::onButtonReference(const bool pressed)
172137
Gui::Selection().clearSelection();
173138
}
174139

175-
void TaskFemConstraint::onButtonWizOk()
176-
{
177-
// Remove dialog elements
178-
buttonBox->removeButton(okButton);
179-
delete okButton;
180-
buttonBox->removeButton(cancelButton);
181-
delete cancelButton;
182-
ConstraintView->wizardWidget->removeWidget(buttonBox);
183-
delete buttonBox;
184-
ConstraintView->wizardWidget->removeWidget(this);
185-
186-
// Show the wizard shaft dialog again
187-
ConstraintView->wizardSubLayout->itemAt(0)->widget()->show();
188-
QGridLayout* buttons = ConstraintView->wizardSubLayout->findChild<QGridLayout*>();
189-
for (int b = 0; b < buttons->count(); b++) {
190-
buttons->itemAt(b)->widget()->show();
191-
}
192-
193-
Gui::Application::Instance->activeDocument()
194-
->resetEdit(); // Reaches ViewProviderFemConstraint::unsetEdit() eventually
195-
}
196-
197-
void TaskFemConstraint::onButtonWizCancel()
198-
{
199-
Fem::Constraint* pcConstraint = static_cast<Fem::Constraint*>(ConstraintView->getObject());
200-
if (pcConstraint) {
201-
pcConstraint->getDocument()->removeObject(pcConstraint->getNameInDocument());
202-
}
203-
onButtonWizOk();
204-
}
205-
206140
const QString TaskFemConstraint::makeRefText(const std::string& objName,
207141
const std::string& subName) const
208142
{

src/Mod/Fem/Gui/TaskFemConstraint.h

-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ protected Q_SLOTS:
6161
void onReferenceDeleted(const int row);
6262
void onButtonReference(const bool pressed = true);
6363
void setSelection(QListWidgetItem* item);
64-
// Shaft Wizard integration
65-
void onButtonWizOk();
66-
void onButtonWizCancel();
6764

6865
protected:
6966
void changeEvent(QEvent* e) override

src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp

+10-84
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,17 @@
3232
#include <Inventor/nodes/SoShapeHints.h>
3333
#include <Inventor/nodes/SoTransform.h>
3434
#include <QAction>
35-
#include <QDockWidget>
3635
#include <QMenu>
37-
#include <QStackedWidget>
3836
#endif
3937

4038
#include "App/Application.h"
4139
#include "Gui/Command.h"
4240
#include "Gui/Control.h"
4341
#include "Gui/Document.h"
4442
#include "Gui/MainWindow.h"
43+
#include "Gui/Selection.h"
4544
#include "Mod/Fem/App/FemConstraint.h"
4645

47-
#include "TaskFemConstraint.h"
4846
#include "ViewProviderFemConstraint.h"
4947
#include "ViewProviderFemConstraintPy.h"
5048

@@ -60,8 +58,6 @@ ViewProviderFemConstraint::ViewProviderFemConstraint()
6058
, pExtraSymbol(nullptr)
6159
, pExtraTrans(nullptr)
6260
, ivFile(nullptr)
63-
, wizardWidget(nullptr)
64-
, wizardSubLayout(nullptr)
6561
, constraintDialog(nullptr)
6662
{
6763
pShapeSep = new SoSeparator();
@@ -151,7 +147,7 @@ void ViewProviderFemConstraint::setDisplayMode(const char* ModeName)
151147
if (strcmp(ModeName, "Base") == 0) {
152148
setDisplayMaskMode("Base");
153149
}
154-
ViewProviderDocumentObject::setDisplayMode(ModeName);
150+
ViewProviderGeometryObject::setDisplayMode(ModeName);
155151
}
156152

157153
std::vector<App::DocumentObject*> ViewProviderFemConstraint::claimChildren() const
@@ -164,7 +160,7 @@ void ViewProviderFemConstraint::setupContextMenu(QMenu* menu, QObject* receiver,
164160
QAction* act;
165161
act = menu->addAction(QObject::tr("Edit analysis feature"), receiver, member);
166162
act->setData(QVariant((int)ViewProvider::Default));
167-
ViewProviderDocumentObject::setupContextMenu(menu,
163+
ViewProviderGeometryObject::setupContextMenu(menu,
168164
receiver,
169165
member); // clazy:exclude=skipped-base-method
170166
}
@@ -283,26 +279,15 @@ void ViewProviderFemConstraint::unsetEdit(int ModNum)
283279
{
284280
// clear the selection (convenience)
285281
Gui::Selection().clearSelection();
286-
287-
if (wizardWidget && wizardSubLayout && constraintDialog) {
288-
wizardWidget = nullptr;
289-
wizardSubLayout = nullptr;
290-
delete constraintDialog;
291-
constraintDialog = nullptr;
292-
293-
// Notify the Shaft Wizard that we have finished editing
294-
// See WizardShaft.py on why we do it this way
295-
Gui::Command::runCommand(Gui::Command::Doc,
296-
"Gui.runCommand('PartDesign_WizardShaftCallBack')");
282+
printf("unset 0\t%d\n", ModNum);
283+
if (ModNum == ViewProvider::Default) {
284+
// when pressing ESC make sure to close the dialog
285+
printf("unset 1\n");
286+
Gui::Control().closeDialog();
297287
}
298288
else {
299-
if (ModNum == ViewProvider::Default) {
300-
// when pressing ESC make sure to close the dialog
301-
Gui::Control().closeDialog();
302-
}
303-
else {
304-
ViewProviderGeometryObject::unsetEdit(ModNum);
305-
}
289+
printf("unset 2\n");
290+
ViewProviderGeometryObject::unsetEdit(ModNum);
306291
}
307292
}
308293

@@ -316,65 +301,6 @@ PyObject* ViewProviderFemConstraint::getPyObject()
316301
}
317302

318303

319-
QObject* ViewProviderFemConstraint::findChildByName(const QObject* parent, const QString& name)
320-
{
321-
for (auto o : parent->children()) {
322-
if (o->objectName() == name) {
323-
return o;
324-
}
325-
if (!o->children().empty()) {
326-
QObject* result = findChildByName(o, name);
327-
if (result) {
328-
return result;
329-
}
330-
}
331-
}
332-
333-
return nullptr;
334-
}
335-
336-
void ViewProviderFemConstraint::checkForWizard()
337-
{
338-
wizardWidget = nullptr;
339-
wizardSubLayout = nullptr;
340-
Gui::MainWindow* mw = Gui::getMainWindow();
341-
if (!mw) {
342-
return;
343-
}
344-
QDockWidget* dw = mw->findChild<QDockWidget*>(QString::fromLatin1("Combo View"));
345-
if (!dw) {
346-
return;
347-
}
348-
QWidget* cw = dw->findChild<QWidget*>(QString::fromLatin1("Combo View"));
349-
if (!cw) {
350-
return;
351-
}
352-
QTabWidget* tw = cw->findChild<QTabWidget*>(QString::fromLatin1("combiTab"));
353-
if (!tw) {
354-
return;
355-
}
356-
QStackedWidget* sw =
357-
tw->findChild<QStackedWidget*>(QString::fromLatin1("qt_tabwidget_stackedwidget"));
358-
if (!sw) {
359-
return;
360-
}
361-
QScrollArea* sa = sw->findChild<QScrollArea*>();
362-
if (!sa) {
363-
return;
364-
}
365-
QWidget* wd =
366-
sa->widget(); // This is the reason why we cannot use findChildByName() right away!!!
367-
if (!wd) {
368-
return;
369-
}
370-
QObject* wiz = findChildByName(wd, QString::fromLatin1("ShaftWizard"));
371-
if (wiz) {
372-
wizardWidget = static_cast<QVBoxLayout*>(wiz);
373-
wizardSubLayout = wiz->findChild<QVBoxLayout*>(QString::fromLatin1("ShaftWizardLayout"));
374-
}
375-
}
376-
377-
378304
// Python feature -----------------------------------------------------------------------
379305

380306
namespace Gui

src/Mod/Fem/Gui/ViewProviderFemConstraint.h

-6
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,9 @@ class FemGuiExport ViewProviderFemConstraint: public Gui::ViewProviderGeometryOb
112112

113113
static std::string resourceSymbolDir;
114114

115-
// Shaft design wizard integration
116115
protected:
117116
friend class TaskFemConstraint;
118-
QVBoxLayout* wizardWidget;
119-
QVBoxLayout* wizardSubLayout;
120117
TaskFemConstraint* constraintDialog;
121-
122-
void checkForWizard();
123-
static QObject* findChildByName(const QObject* parent, const QString& name);
124118
};
125119

126120

src/Mod/Fem/Gui/ViewProviderFemConstraintBearing.cpp

+10-38
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <Inventor/SbRotation.h>
2828
#include <Inventor/SbVec3f.h>
2929
#include <Inventor/nodes/SoSeparator.h>
30-
#include <QMessageBox>
3130
#endif
3231

3332
#include "Gui/Control.h"
@@ -52,60 +51,33 @@ ViewProviderFemConstraintBearing::~ViewProviderFemConstraintBearing() = default;
5251

5352
bool ViewProviderFemConstraintBearing::setEdit(int ModNum)
5453
{
55-
5654
if (ModNum == ViewProvider::Default) {
5755
// When double-clicking on the item for this constraint the
5856
// object unsets and sets its edit mode without closing
5957
// the task panel
6058
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
61-
TaskDlgFemConstraintBearing* constrDlg = qobject_cast<TaskDlgFemConstraintBearing*>(dlg);
62-
if (constrDlg && constrDlg->getConstraintView() != this) {
63-
constrDlg = nullptr; // another constraint left open its task panel
59+
TaskDlgFemConstraint* constrDlg = qobject_cast<TaskDlgFemConstraint*>(dlg);
60+
if (constrDlg
61+
&& constrDlg->getConstraintView() == static_cast<ViewProviderFemConstraint*>(this)) {
62+
return false;
6463
}
65-
if (dlg && !constrDlg) {
66-
// This case will occur in the ShaftWizard application
67-
checkForWizard();
68-
if (!wizardWidget || !wizardSubLayout) {
69-
// No shaft wizard is running
70-
QMessageBox msgBox;
71-
msgBox.setText(QObject::tr("A dialog is already open in the task panel"));
72-
msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?"));
73-
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
74-
msgBox.setDefaultButton(QMessageBox::Yes);
75-
int ret = msgBox.exec();
76-
if (ret == QMessageBox::Yes) {
77-
Gui::Control().reject();
78-
}
79-
else {
80-
return false;
81-
}
82-
}
83-
else if (constraintDialog) {
84-
// Another FemConstraint* dialog is already open inside the Shaft Wizard
85-
// Ignore the request to open another dialog
86-
return false;
64+
if (dlg) {
65+
if (dlg->canClose()) {
66+
Gui::Control().reject();
8767
}
8868
else {
89-
constraintDialog = new TaskFemConstraintBearing(this);
90-
return true;
69+
return false;
9170
}
9271
}
9372

9473
// clear the selection (convenience)
9574
Gui::Selection().clearSelection();
96-
97-
// start the edit dialog
98-
if (constrDlg) {
99-
Gui::Control().showDialog(constrDlg);
100-
}
101-
else {
102-
Gui::Control().showDialog(new TaskDlgFemConstraintBearing(this));
103-
}
75+
Gui::Control().showDialog(new TaskDlgFemConstraintBearing(this));
10476

10577
return true;
10678
}
10779
else {
108-
return ViewProviderDocumentObject::setEdit(ModNum); // clazy:exclude=skipped-base-method
80+
return ViewProviderFemConstraint::setEdit(ModNum);
10981
}
11082
}
11183

src/Mod/Fem/Gui/ViewProviderFemConstraintContact.cpp

+10-17
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,28 @@ bool ViewProviderFemConstraintContact::setEdit(int ModNum)
5757
// object unsets and sets its edit mode without closing
5858
// the task panel
5959
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
60-
TaskDlgFemConstraintContact* constrDlg = qobject_cast<TaskDlgFemConstraintContact*>(dlg);
61-
if (constrDlg && constrDlg->getConstraintView() != this) {
62-
constrDlg = nullptr; // another constraint left open its task panel
60+
TaskDlgFemConstraint* constrDlg = qobject_cast<TaskDlgFemConstraint*>(dlg);
61+
if (constrDlg
62+
&& constrDlg->getConstraintView() == static_cast<ViewProviderFemConstraint*>(this)) {
63+
return false;
6364
}
64-
if (dlg && !constrDlg) {
65-
if (constraintDialog) {
66-
// Ignore the request to open another dialog
67-
return false;
65+
if (dlg) {
66+
if (dlg->canClose()) {
67+
Gui::Control().reject();
6868
}
6969
else {
70-
constraintDialog = new TaskFemConstraintContact(this);
71-
return true;
70+
return false;
7271
}
7372
}
7473

7574
// clear the selection (convenience)
7675
Gui::Selection().clearSelection();
76+
Gui::Control().showDialog(new TaskDlgFemConstraintContact(this));
7777

78-
// start the edit dialog
79-
if (constrDlg) {
80-
Gui::Control().showDialog(constrDlg);
81-
}
82-
else {
83-
Gui::Control().showDialog(new TaskDlgFemConstraintContact(this));
84-
}
8578
return true;
8679
}
8780
else {
88-
return ViewProviderDocumentObject::setEdit(ModNum); // clazy:exclude=skipped-base-method
81+
return ViewProviderFemConstraint::setEdit(ModNum);
8982
}
9083
}
9184

0 commit comments

Comments
 (0)