1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GenerationGUI_FillingDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "GenerationGUI_FillingDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <TopoDS_Iterator.hxx>
38 #include <GEOMImpl_Types.hxx>
40 //=================================================================================
41 // class : GenerationGUI_FillingDlg()
42 // purpose : Constructs a GenerationGUI_FillingDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 GenerationGUI_FillingDlg::GenerationGUI_FillingDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
48 bool modal, Qt::WindowFlags fl )
49 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
51 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_FILLING" ) ) );
52 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
54 setWindowTitle( tr( "GEOM_FILLING_TITLE" ) );
56 /***************************************************************/
57 mainFrame()->GroupConstructors->setTitle( tr ( "GEOM_FILLING" ) );
58 mainFrame()->RadioButton1->setIcon( image0 );
59 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
60 mainFrame()->RadioButton2->close();
61 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton3->close();
64 GroupPoints = new DlgRef_1Sel5Spin1Check( centralWidget() );
65 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
66 GroupPoints->TextLabel1->setText( tr( "GEOM_FILLING_COMPOUND" ) );
67 GroupPoints->TextLabel2->setText( tr( "GEOM_FILLING_MIN_DEG" ) );
68 GroupPoints->TextLabel3->setText( tr( "GEOM_FILLING_TOL_2D" ) );
69 GroupPoints->TextLabel4->setText( tr( "GEOM_FILLING_NB_ITER" ) );
70 GroupPoints->TextLabel5->setText( tr( "GEOM_FILLING_MAX_DEG" ) );
71 GroupPoints->TextLabel6->setText( tr( "GEOM_FILLING_TOL_3D" ) );
72 GroupPoints->CheckBox1->setText( tr( "GEOM_FILLING_APPROX" ) );
73 GroupPoints->PushButton1->setIcon( image1 );
74 GroupPoints->LineEdit1->setReadOnly( true );
76 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
77 layout->setMargin( 0 ); layout->setSpacing( 6 );
78 layout->addWidget( GroupPoints );
79 /***************************************************************/
81 setHelpFileName( "create_filling_page.html" );
87 //=================================================================================
88 // function : ~GenerationGUI_FillingDlg()
89 // purpose : Destroys the object and frees any allocated resources
90 //=================================================================================
91 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
93 // no need to delete child widgets, Qt does it all for us
96 //=================================================================================
99 //=================================================================================
100 void GenerationGUI_FillingDlg::Init()
103 myEditCurrentArgument = GroupPoints->LineEdit1;
104 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 initSpinBox( GroupPoints->SpinBox1, 2.0, MAX_NUMBER, SpecificStep1, 3 );
120 initSpinBox( GroupPoints->SpinBox2, 0.00001, 10000.0, SpecificStep2, 5 );
121 initSpinBox( GroupPoints->SpinBox3, 0.0, MAX_NUMBER, SpecificStep1, 3 );
122 initSpinBox( GroupPoints->SpinBox4, 1.0, MAX_NUMBER, SpecificStep1, 3 );
123 initSpinBox( GroupPoints->SpinBox5, 0.00001, 10000.0, SpecificStep2, 5 );
125 GroupPoints->SpinBox1->setValue( myMinDeg );
126 GroupPoints->SpinBox2->setValue( myTol2D );
127 GroupPoints->SpinBox3->setValue( myNbIter );
128 GroupPoints->SpinBox4->setValue( myMaxDeg );
129 GroupPoints->SpinBox5->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->SpinBox1, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
139 connect( GroupPoints->SpinBox2, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
140 connect( GroupPoints->SpinBox3, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
141 connect( GroupPoints->SpinBox4, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
142 connect( GroupPoints->SpinBox5, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
144 connect( GroupPoints->CheckBox1, SIGNAL( stateChanged( int ) ), this, SLOT( ApproxChanged() ) );
146 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
148 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
149 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
151 initName( tr( "GEOM_FILLING" ) );
155 //=================================================================================
156 // function : SetDoubleSpinBoxStep()
157 // purpose : Double spin box management
158 //=================================================================================
159 void GenerationGUI_FillingDlg::SetDoubleSpinBoxStep( double step )
161 GroupPoints->SpinBox1->setSingleStep(step);
162 GroupPoints->SpinBox2->setSingleStep(step);
163 GroupPoints->SpinBox3->setSingleStep(step);
164 GroupPoints->SpinBox4->setSingleStep(step);
165 GroupPoints->SpinBox5->setSingleStep(step);
169 //=================================================================================
170 // function : ClickOnOk()
172 //=================================================================================
173 void GenerationGUI_FillingDlg::ClickOnOk()
175 if ( ClickOnApply() )
180 //=================================================================================
181 // function : ClickOnApply()
183 //=================================================================================
184 bool GenerationGUI_FillingDlg::ClickOnApply()
194 //=================================================================================
195 // function : SelectionIntoArgument()
196 // purpose : Called when selection as changed or other case
197 //=================================================================================
198 void GenerationGUI_FillingDlg::SelectionIntoArgument()
201 myEditCurrentArgument->setText("");
203 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
204 SALOME_ListIO aSelList;
205 aSelMgr->selectedObjects(aSelList);
207 if (aSelList.Extent() != 1) {
208 if (myEditCurrentArgument == GroupPoints->LineEdit1)
209 myOkCompound = false;
214 Standard_Boolean testResult = Standard_False;
215 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
220 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
222 myOkCompound = false;
224 if (GEOMBase::GetShape(aSelectedObject, S) && S.ShapeType() == TopAbs_COMPOUND) {
225 // myCompound should be a compound of edges
226 for (TopoDS_Iterator it (S); it.More(); it.Next())
227 if (it.Value().ShapeType() != TopAbs_EDGE)
229 myCompound = aSelectedObject;
234 myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
238 //=================================================================================
239 // function : SetEditCurrentArgument()
241 //=================================================================================
242 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
244 QPushButton* send = (QPushButton*)sender();
245 globalSelection( GEOM_ALLSHAPES );
247 if ( send == GroupPoints->PushButton1 ) {
248 GroupPoints->LineEdit1->setFocus();
249 myEditCurrentArgument = GroupPoints->LineEdit1;
250 globalSelection( GEOM_COMPOUND );
251 this->SelectionIntoArgument();
256 //=================================================================================
257 // function : LineEditReturnPressed()
259 //=================================================================================
260 void GenerationGUI_FillingDlg::LineEditReturnPressed()
262 QLineEdit* send = (QLineEdit*)sender();
263 if ( send == GroupPoints->LineEdit1 ) {
264 myEditCurrentArgument = send;
265 GEOMBase_Skeleton::LineEditReturnPressed();
270 //=================================================================================
271 // function : ActivateThisDialog()
273 //=================================================================================
274 void GenerationGUI_FillingDlg::ActivateThisDialog()
276 GEOMBase_Skeleton::ActivateThisDialog();
277 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
278 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
279 globalSelection( GEOM_COMPOUND );
284 //=================================================================================
285 // function : enterEvent()
287 //=================================================================================
288 void GenerationGUI_FillingDlg::enterEvent( QEvent* )
290 if ( !mainFrame()->GroupConstructors->isEnabled() )
291 ActivateThisDialog();
295 //=================================================================================
296 // function : ValueChangedInSpinBox()
298 //=================================================================================
299 void GenerationGUI_FillingDlg::ValueChangedInSpinBox( double newValue )
301 QObject* send = (QObject*)sender();
303 if ( send == GroupPoints->SpinBox1 )
304 myMinDeg = int( newValue );
305 else if ( send == GroupPoints->SpinBox2 )
307 else if ( send == GroupPoints->SpinBox3 )
308 myNbIter = int(newValue);
309 else if ( send == GroupPoints->SpinBox4 )
310 myMaxDeg = int(newValue);
311 else if ( send == GroupPoints->SpinBox5 )
317 //=================================================================================
318 // function : ApproxChanged()
320 //=================================================================================
321 void GenerationGUI_FillingDlg::ApproxChanged()
323 myIsApprox = GroupPoints->CheckBox1->isChecked();
327 //=================================================================================
328 // function : createOperation
330 //=================================================================================
331 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
333 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
336 //=================================================================================
337 // function : isValid
339 //=================================================================================
340 bool GenerationGUI_FillingDlg::isValid( QString& msg )
343 ok = GroupPoints->SpinBox1->isValid( msg, !IsPreview() ) && ok;
344 ok = GroupPoints->SpinBox2->isValid( msg, !IsPreview() ) && ok;
345 ok = GroupPoints->SpinBox3->isValid( msg, !IsPreview() ) && ok;
346 ok = GroupPoints->SpinBox4->isValid( msg, !IsPreview() ) && ok;
347 ok = GroupPoints->SpinBox5->isValid( msg, !IsPreview() ) && ok;
349 return myOkCompound > 0 && ok;
352 //=================================================================================
353 // function : execute
355 //=================================================================================
356 bool GenerationGUI_FillingDlg::execute( ObjectList& objects )
358 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
359 GEOM::GEOM_Object_var anObj = anOper->MakeFilling( myCompound, myMinDeg, myMaxDeg,
360 myTol2D, myTol3D, myNbIter, myIsApprox );
361 if ( !anObj->_is_nil() )
365 QStringList aParameters;
366 aParameters << GroupPoints->SpinBox1->text();
367 aParameters << GroupPoints->SpinBox2->text();
368 aParameters << GroupPoints->SpinBox3->text();
369 aParameters << GroupPoints->SpinBox4->text();
370 aParameters << GroupPoints->SpinBox5->text();
371 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
373 objects.push_back( anObj._retn() );