Salome HOME
ae4828de1b4d65b5c2db42e308e59bd61fe8c692
[modules/geom.git] / src / GenerationGUI / GenerationGUI_FillingDlg.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : GenerationGUI_FillingDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26
27 #include "GenerationGUI_FillingDlg.h"
28
29 #include <DlgRef.h>
30 #include <GeometryGUI.h>
31 #include <GEOMBase.h>
32
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_Session.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
37
38 #include <TopoDS_Iterator.hxx>
39 #include <GEOMImpl_Types.hxx>
40
41 //=================================================================================
42 // class    : GenerationGUI_FillingDlg()
43 // purpose  : Constructs a GenerationGUI_FillingDlg which is a child of 'parent', with the
44 //            name 'name' and widget flags set to 'f'.
45 //            The dialog will by default be modeless, unless you set 'modal' to
46 //            TRUE to construct a modal dialog.
47 //=================================================================================
48 GenerationGUI_FillingDlg::GenerationGUI_FillingDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
49                                                     bool modal, Qt::WindowFlags fl)
50   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
51 {
52   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FILLING")));
53   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
54
55   setWindowTitle(tr("GEOM_FILLING_TITLE"));
56
57   /***************************************************************/
58   mainFrame()->GroupConstructors->setTitle(tr ("GEOM_FILLING"));
59   mainFrame()->RadioButton1->setIcon(image0);
60   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
61   mainFrame()->RadioButton2->close();
62   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
63   mainFrame()->RadioButton3->close();
64
65   GroupPoints = new DlgRef_1Sel5Spin1Check(centralWidget());
66   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
67   GroupPoints->TextLabel1->setText(tr("GEOM_FILLING_COMPOUND"));
68   GroupPoints->TextLabel2->setText(tr("GEOM_FILLING_MIN_DEG"));
69   GroupPoints->TextLabel3->setText(tr("GEOM_FILLING_TOL_2D"));
70   GroupPoints->TextLabel4->setText(tr("GEOM_FILLING_NB_ITER"));
71   GroupPoints->TextLabel5->setText(tr("GEOM_FILLING_MAX_DEG"));
72   GroupPoints->TextLabel6->setText(tr("GEOM_FILLING_TOL_3D"));
73   GroupPoints->CheckBox1->setText(tr("GEOM_FILLING_APPROX"));
74   GroupPoints->TextLabel7->setText(tr("GEOM_FILLING_METHOD"));
75   GroupPoints->PushButton1->setIcon(image1);
76   GroupPoints->LineEdit1->setReadOnly(true);
77
78   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
79   layout->setMargin(0); layout->setSpacing(6);
80   layout->addWidget(GroupPoints);
81   /***************************************************************/
82
83   setHelpFileName("create_filling_page.html");
84
85   /* Initialisations */
86   Init();
87 }
88
89 //=================================================================================
90 // function : ~GenerationGUI_FillingDlg()
91 // purpose  : Destroys the object and frees any allocated resources
92 //=================================================================================
93 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
94 {
95   // no need to delete child widgets, Qt does it all for us
96 }
97
98 //=================================================================================
99 // function : Init()
100 // purpose  :
101 //=================================================================================
102 void GenerationGUI_FillingDlg::Init()
103 {
104   /* init variables */
105   myEditCurrentArgument = GroupPoints->LineEdit1;
106   GroupPoints->LineEdit1->setReadOnly(true);
107
108   globalSelection(GEOM_COMPOUND);
109
110   int SpecificStep1 = 1;
111   double SpecificStep2 = 0.0001;
112   /* min, max, step and decimals for spin boxes & initial values */
113   initSpinBox(GroupPoints->SpinBox1, 2, MAX_NUMBER,  SpecificStep1);
114   initSpinBox(GroupPoints->SpinBox2, 0.00001, 10000.0, SpecificStep2, "len_tol_precision");
115   initSpinBox(GroupPoints->SpinBox3, 0, MAX_NUMBER,  SpecificStep1);
116   initSpinBox(GroupPoints->SpinBox4, 1, MAX_NUMBER,  SpecificStep1);
117   initSpinBox(GroupPoints->SpinBox5, 0.00001, 10000.0, SpecificStep2, "len_tol_precision");
118
119   GroupPoints->SpinBox1->setValue(2);
120   GroupPoints->SpinBox2->setValue(0.0001);
121   GroupPoints->SpinBox3->setValue(0);
122   GroupPoints->SpinBox4->setValue(5);
123   GroupPoints->SpinBox5->setValue(0.0001);
124
125   GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_DEFAULT"));
126   GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_USEORI"));
127   GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_AUTO"));
128
129   showOnlyPreviewControl();
130
131   /* signals and slots connections */
132   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
133   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
134
135   connect(GroupPoints->PushButton1, SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
136
137   connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(MethodChanged()));
138
139   connect(GroupPoints->SpinBox1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
140   connect(GroupPoints->SpinBox2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
141   connect(GroupPoints->SpinBox3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
142   connect(GroupPoints->SpinBox4, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
143   connect(GroupPoints->SpinBox5, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
144
145   connect(GroupPoints->CheckBox1, SIGNAL(stateChanged(int)),
146            this, SLOT(ApproxChanged()));
147
148   // san: Commented, as all spin boxes here either are integer or use specific non-default step value
149   //connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
150
151   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
152            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
153
154   initName(tr("GEOM_FILLING"));
155   resize(100,100);
156 }
157
158 //=================================================================================
159 // function : SetDoubleSpinBoxStep()
160 // purpose  : Double spin box management
161 //=================================================================================
162 void GenerationGUI_FillingDlg::SetDoubleSpinBoxStep(double step)
163 {
164   GroupPoints->SpinBox2->setSingleStep(step);
165   GroupPoints->SpinBox5->setSingleStep(step);
166 }
167
168 //=================================================================================
169 // function : ClickOnOk()
170 // purpose  :
171 //=================================================================================
172 void GenerationGUI_FillingDlg::ClickOnOk()
173 {
174   setIsApplyAndClose(true);
175   if (ClickOnApply())
176     ClickOnCancel();
177 }
178
179 //=================================================================================
180 // function : ClickOnApply()
181 // purpose  :
182 //=================================================================================
183 bool GenerationGUI_FillingDlg::ClickOnApply()
184 {
185   if (!onAccept())
186     return false;
187
188   initName();
189   return true;
190 }
191
192 //=================================================================================
193 // function : SelectionIntoArgument()
194 // purpose  : Called when selection as changed or other case
195 //=================================================================================
196 void GenerationGUI_FillingDlg::SelectionIntoArgument()
197 {
198   erasePreview();
199   myEditCurrentArgument->setText("");
200
201   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
202     myCompound = getSelected(TopAbs_COMPOUND);
203     if (myCompound) {
204       if (myCompound->GetMaxShapeType() < GEOM::WIRE || myCompound->GetMinShapeType() > GEOM::EDGE) {
205         myCompound.nullify();
206       }
207       else {
208         QString aName = GEOMBase::GetName(myCompound.get());
209         myEditCurrentArgument->setText(aName);
210       }
211     }
212   }
213
214   processPreview();
215 }
216
217 //=================================================================================
218 // function : SetEditCurrentArgument()
219 // purpose  :
220 //=================================================================================
221 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
222 {
223   QPushButton* send = (QPushButton*)sender();
224   globalSelection(GEOM_ALLSHAPES);
225
226   if (send == GroupPoints->PushButton1) {
227     GroupPoints->LineEdit1->setFocus();
228     myEditCurrentArgument = GroupPoints->LineEdit1;
229     globalSelection(GEOM_COMPOUND);
230     this->SelectionIntoArgument();
231   }
232 }
233
234 //=================================================================================
235 // function : ActivateThisDialog()
236 // purpose  :
237 //=================================================================================
238 void GenerationGUI_FillingDlg::ActivateThisDialog()
239 {
240   GEOMBase_Skeleton::ActivateThisDialog();
241   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
242            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
243   globalSelection(GEOM_COMPOUND);
244   processPreview();
245 }
246
247 //=================================================================================
248 // function : enterEvent()
249 // purpose  :
250 //=================================================================================
251 void GenerationGUI_FillingDlg::enterEvent(QEvent*)
252 {
253   if (!mainFrame()->GroupConstructors->isEnabled())
254     ActivateThisDialog();
255 }
256
257 //=================================================================================
258 // function : ValueChangedInSpinBox()
259 // purpose  :
260 //=================================================================================
261 void GenerationGUI_FillingDlg::ValueChangedInSpinBox(double newValue)
262 {
263   processPreview();
264 }
265
266 //=================================================================================
267 // function : MethodChanged
268 // purpose  :
269 //=================================================================================
270 void GenerationGUI_FillingDlg::MethodChanged()
271 {
272   processPreview();
273 }
274
275 //=================================================================================
276 // function : ApproxChanged()
277 // purpose  :
278 //=================================================================================
279 void GenerationGUI_FillingDlg::ApproxChanged()
280 {
281   if (GroupPoints->CheckBox1->isChecked()) {
282     // tol2d
283     GroupPoints->TextLabel3->setEnabled(false);
284     GroupPoints->SpinBox2->setEnabled(false);
285     // nbIter
286     GroupPoints->TextLabel4->setEnabled(false);
287     GroupPoints->SpinBox3->setEnabled(false);
288     // method
289     GroupPoints->TextLabel7->setEnabled(false);
290     GroupPoints->ComboBox1->setEnabled(false);
291   }
292   else {
293     // tol2d
294     GroupPoints->TextLabel3->setEnabled(true);
295     GroupPoints->SpinBox2->setEnabled(true);
296     // nbIter
297     GroupPoints->TextLabel4->setEnabled(true);
298     GroupPoints->SpinBox3->setEnabled(true);
299     // method
300     GroupPoints->TextLabel7->setEnabled(true);
301     GroupPoints->ComboBox1->setEnabled(true);
302   }
303
304   processPreview();
305 }
306
307 //=================================================================================
308 // function : createOperation
309 // purpose  :
310 //=================================================================================
311 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
312 {
313   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
314 }
315
316 //=================================================================================
317 // function : isValid
318 // purpose  :
319 //=================================================================================
320 bool GenerationGUI_FillingDlg::isValid(QString& msg)
321 {
322   bool ok = GroupPoints->SpinBox1->isValid(msg, !IsPreview()) &&
323             GroupPoints->SpinBox2->isValid(msg, !IsPreview()) &&
324             GroupPoints->SpinBox3->isValid(msg, !IsPreview()) &&
325             GroupPoints->SpinBox4->isValid(msg, !IsPreview()) &&
326             GroupPoints->SpinBox5->isValid(msg, !IsPreview()) &&
327             myCompound;
328   return ok;
329 }
330
331 //=================================================================================
332 // function : execute
333 // purpose  :
334 //=================================================================================
335 bool GenerationGUI_FillingDlg::execute(ObjectList& objects)
336 {
337   GEOM::GEOM_I3DPrimOperations_var anOper =
338     GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
339
340   GEOM::filling_oper_method aMethod;
341   switch (GroupPoints->ComboBox1->currentIndex())
342   {
343     case 0:  aMethod = GEOM::FOM_Default; break;
344     case 1:  aMethod = GEOM::FOM_UseOri; break;
345     case 2:  aMethod = GEOM::FOM_AutoCorrect; break;
346     default: break;
347   }
348
349   GEOM::GEOM_Object_var anObj =
350     anOper->MakeFilling(myCompound.get(),
351                          GroupPoints->SpinBox1->value(),
352                          GroupPoints->SpinBox4->value(),
353                          GroupPoints->SpinBox2->value(),
354                          GroupPoints->SpinBox5->value(),
355                          GroupPoints->SpinBox3->value(),
356                          aMethod,
357                          GroupPoints->CheckBox1->isChecked());
358   if (!anObj->_is_nil())
359   {
360     if (!IsPreview())
361     {
362       QStringList aParameters;
363       aParameters << GroupPoints->SpinBox1->text();
364       aParameters << GroupPoints->SpinBox2->text();
365       aParameters << GroupPoints->SpinBox3->text();
366       aParameters << GroupPoints->SpinBox4->text();
367       aParameters << GroupPoints->SpinBox5->text();
368       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
369     }
370     objects.push_back(anObj._retn());
371   }
372
373   return true;
374 }