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