1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GenerationGUI_FillingDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "GenerationGUI_FillingDlg.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
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 "GEOMImpl_Types.hxx"
48 #include <qcheckbox.h>
50 #include "utilities.h"
52 //=================================================================================
53 // class : GenerationGUI_FillingDlg()
54 // purpose : Constructs a GenerationGUI_FillingDlg which is a child of 'parent', with the
55 // name 'name' and widget flags set to 'f'.
56 // The dialog will by default be modeless, unless you set 'modal' to
57 // TRUE to construct a modal dialog.
58 //=================================================================================
59 GenerationGUI_FillingDlg::GenerationGUI_FillingDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
60 const char* name, bool modal, WFlags fl)
61 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal,
62 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
64 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FILLING")));
65 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
67 setCaption(tr("GEOM_FILLING_TITLE"));
69 /***************************************************************/
70 GroupConstructors->setTitle(tr("GEOM_FILLING"));
71 RadioButton1->setPixmap(image0);
72 RadioButton2->close(TRUE);
73 RadioButton3->close(TRUE);
75 GroupPoints = new DlgRef_1Sel5Spin1Check(this, "GroupPoints");
76 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
77 GroupPoints->TextLabel1->setText(tr("GEOM_FILLING_COMPOUND"));
78 GroupPoints->TextLabel2->setText(tr("GEOM_FILLING_MIN_DEG"));
79 GroupPoints->TextLabel3->setText(tr("GEOM_FILLING_TOL_2D"));
80 GroupPoints->TextLabel4->setText(tr("GEOM_FILLING_NB_ITER"));
81 GroupPoints->TextLabel5->setText(tr("GEOM_FILLING_MAX_DEG"));
82 GroupPoints->TextLabel6->setText(tr("GEOM_FILLING_TOL_3D"));
83 GroupPoints->CheckBox1->setText(tr("GEOM_FILLING_APPROX"));
84 GroupPoints->PushButton1->setPixmap(image1);
85 GroupPoints->LineEdit1->setReadOnly( true );
87 Layout1->addWidget(GroupPoints, 2, 0);
88 /***************************************************************/
90 setHelpFileName("create_filling_page.html");
96 //=================================================================================
97 // function : ~GenerationGUI_FillingDlg()
98 // purpose : Destroys the object and frees any allocated resources
99 //=================================================================================
100 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
102 // no need to delete child widgets, Qt does it all for us
105 //=================================================================================
108 //=================================================================================
109 void GenerationGUI_FillingDlg::Init()
112 myEditCurrentArgument = GroupPoints->LineEdit1;
113 GroupPoints->LineEdit1->setReadOnly( true );
121 myOkCompound = false;
123 globalSelection( GEOM_COMPOUND );
125 double SpecificStep1 = 1;
126 double SpecificStep2 = 0.0001;
127 /* min, max, step and decimals for spin boxes & initial values */
128 GroupPoints->SpinBox_1->RangeStepAndValidator(2.0, MAX_NUMBER, SpecificStep1, 3);
129 GroupPoints->SpinBox_2->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
130 GroupPoints->SpinBox_3->RangeStepAndValidator(0.0, MAX_NUMBER, SpecificStep1, 3);
131 GroupPoints->SpinBox_4->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep1, 3);
132 GroupPoints->SpinBox_5->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
134 GroupPoints->SpinBox_1->SetValue(myMinDeg);
135 GroupPoints->SpinBox_2->SetValue(myTol2D);
136 GroupPoints->SpinBox_3->SetValue(myNbIter);
137 GroupPoints->SpinBox_4->SetValue(myMaxDeg);
138 GroupPoints->SpinBox_5->SetValue(myTol3D);
140 /* signals and slots connections */
141 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
142 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
144 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(GroupPoints->SpinBox_1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
148 connect(GroupPoints->SpinBox_2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
149 connect(GroupPoints->SpinBox_3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
150 connect(GroupPoints->SpinBox_4, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
151 connect(GroupPoints->SpinBox_5, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
152 connect(GroupPoints->CheckBox1, SIGNAL(stateChanged(int)), this, SLOT(ApproxChanged()));
154 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_1, SLOT(SetStep(double)));
155 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_2, SLOT(SetStep(double)));
156 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_3, SLOT(SetStep(double)));
157 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_4, SLOT(SetStep(double)));
158 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_5, SLOT(SetStep(double)));
160 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
161 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
163 initName(tr("GEOM_FILLING"));
167 //=================================================================================
168 // function : ClickOnOk()
170 //=================================================================================
171 void GenerationGUI_FillingDlg::ClickOnOk()
173 if ( ClickOnApply() )
178 //=================================================================================
179 // function : ClickOnApply()
181 //=================================================================================
182 bool GenerationGUI_FillingDlg::ClickOnApply()
192 //=================================================================================
193 // function : SelectionIntoArgument()
194 // purpose : Called when selection as changed or other case
195 //=================================================================================
196 void GenerationGUI_FillingDlg::SelectionIntoArgument()
199 myEditCurrentArgument->setText("");
201 if(IObjectCount() != 1) {
202 if(myEditCurrentArgument == GroupPoints->LineEdit1)
203 myOkCompound = false;
208 Standard_Boolean testResult = Standard_False;
209 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
214 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
216 myOkCompound = false;
218 if ( GEOMBase::GetShape(aSelectedObject, S) &&
219 S.ShapeType() == TopAbs_COMPOUND)
221 // myCompound should be a compound of edges
222 for ( TopoDS_Iterator it( S ); it.More(); it.Next() )
223 if ( it.Value().ShapeType() != TopAbs_EDGE )
225 myCompound = aSelectedObject;
230 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
235 //=================================================================================
236 // function : SetEditCurrentArgument()
238 //=================================================================================
239 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
241 QPushButton* send = (QPushButton*)sender();
242 globalSelection( GEOM_ALLSHAPES );
244 if(send == GroupPoints->PushButton1) {
245 GroupPoints->LineEdit1->setFocus();
246 myEditCurrentArgument = GroupPoints->LineEdit1;
247 globalSelection( GEOM_COMPOUND );
248 this->SelectionIntoArgument();
253 //=================================================================================
254 // function : LineEditReturnPressed()
256 //=================================================================================
257 void GenerationGUI_FillingDlg::LineEditReturnPressed()
259 QLineEdit* send = (QLineEdit*)sender();
260 if(send == GroupPoints->LineEdit1)
262 myEditCurrentArgument = send;
263 GEOMBase_Skeleton::LineEditReturnPressed();
268 //=================================================================================
269 // function : ActivateThisDialog()
271 //=================================================================================
272 void GenerationGUI_FillingDlg::ActivateThisDialog()
274 GEOMBase_Skeleton::ActivateThisDialog();
275 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
276 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
277 globalSelection( GEOM_COMPOUND );
282 //=================================================================================
283 // function : enterEvent()
285 //=================================================================================
286 void GenerationGUI_FillingDlg::enterEvent(QEvent* e)
288 if ( !GroupConstructors->isEnabled() )
289 ActivateThisDialog();
293 //=================================================================================
294 // function : ValueChangedInSpinBox()
296 //=================================================================================
297 void GenerationGUI_FillingDlg::ValueChangedInSpinBox(double newValue)
299 QObject* send = (QObject*)sender();
301 if(send == GroupPoints->SpinBox_1)
302 myMinDeg = int(newValue);
303 else if(send == GroupPoints->SpinBox_2)
305 else if(send == GroupPoints->SpinBox_3)
306 myNbIter = int(newValue);
307 else if(send == GroupPoints->SpinBox_4)
308 myMaxDeg = int(newValue);
309 else if(send == GroupPoints->SpinBox_5)
315 //=================================================================================
316 // function : ApproxChanged()
318 //=================================================================================
319 void GenerationGUI_FillingDlg::ApproxChanged()
321 myIsApprox = GroupPoints->CheckBox1->isChecked();
325 //=================================================================================
326 // function : createOperation
328 //=================================================================================
329 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
331 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
334 //=================================================================================
335 // function : isValid
337 //=================================================================================
338 bool GenerationGUI_FillingDlg::isValid( QString& )
340 return myOkCompound > 0;
343 //=================================================================================
344 // function : execute
346 //=================================================================================
347 bool GenerationGUI_FillingDlg::execute( ObjectList& objects )
349 GEOM::GEOM_Object_var anObj;
351 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation() )->MakeFilling(
352 myCompound, myMinDeg, myMaxDeg, myTol2D, myTol3D, myNbIter, myIsApprox );
354 if ( !anObj->_is_nil() )
355 objects.push_back( anObj._retn() );