1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GenerationGUI_FillingDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GenerationGUI_FillingDlg.h"
32 #include "QAD_Config.h"
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>
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)
54 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_FILLING")));
55 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
57 setCaption(tr("GEOM_FILLING_TITLE"));
59 /***************************************************************/
60 GroupConstructors->setTitle(tr("GEOM_FILLING"));
61 RadioButton1->setPixmap(image0);
62 RadioButton2->close(TRUE);
63 RadioButton3->close(TRUE);
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);
75 Layout1->addWidget(GroupPoints, 1, 0);
76 /***************************************************************/
79 myGenerationGUI = theGenerationGUI;
84 //=================================================================================
85 // function : ~GenerationGUI_FillingDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
90 // no need to delete child widgets, Qt does it all for us
94 //=================================================================================
97 //=================================================================================
98 void GenerationGUI_FillingDlg::Init()
101 myEditCurrentArgument = GroupPoints->LineEdit1;
108 myOkSectionShape = false;
110 myCompoundFilter = new GEOM_ShapeTypeFilter(TopAbs_COMPOUND, myGeom);
111 mySelection->AddFilter(myCompoundFilter);
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);
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);
128 /* signals and slots connections */
129 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
130 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
132 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
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)));
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)));
147 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
149 /* displays Dialog */
157 //=================================================================================
158 // function : ClickOnOk()
160 //=================================================================================
161 void GenerationGUI_FillingDlg::ClickOnOk()
163 this->ClickOnApply();
169 //=================================================================================
170 // function : ClickOnApply()
172 //=================================================================================
173 void GenerationGUI_FillingDlg::ClickOnApply()
175 QAD_Application::getDesktop()->putInfo(tr(""));
176 if (mySimulationTopoDs.IsNull())
178 myGeomBase->EraseSimulationShape();
179 mySimulationTopoDs.Nullify();
182 myGenerationGUI->MakeFillingAndDisplay(myGeomShape, myMinDeg, myMaxDeg, myTol3D, myTol2D, myNbIter);
187 //=================================================================================
188 // function : SelectionIntoArgument()
189 // purpose : Called when selection as changed or other case
190 //=================================================================================
191 void GenerationGUI_FillingDlg::SelectionIntoArgument()
193 myGeomBase->EraseSimulationShape();
194 mySimulationTopoDs.Nullify();
195 myEditCurrentArgument->setText("");
196 QString aString = ""; /* name of selection */
198 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
200 if(myEditCurrentArgument == GroupPoints->LineEdit1)
201 myOkSectionShape = false;
206 Standard_Boolean testResult;
207 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
208 if(!myGeomBase->GetTopoFromSelection(mySelection, mySectionShape))
211 if(myEditCurrentArgument == GroupPoints->LineEdit1 && mySectionShape.ShapeType() == TopAbs_COMPOUND) {
212 myEditCurrentArgument->setText(aString);
213 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
216 myOkSectionShape = true;
220 this->MakeFillingSimulationAndDisplay();
225 //=================================================================================
226 // function : SetEditCurrentArgument()
228 //=================================================================================
229 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
231 QPushButton* send = (QPushButton*)sender();
232 mySelection->ClearFilters();
234 if(send == GroupPoints->PushButton1) {
235 GroupPoints->LineEdit1->setFocus();
236 myEditCurrentArgument = GroupPoints->LineEdit1;
237 mySelection->AddFilter(myCompoundFilter);
238 this->SelectionIntoArgument();
245 //=================================================================================
246 // function : LineEditReturnPressed()
248 //=================================================================================
249 void GenerationGUI_FillingDlg::LineEditReturnPressed()
251 QLineEdit* send = (QLineEdit*)sender();
252 if(send == GroupPoints->LineEdit1)
253 myEditCurrentArgument = GroupPoints->LineEdit1;
257 GEOMBase_Skeleton::LineEditReturnPressed();
262 //=================================================================================
263 // function : ActivateThisDialog()
265 //=================================================================================
266 void GenerationGUI_FillingDlg::ActivateThisDialog()
268 GEOMBase_Skeleton::ActivateThisDialog();
269 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
270 mySelection->AddFilter(myCompoundFilter);
271 if(!mySimulationTopoDs.IsNull())
272 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
277 //=================================================================================
278 // function : enterEvent()
280 //=================================================================================
281 void GenerationGUI_FillingDlg::enterEvent(QEvent* e)
283 if (GroupConstructors->isEnabled())
285 this->ActivateThisDialog();
290 //=================================================================================
291 // function : ValueChangedInSpinBox()
293 //=================================================================================
294 void GenerationGUI_FillingDlg::ValueChangedInSpinBox(double newValue)
296 QObject* send = (QObject*)sender();
298 if(send == GroupPoints->SpinBox_1)
299 myMinDeg = int(newValue);
300 else if(send == GroupPoints->SpinBox_2)
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)
310 this->MakeFillingSimulationAndDisplay();
315 //=================================================================================
316 // function : MakeFillingSimulationAndDisplay()
318 //=================================================================================
319 void GenerationGUI_FillingDlg::MakeFillingSimulationAndDisplay()
321 myGeomBase->EraseSimulationShape();
322 mySimulationTopoDs.Nullify();
325 /* we verify the contents of the shape */
327 TopoDS_Shape Scurrent;
328 Standard_Real First, Last;
329 Handle(Geom_Curve) C;
330 GeomFill_SectionGenerator Section;
332 Standard_Integer i = 0;
333 for(Ex.Init(mySectionShape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
334 Scurrent = Ex.Current();
335 if( Scurrent.IsNull() || Scurrent.ShapeType() != TopAbs_EDGE)
337 C = BRep_Tool::Curve(TopoDS::Edge(Scurrent), First, Last);
338 C = new Geom_TrimmedCurve(C, First, Last);
339 Section.AddCurve(C) ;
343 /* a 'tolerance' is used to compare 2 knots : see GeomFill_Generator.cdl */
344 /* We set 'tolerance' = tol3d */
345 // Section.Perform( tol3d ) ; NRI */
346 Section.Perform(Precision::Confusion());
347 Handle(GeomFill_Line) Line = new GeomFill_Line(i);
349 GeomFill_AppSurf App(myMinDeg, myMaxDeg, myTol3D, myTol2D, myNbIter) ; /* user parameters */
350 App.Perform(Line, Section);
355 Standard_Integer UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots;
356 App.SurfShape(UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots);
357 Handle(Geom_BSplineSurface) GBS = new Geom_BSplineSurface(App.SurfPoles(), App.SurfWeights(), App.SurfUKnots(), App.SurfVKnots(), App.SurfUMults(), App.SurfVMults(), App.UDegree(), App.VDegree());
361 mySimulationTopoDs = BRepBuilderAPI_MakeFace(GBS);
362 if(mySimulationTopoDs.IsNull())
365 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
367 catch(Standard_Failure) {
368 MESSAGE("Exception catched in MakePrismSimulationAndDisplay" << endl);