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_InitMeshDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "SMESHGUI_InitMeshDlg.h"
32 #include "SALOME_ListIteratorOfListIO.hxx"
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "QAD_MessageBox.h"
37 #include "QAD_WaitCursor.h"
38 #include "QAD_Operation.h"
40 #include "utilities.h"
43 #include <qgroupbox.h>
45 #include <qlineedit.h>
46 #include <qpushbutton.h>
50 //=================================================================================
51 // class : SMESHGUI_InitMeshDlg()
52 // purpose : Constructs a SMESHGUI_InitMeshDlg which is a child of 'parent', with the
53 // name 'name' and widget flags set to 'f'.
54 // The dialog will by default be modeless, unless you set 'modal' to
55 // TRUE to construct a modal dialog.
56 //=================================================================================
57 SMESHGUI_InitMeshDlg::SMESHGUI_InitMeshDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
58 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
60 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
62 setName( "SMESHGUI_InitMeshDlg" );
63 setCaption( tr( "SMESH_INIT_MESH" ) );
64 setSizeGripEnabled( TRUE );
65 QGridLayout* SMESHGUI_InitMeshDlgLayout = new QGridLayout( this );
66 SMESHGUI_InitMeshDlgLayout->setSpacing( 6 );
67 SMESHGUI_InitMeshDlgLayout->setMargin( 11 );
69 /***************************************************************/
70 GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), this, "GroupC1" );
71 GroupC1->setColumnLayout(0, Qt::Vertical );
72 GroupC1->layout()->setSpacing( 0 );
73 GroupC1->layout()->setMargin( 0 );
74 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
75 GroupC1Layout->setAlignment( Qt::AlignTop );
76 GroupC1Layout->setSpacing( 6 );
77 GroupC1Layout->setMargin( 11 );
79 TextLabel_NameMesh = new QLabel( tr( "SMESH_NAME" ), GroupC1, "TextLabel_NameMesh" );
80 GroupC1Layout->addWidget( TextLabel_NameMesh, 0, 0 );
81 LineEdit_NameMesh = new QLineEdit( GroupC1, "LineEdit_NameMesh" );
82 GroupC1Layout->addWidget( LineEdit_NameMesh, 0, 2 );
84 TextLabelC1A1 = new QLabel( tr( "SMESH_OBJECT_GEOM" ), GroupC1, "TextLabelC1A1" );
85 GroupC1Layout->addWidget( TextLabelC1A1, 1, 0 );
86 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
87 SelectButtonC1A1->setPixmap( image0 );
88 SelectButtonC1A1->setToggleButton( FALSE );
89 GroupC1Layout->addWidget( SelectButtonC1A1, 1, 1 );
90 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
91 GroupC1Layout->addWidget( LineEditC1A1, 1, 2 );
93 TextLabelC1A1Hyp = new QLabel( tr( "SMESH_OBJECT_HYPOTHESIS" ), GroupC1, "TextLabelC1A1Hyp" );
94 GroupC1Layout->addWidget( TextLabelC1A1Hyp, 2, 0 );
95 SelectButtonC1A1Hyp = new QPushButton( GroupC1, "SelectButtonC1A1Hyp" );
96 SelectButtonC1A1Hyp->setPixmap( image0 );
97 GroupC1Layout->addWidget( SelectButtonC1A1Hyp, 2, 1 );
98 LineEditC1A1Hyp = new QLineEdit( GroupC1, "LineEditC1A1Hyp" );
99 GroupC1Layout->addWidget( LineEditC1A1Hyp, 2, 2 );
101 TextLabelC1A1Algo = new QLabel( tr( "SMESH_OBJECT_ALGORITHM" ), GroupC1, "TextLabelC1A1Algo" );
102 GroupC1Layout->addWidget( TextLabelC1A1Algo, 3, 0 );
103 SelectButtonC1A1Algo = new QPushButton( GroupC1, "SelectButtonC1A1Algo" );
104 SelectButtonC1A1Algo->setPixmap( image0 );
105 GroupC1Layout->addWidget( SelectButtonC1A1Algo, 3, 1 );
106 LineEditC1A1Algo = new QLineEdit( GroupC1, "LineEditC1A1Algo" );
107 GroupC1Layout->addWidget( LineEditC1A1Algo, 3, 2 );
109 SMESHGUI_InitMeshDlgLayout->addWidget( GroupC1, 1, 0 );
111 /***************************************************************/
112 GroupButtons = new QGroupBox( this, "GroupButtons" );
113 GroupButtons->setColumnLayout(0, Qt::Vertical );
114 GroupButtons->layout()->setSpacing( 0 );
115 GroupButtons->layout()->setMargin( 0 );
116 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
117 GroupButtonsLayout->setAlignment( Qt::AlignTop );
118 GroupButtonsLayout->setSpacing( 6 );
119 GroupButtonsLayout->setMargin( 11 );
121 buttonOk = new QPushButton( tr( "SMESH_BUT_OK" ), GroupButtons, "buttonOk" );
122 buttonOk->setAutoDefault( TRUE );
123 buttonOk->setDefault( TRUE );
124 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
126 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons, "buttonApply" );
127 buttonApply->setAutoDefault( TRUE );
128 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
130 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 2 );
132 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons, "buttonCancel" );
133 buttonCancel->setAutoDefault( TRUE );
134 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
136 SMESHGUI_InitMeshDlgLayout->addWidget( GroupButtons, 2, 0 );
138 /***************************************************************/
143 //=================================================================================
144 // function : ~SMESHGUI_InitMeshDlg()
145 // purpose : Destroys the object and frees any allocated resources
146 //=================================================================================
147 SMESHGUI_InitMeshDlg::~SMESHGUI_InitMeshDlg()
149 // no need to delete child widgets, Qt does it all for us
153 //=================================================================================
156 //=================================================================================
157 void SMESHGUI_InitMeshDlg::Init( SALOME_Selection* Sel )
160 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
161 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
163 myGeomFilter = new SALOME_TypeFilter( "GEOM" );
164 myAlgorithmFilter = new SMESH_TypeFilter( ALGORITHM );
165 myHypothesisFilter = new SMESH_TypeFilter( HYPOTHESIS );
167 /* signals and slots connections */
168 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
169 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
170 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
172 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
173 connect( SelectButtonC1A1Hyp, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
174 connect( SelectButtonC1A1Algo, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
176 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
177 connect( mySMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
178 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
181 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
185 LineEdit_NameMesh->setText( tr( "SMESH_OBJECT_MESH" ) );
186 LineEdit_NameMesh->setFocus() ;
187 myEditCurrentArgument = LineEditC1A1 ;
188 mySelection->ClearFilters() ;
189 mySelection->AddFilter( myGeomFilter ) ;
191 SelectionIntoArgument();
193 UpdateControlState();
197 //=================================================================================
198 // function : ClickOnOk()
200 //=================================================================================
201 void SMESHGUI_InitMeshDlg::ClickOnOk()
203 if ( this->ClickOnApply() )
204 this->ClickOnCancel() ;
207 //=================================================================================
208 // function : ClickOnApply()
210 //=================================================================================
211 bool SMESHGUI_InitMeshDlg::ClickOnApply()
213 QString myNameMesh = LineEdit_NameMesh->text().stripWhiteSpace();
214 if ( myNameMesh.isEmpty() ) {
215 QAD_MessageBox::warn1( this, tr( "SMESH_WRN_WARNING" ), tr( "SMESH_WRN_EMPTY_NAME" ), tr( "SMESH_BUT_OK" ) );
219 if ( myGeomShape->_is_nil() || !HypoList.count() || !AlgoList.count() )
224 QAD_Operation* op = new QAD_Operation( mySMESHGUI->GetActiveStudy() );
230 SMESH::SMESH_Mesh_var aMesh = mySMESHGUI->InitMesh( myGeomShape, myNameMesh ) ;
232 if ( !aMesh->_is_nil() ) {
234 for( int i = 0; i < HypoList.count(); i++ ) {
235 SALOMEDS::SObject_var aHypSO = mySMESHGUI->GetStudy()->FindObjectID( HypoList[i] );
236 if ( !aHypSO->_is_nil() ) {
237 CORBA::Object_var anObject = aHypSO->GetObject();
238 if ( !CORBA::is_nil( anObject ) ) {
239 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
240 if ( !aHyp->_is_nil() ) {
241 if ( !mySMESHGUI->AddHypothesisOnMesh( aMesh, aHyp ) ) {
251 for( int i = 0; i < AlgoList.count(); i++ ) {
252 SALOMEDS::SObject_var aHypSO = mySMESHGUI->GetStudy()->FindObjectID( AlgoList[i] );
253 if ( !aHypSO->_is_nil() ) {
254 CORBA::Object_var anObject = aHypSO->GetObject();
255 if ( !CORBA::is_nil( anObject ) ) {
256 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
257 if ( !aHyp->_is_nil() ) {
258 if ( !mySMESHGUI->AddAlgorithmOnMesh( aMesh, aHyp ) ) {
268 // commit transaction
274 //=================================================================================
275 // function : ClickOnCancel()
277 //=================================================================================
278 void SMESHGUI_InitMeshDlg::ClickOnCancel()
284 //=================================================================================
285 // function : SelectionIntoArgument()
286 // purpose : Called when selection as changed or other case
287 //=================================================================================
288 void SMESHGUI_InitMeshDlg::SelectionIntoArgument()
290 QString aString = "";
292 int nbSel = mySMESHGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
294 if ( myEditCurrentArgument == LineEditC1A1 ) {
297 myGeomShape = GEOM::GEOM_Shape::_nil();
301 Standard_Boolean testResult ;
302 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
303 myGeomShape = mySMESHGUI->ConvertIOinGEOMShape(IO, testResult) ;
305 myGeomShape = GEOM::GEOM_Shape::_nil();
310 else if ( myEditCurrentArgument == LineEditC1A1Hyp ) {
314 SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
315 for ( ; Itinit.More(); Itinit.Next() ) {
316 HypoList.append( Itinit.Value()->getEntry() );
319 aString = tr( "%1 Hypothesis" ).arg( nbSel ) ;
325 else if ( myEditCurrentArgument == LineEditC1A1Algo ) {
329 SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
330 for ( ; Itinit.More(); Itinit.Next() ) {
331 AlgoList.append( Itinit.Value()->getEntry() );
334 aString = tr( "%1 Algorithms" ).arg( nbSel ) ;
341 myEditCurrentArgument->setText(aString) ;
343 UpdateControlState();
347 //=================================================================================
348 // function : SetEditCurrentArgument()
350 //=================================================================================
351 void SMESHGUI_InitMeshDlg::SetEditCurrentArgument()
353 QPushButton* send = (QPushButton*)sender();
354 if(send == SelectButtonC1A1) {
355 LineEditC1A1->setFocus() ;
356 myEditCurrentArgument = LineEditC1A1;
357 mySelection->ClearFilters() ;
358 mySelection->AddFilter(myGeomFilter) ;
359 } else if( send == SelectButtonC1A1Hyp ) {
360 LineEditC1A1Hyp->setFocus() ;
361 myEditCurrentArgument = LineEditC1A1Hyp ;
362 mySelection->ClearFilters() ;
363 mySelection->AddFilter(myHypothesisFilter) ;
364 } else if( send == SelectButtonC1A1Algo ) {
365 LineEditC1A1Algo->setFocus() ;
366 myEditCurrentArgument = LineEditC1A1Algo ;
367 mySelection->ClearFilters() ;
368 mySelection->AddFilter(myAlgorithmFilter) ;
370 SelectionIntoArgument() ;
373 //=================================================================================
374 // function : DeactivateActiveDialog()
376 //=================================================================================
377 void SMESHGUI_InitMeshDlg::DeactivateActiveDialog()
379 if ( GroupC1->isEnabled() ) {
380 disconnect( mySelection, 0, this, 0 );
381 GroupC1->setEnabled(false) ;
382 GroupButtons->setEnabled(false) ;
387 //=================================================================================
388 // function : ActivateThisDialog()
390 //=================================================================================
391 void SMESHGUI_InitMeshDlg::ActivateThisDialog()
393 mySMESHGUI->EmitSignalDeactivateDialog() ;
394 GroupC1->setEnabled(true) ;
395 GroupButtons->setEnabled(true) ;
396 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
400 //=================================================================================
401 // function : enterEvent()
403 //=================================================================================
404 void SMESHGUI_InitMeshDlg::enterEvent(QEvent* e)
406 if ( !GroupC1->isEnabled() )
407 ActivateThisDialog() ;
411 //=================================================================================
412 // function : closeEvent()
414 //=================================================================================
415 void SMESHGUI_InitMeshDlg::closeEvent( QCloseEvent* e )
417 disconnect( mySelection, 0, this, 0 );
418 mySMESHGUI->ResetState() ;
419 mySelection->ClearFilters() ;
420 QDialog::closeEvent( e );
423 //=================================================================================
424 // function : UpdateControlState()
426 //=================================================================================
427 void SMESHGUI_InitMeshDlg::UpdateControlState()
429 bool isEnabled = ( !myGeomShape->_is_nil() && HypoList.count() && AlgoList.count() );
431 buttonOk ->setEnabled( isEnabled );
432 buttonApply->setEnabled( isEnabled );