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_FillingDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "GenerationGUI_FillingDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_Session.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <TColStd_MapOfInteger.hxx>
40 #include <GEOMImpl_Types.hxx>
42 //=================================================================================
43 // class : GenerationGUI_FillingDlg()
44 // purpose : Constructs a GenerationGUI_FillingDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 GenerationGUI_FillingDlg::GenerationGUI_FillingDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
50 bool modal, Qt::WindowFlags fl)
51 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
53 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FILLING")));
54 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
56 setWindowTitle(tr("GEOM_FILLING_TITLE"));
58 /***************************************************************/
59 mainFrame()->GroupConstructors->setTitle(tr ("GEOM_FILLING"));
60 mainFrame()->RadioButton1->setIcon(image0);
61 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
62 mainFrame()->RadioButton2->close();
63 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
64 mainFrame()->RadioButton3->close();
66 GroupPoints = new DlgRef_1Sel5Spin1Check(centralWidget());
67 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_FILLING_COMPOUND"));
69 GroupPoints->TextLabel2->setText(tr("GEOM_FILLING_MIN_DEG"));
70 GroupPoints->TextLabel3->setText(tr("GEOM_FILLING_TOL_2D"));
71 GroupPoints->TextLabel4->setText(tr("GEOM_FILLING_NB_ITER"));
72 GroupPoints->TextLabel5->setText(tr("GEOM_FILLING_MAX_DEG"));
73 GroupPoints->TextLabel6->setText(tr("GEOM_FILLING_TOL_3D"));
74 GroupPoints->CheckBox1->setText(tr("GEOM_FILLING_APPROX"));
75 GroupPoints->TextLabel7->setText(tr("GEOM_FILLING_METHOD"));
76 GroupPoints->PushButton1->setIcon(image1);
77 GroupPoints->LineEdit1->setReadOnly(true);
79 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
80 layout->setMargin(0); layout->setSpacing(6);
81 layout->addWidget(GroupPoints);
82 /***************************************************************/
84 setHelpFileName("create_filling_page.html");
90 //=================================================================================
91 // function : ~GenerationGUI_FillingDlg()
92 // purpose : Destroys the object and frees any allocated resources
93 //=================================================================================
94 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
96 // no need to delete child widgets, Qt does it all for us
99 //=================================================================================
102 //=================================================================================
103 void GenerationGUI_FillingDlg::Init()
106 myEditCurrentArgument = GroupPoints->LineEdit1;
107 GroupPoints->LineEdit1->setReadOnly(true);
111 int SpecificStep1 = 1;
112 double SpecificStep2 = 0.0001;
113 /* min, max, step and decimals for spin boxes & initial values */
114 initSpinBox(GroupPoints->SpinBox1, 2, MAX_NUMBER, SpecificStep1);
115 initSpinBox(GroupPoints->SpinBox2, 0.00001, 10000.0, SpecificStep2, "len_tol_precision");
116 initSpinBox(GroupPoints->SpinBox3, 0, MAX_NUMBER, SpecificStep1);
117 initSpinBox(GroupPoints->SpinBox4, 1, MAX_NUMBER, SpecificStep1);
118 initSpinBox(GroupPoints->SpinBox5, 0.00001, 10000.0, SpecificStep2, "len_tol_precision");
120 GroupPoints->SpinBox1->setValue(2);
121 GroupPoints->SpinBox2->setValue(0.0001);
122 GroupPoints->SpinBox3->setValue(0);
123 GroupPoints->SpinBox4->setValue(5);
124 GroupPoints->SpinBox5->setValue(0.0001);
126 GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_DEFAULT"));
127 GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_USEORI"));
128 GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_AUTO"));
130 showOnlyPreviewControl();
132 /* signals and slots connections */
133 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
134 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
136 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(MethodChanged()));
140 connect(GroupPoints->SpinBox1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
141 connect(GroupPoints->SpinBox2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
142 connect(GroupPoints->SpinBox3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
143 connect(GroupPoints->SpinBox4, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
144 connect(GroupPoints->SpinBox5, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
146 connect(GroupPoints->CheckBox1, SIGNAL(stateChanged(int)),
147 this, SLOT(ApproxChanged()));
149 // san: Commented, as all spin boxes here either are integer or use specific non-default step value
150 //connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
152 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
153 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
155 initName(tr("GEOM_FILLING"));
159 //=================================================================================
160 // function : SetDoubleSpinBoxStep()
161 // purpose : Double spin box management
162 //=================================================================================
163 void GenerationGUI_FillingDlg::SetDoubleSpinBoxStep(double step)
165 GroupPoints->SpinBox2->setSingleStep(step);
166 GroupPoints->SpinBox5->setSingleStep(step);
169 //=================================================================================
170 // function : ClickOnOk()
172 //=================================================================================
173 void GenerationGUI_FillingDlg::ClickOnOk()
175 setIsApplyAndClose(true);
180 //=================================================================================
181 // function : ClickOnApply()
183 //=================================================================================
184 bool GenerationGUI_FillingDlg::ClickOnApply()
195 //=================================================================================
196 // function : initSelection
198 //=================================================================================
199 void GenerationGUI_FillingDlg::initSelection()
201 TColStd_MapOfInteger aTypes;
202 aTypes.Add( GEOM_EDGE );
203 aTypes.Add( GEOM_WIRE );
204 aTypes.Add( GEOM_COMPOUND );
206 std::list<int> needTypes;
207 needTypes.push_back( TopAbs_EDGE );
208 needTypes.push_back( TopAbs_WIRE );
209 needTypes.push_back( TopAbs_COMPOUND );
211 globalSelection( aTypes );
212 localSelection( needTypes );
215 //=================================================================================
216 // function : SelectionIntoArgument()
217 // purpose : Called when selection as changed or other case
218 //=================================================================================
219 void GenerationGUI_FillingDlg::SelectionIntoArgument()
222 myEditCurrentArgument->setText("");
224 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
225 QList<GEOM::GeomObjPtr> objs = getSelected(TopAbs_SHAPE, -1);
226 GEOMBase::Synchronize(myObjects, objs);
227 if ( !myObjects.isEmpty() ) {
228 QString aName = myObjects.count() > 1 ? QString( "%1_objects").arg( myObjects.count() ) : GEOMBase::GetName( myObjects[0].get() );
229 myEditCurrentArgument->setText( aName );
235 //=================================================================================
236 // function : SetEditCurrentArgument()
238 //=================================================================================
239 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
241 QPushButton* send = (QPushButton*)sender();
243 if (send == GroupPoints->PushButton1) {
244 GroupPoints->LineEdit1->setFocus();
245 myEditCurrentArgument = GroupPoints->LineEdit1;
247 this->SelectionIntoArgument();
251 //=================================================================================
252 // function : ActivateThisDialog()
254 //=================================================================================
255 void GenerationGUI_FillingDlg::ActivateThisDialog()
257 GEOMBase_Skeleton::ActivateThisDialog();
258 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
259 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
264 //=================================================================================
265 // function : enterEvent()
267 //=================================================================================
268 void GenerationGUI_FillingDlg::enterEvent(QEvent*)
270 if (!mainFrame()->GroupConstructors->isEnabled())
271 ActivateThisDialog();
274 //=================================================================================
275 // function : ValueChangedInSpinBox()
277 //=================================================================================
278 void GenerationGUI_FillingDlg::ValueChangedInSpinBox(double newValue)
283 //=================================================================================
284 // function : MethodChanged
286 //=================================================================================
287 void GenerationGUI_FillingDlg::MethodChanged()
292 //=================================================================================
293 // function : ApproxChanged()
295 //=================================================================================
296 void GenerationGUI_FillingDlg::ApproxChanged()
298 if (GroupPoints->CheckBox1->isChecked()) {
300 GroupPoints->TextLabel3->setEnabled(false);
301 GroupPoints->SpinBox2->setEnabled(false);
303 GroupPoints->TextLabel4->setEnabled(false);
304 GroupPoints->SpinBox3->setEnabled(false);
306 GroupPoints->TextLabel7->setEnabled(false);
307 GroupPoints->ComboBox1->setEnabled(false);
311 GroupPoints->TextLabel3->setEnabled(true);
312 GroupPoints->SpinBox2->setEnabled(true);
314 GroupPoints->TextLabel4->setEnabled(true);
315 GroupPoints->SpinBox3->setEnabled(true);
317 GroupPoints->TextLabel7->setEnabled(true);
318 GroupPoints->ComboBox1->setEnabled(true);
324 //=================================================================================
325 // function : createOperation
327 //=================================================================================
328 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
330 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
333 //=================================================================================
334 // function : isValid
336 //=================================================================================
337 bool GenerationGUI_FillingDlg::isValid(QString& msg)
339 bool ok = ( GroupPoints->SpinBox1->isValid(msg, !IsPreview()) &&
340 GroupPoints->SpinBox2->isValid(msg, !IsPreview()) &&
341 GroupPoints->SpinBox3->isValid(msg, !IsPreview()) &&
342 GroupPoints->SpinBox4->isValid(msg, !IsPreview()) &&
343 GroupPoints->SpinBox5->isValid(msg, !IsPreview()) &&
348 //=================================================================================
349 // function : execute
351 //=================================================================================
352 bool GenerationGUI_FillingDlg::execute(ObjectList& objects)
354 GEOM::GEOM_I3DPrimOperations_var anOper =
355 GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
357 GEOM::filling_oper_method aMethod;
358 switch (GroupPoints->ComboBox1->currentIndex())
360 case 0: aMethod = GEOM::FOM_Default; break;
361 case 1: aMethod = GEOM::FOM_UseOri; break;
362 case 2: aMethod = GEOM::FOM_AutoCorrect; break;
366 GEOM::ListOfGO_var objList = new GEOM::ListOfGO;
367 objList->length( myObjects.count() );
368 for ( int i = 0; i < myObjects.count(); ++i )
369 objList[i] = myObjects[i].copy();
371 GEOM::GEOM_Object_var anObj =
372 anOper->MakeFilling(objList,
373 GroupPoints->SpinBox1->value(),
374 GroupPoints->SpinBox4->value(),
375 GroupPoints->SpinBox2->value(),
376 GroupPoints->SpinBox5->value(),
377 GroupPoints->SpinBox3->value(),
379 GroupPoints->CheckBox1->isChecked());
380 if (!anObj->_is_nil())
384 QStringList aParameters;
385 aParameters << GroupPoints->SpinBox1->text();
386 aParameters << GroupPoints->SpinBox2->text();
387 aParameters << GroupPoints->SpinBox3->text();
388 aParameters << GroupPoints->SpinBox4->text();
389 aParameters << GroupPoints->SpinBox5->text();
390 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
392 objects.push_back(anObj._retn());
398 //=================================================================================
399 // function : addSubshapesToStudy
400 // purpose : virtual method to add new SubObjects if local selection
401 //=================================================================================
402 void GenerationGUI_FillingDlg::addSubshapesToStudy()
404 foreach( GEOM::GeomObjPtr o, myObjects )
405 GEOMBase::PublishSubObject( o.get() );
408 //=================================================================================
409 // function : getSourceObjects
410 // purpose : virtual method to get source objects
411 //=================================================================================
412 QList<GEOM::GeomObjPtr> GenerationGUI_FillingDlg::getSourceObjects()