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 buttonApply->setFocus();
176 QAD_Application::getDesktop()->putInfo(tr(""));
177 if (mySimulationTopoDs.IsNull())
179 myGeomBase->EraseSimulationShape();
180 mySimulationTopoDs.Nullify();
183 myGenerationGUI->MakeFillingAndDisplay(myGeomShape, myMinDeg, myMaxDeg, myTol3D, myTol2D, myNbIter);
188 //=================================================================================
189 // function : SelectionIntoArgument()
190 // purpose : Called when selection as changed or other case
191 //=================================================================================
192 void GenerationGUI_FillingDlg::SelectionIntoArgument()
194 myGeomBase->EraseSimulationShape();
195 mySimulationTopoDs.Nullify();
196 myEditCurrentArgument->setText("");
197 QString aString = ""; /* name of selection */
199 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
201 if(myEditCurrentArgument == GroupPoints->LineEdit1)
202 myOkSectionShape = false;
207 Standard_Boolean testResult;
208 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
209 if(!myGeomBase->GetTopoFromSelection(mySelection, mySectionShape))
212 if(myEditCurrentArgument == GroupPoints->LineEdit1 && mySectionShape.ShapeType() == TopAbs_COMPOUND) {
213 myEditCurrentArgument->setText(aString);
214 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
217 myOkSectionShape = true;
221 this->MakeFillingSimulationAndDisplay();
226 //=================================================================================
227 // function : SetEditCurrentArgument()
229 //=================================================================================
230 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
232 QPushButton* send = (QPushButton*)sender();
233 mySelection->ClearFilters();
235 if(send == GroupPoints->PushButton1) {
236 GroupPoints->LineEdit1->setFocus();
237 myEditCurrentArgument = GroupPoints->LineEdit1;
238 mySelection->AddFilter(myCompoundFilter);
239 this->SelectionIntoArgument();
246 //=================================================================================
247 // function : LineEditReturnPressed()
249 //=================================================================================
250 void GenerationGUI_FillingDlg::LineEditReturnPressed()
252 QLineEdit* send = (QLineEdit*)sender();
253 if(send == GroupPoints->LineEdit1)
254 myEditCurrentArgument = GroupPoints->LineEdit1;
258 GEOMBase_Skeleton::LineEditReturnPressed();
263 //=================================================================================
264 // function : ActivateThisDialog()
266 //=================================================================================
267 void GenerationGUI_FillingDlg::ActivateThisDialog()
269 GEOMBase_Skeleton::ActivateThisDialog();
270 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
271 mySelection->AddFilter(myCompoundFilter);
272 if(!mySimulationTopoDs.IsNull())
273 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
278 //=================================================================================
279 // function : enterEvent()
281 //=================================================================================
282 void GenerationGUI_FillingDlg::enterEvent(QEvent* e)
284 if (GroupConstructors->isEnabled())
286 this->ActivateThisDialog();
291 //=================================================================================
292 // function : ValueChangedInSpinBox()
294 //=================================================================================
295 void GenerationGUI_FillingDlg::ValueChangedInSpinBox(double newValue)
297 QObject* send = (QObject*)sender();
299 if(send == GroupPoints->SpinBox_1)
300 myMinDeg = int(newValue);
301 else if(send == GroupPoints->SpinBox_2)
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)
311 this->MakeFillingSimulationAndDisplay();
316 //=================================================================================
317 // function : MakeFillingSimulationAndDisplay()
319 //=================================================================================
320 void GenerationGUI_FillingDlg::MakeFillingSimulationAndDisplay()
322 myGeomBase->EraseSimulationShape();
323 mySimulationTopoDs.Nullify();
326 /* we verify the contents of the shape */
328 TopoDS_Shape Scurrent;
329 Standard_Real First, Last;
330 Handle(Geom_Curve) C;
331 GeomFill_SectionGenerator Section;
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)
338 C = BRep_Tool::Curve(TopoDS::Edge(Scurrent), First, Last);
339 C = new Geom_TrimmedCurve(C, First, Last);
340 Section.AddCurve(C) ;
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);
350 GeomFill_AppSurf App(myMinDeg, myMaxDeg, myTol3D, myTol2D, myNbIter) ; /* user parameters */
351 App.Perform(Line, Section);
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());
362 mySimulationTopoDs = BRepBuilderAPI_MakeFace(GBS);
363 if(mySimulationTopoDs.IsNull())
366 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
368 catch(Standard_Failure) {
369 MESSAGE("Exception catched in MakePrismSimulationAndDisplay" << endl);