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
29 #include <qbuttongroup.h>
30 #include <qgroupbox.h>
31 #include <qpushbutton.h>
33 #include <qlistview.h>
36 #include "QAD_Application.h"
37 #include "QAD_Desktop.h"
39 #include "SALOME_ListIteratorOfListIO.hxx"
41 #include "SMESHGUI_CreateHypothesesDlg.h"
42 #include "SMESHGUI_HypothesesUtils.h"
43 #include "SMESHGUI_Hypotheses.h"
44 #include "SMESHGUI_Utils.h"
47 #include "utilities.h"
51 //=================================================================================
52 // class : SMESHGUI_CreateHypothesesDlg()
53 // purpose : Constructs a SMESHGUI_CreateHypothesesDlg which is a child of 'parent', with the
54 // name 'name' and widget flags set to 'f'.
55 // The dialog will by default be modeless, unless you set 'modal' to
56 // TRUE to construct a modal dialog.
57 //=================================================================================
58 SMESHGUI_CreateHypothesesDlg::SMESHGUI_CreateHypothesesDlg (QWidget* parent,
62 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
65 MESSAGE("SMESHGUI_CreateHypothesesDlg");
68 setName( "SMESHGUI_CreateHypothesesDlg" );
69 setCaption( isAlgo ? tr( "SMESH_CREATE_ALGORITHMS" ) : tr( "SMESH_CREATE_HYPOTHESES" ) );
70 setSizeGripEnabled( TRUE );
72 QGridLayout* SMESHGUI_CreateHypothesesDlgLayout = new QGridLayout( this );
73 SMESHGUI_CreateHypothesesDlgLayout->setSpacing( 6 );
74 SMESHGUI_CreateHypothesesDlgLayout->setMargin( 11 );
76 /***************************************************************/
77 GroupAlgorithms = new QGroupBox( this, "GroupAlgorithms" );
78 GroupAlgorithms->setTitle( isAlgo ? tr("SMESH_AVAILABLE_ALGORITHMS") : tr("SMESH_AVAILABLE_HYPOTHESES") );
79 GroupAlgorithms->setColumnLayout(0, Qt::Vertical );
80 GroupAlgorithms->layout()->setSpacing( 0 );
81 GroupAlgorithms->layout()->setMargin( 0 );
83 QGridLayout* hypLayout = new QGridLayout( GroupAlgorithms->layout() );
84 hypLayout->setGeometry( QRect( 12, 18, 139, 250 ) );
85 hypLayout->setAlignment( Qt::AlignTop );
86 hypLayout->setSpacing( 6 );
87 hypLayout->setMargin( 11 );
89 ListAlgoDefinition = new QListView( GroupAlgorithms, "ListAlgoDefinition" );
90 ListAlgoDefinition->setMinimumSize( 400, 200 );
91 ListAlgoDefinition->addColumn("");
92 ListAlgoDefinition->header()->hide();
93 ListAlgoDefinition->setSelectionMode(QListView::Single);
94 ListAlgoDefinition->setResizeMode(QListView::AllColumns);
95 ListAlgoDefinition->setRootIsDecorated( true );
97 hypLayout->addWidget( ListAlgoDefinition, 0, 0 );
98 SMESHGUI_CreateHypothesesDlgLayout->addWidget( GroupAlgorithms, 0, 0 );
100 /***************************************************************/
101 GroupButtons = new QGroupBox( this, "GroupButtons" );
102 GroupButtons->setColumnLayout( 0, Qt::Vertical );
103 GroupButtons->layout()->setSpacing( 0 );
104 GroupButtons->layout()->setMargin( 0 );
105 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
106 GroupButtonsLayout->setAlignment( Qt::AlignTop );
107 GroupButtonsLayout->setSpacing( 6 );
108 GroupButtonsLayout->setMargin( 11 );
110 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
111 buttonApply->setText( tr( "SMESH_BUT_CREATE" ) );
112 buttonApply->setAutoDefault( TRUE );
113 buttonApply->setDefault( FALSE );
114 buttonApply->setEnabled( FALSE ) ;
115 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
117 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
118 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
120 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
121 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
122 buttonCancel->setAutoDefault( TRUE );
123 buttonCancel->setDefault( TRUE );
124 buttonCancel->setEnabled( TRUE ) ;
125 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
127 SMESHGUI_CreateHypothesesDlgLayout->addWidget( GroupButtons, 1, 0 );
128 /***************************************************************/
133 //=================================================================================
134 // function : ~SMESHGUI_CreateHypothesesDlg()
135 // purpose : Destroys the object and frees any allocated resources
136 //=================================================================================
137 SMESHGUI_CreateHypothesesDlg::~SMESHGUI_CreateHypothesesDlg()
139 // no need to delete child widgets, Qt does it all for us
142 //=================================================================================
145 //=================================================================================
146 void SMESHGUI_CreateHypothesesDlg::Init()
148 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
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->ActiveStudyLocked())
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 == "")
201 // Call hypothesis creation server method (without GUI)
202 QString aHypName = aHypData->Label;
203 SMESH::CreateHypothesis(sHypType, aHypName, myIsAlgo);
207 // Get hypotheses creator client (GUI)
208 SMESHGUI_GenericHypothesisCreator* aCreator =
209 SMESH::GetHypothesisCreator(sHypType);
211 // Create hypothesis/algorithm
212 aCreator->CreateHypothesis(myIsAlgo, this);
215 // buttonApply->setEnabled(FALSE);
219 //=================================================================================
220 // function : ActivateThisDialog()
222 //=================================================================================
223 void SMESHGUI_CreateHypothesesDlg::ActivateThisDialog()
225 mySMESHGUI->EmitSignalDeactivateDialog() ;
226 GroupButtons->setEnabled(true) ;
230 //=================================================================================
231 // function : enterEvent()
233 //=================================================================================
234 void SMESHGUI_CreateHypothesesDlg::enterEvent(QEvent* e)
236 ActivateThisDialog() ;
240 //=================================================================================
241 // function : closeEvent()
243 //=================================================================================
244 void SMESHGUI_CreateHypothesesDlg::closeEvent( QCloseEvent* e )
246 mySMESHGUI->ResetState();
247 QDialog::closeEvent( e );
250 //=================================================================================
251 // function : onSelectionChanged()
253 //=================================================================================
254 void SMESHGUI_CreateHypothesesDlg::onSelectionChanged()
256 QListViewItem* item = ListAlgoDefinition->selectedItem();
257 buttonApply->setEnabled( item && item->depth() > 0 ) ;
260 //=================================================================================
261 // function : onDoubleClicked()
263 //=================================================================================
264 void SMESHGUI_CreateHypothesesDlg::onDoubleClicked(QListViewItem* i)
266 if ( i && i->depth() > 0 )
267 this->ClickOnApply();
270 //=================================================================================
271 // function : InitAlgoDefinition()
273 //=================================================================================
274 void SMESHGUI_CreateHypothesesDlg::InitAlgoDefinition()
276 ListAlgoDefinition->clear();
277 QStringList HypList = SMESH::GetAvailableHypotheses(myIsAlgo);
278 for ( int i = 0; i < HypList.count(); ++i ) {
279 HypothesisData* aHypData = SMESH::GetHypothesisData( HypList[i] );
280 QListViewItem* parentItem = 0;
281 QListViewItem* childItem = ListAlgoDefinition->firstChild();
282 while ( childItem ) {
283 if ( childItem->text(0) == aHypData->PluginName ) {
284 parentItem = childItem;
287 childItem = childItem->nextSibling();
290 parentItem = new QListViewItem( ListAlgoDefinition, aHypData->PluginName );
291 parentItem->setOpen( true );
292 QListViewItem* aItem = new QListViewItem( parentItem, aHypData->Label, HypList[i] );
293 QPixmap aPixMap (QAD_Desktop::getResourceManager()->loadPixmap
294 ("SMESH", tr(aHypData->IconId)));
295 if ( !aPixMap.isNull() )
296 aItem->setPixmap( 0, aPixMap );