]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_FillingDlg.cxx
Salome HOME
Correct make file for shared modules script
[modules/geom.git] / src / GenerationGUI / GenerationGUI_FillingDlg.cxx
1 //  Copyright (C) 2007-2008  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
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include "GenerationGUI_FillingDlg.h"
29
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
34
35 #include <GeomFill_SectionGenerator.hxx>
36 #include <GeomFill_Line.hxx>
37 #include <GeomFill_AppSurf.hxx>
38 #include <Geom_BSplineSurface.hxx>
39 #include <Geom_TrimmedCurve.hxx>
40 #include <BRepBuilderAPI_MakeFace.hxx>
41 #include <TopExp_Explorer.hxx>
42 #include <TopoDS_Iterator.hxx>
43 #include <BRep_Tool.hxx>
44 #include <Precision.hxx>
45 #include "GEOMImpl_Types.hxx"
46
47 #include <qlabel.h>
48 #include <qcheckbox.h>
49
50 #include "utilities.h"
51
52 //=================================================================================
53 // class    : GenerationGUI_FillingDlg()
54 // purpose  : Constructs a GenerationGUI_FillingDlg which is a child of 'parent', with the
55 //            name 'name' and widget flags set to 'f'.
56 //            The dialog will by default be modeless, unless you set 'modal' to
57 //            TRUE to construct a modal dialog.
58 //=================================================================================
59 GenerationGUI_FillingDlg::GenerationGUI_FillingDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
60                                                    const char* name, bool modal, WFlags fl)
61   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal,
62                      WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
63 {
64   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FILLING")));
65   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
66
67   setCaption(tr("GEOM_FILLING_TITLE"));
68
69   /***************************************************************/
70   GroupConstructors->setTitle(tr("GEOM_FILLING"));
71   RadioButton1->setPixmap(image0);
72   RadioButton2->close(TRUE);
73   RadioButton3->close(TRUE);
74
75   GroupPoints = new DlgRef_1Sel5Spin1Check(this, "GroupPoints");
76   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
77   GroupPoints->TextLabel1->setText(tr("GEOM_FILLING_COMPOUND"));
78   GroupPoints->TextLabel2->setText(tr("GEOM_FILLING_MIN_DEG"));
79   GroupPoints->TextLabel3->setText(tr("GEOM_FILLING_TOL_2D"));
80   GroupPoints->TextLabel4->setText(tr("GEOM_FILLING_NB_ITER"));
81   GroupPoints->TextLabel5->setText(tr("GEOM_FILLING_MAX_DEG"));
82   GroupPoints->TextLabel6->setText(tr("GEOM_FILLING_TOL_3D"));
83   GroupPoints->CheckBox1->setText(tr("GEOM_FILLING_APPROX"));
84   GroupPoints->PushButton1->setPixmap(image1);
85   GroupPoints->LineEdit1->setReadOnly( true );
86
87   Layout1->addWidget(GroupPoints, 2, 0);
88   /***************************************************************/
89
90   setHelpFileName("create_filling_page.html");
91
92   /* Initialisations */
93   Init();
94 }
95
96 //=================================================================================
97 // function : ~GenerationGUI_FillingDlg()
98 // purpose  : Destroys the object and frees any allocated resources
99 //=================================================================================
100 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
101 {
102   // no need to delete child widgets, Qt does it all for us
103 }
104
105 //=================================================================================
106 // function : Init()
107 // purpose  :
108 //=================================================================================
109 void GenerationGUI_FillingDlg::Init()
110 {
111   /* init variables */
112   myEditCurrentArgument = GroupPoints->LineEdit1;
113   GroupPoints->LineEdit1->setReadOnly( true );
114
115   myMinDeg = 2;
116   myMaxDeg = 5;
117   myTol3D = 0.0001;
118   myTol2D = 0.0001;
119   myNbIter = 0;
120   myIsApprox = false;
121   myOkCompound = false;
122
123   globalSelection( GEOM_COMPOUND );
124
125   double SpecificStep1 = 1;
126   double SpecificStep2 = 0.0001;
127   /* min, max, step and decimals for spin boxes & initial values */
128   GroupPoints->SpinBox_1->RangeStepAndValidator(2.0, MAX_NUMBER, SpecificStep1, 3);
129   GroupPoints->SpinBox_2->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
130   GroupPoints->SpinBox_3->RangeStepAndValidator(0.0, MAX_NUMBER, SpecificStep1, 3);
131   GroupPoints->SpinBox_4->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep1, 3);
132   GroupPoints->SpinBox_5->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
133
134   GroupPoints->SpinBox_1->SetValue(myMinDeg);
135   GroupPoints->SpinBox_2->SetValue(myTol2D);
136   GroupPoints->SpinBox_3->SetValue(myNbIter);
137   GroupPoints->SpinBox_4->SetValue(myMaxDeg);
138   GroupPoints->SpinBox_5->SetValue(myTol3D);
139
140   /* signals and slots connections */
141   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
142   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
143
144   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146
147   connect(GroupPoints->SpinBox_1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
148   connect(GroupPoints->SpinBox_2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
149   connect(GroupPoints->SpinBox_3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
150   connect(GroupPoints->SpinBox_4, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
151   connect(GroupPoints->SpinBox_5, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
152   connect(GroupPoints->CheckBox1, SIGNAL(stateChanged(int)), this, SLOT(ApproxChanged()));
153
154   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_1, SLOT(SetStep(double)));
155   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_2, SLOT(SetStep(double)));
156   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_3, SLOT(SetStep(double)));
157   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_4, SLOT(SetStep(double)));
158   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_5, SLOT(SetStep(double)));
159
160   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
161           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
162
163   initName(tr("GEOM_FILLING"));
164 }
165
166
167 //=================================================================================
168 // function : ClickOnOk()
169 // purpose  :
170 //=================================================================================
171 void GenerationGUI_FillingDlg::ClickOnOk()
172 {
173   if ( ClickOnApply() )
174     ClickOnCancel();
175 }
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 //=================================================================================
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(IObjectCount() != 1) {
202     if(myEditCurrentArgument == GroupPoints->LineEdit1)
203       myOkCompound = false;
204     return;
205   }
206
207   // nbSel == 1
208   Standard_Boolean testResult = Standard_False;
209   GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
210
211   if (!testResult)
212     return;
213
214   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
215     TopoDS_Shape S;
216     myOkCompound = false;
217
218     if ( GEOMBase::GetShape(aSelectedObject, S) &&
219          S.ShapeType() == TopAbs_COMPOUND)
220       {
221         // myCompound should be a compound of edges
222         for ( TopoDS_Iterator it( S ); it.More(); it.Next() )
223           if ( it.Value().ShapeType() != TopAbs_EDGE )
224             return;
225         myCompound = aSelectedObject;
226         myOkCompound = true;
227       }
228   }
229
230   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
231   displayPreview();
232 }
233
234
235 //=================================================================================
236 // function : SetEditCurrentArgument()
237 // purpose  :
238 //=================================================================================
239 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
240 {
241   QPushButton* send = (QPushButton*)sender();
242   globalSelection( GEOM_ALLSHAPES );
243
244   if(send == GroupPoints->PushButton1) {
245     GroupPoints->LineEdit1->setFocus();
246     myEditCurrentArgument = GroupPoints->LineEdit1;
247     globalSelection( GEOM_COMPOUND );
248     this->SelectionIntoArgument();
249   }
250 }
251
252
253 //=================================================================================
254 // function : LineEditReturnPressed()
255 // purpose  :
256 //=================================================================================
257 void GenerationGUI_FillingDlg::LineEditReturnPressed()
258 {
259   QLineEdit* send = (QLineEdit*)sender();
260   if(send == GroupPoints->LineEdit1)
261     {
262       myEditCurrentArgument = send;
263       GEOMBase_Skeleton::LineEditReturnPressed();
264     }
265 }
266
267
268 //=================================================================================
269 // function : ActivateThisDialog()
270 // purpose  :
271 //=================================================================================
272 void GenerationGUI_FillingDlg::ActivateThisDialog()
273 {
274   GEOMBase_Skeleton::ActivateThisDialog();
275   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
276           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
277   globalSelection( GEOM_COMPOUND );
278   displayPreview();
279 }
280
281
282 //=================================================================================
283 // function : enterEvent()
284 // purpose  :
285 //=================================================================================
286 void GenerationGUI_FillingDlg::enterEvent(QEvent* e)
287 {
288   if ( !GroupConstructors->isEnabled() )
289     ActivateThisDialog();
290 }
291
292
293 //=================================================================================
294 // function : ValueChangedInSpinBox()
295 // purpose  :
296 //=================================================================================
297 void GenerationGUI_FillingDlg::ValueChangedInSpinBox(double newValue)
298 {
299   QObject* send = (QObject*)sender();
300
301   if(send == GroupPoints->SpinBox_1)
302     myMinDeg = int(newValue);
303   else if(send == GroupPoints->SpinBox_2)
304     myTol2D = newValue;
305   else if(send == GroupPoints->SpinBox_3)
306     myNbIter = int(newValue);
307   else if(send == GroupPoints->SpinBox_4)
308     myMaxDeg = int(newValue);
309   else if(send == GroupPoints->SpinBox_5)
310     myTol3D = newValue;
311
312   displayPreview();
313 }
314
315 //=================================================================================
316 // function : ApproxChanged()
317 // purpose  :
318 //=================================================================================
319 void GenerationGUI_FillingDlg::ApproxChanged()
320 {
321   myIsApprox = GroupPoints->CheckBox1->isChecked();
322   displayPreview();
323 }
324
325 //=================================================================================
326 // function : createOperation
327 // purpose  :
328 //=================================================================================
329 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
330 {
331   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
332 }
333
334 //=================================================================================
335 // function : isValid
336 // purpose  :
337 //=================================================================================
338 bool GenerationGUI_FillingDlg::isValid( QString& )
339 {
340   return myOkCompound > 0;
341 }
342
343 //=================================================================================
344 // function : execute
345 // purpose  :
346 //=================================================================================
347 bool GenerationGUI_FillingDlg::execute( ObjectList& objects )
348 {
349   GEOM::GEOM_Object_var anObj;
350
351   anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation() )->MakeFilling(
352           myCompound, myMinDeg, myMaxDeg, myTol2D, myTol3D, myNbIter, myIsApprox );
353
354   if ( !anObj->_is_nil() )
355     objects.push_back( anObj._retn() );
356
357   return true;
358 }