]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_GlueDlg.cxx
Salome HOME
44277ab710b3ebd8cb94608deed8f510f5675d18
[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 // File   : RepairGUI_GlueDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S. 
24 //
25
26 #include "RepairGUI_GlueDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SalomeApp_Study.h>
35 #include <SalomeApp_Tools.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_Desktop.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_OverrideCursor.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SUIT_ViewWindow.h>
42 #include <SUIT_ViewManager.h>
43 #include <OCCViewer_ViewModel.h>
44 #include <SALOME_ListIteratorOfListIO.hxx>
45
46 #include <GEOMImpl_Types.hxx>
47
48 #include <TCollection_AsciiString.hxx>
49
50 #define DEFAULT_TOLERANCE_VALUE 1e-07
51
52 //=================================================================================
53 // class    : RepairGUI_GlueDlg()
54 // purpose  : Constructs a RepairGUI_GlueDlg  which is a child of 'parent', with the
55 //            name 'name' and widget flags set to 'f'.
56 //            The dialog will by default be modeless, unless you set 'modal' to
57 //            TRUE to construct a modal dialog.
58 //=================================================================================
59 RepairGUI_GlueDlg::RepairGUI_GlueDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
60                                       bool modal )
61   : GEOMBase_Skeleton( theGeometryGUI, parent, modal ),
62     myCurrConstrId( -1 )
63 {
64   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_GLUE_FACES" ) ) );
65   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_GLUE_FACES2" )  ));
66   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
67
68   setWindowTitle( tr( "GEOM_GLUE_TITLE" ) );
69
70   /***************************************************************/
71   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_GLUE_TITLE" ) );
72   mainFrame()->RadioButton1->setIcon( image0 );
73   mainFrame()->RadioButton2->setIcon( image2 );
74   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
75   mainFrame()->RadioButton3->close();
76
77   GroupPoints = new DlgRef_1SelExt( centralWidget() );
78   GroupPoints->GroupBox1->setTitle( tr( "GEOM_GLUE" ) );
79   GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
80   GroupPoints->PushButton1->setIcon( image1 );
81   GroupPoints->LineEdit1->setReadOnly( true );
82   
83   QLabel* aTolLab = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->Box );
84   myTolEdt = new QDoubleSpinBox( GroupPoints->Box );
85   initSpinBox( myTolEdt,  0, 100, 1e-7, 10 );
86   myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
87
88   QGridLayout* boxLayout = new QGridLayout( GroupPoints->Box );
89   boxLayout->setMargin( 0 ); boxLayout->setSpacing( 6 );
90   boxLayout->addWidget( aTolLab,  0, 0 );
91   boxLayout->addWidget( myTolEdt, 0, 2 );
92   /***************************************************************/
93
94   GroupPoints2 = new DlgRef_1SelExt( centralWidget() );
95   GroupPoints2->GroupBox1->setTitle( tr( "GEOM_GLUE" ) );
96   GroupPoints2->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
97   GroupPoints2->PushButton1->setIcon( image1 );
98   GroupPoints2->LineEdit1->setReadOnly( true );
99
100   QLabel* aTolLab2 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints2->Box );
101   myTolEdt2 = new QDoubleSpinBox( GroupPoints2->Box );
102   initSpinBox( myTolEdt2, 0, 100, 1e-7, 10 );
103   myTolEdt2->setValue( DEFAULT_TOLERANCE_VALUE );
104
105   myDetectBtn = new QPushButton( tr( "GEOM_DETECT" ) + QString( " [%1]" ).arg( tr( "GLUE_FACES" ) ), 
106                                  GroupPoints2->Box );
107   mySubShapesChk = new QCheckBox( tr( "SELECT_FACES" ), GroupPoints2->Box );
108
109   boxLayout = new QGridLayout( GroupPoints2->Box );
110   boxLayout->setMargin( 0 ); boxLayout->setSpacing( 6 );
111   boxLayout->addWidget( aTolLab2,    0, 0 );
112   boxLayout->addWidget( myTolEdt2,   0, 2 );
113   boxLayout->addWidget( myDetectBtn, 1, 0, 1, 3 );
114   boxLayout->addWidget( mySubShapesChk, 2, 0, 1, 3 );
115
116   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
117   layout->setMargin( 0 ); layout->setSpacing( 6 );
118   layout->addWidget( GroupPoints );
119   layout->addWidget( GroupPoints2 );
120
121   /***************************************************************/
122
123   setHelpFileName( "glue_faces_operation_page.html" );
124   
125   // Disable second way of gluing if OCC viewer is not active one
126   if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() 
127        != OCCViewer_Viewer::Type() )
128     mainFrame()->RadioButton2->setEnabled( false );
129
130   Init();
131 }
132
133
134 //=================================================================================
135 // function : ~RepairGUI_GlueDlg()
136 // purpose  : Destroys the object and frees any allocated resources
137 //=================================================================================
138 RepairGUI_GlueDlg::~RepairGUI_GlueDlg()
139 {
140 }
141
142
143 //=================================================================================
144 // function : Init()
145 // purpose  :
146 //=================================================================================
147 void RepairGUI_GlueDlg::Init()
148 {
149   /* init variables */
150   myEditCurrentArgument = GroupPoints->LineEdit1;
151
152   myObject = GEOM::GEOM_Object::_nil();
153
154   //myGeomGUI->SetState( 0 );
155   //globalSelection( GEOM_COMPOUND );
156
157   /* signals and slots connections */
158   connect( buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
159   connect( buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
160
161   connect( this,          SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
162
163   connect( GroupPoints->PushButton1,  SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
164   connect( GroupPoints->LineEdit1,    SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
165
166   connect( GroupPoints2->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
167   connect( GroupPoints2->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
168   connect( myTolEdt2, SIGNAL( valueChanged( double ) ), this, SLOT( onTolerChanged( double ) ) );
169   connect( mySubShapesChk, SIGNAL( stateChanged( int ) ), this, SLOT( onSubShapesChk() ) );
170
171   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
172            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
173
174   connect( myDetectBtn, SIGNAL( clicked() ), this, SLOT( onDetect() ) );
175
176   initName( tr( "GLUE_NEW_OBJ_NAME" ) );
177
178   ConstructorsClicked( 0 );
179   
180   activateSelection();
181   updateButtonState();
182 }
183
184
185 //=================================================================================
186 // function : ConstructorsClicked()
187 // purpose  : Radio button management
188 //=================================================================================
189 void RepairGUI_GlueDlg::ConstructorsClicked( int constructorId )
190 {
191   if ( myCurrConstrId == constructorId )
192     return;
193   
194   disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
195   
196   switch ( constructorId ) {
197   case 0:
198     GroupPoints2->hide();
199     GroupPoints->show();
200     GroupPoints->LineEdit1->setText( "" );
201     myEditCurrentArgument = GroupPoints->LineEdit1;
202     
203     if ( myCurrConstrId >= 0 ) {
204       // i.e. it is not initialisation
205       // copy tolerance from previous tolerance field
206       myTolEdt->setValue( myTolEdt2->value() );
207     }
208     break;
209   case 1:
210     GroupPoints->hide();
211     GroupPoints2->show();
212     GroupPoints->LineEdit1->setText( "" );
213     myEditCurrentArgument = GroupPoints2->LineEdit1;
214         
215     if ( myCurrConstrId >= 0 ) {
216       // i.e. it is not initialisation
217       // copy tolerance from previous tolerance field
218       myTolEdt2->setValue( myTolEdt->value() );
219       mySubShapesChk->setChecked( false );
220       clearTemporary();
221     }
222     break;
223   }
224     
225   myCurrConstrId = constructorId;
226
227   myEditCurrentArgument->setFocus();
228
229   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
230            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
231
232   qApp->processEvents();
233   updateGeometry();
234   resize( minimumSize() );
235
236   displayPreview();
237   updateButtonState();
238   activateSelection();
239   SelectionIntoArgument();
240 }
241
242
243 //=================================================================================
244 // function : ClickOnOk()
245 // purpose  : Same than click on apply but close this dialog.
246 //=================================================================================
247 void RepairGUI_GlueDlg::ClickOnOk()
248 {
249   if ( ClickOnApply() )
250     ClickOnCancel();
251 }
252
253
254 //=================================================================================
255 // function : ClickOnApply()
256 // purpose  :
257 //=================================================================================
258 bool RepairGUI_GlueDlg::ClickOnApply()
259 {
260   if ( !onAcceptLocal() )
261     return false;
262
263   initName();
264
265   //GroupPoints->LineEdit1->setText("");
266   //myObject = GEOM::GEOM_Object::_nil();
267
268   //globalSelection( GEOM_COMPOUND );
269
270   ConstructorsClicked( getConstructorId() );
271
272   return true;
273 }
274
275
276 //=================================================================================
277 // function : SelectionIntoArgument()
278 // purpose  : Called when selection
279 //=================================================================================
280 void RepairGUI_GlueDlg::SelectionIntoArgument()
281 {
282   if ( mySubShapesChk->isChecked() &&  getConstructorId() == 1 ) {
283     updateButtonState();
284     return;
285   }
286   
287   erasePreview();
288   myEditCurrentArgument->setText( "" );
289   myObject = GEOM::GEOM_Object::_nil();
290
291   if ( IObjectCount() == 1 ) {
292     Handle(SALOME_InteractiveObject) anIO = firstIObject();
293     Standard_Boolean aRes;
294     myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
295     if ( aRes )
296       myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
297   }
298   updateButtonState();
299 }
300
301 //=================================================================================
302 // function : SetEditCurrentArgument()
303 // purpose  :
304 //=================================================================================
305 void RepairGUI_GlueDlg::SetEditCurrentArgument()
306 {
307   const QObject* send = sender();
308   if ( send == GroupPoints->PushButton1 || send == GroupPoints2->PushButton1 )  {
309     myEditCurrentArgument->setFocus();
310     SelectionIntoArgument();
311   }
312 }
313
314
315 //=================================================================================
316 // function : LineEditReturnPressed()
317 // purpose  :
318 //=================================================================================
319 void RepairGUI_GlueDlg::LineEditReturnPressed()
320 {
321   const QObject* send = sender();
322   if ( send == GroupPoints->LineEdit1 ) {
323     myEditCurrentArgument = GroupPoints->LineEdit1;
324     GEOMBase_Skeleton::LineEditReturnPressed();
325   }
326   else if ( send == GroupPoints2->LineEdit1 ) {
327     myEditCurrentArgument = GroupPoints2->LineEdit1;
328     GEOMBase_Skeleton::LineEditReturnPressed();
329   }
330 }
331
332
333 //=================================================================================
334 // function : ActivateThisDialog()
335 // purpose  :
336 //=================================================================================
337 void RepairGUI_GlueDlg::ActivateThisDialog()
338 {
339   GEOMBase_Skeleton::ActivateThisDialog();
340   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
341            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
342
343   //GroupPoints->LineEdit1->setText("");
344   //GroupPoints2->LineEdit1->setText("");
345   //myObject = GEOM::GEOM_Object::_nil();
346
347   //myGeomGUI->SetState( 0 );
348   //globalSelection( GEOM_COMPOUND );
349   activateSelection();
350 }
351
352
353 //=================================================================================
354 // function : enterEvent()
355 // purpose  : Mouse enter onto the dialog to activate it
356 //=================================================================================
357 void RepairGUI_GlueDlg::enterEvent( QEvent* )
358 {
359   if ( !mainFrame()->GroupConstructors->isEnabled() )
360     ActivateThisDialog();
361 }
362
363
364 //=================================================================================
365 // function : createOperation
366 // purpose  :
367 //=================================================================================
368 GEOM::GEOM_IOperations_ptr RepairGUI_GlueDlg::createOperation()
369 {
370   return getGeomEngine()->GetIShapesOperations( getStudyId() );
371 }
372
373 //=================================================================================
374 // function : isValid
375 // purpose  :
376 //=================================================================================
377 bool RepairGUI_GlueDlg::isValid( QString& )
378 {
379   return !myObject->_is_nil() && ( IsPreview() || myTolEdt->value() > 0. );
380 }
381
382 //=================================================================================
383 // function : execute
384 // purpose  :
385 //=================================================================================
386 bool RepairGUI_GlueDlg::execute( ObjectList& objects )
387 {
388   bool aResult = false;
389   objects.clear();
390
391   switch ( getConstructorId() ) {
392   case 0:
393     {
394       GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow
395         ( getOperation() )->MakeGlueFaces( myObject, myTolEdt2->value(), true );
396       aResult = !anObj->_is_nil();
397       if ( aResult )
398         objects.push_back( anObj._retn() );
399       break;
400     }
401   case 1:
402     {
403       if ( IsPreview() ) {
404         // if this method is used for displaying preview then we must detect glue faces only
405         ObjectList::iterator anIter;
406         for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
407           objects.push_back( GEOM::GEOM_Object::_duplicate( *anIter ) );
408         return myTmpObjs.size() ? true : false;
409       } // IsPreview
410
411       // Make glue face by list.
412       // Iterate through myTmpObjs and verifies where each object is currently selected or not.
413       QMap<QString, char> selected;
414
415       // Get names of selected objects
416       SALOME_ListIteratorOfListIO it ( selectedIO() );
417       for ( ; it.More(); it.Next() ) 
418         selected.insert( it.Value()->getName(), 0 );
419
420       // Iterate through result and select objects with names from selection
421       // ObjectList toRemoveFromEnggine;
422       ObjectList toGlue;
423       ObjectList::iterator anIter;
424       for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter ) {
425         if ( selected.contains( myGeomGUI->getApp()->orb()->object_to_string(*anIter) ) )
426           toGlue.push_back( *anIter );
427       }
428       
429       // make glue faces
430       GEOM::ListOfGO_var aListForGlue = new GEOM::ListOfGO();
431       aListForGlue->length( toGlue.size() );
432       ObjectList::iterator anIter3 = toGlue.begin();
433       for ( int i = 0; anIter3 != toGlue.end(); ++anIter3, ++i )
434         aListForGlue[ i ] = *anIter3;
435       GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow
436         ( getOperation() )->MakeGlueFacesByList( myObject, myTolEdt2->value(), aListForGlue, true );
437
438       aResult = !anObj->_is_nil();
439
440       if ( aResult )
441         objects.push_back( anObj._retn() );
442
443       // Remove from engine useless objects
444       clearTemporary();
445
446       updateButtonState();
447
448       break;
449     } // case 1
450   } // switch
451
452   return aResult;
453 }
454
455
456 //================================================================
457 // Function : clearShapeBufferLocal
458 // Purpose  : 
459 //================================================================
460 void RepairGUI_GlueDlg::clearShapeBufferLocal( GEOM::GEOM_Object_ptr theObj )
461 {
462   if ( CORBA::is_nil( theObj ) )
463     return;
464
465   CORBA::String_var IOR = myGeomGUI->getApp()->orb()->object_to_string( theObj );
466   TCollection_AsciiString asciiIOR( (char *)( IOR.in() ) );
467   myGeomGUI->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );
468
469   if ( !getStudy() || !( getStudy()->studyDS() ) )
470     return;
471
472   _PTR(Study) aStudy = getStudy()->studyDS();
473   _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR.in() ) ) );
474   if ( !aSObj )
475     return;
476
477   _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
478   for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
479     _PTR(GenericAttribute) anAttr;
480     if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
481       _PTR(AttributeIOR) anIOR ( anAttr );
482       TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
483       myGeomGUI->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );      
484     }
485   }
486 }
487
488 //================================================================
489 // Function : onAccept
490 // Purpose  : This method should be called from dialog's slots onOk() and onApply()
491 //            It perfroms user input validation, then it 
492 //            performs a proper operation and manages transactions, etc.
493 //================================================================
494 bool RepairGUI_GlueDlg::onAcceptLocal()
495 {
496   if ( !getStudy() || !( getStudy()->studyDS() ) )
497     return false;
498
499   _PTR(Study) aStudy = getStudy()->studyDS();
500
501   bool aLocked = aStudy->GetProperties()->IsLocked();
502   if ( aLocked ) {
503     MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
504     SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), tr( "WRN_STUDY_LOCKED" ), tr( "BUT_OK" ) );
505     return false;
506   }
507
508   QString msg;
509   if ( !isValid( msg ) ) {
510     showError( msg );
511     return false;
512   }
513
514   erasePreview( false );
515
516   try {
517     if ( openCommand() ) {
518       SUIT_OverrideCursor wc;
519       
520       SUIT_Session::session()->activeApplication()->putInfo( "" );
521       ObjectList objects;
522       
523       if ( !execute( objects ) ) { 
524         wc.suspend();
525         abortCommand();
526         showError();
527       }
528       else {
529         const int nbObjs = objects.size();
530         bool withChildren = false;
531         for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
532           QString aName( "" );
533           if ( nbObjs > 1 ) {
534             aName = strlen( getNewObjectName() ) ? GEOMBase::GetDefaultName( getNewObjectName() ) : GEOMBase::GetDefaultName( getPrefix( *it ) );
535           }
536           else {
537             aName = getNewObjectName();
538             // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
539             if ( aName.isEmpty() )
540               aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
541           }
542           addInStudy( *it, aName.toLatin1().data() );
543           withChildren = false;
544           display( *it, false );
545         }
546         
547         if ( nbObjs ) {
548           commitCommand();
549           updateObjBrowser();
550           SUIT_Session::session()->activeApplication()->putInfo( tr( "GEOM_PRP_DONE" ) );
551         }
552         else {
553           abortCommand();
554         }
555
556         // JFA 28.12.2004 BEGIN // To enable warnings
557         if ( !getOperation()->_is_nil() ) {
558           if ( !getOperation()->IsDone() ) {
559             wc.suspend();
560             QString msgw = QObject::tr( getOperation()->GetErrorCode() );
561             SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), msgw, tr( "BUT_OK" ) );
562           }
563         }
564         // JFA 28.12.2004 END
565       }
566     }
567   }
568   catch( const SALOME::SALOME_Exception& e ) {
569     SalomeApp_Tools::QtCatchCorbaException( e );
570     abortCommand();
571   }
572
573   updateViewer();
574   activateSelection();
575   updateButtonState();
576
577   return true;
578 }
579
580
581 //=================================================================================
582 // function : onDetect
583 // purpose  :
584 //=================================================================================
585 void RepairGUI_GlueDlg::onDetect()
586 {
587   clearTemporary();
588   QString msg;
589   if ( !isValid( msg ) ) {
590     showError( msg );
591     return;
592   }
593
594   GEOM::ListOfGO_var aList = GEOM::GEOM_IShapesOperations::_narrow
595     ( getOperation() )->GetGlueFaces( myObject, myTolEdt2->value() );
596   
597   for ( int i = 0, n = aList->length(); i < n; i++ ) 
598     myTmpObjs.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
599   
600   if ( myTmpObjs.size() > 0  ) {
601     msg = tr( "FACES_FOR_GLUING_ARE_DETECTED" ).arg( myTmpObjs.size() );
602     mySubShapesChk->setChecked( true );
603   }
604   else {
605     msg = tr( "THERE_ARE_NO_FACES_FOR_GLUING" );
606   }
607   
608   connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
609            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()) ) ;
610   SUIT_MessageBox::information( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg, tr( "Close" ) );
611   updateButtonState();
612   activateSelection();
613 }
614
615 //=================================================================================
616 // function : activateSelection
617 // purpose  : Redisplay preview and Activate selection
618 //=================================================================================
619 void RepairGUI_GlueDlg::activateSelection()
620 {
621   erasePreview( false );
622   
623   int anId = getConstructorId();
624   if ( anId == 0 )  { 
625     // Case of whole gluing
626     disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
627                 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
628     
629     globalSelection( GEOM_ALLSHAPES );
630     if ( myObject->_is_nil()) 
631       SelectionIntoArgument();
632
633     connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
634              SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
635   } 
636   else {
637     // Second case of gluing
638     if ( !mySubShapesChk->isChecked() ) 
639       globalSelection( GEOM_ALLSHAPES );
640     else {
641       displayPreview( true, false, false, 2/*line width*/, 1/*display mode*/, Quantity_NOC_RED );
642       disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
643                   SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ) ;
644       globalSelection( GEOM_PREVIEW );
645       connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
646                SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ) ;
647     } 
648   }
649   updateViewer();
650 }
651
652 //=================================================================================
653 // function : updateButtonState
654 // purpose  : Update button state 
655 //=================================================================================
656 void RepairGUI_GlueDlg::updateButtonState()
657 {
658   int anId = getConstructorId();
659   bool hasMainObj = !myObject->_is_nil();
660   if ( anId == 0 ) {
661     buttonOk()->setEnabled( hasMainObj );
662     buttonApply()->setEnabled( hasMainObj );
663   }
664   else
665   {
666     bool wasSelected = false;
667     SALOME_ListIteratorOfListIO it ( selectedIO() );
668     if (it.More() > 0)
669       wasSelected = true;
670     bool wasDetected = myTmpObjs.size() ? true : false;
671     buttonOk()->setEnabled( hasMainObj && wasDetected && wasSelected );
672     buttonApply()->setEnabled( hasMainObj && wasDetected && wasSelected );
673     mySubShapesChk->setEnabled( hasMainObj && wasDetected );
674     myDetectBtn->setEnabled( hasMainObj );
675     if ( !hasMainObj || !wasDetected )
676       mySubShapesChk->setChecked( false );
677   }
678 }
679
680 //=================================================================================
681 // function : clearTemporary
682 // purpose  : Remove temporary objects from engine
683 //=================================================================================
684 void RepairGUI_GlueDlg::clearTemporary()
685 {
686   ObjectList::iterator anIter;
687   for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
688     getGeomEngine()->RemoveObject(*anIter);
689
690   myTmpObjs.clear();
691 }
692
693 //=================================================================================
694 // function : onTolerChanged
695 // purpose  : Remove temporary objects from engine
696 //=================================================================================
697 void RepairGUI_GlueDlg::onTolerChanged( double /*theVal*/ )
698 {
699   clearTemporary();
700   activateSelection();
701   updateButtonState();
702 }
703
704 //=================================================================================
705 // function : onSubShapesChk
706 // purpose  : Update selection mode
707 //=================================================================================
708 void RepairGUI_GlueDlg::onSubShapesChk()
709 {
710   if ( !mySubShapesChk->isChecked() )
711     clearTemporary();
712   activateSelection();
713   updateButtonState();
714 }
715
716 //=================================================================================
717 // function : ClickOnCancel
718 // purpose  : Remove temporary objects from engine and call method of base class
719 //=================================================================================
720 void RepairGUI_GlueDlg::ClickOnCancel()
721 {
722   clearTemporary();
723   GEOMBase_Skeleton::ClickOnCancel();
724 }
725
726 //================================================================
727 // Function : getEntry
728 // Purpose  :
729 //================================================================
730 static std::string getEntry( GEOM::GEOM_Object_ptr object )
731 {
732   SUIT_Session* session = SUIT_Session::session();
733   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
734   if ( app ) {
735     std::string IOR = app->orb()->object_to_string( object );
736     if ( IOR != "" ) {
737       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
738       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
739       if ( SO )
740         return SO->GetID();
741     }
742   }
743   return "";
744 }
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761