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