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_AddEdgeDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "SMESHGUI_AddEdgeDlg.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_AddEdgeDlg()
57 //=================================================================================
58 SMESHGUI_AddEdgeDlg::SMESHGUI_AddEdgeDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
59 bool modal, WFlags fl )
60 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
63 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_LINE")));
64 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
67 setName( "SMESHGUI_AddEdgeDlg" );
69 setCaption( tr( "SMESH_ADD_EDGE_TITLE" ) );
70 setSizeGripEnabled( TRUE );
71 SMESHGUI_AddEdgeDlgLayout = new QGridLayout( this );
72 SMESHGUI_AddEdgeDlgLayout->setSpacing( 6 );
73 SMESHGUI_AddEdgeDlgLayout->setMargin( 11 );
75 /***************************************************************/
76 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
77 GroupConstructors->setTitle( tr( "SMESH_EDGE" ) );
79 GroupConstructors->setExclusive( TRUE );
80 GroupConstructors->setColumnLayout(0, Qt::Vertical );
81 GroupConstructors->layout()->setSpacing( 0 );
82 GroupConstructors->layout()->setMargin( 0 );
83 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
84 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
85 GroupConstructorsLayout->setSpacing( 6 );
86 GroupConstructorsLayout->setMargin( 11 );
87 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
88 Constructor1->setText( tr( "" ) );
89 Constructor1->setPixmap( image0 );
90 Constructor1->setChecked( TRUE );
91 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
92 Constructor1->setMinimumSize( QSize( 50, 0 ) );
93 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
94 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
95 GroupConstructorsLayout->addItem( spacer, 0, 1 );
96 SMESHGUI_AddEdgeDlgLayout->addWidget( GroupConstructors, 0, 0 );
98 /***************************************************************/
99 GroupButtons = new QGroupBox( this, "GroupButtons" );
100 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
101 GroupButtons->setTitle( tr( "" ) );
102 GroupButtons->setColumnLayout(0, Qt::Vertical );
103 GroupButtons->layout()->setSpacing( 0 );
104 GroupButtons->layout()->setMargin( 0 );
105 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
106 GroupButtonsLayout->setAlignment( Qt::AlignTop );
107 GroupButtonsLayout->setSpacing( 6 );
108 GroupButtonsLayout->setMargin( 11 );
109 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
110 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
111 buttonCancel->setAutoDefault( TRUE );
112 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
113 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
114 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
115 buttonApply->setAutoDefault( TRUE );
116 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
117 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
118 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
119 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
120 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
121 buttonOk->setAutoDefault( TRUE );
122 buttonOk->setDefault( TRUE );
123 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
124 SMESHGUI_AddEdgeDlgLayout->addWidget( GroupButtons, 2, 0 );
126 /***************************************************************/
127 GroupC1 = new QGroupBox( this, "GroupC1" );
128 GroupC1->setTitle( tr( "SMESH_ADD_EDGE" ) );
130 GroupC1->setMinimumSize( QSize( 0, 0 ) );
131 GroupC1->setFrameShape( QGroupBox::Box );
132 GroupC1->setFrameShadow( QGroupBox::Sunken );
133 GroupC1->setColumnLayout(0, Qt::Vertical );
134 GroupC1->layout()->setSpacing( 0 );
135 GroupC1->layout()->setMargin( 0 );
136 GroupC1Layout = new QGridLayout( GroupC1->layout() );
137 GroupC1Layout->setAlignment( Qt::AlignTop );
138 GroupC1Layout->setSpacing( 6 );
139 GroupC1Layout->setMargin( 11 );
140 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
141 TextLabelC1A1->setText( tr( "SMESH_ID_NODES" ) );
142 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
143 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
144 TextLabelC1A1->setFrameShadow( QLabel::Plain );
145 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
146 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
147 SelectButtonC1A1->setText( tr( "" ) );
148 SelectButtonC1A1->setPixmap( image1 );
149 SelectButtonC1A1->setToggleButton( FALSE );
150 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
151 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
152 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
154 SMESHGUI_AddEdgeDlgLayout->addWidget( GroupC1, 1, 0 );
156 Init(Sel) ; /* Initialisations */
159 //=================================================================================
160 // function : ~SMESHGUI_AddEdgeDlg()
161 // purpose : Destroys the object and frees any allocated resources
162 //=================================================================================
163 SMESHGUI_AddEdgeDlg::~SMESHGUI_AddEdgeDlg()
165 // no need to delete child widgets, Qt does it all for us
169 //=================================================================================
172 //=================================================================================
173 void SMESHGUI_AddEdgeDlg::Init( SALOME_Selection* Sel )
177 myConstructorId = 0 ;
178 Constructor1->setChecked( TRUE );
179 myEditCurrentArgument = LineEditC1A1 ;
181 this->myOkNodes = false ;
182 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
183 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
185 /* signals and slots connections */
186 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
187 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
188 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
189 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
191 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
192 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
193 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
194 /* to close dialog if study change */
195 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
197 /* Move widget on the botton right corner of main widget */
199 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
201 this->show() ; /* displays Dialog */
203 SelectionIntoArgument();
209 //=================================================================================
210 // function : ConstructorsClicked()
211 // purpose : Radio button management
212 //=================================================================================
213 void SMESHGUI_AddEdgeDlg::ConstructorsClicked(int constructorId)
219 //=================================================================================
220 // function : ClickOnApply()
222 //=================================================================================
223 void SMESHGUI_AddEdgeDlg::ClickOnApply()
225 switch(myConstructorId)
230 mySMESHGUI->EraseSimulationActors();
231 mySMESHGUI->AddEdge( myMesh, myMapIndex ) ;
232 mySMESHGUI->ViewNodes();
233 mySelection->ClearIObjects();
241 //=================================================================================
242 // function : ClickOnOk()
244 //=================================================================================
245 void SMESHGUI_AddEdgeDlg::ClickOnOk()
247 this->ClickOnApply() ;
248 this->ClickOnCancel() ;
252 //=================================================================================
253 // function : ClickOnCancel()
255 //=================================================================================
256 void SMESHGUI_AddEdgeDlg::ClickOnCancel()
258 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
259 disconnect( mySelection, 0, this, 0 );
260 mySMESHGUI->ResetState() ;
261 mySMESHGUI->EraseSimulationActors();
267 //=================================================================================
268 // function : SelectionIntoArgument()
269 // purpose : Called when selection as changed or other case
270 //=================================================================================
271 void SMESHGUI_AddEdgeDlg::SelectionIntoArgument()
273 myEditCurrentArgument->setText("") ;
275 QString aString = "";
277 int nbSel = mySelection->IObjectCount();
281 int nbNodes = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aString) ;
285 if ( mySelection->SelectionMode() != NodeSelection ) {
286 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
287 tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_OK") );
291 myEditCurrentArgument->setText(aString) ;
292 Standard_Boolean res;
293 myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
297 mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
299 if ( myNodes == 2 && nbNodes == 2 ) {
300 mySMESHGUI->DisplaySimulationEdge(myMesh, myMapIndex);
303 // mySMESHGUI->EraseSimulationActors();
310 //=================================================================================
311 // function : SetEditCurrentArgument()
313 //=================================================================================
314 void SMESHGUI_AddEdgeDlg::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_AddEdgeDlg::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_AddEdgeDlg::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_AddEdgeDlg::enterEvent(QEvent* e)
371 if ( GroupConstructors->isEnabled() )
373 ActivateThisDialog() ;
378 //=================================================================================
379 // function : closeEvent()
381 //=================================================================================
382 void SMESHGUI_AddEdgeDlg::closeEvent( QCloseEvent* e )
384 /* same than click on cancel button */
385 this->ClickOnCancel() ;