]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_LimitToleranceDlg.cxx
Salome HOME
IMPs 0020745 (GetVertexNearPoint and GetShapesNearPoint) and 0020851 (LimitTolerance).
[modules/geom.git] / src / RepairGUI / RepairGUI_LimitToleranceDlg.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  GEOM RepairGUI : GUI for Geometry component
23 //  File   : RepairGUI_LimitToleranceDlg.cxx
24
25 #include "RepairGUI_LimitToleranceDlg.h"
26
27 #include <DlgRef.h>
28 #include <GeometryGUI.h>
29 #include <GEOMBase.h>
30 #include <SalomeApp_DoubleSpinBox.h>
31
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SalomeApp_Study.h>
35 #include <SalomeApp_Tools.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_Desktop.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_OverrideCursor.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SUIT_ViewWindow.h>
42 #include <SUIT_ViewManager.h>
43 #include <OCCViewer_ViewModel.h>
44 #include <SALOME_ListIteratorOfListIO.hxx>
45
46 #include <GEOMImpl_Types.hxx>
47
48 #include <TCollection_AsciiString.hxx>
49
50 #define DEFAULT_TOLERANCE_VALUE 1e-07
51
52 //=================================================================================
53 // class    : RepairGUI_LimitToleranceDlg()
54 // purpose  : Constructs a RepairGUI_LimitToleranceDlg  which is a child of 'parent', with the
55 //            name 'name' and widget flags set to 'f'.
56 //            The dialog will by default be modeless, unless you set 'modal' to
57 //            TRUE to construct a modal dialog.
58 //=================================================================================
59 RepairGUI_LimitToleranceDlg::RepairGUI_LimitToleranceDlg(GeometryGUI* theGeometryGUI,
60                                                          QWidget* parent, bool modal)
61   : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
62 {
63   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_LIMIT_TOLERANCE")));
64   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
65
66   setWindowTitle(tr("GEOM_LIMIT_TOLERANCE_TITLE"));
67
68   /***************************************************************/
69   mainFrame()->GroupConstructors->setTitle(tr("GEOM_LIMIT_TOLERANCE_TITLE"));
70   mainFrame()->RadioButton1->setIcon(image0);
71   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
72   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
73   mainFrame()->RadioButton2->close();
74   mainFrame()->RadioButton3->close();
75
76   GroupPoints = new DlgRef_1SelExt(centralWidget());
77   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
78   GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
79   GroupPoints->PushButton1->setIcon(image1);
80   GroupPoints->LineEdit1->setReadOnly(true);
81
82   QLabel* aTolLab = new QLabel(tr("GEOM_TOLERANCE"), GroupPoints->Box);
83   myTolEdt = new SalomeApp_DoubleSpinBox(GroupPoints->Box);
84   initSpinBox(myTolEdt, 0., 100., DEFAULT_TOLERANCE_VALUE, "len_tol_precision");
85   myTolEdt->setValue(DEFAULT_TOLERANCE_VALUE);
86
87   QGridLayout* boxLayout = new QGridLayout(GroupPoints->Box);
88   boxLayout->setMargin(0); boxLayout->setSpacing(6);
89   boxLayout->addWidget(aTolLab,  0, 0);
90   boxLayout->addWidget(myTolEdt, 0, 2);
91
92   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
93   layout->setMargin(0); layout->setSpacing(6);
94   layout->addWidget(GroupPoints);
95
96   setHelpFileName("limit_tolerance_operation_page.html");
97
98   Init();
99 }
100
101
102 //=================================================================================
103 // function : ~RepairGUI_LimitToleranceDlg()
104 // purpose  : Destroys the object and frees any allocated resources
105 //=================================================================================
106 RepairGUI_LimitToleranceDlg::~RepairGUI_LimitToleranceDlg()
107 {
108 }
109
110
111 //=================================================================================
112 // function : Init()
113 // purpose  :
114 //=================================================================================
115 void RepairGUI_LimitToleranceDlg::Init()
116 {
117   /* init variables */
118   myEditCurrentArgument = GroupPoints->LineEdit1;
119
120   myObject = GEOM::GEOM_Object::_nil();
121
122   //myGeomGUI->SetState(0);
123   //globalSelection(GEOM_COMPOUND);
124
125   mainFrame()->GroupBoxPublish->show();
126
127   /* signals and slots connections */
128   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
129   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
130
131   connect(GroupPoints->PushButton1,  SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
132   connect(GroupPoints->LineEdit1,    SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
133
134   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
135           this, SLOT(SelectionIntoArgument()));
136
137   initName(tr("LIMIT_TOLERANCE_NEW_OBJ_NAME"));
138
139   ConstructorsClicked(0);
140
141   activateSelection();
142   updateButtonState();
143 }
144
145
146 //=================================================================================
147 // function : ConstructorsClicked()
148 // purpose  : Radio button management
149 //=================================================================================
150 void RepairGUI_LimitToleranceDlg::ConstructorsClicked(int constructorId)
151 {
152   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
153
154   GroupPoints->show();
155   GroupPoints->LineEdit1->setText("");
156   myEditCurrentArgument = GroupPoints->LineEdit1;
157   myEditCurrentArgument->setFocus();
158
159   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
160            this, SLOT(SelectionIntoArgument()));
161
162   qApp->processEvents();
163   updateGeometry();
164   resize(minimumSizeHint());
165
166   updateButtonState();
167   activateSelection();
168   SelectionIntoArgument();
169 }
170
171
172 //=================================================================================
173 // function : ClickOnOk()
174 // purpose  : Same than click on apply but close this dialog.
175 //=================================================================================
176 void RepairGUI_LimitToleranceDlg::ClickOnOk()
177 {
178   if (ClickOnApply())
179     ClickOnCancel();
180 }
181
182 //=================================================================================
183 // function : ClickOnApply()
184 // purpose  :
185 //=================================================================================
186 bool RepairGUI_LimitToleranceDlg::ClickOnApply()
187 {
188   if (!onAcceptLocal())
189     return false;
190
191   initName();
192
193   ConstructorsClicked(0);
194
195   return true;
196 }
197
198 //=================================================================================
199 // function : SelectionIntoArgument()
200 // purpose  : Called when selection
201 //=================================================================================
202 void RepairGUI_LimitToleranceDlg::SelectionIntoArgument()
203 {
204   myEditCurrentArgument->setText("");
205   myObject = GEOM::GEOM_Object::_nil();
206
207   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
208   SALOME_ListIO aSelList;
209   aSelMgr->selectedObjects(aSelList);
210
211   if (aSelList.Extent() == 1) {
212     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
213     Standard_Boolean aRes;
214     myObject = GEOMBase::ConvertIOinGEOMObject(anIO, aRes);
215     if (aRes)
216       myEditCurrentArgument->setText(GEOMBase::GetName(myObject));
217   }
218   updateButtonState();
219 }
220
221 //=================================================================================
222 // function : SetEditCurrentArgument()
223 // purpose  :
224 //=================================================================================
225 void RepairGUI_LimitToleranceDlg::SetEditCurrentArgument()
226 {
227   const QObject* send = sender();
228   if (send == GroupPoints->PushButton1)  {
229     myEditCurrentArgument->setFocus();
230     SelectionIntoArgument();
231   }
232 }
233
234 //=================================================================================
235 // function : LineEditReturnPressed()
236 // purpose  :
237 //=================================================================================
238 void RepairGUI_LimitToleranceDlg::LineEditReturnPressed()
239 {
240   const QObject* send = sender();
241   if (send == GroupPoints->LineEdit1) {
242     myEditCurrentArgument = GroupPoints->LineEdit1;
243     GEOMBase_Skeleton::LineEditReturnPressed();
244   }
245 }
246
247 //=================================================================================
248 // function : ActivateThisDialog()
249 // purpose  :
250 //=================================================================================
251 void RepairGUI_LimitToleranceDlg::ActivateThisDialog()
252 {
253   GEOMBase_Skeleton::ActivateThisDialog();
254   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
255            this, SLOT(SelectionIntoArgument()));
256   activateSelection();
257 }
258
259 //=================================================================================
260 // function : enterEvent()
261 // purpose  : Mouse enter onto the dialog to activate it
262 //=================================================================================
263 void RepairGUI_LimitToleranceDlg::enterEvent(QEvent*)
264 {
265   if (!mainFrame()->GroupConstructors->isEnabled())
266     ActivateThisDialog();
267 }
268
269 //=================================================================================
270 // function : createOperation
271 // purpose  :
272 //=================================================================================
273 GEOM::GEOM_IOperations_ptr RepairGUI_LimitToleranceDlg::createOperation()
274 {
275   return getGeomEngine()->GetIHealingOperations(getStudyId());
276 }
277
278 //=================================================================================
279 // function : isValid
280 // purpose  :
281 //=================================================================================
282 bool RepairGUI_LimitToleranceDlg::isValid(QString& msg)
283 {
284   double v = myTolEdt->value();
285   bool ok = myTolEdt->isValid(msg, true);
286   return !myObject->_is_nil() && (v > 0.) && ok;
287 }
288
289 //=================================================================================
290 // function : execute
291 // purpose  :
292 //=================================================================================
293 bool RepairGUI_LimitToleranceDlg::execute(ObjectList& objects)
294 {
295   bool aResult = false;
296   objects.clear();
297
298   GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
299   GEOM::GEOM_Object_var anObj = anOper->LimitTolerance(myObject, myTolEdt->value());
300   aResult = !anObj->_is_nil();
301   if (aResult) {
302     QStringList aParameters;
303     aParameters << myTolEdt->text();
304     anObj->SetParameters(aParameters.join(":").toLatin1().constData());
305     objects.push_back(anObj._retn());
306   }
307
308   return aResult;
309 }
310
311 //================================================================
312 // Function : onAccept
313 // Purpose  : This method should be called from dialog's slots onOk() and onApply()
314 //            It perfroms user input validation, then it
315 //            performs a proper operation and manages transactions, etc.
316 //================================================================
317 bool RepairGUI_LimitToleranceDlg::onAcceptLocal()
318 {
319   if (!getStudy() || !(getStudy()->studyDS()))
320     return false;
321
322   _PTR(Study) aStudy = getStudy()->studyDS();
323
324   bool aLocked = aStudy->GetProperties()->IsLocked();
325   if (aLocked) {
326     MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
327     SUIT_MessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"), tr("BUT_OK"));
328     return false;
329   }
330
331   QString msg;
332   if (!isValid(msg)) {
333     showError(msg);
334     return false;
335   }
336
337   try {
338     if (openCommand()) {
339       SUIT_OverrideCursor wc;
340
341       myGeomGUI->getApp()->putInfo("");
342       ObjectList objects;
343
344       if (!execute(objects)) {
345         wc.suspend();
346         abortCommand();
347         showError();
348       }
349       else {
350         const int nbObjs = objects.size();
351         for (ObjectList::iterator it = objects.begin(); it != objects.end(); ++it) {
352           QString aName = getNewObjectName();
353           if (nbObjs > 1) {
354             if (aName.isEmpty())
355               aName = getPrefix(*it);
356             aName = GEOMBase::GetDefaultName(aName);
357           }
358           else {
359             // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
360             if (aName.isEmpty())
361               aName = GEOMBase::GetDefaultName(getPrefix(*it));
362           }
363           addInStudy(*it, aName.toLatin1().data());
364           display(*it, false);
365         }
366
367         if (nbObjs) {
368           commitCommand();
369           updateObjBrowser();
370           myGeomGUI->getApp()->putInfo(QObject::tr("GEOM_PRP_DONE"));
371         }
372         else {
373           abortCommand();
374         }
375
376         // JFA 28.12.2004 BEGIN // To enable warnings
377         GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
378         if (!CORBA::is_nil(anOper) && !anOper->IsDone()) {
379           wc.suspend();
380           QString msgw = QObject::tr(anOper->GetErrorCode());
381           SUIT_MessageBox::warning(this, tr("WRN_WARNING"), msgw, tr("BUT_OK"));
382         }
383         // JFA 28.12.2004 END
384       }
385     }
386   }
387   catch(const SALOME::SALOME_Exception& e) {
388     SalomeApp_Tools::QtCatchCorbaException(e);
389     abortCommand();
390   }
391
392   updateViewer();
393   activateSelection();
394   updateButtonState();
395
396   return true;
397 }
398
399 //=================================================================================
400 // function : activateSelection
401 // purpose  : Activate selection
402 //=================================================================================
403 void RepairGUI_LimitToleranceDlg::activateSelection()
404 {
405   disconnect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
406              this, SLOT(SelectionIntoArgument()));
407
408   globalSelection(GEOM_ALLSHAPES);
409   if (myObject->_is_nil())
410     SelectionIntoArgument();
411
412   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
413           this, SLOT(SelectionIntoArgument()));
414   updateViewer();
415 }
416
417 //=================================================================================
418 // function : updateButtonState
419 // purpose  : Update button state
420 //=================================================================================
421 void RepairGUI_LimitToleranceDlg::updateButtonState()
422 {
423   bool hasMainObj = !myObject->_is_nil();
424   buttonOk()->setEnabled(hasMainObj);
425   buttonApply()->setEnabled(hasMainObj);
426 }
427
428 //=================================================================================
429 // function : restoreSubShapes
430 // purpose  :
431 //=================================================================================
432 void RepairGUI_LimitToleranceDlg::restoreSubShapes(SALOMEDS::Study_ptr   theStudy,
433                                                    SALOMEDS::SObject_ptr theSObject)
434 {
435   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
436     // empty list of arguments means that all arguments should be restored
437     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
438                                         GEOM::FSM_GetInPlace, /*theInheritFirstArg=*/true,
439                                         mainFrame()->CheckBoxAddPrefix->isChecked());
440   }
441 }