Salome HOME
63ffa51cd742be0223f24c4ad00c1f8e8cf3c65f
[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 <Standard_ErrorHandler.hxx>
47 #include "GEOMImpl_Types.hxx"
48
49 #include <qlabel.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_1Sel5Spin(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->PushButton1->setPixmap(image1);
85   GroupPoints->LineEdit1->setReadOnly( true );
86
87   Layout1->addWidget(GroupPoints, 2, 0);
88   /***************************************************************/
89
90   setHelpFileName("filling.htm");
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 = 5;
120   myOkCompound = false;
121
122   globalSelection( GEOM_COMPOUND );
123
124   double SpecificStep1 = 1;
125   double SpecificStep2 = 0.0001;
126   /* min, max, step and decimals for spin boxes & initial values */
127   GroupPoints->SpinBox_1->RangeStepAndValidator(2.0, MAX_NUMBER, SpecificStep1, 3);
128   GroupPoints->SpinBox_2->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
129   GroupPoints->SpinBox_3->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep1, 3);
130   GroupPoints->SpinBox_4->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep1, 3);
131   GroupPoints->SpinBox_5->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
132
133   GroupPoints->SpinBox_1->SetValue(myMinDeg);
134   GroupPoints->SpinBox_2->SetValue(myTol2D);
135   GroupPoints->SpinBox_3->SetValue(myNbIter);
136   GroupPoints->SpinBox_4->SetValue(myMaxDeg);
137   GroupPoints->SpinBox_5->SetValue(myTol3D);
138
139   /* signals and slots connections */
140   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
141   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
142
143   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
144   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145
146   connect(GroupPoints->SpinBox_1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
147   connect(GroupPoints->SpinBox_2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
148   connect(GroupPoints->SpinBox_3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
149   connect(GroupPoints->SpinBox_4, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
150   connect(GroupPoints->SpinBox_5, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
151
152   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_1, SLOT(SetStep(double)));
153   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_2, SLOT(SetStep(double)));
154   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_3, SLOT(SetStep(double)));
155   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_4, SLOT(SetStep(double)));
156   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_5, SLOT(SetStep(double)));
157
158   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
159           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
160
161   initName(tr("GEOM_FILLING"));
162 }
163
164
165 //=================================================================================
166 // function : ClickOnOk()
167 // purpose  :
168 //=================================================================================
169 void GenerationGUI_FillingDlg::ClickOnOk()
170 {
171   if ( ClickOnApply() )
172     ClickOnCancel();
173 }
174
175
176 //=================================================================================
177 // function : ClickOnApply()
178 // purpose  :
179 //=================================================================================
180 bool GenerationGUI_FillingDlg::ClickOnApply()
181 {
182   if ( !onAccept() )
183     return false;
184
185   initName();
186   return true;
187 }
188
189
190 //=================================================================================
191 // function : SelectionIntoArgument()
192 // purpose  : Called when selection as changed or other case
193 //=================================================================================
194 void GenerationGUI_FillingDlg::SelectionIntoArgument()
195 {
196   erasePreview();
197   myEditCurrentArgument->setText("");
198
199   if(IObjectCount() != 1) {
200     if(myEditCurrentArgument == GroupPoints->LineEdit1)
201       myOkCompound = false;
202     return;
203   }
204
205   // nbSel == 1
206   Standard_Boolean testResult = Standard_False;
207   GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
208
209   if (!testResult)
210     return;
211
212   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
213     TopoDS_Shape S;
214     myOkCompound = false;
215
216     if ( GEOMBase::GetShape(aSelectedObject, S) &&
217          S.ShapeType() == TopAbs_COMPOUND)
218       {
219         // myCompound should be a compound of edges
220         for ( TopoDS_Iterator it( S ); it.More(); it.Next() )
221           if ( it.Value().ShapeType() != TopAbs_EDGE )
222             return;
223         myCompound = aSelectedObject;
224         myOkCompound = true;
225       }
226   }
227
228   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
229   displayPreview();
230 }
231
232
233 //=================================================================================
234 // function : SetEditCurrentArgument()
235 // purpose  :
236 //=================================================================================
237 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
238 {
239   QPushButton* send = (QPushButton*)sender();
240   globalSelection( GEOM_ALLSHAPES );
241
242   if(send == GroupPoints->PushButton1) {
243     GroupPoints->LineEdit1->setFocus();
244     myEditCurrentArgument = GroupPoints->LineEdit1;
245     globalSelection( GEOM_COMPOUND );
246     this->SelectionIntoArgument();
247   }
248 }
249
250
251 //=================================================================================
252 // function : LineEditReturnPressed()
253 // purpose  :
254 //=================================================================================
255 void GenerationGUI_FillingDlg::LineEditReturnPressed()
256 {
257   QLineEdit* send = (QLineEdit*)sender();
258   if(send == GroupPoints->LineEdit1)
259     {
260       myEditCurrentArgument = send;
261       GEOMBase_Skeleton::LineEditReturnPressed();
262     }
263 }
264
265
266 //=================================================================================
267 // function : ActivateThisDialog()
268 // purpose  :
269 //=================================================================================
270 void GenerationGUI_FillingDlg::ActivateThisDialog()
271 {
272   GEOMBase_Skeleton::ActivateThisDialog();
273   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
274           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
275   globalSelection( GEOM_COMPOUND );
276   displayPreview();
277 }
278
279
280 //=================================================================================
281 // function : enterEvent()
282 // purpose  :
283 //=================================================================================
284 void GenerationGUI_FillingDlg::enterEvent(QEvent* e)
285 {
286   if ( !GroupConstructors->isEnabled() )
287     ActivateThisDialog();
288 }
289
290
291 //=================================================================================
292 // function : ValueChangedInSpinBox()
293 // purpose  :
294 //=================================================================================
295 void GenerationGUI_FillingDlg::ValueChangedInSpinBox(double newValue)
296 {
297   QObject* send = (QObject*)sender();
298
299   if(send == GroupPoints->SpinBox_1)
300     myMinDeg = int(newValue);
301   else if(send == GroupPoints->SpinBox_2)
302     myTol2D = newValue;
303   else if(send == GroupPoints->SpinBox_3)
304     myNbIter = int(newValue);
305   else if(send == GroupPoints->SpinBox_4)
306     myMaxDeg = int(newValue);
307   else if(send == GroupPoints->SpinBox_5)
308     myTol3D = newValue;
309
310   displayPreview();
311 }
312
313 //=================================================================================
314 // function : createOperation
315 // purpose  :
316 //=================================================================================
317 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
318 {
319   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
320 }
321
322 //=================================================================================
323 // function : isValid
324 // purpose  :
325 //=================================================================================
326 bool GenerationGUI_FillingDlg::isValid( QString& )
327 {
328   return myOkCompound > 0;
329 }
330
331 //=================================================================================
332 // function : execute
333 // purpose  :
334 //=================================================================================
335 bool GenerationGUI_FillingDlg::execute( ObjectList& objects )
336 {
337   GEOM::GEOM_Object_var anObj;
338
339   anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation() )->MakeFilling(
340     myCompound, myMinDeg, myMaxDeg, myTol2D, myTol3D, myNbIter );
341
342   if ( !anObj->_is_nil() )
343     objects.push_back( anObj._retn() );
344
345   return true;
346 }