2 // File : SMESHGUI_AddEdgeDlg.cxx
3 // Created : Wed Jun 26 21:00:14 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
12 #include "SMESHGUI_AddEdgeDlg.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_AddEdgeDlg()
39 //=================================================================================
40 SMESHGUI_AddEdgeDlg::SMESHGUI_AddEdgeDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
41 bool modal, WFlags fl )
42 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
45 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESHGUI",tr("ICON_DLG_LINE")));
46 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESHGUI",tr("ICON_SELECT")));
49 setName( "SMESHGUI_AddEdgeDlg" );
51 setCaption( tr( "SMESH_ADD_EDGE_TITLE" ) );
52 setSizeGripEnabled( TRUE );
53 SMESHGUI_AddEdgeDlgLayout = new QGridLayout( this );
54 SMESHGUI_AddEdgeDlgLayout->setSpacing( 6 );
55 SMESHGUI_AddEdgeDlgLayout->setMargin( 11 );
57 /***************************************************************/
58 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
59 GroupConstructors->setTitle( tr( "SMESH_EDGE" ) );
61 GroupConstructors->setExclusive( TRUE );
62 GroupConstructors->setColumnLayout(0, Qt::Vertical );
63 GroupConstructors->layout()->setSpacing( 0 );
64 GroupConstructors->layout()->setMargin( 0 );
65 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
66 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
67 GroupConstructorsLayout->setSpacing( 6 );
68 GroupConstructorsLayout->setMargin( 11 );
69 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
70 Constructor1->setText( tr( "" ) );
71 Constructor1->setPixmap( image0 );
72 Constructor1->setChecked( TRUE );
73 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
74 Constructor1->setMinimumSize( QSize( 50, 0 ) );
75 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
76 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
77 GroupConstructorsLayout->addItem( spacer, 0, 1 );
78 SMESHGUI_AddEdgeDlgLayout->addWidget( GroupConstructors, 0, 0 );
80 /***************************************************************/
81 GroupButtons = new QGroupBox( this, "GroupButtons" );
82 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
83 GroupButtons->setTitle( tr( "" ) );
84 GroupButtons->setColumnLayout(0, Qt::Vertical );
85 GroupButtons->layout()->setSpacing( 0 );
86 GroupButtons->layout()->setMargin( 0 );
87 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
88 GroupButtonsLayout->setAlignment( Qt::AlignTop );
89 GroupButtonsLayout->setSpacing( 6 );
90 GroupButtonsLayout->setMargin( 11 );
91 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
92 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
93 buttonCancel->setAutoDefault( TRUE );
94 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
95 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
96 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
97 buttonApply->setAutoDefault( TRUE );
98 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
99 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
100 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
101 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
102 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
103 buttonOk->setAutoDefault( TRUE );
104 buttonOk->setDefault( TRUE );
105 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
106 SMESHGUI_AddEdgeDlgLayout->addWidget( GroupButtons, 2, 0 );
108 /***************************************************************/
109 GroupC1 = new QGroupBox( this, "GroupC1" );
110 GroupC1->setTitle( tr( "SMESH_ADD_EDGE" ) );
112 GroupC1->setMinimumSize( QSize( 0, 0 ) );
113 GroupC1->setFrameShape( QGroupBox::Box );
114 GroupC1->setFrameShadow( QGroupBox::Sunken );
115 GroupC1->setColumnLayout(0, Qt::Vertical );
116 GroupC1->layout()->setSpacing( 0 );
117 GroupC1->layout()->setMargin( 0 );
118 GroupC1Layout = new QGridLayout( GroupC1->layout() );
119 GroupC1Layout->setAlignment( Qt::AlignTop );
120 GroupC1Layout->setSpacing( 6 );
121 GroupC1Layout->setMargin( 11 );
122 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
123 TextLabelC1A1->setText( tr( "SMESH_ID_NODES" ) );
124 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
125 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
126 TextLabelC1A1->setFrameShadow( QLabel::Plain );
127 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
128 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
129 SelectButtonC1A1->setText( tr( "" ) );
130 SelectButtonC1A1->setPixmap( image1 );
131 SelectButtonC1A1->setToggleButton( FALSE );
132 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
133 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
134 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
136 SMESHGUI_AddEdgeDlgLayout->addWidget( GroupC1, 1, 0 );
138 Init(Sel) ; /* Initialisations */
141 //=================================================================================
142 // function : ~SMESHGUI_AddEdgeDlg()
143 // purpose : Destroys the object and frees any allocated resources
144 //=================================================================================
145 SMESHGUI_AddEdgeDlg::~SMESHGUI_AddEdgeDlg()
147 // no need to delete child widgets, Qt does it all for us
151 //=================================================================================
154 //=================================================================================
155 void SMESHGUI_AddEdgeDlg::Init( SALOME_Selection* Sel )
159 myConstructorId = 0 ;
160 Constructor1->setChecked( TRUE );
161 myEditCurrentArgument = LineEditC1A1 ;
163 this->myOkNodes = false ;
164 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
165 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
167 /* signals and slots connections */
168 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
169 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
170 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
171 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
173 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
174 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
175 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
176 /* to close dialog if study change */
177 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
179 /* Move widget on the botton right corner of main widget */
181 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
183 this->show() ; /* displays Dialog */
185 SelectionIntoArgument();
191 //=================================================================================
192 // function : ConstructorsClicked()
193 // purpose : Radio button management
194 //=================================================================================
195 void SMESHGUI_AddEdgeDlg::ConstructorsClicked(int constructorId)
201 //=================================================================================
202 // function : ClickOnApply()
204 //=================================================================================
205 void SMESHGUI_AddEdgeDlg::ClickOnApply()
207 switch(myConstructorId)
212 mySMESHGUI->EraseSimulationActors();
213 mySMESHGUI->AddEdge( myMesh, myMapIndex ) ;
214 mySMESHGUI->ViewNodes();
215 mySelection->ClearIObjects();
223 //=================================================================================
224 // function : ClickOnOk()
226 //=================================================================================
227 void SMESHGUI_AddEdgeDlg::ClickOnOk()
229 this->ClickOnApply() ;
230 this->ClickOnCancel() ;
234 //=================================================================================
235 // function : ClickOnCancel()
237 //=================================================================================
238 void SMESHGUI_AddEdgeDlg::ClickOnCancel()
240 QAD_Application::getDesktop()->SetSelectionMode( 4 );
241 disconnect( mySelection, 0, this, 0 );
242 mySMESHGUI->ResetState() ;
243 mySMESHGUI->EraseSimulationActors();
249 //=================================================================================
250 // function : SelectionIntoArgument()
251 // purpose : Called when selection as changed or other case
252 //=================================================================================
253 void SMESHGUI_AddEdgeDlg::SelectionIntoArgument()
255 myEditCurrentArgument->setText("") ;
257 QString aString = "";
259 int nbSel = mySelection->IObjectCount();
263 int nbNodes = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aString) ;
267 if ( mySelection->SelectionMode() != 1 ) {
268 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
269 tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_YES") );
273 myEditCurrentArgument->setText(aString) ;
274 Standard_Boolean res;
275 myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
279 mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
281 if ( myNodes == 2 && nbNodes == 2 ) {
282 mySMESHGUI->DisplaySimulationEdge(myMesh, myMapIndex);
285 // mySMESHGUI->EraseSimulationActors();
292 //=================================================================================
293 // function : SetEditCurrentArgument()
295 //=================================================================================
296 void SMESHGUI_AddEdgeDlg::SetEditCurrentArgument()
298 QPushButton* send = (QPushButton*)sender();
299 switch (myConstructorId)
301 case 0: /* default constructor */
303 if(send == SelectButtonC1A1) {
304 LineEditC1A1->setFocus() ;
305 myEditCurrentArgument = LineEditC1A1;
307 SelectionIntoArgument() ;
314 //=================================================================================
315 // function : DeactivateActiveDialog()
317 //=================================================================================
318 void SMESHGUI_AddEdgeDlg::DeactivateActiveDialog()
320 if ( GroupConstructors->isEnabled() ) {
321 GroupConstructors->setEnabled(false) ;
322 GroupC1->setEnabled(false) ;
323 GroupButtons->setEnabled(false) ;
324 mySMESHGUI->EraseSimulationActors() ;
325 mySMESHGUI->ResetState() ;
326 mySMESHGUI->SetActiveDialogBox(0) ;
332 //=================================================================================
333 // function : ActivateThisDialog()
335 //=================================================================================
336 void SMESHGUI_AddEdgeDlg::ActivateThisDialog()
338 /* Emit a signal to deactivate the active dialog */
339 mySMESHGUI->EmitSignalDeactivateDialog() ;
340 GroupConstructors->setEnabled(true) ;
341 GroupC1->setEnabled(true) ;
342 GroupButtons->setEnabled(true) ;
347 //=================================================================================
348 // function : enterEvent()
350 //=================================================================================
351 void SMESHGUI_AddEdgeDlg::enterEvent(QEvent* e)
353 if ( GroupConstructors->isEnabled() )
355 ActivateThisDialog() ;
360 //=================================================================================
361 // function : closeEvent()
363 //=================================================================================
364 void SMESHGUI_AddEdgeDlg::closeEvent( QCloseEvent* e )
366 /* same than click on cancel button */
367 this->ClickOnCancel() ;