1 // Copyright (C) 2007-2024 CEA, EDF, 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 "RepairGUI.h"
31 #include <SalomeApp_DoubleSpinBox.h>
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_ListIO.hxx>
45 #include "utilities.h"
47 #include <GEOMImpl_Types.hxx>
49 #include <TCollection_AsciiString.hxx>
51 #define DEFAULT_TOLERANCE_VALUE 1e-07
53 //=================================================================================
54 // class : RepairGUI_LimitToleranceDlg()
55 // purpose : Constructs a RepairGUI_LimitToleranceDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 RepairGUI_LimitToleranceDlg::RepairGUI_LimitToleranceDlg(GeometryGUI* theGeometryGUI,
61 QWidget* parent, bool modal)
62 : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
64 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_LIMIT_TOLERANCE")));
65 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
67 setWindowTitle(tr("GEOM_LIMIT_TOLERANCE_TITLE"));
69 /***************************************************************/
70 mainFrame()->GroupConstructors->setTitle(tr("GEOM_LIMIT_TOLERANCE_TITLE"));
71 mainFrame()->RadioButton1->setIcon(image0);
72 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
73 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
74 mainFrame()->RadioButton2->close();
75 mainFrame()->RadioButton3->close();
77 GroupPoints = new DlgRef_1SelExt(centralWidget());
78 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
79 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
80 GroupPoints->PushButton1->setIcon(image1);
81 GroupPoints->LineEdit1->setReadOnly(true);
83 QLabel* aTolLab = new QLabel(tr("GEOM_TOLERANCE"), GroupPoints->Box);
84 myTolEdt = new SalomeApp_DoubleSpinBox(GroupPoints->Box);
85 initSpinBox(myTolEdt, 0., 100., DEFAULT_TOLERANCE_VALUE, "len_tol_precision");
86 myTolEdt->setValue(DEFAULT_TOLERANCE_VALUE);
88 QGridLayout* boxLayout = new QGridLayout(GroupPoints->Box);
89 boxLayout->setMargin(0); boxLayout->setSpacing(6);
90 boxLayout->addWidget(aTolLab, 0, 0);
91 boxLayout->addWidget(myTolEdt, 0, 2);
93 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
94 layout->setMargin(0); layout->setSpacing(6);
95 layout->addWidget(GroupPoints);
97 setHelpFileName("limit_tolerance_operation_page.html");
103 //=================================================================================
104 // function : ~RepairGUI_LimitToleranceDlg()
105 // purpose : Destroys the object and frees any allocated resources
106 //=================================================================================
107 RepairGUI_LimitToleranceDlg::~RepairGUI_LimitToleranceDlg()
112 //=================================================================================
115 //=================================================================================
116 void RepairGUI_LimitToleranceDlg::Init()
119 myEditCurrentArgument = GroupPoints->LineEdit1;
121 myObject = GEOM::GEOM_Object::_nil();
123 //myGeomGUI->SetState(0);
124 //globalSelection(GEOM_COMPOUND);
126 mainFrame()->GroupBoxPublish->show();
127 //Hide preview checkbox
128 mainFrame()->CheckBoxPreview->hide();
130 /* signals and slots connections */
131 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
132 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
134 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
137 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
138 this, SLOT(SelectionIntoArgument()));
140 initName(tr("LIMIT_TOLERANCE_NEW_OBJ_NAME"));
142 ConstructorsClicked(0);
149 //=================================================================================
150 // function : ConstructorsClicked()
151 // purpose : Radio button management
152 //=================================================================================
153 void RepairGUI_LimitToleranceDlg::ConstructorsClicked(int /*constructorId*/)
155 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
158 GroupPoints->LineEdit1->setText("");
159 myEditCurrentArgument = GroupPoints->LineEdit1;
160 myEditCurrentArgument->setFocus();
162 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
163 this, SLOT(SelectionIntoArgument()));
165 qApp->processEvents();
167 resize(minimumSizeHint());
171 SelectionIntoArgument();
175 //=================================================================================
176 // function : ClickOnOk()
177 // purpose : Same than click on apply but close this dialog.
178 //=================================================================================
179 void RepairGUI_LimitToleranceDlg::ClickOnOk()
181 setIsApplyAndClose( true );
186 //=================================================================================
187 // function : ClickOnApply()
189 //=================================================================================
190 bool RepairGUI_LimitToleranceDlg::ClickOnApply()
192 if (!onAcceptLocal())
197 ConstructorsClicked(0);
202 //=================================================================================
203 // function : SelectionIntoArgument()
204 // purpose : Called when selection
205 //=================================================================================
206 void RepairGUI_LimitToleranceDlg::SelectionIntoArgument()
208 myEditCurrentArgument->setText("");
209 myObject = GEOM::GEOM_Object::_nil();
211 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
212 SALOME_ListIO aSelList;
213 aSelMgr->selectedObjects(aSelList);
215 if (aSelList.Extent() == 1) {
216 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
217 myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
218 if ( !CORBA::is_nil( myObject ) )
219 myEditCurrentArgument->setText(GEOMBase::GetName(myObject));
224 //=================================================================================
225 // function : SetEditCurrentArgument()
227 //=================================================================================
228 void RepairGUI_LimitToleranceDlg::SetEditCurrentArgument()
230 const QObject* send = sender();
231 if (send == GroupPoints->PushButton1) {
232 myEditCurrentArgument->setFocus();
233 SelectionIntoArgument();
237 //=================================================================================
238 // function : LineEditReturnPressed()
240 //=================================================================================
241 void RepairGUI_LimitToleranceDlg::LineEditReturnPressed()
243 const QObject* send = sender();
244 if (send == GroupPoints->LineEdit1) {
245 myEditCurrentArgument = GroupPoints->LineEdit1;
246 GEOMBase_Skeleton::LineEditReturnPressed();
250 //=================================================================================
251 // function : ActivateThisDialog()
253 //=================================================================================
254 void RepairGUI_LimitToleranceDlg::ActivateThisDialog()
256 GEOMBase_Skeleton::ActivateThisDialog();
257 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
258 this, SLOT(SelectionIntoArgument()));
262 //=================================================================================
263 // function : enterEvent()
264 // purpose : Mouse enter onto the dialog to activate it
265 //=================================================================================
266 void RepairGUI_LimitToleranceDlg::enterEvent(QEvent*)
268 if (!mainFrame()->GroupConstructors->isEnabled())
269 ActivateThisDialog();
272 //=================================================================================
273 // function : createOperation
275 //=================================================================================
276 GEOM::GEOM_IOperations_ptr RepairGUI_LimitToleranceDlg::createOperation()
278 return getGeomEngine()->GetIHealingOperations();
281 //=================================================================================
282 // function : isValid
284 //=================================================================================
285 bool RepairGUI_LimitToleranceDlg::isValid(QString& msg)
287 double v = myTolEdt->value();
288 bool ok = myTolEdt->isValid(msg, true);
289 return !myObject->_is_nil() && (v > 0.) && ok;
292 //=================================================================================
293 // function : execute
295 //=================================================================================
296 bool RepairGUI_LimitToleranceDlg::execute(ObjectList& objects)
298 bool aResult = false;
301 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
302 GEOM::GEOM_Object_var anObj = anOper->LimitTolerance(myObject, myTolEdt->value());
303 aResult = !anObj->_is_nil();
305 QStringList aParameters;
306 aParameters << myTolEdt->text();
307 anObj->SetParameters(aParameters.join(":").toUtf8().constData());
309 RepairGUI::ShowStatistics( anOper, this );
310 objects.push_back(anObj._retn());
316 //================================================================
317 // Function : onAccept
318 // Purpose : This method should be called from dialog's slots onOk() and onApply()
319 // It performs user input validation, then it
320 // performs a proper operation and manages transactions, etc.
321 //================================================================
322 bool RepairGUI_LimitToleranceDlg::onAcceptLocal()
324 if (!getStudy() || !(getStudy()->studyDS()))
327 _PTR(Study) aStudy = getStudy()->studyDS();
329 bool aLocked = aStudy->GetProperties()->IsLocked();
331 SUIT_MessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"), tr("BUT_OK"));
343 SUIT_OverrideCursor wc;
345 myGeomGUI->getApp()->putInfo("");
348 if (!execute(objects)) {
354 const int nbObjs = objects.size();
355 for (ObjectList::iterator it = objects.begin(); it != objects.end(); ++it) {
356 QString aName = getNewObjectName();
359 aName = getPrefix(*it);
360 aName = GEOMBase::GetDefaultName(aName);
363 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
365 aName = GEOMBase::GetDefaultName(getPrefix(*it));
367 addInStudy(*it, aName.toUtf8().data());
374 myGeomGUI->getApp()->putInfo(QObject::tr("GEOM_PRP_DONE"));
380 // JFA 28.12.2004 BEGIN // To enable warnings
381 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
382 if (!CORBA::is_nil(anOper) && !anOper->IsDone()) {
384 QString msgw = QObject::tr(anOper->GetErrorCode());
385 SUIT_MessageBox::warning(this, tr("WRN_WARNING"), msgw, tr("BUT_OK"));
387 // JFA 28.12.2004 END
391 catch(const SALOME::SALOME_Exception& e) {
392 SalomeApp_Tools::QtCatchCorbaException(e);
403 //=================================================================================
404 // function : activateSelection
405 // purpose : Activate selection
406 //=================================================================================
407 void RepairGUI_LimitToleranceDlg::activateSelection()
409 disconnect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
410 this, SLOT(SelectionIntoArgument()));
412 globalSelection(GEOM_ALLSHAPES);
413 if (myObject->_is_nil())
414 SelectionIntoArgument();
416 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
417 this, SLOT(SelectionIntoArgument()));
421 //=================================================================================
422 // function : updateButtonState
423 // purpose : Update button state
424 //=================================================================================
425 void RepairGUI_LimitToleranceDlg::updateButtonState()
427 bool hasMainObj = !myObject->_is_nil();
428 buttonOk()->setEnabled(hasMainObj);
429 buttonApply()->setEnabled(hasMainObj);
432 //=================================================================================
433 // function : restoreSubShapes
435 //=================================================================================
436 void RepairGUI_LimitToleranceDlg::restoreSubShapes(SALOMEDS::SObject_ptr theSObject)
438 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
439 // empty list of arguments means that all arguments should be restored
440 getGeomEngine()->RestoreSubShapesSO(theSObject, GEOM::ListOfGO(),
441 GEOM::FSM_GetInPlace, /*theInheritFirstArg=*/true,
442 mainFrame()->CheckBoxAddPrefix->isChecked());
446 //=================================================================================
447 // function : getSourceObjects
448 // purpose : virtual method to get source objects
449 //=================================================================================
450 QList<GEOM::GeomObjPtr> RepairGUI_LimitToleranceDlg::getSourceObjects()
452 QList<GEOM::GeomObjPtr> res;
453 GEOM::GeomObjPtr aGeomObjPtr(myObject);