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