1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_AddAlgorithmDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "SMESHGUI_AddAlgorithmDlg.h"
31 #include "SALOME_ListIteratorOfListIO.hxx"
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "utilities.h"
39 #include <qbuttongroup.h>
41 #include <qgroupbox.h>
43 #include <qlineedit.h>
44 #include <qpushbutton.h>
45 #include <qradiobutton.h>
49 #include <qwhatsthis.h>
55 //=================================================================================
56 // class : SMESHGUI_AddAlgorithmDlg()
57 // purpose : Constructs a SMESHGUI_AddAlgorithmDlg which is a child of 'parent', with the
58 // name 'name' and widget flags set to 'f'.
59 // The dialog will by default be modeless, unless you set 'modal' to
60 // TRUE to construct a modal dialog.
61 //=================================================================================
62 SMESHGUI_AddAlgorithmDlg::SMESHGUI_AddAlgorithmDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
63 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
65 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_ADD_ALGORITHM")));
66 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
69 setName( "SMESHGUI_AddAlgorithmDlg" );
71 setCaption( tr( "SMESH_ADD_ALGORITHM_TITLE" ) );
72 setSizeGripEnabled( TRUE );
74 SMESHGUI_AddAlgorithmDlgLayout = new QGridLayout( this );
75 SMESHGUI_AddAlgorithmDlgLayout->setSpacing( 6 );
76 SMESHGUI_AddAlgorithmDlgLayout->setMargin( 11 );
78 /***************************************************************/
79 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
80 GroupConstructors->setTitle( tr( "SMESH_ADD_ALGORITHM" ) );
81 GroupConstructors->setExclusive( TRUE );
82 GroupConstructors->setColumnLayout(0, Qt::Vertical );
83 GroupConstructors->layout()->setSpacing( 0 );
84 GroupConstructors->layout()->setMargin( 0 );
85 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
86 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
87 GroupConstructorsLayout->setSpacing( 6 );
88 GroupConstructorsLayout->setMargin( 11 );
89 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
90 GroupConstructorsLayout->addItem( spacer, 0, 1 );
91 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
92 Constructor1->setText( tr( "" ) );
93 Constructor1->setPixmap( image0 );
94 Constructor1->setChecked( TRUE );
95 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
96 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
97 SMESHGUI_AddAlgorithmDlgLayout->addWidget( GroupConstructors, 0, 0 );
99 /***************************************************************/
100 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
101 GroupConstructor1->setTitle( tr( "SMESH_ARGUMENTS" ) );
102 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
103 GroupConstructor1->layout()->setSpacing( 0 );
104 GroupConstructor1->layout()->setMargin( 0 );
105 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
106 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
107 GroupConstructor1Layout->setSpacing( 6 );
108 GroupConstructor1Layout->setMargin( 11 );
109 LineEditC1A2Mesh = new QLineEdit( GroupConstructor1, "LineEditC1A2Mesh" );
110 LineEditC1A2Mesh->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2Mesh->sizePolicy().hasHeightForWidth() ) );
111 GroupConstructor1Layout->addWidget( LineEditC1A2Mesh, 1, 2 );
112 LineEditC1A1Hyp = new QLineEdit( GroupConstructor1, "LineEditC1A1Hyp" );
113 LineEditC1A1Hyp->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Hyp->sizePolicy().hasHeightForWidth() ) );
114 GroupConstructor1Layout->addWidget( LineEditC1A1Hyp, 0, 2 );
115 SelectButtonC1A1Hyp = new QPushButton( GroupConstructor1, "SelectButtonC1A1Hyp" );
116 SelectButtonC1A1Hyp->setText( tr( "" ) );
117 SelectButtonC1A1Hyp->setPixmap( image1 );
118 GroupConstructor1Layout->addWidget( SelectButtonC1A1Hyp, 0, 1 );
119 SelectButtonC1A2Mesh = new QPushButton( GroupConstructor1, "SelectButtonC1A2Mesh" );
120 SelectButtonC1A2Mesh->setText( tr( "" ) );
121 SelectButtonC1A2Mesh->setPixmap( image1 );
122 GroupConstructor1Layout->addWidget( SelectButtonC1A2Mesh, 1, 1 );
123 TextLabelC1A2Mesh = new QLabel( GroupConstructor1, "TextLabelC1A2Mesh" );
124 TextLabelC1A2Mesh->setText( tr( "SMESH_OBJECT_MESHorSUBMESH" ) );
125 TextLabelC1A2Mesh->setMinimumSize( QSize( 50, 0 ) );
126 TextLabelC1A2Mesh->setFrameShape( QLabel::NoFrame );
127 TextLabelC1A2Mesh->setFrameShadow( QLabel::Plain );
128 GroupConstructor1Layout->addWidget( TextLabelC1A2Mesh, 1, 0 );
129 TextLabelC1A1Hyp = new QLabel( GroupConstructor1, "TextLabelC1A1Hyp" );
130 TextLabelC1A1Hyp->setText( tr( "SMESH_OBJECT_ALGORITHM" ) );
131 TextLabelC1A1Hyp->setMinimumSize( QSize( 50, 0 ) );
132 TextLabelC1A1Hyp->setFrameShape( QLabel::NoFrame );
133 TextLabelC1A1Hyp->setFrameShadow( QLabel::Plain );
134 GroupConstructor1Layout->addWidget( TextLabelC1A1Hyp, 0, 0 );
135 SMESHGUI_AddAlgorithmDlgLayout->addWidget( GroupConstructor1, 1, 0 );
137 /***************************************************************/
138 GroupButtons = new QGroupBox( this, "GroupButtons" );
139 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
140 GroupButtons->setTitle( tr( "" ) );
141 GroupButtons->setColumnLayout(0, Qt::Vertical );
142 GroupButtons->layout()->setSpacing( 0 );
143 GroupButtons->layout()->setMargin( 0 );
144 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
145 GroupButtonsLayout->setAlignment( Qt::AlignTop );
146 GroupButtonsLayout->setSpacing( 6 );
147 GroupButtonsLayout->setMargin( 11 );
148 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
149 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
150 buttonCancel->setAutoDefault( TRUE );
151 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
152 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
153 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
154 buttonApply->setAutoDefault( TRUE );
155 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
156 QSpacerItem* spacer_1 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
157 GroupButtonsLayout->addItem( spacer_1, 0, 2 );
158 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
159 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
160 buttonOk->setAutoDefault( TRUE );
161 buttonOk->setDefault( TRUE );
162 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
163 SMESHGUI_AddAlgorithmDlgLayout->addWidget( GroupButtons, 2, 0 );
170 //=================================================================================
171 // function : ~SMESHGUI_AddAlgorithmDlg()
172 // purpose : Destroys the object and frees any allocated resources
173 //=================================================================================
174 SMESHGUI_AddAlgorithmDlg::~SMESHGUI_AddAlgorithmDlg()
176 /* no need to delete child widgets, Qt does it all for us */
177 this->destroy(TRUE, TRUE) ;
182 //=================================================================================
185 //=================================================================================
186 void SMESHGUI_AddAlgorithmDlg::Init( SALOME_Selection* Sel )
189 myConstructorId = 0 ;
191 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
193 GroupConstructor1->show();
194 myConstructorId = 0 ;
195 myEditCurrentArgument = LineEditC1A1Hyp ;
196 Constructor1->setChecked( TRUE );
197 myOkMesh = myOkSubMesh = myOkAlgorithm = false ;
199 myAlgorithmFilter = new SMESH_TypeFilter( ALGORITHM );
200 myMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
202 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
204 /* signals and slots connections */
205 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
206 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
207 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
208 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
209 connect( SelectButtonC1A1Hyp, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
210 connect( SelectButtonC1A2Mesh, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
211 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
212 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
213 /* to close dialog if study change */
214 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
216 /* Move widget on the botton right corner of main widget */
218 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
220 this->show() ; /* Displays Dialog */
227 //=================================================================================
228 // function : ConstructorsClicked()
229 // purpose : Radio button management
230 //=================================================================================
231 void SMESHGUI_AddAlgorithmDlg::ConstructorsClicked(int constructorId)
233 switch (constructorId)
237 GroupConstructor1->show();
238 myConstructorId = constructorId ;
239 myEditCurrentArgument = LineEditC1A1Hyp ;
240 LineEditC1A2Mesh->setText(tr("")) ;
241 Constructor1->setChecked( TRUE );
242 myOkMesh = myOkSubMesh = myOkAlgorithm = false ;
249 //=================================================================================
250 // function : ClickOnOk()
252 //=================================================================================
253 void SMESHGUI_AddAlgorithmDlg::ClickOnOk()
255 this->ClickOnApply() ;
256 this->ClickOnCancel() ;
261 //=================================================================================
262 // function : ClickOnApply()
264 //=================================================================================
265 void SMESHGUI_AddAlgorithmDlg::ClickOnApply()
267 switch(myConstructorId)
271 if(myOkMesh && myOkAlgorithm ) {
272 SALOME_ListIteratorOfListIO It( AlgoList );
273 for(;It.More();It.Next()) {
274 Handle(SALOME_InteractiveObject) IObject = It.Value();
275 Standard_Boolean testResult;
276 myAlgorithm = mySMESHGUI->ConvertIOinSMESHHypothesis(IObject, testResult) ;
278 mySMESHGUI->AddAlgorithmOnMesh(myMesh, myAlgorithm) ;
280 } else if ( myOkSubMesh && myOkAlgorithm ) {
281 SALOME_ListIteratorOfListIO It( AlgoList );
282 for(;It.More();It.Next()) {
283 Handle(SALOME_InteractiveObject) IObject = It.Value();
284 Standard_Boolean testResult;
285 myAlgorithm = mySMESHGUI->ConvertIOinSMESHHypothesis(IObject, testResult) ;
287 mySMESHGUI->AddAlgorithmOnSubMesh(mySubMesh, myAlgorithm) ;
295 //=================================================================================
296 // function : ClickOnCancel()
298 //=================================================================================
299 void SMESHGUI_AddAlgorithmDlg::ClickOnCancel()
301 mySelection->ClearFilters() ;
302 disconnect( mySelection, 0, this, 0 );
303 mySMESHGUI->ResetState() ;
310 //=================================================================================
311 // function : SelectionIntoArgument()
312 // purpose : Called when selection has changed
313 //=================================================================================
314 void SMESHGUI_AddAlgorithmDlg::SelectionIntoArgument()
316 myEditCurrentArgument->setText("") ;
317 QString aString = "";
319 int nbSel = mySMESHGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
321 if ( myEditCurrentArgument == LineEditC1A2Mesh ) {
323 Handle(SALOME_InteractiveObject) IObject = mySelection->firstIObject();
324 QString aName = IObject->getName();
325 Standard_Boolean testResult;
327 myMesh = mySMESHGUI->ConvertIOinMesh(IObject, testResult) ;
331 mySubMesh = mySMESHGUI->ConvertIOinSubMesh(IObject, testResult) ;
337 LineEditC1A2Mesh->setText(aString) ;
340 myOkMesh = myOkSubMesh = false ;
344 else if ( myEditCurrentArgument == LineEditC1A1Hyp ) {
346 AlgoList.Clear(); // = mySelection->StoredIObjects() ;
347 SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
348 for (; Itinit.More(); Itinit.Next()) {
349 AlgoList.Append(Itinit.Value());
351 myOkAlgorithm = true ;
353 aString = tr("%1 Algorithms").arg(nbSel) ;
354 LineEditC1A1Hyp->setText(aString) ;
357 myOkAlgorithm = false ;
366 //=================================================================================
367 // function : SetEditCurrentArgument()
369 //=================================================================================
370 void SMESHGUI_AddAlgorithmDlg::SetEditCurrentArgument()
372 QPushButton* send = (QPushButton*)sender();
374 switch (myConstructorId)
376 case 0: /* default constructor */
378 if( send == SelectButtonC1A1Hyp ) {
379 LineEditC1A1Hyp->setFocus() ;
380 myEditCurrentArgument = LineEditC1A1Hyp ;
381 mySelection->ClearFilters() ;
382 mySelection->AddFilter(myAlgorithmFilter) ;
384 else if(send == SelectButtonC1A2Mesh) {
385 LineEditC1A2Mesh->setFocus() ;
386 myEditCurrentArgument = LineEditC1A2Mesh;
387 mySelection->ClearFilters() ;
388 mySelection->AddFilter(myMeshOrSubMeshFilter) ;
390 SelectionIntoArgument() ;
399 //=================================================================================
400 // function : LineEditReturnPressed()
402 //=================================================================================
403 void SMESHGUI_AddAlgorithmDlg::LineEditReturnPressed()
411 //=================================================================================
412 // function : DeactivateActiveDialog()
414 //=================================================================================
415 void SMESHGUI_AddAlgorithmDlg::DeactivateActiveDialog()
417 if ( GroupConstructors->isEnabled() ) {
419 GroupConstructors->setEnabled(false) ;
420 GroupConstructor1->setEnabled(false) ;
421 GroupButtons->setEnabled(false) ;
422 disconnect( mySelection, 0, this, 0 );
429 //=================================================================================
430 // function : closeEvent()
432 //=================================================================================
433 void SMESHGUI_AddAlgorithmDlg::closeEvent( QCloseEvent* e )
435 this->ClickOnCancel() ; /* same than click on cancel button */
439 //=================================================================================
440 // function : enterEvent()
441 // purpose : when mouse enter onto the QWidget
442 //=================================================================================
443 void SMESHGUI_AddAlgorithmDlg::enterEvent( QEvent * )
445 if ( GroupConstructors->isEnabled() )
447 ActivateThisDialog() ;
452 //=================================================================================
453 // function : ActivateThisDialog()
455 //=================================================================================
456 void SMESHGUI_AddAlgorithmDlg::ActivateThisDialog()
458 /* Emit a signal to deactivate any active dialog */
459 mySMESHGUI->EmitSignalDeactivateDialog() ;
460 GroupConstructors->setEnabled(true) ;
461 GroupConstructor1->setEnabled(true) ;
462 GroupButtons->setEnabled(true) ;
464 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );