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