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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : GenerationGUI_FillingDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "GenerationGUI_FillingDlg.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
36 #include <GeomFill_SectionGenerator.hxx>
37 #include <GeomFill_Line.hxx>
38 #include <GeomFill_AppSurf.hxx>
39 #include <Geom_BSplineSurface.hxx>
40 #include <Geom_TrimmedCurve.hxx>
41 #include <BRepBuilderAPI_MakeFace.hxx>
42 #include <TopExp_Explorer.hxx>
43 #include <TopoDS_Iterator.hxx>
44 #include <BRep_Tool.hxx>
45 #include <Precision.hxx>
46 #include "GEOMImpl_Types.hxx"
49 #include <qcheckbox.h>
51 #include "utilities.h"
53 //=================================================================================
54 // class : GenerationGUI_FillingDlg()
55 // purpose : Constructs a GenerationGUI_FillingDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 GenerationGUI_FillingDlg::GenerationGUI_FillingDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
61 const char* name, bool modal, WFlags fl)
62 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal,
63 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
65 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FILLING")));
66 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
68 setCaption(tr("GEOM_FILLING_TITLE"));
70 /***************************************************************/
71 GroupConstructors->setTitle(tr("GEOM_FILLING"));
72 RadioButton1->setPixmap(image0);
73 RadioButton2->close(TRUE);
74 RadioButton3->close(TRUE);
76 GroupPoints = new DlgRef_1Sel5Spin1Check(this, "GroupPoints");
77 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
78 GroupPoints->TextLabel1->setText(tr("GEOM_FILLING_COMPOUND"));
79 GroupPoints->TextLabel2->setText(tr("GEOM_FILLING_MIN_DEG"));
80 GroupPoints->TextLabel3->setText(tr("GEOM_FILLING_TOL_2D"));
81 GroupPoints->TextLabel4->setText(tr("GEOM_FILLING_NB_ITER"));
82 GroupPoints->TextLabel5->setText(tr("GEOM_FILLING_MAX_DEG"));
83 GroupPoints->TextLabel6->setText(tr("GEOM_FILLING_TOL_3D"));
84 GroupPoints->CheckBox1->setText(tr("GEOM_FILLING_APPROX"));
85 GroupPoints->PushButton1->setPixmap(image1);
86 GroupPoints->LineEdit1->setReadOnly( true );
88 Layout1->addWidget(GroupPoints, 2, 0);
89 /***************************************************************/
91 setHelpFileName("create_filling_page.html");
97 //=================================================================================
98 // function : ~GenerationGUI_FillingDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
103 // no need to delete child widgets, Qt does it all for us
106 //=================================================================================
109 //=================================================================================
110 void GenerationGUI_FillingDlg::Init()
113 myEditCurrentArgument = GroupPoints->LineEdit1;
114 GroupPoints->LineEdit1->setReadOnly( true );
122 myOkCompound = false;
124 globalSelection( GEOM_COMPOUND );
126 double SpecificStep1 = 1;
127 double SpecificStep2 = 0.0001;
128 /* min, max, step and decimals for spin boxes & initial values */
129 GroupPoints->SpinBox_1->RangeStepAndValidator(2.0, MAX_NUMBER, SpecificStep1, 3);
130 GroupPoints->SpinBox_2->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
131 GroupPoints->SpinBox_3->RangeStepAndValidator(0.0, MAX_NUMBER, SpecificStep1, 3);
132 GroupPoints->SpinBox_4->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep1, 3);
133 GroupPoints->SpinBox_5->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
135 GroupPoints->SpinBox_1->SetValue(myMinDeg);
136 GroupPoints->SpinBox_2->SetValue(myTol2D);
137 GroupPoints->SpinBox_3->SetValue(myNbIter);
138 GroupPoints->SpinBox_4->SetValue(myMaxDeg);
139 GroupPoints->SpinBox_5->SetValue(myTol3D);
141 /* signals and slots connections */
142 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
143 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
145 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
148 connect(GroupPoints->SpinBox_1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
149 connect(GroupPoints->SpinBox_2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
150 connect(GroupPoints->SpinBox_3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
151 connect(GroupPoints->SpinBox_4, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
152 connect(GroupPoints->SpinBox_5, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
153 connect(GroupPoints->CheckBox1, SIGNAL(stateChanged(int)), this, SLOT(ApproxChanged()));
155 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_1, SLOT(SetStep(double)));
156 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_2, SLOT(SetStep(double)));
157 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_3, SLOT(SetStep(double)));
158 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_4, SLOT(SetStep(double)));
159 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_5, SLOT(SetStep(double)));
161 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
162 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
164 initName(tr("GEOM_FILLING"));
168 //=================================================================================
169 // function : ClickOnOk()
171 //=================================================================================
172 void GenerationGUI_FillingDlg::ClickOnOk()
174 if ( ClickOnApply() )
179 //=================================================================================
180 // function : ClickOnApply()
182 //=================================================================================
183 bool GenerationGUI_FillingDlg::ClickOnApply()
193 //=================================================================================
194 // function : SelectionIntoArgument()
195 // purpose : Called when selection as changed or other case
196 //=================================================================================
197 void GenerationGUI_FillingDlg::SelectionIntoArgument()
200 myEditCurrentArgument->setText("");
202 if(IObjectCount() != 1) {
203 if(myEditCurrentArgument == GroupPoints->LineEdit1)
204 myOkCompound = false;
209 Standard_Boolean testResult = Standard_False;
210 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
215 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
217 myOkCompound = false;
219 if ( GEOMBase::GetShape(aSelectedObject, S) &&
220 S.ShapeType() == TopAbs_COMPOUND)
222 // myCompound should be a compound of edges
223 for ( TopoDS_Iterator it( S ); it.More(); it.Next() )
224 if ( it.Value().ShapeType() != TopAbs_EDGE )
226 myCompound = aSelectedObject;
231 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
236 //=================================================================================
237 // function : SetEditCurrentArgument()
239 //=================================================================================
240 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
242 QPushButton* send = (QPushButton*)sender();
243 globalSelection( GEOM_ALLSHAPES );
245 if(send == GroupPoints->PushButton1) {
246 GroupPoints->LineEdit1->setFocus();
247 myEditCurrentArgument = GroupPoints->LineEdit1;
248 globalSelection( GEOM_COMPOUND );
249 this->SelectionIntoArgument();
254 //=================================================================================
255 // function : LineEditReturnPressed()
257 //=================================================================================
258 void GenerationGUI_FillingDlg::LineEditReturnPressed()
260 QLineEdit* send = (QLineEdit*)sender();
261 if(send == GroupPoints->LineEdit1)
263 myEditCurrentArgument = send;
264 GEOMBase_Skeleton::LineEditReturnPressed();
269 //=================================================================================
270 // function : ActivateThisDialog()
272 //=================================================================================
273 void GenerationGUI_FillingDlg::ActivateThisDialog()
275 GEOMBase_Skeleton::ActivateThisDialog();
276 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
277 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
278 globalSelection( GEOM_COMPOUND );
283 //=================================================================================
284 // function : enterEvent()
286 //=================================================================================
287 void GenerationGUI_FillingDlg::enterEvent(QEvent* e)
289 if ( !GroupConstructors->isEnabled() )
290 ActivateThisDialog();
294 //=================================================================================
295 // function : ValueChangedInSpinBox()
297 //=================================================================================
298 void GenerationGUI_FillingDlg::ValueChangedInSpinBox(double newValue)
300 QObject* send = (QObject*)sender();
302 if(send == GroupPoints->SpinBox_1)
303 myMinDeg = int(newValue);
304 else if(send == GroupPoints->SpinBox_2)
306 else if(send == GroupPoints->SpinBox_3)
307 myNbIter = int(newValue);
308 else if(send == GroupPoints->SpinBox_4)
309 myMaxDeg = int(newValue);
310 else if(send == GroupPoints->SpinBox_5)
316 //=================================================================================
317 // function : ApproxChanged()
319 //=================================================================================
320 void GenerationGUI_FillingDlg::ApproxChanged()
322 myIsApprox = GroupPoints->CheckBox1->isChecked();
326 //=================================================================================
327 // function : createOperation
329 //=================================================================================
330 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
332 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
335 //=================================================================================
336 // function : isValid
338 //=================================================================================
339 bool GenerationGUI_FillingDlg::isValid( QString& )
341 return myOkCompound > 0;
344 //=================================================================================
345 // function : execute
347 //=================================================================================
348 bool GenerationGUI_FillingDlg::execute( ObjectList& objects )
350 GEOM::GEOM_Object_var anObj;
352 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation() )->MakeFilling(
353 myCompound, myMinDeg, myMaxDeg, myTol2D, myTol3D, myNbIter, myIsApprox );
355 if ( !anObj->_is_nil() )
356 objects.push_back( anObj._retn() );