1 // Copyright (C) 2007-2011 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 : BasicGUI_CurveDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "BasicGUI_CurveDlg.h"
28 #include "BasicGUI_ParamCurveWidget.h"
31 #include <GeometryGUI.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
36 #include <SalomeApp_Application.h>
37 #include <SalomeApp_Study.h>
38 #include <LightApp_SelectionMgr.h>
40 #include <SALOME_ListIteratorOfListIO.hxx>
41 #include <SALOME_ListIO.hxx>
43 #include <TopoDS_Shape.hxx>
46 #include <TColStd_IndexedMapOfInteger.hxx>
47 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <GEOMImpl_Types.hxx>
51 //=================================================================================
52 // class : BasicGUI_CurveDlg()
53 // purpose : Constructs a BasicGUI_CurveDlg which is a child of 'parent', with the
54 // name 'name' and widget flags set to 'f'.
55 // The dialog will by default be modeless, unless you set 'modal' to
56 // TRUE to construct a modal dialog.
57 //=================================================================================
58 BasicGUI_CurveDlg::BasicGUI_CurveDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
59 bool modal, Qt::WindowFlags fl )
60 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
62 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POLYLINE" ) ) );
63 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SPLINE" ) ) );
64 QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BEZIER" ) ) );
65 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
67 setWindowTitle( tr( "GEOM_CURVE_TITLE" ) );
69 /***************************************************************/
70 mainFrame()->RadioButton1->setIcon( image0 );
71 mainFrame()->RadioButton2->setIcon( image3 );
72 mainFrame()->RadioButton3->setIcon( image2 );
74 QGroupBox* creationModeCroup = new QGroupBox(this);
75 QButtonGroup* bg = new QButtonGroup(this);
77 creationModeCroup->setTitle( tr( "GEOM_CURVE_CRMODE" ) );
78 QHBoxLayout * creationModeLayout = new QHBoxLayout(creationModeCroup);
79 myBySelectionBtn = new QRadioButton( tr( "GEOM_CURVE_SELECTION" ) ,creationModeCroup );
80 myAnaliticalBtn = new QRadioButton( tr( "GEOM_CURVE_ANALITICAL" ) ,creationModeCroup );
82 bg->addButton(myBySelectionBtn);
83 bg->addButton(myAnaliticalBtn);
85 creationModeLayout->addWidget(myBySelectionBtn);
86 creationModeLayout->addWidget(myAnaliticalBtn);
88 GroupPoints = new DlgRef_1Sel3Check( centralWidget() );
90 GroupPoints->GroupBox1->setTitle( tr( "GEOM_NODES" ) );
91 GroupPoints->TextLabel1->setText( tr( "GEOM_POINTS" ) );
92 GroupPoints->PushButton1->setIcon( image1 );
93 GroupPoints->PushButton1->setDown( true );
95 GroupPoints->LineEdit1->setReadOnly( true );
97 GroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
98 GroupPoints->CheckButton1->setChecked(false);
99 //GroupPoints->CheckButton1->hide();
101 GroupPoints->CheckButton2->setText( tr( "GEOM_IS_REORDER" ) );
102 GroupPoints->CheckButton2->setChecked(false);
103 GroupPoints->CheckButton2->hide();
105 GroupPoints->CheckButton3->hide();
107 myParams = new BasicGUI_ParamCurveWidget( centralWidget() );
109 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
110 layout->setMargin( 0 ); layout->setSpacing( 6 );
111 layout->addWidget( creationModeCroup );
112 layout->addWidget( GroupPoints );
113 layout->addWidget( myParams );
114 /***************************************************************/
116 setHelpFileName( "create_curve_page.html" );
122 //=================================================================================
123 // function : ~BasicGUI_CurveDlg()
124 // purpose : Destroys the object and frees any allocated resources
125 //=================================================================================
126 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
131 //=================================================================================
134 //=================================================================================
135 void BasicGUI_CurveDlg::Init()
138 myEditCurrentArgument = GroupPoints->LineEdit1;
142 globalSelection(); // close local contexts, if any
143 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
145 showOnlyPreviewControl();
146 myBySelectionBtn->setChecked(true);
148 /* Get setting of step value from file configuration */
149 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
150 double step = resMgr ? resMgr->doubleValue( "Geometry", "SettingsGeomStep", 10. ) : 10.;
152 double aMax( 100. ), aMin( 0.0 );
154 /* min, max, step and decimals for spin boxes & initial values */
155 initSpinBox( myParams->myPMin, COORD_MIN, COORD_MAX, step, "length_precision" );
156 initSpinBox( myParams->myPMax, COORD_MIN, COORD_MAX, step, "length_precision" );
157 initSpinBox( myParams->myPStep, COORD_MIN, COORD_MAX, step, "length_precision" );
158 myParams->myPMin->setValue( aMin );
159 myParams->myPMax->setValue( aMax );
160 myParams->myPStep->setValue( step );
161 myParams->myXExpr->setText("t");
162 myParams->myYExpr->setText("t");
163 myParams->myZExpr->setText("t");
167 /* signals and slots connections */
168 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog( ) ) );
169 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
171 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
172 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
174 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
176 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
178 connect( GroupPoints->CheckButton1, SIGNAL( toggled(bool) ), this, SLOT( CheckButtonToggled() ) );
179 connect( GroupPoints->CheckButton2, SIGNAL( toggled(bool) ), this, SLOT( CheckButtonToggled() ) );
181 connect( myGeomGUI->getApp()->selectionMgr(),
182 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
184 connect( myBySelectionBtn, SIGNAL( clicked() ), this, SLOT( CreationModeChanged() ) );
185 connect( myAnaliticalBtn, SIGNAL( clicked() ), this, SLOT( CreationModeChanged() ) );
187 connect(myParams->myPMin, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
188 connect(myParams->myPMax, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
189 connect(myParams->myPStep, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
191 connect(myParams->myXExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
192 connect(myParams->myYExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
193 connect(myParams->myZExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
195 initName( tr( "GEOM_CURVE" ) );
197 ConstructorsClicked( 0 );
200 //=================================================================================
201 // function : ConstructorsClicked()
203 //=================================================================================
204 void BasicGUI_CurveDlg::ConstructorsClicked( int id )
206 QString aTitle = tr( id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL" );
207 mainFrame()->GroupConstructors->setTitle( aTitle );
209 if (id == 0) { // polyline (wire)
210 //GroupPoints->CheckButton1->hide();
211 GroupPoints->CheckButton1->setText( tr( "GEOM_BUILD_CLOSED_WIRE" ) );
212 GroupPoints->CheckButton2->hide();
214 else if (id == 1) { // bezier
215 //GroupPoints->CheckButton1->hide();
216 GroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
217 GroupPoints->CheckButton2->hide();
220 //GroupPoints->CheckButton1->show();
221 GroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
222 GroupPoints->CheckButton2->show();
227 myEditCurrentArgument->setText( "" );
228 qApp->processEvents();
230 resize( minimumSizeHint() );
231 SelectionIntoArgument();
235 //=================================================================================
236 // function : SetEditCurrentArgument()
238 //=================================================================================
239 void BasicGUI_CurveDlg::SetEditCurrentArgument()
241 if ( sender() == GroupPoints->PushButton1 )
242 myEditCurrentArgument = GroupPoints->LineEdit1;
243 myEditCurrentArgument->setFocus();
244 SelectionIntoArgument();
247 //=================================================================================
248 // function : CheckButtonToggled()
250 //=================================================================================
251 void BasicGUI_CurveDlg::CheckButtonToggled()
256 //=================================================================================
257 // function : ClickOnOk()
259 //=================================================================================
260 void BasicGUI_CurveDlg::ClickOnOk()
262 setIsApplyAndClose( true );
263 if ( ClickOnApply() )
267 //=================================================================================
268 // function : ClickOnApply()
270 //=================================================================================
271 bool BasicGUI_CurveDlg::ClickOnApply()
277 globalSelection(); // close local contexts, if any
278 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
282 static void synchronize( QList<GEOM::GeomObjPtr>& left, QList<GEOM::GeomObjPtr>& right )
284 // 1. remove items from the "left" list that are not in the "right" list
285 QMutableListIterator<GEOM::GeomObjPtr> it1( left );
286 while ( it1.hasNext() ) {
287 GEOM::GeomObjPtr o1 = it1.next();
289 QMutableListIterator<GEOM::GeomObjPtr> it2( right );
290 while ( it2.hasNext() && !found )
291 found = o1 == it2.next();
295 // 2. add items from the "right" list that are not in the "left" list (to keep selection order)
297 while ( it1.hasNext() ) {
298 GEOM::GeomObjPtr o1 = it1.next();
300 QMutableListIterator<GEOM::GeomObjPtr> it2( left );
301 while ( it2.hasNext() && !found )
302 found = o1 == it2.next();
308 //=================================================================================
309 // function : SelectionIntoArgument()
310 // purpose : Called when selection as changed or other case
311 //=================================================================================
312 void BasicGUI_CurveDlg::SelectionIntoArgument()
314 QList<GEOM::GeomObjPtr> points = getSelected( TopAbs_VERTEX, -1 );
315 synchronize( myPoints, points );
316 if ( !myPoints.isEmpty() )
317 GroupPoints->LineEdit1->setText( QString::number( myPoints.count() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
319 GroupPoints->LineEdit1->setText( "" );
324 //=================================================================================
325 // function : ActivateThisDialog()
327 //=================================================================================
328 void BasicGUI_CurveDlg::ActivateThisDialog()
330 GEOMBase_Skeleton::ActivateThisDialog();
331 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
332 this, SLOT( SelectionIntoArgument() ) );
334 globalSelection(); // close local contexts, if any
335 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
337 ConstructorsClicked( getConstructorId() );
340 //=================================================================================
341 // function : DeactivateActiveDialog()
342 // purpose : public slot to deactivate if active
343 //=================================================================================
344 void BasicGUI_CurveDlg::DeactivateActiveDialog()
346 // myGeomGUI->SetState( -1 );
347 GEOMBase_Skeleton::DeactivateActiveDialog();
350 //=================================================================================
351 // function : enterEvent()
353 //=================================================================================
354 void BasicGUI_CurveDlg::enterEvent( QEvent* )
356 if ( !mainFrame()->GroupConstructors->isEnabled() )
357 ActivateThisDialog();
360 //=================================================================================
361 // function : createOperation
363 //=================================================================================
364 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
366 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
369 //=================================================================================
370 // function : isValid
372 //=================================================================================
373 bool BasicGUI_CurveDlg::isValid( QString& msg )
375 if( myBySelectionBtn->isChecked() )
376 return myPoints.count() > 1;
378 bool ok = myParams->myPMin->isValid( msg, !IsPreview() ) &&
379 myParams->myPMax->isValid( msg, !IsPreview() ) &&
380 myParams->myPStep->isValid( msg, !IsPreview() );
381 ok &= !myParams->myXExpr->text().isEmpty();
382 ok &= !myParams->myYExpr->text().isEmpty();
383 ok &= !myParams->myZExpr->text().isEmpty();
388 //=================================================================================
389 // function : execute
391 //=================================================================================
392 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
396 GEOM::GEOM_Object_var anObj;
398 GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() );
400 GEOM::ListOfGO_var points = new GEOM::ListOfGO();
401 points->length( myPoints.count() );
402 for ( int i = 0; i < myPoints.count(); i++ )
403 points[i] = myPoints[i].copy();
405 switch ( getConstructorId() ) {
407 if( myBySelectionBtn->isChecked() )
408 anObj = anOper->MakePolyline( points.in(), GroupPoints->CheckButton1->isChecked() );
410 anObj = anOper->MakeCurveParametric(qPrintable(myParams->myXExpr->text()),
411 qPrintable(myParams->myYExpr->text()),
412 qPrintable(myParams->myZExpr->text()),
413 myParams->myPMin->value(),
414 myParams->myPMax->value(),
415 myParams->myPStep->value(),
420 if( myBySelectionBtn->isChecked() )
421 anObj = anOper->MakeSplineBezier( points.in(), GroupPoints->CheckButton1->isChecked() );
423 anObj = anOper->MakeCurveParametric(qPrintable(myParams->myXExpr->text()),
424 qPrintable(myParams->myYExpr->text()),
425 qPrintable(myParams->myZExpr->text()),
426 myParams->myPMin->value(),
427 myParams->myPMax->value(),
428 myParams->myPStep->value(),
434 if( myBySelectionBtn->isChecked() )
435 anObj = anOper->MakeSplineInterpolation( points.in(), GroupPoints->CheckButton1->isChecked(),
436 GroupPoints->CheckButton2->isChecked() );
438 anObj = anOper->MakeCurveParametric(qPrintable(myParams->myXExpr->text()),
439 qPrintable(myParams->myYExpr->text()),
440 qPrintable(myParams->myZExpr->text()),
441 myParams->myPMin->value(),
442 myParams->myPMax->value(),
443 myParams->myPStep->value(),
444 GEOM::Interpolation);
449 if ( !anObj->_is_nil() ) {
450 if(myAnaliticalBtn->isChecked() && !IsPreview()) {
451 QStringList aParameters;
452 aParameters<<myParams->myPMin->text();
453 aParameters<<myParams->myPMax->text();
454 aParameters<<myParams->myPStep->text();
455 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
457 objects.push_back( anObj._retn() );
463 //=================================================================================
464 // function : addSubshapeToStudy
465 // purpose : virtual method to add new SubObjects if local selection
466 //=================================================================================
467 void BasicGUI_CurveDlg::addSubshapesToStudy()
469 for ( int i = 0; i < myPoints.count(); i++ )
470 GEOMBase::PublishSubObject( myPoints[i].get() );
473 //=================================================================================
474 // function : CreationModeChanged
476 //=================================================================================
477 void BasicGUI_CurveDlg::CreationModeChanged() {
478 const QObject* s = sender();
479 GroupPoints->setVisible(myBySelectionBtn == s);
480 myParams->setVisible(myBySelectionBtn != s);
482 ConstructorsClicked( getConstructorId() );
485 //=================================================================================
486 // function : ValueChangedInSpinBox()
488 //=================================================================================
489 void BasicGUI_CurveDlg::ValueChangedInSpinBox(double/*theValue*/)
494 //=================================================================================
495 // function : ValueChangedInSpinBox()
497 //=================================================================================
498 void BasicGUI_CurveDlg::OnEditingFinished() {