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