1 // Copyright (C) 2007-2012 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.
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 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GenerationGUI_FillingDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "GenerationGUI_FillingDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <TopoDS_Iterator.hxx>
38 #include <GEOMImpl_Types.hxx>
40 //=================================================================================
41 // class : GenerationGUI_FillingDlg()
42 // purpose : Constructs a GenerationGUI_FillingDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 GenerationGUI_FillingDlg::GenerationGUI_FillingDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
48 bool modal, Qt::WindowFlags fl)
49 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
51 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FILLING")));
52 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
54 setWindowTitle(tr("GEOM_FILLING_TITLE"));
56 /***************************************************************/
57 mainFrame()->GroupConstructors->setTitle(tr ("GEOM_FILLING"));
58 mainFrame()->RadioButton1->setIcon(image0);
59 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
60 mainFrame()->RadioButton2->close();
61 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
62 mainFrame()->RadioButton3->close();
64 GroupPoints = new DlgRef_1Sel5Spin1Check(centralWidget());
65 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
66 GroupPoints->TextLabel1->setText(tr("GEOM_FILLING_COMPOUND"));
67 GroupPoints->TextLabel2->setText(tr("GEOM_FILLING_MIN_DEG"));
68 GroupPoints->TextLabel3->setText(tr("GEOM_FILLING_TOL_2D"));
69 GroupPoints->TextLabel4->setText(tr("GEOM_FILLING_NB_ITER"));
70 GroupPoints->TextLabel5->setText(tr("GEOM_FILLING_MAX_DEG"));
71 GroupPoints->TextLabel6->setText(tr("GEOM_FILLING_TOL_3D"));
72 GroupPoints->CheckBox1->setText(tr("GEOM_FILLING_APPROX"));
73 GroupPoints->TextLabel7->setText(tr("GEOM_FILLING_METHOD"));
74 GroupPoints->PushButton1->setIcon(image1);
75 GroupPoints->LineEdit1->setReadOnly(true);
77 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
78 layout->setMargin(0); layout->setSpacing(6);
79 layout->addWidget(GroupPoints);
80 /***************************************************************/
82 setHelpFileName("create_filling_page.html");
88 //=================================================================================
89 // function : ~GenerationGUI_FillingDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
94 // no need to delete child widgets, Qt does it all for us
97 //=================================================================================
100 //=================================================================================
101 void GenerationGUI_FillingDlg::Init()
104 myEditCurrentArgument = GroupPoints->LineEdit1;
105 GroupPoints->LineEdit1->setReadOnly(true);
107 globalSelection(GEOM_COMPOUND);
109 int SpecificStep1 = 1;
110 double SpecificStep2 = 0.0001;
111 /* min, max, step and decimals for spin boxes & initial values */
112 initSpinBox(GroupPoints->SpinBox1, 2, MAX_NUMBER, SpecificStep1);
113 initSpinBox(GroupPoints->SpinBox2, 0.00001, 10000.0, SpecificStep2, "len_tol_precision");
114 initSpinBox(GroupPoints->SpinBox3, 0, MAX_NUMBER, SpecificStep1);
115 initSpinBox(GroupPoints->SpinBox4, 1, MAX_NUMBER, SpecificStep1);
116 initSpinBox(GroupPoints->SpinBox5, 0.00001, 10000.0, SpecificStep2, "len_tol_precision");
118 GroupPoints->SpinBox1->setValue(2);
119 GroupPoints->SpinBox2->setValue(0.0001);
120 GroupPoints->SpinBox3->setValue(0);
121 GroupPoints->SpinBox4->setValue(5);
122 GroupPoints->SpinBox5->setValue(0.0001);
124 GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_DEFAULT"));
125 GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_USEORI"));
126 GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_AUTO"));
128 showOnlyPreviewControl();
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()));
136 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(MethodChanged()));
138 connect(GroupPoints->SpinBox1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
139 connect(GroupPoints->SpinBox2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
140 connect(GroupPoints->SpinBox3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
141 connect(GroupPoints->SpinBox4, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
142 connect(GroupPoints->SpinBox5, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
144 connect(GroupPoints->CheckBox1, SIGNAL(stateChanged(int)),
145 this, SLOT(ApproxChanged()));
147 // san: Commented, as all spin boxes here either are integer or use specific non-default step value
148 //connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
150 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
151 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
153 initName(tr("GEOM_FILLING"));
157 //=================================================================================
158 // function : SetDoubleSpinBoxStep()
159 // purpose : Double spin box management
160 //=================================================================================
161 void GenerationGUI_FillingDlg::SetDoubleSpinBoxStep(double step)
163 GroupPoints->SpinBox2->setSingleStep(step);
164 GroupPoints->SpinBox5->setSingleStep(step);
167 //=================================================================================
168 // function : ClickOnOk()
170 //=================================================================================
171 void GenerationGUI_FillingDlg::ClickOnOk()
173 setIsApplyAndClose(true);
178 //=================================================================================
179 // function : ClickOnApply()
181 //=================================================================================
182 bool GenerationGUI_FillingDlg::ClickOnApply()
191 //=================================================================================
192 // function : SelectionIntoArgument()
193 // purpose : Called when selection as changed or other case
194 //=================================================================================
195 void GenerationGUI_FillingDlg::SelectionIntoArgument()
198 myEditCurrentArgument->setText("");
200 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
201 myCompound = getSelected(TopAbs_COMPOUND);
203 if (myCompound->GetMaxShapeType() < GEOM::WIRE || myCompound->GetMinShapeType() > GEOM::EDGE) {
204 myCompound.nullify();
207 QString aName = GEOMBase::GetName(myCompound.get());
208 myEditCurrentArgument->setText(aName);
216 //=================================================================================
217 // function : SetEditCurrentArgument()
219 //=================================================================================
220 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
222 QPushButton* send = (QPushButton*)sender();
223 globalSelection(GEOM_ALLSHAPES);
225 if (send == GroupPoints->PushButton1) {
226 GroupPoints->LineEdit1->setFocus();
227 myEditCurrentArgument = GroupPoints->LineEdit1;
228 globalSelection(GEOM_COMPOUND);
229 this->SelectionIntoArgument();
233 //=================================================================================
234 // function : ActivateThisDialog()
236 //=================================================================================
237 void GenerationGUI_FillingDlg::ActivateThisDialog()
239 GEOMBase_Skeleton::ActivateThisDialog();
240 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
241 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
242 globalSelection(GEOM_COMPOUND);
246 //=================================================================================
247 // function : enterEvent()
249 //=================================================================================
250 void GenerationGUI_FillingDlg::enterEvent(QEvent*)
252 if (!mainFrame()->GroupConstructors->isEnabled())
253 ActivateThisDialog();
256 //=================================================================================
257 // function : ValueChangedInSpinBox()
259 //=================================================================================
260 void GenerationGUI_FillingDlg::ValueChangedInSpinBox(double newValue)
265 //=================================================================================
266 // function : MethodChanged
268 //=================================================================================
269 void GenerationGUI_FillingDlg::MethodChanged()
274 //=================================================================================
275 // function : ApproxChanged()
277 //=================================================================================
278 void GenerationGUI_FillingDlg::ApproxChanged()
280 if (GroupPoints->CheckBox1->isChecked()) {
282 GroupPoints->TextLabel3->setEnabled(false);
283 GroupPoints->SpinBox2->setEnabled(false);
285 GroupPoints->TextLabel4->setEnabled(false);
286 GroupPoints->SpinBox3->setEnabled(false);
288 GroupPoints->TextLabel7->setEnabled(false);
289 GroupPoints->ComboBox1->setEnabled(false);
293 GroupPoints->TextLabel3->setEnabled(true);
294 GroupPoints->SpinBox2->setEnabled(true);
296 GroupPoints->TextLabel4->setEnabled(true);
297 GroupPoints->SpinBox3->setEnabled(true);
299 GroupPoints->TextLabel7->setEnabled(true);
300 GroupPoints->ComboBox1->setEnabled(true);
306 //=================================================================================
307 // function : createOperation
309 //=================================================================================
310 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
312 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
315 //=================================================================================
316 // function : isValid
318 //=================================================================================
319 bool GenerationGUI_FillingDlg::isValid(QString& msg)
321 bool ok = GroupPoints->SpinBox1->isValid(msg, !IsPreview()) &&
322 GroupPoints->SpinBox2->isValid(msg, !IsPreview()) &&
323 GroupPoints->SpinBox3->isValid(msg, !IsPreview()) &&
324 GroupPoints->SpinBox4->isValid(msg, !IsPreview()) &&
325 GroupPoints->SpinBox5->isValid(msg, !IsPreview()) &&
330 //=================================================================================
331 // function : execute
333 //=================================================================================
334 bool GenerationGUI_FillingDlg::execute(ObjectList& objects)
336 GEOM::GEOM_I3DPrimOperations_var anOper =
337 GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
339 GEOM::filling_oper_method aMethod;
340 switch (GroupPoints->ComboBox1->currentIndex())
342 case 0: aMethod = GEOM::FOM_Default; break;
343 case 1: aMethod = GEOM::FOM_UseOri; break;
344 case 2: aMethod = GEOM::FOM_AutoCorrect; break;
348 GEOM::GEOM_Object_var anObj =
349 anOper->MakeFilling(myCompound.get(),
350 GroupPoints->SpinBox1->value(),
351 GroupPoints->SpinBox4->value(),
352 GroupPoints->SpinBox2->value(),
353 GroupPoints->SpinBox5->value(),
354 GroupPoints->SpinBox3->value(),
356 GroupPoints->CheckBox1->isChecked());
357 if (!anObj->_is_nil())
361 QStringList aParameters;
362 aParameters << GroupPoints->SpinBox1->text();
363 aParameters << GroupPoints->SpinBox2->text();
364 aParameters << GroupPoints->SpinBox3->text();
365 aParameters << GroupPoints->SpinBox4->text();
366 aParameters << GroupPoints->SpinBox5->text();
367 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
369 objects.push_back(anObj._retn());