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_AddVolumeDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "SMESHGUI_AddVolumeDlg.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_MessageBox.h"
36 #include "utilities.h"
39 #include <qbuttongroup.h>
40 #include <qgroupbox.h>
42 #include <qlineedit.h>
43 #include <qpushbutton.h>
44 #include <qradiobutton.h>
48 #include <qwhatsthis.h>
51 #include <qcheckbox.h>
54 //=================================================================================
55 // class : SMESHGUI_AddVolumeDlg()
57 //=================================================================================
58 SMESHGUI_AddVolumeDlg::SMESHGUI_AddVolumeDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
59 int nbNodes, bool modal, WFlags fl )
60 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
65 image0 = QPixmap(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_TETRAS")));
66 else if ( myNodes == 8 )
67 image0 = QPixmap(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_HEXAS")));
69 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
72 setName( "SMESHGUI_AddVolumeDlg" );
75 setCaption( tr( "SMESH_ADD_TETRAS_TITLE" ) );
76 else if ( myNodes == 8 )
77 setCaption( tr( "SMESH_ADD_HEXAS_TITLE" ) );
79 setSizeGripEnabled( TRUE );
80 SMESHGUI_AddVolumeDlgLayout = new QGridLayout( this );
81 SMESHGUI_AddVolumeDlgLayout->setSpacing( 6 );
82 SMESHGUI_AddVolumeDlgLayout->setMargin( 11 );
84 /***************************************************************/
85 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
87 GroupConstructors->setTitle( tr( "SMESH_TETRAS" ) );
88 else if ( myNodes == 8 )
89 GroupConstructors->setTitle( tr( "SMESH_HEXAS" ) );
91 GroupConstructors->setExclusive( TRUE );
92 GroupConstructors->setColumnLayout(0, Qt::Vertical );
93 GroupConstructors->layout()->setSpacing( 0 );
94 GroupConstructors->layout()->setMargin( 0 );
95 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
96 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
97 GroupConstructorsLayout->setSpacing( 6 );
98 GroupConstructorsLayout->setMargin( 11 );
99 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
100 Constructor1->setText( tr( "" ) );
101 Constructor1->setPixmap( image0 );
102 Constructor1->setChecked( TRUE );
103 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
104 Constructor1->setMinimumSize( QSize( 50, 0 ) );
105 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
106 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
107 GroupConstructorsLayout->addItem( spacer, 0, 1 );
108 SMESHGUI_AddVolumeDlgLayout->addWidget( GroupConstructors, 0, 0 );
110 /***************************************************************/
111 GroupButtons = new QGroupBox( this, "GroupButtons" );
112 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
113 GroupButtons->setTitle( tr( "" ) );
114 GroupButtons->setColumnLayout(0, Qt::Vertical );
115 GroupButtons->layout()->setSpacing( 0 );
116 GroupButtons->layout()->setMargin( 0 );
117 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
118 GroupButtonsLayout->setAlignment( Qt::AlignTop );
119 GroupButtonsLayout->setSpacing( 6 );
120 GroupButtonsLayout->setMargin( 11 );
121 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
122 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
123 buttonCancel->setAutoDefault( TRUE );
124 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
125 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
126 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
127 buttonApply->setAutoDefault( TRUE );
128 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
129 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
130 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
131 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
132 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
133 buttonOk->setAutoDefault( TRUE );
134 buttonOk->setDefault( TRUE );
135 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
136 SMESHGUI_AddVolumeDlgLayout->addWidget( GroupButtons, 2, 0 );
138 /***************************************************************/
139 GroupC1 = new QGroupBox( this, "GroupC1" );
141 GroupC1->setTitle( tr( "SMESH_ADD_TETRAS" ) );
142 else if ( myNodes == 8 )
143 GroupC1->setTitle( tr( "SMESH_ADD_HEXAS" ) );
145 GroupC1->setMinimumSize( QSize( 0, 0 ) );
146 GroupC1->setFrameShape( QGroupBox::Box );
147 GroupC1->setFrameShadow( QGroupBox::Sunken );
148 GroupC1->setColumnLayout(0, Qt::Vertical );
149 GroupC1->layout()->setSpacing( 0 );
150 GroupC1->layout()->setMargin( 0 );
151 GroupC1Layout = new QGridLayout( GroupC1->layout() );
152 GroupC1Layout->setAlignment( Qt::AlignTop );
153 GroupC1Layout->setSpacing( 6 );
154 GroupC1Layout->setMargin( 11 );
155 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
156 TextLabelC1A1->setText( tr( "SMESH_ID_NODES" ) );
157 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
158 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
159 TextLabelC1A1->setFrameShadow( QLabel::Plain );
160 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
161 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
162 SelectButtonC1A1->setText( tr( "" ) );
163 SelectButtonC1A1->setPixmap( image1 );
164 SelectButtonC1A1->setToggleButton( FALSE );
165 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
166 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
167 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
169 SMESHGUI_AddVolumeDlgLayout->addWidget( GroupC1, 1, 0 );
171 Init(Sel) ; /* Initialisations */
174 //=================================================================================
175 // function : ~SMESHGUI_AddVolumeDlg()
176 // purpose : Destroys the object and frees any allocated resources
177 //=================================================================================
178 SMESHGUI_AddVolumeDlg::~SMESHGUI_AddVolumeDlg()
180 // no need to delete child widgets, Qt does it all for us
184 //=================================================================================
187 //=================================================================================
188 void SMESHGUI_AddVolumeDlg::Init( SALOME_Selection* Sel )
192 myConstructorId = 0 ;
193 Constructor1->setChecked( TRUE );
194 myEditCurrentArgument = LineEditC1A1 ;
196 this->myOkNodes = false ;
197 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
198 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
200 /* signals and slots connections */
201 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
202 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
203 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
204 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
206 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
207 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
208 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
209 /* to close dialog if study change */
210 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
212 /* Move widget on the botton right corner of main widget */
214 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
216 this->show() ; /* displays Dialog */
218 SelectionIntoArgument();
224 //=================================================================================
225 // function : ConstructorsClicked()
226 // purpose : Radio button management
227 //=================================================================================
228 void SMESHGUI_AddVolumeDlg::ConstructorsClicked(int constructorId)
234 //=================================================================================
235 // function : ClickOnApply()
237 //=================================================================================
238 void SMESHGUI_AddVolumeDlg::ClickOnApply()
240 switch(myConstructorId)
245 mySMESHGUI->EraseSimulationActors();
246 mySMESHGUI->AddVolume( myMesh, myMapIndex ) ;
247 mySMESHGUI->ViewNodes();
248 mySelection->ClearIObjects();
256 //=================================================================================
257 // function : ClickOnOk()
259 //=================================================================================
260 void SMESHGUI_AddVolumeDlg::ClickOnOk()
262 this->ClickOnApply() ;
263 this->ClickOnCancel() ;
267 //=================================================================================
268 // function : ClickOnCancel()
270 //=================================================================================
271 void SMESHGUI_AddVolumeDlg::ClickOnCancel()
273 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
274 disconnect( mySelection, 0, this, 0 );
275 mySMESHGUI->ResetState() ;
276 mySMESHGUI->EraseSimulationActors();
282 //=================================================================================
283 // function : SelectionIntoArgument()
284 // purpose : Called when selection as changed or other case
285 //=================================================================================
286 void SMESHGUI_AddVolumeDlg::SelectionIntoArgument()
288 myEditCurrentArgument->setText("") ;
290 QString aString = "";
292 int nbSel = mySelection->IObjectCount();
296 int nbNodes = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aString) ;
300 if ( mySelection->SelectionMode() != NodeSelection ) {
301 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
302 tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_OK") );
306 myEditCurrentArgument->setText(aString) ;
307 Standard_Boolean res;
308 myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
312 mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
314 if ( myNodes == 4 && nbNodes == 4 ) {
315 mySMESHGUI->DisplaySimulationTetra(myMesh, myMapIndex);
317 } else if ( myNodes == 8 && nbNodes == 8 ) {
318 mySMESHGUI->DisplaySimulationHexa(myMesh, myMapIndex);
321 // mySMESHGUI->EraseSimulationActors();
328 //=================================================================================
329 // function : SetEditCurrentArgument()
331 //=================================================================================
332 void SMESHGUI_AddVolumeDlg::SetEditCurrentArgument()
334 QPushButton* send = (QPushButton*)sender();
335 switch (myConstructorId)
337 case 0: /* default constructor */
339 if(send == SelectButtonC1A1) {
340 LineEditC1A1->setFocus() ;
341 myEditCurrentArgument = LineEditC1A1;
343 SelectionIntoArgument() ;
350 //=================================================================================
351 // function : DeactivateActiveDialog()
353 //=================================================================================
354 void SMESHGUI_AddVolumeDlg::DeactivateActiveDialog()
356 if ( GroupConstructors->isEnabled() ) {
357 GroupConstructors->setEnabled(false) ;
358 GroupC1->setEnabled(false) ;
359 GroupButtons->setEnabled(false) ;
360 mySMESHGUI->EraseSimulationActors() ;
361 mySMESHGUI->ResetState() ;
362 mySMESHGUI->SetActiveDialogBox(0) ;
368 //=================================================================================
369 // function : ActivateThisDialog()
371 //=================================================================================
372 void SMESHGUI_AddVolumeDlg::ActivateThisDialog()
374 /* Emit a signal to deactivate the active dialog */
375 mySMESHGUI->EmitSignalDeactivateDialog() ;
376 GroupConstructors->setEnabled(true) ;
377 GroupC1->setEnabled(true) ;
378 GroupButtons->setEnabled(true) ;
383 //=================================================================================
384 // function : enterEvent()
386 //=================================================================================
387 void SMESHGUI_AddVolumeDlg::enterEvent(QEvent* e)
389 if ( GroupConstructors->isEnabled() )
391 ActivateThisDialog() ;
396 //=================================================================================
397 // function : closeEvent()
399 //=================================================================================
400 void SMESHGUI_AddVolumeDlg::closeEvent( QCloseEvent* e )
402 /* same than click on cancel button */
403 this->ClickOnCancel() ;