2 // File : SMESHGUI_AddVolumeDlg.cxx
3 // Created : Wed Jun 26 21:00:14 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
12 #include "SMESHGUI_AddVolumeDlg.h"
15 #include "QAD_Application.h"
16 #include "QAD_Desktop.h"
17 #include "QAD_MessageBox.h"
18 #include "utilities.h"
21 #include <qbuttongroup.h>
22 #include <qgroupbox.h>
24 #include <qlineedit.h>
25 #include <qpushbutton.h>
26 #include <qradiobutton.h>
30 #include <qwhatsthis.h>
33 #include <qcheckbox.h>
36 //=================================================================================
37 // class : SMESHGUI_AddVolumeDlg()
39 //=================================================================================
40 SMESHGUI_AddVolumeDlg::SMESHGUI_AddVolumeDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
41 int nbNodes, bool modal, WFlags fl )
42 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
47 image0 = QPixmap(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_TETRAS")));
48 else if ( myNodes == 8 )
49 image0 = QPixmap(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_HEXAS")));
51 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
54 setName( "SMESHGUI_AddVolumeDlg" );
57 setCaption( tr( "SMESH_ADD_TETRAS_TITLE" ) );
58 else if ( myNodes == 8 )
59 setCaption( tr( "SMESH_ADD_HEXAS_TITLE" ) );
61 setSizeGripEnabled( TRUE );
62 SMESHGUI_AddVolumeDlgLayout = new QGridLayout( this );
63 SMESHGUI_AddVolumeDlgLayout->setSpacing( 6 );
64 SMESHGUI_AddVolumeDlgLayout->setMargin( 11 );
66 /***************************************************************/
67 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
69 GroupConstructors->setTitle( tr( "SMESH_TETRAS" ) );
70 else if ( myNodes == 8 )
71 GroupConstructors->setTitle( tr( "SMESH_HEXAS" ) );
73 GroupConstructors->setExclusive( TRUE );
74 GroupConstructors->setColumnLayout(0, Qt::Vertical );
75 GroupConstructors->layout()->setSpacing( 0 );
76 GroupConstructors->layout()->setMargin( 0 );
77 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
78 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
79 GroupConstructorsLayout->setSpacing( 6 );
80 GroupConstructorsLayout->setMargin( 11 );
81 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
82 Constructor1->setText( tr( "" ) );
83 Constructor1->setPixmap( image0 );
84 Constructor1->setChecked( TRUE );
85 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
86 Constructor1->setMinimumSize( QSize( 50, 0 ) );
87 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
88 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
89 GroupConstructorsLayout->addItem( spacer, 0, 1 );
90 SMESHGUI_AddVolumeDlgLayout->addWidget( GroupConstructors, 0, 0 );
92 /***************************************************************/
93 GroupButtons = new QGroupBox( this, "GroupButtons" );
94 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
95 GroupButtons->setTitle( tr( "" ) );
96 GroupButtons->setColumnLayout(0, Qt::Vertical );
97 GroupButtons->layout()->setSpacing( 0 );
98 GroupButtons->layout()->setMargin( 0 );
99 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
100 GroupButtonsLayout->setAlignment( Qt::AlignTop );
101 GroupButtonsLayout->setSpacing( 6 );
102 GroupButtonsLayout->setMargin( 11 );
103 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
104 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
105 buttonCancel->setAutoDefault( TRUE );
106 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
107 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
108 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
109 buttonApply->setAutoDefault( TRUE );
110 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
111 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
112 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
113 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
114 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
115 buttonOk->setAutoDefault( TRUE );
116 buttonOk->setDefault( TRUE );
117 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
118 SMESHGUI_AddVolumeDlgLayout->addWidget( GroupButtons, 2, 0 );
120 /***************************************************************/
121 GroupC1 = new QGroupBox( this, "GroupC1" );
123 GroupC1->setTitle( tr( "SMESH_ADD_TETRAS" ) );
124 else if ( myNodes == 8 )
125 GroupC1->setTitle( tr( "SMESH_ADD_HEXAS" ) );
127 GroupC1->setMinimumSize( QSize( 0, 0 ) );
128 GroupC1->setFrameShape( QGroupBox::Box );
129 GroupC1->setFrameShadow( QGroupBox::Sunken );
130 GroupC1->setColumnLayout(0, Qt::Vertical );
131 GroupC1->layout()->setSpacing( 0 );
132 GroupC1->layout()->setMargin( 0 );
133 GroupC1Layout = new QGridLayout( GroupC1->layout() );
134 GroupC1Layout->setAlignment( Qt::AlignTop );
135 GroupC1Layout->setSpacing( 6 );
136 GroupC1Layout->setMargin( 11 );
137 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
138 TextLabelC1A1->setText( tr( "SMESH_ID_NODES" ) );
139 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
140 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
141 TextLabelC1A1->setFrameShadow( QLabel::Plain );
142 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
143 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
144 SelectButtonC1A1->setText( tr( "" ) );
145 SelectButtonC1A1->setPixmap( image1 );
146 SelectButtonC1A1->setToggleButton( FALSE );
147 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
148 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
149 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
151 SMESHGUI_AddVolumeDlgLayout->addWidget( GroupC1, 1, 0 );
153 Init(Sel) ; /* Initialisations */
156 //=================================================================================
157 // function : ~SMESHGUI_AddVolumeDlg()
158 // purpose : Destroys the object and frees any allocated resources
159 //=================================================================================
160 SMESHGUI_AddVolumeDlg::~SMESHGUI_AddVolumeDlg()
162 // no need to delete child widgets, Qt does it all for us
166 //=================================================================================
169 //=================================================================================
170 void SMESHGUI_AddVolumeDlg::Init( SALOME_Selection* Sel )
174 myConstructorId = 0 ;
175 Constructor1->setChecked( TRUE );
176 myEditCurrentArgument = LineEditC1A1 ;
178 this->myOkNodes = false ;
179 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
180 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
182 /* signals and slots connections */
183 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
184 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
185 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
186 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
188 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
189 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
190 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
191 /* to close dialog if study change */
192 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
194 /* Move widget on the botton right corner of main widget */
196 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
198 this->show() ; /* displays Dialog */
200 SelectionIntoArgument();
206 //=================================================================================
207 // function : ConstructorsClicked()
208 // purpose : Radio button management
209 //=================================================================================
210 void SMESHGUI_AddVolumeDlg::ConstructorsClicked(int constructorId)
216 //=================================================================================
217 // function : ClickOnApply()
219 //=================================================================================
220 void SMESHGUI_AddVolumeDlg::ClickOnApply()
222 switch(myConstructorId)
227 mySMESHGUI->EraseSimulationActors();
228 mySMESHGUI->AddVolume( myMesh, myMapIndex ) ;
229 mySMESHGUI->ViewNodes();
230 mySelection->ClearIObjects();
238 //=================================================================================
239 // function : ClickOnOk()
241 //=================================================================================
242 void SMESHGUI_AddVolumeDlg::ClickOnOk()
244 this->ClickOnApply() ;
245 this->ClickOnCancel() ;
249 //=================================================================================
250 // function : ClickOnCancel()
252 //=================================================================================
253 void SMESHGUI_AddVolumeDlg::ClickOnCancel()
255 QAD_Application::getDesktop()->SetSelectionMode( 4 );
256 disconnect( mySelection, 0, this, 0 );
257 mySMESHGUI->ResetState() ;
258 mySMESHGUI->EraseSimulationActors();
264 //=================================================================================
265 // function : SelectionIntoArgument()
266 // purpose : Called when selection as changed or other case
267 //=================================================================================
268 void SMESHGUI_AddVolumeDlg::SelectionIntoArgument()
270 myEditCurrentArgument->setText("") ;
272 QString aString = "";
274 int nbSel = mySelection->IObjectCount();
278 int nbNodes = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aString) ;
282 if ( mySelection->SelectionMode() != 1 ) {
283 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
284 tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_YES") );
288 myEditCurrentArgument->setText(aString) ;
289 Standard_Boolean res;
290 myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
294 mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
296 if ( myNodes == 4 && nbNodes == 4 ) {
297 mySMESHGUI->DisplaySimulationTetra(myMesh, myMapIndex);
299 } else if ( myNodes == 8 && nbNodes == 8 ) {
300 mySMESHGUI->DisplaySimulationHexa(myMesh, myMapIndex);
303 // mySMESHGUI->EraseSimulationActors();
310 //=================================================================================
311 // function : SetEditCurrentArgument()
313 //=================================================================================
314 void SMESHGUI_AddVolumeDlg::SetEditCurrentArgument()
316 QPushButton* send = (QPushButton*)sender();
317 switch (myConstructorId)
319 case 0: /* default constructor */
321 if(send == SelectButtonC1A1) {
322 LineEditC1A1->setFocus() ;
323 myEditCurrentArgument = LineEditC1A1;
325 SelectionIntoArgument() ;
332 //=================================================================================
333 // function : DeactivateActiveDialog()
335 //=================================================================================
336 void SMESHGUI_AddVolumeDlg::DeactivateActiveDialog()
338 if ( GroupConstructors->isEnabled() ) {
339 GroupConstructors->setEnabled(false) ;
340 GroupC1->setEnabled(false) ;
341 GroupButtons->setEnabled(false) ;
342 mySMESHGUI->EraseSimulationActors() ;
343 mySMESHGUI->ResetState() ;
344 mySMESHGUI->SetActiveDialogBox(0) ;
350 //=================================================================================
351 // function : ActivateThisDialog()
353 //=================================================================================
354 void SMESHGUI_AddVolumeDlg::ActivateThisDialog()
356 /* Emit a signal to deactivate the active dialog */
357 mySMESHGUI->EmitSignalDeactivateDialog() ;
358 GroupConstructors->setEnabled(true) ;
359 GroupC1->setEnabled(true) ;
360 GroupButtons->setEnabled(true) ;
365 //=================================================================================
366 // function : enterEvent()
368 //=================================================================================
369 void SMESHGUI_AddVolumeDlg::enterEvent(QEvent* e)
371 if ( GroupConstructors->isEnabled() )
373 ActivateThisDialog() ;
378 //=================================================================================
379 // function : closeEvent()
381 //=================================================================================
382 void SMESHGUI_AddVolumeDlg::closeEvent( QCloseEvent* e )
384 /* same than click on cancel button */
385 this->ClickOnCancel() ;