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
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(parent, name, modal,
63 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
64 myGeometryGUI(theGeometryGUI)
66 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FILLING")));
67 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
69 setCaption(tr("GEOM_FILLING_TITLE"));
71 /***************************************************************/
72 GroupConstructors->setTitle(tr("GEOM_FILLING"));
73 RadioButton1->setPixmap(image0);
74 RadioButton2->close(TRUE);
75 RadioButton3->close(TRUE);
77 GroupPoints = new DlgRef_1Sel5Spin(this, "GroupPoints");
78 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
79 GroupPoints->TextLabel1->setText(tr("GEOM_FILLING_COMPOUND"));
80 GroupPoints->TextLabel2->setText(tr("GEOM_FILLING_MIN_DEG"));
81 GroupPoints->TextLabel3->setText(tr("GEOM_FILLING_TOL_2D"));
82 GroupPoints->TextLabel4->setText(tr("GEOM_FILLING_NB_ITER"));
83 GroupPoints->TextLabel5->setText(tr("GEOM_FILLING_MAX_DEG"));
84 GroupPoints->TextLabel6->setText(tr("GEOM_FILLING_TOL_3D"));
85 GroupPoints->PushButton1->setPixmap(image1);
86 GroupPoints->LineEdit1->setReadOnly( true );
88 Layout1->addWidget(GroupPoints, 2, 0);
89 /***************************************************************/
95 //=================================================================================
96 // function : ~GenerationGUI_FillingDlg()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
101 // no need to delete child widgets, Qt does it all for us
104 //=================================================================================
107 //=================================================================================
108 void GenerationGUI_FillingDlg::Init()
111 myEditCurrentArgument = GroupPoints->LineEdit1;
112 GroupPoints->LineEdit1->setReadOnly( true );
119 myOkCompound = false;
121 globalSelection( GEOM_COMPOUND );
123 double SpecificStep1 = 1;
124 double SpecificStep2 = 0.0001;
125 /* min, max, step and decimals for spin boxes & initial values */
126 GroupPoints->SpinBox_1->RangeStepAndValidator(2.0, 999.999, SpecificStep1, 3);
127 GroupPoints->SpinBox_2->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
128 GroupPoints->SpinBox_3->RangeStepAndValidator(1.0, 999.999, SpecificStep1, 3);
129 GroupPoints->SpinBox_4->RangeStepAndValidator(1.0, 999.999, SpecificStep1, 3);
130 GroupPoints->SpinBox_5->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
132 GroupPoints->SpinBox_1->SetValue(myMinDeg);
133 GroupPoints->SpinBox_2->SetValue(myTol2D);
134 GroupPoints->SpinBox_3->SetValue(myNbIter);
135 GroupPoints->SpinBox_4->SetValue(myMaxDeg);
136 GroupPoints->SpinBox_5->SetValue(myTol3D);
138 /* signals and slots connections */
139 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
140 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
142 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145 connect(GroupPoints->SpinBox_1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
146 connect(GroupPoints->SpinBox_2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
147 connect(GroupPoints->SpinBox_3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
148 connect(GroupPoints->SpinBox_4, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
149 connect(GroupPoints->SpinBox_5, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
151 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_1, SLOT(SetStep(double)));
152 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_2, SLOT(SetStep(double)));
153 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_3, SLOT(SetStep(double)));
154 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_4, SLOT(SetStep(double)));
155 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_5, SLOT(SetStep(double)));
157 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
158 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
160 initName(tr("GEOM_FILLING"));
164 //=================================================================================
165 // function : ClickOnOk()
167 //=================================================================================
168 void GenerationGUI_FillingDlg::ClickOnOk()
170 if ( ClickOnApply() )
175 //=================================================================================
176 // function : ClickOnApply()
178 //=================================================================================
179 bool GenerationGUI_FillingDlg::ClickOnApply()
189 //=================================================================================
190 // function : SelectionIntoArgument()
191 // purpose : Called when selection as changed or other case
192 //=================================================================================
193 void GenerationGUI_FillingDlg::SelectionIntoArgument()
196 myEditCurrentArgument->setText("");
198 if(IObjectCount() != 1) {
199 if(myEditCurrentArgument == GroupPoints->LineEdit1)
200 myOkCompound = false;
205 Standard_Boolean testResult = Standard_False;
206 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
211 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
213 myOkCompound = false;
215 if ( GEOMBase::GetShape(aSelectedObject, S) &&
216 S.ShapeType() == TopAbs_COMPOUND)
218 // myCompound should be a compound of edges
219 for ( TopoDS_Iterator it( S ); it.More(); it.Next() )
220 if ( it.Value().ShapeType() != TopAbs_EDGE )
222 myCompound = aSelectedObject;
227 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
232 //=================================================================================
233 // function : SetEditCurrentArgument()
235 //=================================================================================
236 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
238 QPushButton* send = (QPushButton*)sender();
239 globalSelection( GEOM_ALLSHAPES );
241 if(send == GroupPoints->PushButton1) {
242 GroupPoints->LineEdit1->setFocus();
243 myEditCurrentArgument = GroupPoints->LineEdit1;
244 globalSelection( GEOM_COMPOUND );
245 this->SelectionIntoArgument();
250 //=================================================================================
251 // function : LineEditReturnPressed()
253 //=================================================================================
254 void GenerationGUI_FillingDlg::LineEditReturnPressed()
256 QLineEdit* send = (QLineEdit*)sender();
257 if(send == GroupPoints->LineEdit1)
259 myEditCurrentArgument = send;
260 GEOMBase_Skeleton::LineEditReturnPressed();
265 //=================================================================================
266 // function : ActivateThisDialog()
268 //=================================================================================
269 void GenerationGUI_FillingDlg::ActivateThisDialog()
271 GEOMBase_Skeleton::ActivateThisDialog();
272 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
273 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
274 globalSelection( GEOM_COMPOUND );
279 //=================================================================================
280 // function : enterEvent()
282 //=================================================================================
283 void GenerationGUI_FillingDlg::enterEvent(QEvent* e)
285 if ( !GroupConstructors->isEnabled() )
286 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)
312 //=================================================================================
313 // function : createOperation
315 //=================================================================================
316 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
318 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
321 //=================================================================================
322 // function : isValid
324 //=================================================================================
325 bool GenerationGUI_FillingDlg::isValid( QString& )
327 return myOkCompound > 0;
330 //=================================================================================
331 // function : execute
333 //=================================================================================
334 bool GenerationGUI_FillingDlg::execute( ObjectList& objects )
336 GEOM::GEOM_Object_var anObj;
338 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation() )->MakeFilling(
339 myCompound, myMinDeg, myMaxDeg, myTol2D, myTol3D, myNbIter );
341 if ( !anObj->_is_nil() )
342 objects.push_back( anObj._retn() );