2 // File : SMESHGUI_AddFaceDlg.cxx
3 // Created : Wed Jun 26 21:00:14 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
12 #include "SMESHGUI_AddFaceDlg.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_AddFaceDlg()
39 //=================================================================================
40 SMESHGUI_AddFaceDlg::SMESHGUI_AddFaceDlg( 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_TRIANGLE")));
48 else if ( myNodes == 4 )
49 image0 = QPixmap(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_QUADRANGLE")));
51 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
54 setName( "SMESHGUI_AddFaceDlg" );
57 setCaption( tr( "SMESH_ADD_TRIANGLE_TITLE" ) );
58 else if ( myNodes == 4 )
59 setCaption( tr( "SMESH_ADD_QUADRANGLE_TITLE" ) );
61 setSizeGripEnabled( TRUE );
62 SMESHGUI_AddFaceDlgLayout = new QGridLayout( this );
63 SMESHGUI_AddFaceDlgLayout->setSpacing( 6 );
64 SMESHGUI_AddFaceDlgLayout->setMargin( 11 );
66 /***************************************************************/
67 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
69 GroupConstructors->setTitle( tr( "SMESH_TRIANGLE" ) );
70 else if ( myNodes == 4 )
71 GroupConstructors->setTitle( tr( "SMESH_QUADRANGLE" ) );
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_AddFaceDlgLayout->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_AddFaceDlgLayout->addWidget( GroupButtons, 2, 0 );
120 /***************************************************************/
121 GroupC1 = new QGroupBox( this, "GroupC1" );
123 GroupC1->setTitle( tr( "SMESH_ADD_TRIANGLE" ) );
124 else if ( myNodes == 4 )
125 GroupC1->setTitle( tr( "SMESH_ADD_QUADRANGLE" ) );
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 Reverse = new QCheckBox( GroupC1, "Reverse" );
152 Reverse->setText( tr( "SMESH_REVERSE" ) );
153 GroupC1Layout->addWidget( Reverse, 1, 0 );
155 SMESHGUI_AddFaceDlgLayout->addWidget( GroupC1, 1, 0 );
157 Init(Sel) ; /* Initialisations */
160 //=================================================================================
161 // function : ~SMESHGUI_AddFaceDlg()
162 // purpose : Destroys the object and frees any allocated resources
163 //=================================================================================
164 SMESHGUI_AddFaceDlg::~SMESHGUI_AddFaceDlg()
166 // no need to delete child widgets, Qt does it all for us
170 //=================================================================================
173 //=================================================================================
174 void SMESHGUI_AddFaceDlg::Init( SALOME_Selection* Sel )
178 myConstructorId = 0 ;
179 Constructor1->setChecked( TRUE );
180 myEditCurrentArgument = LineEditC1A1 ;
182 this->myOkNodes = false ;
183 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
184 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
186 /* signals and slots connections */
187 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
188 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
189 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
190 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
192 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
193 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
194 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
195 /* to close dialog if study change */
196 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
198 connect( Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)) );
202 /* Move widget on the botton right corner of main widget */
204 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
206 this->show() ; /* displays Dialog */
208 SelectionIntoArgument();
214 //=================================================================================
215 // function : ConstructorsClicked()
216 // purpose : Radio button management
217 //=================================================================================
218 void SMESHGUI_AddFaceDlg::ConstructorsClicked(int constructorId)
224 //=================================================================================
225 // function : ClickOnApply()
227 //=================================================================================
228 void SMESHGUI_AddFaceDlg::ClickOnApply()
230 switch(myConstructorId)
235 mySMESHGUI->EraseSimulationActors();
236 mySMESHGUI->AddFace( myMesh, myMapIndex, reverse ) ;
237 mySMESHGUI->ViewNodes();
238 mySelection->ClearIObjects();
246 //=================================================================================
247 // function : ClickOnOk()
249 //=================================================================================
250 void SMESHGUI_AddFaceDlg::ClickOnOk()
252 this->ClickOnApply() ;
253 this->ClickOnCancel() ;
257 //=================================================================================
258 // function : ClickOnCancel()
260 //=================================================================================
261 void SMESHGUI_AddFaceDlg::ClickOnCancel()
263 QAD_Application::getDesktop()->SetSelectionMode( 4 );
264 disconnect( mySelection, 0, this, 0 );
265 mySMESHGUI->ResetState() ;
266 mySMESHGUI->EraseSimulationActors();
272 //=================================================================================
273 // function : SelectionIntoArgument()
274 // purpose : Called when selection as changed or other case
275 //=================================================================================
276 void SMESHGUI_AddFaceDlg::SelectionIntoArgument()
278 myEditCurrentArgument->setText("") ;
280 QString aString = "";
282 int nbSel = mySelection->IObjectCount();
286 int nbNodes = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aString) ;
290 if ( mySelection->SelectionMode() != 1 ) {
291 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
292 tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_YES") );
296 myEditCurrentArgument->setText(aString) ;
297 Standard_Boolean res;
298 myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
302 mySelection->GetIndex( mySelection->firstIObject(), myMapIndex );
304 if ( myNodes == 3 && nbNodes == 3 ) {
305 mySMESHGUI->DisplaySimulationTriangle(myMesh, myMapIndex, reverse);
307 } else if ( myNodes == 4 && nbNodes == 4 ) {
308 mySMESHGUI->DisplaySimulationQuadrangle(myMesh, myMapIndex, reverse);
311 // mySMESHGUI->EraseSimulationActors();
318 //=================================================================================
319 // function : SetEditCurrentArgument()
321 //=================================================================================
322 void SMESHGUI_AddFaceDlg::SetEditCurrentArgument()
324 QPushButton* send = (QPushButton*)sender();
325 switch (myConstructorId)
327 case 0: /* default constructor */
329 if(send == SelectButtonC1A1) {
330 LineEditC1A1->setFocus() ;
331 myEditCurrentArgument = LineEditC1A1;
333 SelectionIntoArgument() ;
340 //=================================================================================
341 // function : DeactivateActiveDialog()
343 //=================================================================================
344 void SMESHGUI_AddFaceDlg::DeactivateActiveDialog()
346 if ( GroupConstructors->isEnabled() ) {
347 GroupConstructors->setEnabled(false) ;
348 GroupC1->setEnabled(false) ;
349 GroupButtons->setEnabled(false) ;
350 mySMESHGUI->EraseSimulationActors() ;
351 mySMESHGUI->ResetState() ;
352 mySMESHGUI->SetActiveDialogBox(0) ;
358 //=================================================================================
359 // function : ActivateThisDialog()
361 //=================================================================================
362 void SMESHGUI_AddFaceDlg::ActivateThisDialog()
364 /* Emit a signal to deactivate the active dialog */
365 mySMESHGUI->EmitSignalDeactivateDialog() ;
366 GroupConstructors->setEnabled(true) ;
367 GroupC1->setEnabled(true) ;
368 GroupButtons->setEnabled(true) ;
373 //=================================================================================
374 // function : enterEvent()
376 //=================================================================================
377 void SMESHGUI_AddFaceDlg::enterEvent(QEvent* e)
379 if ( GroupConstructors->isEnabled() )
381 ActivateThisDialog() ;
386 //=================================================================================
387 // function : closeEvent()
389 //=================================================================================
390 void SMESHGUI_AddFaceDlg::closeEvent( QCloseEvent* e )
392 /* same than click on cancel button */
393 this->ClickOnCancel() ;
398 void SMESHGUI_AddFaceDlg::CheckBox( int state )
400 if( Reverse->isOn() ) reverse = true;
401 else reverse = false;
403 if ( myOkNodes == false )
407 mySMESHGUI->EraseSimulationActors();
409 mySMESHGUI->DisplaySimulationTriangle( myMesh, myMapIndex, reverse);
410 else if ( myNodes == 4 ) {
411 mySMESHGUI->DisplaySimulationQuadrangle( myMesh, myMapIndex, reverse);