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