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 "SMESHGUI_CreateHypothesesDlg.h"
31 #include "SALOME_ListIteratorOfListIO.hxx"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
38 #include <qbuttongroup.h>
39 #include <qgroupbox.h>
40 #include <qpushbutton.h>
42 #include <qlistview.h>
45 //=================================================================================
46 // class : SMESHGUI_CreateHypothesesDlg()
47 // purpose : Constructs a SMESHGUI_CreateHypothesesDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 SMESHGUI_CreateHypothesesDlg::SMESHGUI_CreateHypothesesDlg (QWidget* parent,
56 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
59 MESSAGE("SMESHGUI_CreateHypothesesDlg");
62 setName( "SMESHGUI_CreateHypothesesDlg" );
63 setCaption( isAlgo ? tr( "SMESH_CREATE_ALGORITHMS" ) : tr( "SMESH_CREATE_HYPOTHESES" ) );
64 setSizeGripEnabled( TRUE );
66 QGridLayout* SMESHGUI_CreateHypothesesDlgLayout = new QGridLayout( this );
67 SMESHGUI_CreateHypothesesDlgLayout->setSpacing( 6 );
68 SMESHGUI_CreateHypothesesDlgLayout->setMargin( 11 );
70 /***************************************************************/
71 GroupAlgorithms = new QGroupBox( this, "GroupAlgorithms" );
72 GroupAlgorithms->setTitle( isAlgo ? tr("SMESH_AVAILABLE_ALGORITHMS") : tr("SMESH_AVAILABLE_HYPOTHESES") );
73 GroupAlgorithms->setColumnLayout(0, Qt::Vertical );
74 GroupAlgorithms->layout()->setSpacing( 0 );
75 GroupAlgorithms->layout()->setMargin( 0 );
77 QGridLayout* hypLayout = new QGridLayout( GroupAlgorithms->layout() );
78 hypLayout->setGeometry( QRect( 12, 18, 139, 250 ) );
79 hypLayout->setAlignment( Qt::AlignTop );
80 hypLayout->setSpacing( 6 );
81 hypLayout->setMargin( 11 );
83 ListAlgoDefinition = new QListView( GroupAlgorithms, "ListAlgoDefinition" );
84 ListAlgoDefinition->setMinimumSize( 400, 200 );
85 ListAlgoDefinition->addColumn("");
86 ListAlgoDefinition->header()->hide();
87 ListAlgoDefinition->setSelectionMode(QListView::Single);
88 ListAlgoDefinition->setResizeMode(QListView::AllColumns);
89 ListAlgoDefinition->setRootIsDecorated( true );
91 hypLayout->addWidget( ListAlgoDefinition, 0, 0 );
92 SMESHGUI_CreateHypothesesDlgLayout->addWidget( GroupAlgorithms, 0, 0 );
94 /***************************************************************/
95 GroupButtons = new QGroupBox( this, "GroupButtons" );
96 GroupButtons->setColumnLayout( 0, Qt::Vertical );
97 GroupButtons->layout()->setSpacing( 0 );
98 GroupButtons->layout()->setMargin( 0 );
99 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
100 GroupButtonsLayout->setAlignment( Qt::AlignTop );
101 GroupButtonsLayout->setSpacing( 6 );
102 GroupButtonsLayout->setMargin( 11 );
104 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
105 buttonApply->setText( tr( "SMESH_BUT_CREATE" ) );
106 buttonApply->setAutoDefault( TRUE );
107 buttonApply->setDefault( FALSE );
108 buttonApply->setEnabled( FALSE ) ;
109 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
111 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
112 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
114 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
115 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
116 buttonCancel->setAutoDefault( TRUE );
117 buttonCancel->setDefault( TRUE );
118 buttonCancel->setEnabled( TRUE ) ;
119 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
121 SMESHGUI_CreateHypothesesDlgLayout->addWidget( GroupButtons, 1, 0 );
122 /***************************************************************/
127 //=================================================================================
128 // function : ~SMESHGUI_CreateHypothesesDlg()
129 // purpose : Destroys the object and frees any allocated resources
130 //=================================================================================
131 SMESHGUI_CreateHypothesesDlg::~SMESHGUI_CreateHypothesesDlg()
133 // no need to delete child widgets, Qt does it all for us
136 //=================================================================================
139 //=================================================================================
140 void SMESHGUI_CreateHypothesesDlg::Init()
142 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
143 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
145 InitAlgoDefinition();
147 /* signals and slots connections */
148 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
149 connect( buttonApply , SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ) ;
151 // connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
152 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
154 connect( ListAlgoDefinition, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
155 connect( ListAlgoDefinition, SIGNAL( doubleClicked(QListViewItem*) ), this, SLOT( onDoubleClicked(QListViewItem*) ) );
158 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
163 //=================================================================================
164 // function : ClickOnCancel()
166 //=================================================================================
167 void SMESHGUI_CreateHypothesesDlg::ClickOnCancel()
172 //=================================================================================
173 // function : ClickOnApply()
175 //=================================================================================
176 void SMESHGUI_CreateHypothesesDlg::ClickOnApply()
178 QListViewItem* item = ListAlgoDefinition->selectedItem();
181 QString aHypType = item->text( 1 );
182 MESSAGE("Apply " << aHypType);
183 char* sHypType = (char*)aHypType.latin1();
185 HypothesisData* aHypData = mySMESHGUI->GetHypothesisData(sHypType);
188 QString aClientLibName = aHypData->ClientLibName;
189 MESSAGE("Client lib name = " << aClientLibName);
191 if (aClientLibName == "")
193 // Call hypothesis creation server method (without GUI)
194 QString aHypName = aHypData->Label;
195 mySMESHGUI->CreateHypothesis(sHypType, aHypName, myIsAlgo);
199 // Get hypotheses creator client (GUI)
200 SMESHGUI_GenericHypothesisCreator* aCreator =
201 mySMESHGUI->GetHypothesisCreator(sHypType);
203 // Create hypothesis/algorithm
204 aCreator->CreateHypothesis(myIsAlgo, this);
207 // buttonApply->setEnabled(FALSE);
211 //=================================================================================
212 // function : ActivateThisDialog()
214 //=================================================================================
215 void SMESHGUI_CreateHypothesesDlg::ActivateThisDialog()
217 mySMESHGUI->EmitSignalDeactivateDialog() ;
218 GroupButtons->setEnabled(true) ;
222 //=================================================================================
223 // function : enterEvent()
225 //=================================================================================
226 void SMESHGUI_CreateHypothesesDlg::enterEvent(QEvent* e)
228 ActivateThisDialog() ;
232 //=================================================================================
233 // function : closeEvent()
235 //=================================================================================
236 void SMESHGUI_CreateHypothesesDlg::closeEvent( QCloseEvent* e )
238 mySMESHGUI->ResetState();
239 QDialog::closeEvent( e );
242 //=================================================================================
243 // function : onSelectionChanged()
245 //=================================================================================
246 void SMESHGUI_CreateHypothesesDlg::onSelectionChanged()
248 QListViewItem* item = ListAlgoDefinition->selectedItem();
249 buttonApply->setEnabled( item && item->depth() > 0 ) ;
252 //=================================================================================
253 // function : onDoubleClicked()
255 //=================================================================================
256 void SMESHGUI_CreateHypothesesDlg::onDoubleClicked(QListViewItem* i)
258 if ( i && i->depth() > 0 )
259 this->ClickOnApply();
262 //=================================================================================
263 // function : InitAlgoDefinition()
265 //=================================================================================
266 void SMESHGUI_CreateHypothesesDlg::InitAlgoDefinition()
268 ListAlgoDefinition->clear();
269 QStringList HypList = mySMESHGUI->GetAvailableHypotheses(myIsAlgo);
270 for ( int i = 0; i < HypList.count(); ++i ) {
271 HypothesisData* aHypData = mySMESHGUI->GetHypothesisData( HypList[i] );
272 QListViewItem* parentItem = 0;
273 QListViewItem* childItem = ListAlgoDefinition->firstChild();
274 while ( childItem ) {
275 if ( childItem->text(0) == aHypData->PluginName ) {
276 parentItem = childItem;
279 childItem = childItem->nextSibling();
282 parentItem = new QListViewItem( ListAlgoDefinition, aHypData->PluginName );
283 parentItem->setOpen( true );
284 QListViewItem* aItem = new QListViewItem( parentItem, aHypData->Label, HypList[i] );
285 QPixmap aPixMap (QAD_Desktop::getResourceManager()->loadPixmap
286 ("SMESH", tr(aHypData->IconId)));
287 if ( !aPixMap.isNull() )
288 aItem->setPixmap( 0, aPixMap );