Salome HOME
cee8cec19bb71a7a35a4a9f66079a41f65e7f92b
[modules/geom.git] / src / GenerationGUI / GenerationGUI_FillingDlg.cxx
1 // Copyright (C) 2007-2012  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 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : GenerationGUI_FillingDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25
26 #include "GenerationGUI_FillingDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36
37 #include <TopoDS_Iterator.hxx>
38 #include <GEOMImpl_Types.hxx>
39
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)
50 {
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")));
53
54   setWindowTitle(tr("GEOM_FILLING_TITLE"));
55
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();
63
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);
76
77   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
78   layout->setMargin(0); layout->setSpacing(6);
79   layout->addWidget(GroupPoints);
80   /***************************************************************/
81
82   setHelpFileName("create_filling_page.html");
83
84   /* Initialisations */
85   Init();
86 }
87
88 //=================================================================================
89 // function : ~GenerationGUI_FillingDlg()
90 // purpose  : Destroys the object and frees any allocated resources
91 //=================================================================================
92 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
93 {
94   // no need to delete child widgets, Qt does it all for us
95 }
96
97 //=================================================================================
98 // function : Init()
99 // purpose  :
100 //=================================================================================
101 void GenerationGUI_FillingDlg::Init()
102 {
103   /* init variables */
104   myEditCurrentArgument = GroupPoints->LineEdit1;
105   GroupPoints->LineEdit1->setReadOnly(true);
106
107   globalSelection(GEOM_COMPOUND);
108
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");
117
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);
123
124   GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_DEFAULT"));
125   GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_USEORI"));
126   GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_AUTO"));
127
128   showOnlyPreviewControl();
129
130   /* signals and slots connections */
131   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
132   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
133
134   connect(GroupPoints->PushButton1, SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
135
136   connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(MethodChanged()));
137
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)));
143
144   connect(GroupPoints->CheckBox1, SIGNAL(stateChanged(int)),
145            this, SLOT(ApproxChanged()));
146
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)));
149
150   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
151            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
152
153   initName(tr("GEOM_FILLING"));
154   resize(100,100);
155 }
156
157 //=================================================================================
158 // function : SetDoubleSpinBoxStep()
159 // purpose  : Double spin box management
160 //=================================================================================
161 void GenerationGUI_FillingDlg::SetDoubleSpinBoxStep(double step)
162 {
163   GroupPoints->SpinBox2->setSingleStep(step);
164   GroupPoints->SpinBox5->setSingleStep(step);
165 }
166
167 //=================================================================================
168 // function : ClickOnOk()
169 // purpose  :
170 //=================================================================================
171 void GenerationGUI_FillingDlg::ClickOnOk()
172 {
173   setIsApplyAndClose(true);
174   if (ClickOnApply())
175     ClickOnCancel();
176 }
177
178 //=================================================================================
179 // function : ClickOnApply()
180 // purpose  :
181 //=================================================================================
182 bool GenerationGUI_FillingDlg::ClickOnApply()
183 {
184   if (!onAccept())
185     return false;
186
187   initName();
188   return true;
189 }
190
191 //=================================================================================
192 // function : SelectionIntoArgument()
193 // purpose  : Called when selection as changed or other case
194 //=================================================================================
195 void GenerationGUI_FillingDlg::SelectionIntoArgument()
196 {
197   erasePreview();
198   myEditCurrentArgument->setText("");
199
200   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
201     myCompound = getSelected(TopAbs_COMPOUND);
202     if (myCompound) {
203       if (myCompound->GetMaxShapeType() < GEOM::WIRE || myCompound->GetMinShapeType() > GEOM::EDGE) {
204         myCompound.nullify();
205       }
206       else {
207         QString aName = GEOMBase::GetName(myCompound.get());
208         myEditCurrentArgument->setText(aName);
209       }
210     }
211   }
212
213   processPreview();
214 }
215
216 //=================================================================================
217 // function : SetEditCurrentArgument()
218 // purpose  :
219 //=================================================================================
220 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
221 {
222   QPushButton* send = (QPushButton*)sender();
223   globalSelection(GEOM_ALLSHAPES);
224
225   if (send == GroupPoints->PushButton1) {
226     GroupPoints->LineEdit1->setFocus();
227     myEditCurrentArgument = GroupPoints->LineEdit1;
228     globalSelection(GEOM_COMPOUND);
229     this->SelectionIntoArgument();
230   }
231 }
232
233 //=================================================================================
234 // function : ActivateThisDialog()
235 // purpose  :
236 //=================================================================================
237 void GenerationGUI_FillingDlg::ActivateThisDialog()
238 {
239   GEOMBase_Skeleton::ActivateThisDialog();
240   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
241            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
242   globalSelection(GEOM_COMPOUND);
243   processPreview();
244 }
245
246 //=================================================================================
247 // function : enterEvent()
248 // purpose  :
249 //=================================================================================
250 void GenerationGUI_FillingDlg::enterEvent(QEvent*)
251 {
252   if (!mainFrame()->GroupConstructors->isEnabled())
253     ActivateThisDialog();
254 }
255
256 //=================================================================================
257 // function : ValueChangedInSpinBox()
258 // purpose  :
259 //=================================================================================
260 void GenerationGUI_FillingDlg::ValueChangedInSpinBox(double newValue)
261 {
262   processPreview();
263 }
264
265 //=================================================================================
266 // function : MethodChanged
267 // purpose  :
268 //=================================================================================
269 void GenerationGUI_FillingDlg::MethodChanged()
270 {
271   processPreview();
272 }
273
274 //=================================================================================
275 // function : ApproxChanged()
276 // purpose  :
277 //=================================================================================
278 void GenerationGUI_FillingDlg::ApproxChanged()
279 {
280   if (GroupPoints->CheckBox1->isChecked()) {
281     // tol2d
282     GroupPoints->TextLabel3->setEnabled(false);
283     GroupPoints->SpinBox2->setEnabled(false);
284     // nbIter
285     GroupPoints->TextLabel4->setEnabled(false);
286     GroupPoints->SpinBox3->setEnabled(false);
287     // method
288     GroupPoints->TextLabel7->setEnabled(false);
289     GroupPoints->ComboBox1->setEnabled(false);
290   }
291   else {
292     // tol2d
293     GroupPoints->TextLabel3->setEnabled(true);
294     GroupPoints->SpinBox2->setEnabled(true);
295     // nbIter
296     GroupPoints->TextLabel4->setEnabled(true);
297     GroupPoints->SpinBox3->setEnabled(true);
298     // method
299     GroupPoints->TextLabel7->setEnabled(true);
300     GroupPoints->ComboBox1->setEnabled(true);
301   }
302
303   processPreview();
304 }
305
306 //=================================================================================
307 // function : createOperation
308 // purpose  :
309 //=================================================================================
310 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
311 {
312   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
313 }
314
315 //=================================================================================
316 // function : isValid
317 // purpose  :
318 //=================================================================================
319 bool GenerationGUI_FillingDlg::isValid(QString& msg)
320 {
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()) &&
326             myCompound;
327   return ok;
328 }
329
330 //=================================================================================
331 // function : execute
332 // purpose  :
333 //=================================================================================
334 bool GenerationGUI_FillingDlg::execute(ObjectList& objects)
335 {
336   GEOM::GEOM_I3DPrimOperations_var anOper =
337     GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
338
339   GEOM::filling_oper_method aMethod;
340   switch (GroupPoints->ComboBox1->currentIndex())
341   {
342     case 0:  aMethod = GEOM::FOM_Default; break;
343     case 1:  aMethod = GEOM::FOM_UseOri; break;
344     case 2:  aMethod = GEOM::FOM_AutoCorrect; break;
345     default: break;
346   }
347
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(),
355                          aMethod,
356                          GroupPoints->CheckBox1->isChecked());
357   if (!anObj->_is_nil())
358   {
359     if (!IsPreview())
360     {
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());
368     }
369     objects.push_back(anObj._retn());
370   }
371
372   return true;
373 }