Salome HOME
yfr : merge 1.2
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_EdgesConnectivityDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESHGUI_EdgesConnectivityDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESHGUI_EdgesConnectivityDlg.h"
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_SpinBox.h"
33
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "QAD_MessageBox.h"
37 #include "utilities.h"
38
39 // QT Includes
40 #include <qbuttongroup.h>
41 #include <qgroupbox.h>
42 #include <qlabel.h>
43 #include <qlineedit.h>
44 #include <qpushbutton.h>
45 #include <qradiobutton.h>
46 #include <qlayout.h>
47 #include <qvariant.h>
48 #include <qtooltip.h>
49 #include <qwhatsthis.h>
50 #include <qimage.h>
51 #include <qpixmap.h>
52 #include <qcheckbox.h>
53
54 // VTK Include
55 #include <vtkFeatureEdges.h>
56
57 //=================================================================================
58 // class    : SMESHGUI_EdgesConnectivityDlg()
59 // purpose  : 
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 )
64 {
65     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_CONNECTIVITY")));
66     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
67
68     if ( !name )
69         setName( "SMESHGUI_EdgesConnectivityDlg" );
70     resize( 303, 185 ); 
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 );
76
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 );
98     
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 );
126
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 );
153
154     BoundaryEdges = new QCheckBox( GroupC1, "BoundaryEdges" );
155     BoundaryEdges->setText( tr( "SMESH_BOUNDARYEDGES"  ) );
156     GroupC1Layout->addWidget( BoundaryEdges, 1, 0 );
157
158     ManifoldEdges = new QCheckBox( GroupC1, "ManifoldEdges" );
159     ManifoldEdges->setText( tr( "SMESH_MANIFOLDEDGES"  ) );
160     GroupC1Layout->addWidget( ManifoldEdges, 2, 0 );
161
162     NonManifoldEdges = new QCheckBox( GroupC1, "NonManifoldEdges" );
163     NonManifoldEdges->setText( tr( "SMESH_NONMANIFOLDEDGES"  ) );
164     GroupC1Layout->addWidget( NonManifoldEdges, 1, 2 );
165
166     FeatureEdges = new QCheckBox( GroupC1, "FeatureEdges" );
167     FeatureEdges->setText( tr( "SMESH_FEATUREEDGES"  ) );
168     GroupC1Layout->addWidget( FeatureEdges, 2, 2 );
169
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 );
176
177     SpinBox_FeatureAngle = new SMESHGUI_SpinBox( GroupC1, "SpinBox_FeatureAngle" ) ;
178     GroupC1Layout->addWidget( SpinBox_FeatureAngle , 3, 2 );
179
180     SMESHGUI_EdgesConnectivityDlgLayout->addWidget( GroupC1, 1, 0 );
181
182     Init(Sel) ; /* Initialisations */
183 }
184
185 //=================================================================================
186 // function : ~SMESHGUI_EdgesConnectivityDlg()
187 // purpose  : Destroys the object and frees any allocated resources
188 //=================================================================================
189 SMESHGUI_EdgesConnectivityDlg::~SMESHGUI_EdgesConnectivityDlg()
190 {
191     // no need to delete child widgets, Qt does it all for us
192 }
193
194
195 //=================================================================================
196 // function : Init()
197 // purpose  :
198 //=================================================================================
199 void SMESHGUI_EdgesConnectivityDlg::Init( SALOME_Selection* Sel )
200 {
201
202   GroupC1->show();
203   myConstructorId = 0 ;
204   Constructor1->setChecked( TRUE );
205   myEditCurrentArgument = LineEditC1A1 ;        
206   mySelection = Sel;  
207   this->myOkActor = false ;
208
209   /* Get setting of step value from file configuration */
210   double step ;
211   // QString St = QAD_CONFIG->getSetting( "xxxxxxxxxxxxx" ) ;  TODO
212   // step = St.toDouble() ;                                    TODO
213   step = 5.0 ;
214   
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 ) ;
218
219
220   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
221   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
222
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) ) );
228
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)) );
233
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() ) ) ;
239
240   /* Move widget on the botton right corner of main widget */
241   int x, y ;
242   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
243   this->move( x, y ) ;
244   this->show() ; /* displays Dialog */
245
246   return ;
247 }
248
249
250 //=================================================================================
251 // function : ConstructorsClicked()
252 // purpose  : Radio button management
253 //=================================================================================
254 void SMESHGUI_EdgesConnectivityDlg::ConstructorsClicked(int constructorId)
255 {
256   return ;
257 }
258
259
260 //=================================================================================
261 // function : ClickOnApply()
262 // purpose  :
263 //=================================================================================
264 void SMESHGUI_EdgesConnectivityDlg::ClickOnApply()
265 {
266   switch(myConstructorId)
267     { 
268     case 0 :
269       { 
270         if(myOkActor) {   
271           Standard_Boolean res;
272           Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
273           if ( !IO->hasEntry() )
274             break;
275
276           SMESH_Actor* ac = mySMESHGUI->FindActorByEntry( IO->getEntry(), res, true );
277           if ( !res )
278             break;
279
280           mySMESHGUI->ChangeRepresentation( ac, 0 );
281
282           vtkGeometryFilter *gf = vtkGeometryFilter::New();
283           gf->SetInput(ac->DataSource);
284           vtkFeatureEdges *edges = vtkFeatureEdges::New();
285           edges->SetInput( gf->GetOutput() );
286           edges->ColoringOn();
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();
295
296           double angle = SpinBox_FeatureAngle->GetValue() ;
297           edges->SetFeatureAngle( angle );
298
299           vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
300           EdgeMapper->SetInput( edges->GetOutput() );
301           EdgeMapper->SetScalarModeToUseCellData();
302           ac->SetMapper(EdgeMapper);
303
304           mySMESHGUI->DisplayEdgesConnectivityLegendBox(ac);
305         }
306         break ;
307       }
308     }
309   return ;
310 }
311
312 //=================================================================================
313 // function : ClickOnOk()
314 // purpose  :
315 //=================================================================================
316 void SMESHGUI_EdgesConnectivityDlg::ClickOnOk()
317 {
318   this->ClickOnApply() ;
319   this->ClickOnCancel() ;
320
321   return ;
322 }
323
324 //=================================================================================
325 // function : ClickOnCancel()
326 // purpose  :
327 //=================================================================================
328 void SMESHGUI_EdgesConnectivityDlg::ClickOnCancel()
329 {
330   mySMESHGUI->ScalarVisibilityOff();
331   disconnect( mySelection, 0, this, 0 );
332   mySMESHGUI->ResetState() ;
333   mySMESHGUI->EraseSimulationActors();
334   mySMESHGUI->ScalarVisibilityOff();
335   reject() ;
336   return ;
337 }
338
339
340 //=================================================================================
341 // function : SelectionIntoArgument()
342 // purpose  : Called when selection as changed or other case
343 //=================================================================================
344 void SMESHGUI_EdgesConnectivityDlg::SelectionIntoArgument()
345 {
346   myEditCurrentArgument->setText("") ;
347   myOkActor = false;
348   QString aString = "";
349
350   int nbSel = mySMESHGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
351   if(nbSel != 1) {
352     mySMESHGUI->ScalarVisibilityOff();
353     return;
354   }
355
356   myEditCurrentArgument->setText(aString) ;
357   myOkActor = true ;
358   return ;
359 }
360
361
362 //=================================================================================
363 // function : SetEditCurrentArgument()
364 // purpose  :
365 //=================================================================================
366 void SMESHGUI_EdgesConnectivityDlg::SetEditCurrentArgument()
367 {
368   QPushButton* send = (QPushButton*)sender();
369   switch (myConstructorId)
370     {
371     case 0: /* default constructor */
372       { 
373         if(send == SelectButtonC1A1) {
374           LineEditC1A1->setFocus() ;
375           myEditCurrentArgument = LineEditC1A1;
376         }
377         SelectionIntoArgument() ;
378         break;
379       }
380     }
381   return ;
382 }
383
384 //=================================================================================
385 // function : DeactivateActiveDialog()
386 // purpose  :
387 //=================================================================================
388 void SMESHGUI_EdgesConnectivityDlg::DeactivateActiveDialog()
389 {
390   if ( GroupConstructors->isEnabled() ) {
391     GroupConstructors->setEnabled(false) ;
392     GroupC1->setEnabled(false) ;
393     GroupButtons->setEnabled(false) ;
394   }
395   return ;
396 }
397
398
399 //=================================================================================
400 // function : ActivateThisDialog()
401 // purpose  :
402 //=================================================================================
403 void SMESHGUI_EdgesConnectivityDlg::ActivateThisDialog()
404 {
405   /* Emit a signal to deactivate the active dialog */
406   mySMESHGUI->EmitSignalDeactivateDialog() ;   
407   GroupConstructors->setEnabled(true) ;
408   GroupC1->setEnabled(true) ;
409   GroupButtons->setEnabled(true) ;
410   return ;
411 }
412
413
414 //=================================================================================
415 // function : enterEvent()
416 // purpose  :
417 //=================================================================================
418 void SMESHGUI_EdgesConnectivityDlg::enterEvent(QEvent* e)
419 {
420   if ( GroupConstructors->isEnabled() )
421     return ;  
422   ActivateThisDialog() ;
423   return ;
424 }
425
426
427 //=================================================================================
428 // function : closeEvent()
429 // purpose  :
430 //=================================================================================
431 void SMESHGUI_EdgesConnectivityDlg::closeEvent( QCloseEvent* e )
432 {
433   /* same than click on cancel button */
434   this->ClickOnCancel() ;
435   return ;
436 }
437
438 void SMESHGUI_EdgesConnectivityDlg::CheckBox( int state )
439 {
440     QCheckBox* send = (QCheckBox*)sender();
441     if( send == BoundaryEdges ) {
442     } else if( send == ManifoldEdges ) {
443     } else if( send == NonManifoldEdges ) {
444     } else {
445     }
446 }
447