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