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_EdgesConnectivityDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "SMESHGUI_EdgesConnectivityDlg.h"
32 #include "SMESHGUI_SpinBox.h"
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "QAD_MessageBox.h"
37 #include "utilities.h"
40 #include <qbuttongroup.h>
41 #include <qgroupbox.h>
43 #include <qlineedit.h>
44 #include <qpushbutton.h>
45 #include <qradiobutton.h>
49 #include <qwhatsthis.h>
52 #include <qcheckbox.h>
55 #include <vtkFeatureEdges.h>
57 //=================================================================================
58 // class : SMESHGUI_EdgesConnectivityDlg()
60 //=================================================================================
61 SMESHGUI_EdgesConnectivityDlg::SMESHGUI_EdgesConnectivityDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
62 bool modal, WFlags fl )
63 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
65 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_CONNECTIVITY")));
66 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
69 setName( "SMESHGUI_EdgesConnectivityDlg" );
71 setCaption( tr( "SMESH_EDGES_CONNECTIVITY_TITLE" ) );
72 setSizeGripEnabled( TRUE );
73 SMESHGUI_EdgesConnectivityDlgLayout = new QGridLayout( this );
74 SMESHGUI_EdgesConnectivityDlgLayout->setSpacing( 6 );
75 SMESHGUI_EdgesConnectivityDlgLayout->setMargin( 11 );
77 /***************************************************************/
78 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
79 GroupConstructors->setTitle( tr( "SMESH_EDGES_CONNECTIVITY" ) );
80 GroupConstructors->setExclusive( TRUE );
81 GroupConstructors->setColumnLayout(0, Qt::Vertical );
82 GroupConstructors->layout()->setSpacing( 0 );
83 GroupConstructors->layout()->setMargin( 0 );
84 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
85 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
86 GroupConstructorsLayout->setSpacing( 6 );
87 GroupConstructorsLayout->setMargin( 11 );
88 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
89 Constructor1->setText( tr( "" ) );
90 Constructor1->setPixmap( image0 );
91 Constructor1->setChecked( TRUE );
92 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
93 Constructor1->setMinimumSize( QSize( 50, 0 ) );
94 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
95 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
96 GroupConstructorsLayout->addItem( spacer, 0, 1 );
97 SMESHGUI_EdgesConnectivityDlgLayout->addWidget( GroupConstructors, 0, 0 );
99 /***************************************************************/
100 GroupButtons = new QGroupBox( this, "GroupButtons" );
101 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
102 GroupButtons->setTitle( tr( "" ) );
103 GroupButtons->setColumnLayout(0, Qt::Vertical );
104 GroupButtons->layout()->setSpacing( 0 );
105 GroupButtons->layout()->setMargin( 0 );
106 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
107 GroupButtonsLayout->setAlignment( Qt::AlignTop );
108 GroupButtonsLayout->setSpacing( 6 );
109 GroupButtonsLayout->setMargin( 11 );
110 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
111 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
112 buttonCancel->setAutoDefault( TRUE );
113 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
114 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
115 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
116 buttonApply->setAutoDefault( TRUE );
117 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
118 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
119 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
120 //buttonOk = new QPushButton( GroupButtons, "buttonOk" );
121 //buttonOk->setText( tr( "SMESH_BUT_OK" ) );
122 //buttonOk->setAutoDefault( TRUE );
123 //buttonOk->setDefault( TRUE );
124 //GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
125 SMESHGUI_EdgesConnectivityDlgLayout->addWidget( GroupButtons, 2, 0 );
127 /***************************************************************/
128 GroupC1 = new QGroupBox( this, "GroupC1" );
129 GroupC1->setTitle( tr( "SMESH_EDGES_CONNECTIVITY" ) );
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_MESH" ) );
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 BoundaryEdges = new QCheckBox( GroupC1, "BoundaryEdges" );
155 BoundaryEdges->setText( tr( "SMESH_BOUNDARYEDGES" ) );
156 GroupC1Layout->addWidget( BoundaryEdges, 1, 0 );
158 ManifoldEdges = new QCheckBox( GroupC1, "ManifoldEdges" );
159 ManifoldEdges->setText( tr( "SMESH_MANIFOLDEDGES" ) );
160 GroupC1Layout->addWidget( ManifoldEdges, 2, 0 );
162 NonManifoldEdges = new QCheckBox( GroupC1, "NonManifoldEdges" );
163 NonManifoldEdges->setText( tr( "SMESH_NONMANIFOLDEDGES" ) );
164 GroupC1Layout->addWidget( NonManifoldEdges, 1, 2 );
166 FeatureEdges = new QCheckBox( GroupC1, "FeatureEdges" );
167 FeatureEdges->setText( tr( "SMESH_FEATUREEDGES" ) );
168 GroupC1Layout->addWidget( FeatureEdges, 2, 2 );
170 FeatureAngle= new QLabel( GroupC1, "FeatureAngle" );
171 FeatureAngle->setText( tr( "SMESH_FEATUREANGLE" ) );
172 FeatureAngle->setMinimumSize( QSize( 50, 0 ) );
173 FeatureAngle->setFrameShape( QLabel::NoFrame );
174 FeatureAngle->setFrameShadow( QLabel::Plain );
175 GroupC1Layout->addWidget( FeatureAngle, 3, 0 );
177 SpinBox_FeatureAngle = new SMESHGUI_SpinBox( GroupC1, "SpinBox_FeatureAngle" ) ;
178 GroupC1Layout->addWidget( SpinBox_FeatureAngle , 3, 2 );
180 SMESHGUI_EdgesConnectivityDlgLayout->addWidget( GroupC1, 1, 0 );
182 Init(Sel) ; /* Initialisations */
185 //=================================================================================
186 // function : ~SMESHGUI_EdgesConnectivityDlg()
187 // purpose : Destroys the object and frees any allocated resources
188 //=================================================================================
189 SMESHGUI_EdgesConnectivityDlg::~SMESHGUI_EdgesConnectivityDlg()
191 // no need to delete child widgets, Qt does it all for us
195 //=================================================================================
198 //=================================================================================
199 void SMESHGUI_EdgesConnectivityDlg::Init( SALOME_Selection* Sel )
203 myConstructorId = 0 ;
204 Constructor1->setChecked( TRUE );
205 myEditCurrentArgument = LineEditC1A1 ;
207 this->myOkActor = false ;
209 /* Get setting of step value from file configuration */
211 // QString St = QAD_CONFIG->getSetting( "xxxxxxxxxxxxx" ) ; TODO
212 // step = St.toDouble() ; TODO
215 /* min, max, step and decimals for spin boxes */
216 SpinBox_FeatureAngle->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
217 SpinBox_FeatureAngle->SetValue( 30.0 ) ;
220 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
221 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
223 /* signals and slots connections */
224 //connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
225 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
226 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
227 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
229 connect( BoundaryEdges, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)) );
230 connect( ManifoldEdges, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)) );
231 connect( NonManifoldEdges, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)) );
232 connect( FeatureEdges, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)) );
234 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
235 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
236 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
237 /* to close dialog if study change */
238 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
240 /* Move widget on the botton right corner of main widget */
242 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
244 this->show() ; /* displays Dialog */
250 //=================================================================================
251 // function : ConstructorsClicked()
252 // purpose : Radio button management
253 //=================================================================================
254 void SMESHGUI_EdgesConnectivityDlg::ConstructorsClicked(int constructorId)
260 //=================================================================================
261 // function : ClickOnApply()
263 //=================================================================================
264 void SMESHGUI_EdgesConnectivityDlg::ClickOnApply()
266 switch(myConstructorId)
271 Standard_Boolean res;
272 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
273 if ( !IO->hasEntry() )
276 SMESH_Actor* ac = mySMESHGUI->FindActorByEntry( IO->getEntry(), res, true );
280 mySMESHGUI->ChangeRepresentation( ac, 0 );
282 vtkGeometryFilter *gf = vtkGeometryFilter::New();
283 gf->SetInput(ac->DataSource);
284 vtkFeatureEdges *edges = vtkFeatureEdges::New();
285 edges->SetInput( gf->GetOutput() );
287 if ( BoundaryEdges->isOn() ) edges->BoundaryEdgesOn();
288 else edges->BoundaryEdgesOff();
289 if ( ManifoldEdges->isOn() ) edges->ManifoldEdgesOn();
290 else edges->ManifoldEdgesOff();
291 if ( NonManifoldEdges->isOn() ) edges->NonManifoldEdgesOn();
292 else edges->NonManifoldEdgesOff();
293 if ( FeatureEdges->isOn() ) edges->FeatureEdgesOn();
294 else edges->FeatureEdgesOff();
296 double angle = SpinBox_FeatureAngle->GetValue() ;
297 edges->SetFeatureAngle( angle );
299 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
300 EdgeMapper->SetInput( edges->GetOutput() );
301 EdgeMapper->SetScalarModeToUseCellData();
302 ac->SetMapper(EdgeMapper);
304 mySMESHGUI->DisplayEdgesConnectivityLegendBox(ac);
312 //=================================================================================
313 // function : ClickOnOk()
315 //=================================================================================
316 void SMESHGUI_EdgesConnectivityDlg::ClickOnOk()
318 this->ClickOnApply() ;
319 this->ClickOnCancel() ;
324 //=================================================================================
325 // function : ClickOnCancel()
327 //=================================================================================
328 void SMESHGUI_EdgesConnectivityDlg::ClickOnCancel()
330 mySMESHGUI->ScalarVisibilityOff();
331 disconnect( mySelection, 0, this, 0 );
332 mySMESHGUI->ResetState() ;
333 mySMESHGUI->EraseSimulationActors();
334 mySMESHGUI->ScalarVisibilityOff();
340 //=================================================================================
341 // function : SelectionIntoArgument()
342 // purpose : Called when selection as changed or other case
343 //=================================================================================
344 void SMESHGUI_EdgesConnectivityDlg::SelectionIntoArgument()
346 myEditCurrentArgument->setText("") ;
348 QString aString = "";
350 int nbSel = mySMESHGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
352 mySMESHGUI->ScalarVisibilityOff();
356 myEditCurrentArgument->setText(aString) ;
362 //=================================================================================
363 // function : SetEditCurrentArgument()
365 //=================================================================================
366 void SMESHGUI_EdgesConnectivityDlg::SetEditCurrentArgument()
368 QPushButton* send = (QPushButton*)sender();
369 switch (myConstructorId)
371 case 0: /* default constructor */
373 if(send == SelectButtonC1A1) {
374 LineEditC1A1->setFocus() ;
375 myEditCurrentArgument = LineEditC1A1;
377 SelectionIntoArgument() ;
384 //=================================================================================
385 // function : DeactivateActiveDialog()
387 //=================================================================================
388 void SMESHGUI_EdgesConnectivityDlg::DeactivateActiveDialog()
390 if ( GroupConstructors->isEnabled() ) {
391 GroupConstructors->setEnabled(false) ;
392 GroupC1->setEnabled(false) ;
393 GroupButtons->setEnabled(false) ;
399 //=================================================================================
400 // function : ActivateThisDialog()
402 //=================================================================================
403 void SMESHGUI_EdgesConnectivityDlg::ActivateThisDialog()
405 /* Emit a signal to deactivate the active dialog */
406 mySMESHGUI->EmitSignalDeactivateDialog() ;
407 GroupConstructors->setEnabled(true) ;
408 GroupC1->setEnabled(true) ;
409 GroupButtons->setEnabled(true) ;
414 //=================================================================================
415 // function : enterEvent()
417 //=================================================================================
418 void SMESHGUI_EdgesConnectivityDlg::enterEvent(QEvent* e)
420 if ( GroupConstructors->isEnabled() )
422 ActivateThisDialog() ;
427 //=================================================================================
428 // function : closeEvent()
430 //=================================================================================
431 void SMESHGUI_EdgesConnectivityDlg::closeEvent( QCloseEvent* e )
433 /* same than click on cancel button */
434 this->ClickOnCancel() ;
438 void SMESHGUI_EdgesConnectivityDlg::CheckBox( int state )
440 QCheckBox* send = (QCheckBox*)sender();
441 if( send == BoundaryEdges ) {
442 } else if( send == ManifoldEdges ) {
443 } else if( send == NonManifoldEdges ) {