]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_GlueDlg.cxx
Salome HOME
Preparation of intermediate revision
[modules/geom.git] / src / RepairGUI / RepairGUI_GlueDlg.cxx
1 //  Copyright (C) 2007-2008  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 // GEOM RepairGUI : GUI for Geometry component
23 // File   : RepairGUI_GlueDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S. 
25 //
26 #include "RepairGUI_GlueDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31 #include <QtxDoubleSpinBox.h>
32
33 #include <SalomeApp_Application.h>
34 #include <SalomeApp_Notebook.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( 0.0, 100.0, DEFAULT_TOLERANCE_VALUE, 7, 7, GroupPoints->Box );
87   myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
88
89   QGridLayout* boxLayout = new QGridLayout( GroupPoints->Box );
90   boxLayout->setMargin( 0 ); boxLayout->setSpacing( 6 );
91   boxLayout->addWidget( aTolLab,  0, 0 );
92   boxLayout->addWidget( myTolEdt, 0, 2 );
93   /***************************************************************/
94
95   GroupPoints2 = new DlgRef_1SelExt( centralWidget() );
96   GroupPoints2->GroupBox1->setTitle( tr( "GEOM_GLUE" ) );
97   GroupPoints2->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
98   GroupPoints2->PushButton1->setIcon( image1 );
99   GroupPoints2->LineEdit1->setReadOnly( true );
100
101   QLabel* aTolLab2 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints2->Box );
102   myTolEdt2 = new SalomeApp_DoubleSpinBox( GroupPoints2->Box );
103   initSpinBox( myTolEdt2, 0, 100, 1e-7, 7 );
104   myTolEdt2->setValue( DEFAULT_TOLERANCE_VALUE );
105
106   myDetectBtn = new QPushButton( tr( "GEOM_DETECT" ) + QString( " [%1]" ).arg( tr( "GLUE_FACES" ) ), 
107                                  GroupPoints2->Box );
108   mySubShapesChk = new QCheckBox( tr( "SELECT_FACES" ), GroupPoints2->Box );
109
110   boxLayout = new QGridLayout( GroupPoints2->Box );
111   boxLayout->setMargin( 0 ); boxLayout->setSpacing( 6 );
112   boxLayout->addWidget( aTolLab2,    0, 0 );
113   boxLayout->addWidget( myTolEdt2,   0, 2 );
114   boxLayout->addWidget( myDetectBtn, 1, 0, 1, 3 );
115   boxLayout->addWidget( mySubShapesChk, 2, 0, 1, 3 );
116
117   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
118   layout->setMargin( 0 ); layout->setSpacing( 6 );
119   layout->addWidget( GroupPoints );
120   layout->addWidget( GroupPoints2 );
121
122   /***************************************************************/
123
124   setHelpFileName( "glue_faces_operation_page.html" );
125   
126   // Disable second way of gluing if OCC viewer is not active one
127   if ( myGeomGUI->getApp()->desktop()->activeWindow()->getViewManager()->getType()
128        != OCCViewer_Viewer::Type() )
129     mainFrame()->RadioButton2->setEnabled( false );
130
131   Init();
132 }
133
134
135 //=================================================================================
136 // function : ~RepairGUI_GlueDlg()
137 // purpose  : Destroys the object and frees any allocated resources
138 //=================================================================================
139 RepairGUI_GlueDlg::~RepairGUI_GlueDlg()
140 {
141 }
142
143
144 //=================================================================================
145 // function : Init()
146 // purpose  :
147 //=================================================================================
148 void RepairGUI_GlueDlg::Init()
149 {
150   /* init variables */
151   myEditCurrentArgument = GroupPoints->LineEdit1;
152
153   myObject = GEOM::GEOM_Object::_nil();
154
155   //myGeomGUI->SetState( 0 );
156   //globalSelection( GEOM_COMPOUND );
157
158   mainFrame()->GroupBoxPublish->show();
159
160   /* signals and slots connections */
161   connect( buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
162   connect( buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
163
164   connect( this,          SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
165
166   connect( GroupPoints->PushButton1,  SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
167   connect( GroupPoints->LineEdit1,    SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
168
169   connect( GroupPoints2->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
170   connect( GroupPoints2->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
171   connect( myTolEdt2, SIGNAL( valueChanged( double ) ), this, SLOT( onTolerChanged( double ) ) );
172   connect( mySubShapesChk, SIGNAL( stateChanged( int ) ), this, SLOT( onSubShapesChk() ) );
173
174   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
175            this, SLOT( SelectionIntoArgument() ) );
176
177   connect( myDetectBtn, SIGNAL( clicked() ), this, SLOT( onDetect() ) );
178
179   initName( tr( "GLUE_NEW_OBJ_NAME" ) );
180
181   ConstructorsClicked( 0 );
182   
183   activateSelection();
184   updateButtonState();
185 }
186
187
188 //=================================================================================
189 // function : ConstructorsClicked()
190 // purpose  : Radio button management
191 //=================================================================================
192 void RepairGUI_GlueDlg::ConstructorsClicked( int constructorId )
193 {
194   if ( myCurrConstrId == constructorId )
195     return;
196   
197   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
198   
199   switch ( constructorId ) {
200   case 0:
201     GroupPoints2->hide();
202     GroupPoints->show();
203     GroupPoints->LineEdit1->setText( "" );
204     myEditCurrentArgument = GroupPoints->LineEdit1;
205     
206     if ( myCurrConstrId >= 0 ) {
207       // i.e. it is not initialisation
208       // copy tolerance from previous tolerance field
209       myTolEdt->setValue( myTolEdt2->value() );
210     }
211     break;
212   case 1:
213     GroupPoints->hide();
214     GroupPoints2->show();
215     GroupPoints->LineEdit1->setText( "" );
216     myEditCurrentArgument = GroupPoints2->LineEdit1;
217         
218     if ( myCurrConstrId >= 0 ) {
219       // i.e. it is not initialisation
220       // copy tolerance from previous tolerance field
221       myTolEdt2->setValue( myTolEdt->value() );
222       mySubShapesChk->setChecked( false );
223       clearTemporary();
224     }
225     break;
226   }
227     
228   myCurrConstrId = constructorId;
229
230   myEditCurrentArgument->setFocus();
231
232   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
233            this, SLOT( SelectionIntoArgument() ) );
234
235   qApp->processEvents();
236   updateGeometry();
237   resize( minimumSizeHint() );
238
239   displayPreview();
240   updateButtonState();
241   activateSelection();
242   SelectionIntoArgument();
243 }
244
245
246 //=================================================================================
247 // function : ClickOnOk()
248 // purpose  : Same than click on apply but close this dialog.
249 //=================================================================================
250 void RepairGUI_GlueDlg::ClickOnOk()
251 {
252   if ( ClickOnApply() )
253     ClickOnCancel();
254 }
255
256
257 //=================================================================================
258 // function : ClickOnApply()
259 // purpose  :
260 //=================================================================================
261 bool RepairGUI_GlueDlg::ClickOnApply()
262 {
263   if ( !onAcceptLocal() )
264     return false;
265
266   initName();
267
268   //GroupPoints->LineEdit1->setText("");
269   //myObject = GEOM::GEOM_Object::_nil();
270
271   //globalSelection( GEOM_COMPOUND );
272
273   ConstructorsClicked( getConstructorId() );
274
275   return true;
276 }
277
278
279 //=================================================================================
280 // function : SelectionIntoArgument()
281 // purpose  : Called when selection
282 //=================================================================================
283 void RepairGUI_GlueDlg::SelectionIntoArgument()
284 {
285   if ( mySubShapesChk->isChecked() &&  getConstructorId() == 1 ) {
286     updateButtonState();
287     return;
288   }
289   
290   erasePreview();
291   myEditCurrentArgument->setText( "" );
292   myObject = GEOM::GEOM_Object::_nil();
293
294   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
295   SALOME_ListIO aSelList;
296   aSelMgr->selectedObjects(aSelList);
297
298   if ( aSelList.Extent() == 1 ) {
299     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
300     Standard_Boolean aRes;
301     myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
302     if ( aRes )
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         myNoteBook->setParameters(anObj, 1, myTolEdt);
420         objects.push_back( anObj._retn() );
421       }
422       break;
423     }
424   case 1:
425     {
426       if ( IsPreview() ) {
427         // if this method is used for displaying preview then we must detect glue faces only
428         ObjectList::iterator anIter;
429         for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
430           objects.push_back( GEOM::GEOM_Object::_duplicate( *anIter ) );
431         return myTmpObjs.size() ? true : false;
432       } // IsPreview
433
434       // Make glue face by list.
435       // Iterate through myTmpObjs and verifies where each object is currently selected or not.
436       QMap<QString, char> selected;
437
438       // Get names of selected objects
439       LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
440       SALOME_ListIO aSelList;
441       aSelMgr->selectedObjects(aSelList);
442
443       SALOME_ListIteratorOfListIO it (aSelList);
444       for (; it.More(); it.Next()) 
445         selected.insert(it.Value()->getName(), 0);
446
447       // Iterate through result and select objects with names from selection
448       // ObjectList toRemoveFromEnggine;
449       ObjectList toGlue;
450       ObjectList::iterator anIter;
451       for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter ) {
452         if ( selected.contains( myGeomGUI->getApp()->orb()->object_to_string(*anIter) ) )
453           toGlue.push_back( *anIter );
454       }
455       
456       // make glue faces
457       GEOM::ListOfGO_var aListForGlue = new GEOM::ListOfGO();
458       aListForGlue->length( toGlue.size() );
459       ObjectList::iterator anIter3 = toGlue.begin();
460       for ( int i = 0; anIter3 != toGlue.end(); ++anIter3, ++i )
461         aListForGlue[ i ] = *anIter3;
462       GEOM::GEOM_Object_var anObj = anOper->MakeGlueFacesByList( myObject, myTolEdt2->value(), aListForGlue, true );
463
464       aResult = !anObj->_is_nil();
465
466       if ( aResult )
467       {
468         if ( !IsPreview() )
469           myNoteBook->setParameters(anObj, 1, myTolEdt2);
470         objects.push_back( anObj._retn() );
471       }
472
473       // Remove from engine useless objects
474       clearTemporary();
475
476       updateButtonState();
477
478       break;
479     } // case 1
480   } // switch
481
482   return aResult;
483 }
484
485 //=================================================================================
486 // function : restoreSubShapes
487 // purpose  :
488 //=================================================================================
489 void RepairGUI_GlueDlg::restoreSubShapes( SALOMEDS::Study_ptr   theStudy,
490                                           SALOMEDS::SObject_ptr theSObject )
491 {
492   if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
493     GEOM::find_shape_method aFindMethod = GEOM::FSM_GetInPlace;
494     if ( getConstructorId() == 0 ) // MakeGlueFaces
495       aFindMethod = GEOM::FSM_GetInPlaceByHistory;
496
497     // empty list of arguments means that all arguments should be restored
498     getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
499                                          aFindMethod, /*theInheritFirstArg=*/true );
500   }
501 }
502
503 //================================================================
504 // Function : clearShapeBufferLocal
505 // Purpose  : 
506 //================================================================
507 void RepairGUI_GlueDlg::clearShapeBufferLocal( GEOM::GEOM_Object_ptr theObj )
508 {
509   if ( CORBA::is_nil( theObj ) )
510     return;
511
512   CORBA::String_var IOR = myGeomGUI->getApp()->orb()->object_to_string( theObj );
513   TCollection_AsciiString asciiIOR( (char *)( IOR.in() ) );
514   myGeomGUI->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );
515
516   if ( !getStudy() || !( getStudy()->studyDS() ) )
517     return;
518
519   _PTR(Study) aStudy = getStudy()->studyDS();
520   _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR.in() ) ) );
521   if ( !aSObj )
522     return;
523
524   _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
525   for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
526     _PTR(GenericAttribute) anAttr;
527     if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
528       _PTR(AttributeIOR) anIOR ( anAttr );
529       TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
530       myGeomGUI->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );      
531     }
532   }
533 }
534
535 //================================================================
536 // Function : onAccept
537 // Purpose  : This method should be called from dialog's slots onOk() and onApply()
538 //            It perfroms user input validation, then it 
539 //            performs a proper operation and manages transactions, etc.
540 //================================================================
541 bool RepairGUI_GlueDlg::onAcceptLocal()
542 {
543   if ( !getStudy() || !( getStudy()->studyDS() ) )
544     return false;
545
546   _PTR(Study) aStudy = getStudy()->studyDS();
547
548   bool aLocked = aStudy->GetProperties()->IsLocked();
549   if ( aLocked ) {
550     MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
551     SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), tr( "WRN_STUDY_LOCKED" ), tr( "BUT_OK" ) );
552     return false;
553   }
554
555   QString msg;
556   if ( !isValid( msg ) ) {
557     showError( msg );
558     return false;
559   }
560
561   erasePreview( false );
562
563   try {
564     if ( openCommand() ) {
565       SUIT_OverrideCursor wc;
566       
567       myGeomGUI->getApp()->putInfo( "" );
568       ObjectList objects;
569       
570       if ( !execute( objects ) ) { 
571         wc.suspend();
572         abortCommand();
573         showError();
574       }
575       else {
576         const int nbObjs = objects.size();
577         for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
578           QString aName = getNewObjectName();
579           if ( nbObjs > 1 ) {
580             if ( aName.isEmpty() )
581               aName = getPrefix( *it );
582             aName = GEOMBase::GetDefaultName( aName );
583           }
584           else {
585             // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
586             if ( aName.isEmpty() )
587               aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
588           }
589           addInStudy( *it, aName.toLatin1().data() );
590           display( *it, false );
591         }
592         
593         if ( nbObjs ) {
594           commitCommand();
595           updateObjBrowser();
596           myGeomGUI->getApp()->putInfo( QObject::tr("GEOM_PRP_DONE") );
597         }
598         else {
599           abortCommand();
600         }
601
602         // JFA 28.12.2004 BEGIN // To enable warnings
603         GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
604         if ( !CORBA::is_nil(anOper) && !anOper->IsDone() ) {
605           wc.suspend();
606           QString msgw = QObject::tr( anOper->GetErrorCode() );
607           SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), msgw, tr( "BUT_OK" ) );
608         }
609         // JFA 28.12.2004 END
610       }
611     }
612   }
613   catch( const SALOME::SALOME_Exception& e ) {
614     SalomeApp_Tools::QtCatchCorbaException( e );
615     abortCommand();
616   }
617
618   updateViewer();
619   activateSelection();
620   updateButtonState();
621
622   return true;
623 }
624
625
626 //=================================================================================
627 // function : onDetect
628 // purpose  :
629 //=================================================================================
630 void RepairGUI_GlueDlg::onDetect()
631 {
632   clearTemporary();
633   QString msg;
634   if ( !isValid( msg ) ) {
635     showError( msg );
636     return;
637   }
638
639   buttonOk()->setEnabled( false );
640   buttonApply()->setEnabled( false );
641   globalSelection( GEOM_ALLSHAPES );
642
643   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
644   GEOM::ListOfGO_var aList = anOper->GetGlueFaces( myObject, myTolEdt2->value() );
645   
646   for ( int i = 0, n = aList->length(); i < n; i++ ) 
647     myTmpObjs.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
648   
649   if ( myTmpObjs.size() > 0  ) {
650     msg = tr( "FACES_FOR_GLUING_ARE_DETECTED" ).arg( myTmpObjs.size() );
651     mySubShapesChk->setChecked( true );
652   }
653   else {
654     msg = tr( "THERE_ARE_NO_FACES_FOR_GLUING" );
655   }
656   
657   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
658            this, SLOT( SelectionIntoArgument() ) ) ;
659   SUIT_MessageBox::information( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg, tr( "Close" ) );
660   updateButtonState();
661   activateSelection();
662 }
663
664 //=================================================================================
665 // function : activateSelection
666 // purpose  : Redisplay preview and Activate selection
667 //=================================================================================
668 void RepairGUI_GlueDlg::activateSelection()
669 {
670   erasePreview( false );
671   
672   int anId = getConstructorId();
673   if ( anId == 0 )  { 
674     // Case of whole gluing
675     disconnect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
676                 this, SLOT( SelectionIntoArgument() ) );
677     
678     globalSelection( GEOM_ALLSHAPES );
679     if ( myObject->_is_nil()) 
680       SelectionIntoArgument();
681
682     connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
683              this, SLOT( SelectionIntoArgument() ) );
684   } 
685   else {
686     // Second case of gluing
687     if ( !mySubShapesChk->isChecked() ) 
688       globalSelection( GEOM_ALLSHAPES );
689     else {
690       displayPreview( true, false, false, 2/*line width*/, 1/*display mode*/, Quantity_NOC_RED );
691       disconnect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
692                   this, SLOT( SelectionIntoArgument() ) ) ;
693       globalSelection( GEOM_PREVIEW );
694       connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
695                this, SLOT( SelectionIntoArgument() ) ) ;
696     } 
697   }
698   updateViewer();
699 }
700
701 //=================================================================================
702 // function : updateButtonState
703 // purpose  : Update button state 
704 //=================================================================================
705 void RepairGUI_GlueDlg::updateButtonState()
706 {
707   int anId = getConstructorId();
708   bool hasMainObj = !myObject->_is_nil();
709   if ( anId == 0 ) {
710     buttonOk()->setEnabled( hasMainObj );
711     buttonApply()->setEnabled( hasMainObj );
712   }
713   else
714   {
715     LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
716     SALOME_ListIO aSelList;
717     aSelMgr->selectedObjects(aSelList);
718
719     bool wasSelected = false;
720     SALOME_ListIteratorOfListIO it (aSelList);
721     if (it.More() > 0)
722       wasSelected = true;
723     bool wasDetected = myTmpObjs.size() ? true : false;
724     buttonOk()->setEnabled( hasMainObj && wasDetected && wasSelected );
725     buttonApply()->setEnabled( hasMainObj && wasDetected && wasSelected );
726     mySubShapesChk->setEnabled( hasMainObj && wasDetected );
727     myDetectBtn->setEnabled( hasMainObj );
728     if ( !hasMainObj || !wasDetected )
729       mySubShapesChk->setChecked( false );
730   }
731 }
732
733 //=================================================================================
734 // function : clearTemporary
735 // purpose  : Remove temporary objects from engine
736 //=================================================================================
737 void RepairGUI_GlueDlg::clearTemporary()
738 {
739   ObjectList::iterator anIter;
740   for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
741     getGeomEngine()->RemoveObject(*anIter);
742
743   myTmpObjs.clear();
744 }
745
746 //=================================================================================
747 // function : onTolerChanged
748 // purpose  : Remove temporary objects from engine
749 //=================================================================================
750 void RepairGUI_GlueDlg::onTolerChanged( double /*theVal*/ )
751 {
752   clearTemporary();
753   activateSelection();
754   updateButtonState();
755 }
756
757 //=================================================================================
758 // function : onSubShapesChk
759 // purpose  : Update selection mode
760 //=================================================================================
761 void RepairGUI_GlueDlg::onSubShapesChk()
762 {
763   if ( !mySubShapesChk->isChecked() )
764     clearTemporary();
765   activateSelection();
766   updateButtonState();
767 }
768
769 //=================================================================================
770 // function : ClickOnCancel
771 // purpose  : Remove temporary objects from engine and call method of base class
772 //=================================================================================
773 void RepairGUI_GlueDlg::ClickOnCancel()
774 {
775   clearTemporary();
776   GEOMBase_Skeleton::ClickOnCancel();
777 }