]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_FillingHoleDlg.cxx
Salome HOME
SALOME PAL V1_4_1
[modules/geom.git] / src / RepairGUI / RepairGUI_FillingHoleDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry 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   : GeometryGUI_FillingHoleDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "GeometryGUI_FillingHoleDlg.h"
31
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
36
37
38
39 #include <qbuttongroup.h>
40 #include <qcheckbox.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
53 //=================================================================================
54 // class    : GeometryGUI_FillingHoleDlg()
55 // purpose  : Constructs a  GeometryGUI_FillingHoleDlg which is a child of 'parent', with the
56 //            name 'name' and widget flags set to 'f'.
57 //            The dialog will by default be modeless, unless you set 'modal' to
58 //            TRUE to construct a modal dialog.
59 //=================================================================================
60 GeometryGUI_FillingHoleDlg::GeometryGUI_FillingHoleDlg( QWidget* parent, 
61                                                         const char* name,
62                                                         SALOME_Selection* Sel,
63                                                         Handle (AIS_InteractiveContext) ic,                                       
64                                                         bool modal,
65                                                         WFlags fl )
66   : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
67 {
68   
69   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_SEWING")));
70   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
71   
72   if ( !name )
73     setName( "GeometryGUI_FillingHoleDlg" );
74   resize( 303, 203 ); 
75   setCaption( tr( "Filling hole"  ) );
76   setSizeGripEnabled( TRUE );
77   GeometryGUI_FillingHoleDlgLayout = new QGridLayout( this ); 
78   GeometryGUI_FillingHoleDlgLayout->setSpacing( 6 );
79   GeometryGUI_FillingHoleDlgLayout->setMargin( 11 );
80
81   /***************************************************************/
82   GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
83   GroupConstructors->setTitle( tr( ""  ) );
84   GroupConstructors->setExclusive( TRUE );
85   GroupConstructors->setColumnLayout(0, Qt::Vertical );
86   GroupConstructors->layout()->setSpacing( 0 );
87   GroupConstructors->layout()->setMargin( 0 );
88   GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
89   GroupConstructorsLayout->setAlignment( Qt::AlignTop );
90   GroupConstructorsLayout->setSpacing( 6 );
91   GroupConstructorsLayout->setMargin( 11 );
92   Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
93   Constructor1->setText( tr( ""  ) );
94   Constructor1->setPixmap( image0 );
95   Constructor1->setChecked( TRUE );
96   Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
97   Constructor1->setMinimumSize( QSize( 50, 0 ) );
98   GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
99   QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
100   GroupConstructorsLayout->addItem( spacer, 0, 1 );
101   GeometryGUI_FillingHoleDlgLayout->addWidget( GroupConstructors, 0, 0 );
102
103   /***************************************************************/
104   GroupC1 = new QGroupBox( this, "GroupC1" );
105   GroupC1->setTitle( tr( ""  ) );
106   GroupC1->setMinimumSize( QSize( 0, 0 ) );
107   GroupC1->setFrameShape( QGroupBox::Box );
108   GroupC1->setFrameShadow( QGroupBox::Sunken );
109   GroupC1->setColumnLayout(0, Qt::Vertical );
110   GroupC1->layout()->setSpacing( 0 );
111   GroupC1->layout()->setMargin( 0 );
112   GroupC1Layout = new QGridLayout( GroupC1->layout() );
113   GroupC1Layout->setAlignment( Qt::AlignTop );
114   GroupC1Layout->setSpacing( 6 );
115   GroupC1Layout->setMargin( 11 );
116   Layout2 = new QHBoxLayout; 
117   Layout2->setSpacing( 6 );
118   Layout2->setMargin( 0 );
119   TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
120   TextLabelC1A1->setText( tr( "Main object"  ) );
121   TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
122   TextLabelC1A1->setFrameShape( QLabel::NoFrame );
123   TextLabelC1A1->setFrameShadow( QLabel::Plain );
124   Layout2->addWidget( TextLabelC1A1 );
125   SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
126   SelectButtonC1A1->setText( tr( ""  ) );
127   SelectButtonC1A1->setPixmap( image1 );
128   SelectButtonC1A1->setToggleButton( FALSE );
129   SelectButtonC1A1->setMaximumSize( QSize( 28, 32767 ) );
130   Layout2->addWidget( SelectButtonC1A1 );
131   LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
132   LineEditC1A1->setAlignment( int( QLineEdit::AlignLeft ) );
133   Layout2->addWidget( LineEditC1A1 );
134   GroupC1Layout->addLayout( Layout2, 0, 0 );
135   CheckBox1 = new QCheckBox( GroupC1, "CheckBox1" );
136   CheckBox1->setText( tr( "Select edges of hole on main object"  ) );
137   CheckBox1->setChecked( FALSE );
138   GroupC1Layout->addWidget( CheckBox1, 1, 0 );
139   GeometryGUI_FillingHoleDlgLayout->addWidget( GroupC1, 1, 0 );
140
141   /***************************************************************/
142   GroupButtons = new QGroupBox( this, "GroupButtons" );
143   GroupButtons->setTitle( tr( ""  ) );
144   GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, GroupButtons->sizePolicy().hasHeightForWidth() ) );
145   GroupButtons->setColumnLayout(0, Qt::Vertical );
146   GroupButtons->layout()->setSpacing( 0 );
147   GroupButtons->layout()->setMargin( 0 );
148   GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
149   GroupButtonsLayout->setAlignment( Qt::AlignTop );
150   GroupButtonsLayout->setSpacing( 6 );
151   GroupButtonsLayout->setMargin( 11 );
152   buttonClose = new QPushButton( GroupButtons, "buttonClose" );
153   buttonClose->setText( tr( "&Close"  ) );
154   buttonClose->setAutoDefault( TRUE );
155   GroupButtonsLayout->addWidget( buttonClose, 0, 3 );
156   buttonOk = new QPushButton( GroupButtons, "buttonOk" );
157   buttonOk->setText( tr( "&Ok"  ) );
158   buttonOk->setAutoDefault( TRUE );
159   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
160   buttonApply = new QPushButton( GroupButtons, "buttonApply" );
161   buttonApply->setText( tr( "&Apply"  ) );
162   buttonApply->setAutoDefault( TRUE );
163   buttonApply->setDefault( TRUE );
164   GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
165   QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
166   GroupButtonsLayout->addItem( spacer_2, 0, 2 );
167   GeometryGUI_FillingHoleDlgLayout->addWidget( GroupButtons, 2, 0 );
168   
169   /* Initialisations */
170   Init(Sel, ic) ;
171   
172 }
173
174
175 //=================================================================================
176 // function : ~GeometryGUI_FillingHoleDlg()
177 // purpose  : Destroys the object and frees any allocated resources
178 //=================================================================================
179 GeometryGUI_FillingHoleDlg::~GeometryGUI_FillingHoleDlg()
180 {
181     // no need to delete child widgets, Qt does it all for us
182 }
183
184
185
186 //=================================================================================
187 // function : Init()
188 // purpose  :
189 //=================================================================================
190 void GeometryGUI_FillingHoleDlg::Init( SALOME_Selection* Sel, Handle (AIS_InteractiveContext) ic )
191 {
192
193   GroupC1->show();
194   myConstructorId = 0 ;
195   Constructor1->setChecked( TRUE );
196   myEditCurrentArgument = LineEditC1A1 ;
197   mySelection = Sel;
198   myShape.Nullify() ;
199
200   myIC = ic ;
201   myUseLocalContext = false ;
202   myOkShape = false ;
203   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
204
205   /* Select sub shapes mode not checked */
206   CheckBox1->setChecked( FALSE );
207   myOkSelectSubMode = false ;
208
209   // TODO : previous selection into argument ?
210
211   /* Filter definitions */
212   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
213   myGeom = GEOM::GEOM_Gen::_narrow(comp);
214
215   /* signals and slots connections */
216   connect( buttonOk,          SIGNAL( clicked() ),    this, SLOT( ClickOnOk() ) );
217   connect( buttonApply,       SIGNAL( clicked() ),    this, SLOT( ClickOnApply() ) );
218   connect( buttonClose,       SIGNAL( clicked() ),    this, SLOT( ClickOnClose() ) );
219   connect( GroupConstructors, SIGNAL( clicked(int) ), this, SLOT( ConstructorsClicked(int) ));
220
221   connect( LineEditC1A1,      SIGNAL( returnPressed() ),                this, SLOT( LineEditReturnPressed() ) ) ;
222   connect( SelectButtonC1A1,  SIGNAL( clicked() ),                      this, SLOT( SetEditCurrentArgument() ));
223   connect( CheckBox1,         SIGNAL( stateChanged(int) ),              this, SLOT( ActivateUserSelection() ));
224
225   connect( mySelection,       SIGNAL( currentSelectionChanged() ),      this, SLOT( SelectionIntoArgument() ));
226   connect( myGeomGUI,         SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;  
227   connect( myGeomGUI,         SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnClose() ));
228  
229   /* Move widget on the botton right corner of main widget */
230   int x, y ;
231   myGeomGUI->DefineDlgPosition( this, x, y ) ;
232   this->move( x, y ) ;
233   this->show() ; /* display Dialog */
234
235   return ;
236 }
237
238
239 //=================================================================================
240 // function : ConstructorsClicked()
241 // purpose  : Radio button management
242 //=================================================================================
243 void GeometryGUI_FillingHoleDlg::ConstructorsClicked(int constructorId)
244 {
245   return ;
246 }
247
248
249 //=================================================================================
250 // function : ClickOnOk()
251 // purpose  : Same than click on apply but close this dialog.
252 //=================================================================================
253 void GeometryGUI_FillingHoleDlg::ClickOnOk()
254 {
255   this->ClickOnApply() ;
256   accept();
257
258   return ;
259 }
260
261
262
263 //=================================================================================
264 // function : ClickOnApply()
265 // purpose  :
266 //=================================================================================
267 void GeometryGUI_FillingHoleDlg::ClickOnApply()
268 {
269   bool testResult = false ;
270   QAD_Application::getDesktop()->putInfo( tr("") ) ; 
271
272   switch(myConstructorId)
273     { 
274     case 0 :
275       {
276         if( myOkShape && myOkSelectSubMode ) {
277           testResult = myGeomGUI->OnFillingHole( myShape, myShapeIOR, myLocalContextId, myUseLocalContext ) ; 
278         }
279         if( !testResult ) {
280           QAD_Application::getDesktop()->putInfo(tr("Operation aborted")) ;
281         }
282         else {
283           QAD_Application::getDesktop()->putInfo(tr("Operation done"));
284         }
285         /* Reset arguments to allow a new selection */
286         this->ResetStateOfDialog() ;
287         break ;
288       }
289     }
290   return ;
291 }
292
293
294
295 //=================================================================================
296 // function : ClickOnClose()
297 // purpose  :
298 //=================================================================================
299 void GeometryGUI_FillingHoleDlg::ClickOnClose()
300 {
301   disconnect( mySelection, 0, this, 0 );
302   myGeomGUI->ResetState() ;
303   
304   if(myUseLocalContext) {
305     myIC->CloseLocalContext(myLocalContextId) ;
306     this->myUseLocalContext = false ;
307     myGeomGUI->OnDisplayAll(true) ;
308   }
309   reject() ;
310   return ;
311 }
312
313
314 //=================================================================================
315 // function : SelectionIntoArgument()
316 // purpose  : Called when selection as changed or other case
317 //          : used only by SelectButtonC1A1 (LineEditC1A1)
318 //=================================================================================
319 void GeometryGUI_FillingHoleDlg::SelectionIntoArgument()
320 {
321   
322   /* Reset argument and local context when selection as changed */
323   this->ResetStateOfDialog() ;
324   
325   QString aString = ""; /* name of selection */
326   
327   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
328   if ( nbSel != 1 )
329     return ;
330   
331   /* nbSel == 1 */
332   TopoDS_Shape S ;
333   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
334
335   if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
336     return ;
337   
338 //    if( !IO->hasEntry() ) {
339 //      QAD_Application::getDesktop()->putInfo(tr("Main shape must be in the study before")) ;
340 //      return ;
341 //    }
342   
343   /* Test the exact type of topology to fill an hole */
344   if ( !S.IsNull() && ( S.ShapeType() == TopAbs_SOLID || S.ShapeType() == TopAbs_SHELL || S.ShapeType() == TopAbs_COMPOUND ) ) {
345     
346     if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
347       Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO );
348       myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */
349       LineEditC1A1->setText(aString) ;
350       myShape = S ;
351       myOkShape = true ;
352       return;
353     } 
354     
355     if ( IO->hasEntry() ) {
356       SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
357       SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() );
358       SALOMEDS::GenericAttribute_var anAttr;
359       SALOMEDS::AttributeIOR_var     anIOR;
360       if ( !obj->_is_nil() ) {
361         if (obj->FindAttribute(anAttr, "AttributeIOR")) {
362           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
363           myShapeIOR = anIOR->Value();
364           myOkShape = true ;
365           myShape = S ;
366           LineEditC1A1->setText(aString) ;
367           return;
368         }
369       }
370     }
371
372   }
373   return ;
374 }
375
376
377 //=================================================================================
378 // function : SetEditCurrentArgument()
379 // purpose  :
380 //=================================================================================
381 void GeometryGUI_FillingHoleDlg::SetEditCurrentArgument()
382 {
383   QPushButton* send = (QPushButton*)sender();
384   switch (myConstructorId)
385     {
386     case 0: /* default constructor */
387       {
388         if(send == SelectButtonC1A1) {
389           LineEditC1A1->setFocus() ;
390           myEditCurrentArgument = LineEditC1A1;   
391           SelectionIntoArgument() ;
392         }
393         break;
394       }
395     }
396   return ;
397 }
398
399
400 //=================================================================================
401 // function : LineEditReturnPressed()
402 // purpose  :
403 //=================================================================================
404 void GeometryGUI_FillingHoleDlg::LineEditReturnPressed()
405 {
406   QLineEdit* send = (QLineEdit*)sender();  
407   if( send == LineEditC1A1 )
408     myEditCurrentArgument = LineEditC1A1 ;
409   else
410     return ;
411   
412   /* User name of object input management                          */
413   /* If successfull the selection is changed and signal emitted... */
414   /* so SelectionIntoArgument() is automatically called.           */
415   const QString objectUserName = myEditCurrentArgument->text() ;
416   QWidget* thisWidget = (QWidget*)this ;
417   if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
418     myEditCurrentArgument->setText( objectUserName ) ;
419   }
420   return ;
421 }
422
423
424 //=================================================================================
425 // function : DeactivateActiveDialog()
426 // purpose  :
427 //=================================================================================
428 void GeometryGUI_FillingHoleDlg::DeactivateActiveDialog()
429 {
430   if ( GroupConstructors->isEnabled() ) {
431  
432    this->ResetStateOfDialog() ;
433
434     disconnect( mySelection, 0, this, 0 );
435     GroupConstructors->setEnabled(false) ;
436     GroupC1->setEnabled(false) ;
437     GroupButtons->setEnabled(false) ;
438     myGeomGUI->ResetState() ;    
439     myGeomGUI->SetActiveDialogBox(0) ;
440     myGeomGUI->OnDisplayAll(true) ;
441   }
442   return ;
443 }
444
445
446 //=================================================================================
447 // function : ActivateThisDialog()
448 // purpose  :
449 //=================================================================================
450 void GeometryGUI_FillingHoleDlg::ActivateThisDialog()
451 {
452   /* Emit a signal to deactivate other active dialog */
453   myGeomGUI->EmitSignalDeactivateDialog() ;
454   GroupConstructors->setEnabled(true) ;
455   GroupC1->setEnabled(true) ;
456   GroupButtons->setEnabled(true) ;
457   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
458   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
459   return ;
460 }
461
462
463 //=================================================================================
464 // function : enterEvent()
465 // purpose  : Mouse enter onto the dialog to activate it
466 //=================================================================================
467 void GeometryGUI_FillingHoleDlg::enterEvent(QEvent* e)
468 {
469   if ( GroupConstructors->isEnabled() )
470     return ;  
471   ActivateThisDialog() ;
472   return ;
473 }
474
475
476 //=================================================================================
477 // function : closeEvent()
478 // purpose  :
479 //=================================================================================
480 void GeometryGUI_FillingHoleDlg::closeEvent( QCloseEvent* e )
481 {
482   /* same than click on cancel button */
483   this->ClickOnClose() ;
484   return ;
485 }
486
487
488 //=================================================================================
489 // function : ActivateUserSelection()
490 // purpose  : Activate selection of faces when CheckBox1->isChecked()...
491 //=================================================================================
492 void GeometryGUI_FillingHoleDlg::ActivateUserSelection()
493 {
494   
495   if( !this->myOkShape ) {
496     this->ResetStateOfDialog() ;
497     QAD_Application::getDesktop()->putInfo(tr("Select main shape first")) ;
498     return ;
499   }
500   
501   this->myOkSelectSubMode = CheckBox1->isChecked() ;
502   
503   if( this->myUseLocalContext ) {
504     myIC->CloseLocalContext(myLocalContextId) ;
505     this->myUseLocalContext = false ;
506     myGeomGUI->OnDisplayAll(true) ;
507   }
508
509   if( myOkShape && myOkSelectSubMode ) {
510     /* local context is defined into the method : GEOM::EDGE sub selection */
511     TopAbs_ShapeEnum aType = TopAbs_EDGE ;
512     myGeomGUI->PrepareSubShapeSelection( int(aType), this->myLocalContextId ) ;    
513     myUseLocalContext = true ;
514     QAD_Application::getDesktop()->putInfo(tr("Select edges to fill an hole and click on Ok/Apply")) ;
515   }
516   return ;
517 }
518
519
520
521 //=================================================================================
522 // function : ResetStateOfDialog()
523 // purpose  : Completely reset the state of method including local context
524 //=================================================================================
525 void GeometryGUI_FillingHoleDlg::ResetStateOfDialog()
526 {
527   this->myOkShape = false ;
528   this->myEditCurrentArgument->setText("") ;
529
530   /* Select sub shapes mode not checked */
531   this->myOkSelectSubMode = false ;    
532   this->CheckBox1->setChecked( FALSE );
533
534   /* Close its local contact if opened */
535   if( this->myUseLocalContext ) {
536     myIC->CloseLocalContext(this->myLocalContextId) ;
537     this->myUseLocalContext = false ;
538     myGeomGUI->OnDisplayAll(true) ;
539   }
540   return ;
541 }
542
543
544