Salome HOME
Using files from package LightApp instead of SalomeApp
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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(parent, name, modal,
63                      WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
64    myGeometryGUI(theGeometryGUI)
65 {
66   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FILLING")));
67   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
68
69   setCaption(tr("GEOM_FILLING_TITLE"));
70
71   /***************************************************************/
72   GroupConstructors->setTitle(tr("GEOM_FILLING"));
73   RadioButton1->setPixmap(image0);
74   RadioButton2->close(TRUE);
75   RadioButton3->close(TRUE);
76
77   GroupPoints = new DlgRef_1Sel5Spin(this, "GroupPoints");
78   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
79   GroupPoints->TextLabel1->setText(tr("GEOM_FILLING_COMPOUND"));
80   GroupPoints->TextLabel2->setText(tr("GEOM_FILLING_MIN_DEG"));
81   GroupPoints->TextLabel3->setText(tr("GEOM_FILLING_TOL_2D"));
82   GroupPoints->TextLabel4->setText(tr("GEOM_FILLING_NB_ITER"));
83   GroupPoints->TextLabel5->setText(tr("GEOM_FILLING_MAX_DEG"));
84   GroupPoints->TextLabel6->setText(tr("GEOM_FILLING_TOL_3D"));
85   GroupPoints->PushButton1->setPixmap(image1);
86   GroupPoints->LineEdit1->setReadOnly( true );
87
88   Layout1->addWidget(GroupPoints, 2, 0);
89   /***************************************************************/
90
91   /* Initialisations */
92   Init();
93 }
94
95 //=================================================================================
96 // function : ~GenerationGUI_FillingDlg()
97 // purpose  : Destroys the object and frees any allocated resources
98 //=================================================================================
99 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
100 {
101   // no need to delete child widgets, Qt does it all for us
102 }
103
104 //=================================================================================
105 // function : Init()
106 // purpose  :
107 //=================================================================================
108 void GenerationGUI_FillingDlg::Init()
109 {
110   /* init variables */
111   myEditCurrentArgument = GroupPoints->LineEdit1;
112   GroupPoints->LineEdit1->setReadOnly( true );
113
114   myMinDeg = 2;
115   myMaxDeg = 5;
116   myTol3D = 0.0001;
117   myTol2D = 0.0001;
118   myNbIter = 5;
119   myOkCompound = false;
120
121   globalSelection( GEOM_COMPOUND );
122
123   double SpecificStep1 = 1;
124   double SpecificStep2 = 0.0001;
125   /* min, max, step and decimals for spin boxes & initial values */
126   GroupPoints->SpinBox_1->RangeStepAndValidator(2.0, 999.999, SpecificStep1, 3);
127   GroupPoints->SpinBox_2->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
128   GroupPoints->SpinBox_3->RangeStepAndValidator(1.0, 999.999, SpecificStep1, 3);
129   GroupPoints->SpinBox_4->RangeStepAndValidator(1.0, 999.999, SpecificStep1, 3);
130   GroupPoints->SpinBox_5->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
131
132   GroupPoints->SpinBox_1->SetValue(myMinDeg);
133   GroupPoints->SpinBox_2->SetValue(myTol2D);
134   GroupPoints->SpinBox_3->SetValue(myNbIter);
135   GroupPoints->SpinBox_4->SetValue(myMaxDeg);
136   GroupPoints->SpinBox_5->SetValue(myTol3D);
137
138   /* signals and slots connections */
139   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
140   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
141
142   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
144
145   connect(GroupPoints->SpinBox_1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
146   connect(GroupPoints->SpinBox_2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
147   connect(GroupPoints->SpinBox_3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
148   connect(GroupPoints->SpinBox_4, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
149   connect(GroupPoints->SpinBox_5, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
150
151   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_1, SLOT(SetStep(double)));
152   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_2, SLOT(SetStep(double)));
153   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_3, SLOT(SetStep(double)));
154   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_4, SLOT(SetStep(double)));
155   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_5, SLOT(SetStep(double)));
156
157   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
158           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
159
160   initName(tr("GEOM_FILLING"));
161 }
162
163
164 //=================================================================================
165 // function : ClickOnOk()
166 // purpose  :
167 //=================================================================================
168 void GenerationGUI_FillingDlg::ClickOnOk()
169 {
170   if ( ClickOnApply() )
171     ClickOnCancel();
172 }
173
174
175 //=================================================================================
176 // function : ClickOnApply()
177 // purpose  :
178 //=================================================================================
179 bool GenerationGUI_FillingDlg::ClickOnApply()
180 {
181   if ( !onAccept() )
182     return false;
183
184   initName();
185   return true;
186 }
187
188
189 //=================================================================================
190 // function : SelectionIntoArgument()
191 // purpose  : Called when selection as changed or other case
192 //=================================================================================
193 void GenerationGUI_FillingDlg::SelectionIntoArgument()
194 {
195   erasePreview();
196   myEditCurrentArgument->setText("");
197
198   if(IObjectCount() != 1) {
199     if(myEditCurrentArgument == GroupPoints->LineEdit1)
200       myOkCompound = false;
201     return;
202   }
203
204   // nbSel == 1
205   Standard_Boolean testResult = Standard_False;
206   GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
207
208   if (!testResult)
209     return;
210
211   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
212     TopoDS_Shape S;
213     myOkCompound = false;
214
215     if ( GEOMBase::GetShape(aSelectedObject, S) &&
216          S.ShapeType() == TopAbs_COMPOUND)
217       {
218         // myCompound should be a compound of edges
219         for ( TopoDS_Iterator it( S ); it.More(); it.Next() )
220           if ( it.Value().ShapeType() != TopAbs_EDGE )
221             return;
222         myCompound = aSelectedObject;
223         myOkCompound = true;
224       }
225   }
226
227   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
228   displayPreview();
229 }
230
231
232 //=================================================================================
233 // function : SetEditCurrentArgument()
234 // purpose  :
235 //=================================================================================
236 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
237 {
238   QPushButton* send = (QPushButton*)sender();
239   globalSelection( GEOM_ALLSHAPES );
240
241   if(send == GroupPoints->PushButton1) {
242     GroupPoints->LineEdit1->setFocus();
243     myEditCurrentArgument = GroupPoints->LineEdit1;
244     globalSelection( GEOM_COMPOUND );
245     this->SelectionIntoArgument();
246   }
247 }
248
249
250 //=================================================================================
251 // function : LineEditReturnPressed()
252 // purpose  :
253 //=================================================================================
254 void GenerationGUI_FillingDlg::LineEditReturnPressed()
255 {
256   QLineEdit* send = (QLineEdit*)sender();
257   if(send == GroupPoints->LineEdit1)
258     {
259       myEditCurrentArgument = send;
260       GEOMBase_Skeleton::LineEditReturnPressed();
261     }
262 }
263
264
265 //=================================================================================
266 // function : ActivateThisDialog()
267 // purpose  :
268 //=================================================================================
269 void GenerationGUI_FillingDlg::ActivateThisDialog()
270 {
271   GEOMBase_Skeleton::ActivateThisDialog();
272   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
273           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
274   globalSelection( GEOM_COMPOUND );
275   displayPreview();
276 }
277
278
279 //=================================================================================
280 // function : enterEvent()
281 // purpose  :
282 //=================================================================================
283 void GenerationGUI_FillingDlg::enterEvent(QEvent* e)
284 {
285   if ( !GroupConstructors->isEnabled() )
286     ActivateThisDialog();
287 }
288
289
290 //=================================================================================
291 // function : ValueChangedInSpinBox()
292 // purpose  :
293 //=================================================================================
294 void GenerationGUI_FillingDlg::ValueChangedInSpinBox(double newValue)
295 {
296   QObject* send = (QObject*)sender();
297
298   if(send == GroupPoints->SpinBox_1)
299     myMinDeg = int(newValue);
300   else if(send == GroupPoints->SpinBox_2)
301     myTol2D = newValue;
302   else if(send == GroupPoints->SpinBox_3)
303     myNbIter = int(newValue);
304   else if(send == GroupPoints->SpinBox_4)
305     myMaxDeg = int(newValue);
306   else if(send == GroupPoints->SpinBox_5)
307     myTol3D = newValue;
308
309   displayPreview();
310 }
311
312 //=================================================================================
313 // function : createOperation
314 // purpose  :
315 //=================================================================================
316 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
317 {
318   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
319 }
320
321 //=================================================================================
322 // function : isValid
323 // purpose  :
324 //=================================================================================
325 bool GenerationGUI_FillingDlg::isValid( QString& )
326 {
327   return myOkCompound > 0;
328 }
329
330 //=================================================================================
331 // function : execute
332 // purpose  :
333 //=================================================================================
334 bool GenerationGUI_FillingDlg::execute( ObjectList& objects )
335 {
336   GEOM::GEOM_Object_var anObj;
337
338   anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation() )->MakeFilling(
339     myCompound, myMinDeg, myMaxDeg, myTol2D, myTol3D, myNbIter );
340
341   if ( !anObj->_is_nil() )
342     objects.push_back( anObj._retn() );
343
344   return true;
345 }