2 // File : SMESHGUI_EdgesConnectivityDlg.cxx
3 // Created : Tue Jun 25 21:22:12 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
12 #include "SMESHGUI_EdgesConnectivityDlg.h"
14 #include "SMESHGUI_SpinBox.h"
16 #include "QAD_Application.h"
17 #include "QAD_Desktop.h"
18 #include "QAD_MessageBox.h"
19 #include "utilities.h"
22 #include <qbuttongroup.h>
23 #include <qgroupbox.h>
25 #include <qlineedit.h>
26 #include <qpushbutton.h>
27 #include <qradiobutton.h>
31 #include <qwhatsthis.h>
34 #include <qcheckbox.h>
37 #include <vtkFeatureEdges.h>
39 //=================================================================================
40 // class : SMESHGUI_EdgesConnectivityDlg()
42 //=================================================================================
43 SMESHGUI_EdgesConnectivityDlg::SMESHGUI_EdgesConnectivityDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
44 bool modal, WFlags fl )
45 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
47 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_CONNECTIVITY")));
48 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
51 setName( "SMESHGUI_EdgesConnectivityDlg" );
53 setCaption( tr( "SMESH_EDGES_CONNECTIVITY_TITLE" ) );
54 setSizeGripEnabled( TRUE );
55 SMESHGUI_EdgesConnectivityDlgLayout = new QGridLayout( this );
56 SMESHGUI_EdgesConnectivityDlgLayout->setSpacing( 6 );
57 SMESHGUI_EdgesConnectivityDlgLayout->setMargin( 11 );
59 /***************************************************************/
60 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
61 GroupConstructors->setTitle( tr( "SMESH_EDGES_CONNECTIVITY" ) );
62 GroupConstructors->setExclusive( TRUE );
63 GroupConstructors->setColumnLayout(0, Qt::Vertical );
64 GroupConstructors->layout()->setSpacing( 0 );
65 GroupConstructors->layout()->setMargin( 0 );
66 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
67 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
68 GroupConstructorsLayout->setSpacing( 6 );
69 GroupConstructorsLayout->setMargin( 11 );
70 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
71 Constructor1->setText( tr( "" ) );
72 Constructor1->setPixmap( image0 );
73 Constructor1->setChecked( TRUE );
74 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
75 Constructor1->setMinimumSize( QSize( 50, 0 ) );
76 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
77 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
78 GroupConstructorsLayout->addItem( spacer, 0, 1 );
79 SMESHGUI_EdgesConnectivityDlgLayout->addWidget( GroupConstructors, 0, 0 );
81 /***************************************************************/
82 GroupButtons = new QGroupBox( this, "GroupButtons" );
83 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
84 GroupButtons->setTitle( tr( "" ) );
85 GroupButtons->setColumnLayout(0, Qt::Vertical );
86 GroupButtons->layout()->setSpacing( 0 );
87 GroupButtons->layout()->setMargin( 0 );
88 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
89 GroupButtonsLayout->setAlignment( Qt::AlignTop );
90 GroupButtonsLayout->setSpacing( 6 );
91 GroupButtonsLayout->setMargin( 11 );
92 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
93 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
94 buttonCancel->setAutoDefault( TRUE );
95 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
96 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
97 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
98 buttonApply->setAutoDefault( TRUE );
99 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
100 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
101 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
102 //buttonOk = new QPushButton( GroupButtons, "buttonOk" );
103 //buttonOk->setText( tr( "SMESH_BUT_OK" ) );
104 //buttonOk->setAutoDefault( TRUE );
105 //buttonOk->setDefault( TRUE );
106 //GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
107 SMESHGUI_EdgesConnectivityDlgLayout->addWidget( GroupButtons, 2, 0 );
109 /***************************************************************/
110 GroupC1 = new QGroupBox( this, "GroupC1" );
111 GroupC1->setTitle( tr( "SMESH_EDGES_CONNECTIVITY" ) );
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_MESH" ) );
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 BoundaryEdges = new QCheckBox( GroupC1, "BoundaryEdges" );
137 BoundaryEdges->setText( tr( "SMESH_BOUNDARYEDGES" ) );
138 GroupC1Layout->addWidget( BoundaryEdges, 1, 0 );
140 ManifoldEdges = new QCheckBox( GroupC1, "ManifoldEdges" );
141 ManifoldEdges->setText( tr( "SMESH_MANIFOLDEDGES" ) );
142 GroupC1Layout->addWidget( ManifoldEdges, 2, 0 );
144 NonManifoldEdges = new QCheckBox( GroupC1, "NonManifoldEdges" );
145 NonManifoldEdges->setText( tr( "SMESH_NONMANIFOLDEDGES" ) );
146 GroupC1Layout->addWidget( NonManifoldEdges, 1, 2 );
148 FeatureEdges = new QCheckBox( GroupC1, "FeatureEdges" );
149 FeatureEdges->setText( tr( "SMESH_FEATUREEDGES" ) );
150 GroupC1Layout->addWidget( FeatureEdges, 2, 2 );
152 FeatureAngle= new QLabel( GroupC1, "FeatureAngle" );
153 FeatureAngle->setText( tr( "SMESH_FEATUREANGLE" ) );
154 FeatureAngle->setMinimumSize( QSize( 50, 0 ) );
155 FeatureAngle->setFrameShape( QLabel::NoFrame );
156 FeatureAngle->setFrameShadow( QLabel::Plain );
157 GroupC1Layout->addWidget( FeatureAngle, 3, 0 );
159 SpinBox_FeatureAngle = new SMESHGUI_SpinBox( GroupC1, "SpinBox_FeatureAngle" ) ;
160 GroupC1Layout->addWidget( SpinBox_FeatureAngle , 3, 2 );
162 SMESHGUI_EdgesConnectivityDlgLayout->addWidget( GroupC1, 1, 0 );
164 Init(Sel) ; /* Initialisations */
167 //=================================================================================
168 // function : ~SMESHGUI_EdgesConnectivityDlg()
169 // purpose : Destroys the object and frees any allocated resources
170 //=================================================================================
171 SMESHGUI_EdgesConnectivityDlg::~SMESHGUI_EdgesConnectivityDlg()
173 // no need to delete child widgets, Qt does it all for us
177 //=================================================================================
180 //=================================================================================
181 void SMESHGUI_EdgesConnectivityDlg::Init( SALOME_Selection* Sel )
185 myConstructorId = 0 ;
186 Constructor1->setChecked( TRUE );
187 myEditCurrentArgument = LineEditC1A1 ;
189 this->myOkActor = false ;
191 /* Get setting of step value from file configuration */
193 // QString St = QAD_CONFIG->getSetting( "xxxxxxxxxxxxx" ) ; TODO
194 // step = St.toDouble() ; TODO
197 /* min, max, step and decimals for spin boxes */
198 SpinBox_FeatureAngle->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
199 SpinBox_FeatureAngle->SetValue( 30.0 ) ;
202 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
203 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
205 /* signals and slots connections */
206 //connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
207 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
208 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
209 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
211 connect( BoundaryEdges, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)) );
212 connect( ManifoldEdges, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)) );
213 connect( NonManifoldEdges, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)) );
214 connect( FeatureEdges, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)) );
216 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
217 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
218 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
219 /* to close dialog if study change */
220 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
222 /* Move widget on the botton right corner of main widget */
224 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
226 this->show() ; /* displays Dialog */
232 //=================================================================================
233 // function : ConstructorsClicked()
234 // purpose : Radio button management
235 //=================================================================================
236 void SMESHGUI_EdgesConnectivityDlg::ConstructorsClicked(int constructorId)
242 //=================================================================================
243 // function : ClickOnApply()
245 //=================================================================================
246 void SMESHGUI_EdgesConnectivityDlg::ClickOnApply()
248 switch(myConstructorId)
253 Standard_Boolean res;
254 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
255 if ( !IO->hasEntry() )
258 SMESH_Actor* ac = mySMESHGUI->FindActorByEntry( IO->getEntry(), res, true );
262 mySMESHGUI->ChangeRepresentation( ac, 0 );
264 vtkGeometryFilter *gf = vtkGeometryFilter::New();
265 gf->SetInput(ac->DataSource);
266 vtkFeatureEdges *edges = vtkFeatureEdges::New();
267 edges->SetInput( gf->GetOutput() );
269 if ( BoundaryEdges->isOn() ) edges->BoundaryEdgesOn();
270 else edges->BoundaryEdgesOff();
271 if ( ManifoldEdges->isOn() ) edges->ManifoldEdgesOn();
272 else edges->ManifoldEdgesOff();
273 if ( NonManifoldEdges->isOn() ) edges->NonManifoldEdgesOn();
274 else edges->NonManifoldEdgesOff();
275 if ( FeatureEdges->isOn() ) edges->FeatureEdgesOn();
276 else edges->FeatureEdgesOff();
278 double angle = SpinBox_FeatureAngle->GetValue() ;
279 edges->SetFeatureAngle( angle );
281 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
282 EdgeMapper->SetInput( edges->GetOutput() );
283 EdgeMapper->SetScalarModeToUseCellData();
284 ac->SetMapper(EdgeMapper);
286 mySMESHGUI->DisplayEdgesConnectivityLegendBox(ac);
294 //=================================================================================
295 // function : ClickOnOk()
297 //=================================================================================
298 void SMESHGUI_EdgesConnectivityDlg::ClickOnOk()
300 this->ClickOnApply() ;
301 this->ClickOnCancel() ;
306 //=================================================================================
307 // function : ClickOnCancel()
309 //=================================================================================
310 void SMESHGUI_EdgesConnectivityDlg::ClickOnCancel()
312 mySMESHGUI->ScalarVisibilityOff();
313 disconnect( mySelection, 0, this, 0 );
314 mySMESHGUI->ResetState() ;
315 mySMESHGUI->EraseSimulationActors();
316 mySMESHGUI->ScalarVisibilityOff();
322 //=================================================================================
323 // function : SelectionIntoArgument()
324 // purpose : Called when selection as changed or other case
325 //=================================================================================
326 void SMESHGUI_EdgesConnectivityDlg::SelectionIntoArgument()
328 myEditCurrentArgument->setText("") ;
330 QString aString = "";
332 int nbSel = mySMESHGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
334 mySMESHGUI->ScalarVisibilityOff();
338 myEditCurrentArgument->setText(aString) ;
344 //=================================================================================
345 // function : SetEditCurrentArgument()
347 //=================================================================================
348 void SMESHGUI_EdgesConnectivityDlg::SetEditCurrentArgument()
350 QPushButton* send = (QPushButton*)sender();
351 switch (myConstructorId)
353 case 0: /* default constructor */
355 if(send == SelectButtonC1A1) {
356 LineEditC1A1->setFocus() ;
357 myEditCurrentArgument = LineEditC1A1;
359 SelectionIntoArgument() ;
366 //=================================================================================
367 // function : DeactivateActiveDialog()
369 //=================================================================================
370 void SMESHGUI_EdgesConnectivityDlg::DeactivateActiveDialog()
372 if ( GroupConstructors->isEnabled() ) {
373 GroupConstructors->setEnabled(false) ;
374 GroupC1->setEnabled(false) ;
375 GroupButtons->setEnabled(false) ;
381 //=================================================================================
382 // function : ActivateThisDialog()
384 //=================================================================================
385 void SMESHGUI_EdgesConnectivityDlg::ActivateThisDialog()
387 /* Emit a signal to deactivate the active dialog */
388 mySMESHGUI->EmitSignalDeactivateDialog() ;
389 GroupConstructors->setEnabled(true) ;
390 GroupC1->setEnabled(true) ;
391 GroupButtons->setEnabled(true) ;
396 //=================================================================================
397 // function : enterEvent()
399 //=================================================================================
400 void SMESHGUI_EdgesConnectivityDlg::enterEvent(QEvent* e)
402 if ( GroupConstructors->isEnabled() )
404 ActivateThisDialog() ;
409 //=================================================================================
410 // function : closeEvent()
412 //=================================================================================
413 void SMESHGUI_EdgesConnectivityDlg::closeEvent( QCloseEvent* e )
415 /* same than click on cancel button */
416 this->ClickOnCancel() ;
420 void SMESHGUI_EdgesConnectivityDlg::CheckBox( int state )
422 QCheckBox* send = (QCheckBox*)sender();
423 if( send == BoundaryEdges ) {
424 } else if( send == ManifoldEdges ) {
425 } else if( send == NonManifoldEdges ) {