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 "SalomeApp_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, const char* name, bool modal, WFlags fl)
61 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
63 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_FILLING")));
64 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
66 setCaption(tr("GEOM_FILLING_TITLE"));
68 /***************************************************************/
69 GroupConstructors->setTitle(tr("GEOM_FILLING"));
70 RadioButton1->setPixmap(image0);
71 RadioButton2->close(TRUE);
72 RadioButton3->close(TRUE);
74 GroupPoints = new DlgRef_1Sel5Spin(this, "GroupPoints");
75 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
76 GroupPoints->TextLabel1->setText(tr("GEOM_FILLING_COMPOUND"));
77 GroupPoints->TextLabel2->setText(tr("GEOM_FILLING_MIN_DEG"));
78 GroupPoints->TextLabel3->setText(tr("GEOM_FILLING_TOL_2D"));
79 GroupPoints->TextLabel4->setText(tr("GEOM_FILLING_NB_ITER"));
80 GroupPoints->TextLabel5->setText(tr("GEOM_FILLING_MAX_DEG"));
81 GroupPoints->TextLabel6->setText(tr("GEOM_FILLING_TOL_3D"));
82 GroupPoints->PushButton1->setPixmap(image1);
83 GroupPoints->LineEdit1->setReadOnly( true );
85 Layout1->addWidget(GroupPoints, 2, 0);
86 /***************************************************************/
93 //=================================================================================
94 // function : ~GenerationGUI_FillingDlg()
95 // purpose : Destroys the object and frees any allocated resources
96 //=================================================================================
97 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
99 // no need to delete child widgets, Qt does it all for us
103 //=================================================================================
106 //=================================================================================
107 void GenerationGUI_FillingDlg::Init()
110 myEditCurrentArgument = GroupPoints->LineEdit1;
111 GroupPoints->LineEdit1->setReadOnly( true );
118 myOkCompound = false;
120 globalSelection( GEOM_COMPOUND );
122 double SpecificStep1 = 1;
123 double SpecificStep2 = 0.0001;
124 /* min, max, step and decimals for spin boxes & initial values */
125 GroupPoints->SpinBox_1->RangeStepAndValidator(2.0, 999.999, SpecificStep1, 3);
126 GroupPoints->SpinBox_2->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
127 GroupPoints->SpinBox_3->RangeStepAndValidator(1.0, 999.999, SpecificStep1, 3);
128 GroupPoints->SpinBox_4->RangeStepAndValidator(1.0, 999.999, SpecificStep1, 3);
129 GroupPoints->SpinBox_5->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
131 GroupPoints->SpinBox_1->SetValue(myMinDeg);
132 GroupPoints->SpinBox_2->SetValue(myTol2D);
133 GroupPoints->SpinBox_3->SetValue(myNbIter);
134 GroupPoints->SpinBox_4->SetValue(myMaxDeg);
135 GroupPoints->SpinBox_5->SetValue(myTol3D);
137 /* signals and slots connections */
138 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
139 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
141 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
144 connect(GroupPoints->SpinBox_1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
145 connect(GroupPoints->SpinBox_2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
146 connect(GroupPoints->SpinBox_3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
147 connect(GroupPoints->SpinBox_4, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
148 connect(GroupPoints->SpinBox_5, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
150 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_1, SLOT(SetStep(double)));
151 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_2, SLOT(SetStep(double)));
152 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_3, SLOT(SetStep(double)));
153 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_4, SLOT(SetStep(double)));
154 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_5, SLOT(SetStep(double)));
156 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
157 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
159 initName(tr("GEOM_FILLING"));
163 //=================================================================================
164 // function : ClickOnOk()
166 //=================================================================================
167 void GenerationGUI_FillingDlg::ClickOnOk()
169 if ( ClickOnApply() )
174 //=================================================================================
175 // function : ClickOnApply()
177 //=================================================================================
178 bool GenerationGUI_FillingDlg::ClickOnApply()
188 //=================================================================================
189 // function : SelectionIntoArgument()
190 // purpose : Called when selection as changed or other case
191 //=================================================================================
192 void GenerationGUI_FillingDlg::SelectionIntoArgument()
195 myEditCurrentArgument->setText("");
197 if(IObjectCount() != 1) {
198 if(myEditCurrentArgument == GroupPoints->LineEdit1)
199 myOkCompound = false;
204 Standard_Boolean testResult = Standard_False;
205 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
210 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
212 myOkCompound = false;
214 if ( GEOMBase::GetShape(aSelectedObject, S) &&
215 S.ShapeType() == TopAbs_COMPOUND)
217 // myCompound should be a compound of edges
218 for ( TopoDS_Iterator it( S ); it.More(); it.Next() )
219 if ( it.Value().ShapeType() != TopAbs_EDGE )
221 myCompound = aSelectedObject;
226 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
231 //=================================================================================
232 // function : SetEditCurrentArgument()
234 //=================================================================================
235 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
237 QPushButton* send = (QPushButton*)sender();
238 globalSelection( GEOM_ALLSHAPES );
240 if(send == GroupPoints->PushButton1) {
241 GroupPoints->LineEdit1->setFocus();
242 myEditCurrentArgument = GroupPoints->LineEdit1;
243 globalSelection( GEOM_COMPOUND );
244 this->SelectionIntoArgument();
249 //=================================================================================
250 // function : LineEditReturnPressed()
252 //=================================================================================
253 void GenerationGUI_FillingDlg::LineEditReturnPressed()
255 QLineEdit* send = (QLineEdit*)sender();
256 if(send == GroupPoints->LineEdit1)
258 myEditCurrentArgument = send;
259 GEOMBase_Skeleton::LineEditReturnPressed();
264 //=================================================================================
265 // function : ActivateThisDialog()
267 //=================================================================================
268 void GenerationGUI_FillingDlg::ActivateThisDialog()
270 GEOMBase_Skeleton::ActivateThisDialog();
271 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
272 globalSelection( GEOM_COMPOUND );
277 //=================================================================================
278 // function : enterEvent()
280 //=================================================================================
281 void GenerationGUI_FillingDlg::enterEvent(QEvent* e)
283 if ( !GroupConstructors->isEnabled() )
284 ActivateThisDialog();
288 //=================================================================================
289 // function : ValueChangedInSpinBox()
291 //=================================================================================
292 void GenerationGUI_FillingDlg::ValueChangedInSpinBox(double newValue)
294 QObject* send = (QObject*)sender();
296 if(send == GroupPoints->SpinBox_1)
297 myMinDeg = int(newValue);
298 else if(send == GroupPoints->SpinBox_2)
300 else if(send == GroupPoints->SpinBox_3)
301 myNbIter = int(newValue);
302 else if(send == GroupPoints->SpinBox_4)
303 myMaxDeg = int(newValue);
304 else if(send == GroupPoints->SpinBox_5)
310 //=================================================================================
311 // function : createOperation
313 //=================================================================================
314 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
316 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
319 //=================================================================================
320 // function : isValid
322 //=================================================================================
323 bool GenerationGUI_FillingDlg::isValid( QString& )
325 return myOkCompound > 0;
328 //=================================================================================
329 // function : execute
331 //=================================================================================
332 bool GenerationGUI_FillingDlg::execute( ObjectList& objects )
334 GEOM::GEOM_Object_var anObj;
336 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation() )->MakeFilling(
337 myCompound, myMinDeg, myMaxDeg, myTol2D, myTol3D, myNbIter );
339 if ( !anObj->_is_nil() )
340 objects.push_back( anObj._retn() );