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 myParams->myPStep->setValue( 10 );
158 myParams->myPStep->setMaximum( 999 );
159 myParams->myPStep->setSingleStep( 10 );
160 myParams->myPMin->setValue( aMin );
161 myParams->myPMax->setValue( aMax );
162 myParams->myPStep->setValue( step );
163 myParams->myXExpr->setText("t");
164 myParams->myYExpr->setText("t");
165 myParams->myZExpr->setText("t");
169 /* signals and slots connections */
170 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog( ) ) );
171 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
173 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
174 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
176 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
178 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
180 connect( GroupPoints->CheckButton1, SIGNAL( toggled(bool) ), this, SLOT( CheckButtonToggled() ) );
181 connect( GroupPoints->CheckButton2, SIGNAL( toggled(bool) ), this, SLOT( CheckButtonToggled() ) );
183 connect( myGeomGUI->getApp()->selectionMgr(),
184 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
186 connect( myBySelectionBtn, SIGNAL( clicked() ), this, SLOT( CreationModeChanged() ) );
187 connect( myAnaliticalBtn, SIGNAL( clicked() ), this, SLOT( CreationModeChanged() ) );
189 connect(myParams->myPMin, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
190 connect(myParams->myPMax, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
191 connect(myParams->myPStep, SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
193 connect(myParams->myXExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
194 connect(myParams->myYExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
195 connect(myParams->myZExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
197 initName( tr( "GEOM_CURVE" ) );
199 ConstructorsClicked( 0 );
202 //=================================================================================
203 // function : ConstructorsClicked()
205 //=================================================================================
206 void BasicGUI_CurveDlg::ConstructorsClicked( int id )
208 QString aTitle = tr( id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL" );
209 mainFrame()->GroupConstructors->setTitle( aTitle );
211 if (id == 0) { // polyline (wire)
212 //GroupPoints->CheckButton1->hide();
213 GroupPoints->CheckButton1->setText( tr( "GEOM_BUILD_CLOSED_WIRE" ) );
214 GroupPoints->CheckButton2->hide();
216 else if (id == 1) { // bezier
217 //GroupPoints->CheckButton1->hide();
218 GroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
219 GroupPoints->CheckButton2->hide();
222 //GroupPoints->CheckButton1->show();
223 GroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
224 GroupPoints->CheckButton2->show();
229 myEditCurrentArgument->setText( "" );
230 qApp->processEvents();
232 resize( minimumSizeHint() );
233 SelectionIntoArgument();
237 //=================================================================================
238 // function : SetEditCurrentArgument()
240 //=================================================================================
241 void BasicGUI_CurveDlg::SetEditCurrentArgument()
243 if ( sender() == GroupPoints->PushButton1 )
244 myEditCurrentArgument = GroupPoints->LineEdit1;
245 myEditCurrentArgument->setFocus();
246 SelectionIntoArgument();
249 //=================================================================================
250 // function : CheckButtonToggled()
252 //=================================================================================
253 void BasicGUI_CurveDlg::CheckButtonToggled()
258 //=================================================================================
259 // function : ClickOnOk()
261 //=================================================================================
262 void BasicGUI_CurveDlg::ClickOnOk()
264 setIsApplyAndClose( true );
265 if ( ClickOnApply() )
269 //=================================================================================
270 // function : ClickOnApply()
272 //=================================================================================
273 bool BasicGUI_CurveDlg::ClickOnApply()
279 globalSelection(); // close local contexts, if any
280 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
284 static void synchronize( QList<GEOM::GeomObjPtr>& left, QList<GEOM::GeomObjPtr>& right )
286 // 1. remove items from the "left" list that are not in the "right" list
287 QMutableListIterator<GEOM::GeomObjPtr> it1( left );
288 while ( it1.hasNext() ) {
289 GEOM::GeomObjPtr o1 = it1.next();
291 QMutableListIterator<GEOM::GeomObjPtr> it2( right );
292 while ( it2.hasNext() && !found )
293 found = o1 == it2.next();
297 // 2. add items from the "right" list that are not in the "left" list (to keep selection order)
299 while ( it1.hasNext() ) {
300 GEOM::GeomObjPtr o1 = it1.next();
302 QMutableListIterator<GEOM::GeomObjPtr> it2( left );
303 while ( it2.hasNext() && !found )
304 found = o1 == it2.next();
310 //=================================================================================
311 // function : SelectionIntoArgument()
312 // purpose : Called when selection as changed or other case
313 //=================================================================================
314 void BasicGUI_CurveDlg::SelectionIntoArgument()
316 QList<GEOM::GeomObjPtr> points = getSelected( TopAbs_VERTEX, -1 );
317 synchronize( myPoints, points );
318 if ( !myPoints.isEmpty() )
319 GroupPoints->LineEdit1->setText( QString::number( myPoints.count() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
321 GroupPoints->LineEdit1->setText( "" );
326 //=================================================================================
327 // function : ActivateThisDialog()
329 //=================================================================================
330 void BasicGUI_CurveDlg::ActivateThisDialog()
332 GEOMBase_Skeleton::ActivateThisDialog();
333 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
334 this, SLOT( SelectionIntoArgument() ) );
336 globalSelection(); // close local contexts, if any
337 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
339 ConstructorsClicked( getConstructorId() );
342 //=================================================================================
343 // function : DeactivateActiveDialog()
344 // purpose : public slot to deactivate if active
345 //=================================================================================
346 void BasicGUI_CurveDlg::DeactivateActiveDialog()
348 // myGeomGUI->SetState( -1 );
349 GEOMBase_Skeleton::DeactivateActiveDialog();
352 //=================================================================================
353 // function : enterEvent()
355 //=================================================================================
356 void BasicGUI_CurveDlg::enterEvent( QEvent* )
358 if ( !mainFrame()->GroupConstructors->isEnabled() )
359 ActivateThisDialog();
362 //=================================================================================
363 // function : createOperation
365 //=================================================================================
366 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
368 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
371 //=================================================================================
372 // function : isValid
374 //=================================================================================
375 bool BasicGUI_CurveDlg::isValid( QString& msg )
377 if( myBySelectionBtn->isChecked() )
378 return myPoints.count() > 1;
380 bool ok = myParams->myPMin->isValid( msg, !IsPreview() ) &&
381 myParams->myPMax->isValid( msg, !IsPreview() ) &&
382 myParams->myPStep->isValid( msg, !IsPreview() );
383 ok &= !myParams->myXExpr->text().isEmpty();
384 ok &= !myParams->myYExpr->text().isEmpty();
385 ok &= !myParams->myZExpr->text().isEmpty();
390 //=================================================================================
391 // function : execute
393 //=================================================================================
394 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
398 GEOM::GEOM_Object_var anObj;
400 GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() );
402 GEOM::ListOfGO_var points = new GEOM::ListOfGO();
403 points->length( myPoints.count() );
404 for ( int i = 0; i < myPoints.count(); i++ )
405 points[i] = myPoints[i].copy();
407 switch ( getConstructorId() ) {
409 if( myBySelectionBtn->isChecked() )
410 anObj = anOper->MakePolyline( points.in(), GroupPoints->CheckButton1->isChecked() );
412 anObj = anOper->MakeCurveParametricNew(qPrintable(myParams->myXExpr->text()),
413 qPrintable(myParams->myYExpr->text()),
414 qPrintable(myParams->myZExpr->text()),
415 myParams->myPMin->value(),
416 myParams->myPMax->value(),
417 myParams->myPStep->value(),
422 if( myBySelectionBtn->isChecked() )
423 anObj = anOper->MakeSplineBezier( points.in(), GroupPoints->CheckButton1->isChecked() );
425 anObj = anOper->MakeCurveParametricNew(qPrintable(myParams->myXExpr->text()),
426 qPrintable(myParams->myYExpr->text()),
427 qPrintable(myParams->myZExpr->text()),
428 myParams->myPMin->value(),
429 myParams->myPMax->value(),
430 myParams->myPStep->value(),
436 if( myBySelectionBtn->isChecked() )
437 anObj = anOper->MakeSplineInterpolation( points.in(), GroupPoints->CheckButton1->isChecked(),
438 GroupPoints->CheckButton2->isChecked() );
440 anObj = anOper->MakeCurveParametricNew(qPrintable(myParams->myXExpr->text()),
441 qPrintable(myParams->myYExpr->text()),
442 qPrintable(myParams->myZExpr->text()),
443 myParams->myPMin->value(),
444 myParams->myPMax->value(),
445 myParams->myPStep->value(),
446 GEOM::Interpolation);
451 if ( !anObj->_is_nil() ) {
452 if(myAnaliticalBtn->isChecked() && !IsPreview()) {
453 QStringList aParameters;
454 aParameters<<myParams->myPMin->text();
455 aParameters<<myParams->myPMax->text();
456 aParameters<<myParams->myPStep->text();
457 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
459 objects.push_back( anObj._retn() );
465 //=================================================================================
466 // function : addSubshapeToStudy
467 // purpose : virtual method to add new SubObjects if local selection
468 //=================================================================================
469 void BasicGUI_CurveDlg::addSubshapesToStudy()
471 for ( int i = 0; i < myPoints.count(); i++ )
472 GEOMBase::PublishSubObject( myPoints[i].get() );
475 //=================================================================================
476 // function : CreationModeChanged
478 //=================================================================================
479 void BasicGUI_CurveDlg::CreationModeChanged() {
480 const QObject* s = sender();
481 GroupPoints->setVisible(myBySelectionBtn == s);
482 myParams->setVisible(myBySelectionBtn != s);
484 ConstructorsClicked( getConstructorId() );
487 //=================================================================================
488 // function : ValueChangedInSpinBox()
490 //=================================================================================
491 void BasicGUI_CurveDlg::ValueChangedInSpinBox(double/*theValue*/)
496 //=================================================================================
497 // function : ValueChangedInSpinBox()
499 //=================================================================================
500 void BasicGUI_CurveDlg::ValueChangedInSpinBox(int/*theValue*/)
505 //=================================================================================
506 // function : ValueChangedInSpinBox()
508 //=================================================================================
509 void BasicGUI_CurveDlg::OnEditingFinished() {