Skip to content

Commit cffa0b7

Browse files
committed
Fem: Clean up constraint view providers
1 parent d2be7f7 commit cffa0b7

20 files changed

+57
-761
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

+7-86
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,16 @@
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"
44-
#include "Gui/MainWindow.h"
42+
#include "Gui/Selection.h"
4543
#include "Mod/Fem/App/FemConstraint.h"
4644

47-
#include "TaskFemConstraint.h"
4845
#include "ViewProviderFemConstraint.h"
4946
#include "ViewProviderFemConstraintPy.h"
5047

@@ -60,9 +57,6 @@ ViewProviderFemConstraint::ViewProviderFemConstraint()
6057
, pExtraSymbol(nullptr)
6158
, pExtraTrans(nullptr)
6259
, ivFile(nullptr)
63-
, wizardWidget(nullptr)
64-
, wizardSubLayout(nullptr)
65-
, constraintDialog(nullptr)
6660
{
6761
pShapeSep = new SoSeparator();
6862
pShapeSep->ref();
@@ -151,7 +145,7 @@ void ViewProviderFemConstraint::setDisplayMode(const char* ModeName)
151145
if (strcmp(ModeName, "Base") == 0) {
152146
setDisplayMaskMode("Base");
153147
}
154-
ViewProviderDocumentObject::setDisplayMode(ModeName);
148+
ViewProviderGeometryObject::setDisplayMode(ModeName);
155149
}
156150

157151
std::vector<App::DocumentObject*> ViewProviderFemConstraint::claimChildren() const
@@ -164,7 +158,7 @@ void ViewProviderFemConstraint::setupContextMenu(QMenu* menu, QObject* receiver,
164158
QAction* act;
165159
act = menu->addAction(QObject::tr("Edit analysis feature"), receiver, member);
166160
act->setData(QVariant((int)ViewProvider::Default));
167-
ViewProviderDocumentObject::setupContextMenu(menu,
161+
ViewProviderGeometryObject::setupContextMenu(menu,
168162
receiver,
169163
member); // clazy:exclude=skipped-base-method
170164
}
@@ -283,26 +277,12 @@ void ViewProviderFemConstraint::unsetEdit(int ModNum)
283277
{
284278
// clear the selection (convenience)
285279
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')");
280+
if (ModNum == ViewProvider::Default) {
281+
// when pressing ESC make sure to close the dialog
282+
Gui::Control().closeDialog();
297283
}
298284
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-
}
285+
ViewProviderGeometryObject::unsetEdit(ModNum);
306286
}
307287
}
308288

@@ -316,65 +296,6 @@ PyObject* ViewProviderFemConstraint::getPyObject()
316296
}
317297

318298

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-
378299
// Python feature -----------------------------------------------------------------------
379300

380301
namespace Gui

src/Mod/Fem/Gui/ViewProviderFemConstraint.h

+2-15
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,22 @@
2525
#ifndef GUI_VIEWPROVIDERFEMCONSTRAINT_H
2626
#define GUI_VIEWPROVIDERFEMCONSTRAINT_H
2727

28-
#include <QObject>
29-
#include <QVBoxLayout>
30-
3128
#include <Gui/ViewProviderGeometryObject.h>
3229
#include <Gui/ViewProviderPythonFeature.h>
3330
#include <Mod/Fem/FemGlobal.h>
3431

3532
#include <Gui/ViewProviderSuppressibleExtension.h>
3633

3734

35+
class QMenu;
36+
class QObject;
3837
class SbRotation;
3938
class SoMultipleCopy;
4039
class SoTransform;
4140

4241
namespace FemGui
4342
{
4443

45-
class TaskFemConstraint;
46-
4744
class FemGuiExport ViewProviderFemConstraint: public Gui::ViewProviderGeometryObject,
4845
public Gui::ViewProviderSuppressibleExtension
4946
{
@@ -111,16 +108,6 @@ class FemGuiExport ViewProviderFemConstraint: public Gui::ViewProviderGeometryOb
111108
const char* ivFile;
112109

113110
static std::string resourceSymbolDir;
114-
115-
// Shaft design wizard integration
116-
protected:
117-
friend class TaskFemConstraint;
118-
QVBoxLayout* wizardWidget;
119-
QVBoxLayout* wizardSubLayout;
120-
TaskFemConstraint* constraintDialog;
121-
122-
void checkForWizard();
123-
static QObject* findChildByName(const QObject* parent, const QString& name);
124111
};
125112

126113

src/Mod/Fem/Gui/ViewProviderFemConstraintBearing.cpp

+3-48
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,16 @@ ViewProviderFemConstraintBearing::~ViewProviderFemConstraintBearing() = default;
5251

5352
bool ViewProviderFemConstraintBearing::setEdit(int ModNum)
5453
{
55-
5654
if (ModNum == ViewProvider::Default) {
57-
// When double-clicking on the item for this constraint the
58-
// object unsets and sets its edit mode without closing
59-
// the task panel
60-
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
64-
}
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;
87-
}
88-
else {
89-
constraintDialog = new TaskFemConstraintBearing(this);
90-
return true;
91-
}
92-
}
93-
55+
Gui::Control().closeDialog();
9456
// clear the selection (convenience)
9557
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-
}
58+
Gui::Control().showDialog(new TaskDlgFemConstraintBearing(this));
10459

10560
return true;
10661
}
10762
else {
108-
return ViewProviderDocumentObject::setEdit(ModNum); // clazy:exclude=skipped-base-method
63+
return ViewProviderFemConstraint::setEdit(ModNum);
10964
}
11065
}
11166

0 commit comments

Comments
 (0)