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
29 #include "SMESHGUI_InitMeshDlg.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_SMESHGenUtils.h"
34 #include "SMESHGUI_HypothesesUtils.h"
36 #include "QAD_Application.h"
37 #include "QAD_Desktop.h"
38 #include "QAD_MessageBox.h"
39 #include "QAD_WaitCursor.h"
40 #include "QAD_Operation.h"
42 #include "SALOME_ListIteratorOfListIO.hxx"
43 #include "SALOMEGUI_QtCatchCorbaException.hxx"
45 #include "utilities.h"
48 #include <qgroupbox.h>
50 #include <qlineedit.h>
51 #include <qpushbutton.h>
58 SMESH::SMESH_Mesh_var InitMesh(GEOM::GEOM_Object_ptr theShapeObject,
59 const char* theMeshName)
61 SMESH::SMESH_Mesh_var aMesh;
63 SMESH::SMESH_Gen_var aSMESHGen = SMESH::GetSMESHGen();
64 if ( !aSMESHGen->_is_nil() && !theShapeObject->_is_nil() ) {
65 aMesh = aSMESHGen->CreateMesh( theShapeObject );
66 if ( !aMesh->_is_nil() ) {
67 SALOMEDS::SObject_var aMeshSObject = SMESH::FindSObject( aMesh.in() );
68 SMESH::SetName( aMeshSObject, theMeshName );
72 catch( const SALOME::SALOME_Exception& S_ex ) {
73 QtCatchCorbaException( S_ex );
79 //=================================================================================
80 // class : SMESHGUI_InitMeshDlg()
81 // purpose : Constructs a SMESHGUI_InitMeshDlg which is a child of 'parent', with the
82 // name 'name' and widget flags set to 'f'.
83 // The dialog will by default be modeless, unless you set 'modal' to
84 // TRUE to construct a modal dialog.
85 //=================================================================================
86 SMESHGUI_InitMeshDlg::SMESHGUI_InitMeshDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
87 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
89 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
91 setName( "SMESHGUI_InitMeshDlg" );
92 setCaption( tr( "SMESH_INIT_MESH" ) );
93 setSizeGripEnabled( TRUE );
94 QGridLayout* SMESHGUI_InitMeshDlgLayout = new QGridLayout( this );
95 SMESHGUI_InitMeshDlgLayout->setSpacing( 6 );
96 SMESHGUI_InitMeshDlgLayout->setMargin( 11 );
98 /***************************************************************/
99 GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), this, "GroupC1" );
100 GroupC1->setColumnLayout(0, Qt::Vertical );
101 GroupC1->layout()->setSpacing( 0 );
102 GroupC1->layout()->setMargin( 0 );
103 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
104 GroupC1Layout->setAlignment( Qt::AlignTop );
105 GroupC1Layout->setSpacing( 6 );
106 GroupC1Layout->setMargin( 11 );
108 TextLabel_NameMesh = new QLabel( tr( "SMESH_NAME" ), GroupC1, "TextLabel_NameMesh" );
109 GroupC1Layout->addWidget( TextLabel_NameMesh, 0, 0 );
110 LineEdit_NameMesh = new QLineEdit( GroupC1, "LineEdit_NameMesh" );
111 GroupC1Layout->addWidget( LineEdit_NameMesh, 0, 2 );
113 TextLabelC1A1 = new QLabel( tr( "SMESH_OBJECT_GEOM" ), GroupC1, "TextLabelC1A1" );
114 GroupC1Layout->addWidget( TextLabelC1A1, 1, 0 );
115 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
116 SelectButtonC1A1->setPixmap( image0 );
117 SelectButtonC1A1->setToggleButton( FALSE );
118 GroupC1Layout->addWidget( SelectButtonC1A1, 1, 1 );
119 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
120 LineEditC1A1->setReadOnly( true );
121 GroupC1Layout->addWidget( LineEditC1A1, 1, 2 );
123 TextLabelC1A1Hyp = new QLabel( tr( "SMESH_OBJECT_HYPOTHESIS" ), GroupC1, "TextLabelC1A1Hyp" );
124 GroupC1Layout->addWidget( TextLabelC1A1Hyp, 2, 0 );
125 SelectButtonC1A1Hyp = new QPushButton( GroupC1, "SelectButtonC1A1Hyp" );
126 SelectButtonC1A1Hyp->setPixmap( image0 );
127 GroupC1Layout->addWidget( SelectButtonC1A1Hyp, 2, 1 );
128 LineEditC1A1Hyp = new QLineEdit( GroupC1, "LineEditC1A1Hyp" );
129 LineEditC1A1Hyp->setReadOnly( true );
130 GroupC1Layout->addWidget( LineEditC1A1Hyp, 2, 2 );
132 TextLabelC1A1Algo = new QLabel( tr( "SMESH_OBJECT_ALGORITHM" ), GroupC1, "TextLabelC1A1Algo" );
133 GroupC1Layout->addWidget( TextLabelC1A1Algo, 3, 0 );
134 SelectButtonC1A1Algo = new QPushButton( GroupC1, "SelectButtonC1A1Algo" );
135 SelectButtonC1A1Algo->setPixmap( image0 );
136 GroupC1Layout->addWidget( SelectButtonC1A1Algo, 3, 1 );
137 LineEditC1A1Algo = new QLineEdit( GroupC1, "LineEditC1A1Algo" );
138 LineEditC1A1Algo->setReadOnly( true );
139 GroupC1Layout->addWidget( LineEditC1A1Algo, 3, 2 );
141 SMESHGUI_InitMeshDlgLayout->addWidget( GroupC1, 1, 0 );
143 /***************************************************************/
144 GroupButtons = new QGroupBox( this, "GroupButtons" );
145 GroupButtons->setColumnLayout(0, Qt::Vertical );
146 GroupButtons->layout()->setSpacing( 0 );
147 GroupButtons->layout()->setMargin( 0 );
148 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
149 GroupButtonsLayout->setAlignment( Qt::AlignTop );
150 GroupButtonsLayout->setSpacing( 6 );
151 GroupButtonsLayout->setMargin( 11 );
153 buttonOk = new QPushButton( tr( "SMESH_BUT_OK" ), GroupButtons, "buttonOk" );
154 buttonOk->setAutoDefault( TRUE );
155 buttonOk->setDefault( TRUE );
156 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
158 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons, "buttonApply" );
159 buttonApply->setAutoDefault( TRUE );
160 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
162 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 2 );
164 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons, "buttonCancel" );
165 buttonCancel->setAutoDefault( TRUE );
166 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
168 SMESHGUI_InitMeshDlgLayout->addWidget( GroupButtons, 2, 0 );
170 /***************************************************************/
175 //=================================================================================
176 // function : ~SMESHGUI_InitMeshDlg()
177 // purpose : Destroys the object and frees any allocated resources
178 //=================================================================================
179 SMESHGUI_InitMeshDlg::~SMESHGUI_InitMeshDlg()
181 // no need to delete child widgets, Qt does it all for us
185 //=================================================================================
188 //=================================================================================
189 void SMESHGUI_InitMeshDlg::Init( SALOME_Selection* Sel )
192 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
193 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
195 myGeomFilter = new SALOME_TypeFilter( "GEOM" );
196 myAlgorithmFilter = new SMESH_TypeFilter( ALGORITHM );
197 myHypothesisFilter = new SMESH_TypeFilter( HYPOTHESIS );
199 /* signals and slots connections */
200 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
201 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
202 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
204 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
205 connect( SelectButtonC1A1Hyp, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
206 connect( SelectButtonC1A1Algo, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
208 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
209 connect( mySMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
210 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
213 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
217 LineEdit_NameMesh->setText( tr( "SMESH_OBJECT_MESH" ) );
218 LineEdit_NameMesh->setFocus() ;
219 myEditCurrentArgument = LineEditC1A1 ;
220 mySelection->ClearFilters() ;
221 mySelection->AddFilter( myGeomFilter ) ;
223 SelectionIntoArgument();
225 UpdateControlState();
229 //=================================================================================
230 // function : ClickOnOk()
232 //=================================================================================
233 void SMESHGUI_InitMeshDlg::ClickOnOk()
235 if ( this->ClickOnApply() )
236 this->ClickOnCancel() ;
239 //=================================================================================
240 // function : ClickOnApply()
242 //=================================================================================
243 bool SMESHGUI_InitMeshDlg::ClickOnApply()
245 if (mySMESHGUI->ActiveStudyLocked())
248 QString myNameMesh = LineEdit_NameMesh->text().stripWhiteSpace();
249 if ( myNameMesh.isEmpty() ) {
250 QAD_MessageBox::warn1( this, tr( "SMESH_WRN_WARNING" ), tr( "SMESH_WRN_EMPTY_NAME" ), tr( "SMESH_BUT_OK" ) );
254 if ( myGeomShape->_is_nil() || !HypoList.count() || !AlgoList.count() )
259 QAD_Operation* op = new QAD_Operation( mySMESHGUI->GetActiveStudy() );
265 SMESH::SMESH_Mesh_var aMesh = SMESH::InitMesh( myGeomShape, myNameMesh ) ;
267 if ( !aMesh->_is_nil() ) {
269 for( int i = 0; i < HypoList.count(); i++ ) {
270 SALOMEDS::SObject_var aHypSO = SMESH::GetActiveStudyDocument()->FindObjectID( HypoList[i] );
271 if ( !aHypSO->_is_nil() ) {
272 CORBA::Object_var anObject = aHypSO->GetObject();
273 if ( !CORBA::is_nil( anObject ) ) {
274 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
275 if ( !aHyp->_is_nil() ) {
276 if ( !SMESH::AddHypothesisOnMesh( aMesh, aHyp ) ) {
286 for( int i = 0; i < AlgoList.count(); i++ ) {
287 SALOMEDS::SObject_var aHypSO = SMESH::GetActiveStudyDocument()->FindObjectID( AlgoList[i] );
288 if ( !aHypSO->_is_nil() ) {
289 CORBA::Object_var anObject = aHypSO->GetObject();
290 if ( !CORBA::is_nil( anObject ) ) {
291 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
292 if ( !aHyp->_is_nil() ) {
293 if ( !SMESH::AddHypothesisOnMesh( aMesh, aHyp ) ) {
303 // commit transaction
309 //=================================================================================
310 // function : ClickOnCancel()
312 //=================================================================================
313 void SMESHGUI_InitMeshDlg::ClickOnCancel()
319 //=================================================================================
320 // function : SelectionIntoArgument()
321 // purpose : Called when selection as changed or other case
322 //=================================================================================
323 void SMESHGUI_InitMeshDlg::SelectionIntoArgument()
325 QString aString = "";
327 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelection, aString) ;
329 if ( myEditCurrentArgument == LineEditC1A1 ) {
332 myGeomShape = GEOM::GEOM_Object::_nil();
336 Standard_Boolean testResult ;
337 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
338 myGeomShape = SMESH::IObjectToInterface<GEOM::GEOM_Object>(IO) ;
339 if( myGeomShape->_is_nil() ) {
344 else if ( myEditCurrentArgument == LineEditC1A1Hyp ) {
348 SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
349 for ( ; Itinit.More(); Itinit.Next() ) {
350 HypoList.append( Itinit.Value()->getEntry() );
353 aString = tr( "%1 Hypothesis" ).arg( nbSel ) ;
359 else if ( myEditCurrentArgument == LineEditC1A1Algo ) {
363 SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
364 for ( ; Itinit.More(); Itinit.Next() ) {
365 AlgoList.append( Itinit.Value()->getEntry() );
368 aString = tr( "%1 Algorithms" ).arg( nbSel ) ;
375 myEditCurrentArgument->setText(aString) ;
377 UpdateControlState();
381 //=================================================================================
382 // function : SetEditCurrentArgument()
384 //=================================================================================
385 void SMESHGUI_InitMeshDlg::SetEditCurrentArgument()
387 QPushButton* send = (QPushButton*)sender();
388 if(send == SelectButtonC1A1) {
389 LineEditC1A1->setFocus() ;
390 myEditCurrentArgument = LineEditC1A1;
391 mySelection->ClearFilters() ;
392 mySelection->AddFilter(myGeomFilter) ;
393 } else if( send == SelectButtonC1A1Hyp ) {
394 LineEditC1A1Hyp->setFocus() ;
395 myEditCurrentArgument = LineEditC1A1Hyp ;
396 mySelection->ClearFilters() ;
397 mySelection->AddFilter(myHypothesisFilter) ;
398 } else if( send == SelectButtonC1A1Algo ) {
399 LineEditC1A1Algo->setFocus() ;
400 myEditCurrentArgument = LineEditC1A1Algo ;
401 mySelection->ClearFilters() ;
402 mySelection->AddFilter(myAlgorithmFilter) ;
404 SelectionIntoArgument() ;
407 //=================================================================================
408 // function : DeactivateActiveDialog()
410 //=================================================================================
411 void SMESHGUI_InitMeshDlg::DeactivateActiveDialog()
413 if ( GroupC1->isEnabled() ) {
414 disconnect( mySelection, 0, this, 0 );
415 GroupC1->setEnabled(false) ;
416 GroupButtons->setEnabled(false) ;
421 //=================================================================================
422 // function : ActivateThisDialog()
424 //=================================================================================
425 void SMESHGUI_InitMeshDlg::ActivateThisDialog()
427 mySMESHGUI->EmitSignalDeactivateDialog() ;
428 GroupC1->setEnabled(true) ;
429 GroupButtons->setEnabled(true) ;
430 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
434 //=================================================================================
435 // function : enterEvent()
437 //=================================================================================
438 void SMESHGUI_InitMeshDlg::enterEvent(QEvent* e)
440 if ( !GroupC1->isEnabled() )
441 ActivateThisDialog() ;
445 //=================================================================================
446 // function : closeEvent()
448 //=================================================================================
449 void SMESHGUI_InitMeshDlg::closeEvent( QCloseEvent* e )
451 disconnect( mySelection, 0, this, 0 );
452 mySMESHGUI->ResetState() ;
453 mySelection->ClearFilters() ;
454 QDialog::closeEvent( e );
457 //=================================================================================
458 // function : UpdateControlState()
460 //=================================================================================
461 void SMESHGUI_InitMeshDlg::UpdateControlState()
463 bool isEnabled = ( !myGeomShape->_is_nil() && HypoList.count() && AlgoList.count() );
465 buttonOk ->setEnabled( isEnabled );
466 buttonApply->setEnabled( isEnabled );