1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 CEA
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
23 // File : SMESHGUI_CreateHypothesesDlg.cxx
24 // Author : Julia DOROVSKIKH
28 #include "SMESHGUI_CreateHypothesesDlg.h"
30 #include "SMESHGUI_HypothesesUtils.h"
31 #include "SMESHGUI_Hypotheses.h"
32 #include "SMESHGUI_Utils.h"
35 #include "SUIT_Desktop.h"
36 #include "SUIT_ResourceMgr.h"
38 #include "SALOME_ListIteratorOfListIO.hxx"
40 #include "utilities.h"
43 #include <qbuttongroup.h>
44 #include <qgroupbox.h>
45 #include <qpushbutton.h>
47 #include <qlistview.h>
52 //=================================================================================
53 // function : SMESHGUI_CreateHypothesesDlg()
54 // purpose : Constructs a SMESHGUI_CreateHypothesesDlg which is a child of 'parent', with the
55 // name 'name' and widget flags set to 'f'.
56 // The dialog will by default be modeless, unless you set 'modal' to
57 // TRUE to construct a modal dialog.
58 //=================================================================================
59 SMESHGUI_CreateHypothesesDlg::SMESHGUI_CreateHypothesesDlg (SMESHGUI* theModule,
63 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
64 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
66 mySMESHGUI( theModule )
69 setName("SMESHGUI_CreateHypothesesDlg");
70 setCaption(isAlgo ? tr("SMESH_CREATE_ALGORITHMS" ) : tr("SMESH_CREATE_HYPOTHESES" ));
71 setSizeGripEnabled(TRUE);
73 QGridLayout* SMESHGUI_CreateHypothesesDlgLayout = new QGridLayout(this);
74 SMESHGUI_CreateHypothesesDlgLayout->setSpacing(6);
75 SMESHGUI_CreateHypothesesDlgLayout->setMargin(11);
77 /***************************************************************/
78 GroupAlgorithms = new QGroupBox(this, "GroupAlgorithms");
79 GroupAlgorithms->setTitle(isAlgo ? tr("SMESH_AVAILABLE_ALGORITHMS") : tr("SMESH_AVAILABLE_HYPOTHESES"));
80 GroupAlgorithms->setColumnLayout(0, Qt::Vertical);
81 GroupAlgorithms->layout()->setSpacing(0);
82 GroupAlgorithms->layout()->setMargin(0);
84 QGridLayout* hypLayout = new QGridLayout(GroupAlgorithms->layout());
85 hypLayout->setGeometry(QRect(12, 18, 139, 250));
86 hypLayout->setAlignment(Qt::AlignTop);
87 hypLayout->setSpacing(6);
88 hypLayout->setMargin(11);
90 ListAlgoDefinition = new QListView(GroupAlgorithms, "ListAlgoDefinition");
91 ListAlgoDefinition->setMinimumSize(400, 200);
92 ListAlgoDefinition->addColumn("");
93 ListAlgoDefinition->header()->hide();
94 ListAlgoDefinition->setSelectionMode(QListView::Single);
95 ListAlgoDefinition->setResizeMode(QListView::AllColumns);
96 ListAlgoDefinition->setRootIsDecorated(true);
98 hypLayout->addWidget(ListAlgoDefinition, 0, 0);
99 SMESHGUI_CreateHypothesesDlgLayout->addWidget(GroupAlgorithms, 0, 0);
101 /***************************************************************/
102 GroupButtons = new QGroupBox(this, "GroupButtons");
103 GroupButtons->setColumnLayout(0, Qt::Vertical);
104 GroupButtons->layout()->setSpacing(0);
105 GroupButtons->layout()->setMargin(0);
106 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
107 GroupButtonsLayout->setAlignment(Qt::AlignTop);
108 GroupButtonsLayout->setSpacing(6);
109 GroupButtonsLayout->setMargin(11);
111 buttonApply = new QPushButton(GroupButtons, "buttonApply");
112 buttonApply->setText(tr("SMESH_BUT_CREATE" ));
113 buttonApply->setAutoDefault(TRUE);
114 buttonApply->setDefault(FALSE);
115 buttonApply->setEnabled(FALSE);
116 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
118 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
119 GroupButtonsLayout->addItem(spacer_9, 0, 2);
121 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
122 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
123 buttonCancel->setAutoDefault(TRUE);
124 buttonCancel->setDefault(TRUE);
125 buttonCancel->setEnabled(TRUE);
126 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
128 SMESHGUI_CreateHypothesesDlgLayout->addWidget(GroupButtons, 1, 0);
129 /***************************************************************/
134 //=================================================================================
135 // function : ~SMESHGUI_CreateHypothesesDlg()
136 // purpose : Destroys the object and frees any allocated resources
137 //=================================================================================
138 SMESHGUI_CreateHypothesesDlg::~SMESHGUI_CreateHypothesesDlg()
140 // no need to delete child widgets, Qt does it all for us
143 //=================================================================================
146 //=================================================================================
147 void SMESHGUI_CreateHypothesesDlg::Init()
149 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
151 InitAlgoDefinition();
153 /* signals and slots connections */
154 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
155 connect(buttonApply , SIGNAL(clicked()), this, SLOT(ClickOnApply()));
157 // connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
158 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
160 connect(ListAlgoDefinition, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
161 connect(ListAlgoDefinition, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(onDoubleClicked(QListViewItem*)));
164 mySMESHGUI->DefineDlgPosition(this, x, y);
169 //=================================================================================
170 // function : ClickOnCancel()
172 //=================================================================================
173 void SMESHGUI_CreateHypothesesDlg::ClickOnCancel()
178 //=================================================================================
179 // function : ClickOnApply()
181 //=================================================================================
182 void SMESHGUI_CreateHypothesesDlg::ClickOnApply()
184 if (mySMESHGUI->isActiveStudyLocked())
186 QListViewItem* item = ListAlgoDefinition->selectedItem();
189 QString aHypType = item->text(1);
190 MESSAGE("Apply " << aHypType);
191 char* sHypType = (char*)aHypType.latin1();
193 HypothesisData* aHypData = SMESH::GetHypothesisData(sHypType);
196 QString aClientLibName = aHypData->ClientLibName;
197 MESSAGE("Client lib name = " << aClientLibName);
199 if (aClientLibName == "") {
200 // Call hypothesis creation server method (without GUI)
201 QString aHypName = aHypData->Label;
202 SMESH::CreateHypothesis(sHypType, aHypName, myIsAlgo);
204 // Get hypotheses creator client (GUI)
205 SMESHGUI_GenericHypothesisCreator* aCreator =
206 SMESH::GetHypothesisCreator(sHypType);
209 // Create hypothesis/algorithm
210 aCreator->create( myIsAlgo, this );
213 // report about error
217 // buttonApply->setEnabled(FALSE);
221 //=================================================================================
222 // function : ActivateThisDialog()
224 //=================================================================================
225 void SMESHGUI_CreateHypothesesDlg::ActivateThisDialog()
227 mySMESHGUI->EmitSignalDeactivateDialog();
228 GroupButtons->setEnabled(true);
232 //=================================================================================
233 // function : enterEvent()
235 //=================================================================================
236 void SMESHGUI_CreateHypothesesDlg::enterEvent (QEvent*)
238 ActivateThisDialog();
242 //=================================================================================
243 // function : closeEvent()
245 //=================================================================================
246 void SMESHGUI_CreateHypothesesDlg::closeEvent (QCloseEvent* e)
248 mySMESHGUI->ResetState();
249 QDialog::closeEvent(e);
252 //=================================================================================
253 // function : onSelectionChanged()
255 //=================================================================================
256 void SMESHGUI_CreateHypothesesDlg::onSelectionChanged()
258 QListViewItem* item = ListAlgoDefinition->selectedItem();
259 buttonApply->setEnabled(item && item->depth() > 0);
262 //=================================================================================
263 // function : onDoubleClicked()
265 //=================================================================================
266 void SMESHGUI_CreateHypothesesDlg::onDoubleClicked (QListViewItem* i)
268 if (i && i->depth() > 0)
269 this->ClickOnApply();
272 //=================================================================================
273 // function : InitAlgoDefinition()
275 //=================================================================================
276 void SMESHGUI_CreateHypothesesDlg::InitAlgoDefinition()
278 ListAlgoDefinition->clear();
279 QStringList HypList = SMESH::GetAvailableHypotheses(myIsAlgo);
280 for (int i = 0; i < HypList.count(); ++i) {
281 HypothesisData* aHypData = SMESH::GetHypothesisData(HypList[i]);
282 QListViewItem* parentItem = 0;
283 QListViewItem* childItem = ListAlgoDefinition->firstChild();
285 if (childItem->text(0) == aHypData->PluginName) {
286 parentItem = childItem;
289 childItem = childItem->nextSibling();
292 parentItem = new QListViewItem(ListAlgoDefinition, aHypData->PluginName);
293 parentItem->setOpen(true);
294 QListViewItem* aItem = new QListViewItem(parentItem, aHypData->Label, HypList[i]);
295 QPixmap aPixMap (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr(aHypData->IconId)));
296 if (!aPixMap.isNull())
297 aItem->setPixmap(0, aPixMap);