]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_Dialog.cpp
Salome HOME
Improve the correcting orientation in the Filling feature.
[modules/shaper.git] / src / ModuleBase / ModuleBase_Dialog.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "ModuleBase_Dialog.h"
22 #include "ModuleBase_WidgetFactory.h"
23 #include "ModuleBase_IWorkshop.h"
24 #include "ModuleBase_IPropertyPanel.h"
25 #include "ModuleBase_PageWidget.h"
26 #include "ModuleBase_ModelDialogWidget.h"
27
28 #include <ModelAPI_Session.h>
29 #include <ModelAPI_Events.h>
30 #include <Events_Loop.h>
31
32 #include <Config_WidgetAPI.h>
33 #include <Config_Keywords.h>
34
35 #include <QMainWindow>
36 #include <QLayout>
37 #include <QDialogButtonBox>
38 #include <QPushButton>
39
40
41 ModuleBase_Dialog::ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, const QString& theId,
42                                      const std::string& theDescription) :
43                                      QDialog(theParent->desktop()),
44                                      myId(theId),
45                                      myDescription(theDescription),
46                                      myWorkshop(theParent),
47                                      myActiveWidget(0)
48 {
49   ModuleBase_WidgetFactory aFactory(myDescription, myWorkshop);
50   std::string aTitle = aFactory.widgetAPI()->getProperty(FEATURE_TEXT);
51
52   setWindowTitle(aTitle.c_str());
53
54   SessionPtr aMgr = ModelAPI_Session::get();
55   std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
56
57   myFeature = aDoc->addFeature(myId.toStdString());
58   if (!myFeature.get())
59     return;
60   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
61   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
62
63   QVBoxLayout* aLayout = new QVBoxLayout(this);
64   aLayout->setContentsMargins(0, 0, 0, 0);
65   aLayout->setSpacing(1);
66   //setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
67
68   ModuleBase_PageWidget* aPage = new ModuleBase_PageWidget(this);
69   aLayout->addWidget(aPage);
70
71   aFactory.createWidget(aPage, false);
72   myWidgets = aFactory.getModelWidgets();
73
74   QFrame* aFrame = new QFrame(this);
75   aFrame->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
76   aLayout->addWidget(aFrame);
77
78   QVBoxLayout* aBtnLayout = new QVBoxLayout(aFrame);
79   ModuleBase_Tools::adjustMargins(aBtnLayout);
80
81   myButtonsBox = new QDialogButtonBox(
82     QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, aFrame);
83   aBtnLayout->addWidget(myButtonsBox);
84
85   myButtonsBox->button(QDialogButtonBox::Ok)->setIcon(QIcon(":pictures/button_ok.png"));
86   myButtonsBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":pictures/button_cancel.png"));
87
88   connect(myButtonsBox, SIGNAL(accepted()), this, SLOT(accept()));
89   connect(myButtonsBox, SIGNAL(rejected()), this, SLOT(reject()));
90
91   foreach (ModuleBase_ModelWidget* aWidget, myWidgets) {
92     initializeWidget(aWidget);
93   }
94 }
95
96 void ModuleBase_Dialog::initializeWidget(ModuleBase_ModelWidget* theWidget)
97 {
98   ModuleBase_ModelDialogWidget* aDlgWgt = dynamic_cast<ModuleBase_ModelDialogWidget*>(theWidget);
99   if (aDlgWgt)
100     aDlgWgt->setDialogButtons(myButtonsBox);
101
102   theWidget->setFeature(myFeature);
103   theWidget->restoreValue();
104 }
105
106 void ModuleBase_Dialog::showEvent(QShowEvent* theEvent)
107 {
108   QDialog::showEvent(theEvent);
109   if (myWidgets.length() > 0) {
110     myActiveWidget = myWidgets.first();
111     myActiveWidget->activate();
112   }
113 }
114
115 void ModuleBase_Dialog::accept()
116 {
117   if (myActiveWidget) {
118     if (!myActiveWidget->storeValue())
119       return;
120   }
121   QDialog::accept();
122 }