1 // Copyright (C) 2007-2010 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GenerationGUI_FillingDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "GenerationGUI_FillingDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_Session.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <TopoDS_Iterator.hxx>
39 #include <GEOMImpl_Types.hxx>
41 //=================================================================================
42 // class : GenerationGUI_FillingDlg()
43 // purpose : Constructs a GenerationGUI_FillingDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 GenerationGUI_FillingDlg::GenerationGUI_FillingDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
49 bool modal, Qt::WindowFlags fl )
50 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
52 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_FILLING" ) ) );
53 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
55 setWindowTitle( tr( "GEOM_FILLING_TITLE" ) );
57 /***************************************************************/
58 mainFrame()->GroupConstructors->setTitle( tr ( "GEOM_FILLING" ) );
59 mainFrame()->RadioButton1->setIcon( image0 );
60 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
61 mainFrame()->RadioButton2->close();
62 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
63 mainFrame()->RadioButton3->close();
65 GroupPoints = new DlgRef_1Sel5Spin1Check( centralWidget() );
66 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
67 GroupPoints->TextLabel1->setText( tr( "GEOM_FILLING_COMPOUND" ) );
68 GroupPoints->TextLabel2->setText( tr( "GEOM_FILLING_MIN_DEG" ) );
69 GroupPoints->TextLabel3->setText( tr( "GEOM_FILLING_TOL_2D" ) );
70 GroupPoints->TextLabel4->setText( tr( "GEOM_FILLING_NB_ITER" ) );
71 GroupPoints->TextLabel5->setText( tr( "GEOM_FILLING_MAX_DEG" ) );
72 GroupPoints->TextLabel6->setText( tr( "GEOM_FILLING_TOL_3D" ) );
73 GroupPoints->CheckBox1->setText( tr( "GEOM_FILLING_APPROX" ) );
74 GroupPoints->TextLabel7->setText( tr( "GEOM_FILLING_METHOD" ) );
75 GroupPoints->PushButton1->setIcon( image1 );
76 GroupPoints->LineEdit1->setReadOnly( true );
78 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
79 layout->setMargin( 0 ); layout->setSpacing( 6 );
80 layout->addWidget( GroupPoints );
81 /***************************************************************/
83 setHelpFileName( "create_filling_page.html" );
89 //=================================================================================
90 // function : ~GenerationGUI_FillingDlg()
91 // purpose : Destroys the object and frees any allocated resources
92 //=================================================================================
93 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
95 // no need to delete child widgets, Qt does it all for us
98 //=================================================================================
101 //=================================================================================
102 void GenerationGUI_FillingDlg::Init()
105 myEditCurrentArgument = GroupPoints->LineEdit1;
106 GroupPoints->LineEdit1->setReadOnly( true );
115 myOkCompound = false;
117 globalSelection( GEOM_COMPOUND );
119 int SpecificStep1 = 1;
120 double SpecificStep2 = 0.0001;
121 /* min, max, step and decimals for spin boxes & initial values */
122 initSpinBox( GroupPoints->SpinBox1, 2, MAX_NUMBER, SpecificStep1 );
123 initSpinBox( GroupPoints->SpinBox2, 0.00001, 10000.0, SpecificStep2, "len_tol_precision" );
124 initSpinBox( GroupPoints->SpinBox3, 0, MAX_NUMBER, SpecificStep1 );
125 initSpinBox( GroupPoints->SpinBox4, 1, MAX_NUMBER, SpecificStep1 );
126 initSpinBox( GroupPoints->SpinBox5, 0.00001, 10000.0, SpecificStep2, "len_tol_precision" );
128 GroupPoints->SpinBox1->setValue( myMinDeg );
129 GroupPoints->SpinBox2->setValue( myTol2D );
130 GroupPoints->SpinBox3->setValue( myNbIter );
131 GroupPoints->SpinBox4->setValue( myMaxDeg );
132 GroupPoints->SpinBox5->setValue( myTol3D );
134 GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_DEFAULT"));
135 GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_USEORI"));
136 GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_AUTO"));
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->ComboBox1, SIGNAL(activated(int)), this, SLOT(MethodChanged()));
147 connect( GroupPoints->SpinBox1, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
148 connect( GroupPoints->SpinBox2, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
149 connect( GroupPoints->SpinBox3, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
150 connect( GroupPoints->SpinBox4, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
151 connect( GroupPoints->SpinBox5, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
153 connect( GroupPoints->CheckBox1, SIGNAL( stateChanged( int ) ),
154 this, SLOT( ApproxChanged() ) );
156 // san: Commented, as all spin boxes here either are integer or use specific non-default step value
157 //connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
159 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
160 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
162 initName( tr( "GEOM_FILLING" ) );
166 //=================================================================================
167 // function : SetDoubleSpinBoxStep()
168 // purpose : Double spin box management
169 //=================================================================================
170 void GenerationGUI_FillingDlg::SetDoubleSpinBoxStep( double step )
172 GroupPoints->SpinBox2->setSingleStep(step);
173 GroupPoints->SpinBox5->setSingleStep(step);
177 //=================================================================================
178 // function : ClickOnOk()
180 //=================================================================================
181 void GenerationGUI_FillingDlg::ClickOnOk()
183 if ( ClickOnApply() )
188 //=================================================================================
189 // function : ClickOnApply()
191 //=================================================================================
192 bool GenerationGUI_FillingDlg::ClickOnApply()
202 //=================================================================================
203 // function : SelectionIntoArgument()
204 // purpose : Called when selection as changed or other case
205 //=================================================================================
206 void GenerationGUI_FillingDlg::SelectionIntoArgument()
209 myEditCurrentArgument->setText("");
211 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
212 SALOME_ListIO aSelList;
213 aSelMgr->selectedObjects(aSelList);
215 if (aSelList.Extent() != 1) {
216 if (myEditCurrentArgument == GroupPoints->LineEdit1)
217 myOkCompound = false;
222 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
223 if ( CORBA::is_nil( aSelectedObject ) )
226 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
228 myOkCompound = false;
230 if (GEOMBase::GetShape(aSelectedObject, S) && S.ShapeType() == TopAbs_COMPOUND) {
231 // myCompound should be a compound of edges
232 for (TopoDS_Iterator it (S); it.More(); it.Next())
233 if ( it.Value().ShapeType() != TopAbs_EDGE &&
234 it.Value().ShapeType() != TopAbs_WIRE )
236 myCompound = aSelectedObject;
241 myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
245 //=================================================================================
246 // function : SetEditCurrentArgument()
248 //=================================================================================
249 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
251 QPushButton* send = (QPushButton*)sender();
252 globalSelection( GEOM_ALLSHAPES );
254 if ( send == GroupPoints->PushButton1 ) {
255 GroupPoints->LineEdit1->setFocus();
256 myEditCurrentArgument = GroupPoints->LineEdit1;
257 globalSelection( GEOM_COMPOUND );
258 this->SelectionIntoArgument();
263 //=================================================================================
264 // function : LineEditReturnPressed()
266 //=================================================================================
267 void GenerationGUI_FillingDlg::LineEditReturnPressed()
269 QLineEdit* send = (QLineEdit*)sender();
270 if ( send == GroupPoints->LineEdit1 ) {
271 myEditCurrentArgument = send;
272 GEOMBase_Skeleton::LineEditReturnPressed();
277 //=================================================================================
278 // function : ActivateThisDialog()
280 //=================================================================================
281 void GenerationGUI_FillingDlg::ActivateThisDialog()
283 GEOMBase_Skeleton::ActivateThisDialog();
284 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
285 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
286 globalSelection( GEOM_COMPOUND );
291 //=================================================================================
292 // function : enterEvent()
294 //=================================================================================
295 void GenerationGUI_FillingDlg::enterEvent( QEvent* )
297 if ( !mainFrame()->GroupConstructors->isEnabled() )
298 ActivateThisDialog();
302 //=================================================================================
303 // function : ValueChangedInSpinBox()
305 //=================================================================================
306 void GenerationGUI_FillingDlg::ValueChangedInSpinBox( double newValue )
308 QObject* send = (QObject*)sender();
310 if ( send == GroupPoints->SpinBox1 )
311 myMinDeg = int( newValue );
312 else if ( send == GroupPoints->SpinBox2 )
314 else if ( send == GroupPoints->SpinBox3 )
315 myNbIter = int(newValue);
316 else if ( send == GroupPoints->SpinBox4 )
317 myMaxDeg = int(newValue);
318 else if ( send == GroupPoints->SpinBox5 )
324 //=================================================================================
325 // function : MethodChanged
327 //=================================================================================
328 void GenerationGUI_FillingDlg::MethodChanged()
330 myMethod = GroupPoints->ComboBox1->currentIndex();
334 //=================================================================================
335 // function : ApproxChanged()
337 //=================================================================================
338 void GenerationGUI_FillingDlg::ApproxChanged()
340 myIsApprox = GroupPoints->CheckBox1->isChecked();
345 //=================================================================================
346 // function : createOperation
348 //=================================================================================
349 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
351 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
354 //=================================================================================
355 // function : isValid
357 //=================================================================================
358 bool GenerationGUI_FillingDlg::isValid( QString& msg )
361 ok = GroupPoints->SpinBox1->isValid( msg, !IsPreview() ) && ok;
362 ok = GroupPoints->SpinBox2->isValid( msg, !IsPreview() ) && ok;
363 ok = GroupPoints->SpinBox3->isValid( msg, !IsPreview() ) && ok;
364 ok = GroupPoints->SpinBox4->isValid( msg, !IsPreview() ) && ok;
365 ok = GroupPoints->SpinBox5->isValid( msg, !IsPreview() ) && ok;
367 return myOkCompound > 0 && ok;
370 //=================================================================================
371 // function : execute
373 //=================================================================================
374 bool GenerationGUI_FillingDlg::execute( ObjectList& objects )
376 GEOM::GEOM_I3DPrimOperations_var anOper =
377 GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
379 GEOM::filling_oper_method aMethod;
380 switch (GroupPoints->ComboBox1->currentIndex())
382 case 0: aMethod = GEOM::FOM_Default; break;
383 case 1: aMethod = GEOM::FOM_UseOri; break;
384 case 2: aMethod = GEOM::FOM_AutoCorrect; break;
388 GEOM::GEOM_Object_var anObj =
389 anOper->MakeFilling( myCompound, myMinDeg, myMaxDeg, myTol2D, myTol3D,
390 myNbIter, aMethod, myIsApprox );
391 if ( !anObj->_is_nil() )
395 QStringList aParameters;
396 aParameters << GroupPoints->SpinBox1->text();
397 aParameters << GroupPoints->SpinBox2->text();
398 aParameters << GroupPoints->SpinBox3->text();
399 aParameters << GroupPoints->SpinBox4->text();
400 aParameters << GroupPoints->SpinBox5->text();
401 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
403 objects.push_back( anObj._retn() );