2 // File : SMESHGUI_OrientationElementsDlg.cxx
3 // Created : Tue Jun 25 14:28:17 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
12 #include "SMESHGUI_OrientationElementsDlg.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>
35 //=================================================================================
36 // class : SMESHGUI_OrientationElementsDlg()
38 //=================================================================================
39 SMESHGUI_OrientationElementsDlg::SMESHGUI_OrientationElementsDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
40 bool modal, WFlags fl )
41 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
43 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_MESH_ORIENTATION")));
44 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
47 setName( "SMESHGUI_OrientationElementsDlg" );
49 setCaption( tr( "SMESH_ORIENTATION_ELEMENTS_TITLE" ) );
50 setSizeGripEnabled( TRUE );
51 SMESHGUI_OrientationElementsDlgLayout = new QGridLayout( this );
52 SMESHGUI_OrientationElementsDlgLayout->setSpacing( 6 );
53 SMESHGUI_OrientationElementsDlgLayout->setMargin( 11 );
55 /***************************************************************/
56 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
57 GroupConstructors->setTitle( tr( "SMESH_ELEMENTS" ) );
58 GroupConstructors->setExclusive( TRUE );
59 GroupConstructors->setColumnLayout(0, Qt::Vertical );
60 GroupConstructors->layout()->setSpacing( 0 );
61 GroupConstructors->layout()->setMargin( 0 );
62 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
63 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
64 GroupConstructorsLayout->setSpacing( 6 );
65 GroupConstructorsLayout->setMargin( 11 );
66 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
67 Constructor1->setText( tr( "" ) );
68 Constructor1->setPixmap( image0 );
69 Constructor1->setChecked( TRUE );
70 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
71 Constructor1->setMinimumSize( QSize( 50, 0 ) );
72 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
73 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
74 GroupConstructorsLayout->addItem( spacer, 0, 1 );
75 SMESHGUI_OrientationElementsDlgLayout->addWidget( GroupConstructors, 0, 0 );
77 /***************************************************************/
78 GroupButtons = new QGroupBox( this, "GroupButtons" );
79 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
80 GroupButtons->setTitle( tr( "" ) );
81 GroupButtons->setColumnLayout(0, Qt::Vertical );
82 GroupButtons->layout()->setSpacing( 0 );
83 GroupButtons->layout()->setMargin( 0 );
84 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
85 GroupButtonsLayout->setAlignment( Qt::AlignTop );
86 GroupButtonsLayout->setSpacing( 6 );
87 GroupButtonsLayout->setMargin( 11 );
88 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
89 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
90 buttonCancel->setAutoDefault( TRUE );
91 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
92 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
93 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
94 buttonApply->setAutoDefault( TRUE );
95 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
96 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
97 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
98 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
99 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
100 buttonOk->setAutoDefault( TRUE );
101 buttonOk->setDefault( TRUE );
102 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
103 SMESHGUI_OrientationElementsDlgLayout->addWidget( GroupButtons, 2, 0 );
105 /***************************************************************/
106 GroupC1 = new QGroupBox( this, "GroupC1" );
107 GroupC1->setTitle( tr( "SMESH_ORIENTATION" ) );
108 GroupC1->setMinimumSize( QSize( 0, 0 ) );
109 GroupC1->setFrameShape( QGroupBox::Box );
110 GroupC1->setFrameShadow( QGroupBox::Sunken );
111 GroupC1->setColumnLayout(0, Qt::Vertical );
112 GroupC1->layout()->setSpacing( 0 );
113 GroupC1->layout()->setMargin( 0 );
114 GroupC1Layout = new QGridLayout( GroupC1->layout() );
115 GroupC1Layout->setAlignment( Qt::AlignTop );
116 GroupC1Layout->setSpacing( 6 );
117 GroupC1Layout->setMargin( 11 );
118 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
119 TextLabelC1A1->setText( tr( "SMESH_ID_ELEMENTS" ) );
120 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
121 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
122 TextLabelC1A1->setFrameShadow( QLabel::Plain );
123 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
124 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
125 SelectButtonC1A1->setText( tr( "" ) );
126 SelectButtonC1A1->setPixmap( image1 );
127 SelectButtonC1A1->setToggleButton( FALSE );
128 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
129 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
130 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
131 SMESHGUI_OrientationElementsDlgLayout->addWidget( GroupC1, 1, 0 );
133 Init(Sel) ; /* Initialisations */
136 //=================================================================================
137 // function : ~SMESHGUI_OrientationElementsDlg()
138 // purpose : Destroys the object and frees any allocated resources
139 //=================================================================================
140 SMESHGUI_OrientationElementsDlg::~SMESHGUI_OrientationElementsDlg()
142 // no need to delete child widgets, Qt does it all for us
146 //=================================================================================
149 //=================================================================================
150 void SMESHGUI_OrientationElementsDlg::Init( SALOME_Selection* Sel )
154 myConstructorId = 0 ;
155 Constructor1->setChecked( TRUE );
156 myEditCurrentArgument = LineEditC1A1 ;
158 this->myOkElements = false ;
159 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
160 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
162 /* signals and slots connections */
163 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
164 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
165 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
166 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
168 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
169 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
170 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
171 /* to close dialog if study change */
172 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
174 /* Move widget on the botton right corner of main widget */
176 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
178 this->show() ; /* displays Dialog */
180 SelectionIntoArgument();
186 //=================================================================================
187 // function : ConstructorsClicked()
188 // purpose : Radio button management
189 //=================================================================================
190 void SMESHGUI_OrientationElementsDlg::ConstructorsClicked(int constructorId)
196 //=================================================================================
197 // function : ClickOnApply()
199 //=================================================================================
200 void SMESHGUI_OrientationElementsDlg::ClickOnApply()
202 switch(myConstructorId)
207 mySMESHGUI->OrientationElements( myMesh, myMapIndex ) ;
208 mySelection->ClearIObjects();
216 //=================================================================================
217 // function : ClickOnOk()
219 //=================================================================================
220 void SMESHGUI_OrientationElementsDlg::ClickOnOk()
222 this->ClickOnApply() ;
223 this->ClickOnCancel() ;
228 //=================================================================================
229 // function : ClickOnCancel()
231 //=================================================================================
232 void SMESHGUI_OrientationElementsDlg::ClickOnCancel()
234 QAD_Application::getDesktop()->SetSelectionMode( 4 );
235 disconnect( mySelection, 0, this, 0 );
236 mySMESHGUI->ResetState() ;
242 //=================================================================================
243 // function : SelectionIntoArgument()
244 // purpose : Called when selection as changed or other case
245 //=================================================================================
246 void SMESHGUI_OrientationElementsDlg::SelectionIntoArgument()
248 myEditCurrentArgument->setText("") ;
249 myOkElements = false;
250 QString aString = "";
252 int nbSel = mySelection->IObjectCount();
256 int nbElements = mySMESHGUI->GetNameOfSelectedElements(mySelection, aString) ;
260 if ( mySelection->SelectionMode() != 3 ) {
261 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
262 tr ("SMESH_WRN_SELECTIONMODE_ELEMENTS"), tr ("SMESH_BUT_YES") );
266 myEditCurrentArgument->setText(aString) ;
267 Standard_Boolean res;
268 myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
272 mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
273 myOkElements = true ;
278 //=================================================================================
279 // function : SetEditCurrentArgument()
281 //=================================================================================
282 void SMESHGUI_OrientationElementsDlg::SetEditCurrentArgument()
284 QPushButton* send = (QPushButton*)sender();
285 switch (myConstructorId)
287 case 0: /* default constructor */
289 if(send == SelectButtonC1A1) {
290 LineEditC1A1->setFocus() ;
291 myEditCurrentArgument = LineEditC1A1;
293 SelectionIntoArgument() ;
300 //=================================================================================
301 // function : DeactivateActiveDialog()
303 //=================================================================================
304 void SMESHGUI_OrientationElementsDlg::DeactivateActiveDialog()
306 if ( GroupConstructors->isEnabled() ) {
307 GroupConstructors->setEnabled(false) ;
308 GroupC1->setEnabled(false) ;
309 GroupButtons->setEnabled(false) ;
315 //=================================================================================
316 // function : ActivateThisDialog()
318 //=================================================================================
319 void SMESHGUI_OrientationElementsDlg::ActivateThisDialog()
321 /* Emit a signal to deactivate the active dialog */
322 mySMESHGUI->EmitSignalDeactivateDialog() ;
323 GroupConstructors->setEnabled(true) ;
324 GroupC1->setEnabled(true) ;
325 GroupButtons->setEnabled(true) ;
330 //=================================================================================
331 // function : enterEvent()
333 //=================================================================================
334 void SMESHGUI_OrientationElementsDlg::enterEvent(QEvent* e)
336 if ( GroupConstructors->isEnabled() )
338 ActivateThisDialog() ;
343 //=================================================================================
344 // function : closeEvent()
346 //=================================================================================
347 void SMESHGUI_OrientationElementsDlg::closeEvent( QCloseEvent* e )
349 /* same than click on cancel button */
350 this->ClickOnCancel() ;