]> SALOME platform Git repositories - modules/geom.git/blob - RepairGUI_GlueDlg.cxx
Salome HOME
12c2a202118d59c9271bb6cf5f997ba6e8a2d1cb
[modules/geom.git] / RepairGUI_GlueDlg.cxx
1 // GEOM RepairGUI : 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : RepairGUI_GlueDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S. 
24 //
25
26 #include "RepairGUI_GlueDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SalomeApp_Study.h>
35 #include <SalomeApp_Tools.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_Desktop.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_OverrideCursor.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SUIT_ViewWindow.h>
42 #include <SUIT_ViewManager.h>
43 #include <OCCViewer_ViewModel.h>
44 #include <SALOME_ListIteratorOfListIO.hxx>
45
46 #include <GEOMImpl_Types.hxx>
47
48 #include <TCollection_AsciiString.hxx>
49
50 #define DEFAULT_TOLERANCE_VALUE 1e-07
51
52 //=================================================================================
53 // class    : RepairGUI_GlueDlg()
54 // purpose  : Constructs a RepairGUI_GlueDlg  which is a child of 'parent', with the
55 //            name 'name' and widget flags set to 'f'.
56 //            The dialog will by default be modeless, unless you set 'modal' to
57 //            TRUE to construct a modal dialog.
58 //=================================================================================
59 RepairGUI_GlueDlg::RepairGUI_GlueDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
60                                       bool modal )
61   : GEOMBase_Skeleton( theGeometryGUI, parent, modal ),
62     myCurrConstrId( -1 )
63 {
64   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_GLUE_FACES" ) ) );
65   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_GLUE_FACES2" )  ));
66   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
67
68   setWindowTitle( tr( "GEOM_GLUE_TITLE" ) );
69
70   /***************************************************************/
71   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_GLUE_TITLE" ) );
72   mainFrame()->RadioButton1->setIcon( image0 );
73   mainFrame()->RadioButton2->setIcon( image2 );
74   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
75   mainFrame()->RadioButton3->close();
76
77   GroupPoints = new DlgRef_1SelExt( centralWidget() );
78   GroupPoints->GroupBox1->setTitle( tr( "GEOM_GLUE" ) );
79   GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
80   GroupPoints->PushButton1->setIcon( image1 );
81   GroupPoints->LineEdit1->setReadOnly( true );
82   
83   QLabel* aTolLab = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->Box );
84   myTolEdt = new QDoubleSpinBox( GroupPoints->Box );
85   initSpinBox( myTolEdt,  0, 100, 1e-7, 7 );
86   myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
87
88   QGridLayout* boxLayout = new QGridLayout( GroupPoints->Box );
89   boxLayout->setMargin( 0 ); boxLayout->setSpacing( 6 );
90   boxLayout->addWidget( aTolLab,  0, 0 );
91   boxLayout->addWidget( myTolEdt, 0, 2 );
92   /***************************************************************/
93
94   GroupPoints2 = new DlgRef_1SelExt( centralWidget() );
95   GroupPoints2->GroupBox1->setTitle( tr( "GEOM_GLUE" ) );
96   GroupPoints2->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
97   GroupPoints2->PushButton1->setIcon( image1 );
98   GroupPoints2->LineEdit1->setReadOnly( true );
99
100   QLabel* aTolLab2 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints2->Box );
101   myTolEdt2 = new QDoubleSpinBox( GroupPoints2->Box );
102   initSpinBox( myTolEdt2, 0, 100, 1e-7, 7 );
103   myTolEdt2->setValue( DEFAULT_TOLERANCE_VALUE );
104
105   myDetectBtn = new QPushButton( tr( "GEOM_DETECT" ) + QString( " [%1]" ).arg( tr( "GLUE_FACES" ) ), 
106                                  GroupPoints2->Box );
107   mySubShapesChk = new QCheckBox( tr( "SELECT_FACES" ), GroupPoints2->Box );
108
109   boxLayout = new QGridLayout( GroupPoints2->Box );
110   boxLayout->setMargin( 0 ); boxLayout->setSpacing( 6 );
111   boxLayout->addWidget( aTolLab2,    0, 0 );
112   boxLayout->addWidget( myTolEdt2,   0, 2 );
113   boxLayout->addWidget( myDetectBtn, 1, 0, 1, 3 );
114   boxLayout->addWidget( mySubShapesChk, 2, 0, 1, 3 );
115
116   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
117   layout->setMargin( 0 ); layout->setSpacing( 6 );
118   layout->addWidget( GroupPoints );
119   layout->addWidget( GroupPoints2 );
120
121   /***************************************************************/
122
123   setHelpFileName( "glue_faces_operation_page.html" );
124   
125   // Disable second way of gluing if OCC viewer is not active one
126   if ( myGeomGUI->getApp()->desktop()->activeWindow()->getViewManager()->getType()
127        != OCCViewer_Viewer::Type() )
128     mainFrame()->RadioButton2->setEnabled( false );
129
130   Init();
131 }
132
133
134 //=================================================================================
135 // function : ~RepairGUI_GlueDlg()
136 // purpose  : Destroys the object and frees any allocated resources
137 //=================================================================================
138 RepairGUI_GlueDlg::~RepairGUI_GlueDlg()
139 {
140 }
141
142
143 //=================================================================================
144 // function : Init()
145 // purpose  :
146 //=================================================================================
147 void RepairGUI_GlueDlg::Init()
148 {
149   /* init variables */
150   myEditCurrentArgument = GroupPoints->LineEdit1;
151
152   myObject = GEOM::GEOM_Object::_nil();
153
154   //myGeomGUI->SetState( 0 );
155   //globalSelection( GEOM_COMPOUND );
156
157   mainFrame()->GroupBoxPublish->show();
158
159   /* signals and slots connections */
160   connect( buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
161   connect( buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
162
163   connect( this,          SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
164
165   connect( GroupPoints->PushButton1,  SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
166   connect( GroupPoints->LineEdit1,    SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
167
168   connect( GroupPoints2->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
169   connect( GroupPoints2->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
170   connect( myTolEdt2, SIGNAL( valueChanged( double ) ), this, SLOT( onTolerChanged( double ) ) );
171   connect( mySubShapesChk, SIGNAL( stateChanged( int ) ), this, SLOT( onSubShapesChk() ) );
172
173   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
174            this, SLOT( SelectionIntoArgument() ) );
175
176   connect( myDetectBtn, SIGNAL( clicked() ), this, SLOT( onDetect() ) );
177
178   initName( tr( "GLUE_NEW_OBJ_NAME" ) );
179
180   ConstructorsClicked( 0 );
181   
182   activateSelection();
183   updateButtonState();
184 }
185
186
187 //=================================================================================
188 // function : ConstructorsClicked()
189 // purpose  : Radio button management
190 //=================================================================================
191 void RepairGUI_GlueDlg::ConstructorsClicked( int constructorId )
192 {
193   if ( myCurrConstrId == constructorId )
194     return;
195   
196   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
197   
198   switch ( constructorId ) {
199   case 0:
200     GroupPoints2->hide();
201     GroupPoints->show();
202     GroupPoints->LineEdit1->setText( "" );
203     myEditCurrentArgument = GroupPoints->LineEdit1;
204     
205     if ( myCurrConstrId >= 0 ) {
206       // i.e. it is not initialisation
207       // copy tolerance from previous tolerance field
208       myTolEdt->setValue( myTolEdt2->value() );
209     }
210     break;
211   case 1:
212     GroupPoints->hide();
213     GroupPoints2->show();
214     GroupPoints->LineEdit1->setText( "" );
215     myEditCurrentArgument = GroupPoints2->LineEdit1;
216         
217     if ( myCurrConstrId >= 0 ) {
218       // i.e. it is not initialisation
219       // copy tolerance from previous tolerance field
220       myTolEdt2->setValue( myTolEdt->value() );
221       mySubShapesChk->setChecked( false );
222       clearTemporary();
223     }
224     break;
225   }
226     
227   myCurrConstrId = constructorId;
228
229   myEditCurrentArgument->setFocus();
230
231   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
232            this, SLOT( SelectionIntoArgument() ) );
233
234   qApp->processEvents();
235   updateGeometry();
236   resize( minimumSize() );
237
238   displayPreview();
239   updateButtonState();
240   activateSelection();
241   SelectionIntoArgument();
242 }
243
244
245 //=================================================================================
246 // function : ClickOnOk()
247 // purpose  : Same than click on apply but close this dialog.
248 //=================================================================================
249 void RepairGUI_GlueDlg::ClickOnOk()
250 {
251   if ( ClickOnApply() )
252     ClickOnCancel();
253 }
254
255
256 //=================================================================================
257 // function : ClickOnApply()
258 // purpose  :
259 //=================================================================================
260 bool RepairGUI_GlueDlg::ClickOnApply()
261 {
262   if ( !onAcceptLocal() )
263     return false;
264
265   initName();
266
267   //GroupPoints->LineEdit1->setText("");
268   //myObject = GEOM::GEOM_Object::_nil();
269
270   //globalSelection( GEOM_COMPOUND );
271
272   ConstructorsClicked( getConstructorId() );
273
274   return true;
275 }
276
277
278 //=================================================================================
279 // function : SelectionIntoArgument()
280 // purpose  : Called when selection
281 //=================================================================================
282 void RepairGUI_GlueDlg::SelectionIntoArgument()
283 {
284   if ( mySubShapesChk->isChecked() &&  getConstructorId() == 1 ) {
285     updateButtonState();
286     return;
287   }
288   
289   erasePreview();
290   myEditCurrentArgument->setText( "" );
291   myObject = GEOM::GEOM_Object::_nil();
292
293   if ( IObjectCount() == 1 ) {
294     Handle(SALOME_InteractiveObject) anIO = firstIObject();
295     Standard_Boolean aRes;
296     myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
297     if ( aRes )
298       myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
299   }
300   updateButtonState();
301 }
302
303 //=================================================================================
304 // function : SetEditCurrentArgument()
305 // purpose  :
306 //=================================================================================
307 void RepairGUI_GlueDlg::SetEditCurrentArgument()
308 {
309   const QObject* send = sender();
310   if ( send == GroupPoints->PushButton1 || send == GroupPoints2->PushButton1 )  {
311     myEditCurrentArgument->setFocus();
312     SelectionIntoArgument();
313   }
314 }
315
316
317 //=================================================================================
318 // function : LineEditReturnPressed()
319 // purpose  :
320 //=================================================================================
321 void RepairGUI_GlueDlg::LineEditReturnPressed()
322 {
323   const QObject* send = sender();
324   if ( send == GroupPoints->LineEdit1 ) {
325     myEditCurrentArgument = GroupPoints->LineEdit1;
326     GEOMBase_Skeleton::LineEditReturnPressed();
327   }
328   else if ( send == GroupPoints2->LineEdit1 ) {
329     myEditCurrentArgument = GroupPoints2->LineEdit1;
330     GEOMBase_Skeleton::LineEditReturnPressed();
331   }
332 }
333
334
335 //=================================================================================
336 // function : ActivateThisDialog()
337 // purpose  :
338 //=================================================================================
339 void RepairGUI_GlueDlg::ActivateThisDialog()
340 {
341   GEOMBase_Skeleton::ActivateThisDialog();
342   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), 
343            this, SLOT( SelectionIntoArgument() ) );
344
345   //GroupPoints->LineEdit1->setText("");
346   //GroupPoints2->LineEdit1->setText("");
347   //myObject = GEOM::GEOM_Object::_nil();
348
349   //myGeomGUI->SetState( 0 );
350   //globalSelection( GEOM_COMPOUND );
351   activateSelection();
352 }
353
354
355 //=================================================================================
356 // function : enterEvent()
357 // purpose  : Mouse enter onto the dialog to activate it
358 //=================================================================================
359 void RepairGUI_GlueDlg::enterEvent( QEvent* )
360 {
361   if ( !mainFrame()->GroupConstructors->isEnabled() )
362     ActivateThisDialog();
363 }
364
365
366 //=================================================================================
367 // function : createOperation
368 // purpose  :
369 //=================================================================================
370 GEOM::GEOM_IOperations_ptr RepairGUI_GlueDlg::createOperation()
371 {
372   return getGeomEngine()->GetIShapesOperations( getStudyId() );
373 }
374
375 //=================================================================================
376 // function : isValid
377 // purpose  :
378 //=================================================================================
379 bool RepairGUI_GlueDlg::isValid( QString& )
380 {
381   double v = 0;
382   switch ( getConstructorId() )
383   {
384   case 0:
385     v = myTolEdt->value();  break;
386   case 1:
387     v = myTolEdt2->value(); break;
388   }
389   return !myObject->_is_nil() && ( IsPreview() || v > 0. );
390 }
391
392 //=================================================================================
393 // function : execute
394 // purpose  :
395 //=================================================================================
396 bool RepairGUI_GlueDlg::execute( ObjectList& objects )
397 {
398   bool aResult = false;
399   objects.clear();
400
401   switch ( getConstructorId() ) {
402   case 0:
403     {
404       GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow
405         ( getOperation() )->MakeGlueFaces( myObject, myTolEdt->value(), true );
406       aResult = !anObj->_is_nil();
407       if ( aResult )
408         objects.push_back( anObj._retn() );
409       break;
410     }
411   case 1:
412     {
413       if ( IsPreview() ) {
414         // if this method is used for displaying preview then we must detect glue faces only
415         ObjectList::iterator anIter;
416         for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
417           objects.push_back( GEOM::GEOM_Object::_duplicate( *anIter ) );
418         return myTmpObjs.size() ? true : false;
419       } // IsPreview
420
421       // Make glue face by list.
422       // Iterate through myTmpObjs and verifies where each object is currently selected or not.
423       QMap<QString, char> selected;
424
425       // Get names of selected objects
426       SALOME_ListIteratorOfListIO it ( selectedIO() );
427       for ( ; it.More(); it.Next() ) 
428         selected.insert( it.Value()->getName(), 0 );
429
430       // Iterate through result and select objects with names from selection
431       // ObjectList toRemoveFromEnggine;
432       ObjectList toGlue;
433       ObjectList::iterator anIter;
434       for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter ) {
435         if ( selected.contains( myGeomGUI->getApp()->orb()->object_to_string(*anIter) ) )
436           toGlue.push_back( *anIter );
437       }
438       
439       // make glue faces
440       GEOM::ListOfGO_var aListForGlue = new GEOM::ListOfGO();
441       aListForGlue->length( toGlue.size() );
442       ObjectList::iterator anIter3 = toGlue.begin();
443       for ( int i = 0; anIter3 != toGlue.end(); ++anIter3, ++i )
444         aListForGlue[ i ] = *anIter3;
445       GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow
446         ( getOperation() )->MakeGlueFacesByList( myObject, myTolEdt2->value(), aListForGlue, true );
447
448       aResult = !anObj->_is_nil();
449
450       if ( aResult )
451         objects.push_back( anObj._retn() );
452
453       // Remove from engine useless objects
454       clearTemporary();
455
456       updateButtonState();
457
458       break;
459     } // case 1
460   } // switch
461
462   return aResult;
463 }
464
465 //=================================================================================
466 // function : restoreSubShapes
467 // purpose  :
468 //=================================================================================
469 void RepairGUI_GlueDlg::restoreSubShapes( SALOMEDS::Study_ptr   theStudy,
470                                           SALOMEDS::SObject_ptr theSObject )
471 {
472   if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
473     GEOM::find_shape_method aFindMethod = GEOM::FSM_GetInPlace;
474     if ( getConstructorId() == 0 ) // MakeGlueFaces
475       aFindMethod = GEOM::FSM_GetInPlaceByHistory;
476
477     // empty list of arguments means that all arguments should be restored
478     getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
479                                          aFindMethod, /*theInheritFirstArg=*/true );
480   }
481 }
482
483 //================================================================
484 // Function : clearShapeBufferLocal
485 // Purpose  : 
486 //================================================================
487 void RepairGUI_GlueDlg::clearShapeBufferLocal( GEOM::GEOM_Object_ptr theObj )
488 {
489   if ( CORBA::is_nil( theObj ) )
490     return;
491
492   CORBA::String_var IOR = myGeomGUI->getApp()->orb()->object_to_string( theObj );
493   TCollection_AsciiString asciiIOR( (char *)( IOR.in() ) );
494   myGeomGUI->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );
495
496   if ( !getStudy() || !( getStudy()->studyDS() ) )
497     return;
498
499   _PTR(Study) aStudy = getStudy()->studyDS();
500   _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR.in() ) ) );
501   if ( !aSObj )
502     return;
503
504   _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
505   for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
506     _PTR(GenericAttribute) anAttr;
507     if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
508       _PTR(AttributeIOR) anIOR ( anAttr );
509       TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
510       myGeomGUI->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );      
511     }
512   }
513 }
514
515 //================================================================
516 // Function : onAccept
517 // Purpose  : This method should be called from dialog's slots onOk() and onApply()
518 //            It perfroms user input validation, then it 
519 //            performs a proper operation and manages transactions, etc.
520 //================================================================
521 bool RepairGUI_GlueDlg::onAcceptLocal()
522 {
523   if ( !getStudy() || !( getStudy()->studyDS() ) )
524     return false;
525
526   _PTR(Study) aStudy = getStudy()->studyDS();
527
528   bool aLocked = aStudy->GetProperties()->IsLocked();
529   if ( aLocked ) {
530     MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
531     SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), tr( "WRN_STUDY_LOCKED" ), tr( "BUT_OK" ) );
532     return false;
533   }
534
535   QString msg;
536   if ( !isValid( msg ) ) {
537     showError( msg );
538     return false;
539   }
540
541   erasePreview( false );
542
543   try {
544     if ( openCommand() ) {
545       SUIT_OverrideCursor wc;
546       
547       myGeomGUI->getApp()->putInfo( "" );
548       ObjectList objects;
549       
550       if ( !execute( objects ) ) { 
551         wc.suspend();
552         abortCommand();
553         showError();
554       }
555       else {
556         const int nbObjs = objects.size();
557         for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
558           QString aName = getNewObjectName();
559           if ( nbObjs > 1 ) {
560             if ( aName.isEmpty() )
561               aName = getPrefix( *it );
562             aName = GEOMBase::GetDefaultName( aName );
563           }
564           else {
565             // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
566             if ( aName.isEmpty() )
567               aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
568           }
569           addInStudy( *it, aName.toLatin1().data() );
570           display( *it, false );
571         }
572         
573         if ( nbObjs ) {
574           commitCommand();
575           updateObjBrowser();
576           myGeomGUI->getApp()->putInfo( QObject::tr("GEOM_PRP_DONE") );
577         }
578         else {
579           abortCommand();
580         }
581
582         // JFA 28.12.2004 BEGIN // To enable warnings
583         if ( !getOperation()->_is_nil() ) {
584           if ( !getOperation()->IsDone() ) {
585             wc.suspend();
586             QString msgw = QObject::tr( getOperation()->GetErrorCode() );
587             SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), msgw, tr( "BUT_OK" ) );
588           }
589         }
590         // JFA 28.12.2004 END
591       }
592     }
593   }
594   catch( const SALOME::SALOME_Exception& e ) {
595     SalomeApp_Tools::QtCatchCorbaException( e );
596     abortCommand();
597   }
598
599   updateViewer();
600   activateSelection();
601   updateButtonState();
602
603   return true;
604 }
605
606
607 //=================================================================================
608 // function : onDetect
609 // purpose  :
610 //=================================================================================
611 void RepairGUI_GlueDlg::onDetect()
612 {
613   clearTemporary();
614   QString msg;
615   if ( !isValid( msg ) ) {
616     showError( msg );
617     return;
618   }
619
620   buttonOk()->setEnabled( false );
621   buttonApply()->setEnabled( false );
622   globalSelection( GEOM_ALLSHAPES );
623
624   GEOM::ListOfGO_var aList = GEOM::GEOM_IShapesOperations::_narrow
625     ( getOperation() )->GetGlueFaces( myObject, myTolEdt2->value() );
626   
627   for ( int i = 0, n = aList->length(); i < n; i++ ) 
628     myTmpObjs.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
629   
630   if ( myTmpObjs.size() > 0  ) {
631     msg = tr( "FACES_FOR_GLUING_ARE_DETECTED" ).arg( myTmpObjs.size() );
632     mySubShapesChk->setChecked( true );
633   }
634   else {
635     msg = tr( "THERE_ARE_NO_FACES_FOR_GLUING" );
636   }
637   
638   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
639            this, SLOT( SelectionIntoArgument() ) ) ;
640   SUIT_MessageBox::information( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg, tr( "Close" ) );
641   updateButtonState();
642   activateSelection();
643 }
644
645 //=================================================================================
646 // function : activateSelection
647 // purpose  : Redisplay preview and Activate selection
648 //=================================================================================
649 void RepairGUI_GlueDlg::activateSelection()
650 {
651   erasePreview( false );
652   
653   int anId = getConstructorId();
654   if ( anId == 0 )  { 
655     // Case of whole gluing
656     disconnect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
657                 this, SLOT( SelectionIntoArgument() ) );
658     
659     globalSelection( GEOM_ALLSHAPES );
660     if ( myObject->_is_nil()) 
661       SelectionIntoArgument();
662
663     connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
664              this, SLOT( SelectionIntoArgument() ) );
665   } 
666   else {
667     // Second case of gluing
668     if ( !mySubShapesChk->isChecked() ) 
669       globalSelection( GEOM_ALLSHAPES );
670     else {
671       displayPreview( true, false, false, 2/*line width*/, 1/*display mode*/, Quantity_NOC_RED );
672       disconnect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
673                   this, SLOT( SelectionIntoArgument() ) ) ;
674       globalSelection( GEOM_PREVIEW );
675       connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
676                this, SLOT( SelectionIntoArgument() ) ) ;
677     } 
678   }
679   updateViewer();
680 }
681
682 //=================================================================================
683 // function : updateButtonState
684 // purpose  : Update button state 
685 //=================================================================================
686 void RepairGUI_GlueDlg::updateButtonState()
687 {
688   int anId = getConstructorId();
689   bool hasMainObj = !myObject->_is_nil();
690   if ( anId == 0 ) {
691     buttonOk()->setEnabled( hasMainObj );
692     buttonApply()->setEnabled( hasMainObj );
693   }
694   else
695   {
696     bool wasSelected = false;
697     SALOME_ListIteratorOfListIO it ( selectedIO() );
698     if (it.More() > 0)
699       wasSelected = true;
700     bool wasDetected = myTmpObjs.size() ? true : false;
701     buttonOk()->setEnabled( hasMainObj && wasDetected && wasSelected );
702     buttonApply()->setEnabled( hasMainObj && wasDetected && wasSelected );
703     mySubShapesChk->setEnabled( hasMainObj && wasDetected );
704     myDetectBtn->setEnabled( hasMainObj );
705     if ( !hasMainObj || !wasDetected )
706       mySubShapesChk->setChecked( false );
707   }
708 }
709
710 //=================================================================================
711 // function : clearTemporary
712 // purpose  : Remove temporary objects from engine
713 //=================================================================================
714 void RepairGUI_GlueDlg::clearTemporary()
715 {
716   ObjectList::iterator anIter;
717   for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
718     getGeomEngine()->RemoveObject(*anIter);
719
720   myTmpObjs.clear();
721 }
722
723 //=================================================================================
724 // function : onTolerChanged
725 // purpose  : Remove temporary objects from engine
726 //=================================================================================
727 void RepairGUI_GlueDlg::onTolerChanged( double /*theVal*/ )
728 {
729   clearTemporary();
730   activateSelection();
731   updateButtonState();
732 }
733
734 //=================================================================================
735 // function : onSubShapesChk
736 // purpose  : Update selection mode
737 //=================================================================================
738 void RepairGUI_GlueDlg::onSubShapesChk()
739 {
740   if ( !mySubShapesChk->isChecked() )
741     clearTemporary();
742   activateSelection();
743   updateButtonState();
744 }
745
746 //=================================================================================
747 // function : ClickOnCancel
748 // purpose  : Remove temporary objects from engine and call method of base class
749 //=================================================================================
750 void RepairGUI_GlueDlg::ClickOnCancel()
751 {
752   clearTemporary();
753   GEOMBase_Skeleton::ClickOnCancel();
754 }