]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_FillingDlg.cxx
Salome HOME
SALOME PAL V1_4_1
[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 using namespace std;
30 #include "GenerationGUI_FillingDlg.h"
31
32 #include "QAD_Config.h"
33
34 #include <GeomFill_SectionGenerator.hxx>
35 #include <GeomFill_Line.hxx>
36 #include <GeomFill_AppSurf.hxx>
37 #include <Geom_BSplineSurface.hxx>
38 #include <Geom_TrimmedCurve.hxx>
39 #include <BRepBuilderAPI_MakeFace.hxx>
40 #include <TopExp_Explorer.hxx>
41 #include <BRep_Tool.hxx>
42 #include <Precision.hxx>
43
44 //=================================================================================
45 // class    : GenerationGUI_FillingDlg()
46 // purpose  : Constructs a GenerationGUI_FillingDlg which is a child of 'parent', with the 
47 //            name 'name' and widget flags set to 'f'.
48 //            The dialog will by default be modeless, unless you set 'modal' to
49 //            TRUE to construct a modal dialog.
50 //=================================================================================
51 GenerationGUI_FillingDlg::GenerationGUI_FillingDlg(QWidget* parent, const char* name, GenerationGUI* theGenerationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
52   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
53 {
54   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_FILLING")));
55   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
56
57   setCaption(tr("GEOM_FILLING_TITLE"));
58
59   /***************************************************************/
60   GroupConstructors->setTitle(tr("GEOM_FILLING"));
61   RadioButton1->setPixmap(image0);
62   RadioButton2->close(TRUE);
63   RadioButton3->close(TRUE);
64
65   GroupPoints = new DlgRef_1Sel5Spin(this, "GroupPoints");
66   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
67   GroupPoints->TextLabel1->setText(tr("GEOM_FILLING_COMPOUND"));
68   GroupPoints->TextLabel2->setText(tr("GEOM_FILLING_MIN_DEG"));
69   GroupPoints->TextLabel3->setText(tr("GEOM_FILLING_TOL_2D"));
70   GroupPoints->TextLabel4->setText(tr("GEOM_FILLING_NB_ITER"));
71   GroupPoints->TextLabel5->setText(tr("GEOM_FILLING_MAX_DEG"));
72   GroupPoints->TextLabel6->setText(tr("GEOM_FILLING_TOL_3D"));
73   GroupPoints->PushButton1->setPixmap(image1);
74
75   Layout1->addWidget(GroupPoints, 1, 0);
76   /***************************************************************/
77
78   /* Initialisations */
79   myGenerationGUI = theGenerationGUI;
80   Init();
81 }
82
83
84 //=================================================================================
85 // function : ~GenerationGUI_FillingDlg()
86 // purpose  : Destroys the object and frees any allocated resources
87 //=================================================================================
88 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
89 {
90     // no need to delete child widgets, Qt does it all for us
91 }
92
93
94 //=================================================================================
95 // function : Init()
96 // purpose  :
97 //=================================================================================
98 void GenerationGUI_FillingDlg::Init()
99 {
100   /* init variables */
101   myEditCurrentArgument = GroupPoints->LineEdit1;
102
103   myMinDeg = 2;
104   myMaxDeg = 5;
105   myTol3D = 0.0001;
106   myTol2D = 0.0001;
107   myNbIter = 5;
108   myOkSectionShape = false;
109
110   myCompoundFilter = new GEOM_ShapeTypeFilter(TopAbs_COMPOUND, myGeom);
111   mySelection->AddFilter(myCompoundFilter);
112
113   double SpecificStep1 = 1;
114   double SpecificStep2 = 0.0001;
115   /* min, max, step and decimals for spin boxes & initial values */
116   GroupPoints->SpinBox_1->RangeStepAndValidator(2.0, 999.999, SpecificStep1, 3);
117   GroupPoints->SpinBox_2->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
118   GroupPoints->SpinBox_3->RangeStepAndValidator(1.0, 999.999, SpecificStep1, 3);
119   GroupPoints->SpinBox_4->RangeStepAndValidator(1.0, 999.999, SpecificStep1, 3);
120   GroupPoints->SpinBox_5->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
121
122   GroupPoints->SpinBox_1->SetValue(myMinDeg);
123   GroupPoints->SpinBox_2->SetValue(myTol2D);
124   GroupPoints->SpinBox_3->SetValue(myNbIter);
125   GroupPoints->SpinBox_4->SetValue(myMaxDeg);
126   GroupPoints->SpinBox_5->SetValue(myTol3D);
127
128   /* signals and slots connections */
129   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
130   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
131
132   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134   
135   connect(GroupPoints->SpinBox_1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
136   connect(GroupPoints->SpinBox_2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
137   connect(GroupPoints->SpinBox_3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
138   connect(GroupPoints->SpinBox_4, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
139   connect(GroupPoints->SpinBox_5, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
140
141   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_1, SLOT(SetStep(double)));
142   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_2, SLOT(SetStep(double)));
143   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_3, SLOT(SetStep(double)));
144   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_4, SLOT(SetStep(double)));
145   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_5, SLOT(SetStep(double)));
146
147   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
148
149   /* displays Dialog */
150   GroupPoints->show();
151   this->show();
152
153   return;
154 }
155
156
157 //=================================================================================
158 // function : ClickOnOk()
159 // purpose  :
160 //=================================================================================
161 void GenerationGUI_FillingDlg::ClickOnOk()
162 {
163   this->ClickOnApply();
164   ClickOnCancel();
165   return;
166 }
167
168
169 //=================================================================================
170 // function : ClickOnApply()
171 // purpose  :
172 //=================================================================================
173 void GenerationGUI_FillingDlg::ClickOnApply()
174 {
175   buttonApply->setFocus();
176   QAD_Application::getDesktop()->putInfo(tr(""));
177   if (mySimulationTopoDs.IsNull())
178     return;
179   myGeomBase->EraseSimulationShape();
180   mySimulationTopoDs.Nullify();
181
182   if(myOkSectionShape)    
183     myGenerationGUI->MakeFillingAndDisplay(myGeomShape, myMinDeg, myMaxDeg, myTol3D, myTol2D, myNbIter);
184   return;
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   myGeomBase->EraseSimulationShape();
195   mySimulationTopoDs.Nullify();
196   myEditCurrentArgument->setText("");
197   QString aString = ""; /* name of selection */
198   
199   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
200   if(nbSel != 1) {
201     if(myEditCurrentArgument == GroupPoints->LineEdit1)
202       myOkSectionShape = false;
203     return;
204   }
205   
206   // nbSel == 1
207   Standard_Boolean testResult;
208   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
209   if(!myGeomBase->GetTopoFromSelection(mySelection, mySectionShape))
210     return;
211   
212   if(myEditCurrentArgument == GroupPoints->LineEdit1 && mySectionShape.ShapeType() == TopAbs_COMPOUND) {
213     myEditCurrentArgument->setText(aString);
214     myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
215     if(!testResult)
216       return;
217     myOkSectionShape = true;
218   }
219
220   if(myOkSectionShape)
221     this->MakeFillingSimulationAndDisplay();
222   return;
223 }
224
225
226 //=================================================================================
227 // function : SetEditCurrentArgument()
228 // purpose  :
229 //=================================================================================
230 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
231 {
232   QPushButton* send = (QPushButton*)sender();
233   mySelection->ClearFilters();
234
235   if(send == GroupPoints->PushButton1) {
236     GroupPoints->LineEdit1->setFocus();
237     myEditCurrentArgument = GroupPoints->LineEdit1;
238     mySelection->AddFilter(myCompoundFilter);
239     this->SelectionIntoArgument();
240   }
241
242   return;
243 }
244
245
246 //=================================================================================
247 // function : LineEditReturnPressed()
248 // purpose  :
249 //=================================================================================
250 void GenerationGUI_FillingDlg::LineEditReturnPressed()
251 {  
252   QLineEdit* send = (QLineEdit*)sender();
253   if(send == GroupPoints->LineEdit1)
254     myEditCurrentArgument = GroupPoints->LineEdit1;
255   else
256     return;
257
258   GEOMBase_Skeleton::LineEditReturnPressed();
259   return;
260 }
261
262
263 //=================================================================================
264 // function : ActivateThisDialog()
265 // purpose  :
266 //=================================================================================
267 void GenerationGUI_FillingDlg::ActivateThisDialog()
268 {
269   GEOMBase_Skeleton::ActivateThisDialog();
270   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
271   mySelection->AddFilter(myCompoundFilter);
272   if(!mySimulationTopoDs.IsNull())
273     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
274   return;
275 }
276
277
278 //=================================================================================
279 // function : enterEvent()
280 // purpose  :
281 //=================================================================================
282 void GenerationGUI_FillingDlg::enterEvent(QEvent* e)
283 {
284   if (GroupConstructors->isEnabled())
285     return;
286   this->ActivateThisDialog();
287   return;
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   if(myOkSectionShape)
311     this->MakeFillingSimulationAndDisplay();
312   return;
313 }
314
315
316 //=================================================================================
317 // function : MakeFillingSimulationAndDisplay()
318 // purpose  :
319 //=================================================================================
320 void GenerationGUI_FillingDlg::MakeFillingSimulationAndDisplay()
321 {
322   myGeomBase->EraseSimulationShape();
323   mySimulationTopoDs.Nullify();
324
325   try {
326     /* we verify the contents of the shape */
327     TopExp_Explorer Ex;
328     TopoDS_Shape Scurrent;      
329     Standard_Real First, Last;
330     Handle(Geom_Curve) C;
331     GeomFill_SectionGenerator Section;
332     
333     Standard_Integer i = 0;
334     for(Ex.Init(mySectionShape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
335       Scurrent = Ex.Current();
336       if( Scurrent.IsNull() || Scurrent.ShapeType() != TopAbs_EDGE)
337         return;
338       C = BRep_Tool::Curve(TopoDS::Edge(Scurrent), First, Last);
339       C = new Geom_TrimmedCurve(C, First, Last);
340       Section.AddCurve(C) ;
341       i++ ;
342     }
343     
344     /* a 'tolerance' is used to compare 2 knots : see GeomFill_Generator.cdl */
345     /* We set 'tolerance' = tol3d                                            */
346     // Section.Perform( tol3d ) ; NRI */
347     Section.Perform(Precision::Confusion());
348     Handle(GeomFill_Line) Line = new GeomFill_Line(i);
349
350     GeomFill_AppSurf App(myMinDeg, myMaxDeg, myTol3D, myTol2D, myNbIter) ; /* user parameters */
351     App.Perform(Line, Section);
352     
353     if(!App.IsDone())
354       return;
355
356     Standard_Integer UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots;
357     App.SurfShape(UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots);    
358     Handle(Geom_BSplineSurface) GBS = new Geom_BSplineSurface(App.SurfPoles(), App.SurfWeights(), App.SurfUKnots(), App.SurfVKnots(), App.SurfUMults(), App.SurfVMults(), App.UDegree(), App.VDegree());
359     
360     if(GBS.IsNull())
361       return;
362     mySimulationTopoDs  = BRepBuilderAPI_MakeFace(GBS);    
363     if(mySimulationTopoDs.IsNull())
364       return;
365     else
366       myGeomBase->DisplaySimulationShape(mySimulationTopoDs); 
367   }
368   catch(Standard_Failure) {
369     MESSAGE("Exception catched in MakePrismSimulationAndDisplay" << endl);
370     return;
371   }
372   return;
373 }