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_AddFaceDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "SMESHGUI_AddFaceDlg.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_AddFaceDlg()
57 //=================================================================================
58 SMESHGUI_AddFaceDlg::SMESHGUI_AddFaceDlg( 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_TRIANGLE")));
66 else if ( myNodes == 4 )
67 image0 = QPixmap(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_QUADRANGLE")));
69 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
72 setName( "SMESHGUI_AddFaceDlg" );
75 setCaption( tr( "SMESH_ADD_TRIANGLE_TITLE" ) );
76 else if ( myNodes == 4 )
77 setCaption( tr( "SMESH_ADD_QUADRANGLE_TITLE" ) );
79 setSizeGripEnabled( TRUE );
80 SMESHGUI_AddFaceDlgLayout = new QGridLayout( this );
81 SMESHGUI_AddFaceDlgLayout->setSpacing( 6 );
82 SMESHGUI_AddFaceDlgLayout->setMargin( 11 );
84 /***************************************************************/
85 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
87 GroupConstructors->setTitle( tr( "SMESH_TRIANGLE" ) );
88 else if ( myNodes == 4 )
89 GroupConstructors->setTitle( tr( "SMESH_QUADRANGLE" ) );
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_AddFaceDlgLayout->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_AddFaceDlgLayout->addWidget( GroupButtons, 2, 0 );
138 /***************************************************************/
139 GroupC1 = new QGroupBox( this, "GroupC1" );
141 GroupC1->setTitle( tr( "SMESH_ADD_TRIANGLE" ) );
142 else if ( myNodes == 4 )
143 GroupC1->setTitle( tr( "SMESH_ADD_QUADRANGLE" ) );
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 Reverse = new QCheckBox( GroupC1, "Reverse" );
170 Reverse->setText( tr( "SMESH_REVERSE" ) );
171 GroupC1Layout->addWidget( Reverse, 1, 0 );
173 SMESHGUI_AddFaceDlgLayout->addWidget( GroupC1, 1, 0 );
175 Init(Sel) ; /* Initialisations */
178 //=================================================================================
179 // function : ~SMESHGUI_AddFaceDlg()
180 // purpose : Destroys the object and frees any allocated resources
181 //=================================================================================
182 SMESHGUI_AddFaceDlg::~SMESHGUI_AddFaceDlg()
184 // no need to delete child widgets, Qt does it all for us
188 //=================================================================================
191 //=================================================================================
192 void SMESHGUI_AddFaceDlg::Init( SALOME_Selection* Sel )
196 myConstructorId = 0 ;
197 Constructor1->setChecked( TRUE );
198 myEditCurrentArgument = LineEditC1A1 ;
200 this->myOkNodes = false ;
201 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
202 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
204 /* signals and slots connections */
205 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
206 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
207 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
208 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
210 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
211 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
212 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
213 /* to close dialog if study change */
214 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
216 connect( Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)) );
220 /* Move widget on the botton right corner of main widget */
222 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
224 this->show() ; /* displays Dialog */
226 SelectionIntoArgument();
232 //=================================================================================
233 // function : ConstructorsClicked()
234 // purpose : Radio button management
235 //=================================================================================
236 void SMESHGUI_AddFaceDlg::ConstructorsClicked(int constructorId)
242 //=================================================================================
243 // function : ClickOnApply()
245 //=================================================================================
246 void SMESHGUI_AddFaceDlg::ClickOnApply()
248 switch(myConstructorId)
253 mySMESHGUI->EraseSimulationActors();
254 mySMESHGUI->AddFace( myMesh, myMapIndex, reverse ) ;
255 mySMESHGUI->ViewNodes();
256 mySelection->ClearIObjects();
264 //=================================================================================
265 // function : ClickOnOk()
267 //=================================================================================
268 void SMESHGUI_AddFaceDlg::ClickOnOk()
270 this->ClickOnApply() ;
271 this->ClickOnCancel() ;
275 //=================================================================================
276 // function : ClickOnCancel()
278 //=================================================================================
279 void SMESHGUI_AddFaceDlg::ClickOnCancel()
281 QAD_Application::getDesktop()->SetSelectionMode( 4 );
282 disconnect( mySelection, 0, this, 0 );
283 mySMESHGUI->ResetState() ;
284 mySMESHGUI->EraseSimulationActors();
290 //=================================================================================
291 // function : SelectionIntoArgument()
292 // purpose : Called when selection as changed or other case
293 //=================================================================================
294 void SMESHGUI_AddFaceDlg::SelectionIntoArgument()
296 myEditCurrentArgument->setText("") ;
298 QString aString = "";
300 int nbSel = mySelection->IObjectCount();
304 int nbNodes = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aString) ;
308 if ( mySelection->SelectionMode() != 1 ) {
309 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
310 tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_YES") );
314 myEditCurrentArgument->setText(aString) ;
315 Standard_Boolean res;
316 myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
320 mySelection->GetIndex( mySelection->firstIObject(), myMapIndex );
322 if ( myNodes == 3 && nbNodes == 3 ) {
323 mySMESHGUI->DisplaySimulationTriangle(myMesh, myMapIndex, reverse);
325 } else if ( myNodes == 4 && nbNodes == 4 ) {
326 mySMESHGUI->DisplaySimulationQuadrangle(myMesh, myMapIndex, reverse);
329 // mySMESHGUI->EraseSimulationActors();
336 //=================================================================================
337 // function : SetEditCurrentArgument()
339 //=================================================================================
340 void SMESHGUI_AddFaceDlg::SetEditCurrentArgument()
342 QPushButton* send = (QPushButton*)sender();
343 switch (myConstructorId)
345 case 0: /* default constructor */
347 if(send == SelectButtonC1A1) {
348 LineEditC1A1->setFocus() ;
349 myEditCurrentArgument = LineEditC1A1;
351 SelectionIntoArgument() ;
358 //=================================================================================
359 // function : DeactivateActiveDialog()
361 //=================================================================================
362 void SMESHGUI_AddFaceDlg::DeactivateActiveDialog()
364 if ( GroupConstructors->isEnabled() ) {
365 GroupConstructors->setEnabled(false) ;
366 GroupC1->setEnabled(false) ;
367 GroupButtons->setEnabled(false) ;
368 mySMESHGUI->EraseSimulationActors() ;
369 mySMESHGUI->ResetState() ;
370 mySMESHGUI->SetActiveDialogBox(0) ;
376 //=================================================================================
377 // function : ActivateThisDialog()
379 //=================================================================================
380 void SMESHGUI_AddFaceDlg::ActivateThisDialog()
382 /* Emit a signal to deactivate the active dialog */
383 mySMESHGUI->EmitSignalDeactivateDialog() ;
384 GroupConstructors->setEnabled(true) ;
385 GroupC1->setEnabled(true) ;
386 GroupButtons->setEnabled(true) ;
391 //=================================================================================
392 // function : enterEvent()
394 //=================================================================================
395 void SMESHGUI_AddFaceDlg::enterEvent(QEvent* e)
397 if ( GroupConstructors->isEnabled() )
399 ActivateThisDialog() ;
404 //=================================================================================
405 // function : closeEvent()
407 //=================================================================================
408 void SMESHGUI_AddFaceDlg::closeEvent( QCloseEvent* e )
410 /* same than click on cancel button */
411 this->ClickOnCancel() ;
416 void SMESHGUI_AddFaceDlg::CheckBox( int state )
418 if( Reverse->isOn() ) reverse = true;
419 else reverse = false;
421 if ( myOkNodes == false )
425 mySMESHGUI->EraseSimulationActors();
427 mySMESHGUI->DisplaySimulationTriangle( myMesh, myMapIndex, reverse);
428 else if ( myNodes == 4 ) {
429 mySMESHGUI->DisplaySimulationQuadrangle( myMesh, myMapIndex, reverse);