1 // Copyright (C) 2007-2015 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : MeasureGUI_GetNonBlocksDlg.cxx
26 #include "MeasureGUI_GetNonBlocksDlg.h"
30 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <SalomeApp_DoubleSpinBox.h>
36 #include <LightApp_SelectionMgr.h>
37 #include <SalomeApp_Tools.h>
40 #include <QGridLayout>
43 #include <QPushButton>
44 #include <QRadioButton>
45 #include <QVBoxLayout>
47 //=================================================================================
48 // class : MeasureGUI_GetNonBlocksDlg()
49 // purpose : Constructs a MeasureGUI_GetNonBlocksDlg which is a child of 'parent',
50 // with the name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // true to construct a modal dialog.
53 //=================================================================================
54 MeasureGUI_GetNonBlocksDlg::MeasureGUI_GetNonBlocksDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
55 : GEOMBase_Skeleton(theGeometryGUI, parent, false),
62 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_GETNONBLOCKS")));
63 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
65 setWindowTitle(tr("GEOM_GETNONBLOCKS_TITLE"));
67 /***************************************************************/
68 mainFrame()->GroupConstructors->setTitle(tr("GEOM_GETNONBLOCKS"));
69 mainFrame()->RadioButton1->setIcon(image0);
70 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
71 mainFrame()->RadioButton2->close();
72 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
73 mainFrame()->RadioButton3->close();
75 QGroupBox *aGrpParams =
76 new QGroupBox(tr("GEOM_GETNONBLOCKS"), centralWidget());
77 QGridLayout *aParamsLayout = new QGridLayout(aGrpParams);
78 QLabel *anObjLbl = new QLabel(tr("GEOM_OBJECT"), aGrpParams);
80 myObjectName = new QLineEdit(aGrpParams);
81 mySelButton = new QPushButton(aGrpParams);
82 myUseC1Check = new QCheckBox(tr("GEOM_USE_C1_CRITERION"), aGrpParams);
83 myTolLbl = new QLabel(tr("GEOM_ANGULAR_TOLERANCE"), aGrpParams);
84 mySpinTol = new SalomeApp_DoubleSpinBox(aGrpParams);
86 myObjectName->setReadOnly(true);
87 mySelButton->setIcon(image1);
88 mySelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
89 myUseC1Check->setText(tr("GEOM_USE_C1_CRITERION"));
90 myUseC1Check->setChecked(true);
92 aParamsLayout->setMargin(9);
93 aParamsLayout->setSpacing(6);
94 aParamsLayout->addWidget(anObjLbl, 0, 0);
95 aParamsLayout->addWidget(mySelButton, 0, 1);
96 aParamsLayout->addWidget(myObjectName, 0, 2);
97 aParamsLayout->addWidget(myUseC1Check, 1, 0, 1, 3);
98 aParamsLayout->addWidget(myTolLbl, 2, 0);
99 aParamsLayout->addWidget(mySpinTol, 2, 1, 1, 2);
101 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
102 layout->setMargin(0); layout->setSpacing(6);
103 layout->addWidget(aGrpParams);
105 /***************************************************************/
107 myHelpFileName = "get_non_blocks_page.html";
113 //=================================================================================
114 // function : ~MeasureGUI_GetNonBlocksDlg()
115 // purpose : Destroys the object and frees any allocated resources
116 //=================================================================================
117 MeasureGUI_GetNonBlocksDlg::~MeasureGUI_GetNonBlocksDlg()
121 //=================================================================================
124 //=================================================================================
125 void MeasureGUI_GetNonBlocksDlg::Init()
127 showOnlyPreviewControl();
130 double SpecificStep = 0.0001;
131 double aDefaultTol = Precision::Angular();
133 initSpinBox(mySpinTol, aDefaultTol, MAX_NUMBER, SpecificStep, "ang_tol_precision");
134 mySpinTol->setValue(aDefaultTol);
135 myEditCurrentArgument = myObjectName;
137 /* signals and slots connections */
138 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
139 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
140 connect(myUseC1Check, SIGNAL(clicked()), this, SLOT(SetUseC1Tolerance()));
141 connect(mySpinTol, SIGNAL(valueChanged(double)), this, SLOT(processPreview()));
142 connect(myObjectName, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
143 connect(mySelButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
146 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
148 //initName(tr("GEOM_NONBLOCKS"));
149 mainFrame()->ResultName->setText(tr("GEOM_NONBLOCKS"));
151 SelectionIntoArgument();
154 //=================================================================================
155 // function : ClickOnOk()
157 //=================================================================================
158 void MeasureGUI_GetNonBlocksDlg::ClickOnOk()
164 //=================================================================================
165 // function : ClickOnApply()
167 //=================================================================================
168 bool MeasureGUI_GetNonBlocksDlg::ClickOnApply()
177 //=================================================================================
178 // function : SelectionIntoArgument()
179 // purpose : Called when selection as changed or other case
180 //=================================================================================
181 void MeasureGUI_GetNonBlocksDlg::SelectionIntoArgument()
184 myObj = GEOM::GEOM_Object::_nil();
186 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
187 SALOME_ListIO aSelList;
188 aSelMgr->selectedObjects(aSelList);
190 if (aSelList.Extent() != 1) {
195 GEOM::GEOM_Object_var aSelectedObject =
196 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
198 if (aSelectedObject->_is_nil()) {
203 myObj = aSelectedObject;
207 //=================================================================================
208 // function : SetEditCurrentArgument()
210 //=================================================================================
211 void MeasureGUI_GetNonBlocksDlg::SetEditCurrentArgument()
213 myObjectName->setFocus();
214 myEditCurrentArgument = myObjectName;
215 SelectionIntoArgument();
218 //=================================================================================
219 // function : SetUseC1Tolerance()
221 //=================================================================================
222 void MeasureGUI_GetNonBlocksDlg::SetUseC1Tolerance()
224 myTolLbl->setEnabled(myUseC1Check->isChecked());
225 mySpinTol->setEnabled(myUseC1Check->isChecked());
229 //=================================================================================
230 // function : LineEditReturnPressed()
232 //=================================================================================
233 void MeasureGUI_GetNonBlocksDlg::LineEditReturnPressed()
235 QLineEdit* send = (QLineEdit*)sender();
236 if (send == myObjectName) {
237 myEditCurrentArgument = myObjectName;
238 GEOMBase_Skeleton::LineEditReturnPressed();
242 //=================================================================================
243 // function : ActivateThisDialog()
245 //=================================================================================
246 void MeasureGUI_GetNonBlocksDlg::ActivateThisDialog()
248 GEOMBase_Skeleton::ActivateThisDialog();
250 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
251 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
257 //=================================================================================
258 // function : processObject()
259 // purpose : Fill dialog fields in accordance with myObj
260 //=================================================================================
261 void MeasureGUI_GetNonBlocksDlg::processObject()
263 if (myObj->_is_nil()) {
264 myObjectName->setText("");
268 myObjectName->setText(GEOMBase::GetName(myObj));
274 //=================================================================================
275 // function : enterEvent()
277 //=================================================================================
278 void MeasureGUI_GetNonBlocksDlg::enterEvent (QEvent*)
280 if (!mainFrame()->GroupConstructors->isEnabled())
281 ActivateThisDialog();
284 //=================================================================================
285 // function : createOperation
287 //=================================================================================
288 GEOM::GEOM_IOperations_ptr MeasureGUI_GetNonBlocksDlg::createOperation()
290 return getGeomEngine()->GetIBlocksOperations(getStudyId());
293 //=================================================================================
294 // function : isValid
296 //=================================================================================
297 bool MeasureGUI_GetNonBlocksDlg::isValid (QString &msg)
299 return !myObj->_is_nil() && mySpinTol->isValid(msg, !IsPreview());
302 //=================================================================================
303 // function : execute
305 //=================================================================================
306 bool MeasureGUI_GetNonBlocksDlg::execute (ObjectList& objects)
308 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
309 GEOM::GEOM_Object_var aNonQuads;
312 if (myUseC1Check->isChecked()) {
313 aC1Tol = mySpinTol->value();
316 GEOM::GEOM_Object_var anObj = anOper->GetNonBlocks(myObj, aC1Tol, aNonQuads);
317 //mainFrame()->ResultName->setText(tr("GEOM_NONBLOCKS"));
319 if (!anObj->_is_nil())
320 objects.push_back(anObj._retn());
321 if (!aNonQuads->_is_nil())
322 objects.push_back(aNonQuads._retn());
327 //================================================================
328 // Function : getFather
329 // Purpose : Get father object for object to be added in study
330 // ( called with addInStudy method )
331 //================================================================
332 GEOM::GEOM_Object_ptr MeasureGUI_GetNonBlocksDlg::getFather (GEOM::GEOM_Object_ptr)
337 //=================================================================================
338 // function : getSourceObjects
339 // purpose : virtual method to get source objects
340 //=================================================================================
341 QList<GEOM::GeomObjPtr> MeasureGUI_GetNonBlocksDlg::getSourceObjects()
343 QList<GEOM::GeomObjPtr> res;
344 GEOM::GeomObjPtr aGeomObjPtr(myObj);