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