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 : GenerationGUI_ThicknessDlg.cxx
25 // Author : Sergey KHROMOV, Open CASCADE S.A.S.
27 #include "GenerationGUI_ThicknessDlg.h"
30 #include <GeometryGUI.h>
32 #include <LightApp_SelectionMgr.h>
33 #include <SalomeApp_Application.h>
34 #include <SalomeApp_DoubleSpinBox.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
38 #include <QApplication>
40 #include <QGridLayout>
44 #include <QPushButton>
45 #include <QRadioButton>
48 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <Precision.hxx>
51 #define GEOM_SOLID_THICK 0
52 #define GEOM_SOLID_HOLLOWED 1
54 //==============================================================================
55 // class : GenerationGUI_ThicknessDlg()
57 //==============================================================================
58 GenerationGUI_ThicknessDlg::GenerationGUI_ThicknessDlg
59 (GeometryGUI* theGeometryGUI, QWidget* parent,
60 bool modal, Qt::WindowFlags fl)
61 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
70 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
71 QPixmap image0(aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
72 QPixmap image1(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_THICKNESS")));
74 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_THICKNESS_HOLLOWED")));
76 setWindowTitle(tr("GEOM_THICKNESS_TITLE"));
78 /***************************************************************/
79 mainFrame()->GroupConstructors->setTitle(tr("GEOM_THICKNESS"));
80 mainFrame()->RadioButton1->setIcon(image1);
81 mainFrame()->RadioButton2->setIcon(image2);
83 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
84 mainFrame()->RadioButton3->close();
86 mainFrame()->RadioButton1->setChecked(true);
88 QGroupBox *aMainGrp = new QGroupBox (tr("GEOM_ARGUMENTS"), this);
89 QGridLayout *aParamsLayout = new QGridLayout(aMainGrp);
90 QLabel *anObjLbl = new QLabel (tr("GEOM_OBJECT"), aMainGrp);
91 QLabel *aThicknessLbl = new QLabel (tr("GEOM_THICKNESS"), aMainGrp);
93 myFacesLbl = new QLabel (tr("GEOM_FACES"), aMainGrp);
94 myObjSelBtn = new QPushButton(aMainGrp);
95 myFacesSelBtn = new QPushButton(aMainGrp);
96 myObjEdit = new QLineEdit(aMainGrp);
97 myFacesEdit = new QLineEdit(aMainGrp);
98 myThicknessSpin = new SalomeApp_DoubleSpinBox(aMainGrp);
99 myInsideCheck = new QCheckBox(tr("GEOM_TOWARDS_INSIDE"), aMainGrp);
101 myObjSelBtn->setIcon(image0);
102 myFacesSelBtn->setIcon(image0);
103 myObjEdit->setReadOnly(true);
104 myObjEdit->setSizePolicy
105 (QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
106 myFacesEdit->setReadOnly(true);
107 myFacesEdit->setSizePolicy
108 (QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
110 aParamsLayout->setMargin(9);
111 aParamsLayout->setSpacing(6);
112 aParamsLayout->addWidget(anObjLbl, 0, 0);
113 aParamsLayout->addWidget(myObjSelBtn, 0, 1);
114 aParamsLayout->addWidget(myObjEdit, 0, 2);
115 aParamsLayout->addWidget(myFacesLbl, 1, 0);
116 aParamsLayout->addWidget(myFacesSelBtn, 1, 1);
117 aParamsLayout->addWidget(myFacesEdit, 1, 2);
118 aParamsLayout->addWidget(aThicknessLbl, 2, 0);
119 aParamsLayout->addWidget(myThicknessSpin, 2, 1, 1, 2);
120 aParamsLayout->addWidget(myInsideCheck, 3, 0, 1, 3);
122 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
124 layout->setMargin(0);
125 layout->setSpacing(6);
126 layout->addWidget(aMainGrp);
128 myHelpFileName = "create_thickness_page.html";
134 //==============================================================================
135 // function : ~GenerationGUI_ThicknessDlg()
137 //==============================================================================
138 GenerationGUI_ThicknessDlg::~GenerationGUI_ThicknessDlg()
140 // no need to delete child widgets, Qt does it all for us
143 //==============================================================================
146 //==============================================================================
147 void GenerationGUI_ThicknessDlg::Init()
149 // Get setting of step value from file configuration
150 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
151 double aStep = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
152 double aThickness = 10.;
153 double aThicknessMin = Precision::Confusion() * 10.0;
155 initSpinBox(myThicknessSpin, aThicknessMin,
156 COORD_MAX, aStep, "length_precision");
157 myThicknessSpin->setValue(aThickness);
161 showOnlyPreviewControl();
163 // signals and slots connections
164 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
165 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
166 connect(this, SIGNAL(constructorsClicked(int)),
167 this, SLOT(ConstructorsClicked(int)));
168 connect(myObjSelBtn, SIGNAL(clicked()),
169 this, SLOT(SetEditCurrentArgument()));
170 connect(myFacesSelBtn, SIGNAL(clicked()),
171 this, SLOT(SetEditCurrentArgument()));
172 connect(myThicknessSpin, SIGNAL(valueChanged(double)),
173 this, SLOT(ValueChangedInSpinBox()));
174 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
175 this, SLOT(SetDoubleSpinBoxStep(double)));
176 connect(myInsideCheck, SIGNAL(toggled(bool)),
177 this, SLOT(onChangeDirection(bool)));
179 connect(myGeomGUI->getApp()->selectionMgr(),
180 SIGNAL(currentSelectionChanged()),
181 this, SLOT(SelectionIntoArgument()));
183 initName(tr("GEOM_THICKNESS"));
185 ConstructorsClicked(0);
188 //==============================================================================
189 // function : SetDoubleSpinBoxStep()
190 // purpose : Double spin box management
191 //==============================================================================
192 void GenerationGUI_ThicknessDlg::SetDoubleSpinBoxStep (double step)
194 myThicknessSpin->setSingleStep(step);
197 //==============================================================================
198 // function : ConstructorsClicked()
199 // purpose : Radio button management
200 //==============================================================================
201 void GenerationGUI_ThicknessDlg::ConstructorsClicked (int constructorId)
203 switch (constructorId) {
204 case GEOM_SOLID_THICK:
205 myObjSelBtn->setDown(false);
207 myFacesSelBtn->hide();
211 case GEOM_SOLID_HOLLOWED:
212 myObjSelBtn->setDown(true);
214 myFacesSelBtn->show();
221 myEditCurrentArgument = myObjEdit;
222 qApp->processEvents();
224 resize(minimumSizeHint());
226 SelectionIntoArgument();
229 //==============================================================================
230 // function : ClickOnOk()
232 //==============================================================================
233 void GenerationGUI_ThicknessDlg::ClickOnOk()
235 setIsApplyAndClose(true);
237 if (ClickOnApply()) {
242 //==============================================================================
243 // function : ClickOnApply()
245 //==============================================================================
246 bool GenerationGUI_ThicknessDlg::ClickOnApply()
254 // activate selection and connect selection manager
255 ConstructorsClicked(getConstructorId());
260 //==============================================================================
261 // function : SelectionIntoArgument()
262 // purpose : Called when selection is changed or on dialog initialization or
264 //==============================================================================
265 void GenerationGUI_ThicknessDlg::SelectionIntoArgument()
268 myEditCurrentArgument->setText("");
270 if (myEditCurrentArgument == myObjEdit) {
271 QList<TopAbs_ShapeEnum> aTypes;
272 const int anID = getConstructorId();
274 if (anID == GEOM_SOLID_THICK) {
275 aTypes << TopAbs_SHELL << TopAbs_FACE;
276 } else if (anID == GEOM_SOLID_HOLLOWED) {
277 aTypes << TopAbs_SOLID;
280 myObject = getSelected(aTypes);
283 QString aName = GEOMBase::GetName(myObject.get());
285 myEditCurrentArgument->setText(aName);
287 if (anID == GEOM_SOLID_HOLLOWED && myFaces.empty()) {
288 myFacesSelBtn->click();
291 } else if (myEditCurrentArgument == myFacesEdit) {
293 myFaces = getSelected(TopAbs_FACE, -1);
295 int i = myFaces.count();
298 myEditCurrentArgument->setText(GEOMBase::GetName(myFaces.first().get()));
300 myEditCurrentArgument->setText
301 (QString::number( i ) + "_" + tr("GEOM_OBJECTS"));
308 //==============================================================================
309 // function : SetEditCurrentArgument()
311 //==============================================================================
312 void GenerationGUI_ThicknessDlg::SetEditCurrentArgument()
314 QPushButton* send = (QPushButton*)sender();
316 if (send == myObjSelBtn) {
317 myFacesSelBtn->setDown(false);
318 myEditCurrentArgument = myObjEdit;
319 globalSelection(GEOM_ALLSHAPES);
320 } else if (send == myFacesSelBtn) {
321 myObjSelBtn->setDown(false);
322 myEditCurrentArgument = myFacesEdit;
323 globalSelection(); // close local contexts, if any
324 localSelection(myObject.get(), TopAbs_FACE);
327 myEditCurrentArgument->setFocus();
329 const int anID = getConstructorId();
331 // after setFocus(), because it will be setDown(false) when loses focus
332 send->setDown(anID == GEOM_SOLID_HOLLOWED);
334 // seems we need it only to avoid preview disappearing, caused by selection
339 //==============================================================================
340 // function : ActivateThisDialog()
342 //==============================================================================
343 void GenerationGUI_ThicknessDlg::ActivateThisDialog()
345 GEOMBase_Skeleton::ActivateThisDialog();
347 connect(myGeomGUI->getApp()->selectionMgr(),
348 SIGNAL(currentSelectionChanged()),
349 this, SLOT(SelectionIntoArgument()));
351 ConstructorsClicked(getConstructorId());
354 //==============================================================================
355 // function : enterEvent()
356 // purpose : when mouse enter onto the QWidget
357 //==============================================================================
358 void GenerationGUI_ThicknessDlg::enterEvent (QEvent*)
360 if (!mainFrame()->GroupConstructors->isEnabled())
361 ActivateThisDialog();
364 //==============================================================================
365 // function : ValueChangedInSpinBox()
367 //==============================================================================
368 void GenerationGUI_ThicknessDlg::ValueChangedInSpinBox()
373 //==============================================================================
374 // function : createOperation
376 //==============================================================================
377 GEOM::GEOM_IOperations_ptr GenerationGUI_ThicknessDlg::createOperation()
379 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
382 //==============================================================================
383 // function : isValid
385 //==============================================================================
386 bool GenerationGUI_ThicknessDlg::isValid (QString& msg)
390 switch (getConstructorId()) {
391 case GEOM_SOLID_THICK:
392 isOk = myThicknessSpin->isValid(msg, !IsPreview()) && myObject;
394 case GEOM_SOLID_HOLLOWED:
395 isOk = myThicknessSpin->isValid(msg, !IsPreview()) &&
396 myObject && !myFaces.empty();
405 //==============================================================================
406 // function : onChangeDirection(bool)
408 //==============================================================================
409 void GenerationGUI_ThicknessDlg::onChangeDirection(bool)
414 //==============================================================================
415 // function : execute
417 //==============================================================================
418 bool GenerationGUI_ThicknessDlg::execute (ObjectList& objects)
420 GEOM::GEOM_Object_var anObj;
421 GEOM::GEOM_I3DPrimOperations_var anOper =
422 GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
423 double aThickness = myThicknessSpin->value();
424 bool anInside = myInsideCheck->isChecked();
425 GEOM::ListOfLong_var anObjIDsList = new GEOM::ListOfLong();
428 if (GEOMBase::GetShape(myObject.get(), aShape)) {
429 TopTools_IndexedMapOfShape aMainMap;
432 TopExp::MapShapes(aShape, aMainMap);
434 for (int i = 0; i < myFaces.count(); i++) {
437 if (GEOMBase::GetShape(myFaces[i].get(), aFace)) {
438 int anIndex = aMainMap.FindIndex(aFace);
447 if (!aListIDs.empty()) {
448 anObjIDsList->length(aListIDs.length());
450 for (int i = 0; i < aListIDs.length(); i++) {
451 anObjIDsList[i] = aListIDs[i];
456 anObj = anOper->MakeThickening
457 (myObject.get(), anObjIDsList.in(), aThickness, true, anInside);
459 if (!anObj->_is_nil()) {
461 QStringList aParameters;
462 aParameters << myThicknessSpin->text();
463 anObj->SetParameters(aParameters.join(":").toUtf8().constData());
465 objects.push_back(anObj._retn());
471 //=================================================================================
472 // function : getSourceObjects
473 // purpose : virtual method to get source objects
474 //=================================================================================
475 QList<GEOM::GeomObjPtr> GenerationGUI_ThicknessDlg::getSourceObjects()
477 QList<GEOM::GeomObjPtr> res(myFaces);