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