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