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"
30 #include "DlgRef_1Sel5Spin.h"
31 #include "DlgRef_SpinBox.h"
33 #include "GeometryGUI.h"
36 #include "SUIT_ResourceMgr.h"
37 #include "SUIT_Session.h"
38 #include "SalomeApp_Application.h"
39 #include "LightApp_SelectionMgr.h"
41 #include <TopoDS_Iterator.hxx>
42 #include "GEOMImpl_Types.hxx"
44 //=================================================================================
45 // class : GenerationGUI_FillingDlg()
46 // purpose : Constructs a GenerationGUI_FillingDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 GenerationGUI_FillingDlg::GenerationGUI_FillingDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
52 const char* name, bool modal, Qt::WindowFlags fl)
53 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
55 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FILLING")));
56 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
58 setWindowTitle(tr("GEOM_FILLING_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_FILLING"));
62 RadioButton1->setIcon(image0);
63 RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
64 RadioButton2->close();
65 RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
66 RadioButton3->close();
68 GroupPoints = new DlgRef_1Sel5Spin(this, "GroupPoints");
69 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
70 GroupPoints->TextLabel1->setText(tr("GEOM_FILLING_COMPOUND"));
71 GroupPoints->TextLabel2->setText(tr("GEOM_FILLING_MIN_DEG"));
72 GroupPoints->TextLabel3->setText(tr("GEOM_FILLING_TOL_2D"));
73 GroupPoints->TextLabel4->setText(tr("GEOM_FILLING_NB_ITER"));
74 GroupPoints->TextLabel5->setText(tr("GEOM_FILLING_MAX_DEG"));
75 GroupPoints->TextLabel6->setText(tr("GEOM_FILLING_TOL_3D"));
76 GroupPoints->PushButton1->setIcon(image1);
77 GroupPoints->LineEdit1->setReadOnly( true );
79 gridLayout1->addWidget(GroupPoints, 2, 0);
80 /***************************************************************/
82 setHelpFileName("filling.htm");
88 //=================================================================================
89 // function : ~GenerationGUI_FillingDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
94 // no need to delete child widgets, Qt does it all for us
97 //=================================================================================
100 //=================================================================================
101 void GenerationGUI_FillingDlg::Init()
104 myEditCurrentArgument = GroupPoints->LineEdit1;
105 GroupPoints->LineEdit1->setReadOnly( true );
112 myOkCompound = false;
114 globalSelection( GEOM_COMPOUND );
116 double SpecificStep1 = 1;
117 double SpecificStep2 = 0.0001;
118 /* min, max, step and decimals for spin boxes & initial values */
119 GroupPoints->SpinBox_1->RangeStepAndValidator(2.0, MAX_NUMBER, SpecificStep1, 3);
120 GroupPoints->SpinBox_2->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
121 GroupPoints->SpinBox_3->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep1, 3);
122 GroupPoints->SpinBox_4->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep1, 3);
123 GroupPoints->SpinBox_5->RangeStepAndValidator(0.00001, 10000.0, SpecificStep2, 5);
125 GroupPoints->SpinBox_1->SetValue(myMinDeg);
126 GroupPoints->SpinBox_2->SetValue(myTol2D);
127 GroupPoints->SpinBox_3->SetValue(myNbIter);
128 GroupPoints->SpinBox_4->SetValue(myMaxDeg);
129 GroupPoints->SpinBox_5->SetValue(myTol3D);
131 /* signals and slots connections */
132 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
133 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
135 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 connect(GroupPoints->SpinBox_1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
139 connect(GroupPoints->SpinBox_2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
140 connect(GroupPoints->SpinBox_3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
141 connect(GroupPoints->SpinBox_4, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
142 connect(GroupPoints->SpinBox_5, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
144 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_1, SLOT(SetStep(double)));
145 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_2, SLOT(SetStep(double)));
146 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_3, SLOT(SetStep(double)));
147 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_4, SLOT(SetStep(double)));
148 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_5, SLOT(SetStep(double)));
150 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
151 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
153 initName(tr("GEOM_FILLING").toLatin1().constData());
157 //=================================================================================
158 // function : ClickOnOk()
160 //=================================================================================
161 void GenerationGUI_FillingDlg::ClickOnOk()
163 if ( ClickOnApply() )
168 //=================================================================================
169 // function : ClickOnApply()
171 //=================================================================================
172 bool GenerationGUI_FillingDlg::ClickOnApply()
182 //=================================================================================
183 // function : SelectionIntoArgument()
184 // purpose : Called when selection as changed or other case
185 //=================================================================================
186 void GenerationGUI_FillingDlg::SelectionIntoArgument()
189 myEditCurrentArgument->setText("");
191 if(IObjectCount() != 1) {
192 if(myEditCurrentArgument == GroupPoints->LineEdit1)
193 myOkCompound = false;
198 Standard_Boolean testResult = Standard_False;
199 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
204 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
206 myOkCompound = false;
208 if ( GEOMBase::GetShape(aSelectedObject, S) &&
209 S.ShapeType() == TopAbs_COMPOUND)
211 // myCompound should be a compound of edges
212 for ( TopoDS_Iterator it( S ); it.More(); it.Next() )
213 if ( it.Value().ShapeType() != TopAbs_EDGE )
215 myCompound = aSelectedObject;
220 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
225 //=================================================================================
226 // function : SetEditCurrentArgument()
228 //=================================================================================
229 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
231 QPushButton* send = (QPushButton*)sender();
232 globalSelection( GEOM_ALLSHAPES );
234 if(send == GroupPoints->PushButton1) {
235 GroupPoints->LineEdit1->setFocus();
236 myEditCurrentArgument = GroupPoints->LineEdit1;
237 globalSelection( GEOM_COMPOUND );
238 this->SelectionIntoArgument();
243 //=================================================================================
244 // function : LineEditReturnPressed()
246 //=================================================================================
247 void GenerationGUI_FillingDlg::LineEditReturnPressed()
249 QLineEdit* send = (QLineEdit*)sender();
250 if(send == GroupPoints->LineEdit1)
252 myEditCurrentArgument = send;
253 GEOMBase_Skeleton::LineEditReturnPressed();
258 //=================================================================================
259 // function : ActivateThisDialog()
261 //=================================================================================
262 void GenerationGUI_FillingDlg::ActivateThisDialog()
264 GEOMBase_Skeleton::ActivateThisDialog();
265 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
266 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
267 globalSelection( GEOM_COMPOUND );
272 //=================================================================================
273 // function : enterEvent()
275 //=================================================================================
276 void GenerationGUI_FillingDlg::enterEvent(QEvent* e)
278 if ( !GroupConstructors->isEnabled() )
279 ActivateThisDialog();
283 //=================================================================================
284 // function : ValueChangedInSpinBox()
286 //=================================================================================
287 void GenerationGUI_FillingDlg::ValueChangedInSpinBox(double newValue)
289 QObject* send = (QObject*)sender();
291 if(send == GroupPoints->SpinBox_1)
292 myMinDeg = int(newValue);
293 else if(send == GroupPoints->SpinBox_2)
295 else if(send == GroupPoints->SpinBox_3)
296 myNbIter = int(newValue);
297 else if(send == GroupPoints->SpinBox_4)
298 myMaxDeg = int(newValue);
299 else if(send == GroupPoints->SpinBox_5)
305 //=================================================================================
306 // function : createOperation
308 //=================================================================================
309 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
311 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
314 //=================================================================================
315 // function : isValid
317 //=================================================================================
318 bool GenerationGUI_FillingDlg::isValid( QString& )
320 return myOkCompound > 0;
323 //=================================================================================
324 // function : execute
326 //=================================================================================
327 bool GenerationGUI_FillingDlg::execute( ObjectList& objects )
329 GEOM::GEOM_Object_var anObj;
331 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation() )->MakeFilling(
332 myCompound, myMinDeg, myMaxDeg, myTol2D, myTol3D, myNbIter );
334 if ( !anObj->_is_nil() )
335 objects.push_back( anObj._retn() );