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 "QAD_WaitCursor.h"
32 #include "QAD_Config.h"
33 #include "QAD_Desktop.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 <Standard_ErrorHandler.hxx>
46 #include "GEOMImpl_Types.hxx"
48 #include "utilities.h"
50 //=================================================================================
51 // class : GenerationGUI_FillingDlg()
52 // purpose : Constructs a GenerationGUI_FillingDlg which is a child of 'parent', with the
53 // name 'name' and widget flags set to 'f'.
54 // The dialog will by default be modeless, unless you set 'modal' to
55 // TRUE to construct a modal dialog.
56 //=================================================================================
57 GenerationGUI_FillingDlg::GenerationGUI_FillingDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
58 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
60 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_FILLING")));
61 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
63 setCaption(tr("GEOM_FILLING_TITLE"));
65 /***************************************************************/
66 GroupConstructors->setTitle(tr("GEOM_FILLING"));
67 RadioButton1->setPixmap(image0);
68 RadioButton2->close(TRUE);
69 RadioButton3->close(TRUE);
71 GroupPoints = new DlgRef_1Sel5Spin(this, "GroupPoints");
72 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
73 GroupPoints->TextLabel1->setText(tr("GEOM_FILLING_COMPOUND"));
74 GroupPoints->TextLabel2->setText(tr("GEOM_FILLING_MIN_DEG"));
75 GroupPoints->TextLabel3->setText(tr("GEOM_FILLING_TOL_2D"));
76 GroupPoints->TextLabel4->setText(tr("GEOM_FILLING_NB_ITER"));
77 GroupPoints->TextLabel5->setText(tr("GEOM_FILLING_MAX_DEG"));
78 GroupPoints->TextLabel6->setText(tr("GEOM_FILLING_TOL_3D"));
79 GroupPoints->PushButton1->setPixmap(image1);
80 GroupPoints->LineEdit1->setReadOnly( true );
82 Layout1->addWidget(GroupPoints, 2, 0);
83 /***************************************************************/
90 //=================================================================================
91 // function : ~GenerationGUI_FillingDlg()
92 // purpose : Destroys the object and frees any allocated resources
93 //=================================================================================
94 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
96 // no need to delete child widgets, Qt does it all for us
100 //=================================================================================
103 //=================================================================================
104 void GenerationGUI_FillingDlg::Init()
107 myEditCurrentArgument = GroupPoints->LineEdit1;
108 GroupPoints->LineEdit1->setReadOnly( true );
115 myOkCompound = false;
117 globalSelection( GEOM_COMPOUND );
119 double SpecificStep1 = 1;
120 double SpecificStep2 = 0.0001;
121 /* min, max, step and decimals for spin boxes & initial values */
122 GroupPoints->SpinBox_1->RangeStepAndValidator(2.0, 999.999, SpecificStep1, 3);
123 GroupPoints->SpinBox_2->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
124 GroupPoints->SpinBox_3->RangeStepAndValidator(1.0, 999.999, SpecificStep1, 3);
125 GroupPoints->SpinBox_4->RangeStepAndValidator(1.0, 999.999, SpecificStep1, 3);
126 GroupPoints->SpinBox_5->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
128 GroupPoints->SpinBox_1->SetValue(myMinDeg);
129 GroupPoints->SpinBox_2->SetValue(myTol2D);
130 GroupPoints->SpinBox_3->SetValue(myNbIter);
131 GroupPoints->SpinBox_4->SetValue(myMaxDeg);
132 GroupPoints->SpinBox_5->SetValue(myTol3D);
134 /* signals and slots connections */
135 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
136 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
138 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
141 connect(GroupPoints->SpinBox_1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
142 connect(GroupPoints->SpinBox_2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
143 connect(GroupPoints->SpinBox_3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
144 connect(GroupPoints->SpinBox_4, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
145 connect(GroupPoints->SpinBox_5, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
147 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_1, SLOT(SetStep(double)));
148 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_2, SLOT(SetStep(double)));
149 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_3, SLOT(SetStep(double)));
150 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_4, SLOT(SetStep(double)));
151 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_5, SLOT(SetStep(double)));
153 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
155 initName(tr("GEOM_FILLING"));
159 //=================================================================================
160 // function : ClickOnOk()
162 //=================================================================================
163 void GenerationGUI_FillingDlg::ClickOnOk()
165 if ( ClickOnApply() )
170 //=================================================================================
171 // function : ClickOnApply()
173 //=================================================================================
174 bool GenerationGUI_FillingDlg::ClickOnApply()
184 //=================================================================================
185 // function : SelectionIntoArgument()
186 // purpose : Called when selection as changed or other case
187 //=================================================================================
188 void GenerationGUI_FillingDlg::SelectionIntoArgument()
191 myEditCurrentArgument->setText("");
193 if(mySelection->IObjectCount() != 1) {
194 if(myEditCurrentArgument == GroupPoints->LineEdit1)
195 myOkCompound = false;
200 Standard_Boolean testResult = Standard_False;
201 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
206 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
208 myOkCompound = false;
210 if ( GEOMBase::GetShape(aSelectedObject, S) &&
211 S.ShapeType() == TopAbs_COMPOUND)
213 // myCompound should be a compound of edges
214 for ( TopoDS_Iterator it( S ); it.More(); it.Next() )
215 if ( it.Value().ShapeType() != TopAbs_EDGE )
217 myCompound = aSelectedObject;
222 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
227 //=================================================================================
228 // function : SetEditCurrentArgument()
230 //=================================================================================
231 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
233 QPushButton* send = (QPushButton*)sender();
234 globalSelection( GEOM_ALLSHAPES );
236 if(send == GroupPoints->PushButton1) {
237 GroupPoints->LineEdit1->setFocus();
238 myEditCurrentArgument = GroupPoints->LineEdit1;
239 globalSelection( GEOM_COMPOUND );
240 this->SelectionIntoArgument();
245 //=================================================================================
246 // function : LineEditReturnPressed()
248 //=================================================================================
249 void GenerationGUI_FillingDlg::LineEditReturnPressed()
251 QLineEdit* send = (QLineEdit*)sender();
252 if(send == GroupPoints->LineEdit1)
254 myEditCurrentArgument = send;
255 GEOMBase_Skeleton::LineEditReturnPressed();
260 //=================================================================================
261 // function : ActivateThisDialog()
263 //=================================================================================
264 void GenerationGUI_FillingDlg::ActivateThisDialog()
266 GEOMBase_Skeleton::ActivateThisDialog();
267 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
268 globalSelection( GEOM_COMPOUND );
273 //=================================================================================
274 // function : enterEvent()
276 //=================================================================================
277 void GenerationGUI_FillingDlg::enterEvent(QEvent* e)
279 if ( !GroupConstructors->isEnabled() )
280 ActivateThisDialog();
284 //=================================================================================
285 // function : ValueChangedInSpinBox()
287 //=================================================================================
288 void GenerationGUI_FillingDlg::ValueChangedInSpinBox(double newValue)
290 QObject* send = (QObject*)sender();
292 if(send == GroupPoints->SpinBox_1)
293 myMinDeg = int(newValue);
294 else if(send == GroupPoints->SpinBox_2)
296 else if(send == GroupPoints->SpinBox_3)
297 myNbIter = int(newValue);
298 else if(send == GroupPoints->SpinBox_4)
299 myMaxDeg = int(newValue);
300 else if(send == GroupPoints->SpinBox_5)
306 //=================================================================================
307 // function : createOperation
309 //=================================================================================
310 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
312 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
315 //=================================================================================
316 // function : isValid
318 //=================================================================================
319 bool GenerationGUI_FillingDlg::isValid( QString& )
321 return myOkCompound > 0;
324 //=================================================================================
325 // function : execute
327 //=================================================================================
328 bool GenerationGUI_FillingDlg::execute( ObjectList& objects )
330 GEOM::GEOM_Object_var anObj;
332 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation() )->MakeFilling(
333 myCompound, myMinDeg, myMaxDeg, myTol2D, myTol3D, myNbIter );
335 if ( !anObj->_is_nil() )
336 objects.push_back( anObj._retn() );