1 // Copyright (C) 2007-2013 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);
75 QGroupBox* creationModeGroup = new QGroupBox (this);
76 QButtonGroup* bg = new QButtonGroup (this);
78 creationModeGroup->setTitle(tr("GEOM_CURVE_CRMODE"));
79 QHBoxLayout * creationModeLayout = new QHBoxLayout (creationModeGroup);
80 myBySelectionBtn = new QRadioButton (tr("GEOM_CURVE_SELECTION") ,creationModeGroup);
81 myAnaliticalBtn = new QRadioButton (tr("GEOM_CURVE_ANALITICAL") ,creationModeGroup);
83 bg->addButton(myBySelectionBtn);
84 bg->addButton(myAnaliticalBtn);
86 creationModeLayout->addWidget(myBySelectionBtn);
87 creationModeLayout->addWidget(myAnaliticalBtn);
90 myGroupPoints = new DlgRef_1Sel3Check (centralWidget());
92 myGroupPoints->GroupBox1->setTitle(tr("GEOM_NODES"));
93 myGroupPoints->TextLabel1->setText(tr("GEOM_POINTS"));
94 myGroupPoints->PushButton1->setIcon(image1);
95 myGroupPoints->PushButton1->setDown(true);
97 myGroupPoints->LineEdit1->setReadOnly( true );
99 myGroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
100 myGroupPoints->CheckButton1->setChecked(false);
101 //myGroupPoints->CheckButton1->hide();
103 myGroupPoints->CheckButton2->setText( tr( "GEOM_IS_REORDER" ) );
104 myGroupPoints->CheckButton2->setChecked(false);
105 myGroupPoints->CheckButton2->hide();
107 myGroupPoints->CheckButton3->hide();
110 myGroupParams = new BasicGUI_ParamCurveWidget( centralWidget() );
112 // Tangents (only for Interpolation constructor and only not closed and no reordering)
113 myGroupTangents = new QGroupBox (this);
114 myGroupTangents->setCheckable(true);
115 myGroupTangents->setChecked(false);
116 myGroupTangents->setTitle(tr("GEOM_INTERPOL_TANGENTS"));
118 QGridLayout* tangentsLayout = new QGridLayout (myGroupTangents);
120 myPushBtnV1 = new QPushButton (myGroupTangents);
121 myPushBtnV2 = new QPushButton (myGroupTangents);
122 myPushBtnV1->setIcon(image1);
123 myPushBtnV2->setIcon(image1);
125 myLineEditV1 = new QLineEdit (myGroupTangents);
126 myLineEditV2 = new QLineEdit (myGroupTangents);
127 myLineEditV1->setReadOnly(true);
128 myLineEditV2->setReadOnly(true);
130 QLabel* aTextLabelV1 = new QLabel (myGroupTangents);
131 QLabel* aTextLabelV2 = new QLabel (myGroupTangents);
132 aTextLabelV1->setText(tr("GEOM_INTERPOL_FIRST_VEC"));
133 aTextLabelV2->setText(tr("GEOM_INTERPOL_LAST_VEC"));
135 tangentsLayout->addWidget(aTextLabelV1, 0, 0);
136 tangentsLayout->addWidget(myPushBtnV1 , 0, 1);
137 tangentsLayout->addWidget(myLineEditV1, 0, 2);
138 tangentsLayout->addWidget(aTextLabelV2, 1, 0);
139 tangentsLayout->addWidget(myPushBtnV2 , 1, 1);
140 tangentsLayout->addWidget(myLineEditV2, 1, 2);
143 QVBoxLayout* layout = new QVBoxLayout (centralWidget());
144 layout->setMargin(0);
145 layout->setSpacing(6);
146 layout->addWidget(creationModeGroup);
147 layout->addWidget(myGroupPoints);
148 layout->addWidget(myGroupParams);
149 layout->addWidget(myGroupTangents);
150 /***************************************************************/
152 setHelpFileName("create_curve_page.html");
157 //=================================================================================
158 // function : ~BasicGUI_CurveDlg()
159 // purpose : Destroys the object and frees any allocated resources
160 //=================================================================================
161 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
165 //=================================================================================
168 //=================================================================================
169 void BasicGUI_CurveDlg::Init()
172 showOnlyPreviewControl();
173 myBySelectionBtn->setChecked(true);
175 /* Get setting of step value from file configuration */
176 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
177 double step = resMgr ? resMgr->doubleValue( "Geometry", "SettingsGeomStep", 10. ) : 10.;
179 double aMax( 100. ), aMin( 0.0 );
181 /* min, max, step and decimals for spin boxes & initial values */
182 initSpinBox( myGroupParams->myPMin, COORD_MIN, COORD_MAX, step, "length_precision" );
183 initSpinBox( myGroupParams->myPMax, COORD_MIN, COORD_MAX, step, "length_precision" );
184 myGroupParams->myPStep->setValue( 10 );
185 myGroupParams->myPStep->setMaximum( 999 );
186 myGroupParams->myPStep->setSingleStep( 10 );
187 myGroupParams->myPMin->setValue( aMin );
188 myGroupParams->myPMax->setValue( aMax );
189 myGroupParams->myPStep->setValue( step );
190 myGroupParams->myXExpr->setText("t");
191 myGroupParams->myYExpr->setText("t");
192 myGroupParams->myZExpr->setText("t");
194 myGroupParams->hide();
196 /* signals and slots connections */
197 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
198 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
200 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
201 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
203 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
205 connect(myGroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
206 connect(myPushBtnV1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
207 connect(myPushBtnV2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
209 connect(myGroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CheckButtonToggled()));
210 connect(myGroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(CheckButtonToggled()));
211 connect(myGroupTangents, SIGNAL(toggled(bool)), this, SLOT(CheckButtonToggled()));
213 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
214 this, SLOT(SelectionIntoArgument()));
216 connect(myBySelectionBtn, SIGNAL(clicked()), this, SLOT(CreationModeChanged()));
217 connect(myAnaliticalBtn, SIGNAL(clicked()), this, SLOT(CreationModeChanged()));
219 connect(myGroupParams->myPMin, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
220 connect(myGroupParams->myPMax, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
221 connect(myGroupParams->myPStep, SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
223 connect(myGroupParams->myXExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
224 connect(myGroupParams->myYExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
225 connect(myGroupParams->myZExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
227 initName(tr("GEOM_CURVE"));
229 ConstructorsClicked(0);
232 //=================================================================================
233 // function : ConstructorsClicked()
235 //=================================================================================
236 void BasicGUI_CurveDlg::ConstructorsClicked (int id)
238 QString aTitle = tr(id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL");
239 mainFrame()->GroupConstructors->setTitle(aTitle);
241 if (id == 0) { // polyline (wire)
242 myGroupPoints->CheckButton1->setText( tr( "GEOM_BUILD_CLOSED_WIRE" ) );
243 myGroupPoints->CheckButton2->hide();
244 myGroupTangents->hide();
246 else if (id == 1) { // bezier
247 myGroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
248 myGroupPoints->CheckButton2->hide();
249 myGroupTangents->hide();
252 myGroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
253 myGroupPoints->CheckButton2->show();
254 myGroupTangents->setVisible(myBySelectionBtn->isChecked());
261 myGroupPoints->LineEdit1->setText("");
262 myLineEditV1->setText("");
263 myLineEditV2->setText("");
265 qApp->processEvents();
267 resize(minimumSizeHint());
269 myGroupPoints->PushButton1->click();
272 //=================================================================================
273 // function : SetEditCurrentArgument()
275 //=================================================================================
276 void BasicGUI_CurveDlg::SetEditCurrentArgument()
278 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
280 globalSelection(); // close local contexts, if any
282 if (sender() == myGroupPoints->PushButton1) {
283 myEditCurrentArgument = myGroupPoints->LineEdit1;
284 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
286 else if (sender() == myPushBtnV1) {
287 myEditCurrentArgument = myLineEditV1;
288 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
290 else if (sender() == myPushBtnV2) {
291 myEditCurrentArgument = myLineEditV2;
292 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
295 myEditCurrentArgument->setFocus();
297 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
298 this, SLOT(SelectionIntoArgument()));
300 SelectionIntoArgument();
303 //=================================================================================
304 // function : CheckButtonToggled()
306 //=================================================================================
307 void BasicGUI_CurveDlg::CheckButtonToggled()
309 if (sender() == myGroupTangents) {
310 if (myGroupTangents->isChecked())
311 myPushBtnV1->click();
313 myGroupPoints->PushButton1->click();
316 if (getConstructorId() == 2) { // Interpolation
317 bool disableTangents = (myGroupPoints->CheckButton1->isChecked() ||
318 myGroupPoints->CheckButton2->isChecked());
319 myGroupTangents->setEnabled(!disableTangents);
325 //=================================================================================
326 // function : ClickOnOk()
328 //=================================================================================
329 void BasicGUI_CurveDlg::ClickOnOk()
331 setIsApplyAndClose(true);
336 //=================================================================================
337 // function : ClickOnApply()
339 //=================================================================================
340 bool BasicGUI_CurveDlg::ClickOnApply()
346 ConstructorsClicked(getConstructorId());
350 //=================================================================================
351 // function : SelectionIntoArgument()
352 // purpose : Called when selection as changed or other case
353 //=================================================================================
354 static void synchronize (QList<GEOM::GeomObjPtr>& left, QList<GEOM::GeomObjPtr>& right)
356 // 1. remove items from the "left" list that are not in the "right" list
357 QMutableListIterator<GEOM::GeomObjPtr> it1 (left);
358 while (it1.hasNext()) {
359 GEOM::GeomObjPtr o1 = it1.next();
361 QMutableListIterator<GEOM::GeomObjPtr> it2( right );
362 while ( it2.hasNext() && !found )
363 found = o1 == it2.next();
367 // 2. add items from the "right" list that are not in the "left" list (to keep selection order)
369 while ( it1.hasNext() ) {
370 GEOM::GeomObjPtr o1 = it1.next();
372 QMutableListIterator<GEOM::GeomObjPtr> it2( left );
373 while ( it2.hasNext() && !found )
374 found = o1 == it2.next();
380 void BasicGUI_CurveDlg::SelectionIntoArgument()
382 myEditCurrentArgument->setText("");
384 if (myEditCurrentArgument == myGroupPoints->LineEdit1) {
385 QList<GEOM::GeomObjPtr> points = getSelected(TopAbs_VERTEX, -1);
386 synchronize(myPoints, points);
387 if (!myPoints.isEmpty())
388 myGroupPoints->LineEdit1->setText(QString::number(myPoints.count()) + "_" +
389 tr("GEOM_POINT") + tr("_S_"));
392 QList<GEOM::GeomObjPtr> vecs = getSelected(TopAbs_EDGE, -1);
393 if (vecs.count() != 1) {
394 if (myEditCurrentArgument == myLineEditV1) myVec1.nullify();
395 else if (myEditCurrentArgument == myLineEditV2) myVec2.nullify();
398 if (myEditCurrentArgument == myLineEditV1) {
399 myVec1 = vecs.first();
401 else if (myEditCurrentArgument == myLineEditV2) {
402 myVec2 = vecs.first();
404 QString aName = GEOMBase::GetName(vecs.first().get());
405 myEditCurrentArgument->setText(aName);
412 //=================================================================================
413 // function : ActivateThisDialog()
415 //=================================================================================
416 void BasicGUI_CurveDlg::ActivateThisDialog()
418 GEOMBase_Skeleton::ActivateThisDialog();
420 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
421 this, SLOT(SelectionIntoArgument()));
423 ConstructorsClicked(getConstructorId());
426 //=================================================================================
427 // function : DeactivateActiveDialog()
428 // purpose : public slot to deactivate if active
429 //=================================================================================
430 void BasicGUI_CurveDlg::DeactivateActiveDialog()
432 // myGeomGUI->SetState( -1 );
433 GEOMBase_Skeleton::DeactivateActiveDialog();
436 //=================================================================================
437 // function : enterEvent()
439 //=================================================================================
440 void BasicGUI_CurveDlg::enterEvent (QEvent*)
442 if (!mainFrame()->GroupConstructors->isEnabled())
443 ActivateThisDialog();
446 //=================================================================================
447 // function : createOperation
449 //=================================================================================
450 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
452 return myGeomGUI->GetGeomGen()->GetICurvesOperations(getStudyId());
455 //=================================================================================
456 // function : isValid
458 //=================================================================================
459 bool BasicGUI_CurveDlg::isValid (QString& msg)
461 if (myBySelectionBtn->isChecked()) {
463 if (getConstructorId() == 2) { // Interpolation
464 bool disableTangents = (myGroupPoints->CheckButton1->isChecked() ||
465 myGroupPoints->CheckButton2->isChecked());
466 if (!disableTangents && myGroupTangents->isChecked()) {
467 ok = (myVec1 && myVec2);
468 if (!ok) msg = tr("GEOM_BOTH_TANGENTS_REQUIRED");
471 return ok && myPoints.count() > 1;
474 bool ok = myGroupParams->myPMin->isValid( msg, !IsPreview() ) &&
475 myGroupParams->myPMax->isValid( msg, !IsPreview() ) &&
476 myGroupParams->myPStep->isValid( msg, !IsPreview() );
477 ok &= !myGroupParams->myXExpr->text().isEmpty();
478 ok &= !myGroupParams->myYExpr->text().isEmpty();
479 ok &= !myGroupParams->myZExpr->text().isEmpty();
484 //=================================================================================
485 // function : execute
487 //=================================================================================
488 bool BasicGUI_CurveDlg::execute (ObjectList& objects)
492 GEOM::GEOM_Object_var anObj;
494 GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
496 GEOM::ListOfGO_var points = new GEOM::ListOfGO();
497 points->length(myPoints.count());
498 for (int i = 0; i < myPoints.count(); i++)
499 points[i] = myPoints[i].copy();
501 switch (getConstructorId()) {
503 if (myBySelectionBtn->isChecked())
504 anObj = anOper->MakePolyline(points.in(), myGroupPoints->CheckButton1->isChecked());
506 anObj = anOper->MakeCurveParametricNew(qPrintable(myGroupParams->myXExpr->text()),
507 qPrintable(myGroupParams->myYExpr->text()),
508 qPrintable(myGroupParams->myZExpr->text()),
509 myGroupParams->myPMin->value(),
510 myGroupParams->myPMax->value(),
511 myGroupParams->myPStep->value(),
516 if (myBySelectionBtn->isChecked())
517 anObj = anOper->MakeSplineBezier(points.in(), myGroupPoints->CheckButton1->isChecked());
519 anObj = anOper->MakeCurveParametricNew(qPrintable(myGroupParams->myXExpr->text()),
520 qPrintable(myGroupParams->myYExpr->text()),
521 qPrintable(myGroupParams->myZExpr->text()),
522 myGroupParams->myPMin->value(),
523 myGroupParams->myPMax->value(),
524 myGroupParams->myPStep->value(),
529 if (myBySelectionBtn->isChecked()) {
530 bool disableTangents = (myGroupPoints->CheckButton1->isChecked() ||
531 myGroupPoints->CheckButton2->isChecked());
532 if (!disableTangents && myGroupTangents->isChecked()) {
533 anObj = anOper->MakeSplineInterpolWithTangents(points.in(), myVec1.get(), myVec2.get());
536 anObj = anOper->MakeSplineInterpolation(points.in(), myGroupPoints->CheckButton1->isChecked(),
537 myGroupPoints->CheckButton2->isChecked());
540 anObj = anOper->MakeCurveParametricNew(qPrintable(myGroupParams->myXExpr->text()),
541 qPrintable(myGroupParams->myYExpr->text()),
542 qPrintable(myGroupParams->myZExpr->text()),
543 myGroupParams->myPMin->value(),
544 myGroupParams->myPMax->value(),
545 myGroupParams->myPStep->value(),
546 GEOM::Interpolation);
551 if (!anObj->_is_nil()) {
552 if (myAnaliticalBtn->isChecked() && !IsPreview()) {
553 QStringList aParameters;
554 aParameters<<myGroupParams->myPMin->text();
555 aParameters<<myGroupParams->myPMax->text();
556 aParameters<<myGroupParams->myPStep->text();
557 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
559 objects.push_back(anObj._retn());
565 //=================================================================================
566 // function : addSubshapesToStudy
567 // purpose : virtual method to add new SubObjects if local selection
568 //=================================================================================
569 void BasicGUI_CurveDlg::addSubshapesToStudy()
571 for ( int i = 0; i < myPoints.count(); i++ )
572 GEOMBase::PublishSubObject( myPoints[i].get() );
575 //=================================================================================
576 // function : CreationModeChanged
578 //=================================================================================
579 void BasicGUI_CurveDlg::CreationModeChanged()
581 const QObject* s = sender();
582 myGroupPoints->setVisible(myBySelectionBtn == s);
583 myGroupParams->setVisible(myBySelectionBtn != s);
585 ConstructorsClicked(getConstructorId());
588 //=================================================================================
589 // function : ValueChangedInSpinBox()
591 //=================================================================================
592 void BasicGUI_CurveDlg::ValueChangedInSpinBox (double/*theValue*/)
597 //=================================================================================
598 // function : ValueChangedInSpinBox()
600 //=================================================================================
601 void BasicGUI_CurveDlg::ValueChangedInSpinBox (int/*theValue*/)
606 //=================================================================================
607 // function : OnEditingFinished()
609 //=================================================================================
610 void BasicGUI_CurveDlg::OnEditingFinished()