Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_EdgesConnectivityDlg.cxx
1 using namespace std;
2 //  File      : SMESHGUI_EdgesConnectivityDlg.cxx
3 //  Created   : Tue Jun 25 21:22:12 2002
4 //  Author    : Nicolas REJNERI
5
6 //  Project   : SALOME
7 //  Module    : SMESH
8 //  Copyright : Open CASCADE 2002
9 //  $Header$
10
11
12 #include "SMESHGUI_EdgesConnectivityDlg.h"
13 #include "SMESHGUI.h"
14 #include "SMESHGUI_SpinBox.h"
15
16 #include "QAD_Application.h"
17 #include "QAD_Desktop.h"
18 #include "QAD_MessageBox.h"
19 #include "utilities.h"
20
21 // QT Includes
22 #include <qbuttongroup.h>
23 #include <qgroupbox.h>
24 #include <qlabel.h>
25 #include <qlineedit.h>
26 #include <qpushbutton.h>
27 #include <qradiobutton.h>
28 #include <qlayout.h>
29 #include <qvariant.h>
30 #include <qtooltip.h>
31 #include <qwhatsthis.h>
32 #include <qimage.h>
33 #include <qpixmap.h>
34 #include <qcheckbox.h>
35
36 // VTK Include
37 #include <vtkFeatureEdges.h>
38
39 //=================================================================================
40 // class    : SMESHGUI_EdgesConnectivityDlg()
41 // purpose  : 
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 )
46 {
47     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_CONNECTIVITY")));
48     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
49
50     if ( !name )
51         setName( "SMESHGUI_EdgesConnectivityDlg" );
52     resize( 303, 185 ); 
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 );
58
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 );
80     
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 );
108
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 );
135
136     BoundaryEdges = new QCheckBox( GroupC1, "BoundaryEdges" );
137     BoundaryEdges->setText( tr( "SMESH_BOUNDARYEDGES"  ) );
138     GroupC1Layout->addWidget( BoundaryEdges, 1, 0 );
139
140     ManifoldEdges = new QCheckBox( GroupC1, "ManifoldEdges" );
141     ManifoldEdges->setText( tr( "SMESH_MANIFOLDEDGES"  ) );
142     GroupC1Layout->addWidget( ManifoldEdges, 2, 0 );
143
144     NonManifoldEdges = new QCheckBox( GroupC1, "NonManifoldEdges" );
145     NonManifoldEdges->setText( tr( "SMESH_NONMANIFOLDEDGES"  ) );
146     GroupC1Layout->addWidget( NonManifoldEdges, 1, 2 );
147
148     FeatureEdges = new QCheckBox( GroupC1, "FeatureEdges" );
149     FeatureEdges->setText( tr( "SMESH_FEATUREEDGES"  ) );
150     GroupC1Layout->addWidget( FeatureEdges, 2, 2 );
151
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 );
158
159     SpinBox_FeatureAngle = new SMESHGUI_SpinBox( GroupC1, "SpinBox_FeatureAngle" ) ;
160     GroupC1Layout->addWidget( SpinBox_FeatureAngle , 3, 2 );
161
162     SMESHGUI_EdgesConnectivityDlgLayout->addWidget( GroupC1, 1, 0 );
163
164     Init(Sel) ; /* Initialisations */
165 }
166
167 //=================================================================================
168 // function : ~SMESHGUI_EdgesConnectivityDlg()
169 // purpose  : Destroys the object and frees any allocated resources
170 //=================================================================================
171 SMESHGUI_EdgesConnectivityDlg::~SMESHGUI_EdgesConnectivityDlg()
172 {
173     // no need to delete child widgets, Qt does it all for us
174 }
175
176
177 //=================================================================================
178 // function : Init()
179 // purpose  :
180 //=================================================================================
181 void SMESHGUI_EdgesConnectivityDlg::Init( SALOME_Selection* Sel )
182 {
183
184   GroupC1->show();
185   myConstructorId = 0 ;
186   Constructor1->setChecked( TRUE );
187   myEditCurrentArgument = LineEditC1A1 ;        
188   mySelection = Sel;  
189   this->myOkActor = false ;
190
191   /* Get setting of step value from file configuration */
192   double step ;
193   // QString St = QAD_CONFIG->getSetting( "xxxxxxxxxxxxx" ) ;  TODO
194   // step = St.toDouble() ;                                    TODO
195   step = 5.0 ;
196   
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 ) ;
200
201
202   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
203   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
204
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) ) );
210
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)) );
215
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() ) ) ;
221
222   /* Move widget on the botton right corner of main widget */
223   int x, y ;
224   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
225   this->move( x, y ) ;
226   this->show() ; /* displays Dialog */
227
228   return ;
229 }
230
231
232 //=================================================================================
233 // function : ConstructorsClicked()
234 // purpose  : Radio button management
235 //=================================================================================
236 void SMESHGUI_EdgesConnectivityDlg::ConstructorsClicked(int constructorId)
237 {
238   return ;
239 }
240
241
242 //=================================================================================
243 // function : ClickOnApply()
244 // purpose  :
245 //=================================================================================
246 void SMESHGUI_EdgesConnectivityDlg::ClickOnApply()
247 {
248   switch(myConstructorId)
249     { 
250     case 0 :
251       { 
252         if(myOkActor) {   
253           Standard_Boolean res;
254           Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
255           if ( !IO->hasEntry() )
256             break;
257
258           SMESH_Actor* ac = mySMESHGUI->FindActorByEntry( IO->getEntry(), res, true );
259           if ( !res )
260             break;
261
262           mySMESHGUI->ChangeRepresentation( ac, 0 );
263
264           vtkGeometryFilter *gf = vtkGeometryFilter::New();
265           gf->SetInput(ac->DataSource);
266           vtkFeatureEdges *edges = vtkFeatureEdges::New();
267           edges->SetInput( gf->GetOutput() );
268           edges->ColoringOn();
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();
277
278           double angle = SpinBox_FeatureAngle->GetValue() ;
279           edges->SetFeatureAngle( angle );
280
281           vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
282           EdgeMapper->SetInput( edges->GetOutput() );
283           EdgeMapper->SetScalarModeToUseCellData();
284           ac->SetMapper(EdgeMapper);
285
286           mySMESHGUI->DisplayEdgesConnectivityLegendBox(ac);
287         }
288         break ;
289       }
290     }
291   return ;
292 }
293
294 //=================================================================================
295 // function : ClickOnOk()
296 // purpose  :
297 //=================================================================================
298 void SMESHGUI_EdgesConnectivityDlg::ClickOnOk()
299 {
300   this->ClickOnApply() ;
301   this->ClickOnCancel() ;
302
303   return ;
304 }
305
306 //=================================================================================
307 // function : ClickOnCancel()
308 // purpose  :
309 //=================================================================================
310 void SMESHGUI_EdgesConnectivityDlg::ClickOnCancel()
311 {
312   mySMESHGUI->ScalarVisibilityOff();
313   disconnect( mySelection, 0, this, 0 );
314   mySMESHGUI->ResetState() ;
315   mySMESHGUI->EraseSimulationActors();
316   mySMESHGUI->ScalarVisibilityOff();
317   reject() ;
318   return ;
319 }
320
321
322 //=================================================================================
323 // function : SelectionIntoArgument()
324 // purpose  : Called when selection as changed or other case
325 //=================================================================================
326 void SMESHGUI_EdgesConnectivityDlg::SelectionIntoArgument()
327 {
328   myEditCurrentArgument->setText("") ;
329   myOkActor = false;
330   QString aString = "";
331
332   int nbSel = mySMESHGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
333   if(nbSel != 1) {
334     mySMESHGUI->ScalarVisibilityOff();
335     return;
336   }
337
338   myEditCurrentArgument->setText(aString) ;
339   myOkActor = true ;
340   return ;
341 }
342
343
344 //=================================================================================
345 // function : SetEditCurrentArgument()
346 // purpose  :
347 //=================================================================================
348 void SMESHGUI_EdgesConnectivityDlg::SetEditCurrentArgument()
349 {
350   QPushButton* send = (QPushButton*)sender();
351   switch (myConstructorId)
352     {
353     case 0: /* default constructor */
354       { 
355         if(send == SelectButtonC1A1) {
356           LineEditC1A1->setFocus() ;
357           myEditCurrentArgument = LineEditC1A1;
358         }
359         SelectionIntoArgument() ;
360         break;
361       }
362     }
363   return ;
364 }
365
366 //=================================================================================
367 // function : DeactivateActiveDialog()
368 // purpose  :
369 //=================================================================================
370 void SMESHGUI_EdgesConnectivityDlg::DeactivateActiveDialog()
371 {
372   if ( GroupConstructors->isEnabled() ) {
373     GroupConstructors->setEnabled(false) ;
374     GroupC1->setEnabled(false) ;
375     GroupButtons->setEnabled(false) ;
376   }
377   return ;
378 }
379
380
381 //=================================================================================
382 // function : ActivateThisDialog()
383 // purpose  :
384 //=================================================================================
385 void SMESHGUI_EdgesConnectivityDlg::ActivateThisDialog()
386 {
387   /* Emit a signal to deactivate the active dialog */
388   mySMESHGUI->EmitSignalDeactivateDialog() ;   
389   GroupConstructors->setEnabled(true) ;
390   GroupC1->setEnabled(true) ;
391   GroupButtons->setEnabled(true) ;
392   return ;
393 }
394
395
396 //=================================================================================
397 // function : enterEvent()
398 // purpose  :
399 //=================================================================================
400 void SMESHGUI_EdgesConnectivityDlg::enterEvent(QEvent* e)
401 {
402   if ( GroupConstructors->isEnabled() )
403     return ;  
404   ActivateThisDialog() ;
405   return ;
406 }
407
408
409 //=================================================================================
410 // function : closeEvent()
411 // purpose  :
412 //=================================================================================
413 void SMESHGUI_EdgesConnectivityDlg::closeEvent( QCloseEvent* e )
414 {
415   /* same than click on cancel button */
416   this->ClickOnCancel() ;
417   return ;
418 }
419
420 void SMESHGUI_EdgesConnectivityDlg::CheckBox( int state )
421 {
422     QCheckBox* send = (QCheckBox*)sender();
423     if( send == BoundaryEdges ) {
424     } else if( send == ManifoldEdges ) {
425     } else if( send == NonManifoldEdges ) {
426     } else {
427     }
428 }
429