1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : RepairGUI_LimitToleranceDlg.cxx
24 #include "RepairGUI_LimitToleranceDlg.h"
27 #include <GeometryGUI.h>
29 #include <SalomeApp_DoubleSpinBox.h>
31 #include <SalomeApp_Application.h>
32 #include <LightApp_SelectionMgr.h>
33 #include <SalomeApp_Study.h>
34 #include <SalomeApp_Tools.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_Desktop.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_OverrideCursor.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_ViewWindow.h>
41 #include <SUIT_ViewManager.h>
42 #include <OCCViewer_ViewModel.h>
43 #include <SALOME_ListIteratorOfListIO.hxx>
45 #include <GEOMImpl_Types.hxx>
47 #include <TCollection_AsciiString.hxx>
49 #define DEFAULT_TOLERANCE_VALUE 1e-07
51 //=================================================================================
52 // class : RepairGUI_LimitToleranceDlg()
53 // purpose : Constructs a RepairGUI_LimitToleranceDlg which is a child of 'parent', with the
54 // name 'name' and widget flags set to 'f'.
55 // The dialog will by default be modeless, unless you set 'modal' to
56 // TRUE to construct a modal dialog.
57 //=================================================================================
58 RepairGUI_LimitToleranceDlg::RepairGUI_LimitToleranceDlg(GeometryGUI* theGeometryGUI,
59 QWidget* parent, bool modal)
60 : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
62 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_LIMIT_TOLERANCE")));
63 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
65 setWindowTitle(tr("GEOM_LIMIT_TOLERANCE_TITLE"));
67 /***************************************************************/
68 mainFrame()->GroupConstructors->setTitle(tr("GEOM_LIMIT_TOLERANCE_TITLE"));
69 mainFrame()->RadioButton1->setIcon(image0);
70 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
71 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
72 mainFrame()->RadioButton2->close();
73 mainFrame()->RadioButton3->close();
75 GroupPoints = new DlgRef_1SelExt(centralWidget());
76 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
77 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
78 GroupPoints->PushButton1->setIcon(image1);
79 GroupPoints->LineEdit1->setReadOnly(true);
81 QLabel* aTolLab = new QLabel(tr("GEOM_TOLERANCE"), GroupPoints->Box);
82 myTolEdt = new SalomeApp_DoubleSpinBox(GroupPoints->Box);
83 initSpinBox(myTolEdt, 0., 100., DEFAULT_TOLERANCE_VALUE, "len_tol_precision");
84 myTolEdt->setValue(DEFAULT_TOLERANCE_VALUE);
86 QGridLayout* boxLayout = new QGridLayout(GroupPoints->Box);
87 boxLayout->setMargin(0); boxLayout->setSpacing(6);
88 boxLayout->addWidget(aTolLab, 0, 0);
89 boxLayout->addWidget(myTolEdt, 0, 2);
91 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
92 layout->setMargin(0); layout->setSpacing(6);
93 layout->addWidget(GroupPoints);
95 setHelpFileName("limit_tolerance_operation_page.html");
101 //=================================================================================
102 // function : ~RepairGUI_LimitToleranceDlg()
103 // purpose : Destroys the object and frees any allocated resources
104 //=================================================================================
105 RepairGUI_LimitToleranceDlg::~RepairGUI_LimitToleranceDlg()
110 //=================================================================================
113 //=================================================================================
114 void RepairGUI_LimitToleranceDlg::Init()
117 myEditCurrentArgument = GroupPoints->LineEdit1;
119 myObject = GEOM::GEOM_Object::_nil();
121 //myGeomGUI->SetState(0);
122 //globalSelection(GEOM_COMPOUND);
124 mainFrame()->GroupBoxPublish->show();
125 //Hide preview checkbox
126 mainFrame()->CheckBoxPreview->hide();
128 /* signals and slots connections */
129 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
130 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
132 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
135 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
136 this, SLOT(SelectionIntoArgument()));
138 initName(tr("LIMIT_TOLERANCE_NEW_OBJ_NAME"));
140 ConstructorsClicked(0);
147 //=================================================================================
148 // function : ConstructorsClicked()
149 // purpose : Radio button management
150 //=================================================================================
151 void RepairGUI_LimitToleranceDlg::ConstructorsClicked(int constructorId)
153 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
156 GroupPoints->LineEdit1->setText("");
157 myEditCurrentArgument = GroupPoints->LineEdit1;
158 myEditCurrentArgument->setFocus();
160 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
161 this, SLOT(SelectionIntoArgument()));
163 qApp->processEvents();
165 resize(minimumSizeHint());
169 SelectionIntoArgument();
173 //=================================================================================
174 // function : ClickOnOk()
175 // purpose : Same than click on apply but close this dialog.
176 //=================================================================================
177 void RepairGUI_LimitToleranceDlg::ClickOnOk()
179 setIsApplyAndClose( true );
184 //=================================================================================
185 // function : ClickOnApply()
187 //=================================================================================
188 bool RepairGUI_LimitToleranceDlg::ClickOnApply()
190 if (!onAcceptLocal())
195 ConstructorsClicked(0);
200 //=================================================================================
201 // function : SelectionIntoArgument()
202 // purpose : Called when selection
203 //=================================================================================
204 void RepairGUI_LimitToleranceDlg::SelectionIntoArgument()
206 myEditCurrentArgument->setText("");
207 myObject = GEOM::GEOM_Object::_nil();
209 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
210 SALOME_ListIO aSelList;
211 aSelMgr->selectedObjects(aSelList);
213 if (aSelList.Extent() == 1) {
214 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
215 myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
216 if ( !CORBA::is_nil( myObject ) )
217 myEditCurrentArgument->setText(GEOMBase::GetName(myObject));
222 //=================================================================================
223 // function : SetEditCurrentArgument()
225 //=================================================================================
226 void RepairGUI_LimitToleranceDlg::SetEditCurrentArgument()
228 const QObject* send = sender();
229 if (send == GroupPoints->PushButton1) {
230 myEditCurrentArgument->setFocus();
231 SelectionIntoArgument();
235 //=================================================================================
236 // function : LineEditReturnPressed()
238 //=================================================================================
239 void RepairGUI_LimitToleranceDlg::LineEditReturnPressed()
241 const QObject* send = sender();
242 if (send == GroupPoints->LineEdit1) {
243 myEditCurrentArgument = GroupPoints->LineEdit1;
244 GEOMBase_Skeleton::LineEditReturnPressed();
248 //=================================================================================
249 // function : ActivateThisDialog()
251 //=================================================================================
252 void RepairGUI_LimitToleranceDlg::ActivateThisDialog()
254 GEOMBase_Skeleton::ActivateThisDialog();
255 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
256 this, SLOT(SelectionIntoArgument()));
260 //=================================================================================
261 // function : enterEvent()
262 // purpose : Mouse enter onto the dialog to activate it
263 //=================================================================================
264 void RepairGUI_LimitToleranceDlg::enterEvent(QEvent*)
266 if (!mainFrame()->GroupConstructors->isEnabled())
267 ActivateThisDialog();
270 //=================================================================================
271 // function : createOperation
273 //=================================================================================
274 GEOM::GEOM_IOperations_ptr RepairGUI_LimitToleranceDlg::createOperation()
276 return getGeomEngine()->GetIHealingOperations(getStudyId());
279 //=================================================================================
280 // function : isValid
282 //=================================================================================
283 bool RepairGUI_LimitToleranceDlg::isValid(QString& msg)
285 double v = myTolEdt->value();
286 bool ok = myTolEdt->isValid(msg, true);
287 return !myObject->_is_nil() && (v > 0.) && ok;
290 //=================================================================================
291 // function : execute
293 //=================================================================================
294 bool RepairGUI_LimitToleranceDlg::execute(ObjectList& objects)
296 bool aResult = false;
299 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
300 GEOM::GEOM_Object_var anObj = anOper->LimitTolerance(myObject, myTolEdt->value());
301 aResult = !anObj->_is_nil();
303 QStringList aParameters;
304 aParameters << myTolEdt->text();
305 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
306 objects.push_back(anObj._retn());
312 //================================================================
313 // Function : onAccept
314 // Purpose : This method should be called from dialog's slots onOk() and onApply()
315 // It perfroms user input validation, then it
316 // performs a proper operation and manages transactions, etc.
317 //================================================================
318 bool RepairGUI_LimitToleranceDlg::onAcceptLocal()
320 if (!getStudy() || !(getStudy()->studyDS()))
323 _PTR(Study) aStudy = getStudy()->studyDS();
325 bool aLocked = aStudy->GetProperties()->IsLocked();
327 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
328 SUIT_MessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"), tr("BUT_OK"));
340 SUIT_OverrideCursor wc;
342 myGeomGUI->getApp()->putInfo("");
345 if (!execute(objects)) {
351 const int nbObjs = objects.size();
352 for (ObjectList::iterator it = objects.begin(); it != objects.end(); ++it) {
353 QString aName = getNewObjectName();
356 aName = getPrefix(*it);
357 aName = GEOMBase::GetDefaultName(aName);
360 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
362 aName = GEOMBase::GetDefaultName(getPrefix(*it));
364 addInStudy(*it, aName.toLatin1().data());
371 myGeomGUI->getApp()->putInfo(QObject::tr("GEOM_PRP_DONE"));
377 // JFA 28.12.2004 BEGIN // To enable warnings
378 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
379 if (!CORBA::is_nil(anOper) && !anOper->IsDone()) {
381 QString msgw = QObject::tr(anOper->GetErrorCode());
382 SUIT_MessageBox::warning(this, tr("WRN_WARNING"), msgw, tr("BUT_OK"));
384 // JFA 28.12.2004 END
388 catch(const SALOME::SALOME_Exception& e) {
389 SalomeApp_Tools::QtCatchCorbaException(e);
400 //=================================================================================
401 // function : activateSelection
402 // purpose : Activate selection
403 //=================================================================================
404 void RepairGUI_LimitToleranceDlg::activateSelection()
406 disconnect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
407 this, SLOT(SelectionIntoArgument()));
409 globalSelection(GEOM_ALLSHAPES);
410 if (myObject->_is_nil())
411 SelectionIntoArgument();
413 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
414 this, SLOT(SelectionIntoArgument()));
418 //=================================================================================
419 // function : updateButtonState
420 // purpose : Update button state
421 //=================================================================================
422 void RepairGUI_LimitToleranceDlg::updateButtonState()
424 bool hasMainObj = !myObject->_is_nil();
425 buttonOk()->setEnabled(hasMainObj);
426 buttonApply()->setEnabled(hasMainObj);
429 //=================================================================================
430 // function : restoreSubShapes
432 //=================================================================================
433 void RepairGUI_LimitToleranceDlg::restoreSubShapes(SALOMEDS::Study_ptr theStudy,
434 SALOMEDS::SObject_ptr theSObject)
436 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
437 // empty list of arguments means that all arguments should be restored
438 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
439 GEOM::FSM_GetInPlace, /*theInheritFirstArg=*/true,
440 mainFrame()->CheckBoxAddPrefix->isChecked());