Salome HOME
Implementation of the "21187: EDF 1137 GEOM: Performance issue when manipulating...
[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   //Hide preview checkbox
161   mainFrame()->CheckBoxPreview->hide();
162
163   /* signals and slots connections */
164   connect( buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
165   connect( buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
166
167   connect( this,          SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
168
169   connect( GroupPoints->PushButton1,  SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
170   connect( GroupPoints->LineEdit1,    SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
171
172   connect( GroupPoints2->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
173   connect( GroupPoints2->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
174   connect( myTolEdt2, SIGNAL( valueChanged( double ) ), this, SLOT( onTolerChanged( double ) ) );
175   connect( mySubShapesChk, SIGNAL( stateChanged( int ) ), this, SLOT( onSubShapesChk() ) );
176
177   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
178            this, SLOT( SelectionIntoArgument() ) );
179
180   connect( myDetectBtn, SIGNAL( clicked() ), this, SLOT( onDetect() ) );
181
182   initName( tr( "GLUE_NEW_OBJ_NAME" ) );
183
184   ConstructorsClicked( 0 );
185   
186   activateSelection();
187   updateButtonState();
188 }
189
190
191 //=================================================================================
192 // function : ConstructorsClicked()
193 // purpose  : Radio button management
194 //=================================================================================
195 void RepairGUI_GlueDlg::ConstructorsClicked( int constructorId )
196 {
197   if ( myCurrConstrId == constructorId )
198     return;
199   
200   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
201   
202   switch ( constructorId ) {
203   case 0:
204     GroupPoints2->hide();
205     GroupPoints->show();
206     GroupPoints->LineEdit1->setText( "" );
207     myEditCurrentArgument = GroupPoints->LineEdit1;
208     
209     if ( myCurrConstrId >= 0 ) {
210       // i.e. it is not initialisation
211       // copy tolerance from previous tolerance field
212       myTolEdt->setValue( myTolEdt2->value() );
213     }
214     break;
215   case 1:
216     GroupPoints->hide();
217     GroupPoints2->show();
218     GroupPoints->LineEdit1->setText( "" );
219     myEditCurrentArgument = GroupPoints2->LineEdit1;
220         
221     if ( myCurrConstrId >= 0 ) {
222       // i.e. it is not initialisation
223       // copy tolerance from previous tolerance field
224       myTolEdt2->setValue( myTolEdt->value() );
225       mySubShapesChk->setChecked( false );
226       clearTemporary();
227     }
228     break;
229   }
230     
231   myCurrConstrId = constructorId;
232
233   myEditCurrentArgument->setFocus();
234
235   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
236            this, SLOT( SelectionIntoArgument() ) );
237
238   qApp->processEvents();
239   updateGeometry();
240   resize( minimumSizeHint() );
241
242   processPreview();
243   updateButtonState();
244   activateSelection();
245   SelectionIntoArgument();
246 }
247
248
249 //=================================================================================
250 // function : ClickOnOk()
251 // purpose  : Same than click on apply but close this dialog.
252 //=================================================================================
253 void RepairGUI_GlueDlg::ClickOnOk()
254 {
255   if ( ClickOnApply() )
256     ClickOnCancel();
257 }
258
259
260 //=================================================================================
261 // function : ClickOnApply()
262 // purpose  :
263 //=================================================================================
264 bool RepairGUI_GlueDlg::ClickOnApply()
265 {
266   if ( !onAcceptLocal() )
267     return false;
268
269   initName();
270
271   //GroupPoints->LineEdit1->setText("");
272   //myObject = GEOM::GEOM_Object::_nil();
273
274   //globalSelection( GEOM_COMPOUND );
275
276   ConstructorsClicked( getConstructorId() );
277
278   return true;
279 }
280
281
282 //=================================================================================
283 // function : SelectionIntoArgument()
284 // purpose  : Called when selection
285 //=================================================================================
286 void RepairGUI_GlueDlg::SelectionIntoArgument()
287 {
288   if ( mySubShapesChk->isChecked() &&  getConstructorId() == 1 ) {
289     updateButtonState();
290     return;
291   }
292   
293   erasePreview();
294   myEditCurrentArgument->setText( "" );
295   myObject = GEOM::GEOM_Object::_nil();
296
297   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
298   SALOME_ListIO aSelList;
299   aSelMgr->selectedObjects(aSelList);
300
301   if ( aSelList.Extent() == 1 ) {
302     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
303     myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
304     if ( !CORBA::is_nil( myObject ) )
305       myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
306   }
307   updateButtonState();
308 }
309
310 //=================================================================================
311 // function : SetEditCurrentArgument()
312 // purpose  :
313 //=================================================================================
314 void RepairGUI_GlueDlg::SetEditCurrentArgument()
315 {
316   const QObject* send = sender();
317   if ( send == GroupPoints->PushButton1 || send == GroupPoints2->PushButton1 )  {
318     myEditCurrentArgument->setFocus();
319     SelectionIntoArgument();
320   }
321 }
322
323
324 //=================================================================================
325 // function : LineEditReturnPressed()
326 // purpose  :
327 //=================================================================================
328 void RepairGUI_GlueDlg::LineEditReturnPressed()
329 {
330   const QObject* send = sender();
331   if ( send == GroupPoints->LineEdit1 ) {
332     myEditCurrentArgument = GroupPoints->LineEdit1;
333     GEOMBase_Skeleton::LineEditReturnPressed();
334   }
335   else if ( send == GroupPoints2->LineEdit1 ) {
336     myEditCurrentArgument = GroupPoints2->LineEdit1;
337     GEOMBase_Skeleton::LineEditReturnPressed();
338   }
339 }
340
341
342 //=================================================================================
343 // function : ActivateThisDialog()
344 // purpose  :
345 //=================================================================================
346 void RepairGUI_GlueDlg::ActivateThisDialog()
347 {
348   GEOMBase_Skeleton::ActivateThisDialog();
349   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), 
350            this, SLOT( SelectionIntoArgument() ) );
351
352   //GroupPoints->LineEdit1->setText("");
353   //GroupPoints2->LineEdit1->setText("");
354   //myObject = GEOM::GEOM_Object::_nil();
355
356   //myGeomGUI->SetState( 0 );
357   //globalSelection( GEOM_COMPOUND );
358   activateSelection();
359 }
360
361
362 //=================================================================================
363 // function : enterEvent()
364 // purpose  : Mouse enter onto the dialog to activate it
365 //=================================================================================
366 void RepairGUI_GlueDlg::enterEvent( QEvent* )
367 {
368   if ( !mainFrame()->GroupConstructors->isEnabled() )
369     ActivateThisDialog();
370 }
371
372
373 //=================================================================================
374 // function : createOperation
375 // purpose  :
376 //=================================================================================
377 GEOM::GEOM_IOperations_ptr RepairGUI_GlueDlg::createOperation()
378 {
379   return getGeomEngine()->GetIShapesOperations( getStudyId() );
380 }
381
382 //=================================================================================
383 // function : isValid
384 // purpose  :
385 //=================================================================================
386 bool RepairGUI_GlueDlg::isValid( QString& msg )
387 {
388   bool ok = true;
389   double v = 0;
390   switch ( getConstructorId() )
391   {
392   case 0:
393     v = myTolEdt->value();
394     ok = myTolEdt->isValid( msg, !IsPreview() );
395     break;
396   case 1:
397     v = myTolEdt2->value(); 
398     ok = myTolEdt2->isValid( msg, !IsPreview() );
399     break;
400   }
401   return !myObject->_is_nil() && ( IsPreview() || v > 0. ) && ok;
402 }
403
404 //=================================================================================
405 // function : execute
406 // purpose  :
407 //=================================================================================
408 bool RepairGUI_GlueDlg::execute( ObjectList& objects )
409 {
410   bool aResult = false;
411   objects.clear();
412
413   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
414   switch ( getConstructorId() ) {
415   case 0:
416     {
417       GEOM::GEOM_Object_var anObj = anOper->MakeGlueFaces( myObject, myTolEdt->value(), true );
418       aResult = !anObj->_is_nil();
419       if ( aResult && !IsPreview() )
420       {
421         QStringList aParameters;
422         aParameters << myTolEdt->text();
423         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
424
425         objects.push_back( anObj._retn() );
426       }
427       break;
428     }
429   case 1:
430     {
431       if ( IsPreview() ) {
432         // if this method is used for displaying preview then we must detect glue faces only
433         ObjectList::iterator anIter;
434         for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
435           objects.push_back( GEOM::GEOM_Object::_duplicate( *anIter ) );
436         return myTmpObjs.size() ? true : false;
437       } // IsPreview
438
439       // Make glue face by list.
440       // Iterate through myTmpObjs and verifies where each object is currently selected or not.
441       QMap<QString, char> selected;
442
443       // Get names of selected objects
444       LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
445       SALOME_ListIO aSelList;
446       aSelMgr->selectedObjects(aSelList);
447
448       SALOME_ListIteratorOfListIO it (aSelList);
449       for (; it.More(); it.Next()) 
450         selected.insert(it.Value()->getName(), 0);
451
452       // Iterate through result and select objects with names from selection
453       // ObjectList toRemoveFromEnggine;
454       ObjectList toGlue;
455       ObjectList::iterator anIter;
456       for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter ) {
457         if ( selected.contains( myGeomGUI->getApp()->orb()->object_to_string(*anIter) ) )
458           toGlue.push_back( *anIter );
459       }
460       
461       // make glue faces
462       GEOM::ListOfGO_var aListForGlue = new GEOM::ListOfGO();
463       aListForGlue->length( toGlue.size() );
464       ObjectList::iterator anIter3 = toGlue.begin();
465       for ( int i = 0; anIter3 != toGlue.end(); ++anIter3, ++i )
466         aListForGlue[ i ] = *anIter3;
467       GEOM::GEOM_Object_var anObj = anOper->MakeGlueFacesByList( myObject, myTolEdt2->value(), aListForGlue, true );
468
469       aResult = !anObj->_is_nil();
470
471       if ( aResult )
472       {
473         if ( !IsPreview() )
474         {
475           QStringList aParameters;
476           aParameters << myTolEdt2->text();
477           anObj->SetParameters(aParameters.join(":").toLatin1().constData());
478         }
479         objects.push_back( anObj._retn() );
480       }
481
482       // Remove from engine useless objects
483       clearTemporary();
484
485       updateButtonState();
486
487       break;
488     } // case 1
489   } // switch
490
491   return aResult;
492 }
493
494 //=================================================================================
495 // function : restoreSubShapes
496 // purpose  :
497 //=================================================================================
498 void RepairGUI_GlueDlg::restoreSubShapes( SALOMEDS::Study_ptr   theStudy,
499                                           SALOMEDS::SObject_ptr theSObject )
500 {
501   if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
502     GEOM::find_shape_method aFindMethod = GEOM::FSM_GetInPlace;
503     if ( getConstructorId() == 0 ) // MakeGlueFaces
504       aFindMethod = GEOM::FSM_GetInPlaceByHistory;
505
506     // empty list of arguments means that all arguments should be restored
507     getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
508                                          aFindMethod, /*theInheritFirstArg=*/true,
509                                          mainFrame()->CheckBoxAddPrefix->isChecked() );
510   }
511 }
512
513 //================================================================
514 // Function : clearShapeBufferLocal
515 // Purpose  : 
516 //================================================================
517 void RepairGUI_GlueDlg::clearShapeBufferLocal( GEOM::GEOM_Object_ptr theObj )
518 {
519   if ( CORBA::is_nil( theObj ) )
520     return;
521
522   CORBA::String_var IOR = myGeomGUI->getApp()->orb()->object_to_string( theObj );
523   TCollection_AsciiString asciiIOR( (char *)( IOR.in() ) );
524   myGeomGUI->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );
525
526   if ( !getStudy() || !( getStudy()->studyDS() ) )
527     return;
528
529   _PTR(Study) aStudy = getStudy()->studyDS();
530   _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR.in() ) ) );
531   if ( !aSObj )
532     return;
533
534   _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
535   for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
536     _PTR(GenericAttribute) anAttr;
537     if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
538       _PTR(AttributeIOR) anIOR ( anAttr );
539       TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
540       myGeomGUI->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );      
541     }
542   }
543 }
544
545 //================================================================
546 // Function : onAccept
547 // Purpose  : This method should be called from dialog's slots onOk() and onApply()
548 //            It perfroms user input validation, then it 
549 //            performs a proper operation and manages transactions, etc.
550 //================================================================
551 bool RepairGUI_GlueDlg::onAcceptLocal()
552 {
553   if ( !getStudy() || !( getStudy()->studyDS() ) )
554     return false;
555
556   _PTR(Study) aStudy = getStudy()->studyDS();
557
558   bool aLocked = aStudy->GetProperties()->IsLocked();
559   if ( aLocked ) {
560     MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
561     SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), tr( "WRN_STUDY_LOCKED" ), tr( "BUT_OK" ) );
562     return false;
563   }
564
565   QString msg;
566   if ( !isValid( msg ) ) {
567     showError( msg );
568     return false;
569   }
570
571   erasePreview( false );
572
573   try {
574     if ( openCommand() ) {
575       SUIT_OverrideCursor wc;
576       
577       myGeomGUI->getApp()->putInfo( "" );
578       ObjectList objects;
579       
580       if ( !execute( objects ) ) { 
581         wc.suspend();
582         abortCommand();
583         showError();
584       }
585       else {
586         const int nbObjs = objects.size();
587         for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
588           QString aName = getNewObjectName();
589           if ( nbObjs > 1 ) {
590             if ( aName.isEmpty() )
591               aName = getPrefix( *it );
592             aName = GEOMBase::GetDefaultName( aName );
593           }
594           else {
595             // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
596             if ( aName.isEmpty() )
597               aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
598           }
599           addInStudy( *it, aName.toLatin1().data() );
600           display( *it, false );
601         }
602         
603         if ( nbObjs ) {
604           commitCommand();
605           updateObjBrowser();
606           myGeomGUI->getApp()->putInfo( QObject::tr("GEOM_PRP_DONE") );
607         }
608         else {
609           abortCommand();
610         }
611
612         // JFA 28.12.2004 BEGIN // To enable warnings
613         GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
614         if ( !CORBA::is_nil(anOper) && !anOper->IsDone() ) {
615           wc.suspend();
616           QString msgw = QObject::tr( anOper->GetErrorCode() );
617           SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), msgw, tr( "BUT_OK" ) );
618         }
619         // JFA 28.12.2004 END
620       }
621     }
622   }
623   catch( const SALOME::SALOME_Exception& e ) {
624     SalomeApp_Tools::QtCatchCorbaException( e );
625     abortCommand();
626   }
627
628   updateViewer();
629   activateSelection();
630   updateButtonState();
631
632   return true;
633 }
634
635
636 //=================================================================================
637 // function : onDetect
638 // purpose  :
639 //=================================================================================
640 void RepairGUI_GlueDlg::onDetect()
641 {
642   clearTemporary();
643   QString msg;
644   if ( !isValid( msg ) ) {
645     showError( msg );
646     return;
647   }
648
649   buttonOk()->setEnabled( false );
650   buttonApply()->setEnabled( false );
651   globalSelection( GEOM_ALLSHAPES );
652
653   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
654   GEOM::ListOfGO_var aList = anOper->GetGlueFaces( myObject, myTolEdt2->value() );
655   
656   for ( int i = 0, n = aList->length(); i < n; i++ ) 
657     myTmpObjs.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
658   
659   if ( myTmpObjs.size() > 0  ) {
660     msg = tr( "FACES_FOR_GLUING_ARE_DETECTED" ).arg( myTmpObjs.size() );
661     mySubShapesChk->setChecked( true );
662   }
663   else {
664     msg = tr( "THERE_ARE_NO_FACES_FOR_GLUING" );
665   }
666   
667   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
668            this, SLOT( SelectionIntoArgument() ) ) ;
669   SUIT_MessageBox::information( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg, tr( "Close" ) );
670   updateButtonState();
671   activateSelection();
672 }
673
674 //=================================================================================
675 // function : activateSelection
676 // purpose  : Redisplay preview and Activate selection
677 //=================================================================================
678 void RepairGUI_GlueDlg::activateSelection()
679 {
680   erasePreview( false );
681   
682   int anId = getConstructorId();
683   if ( anId == 0 )  { 
684     // Case of whole gluing
685     disconnect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
686                 this, SLOT( SelectionIntoArgument() ) );
687     
688     globalSelection( GEOM_ALLSHAPES );
689     if ( myObject->_is_nil()) 
690       SelectionIntoArgument();
691
692     connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
693              this, SLOT( SelectionIntoArgument() ) );
694   } 
695   else {
696     // Second case of gluing
697     if ( !mySubShapesChk->isChecked() ) 
698       globalSelection( GEOM_ALLSHAPES );
699     else {
700       displayPreview( true, false, false, 2/*line width*/, 1/*display mode*/, Quantity_NOC_RED );
701       disconnect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
702                   this, SLOT( SelectionIntoArgument() ) ) ;
703       globalSelection( GEOM_PREVIEW );
704       connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
705                this, SLOT( SelectionIntoArgument() ) ) ;
706     } 
707   }
708   updateViewer();
709 }
710
711 //=================================================================================
712 // function : updateButtonState
713 // purpose  : Update button state 
714 //=================================================================================
715 void RepairGUI_GlueDlg::updateButtonState()
716 {
717   int anId = getConstructorId();
718   bool hasMainObj = !myObject->_is_nil();
719   if ( anId == 0 ) {
720     buttonOk()->setEnabled( hasMainObj );
721     buttonApply()->setEnabled( hasMainObj );
722   }
723   else
724   {
725     LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
726     SALOME_ListIO aSelList;
727     aSelMgr->selectedObjects(aSelList);
728
729     bool wasSelected = false;
730     SALOME_ListIteratorOfListIO it (aSelList);
731     if (it.More() > 0)
732       wasSelected = true;
733     bool wasDetected = myTmpObjs.size() ? true : false;
734     buttonOk()->setEnabled( hasMainObj && wasDetected && wasSelected );
735     buttonApply()->setEnabled( hasMainObj && wasDetected && wasSelected );
736     mySubShapesChk->setEnabled( hasMainObj && wasDetected );
737     myDetectBtn->setEnabled( hasMainObj );
738     if ( !hasMainObj || !wasDetected )
739       mySubShapesChk->setChecked( false );
740   }
741 }
742
743 //=================================================================================
744 // function : clearTemporary
745 // purpose  : Remove temporary objects from engine
746 //=================================================================================
747 void RepairGUI_GlueDlg::clearTemporary()
748 {
749   ObjectList::iterator anIter;
750   for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
751     getGeomEngine()->RemoveObject(*anIter);
752
753   myTmpObjs.clear();
754 }
755
756 //=================================================================================
757 // function : onTolerChanged
758 // purpose  : Remove temporary objects from engine
759 //=================================================================================
760 void RepairGUI_GlueDlg::onTolerChanged( double /*theVal*/ )
761 {
762   clearTemporary();
763   activateSelection();
764   updateButtonState();
765 }
766
767 //=================================================================================
768 // function : onSubShapesChk
769 // purpose  : Update selection mode
770 //=================================================================================
771 void RepairGUI_GlueDlg::onSubShapesChk()
772 {
773   if ( !mySubShapesChk->isChecked() )
774     clearTemporary();
775   activateSelection();
776   updateButtonState();
777 }
778
779 //=================================================================================
780 // function : ClickOnCancel
781 // purpose  : Remove temporary objects from engine and call method of base class
782 //=================================================================================
783 void RepairGUI_GlueDlg::ClickOnCancel()
784 {
785   clearTemporary();
786   GEOMBase_Skeleton::ClickOnCancel();
787 }