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*)));
166 //=================================================================================
167 // function : ClickOnCancel()
169 //=================================================================================
170 void SMESHGUI_CreateHypothesesDlg::ClickOnCancel()
175 //=================================================================================
176 // function : ClickOnApply()
178 //=================================================================================
179 void SMESHGUI_CreateHypothesesDlg::ClickOnApply()
181 if (mySMESHGUI->isActiveStudyLocked())
183 QListViewItem* item = ListAlgoDefinition->selectedItem();
186 QString aHypType = item->text(1);
187 MESSAGE("Apply " << aHypType);
188 char* sHypType = (char*)aHypType.latin1();
190 HypothesisData* aHypData = SMESH::GetHypothesisData(sHypType);
193 QString aClientLibName = aHypData->ClientLibName;
194 MESSAGE("Client lib name = " << aClientLibName);
196 if (aClientLibName == "") {
197 // Call hypothesis creation server method (without GUI)
198 QString aHypName = aHypData->Label;
199 SMESH::CreateHypothesis(sHypType, aHypName, myIsAlgo);
201 // Get hypotheses creator client (GUI)
202 SMESHGUI_GenericHypothesisCreator* aCreator =
203 SMESH::GetHypothesisCreator(sHypType);
206 // Create hypothesis/algorithm
207 aCreator->create( myIsAlgo, this );
210 // report about error
214 // buttonApply->setEnabled(FALSE);
218 //=================================================================================
219 // function : ActivateThisDialog()
221 //=================================================================================
222 void SMESHGUI_CreateHypothesesDlg::ActivateThisDialog()
224 mySMESHGUI->EmitSignalDeactivateDialog();
225 GroupButtons->setEnabled(true);
229 //=================================================================================
230 // function : enterEvent()
232 //=================================================================================
233 void SMESHGUI_CreateHypothesesDlg::enterEvent (QEvent*)
235 ActivateThisDialog();
239 //=================================================================================
240 // function : closeEvent()
242 //=================================================================================
243 void SMESHGUI_CreateHypothesesDlg::closeEvent (QCloseEvent* e)
245 mySMESHGUI->ResetState();
246 QDialog::closeEvent(e);
249 //=================================================================================
250 // function : onSelectionChanged()
252 //=================================================================================
253 void SMESHGUI_CreateHypothesesDlg::onSelectionChanged()
255 QListViewItem* item = ListAlgoDefinition->selectedItem();
256 buttonApply->setEnabled(item && item->depth() > 0);
259 //=================================================================================
260 // function : onDoubleClicked()
262 //=================================================================================
263 void SMESHGUI_CreateHypothesesDlg::onDoubleClicked (QListViewItem* i)
265 if (i && i->depth() > 0)
266 this->ClickOnApply();
269 //=================================================================================
270 // function : InitAlgoDefinition()
272 //=================================================================================
273 void SMESHGUI_CreateHypothesesDlg::InitAlgoDefinition()
275 ListAlgoDefinition->clear();
276 QStringList HypList = SMESH::GetAvailableHypotheses(myIsAlgo);
277 for (int i = 0; i < HypList.count(); ++i) {
278 HypothesisData* aHypData = SMESH::GetHypothesisData(HypList[i]);
279 QListViewItem* parentItem = 0;
280 QListViewItem* childItem = ListAlgoDefinition->firstChild();
282 if (childItem->text(0) == aHypData->PluginName) {
283 parentItem = childItem;
286 childItem = childItem->nextSibling();
289 parentItem = new QListViewItem(ListAlgoDefinition, aHypData->PluginName);
290 parentItem->setOpen(true);
291 QListViewItem* aItem = new QListViewItem(parentItem, aHypData->Label, HypList[i]);
292 QPixmap aPixMap (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr(aHypData->IconId)));
293 if (!aPixMap.isNull())
294 aItem->setPixmap(0, aPixMap);