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