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 <Standard_ErrorHandler.hxx>
47 #include "GEOMImpl_Types.hxx"
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_1Sel5Spin(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->PushButton1->setPixmap(image1);
85 GroupPoints->LineEdit1->setReadOnly( true );
87 Layout1->addWidget(GroupPoints, 2, 0);
88 /***************************************************************/
90 setHelpFileName("filling.htm");
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 );
120 myOkCompound = false;
122 globalSelection( GEOM_COMPOUND );
124 double SpecificStep1 = 1;
125 double SpecificStep2 = 0.0001;
126 /* min, max, step and decimals for spin boxes & initial values */
127 GroupPoints->SpinBox_1->RangeStepAndValidator(2.0, 999.999, SpecificStep1, 3);
128 GroupPoints->SpinBox_2->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
129 GroupPoints->SpinBox_3->RangeStepAndValidator(1.0, 999.999, SpecificStep1, 3);
130 GroupPoints->SpinBox_4->RangeStepAndValidator(1.0, 999.999, SpecificStep1, 3);
131 GroupPoints->SpinBox_5->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
133 GroupPoints->SpinBox_1->SetValue(myMinDeg);
134 GroupPoints->SpinBox_2->SetValue(myTol2D);
135 GroupPoints->SpinBox_3->SetValue(myNbIter);
136 GroupPoints->SpinBox_4->SetValue(myMaxDeg);
137 GroupPoints->SpinBox_5->SetValue(myTol3D);
139 /* signals and slots connections */
140 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
141 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
143 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
144 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146 connect(GroupPoints->SpinBox_1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
147 connect(GroupPoints->SpinBox_2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
148 connect(GroupPoints->SpinBox_3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
149 connect(GroupPoints->SpinBox_4, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
150 connect(GroupPoints->SpinBox_5, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
152 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_1, SLOT(SetStep(double)));
153 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_2, SLOT(SetStep(double)));
154 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_3, SLOT(SetStep(double)));
155 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_4, SLOT(SetStep(double)));
156 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_5, SLOT(SetStep(double)));
158 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
159 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
161 initName(tr("GEOM_FILLING"));
165 //=================================================================================
166 // function : ClickOnOk()
168 //=================================================================================
169 void GenerationGUI_FillingDlg::ClickOnOk()
171 if ( ClickOnApply() )
176 //=================================================================================
177 // function : ClickOnApply()
179 //=================================================================================
180 bool GenerationGUI_FillingDlg::ClickOnApply()
190 //=================================================================================
191 // function : SelectionIntoArgument()
192 // purpose : Called when selection as changed or other case
193 //=================================================================================
194 void GenerationGUI_FillingDlg::SelectionIntoArgument()
197 myEditCurrentArgument->setText("");
199 if(IObjectCount() != 1) {
200 if(myEditCurrentArgument == GroupPoints->LineEdit1)
201 myOkCompound = false;
206 Standard_Boolean testResult = Standard_False;
207 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
212 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
214 myOkCompound = false;
216 if ( GEOMBase::GetShape(aSelectedObject, S) &&
217 S.ShapeType() == TopAbs_COMPOUND)
219 // myCompound should be a compound of edges
220 for ( TopoDS_Iterator it( S ); it.More(); it.Next() )
221 if ( it.Value().ShapeType() != TopAbs_EDGE )
223 myCompound = aSelectedObject;
228 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
233 //=================================================================================
234 // function : SetEditCurrentArgument()
236 //=================================================================================
237 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
239 QPushButton* send = (QPushButton*)sender();
240 globalSelection( GEOM_ALLSHAPES );
242 if(send == GroupPoints->PushButton1) {
243 GroupPoints->LineEdit1->setFocus();
244 myEditCurrentArgument = GroupPoints->LineEdit1;
245 globalSelection( GEOM_COMPOUND );
246 this->SelectionIntoArgument();
251 //=================================================================================
252 // function : LineEditReturnPressed()
254 //=================================================================================
255 void GenerationGUI_FillingDlg::LineEditReturnPressed()
257 QLineEdit* send = (QLineEdit*)sender();
258 if(send == GroupPoints->LineEdit1)
260 myEditCurrentArgument = send;
261 GEOMBase_Skeleton::LineEditReturnPressed();
266 //=================================================================================
267 // function : ActivateThisDialog()
269 //=================================================================================
270 void GenerationGUI_FillingDlg::ActivateThisDialog()
272 GEOMBase_Skeleton::ActivateThisDialog();
273 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
274 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
275 globalSelection( GEOM_COMPOUND );
280 //=================================================================================
281 // function : enterEvent()
283 //=================================================================================
284 void GenerationGUI_FillingDlg::enterEvent(QEvent* e)
286 if ( !GroupConstructors->isEnabled() )
287 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)
313 //=================================================================================
314 // function : createOperation
316 //=================================================================================
317 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
319 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
322 //=================================================================================
323 // function : isValid
325 //=================================================================================
326 bool GenerationGUI_FillingDlg::isValid( QString& )
328 return myOkCompound > 0;
331 //=================================================================================
332 // function : execute
334 //=================================================================================
335 bool GenerationGUI_FillingDlg::execute( ObjectList& objects )
337 GEOM::GEOM_Object_var anObj;
339 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation() )->MakeFilling(
340 myCompound, myMinDeg, myMaxDeg, myTol2D, myTol3D, myNbIter );
342 if ( !anObj->_is_nil() )
343 objects.push_back( anObj._retn() );