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