]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_Dialog.cpp
Salome HOME
Issue #2052: Modification of parameters don't work (sketch, extrusion)
[modules/shaper.git] / src / ModuleBase / ModuleBase_Dialog.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3
4 #include "ModuleBase_Dialog.h"
5 #include "ModuleBase_WidgetFactory.h"
6 #include "ModuleBase_IWorkshop.h"
7 #include "ModuleBase_IPropertyPanel.h"
8 #include "ModuleBase_PageWidget.h"
9 #include "ModuleBase_ModelDialogWidget.h"
10
11 #include <ModelAPI_Session.h>
12 #include <ModelAPI_Events.h>
13 #include <Events_Loop.h>
14
15 #include <Config_WidgetAPI.h>
16 #include <Config_Keywords.h>
17
18 #include <QMainWindow>
19 #include <QLayout>
20 #include <QDialogButtonBox>
21 #include <QPushButton>
22
23
24 ModuleBase_Dialog::ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, const QString& theId,
25                                      const std::string& theDescription) :
26                                      QDialog(theParent->desktop()),
27                                      myId(theId),
28                                      myDescription(theDescription),
29                                      myWorkshop(theParent),
30                                      myActiveWidget(0)
31 {
32   ModuleBase_WidgetFactory aFactory(myDescription, myWorkshop);
33   std::string aTitle = aFactory.widgetAPI()->getProperty(FEATURE_TEXT);
34
35   setWindowTitle(aTitle.c_str());
36
37   SessionPtr aMgr = ModelAPI_Session::get();
38   std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
39
40   myFeature = aDoc->addFeature(myId.toStdString());
41   if (!myFeature.get())
42     return;
43   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
44   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
45
46   QVBoxLayout* aLayout = new QVBoxLayout(this);
47   aLayout->setContentsMargins(0, 0, 0, 0);
48   aLayout->setSpacing(1);
49   //setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
50
51   ModuleBase_PageWidget* aPage = new ModuleBase_PageWidget(this);
52   aLayout->addWidget(aPage);
53
54   aFactory.createWidget(aPage, false);
55   myWidgets = aFactory.getModelWidgets();
56
57   QFrame* aFrame = new QFrame(this);
58   aFrame->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
59   aLayout->addWidget(aFrame);
60
61   QVBoxLayout* aBtnLayout = new QVBoxLayout(aFrame);
62   ModuleBase_Tools::adjustMargins(aBtnLayout);
63
64   myButtonsBox = new QDialogButtonBox(
65     QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, aFrame);
66   aBtnLayout->addWidget(myButtonsBox);
67
68   myButtonsBox->button(QDialogButtonBox::Ok)->setIcon(QIcon(":pictures/button_ok.png"));
69   myButtonsBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":pictures/button_cancel.png"));
70
71   connect(myButtonsBox, SIGNAL(accepted()), this, SLOT(accept()));
72   connect(myButtonsBox, SIGNAL(rejected()), this, SLOT(reject()));
73
74   foreach (ModuleBase_ModelWidget* aWidget, myWidgets) {
75     initializeWidget(aWidget);
76   }
77 }
78
79 void ModuleBase_Dialog::initializeWidget(ModuleBase_ModelWidget* theWidget)
80 {
81   ModuleBase_ModelDialogWidget* aDlgWgt = dynamic_cast<ModuleBase_ModelDialogWidget*>(theWidget);
82   if (aDlgWgt)
83     aDlgWgt->setDialogButtons(myButtonsBox);
84
85   theWidget->setFeature(myFeature);
86   theWidget->restoreValue();
87 }
88
89 void ModuleBase_Dialog::showEvent(QShowEvent* theEvent)
90 {
91   QDialog::showEvent(theEvent);
92   if (myWidgets.length() > 0) {
93     myActiveWidget = myWidgets.first();
94     myActiveWidget->activate();
95   }
96 }
97
98 void ModuleBase_Dialog::accept()
99 {
100   if (myActiveWidget) {
101     if (!myActiveWidget->storeValue())
102       return;
103   }
104   QDialog::accept();
105 }