1 // Copyright (C) 2007-2022 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, or (at your option) any later version.
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_ListIO.hxx>
42 #include <TopoDS_Shape.hxx>
45 #include <TColStd_IndexedMapOfInteger.hxx>
46 #include <TopTools_IndexedMapOfShape.hxx>
48 #include <GEOMImpl_Types.hxx>
50 #include <QButtonGroup>
52 //=================================================================================
53 // class : BasicGUI_CurveDlg()
54 // purpose : Constructs a BasicGUI_CurveDlg which is a child of 'parent', with the
55 // name 'name' and widget flags set to 'f'.
56 // The dialog will by default be modeless, unless you set 'modal' to
57 // TRUE to construct a modal dialog.
58 //=================================================================================
59 BasicGUI_CurveDlg::BasicGUI_CurveDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
60 bool modal, Qt::WindowFlags fl )
61 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
63 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_POLYLINE")));
64 QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SPLINE")));
65 QPixmap image3 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BEZIER")));
66 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
68 setWindowTitle(tr("GEOM_CURVE_TITLE"));
70 /***************************************************************/
71 mainFrame()->RadioButton1->setIcon(image0);
72 mainFrame()->RadioButton2->setIcon(image3);
73 mainFrame()->RadioButton3->setIcon(image2);
76 QGroupBox* creationModeGroup = new QGroupBox (this);
77 QButtonGroup* bg = new QButtonGroup (this);
79 creationModeGroup->setTitle(tr("GEOM_CURVE_CRMODE"));
80 QHBoxLayout * creationModeLayout = new QHBoxLayout (creationModeGroup);
81 myBySelectionBtn = new QRadioButton (tr("GEOM_CURVE_SELECTION") ,creationModeGroup);
82 myAnaliticalBtn = new QRadioButton (tr("GEOM_CURVE_ANALITICAL") ,creationModeGroup);
84 bg->addButton(myBySelectionBtn);
85 bg->addButton(myAnaliticalBtn);
87 creationModeLayout->addWidget(myBySelectionBtn);
88 creationModeLayout->addWidget(myAnaliticalBtn);
91 myGroupPoints = new DlgRef_1Sel3Check (centralWidget());
93 myGroupPoints->GroupBox1->setTitle(tr("GEOM_NODES"));
94 myGroupPoints->TextLabel1->setText(tr("GEOM_POINTS"));
95 myGroupPoints->PushButton1->setIcon(image1);
96 myGroupPoints->PushButton1->setDown(true);
98 myGroupPoints->LineEdit1->setReadOnly( true );
100 myGroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
101 myGroupPoints->CheckButton1->setChecked(false);
102 //myGroupPoints->CheckButton1->hide();
104 myGroupPoints->CheckButton2->setText( tr( "GEOM_IS_REORDER" ) );
105 myGroupPoints->CheckButton2->setChecked(false);
106 myGroupPoints->CheckButton2->hide();
108 myGroupPoints->CheckButton3->hide();
111 myGroupParams = new BasicGUI_ParamCurveWidget( centralWidget() );
113 // Tangents (only for Interpolation constructor and only not closed and no reordering)
114 myGroupTangents = new QGroupBox (this);
115 myGroupTangents->setCheckable(true);
116 myGroupTangents->setChecked(false);
117 myGroupTangents->setTitle(tr("GEOM_INTERPOL_TANGENTS"));
119 QGridLayout* tangentsLayout = new QGridLayout (myGroupTangents);
121 myPushBtnV1 = new QPushButton (myGroupTangents);
122 myPushBtnV2 = new QPushButton (myGroupTangents);
123 myPushBtnV1->setIcon(image1);
124 myPushBtnV2->setIcon(image1);
126 myLineEditV1 = new QLineEdit (myGroupTangents);
127 myLineEditV2 = new QLineEdit (myGroupTangents);
128 myLineEditV1->setReadOnly(true);
129 myLineEditV2->setReadOnly(true);
131 QLabel* aTextLabelV1 = new QLabel (myGroupTangents);
132 QLabel* aTextLabelV2 = new QLabel (myGroupTangents);
133 aTextLabelV1->setText(tr("GEOM_INTERPOL_FIRST_VEC"));
134 aTextLabelV2->setText(tr("GEOM_INTERPOL_LAST_VEC"));
136 tangentsLayout->addWidget(aTextLabelV1, 0, 0);
137 tangentsLayout->addWidget(myPushBtnV1 , 0, 1);
138 tangentsLayout->addWidget(myLineEditV1, 0, 2);
139 tangentsLayout->addWidget(aTextLabelV2, 1, 0);
140 tangentsLayout->addWidget(myPushBtnV2 , 1, 1);
141 tangentsLayout->addWidget(myLineEditV2, 1, 2);
144 QVBoxLayout* layout = new QVBoxLayout (centralWidget());
145 layout->setMargin(0);
146 layout->setSpacing(6);
147 layout->addWidget(creationModeGroup);
148 layout->addWidget(myGroupPoints);
149 layout->addWidget(myGroupParams);
150 layout->addWidget(myGroupTangents);
151 /***************************************************************/
153 setHelpFileName("create_curve_page.html");
158 //=================================================================================
159 // function : ~BasicGUI_CurveDlg()
160 // purpose : Destroys the object and frees any allocated resources
161 //=================================================================================
162 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
166 //=================================================================================
169 //=================================================================================
170 void BasicGUI_CurveDlg::Init()
173 showOnlyPreviewControl();
174 myBySelectionBtn->setChecked(true);
176 /* Get setting of step value from file configuration */
177 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
178 double step = resMgr ? resMgr->doubleValue( "Geometry", "SettingsGeomStep", 10. ) : 10.;
180 double aMax( 100. ), aMin( 0.0 );
182 /* min, max, step and decimals for spin boxes & initial values */
183 initSpinBox( myGroupParams->myPMin, COORD_MIN, COORD_MAX, step, "length_precision" );
184 initSpinBox( myGroupParams->myPMax, COORD_MIN, COORD_MAX, step, "length_precision" );
185 myGroupParams->myPStep->setValue( 10 );
186 myGroupParams->myPStep->setMaximum( 999 );
187 myGroupParams->myPStep->setSingleStep( 10 );
188 myGroupParams->myPMin->setValue( aMin );
189 myGroupParams->myPMax->setValue( aMax );
190 myGroupParams->myPStep->setValue( step );
191 myGroupParams->myXExpr->setText("t");
192 myGroupParams->myYExpr->setText("t");
193 myGroupParams->myZExpr->setText("t");
195 myGroupParams->hide();
197 /* signals and slots connections */
198 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
199 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
201 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
202 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
204 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
206 connect(myGroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
207 connect(myPushBtnV1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
208 connect(myPushBtnV2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
210 connect(myGroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CheckButtonToggled()));
211 connect(myGroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(CheckButtonToggled()));
212 connect(myGroupTangents, SIGNAL(toggled(bool)), this, SLOT(CheckButtonToggled()));
214 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
215 this, SLOT(SelectionIntoArgument()));
217 connect(myBySelectionBtn, SIGNAL(clicked()), this, SLOT(CreationModeChanged()));
218 connect(myAnaliticalBtn, SIGNAL(clicked()), this, SLOT(CreationModeChanged()));
220 connect(myGroupParams->myPMin, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
221 connect(myGroupParams->myPMax, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
222 connect(myGroupParams->myPStep, SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
224 connect(myGroupParams->myXExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
225 connect(myGroupParams->myYExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
226 connect(myGroupParams->myZExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
228 initName(tr("GEOM_CURVE"));
230 ConstructorsClicked(0);
233 //=================================================================================
234 // function : ConstructorsClicked()
236 //=================================================================================
237 void BasicGUI_CurveDlg::ConstructorsClicked (int id)
239 QString aTitle = tr(id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL");
240 mainFrame()->GroupConstructors->setTitle(aTitle);
242 if (id == 0) { // polyline (wire)
243 myGroupPoints->CheckButton1->setText( tr( "GEOM_BUILD_CLOSED_WIRE" ) );
244 myGroupPoints->CheckButton2->hide();
245 myGroupTangents->hide();
247 else if (id == 1) { // bezier
248 myGroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
249 myGroupPoints->CheckButton2->hide();
250 myGroupTangents->hide();
253 myGroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
254 myGroupPoints->CheckButton2->show();
255 myGroupTangents->setVisible(myBySelectionBtn->isChecked());
262 myGroupPoints->LineEdit1->setText("");
263 myLineEditV1->setText("");
264 myLineEditV2->setText("");
266 qApp->processEvents();
268 resize(minimumSizeHint());
270 myGroupPoints->PushButton1->click();
273 //=================================================================================
274 // function : SetEditCurrentArgument()
276 //=================================================================================
277 void BasicGUI_CurveDlg::SetEditCurrentArgument()
279 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
281 globalSelection(); // close local contexts, if any
283 if (sender() == myGroupPoints->PushButton1) {
284 myEditCurrentArgument = myGroupPoints->LineEdit1;
285 localSelection(TopAbs_VERTEX);
287 else if (sender() == myPushBtnV1) {
288 myEditCurrentArgument = myLineEditV1;
289 localSelection(TopAbs_EDGE);
291 else if (sender() == myPushBtnV2) {
292 myEditCurrentArgument = myLineEditV2;
293 localSelection(TopAbs_EDGE);
296 myEditCurrentArgument->setFocus();
298 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
299 this, SLOT(SelectionIntoArgument()));
301 SelectionIntoArgument();
304 //=================================================================================
305 // function : CheckButtonToggled()
307 //=================================================================================
308 void BasicGUI_CurveDlg::CheckButtonToggled()
310 if (sender() == myGroupTangents) {
311 if (myGroupTangents->isChecked())
312 myPushBtnV1->click();
314 myGroupPoints->PushButton1->click();
317 if (getConstructorId() == 2) { // Interpolation
318 bool disableTangents = (myGroupPoints->CheckButton1->isChecked() ||
319 myGroupPoints->CheckButton2->isChecked());
320 myGroupTangents->setEnabled(!disableTangents);
326 //=================================================================================
327 // function : ClickOnOk()
329 //=================================================================================
330 void BasicGUI_CurveDlg::ClickOnOk()
332 setIsApplyAndClose(true);
337 //=================================================================================
338 // function : ClickOnApply()
340 //=================================================================================
341 bool BasicGUI_CurveDlg::ClickOnApply()
347 ConstructorsClicked(getConstructorId());
351 void BasicGUI_CurveDlg::SelectionIntoArgument()
353 myEditCurrentArgument->setText("");
355 if (myEditCurrentArgument == myGroupPoints->LineEdit1) {
356 QList<GEOM::GeomObjPtr> points = getSelected(TopAbs_VERTEX, -1);
357 GEOMBase::Synchronize(myPoints, points);
358 if (!myPoints.isEmpty())
359 myGroupPoints->LineEdit1->setText(QString::number(myPoints.count()) + "_" +
360 tr("GEOM_POINT") + tr("_S_"));
363 QList<GEOM::GeomObjPtr> vecs = getSelected(TopAbs_EDGE, -1);
364 if (vecs.count() != 1) {
365 if (myEditCurrentArgument == myLineEditV1) myVec1.nullify();
366 else if (myEditCurrentArgument == myLineEditV2) myVec2.nullify();
369 if (myEditCurrentArgument == myLineEditV1) {
370 myVec1 = vecs.first();
372 else if (myEditCurrentArgument == myLineEditV2) {
373 myVec2 = vecs.first();
375 QString aName = GEOMBase::GetName(vecs.first().get());
376 myEditCurrentArgument->setText(aName);
383 //=================================================================================
384 // function : ActivateThisDialog()
386 //=================================================================================
387 void BasicGUI_CurveDlg::ActivateThisDialog()
389 GEOMBase_Skeleton::ActivateThisDialog();
391 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
392 this, SLOT(SelectionIntoArgument()));
394 ConstructorsClicked(getConstructorId());
397 //=================================================================================
398 // function : DeactivateActiveDialog()
399 // purpose : public slot to deactivate if active
400 //=================================================================================
401 void BasicGUI_CurveDlg::DeactivateActiveDialog()
403 // myGeomGUI->SetState( -1 );
404 GEOMBase_Skeleton::DeactivateActiveDialog();
407 //=================================================================================
408 // function : enterEvent()
410 //=================================================================================
411 void BasicGUI_CurveDlg::enterEvent (QEvent*)
413 if (!mainFrame()->GroupConstructors->isEnabled())
414 ActivateThisDialog();
417 //=================================================================================
418 // function : createOperation
420 //=================================================================================
421 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
423 return myGeomGUI->GetGeomGen()->GetICurvesOperations();
426 //=================================================================================
427 // function : isValid
429 //=================================================================================
430 bool BasicGUI_CurveDlg::isValid (QString& msg)
432 if (myBySelectionBtn->isChecked()) {
434 if (getConstructorId() == 2) { // Interpolation
435 bool disableTangents = (myGroupPoints->CheckButton1->isChecked() ||
436 myGroupPoints->CheckButton2->isChecked());
437 if (!disableTangents && myGroupTangents->isChecked()) {
438 ok = (myVec1 && myVec2);
439 if (!ok) msg = tr("GEOM_BOTH_TANGENTS_REQUIRED");
442 return ok && myPoints.count() > 1;
445 bool ok = myGroupParams->myPMin->isValid( msg, !IsPreview() ) &&
446 myGroupParams->myPMax->isValid( msg, !IsPreview() ) &&
447 myGroupParams->myPStep->isValid( msg, !IsPreview() );
448 ok &= !myGroupParams->myXExpr->text().isEmpty();
449 ok &= !myGroupParams->myYExpr->text().isEmpty();
450 ok &= !myGroupParams->myZExpr->text().isEmpty();
455 //=================================================================================
456 // function : execute
458 //=================================================================================
459 bool BasicGUI_CurveDlg::execute (ObjectList& objects)
463 GEOM::GEOM_Object_var anObj;
465 GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
467 GEOM::ListOfGO_var points = new GEOM::ListOfGO();
468 points->length(myPoints.count());
469 for (int i = 0; i < myPoints.count(); i++)
470 points[i] = myPoints[i].copy();
472 switch (getConstructorId()) {
474 if (myBySelectionBtn->isChecked())
475 anObj = anOper->MakePolyline(points.in(), myGroupPoints->CheckButton1->isChecked());
477 anObj = anOper->MakeCurveParametricNew(qUtf8Printable(myGroupParams->myXExpr->text()),
478 qUtf8Printable(myGroupParams->myYExpr->text()),
479 qUtf8Printable(myGroupParams->myZExpr->text()),
480 myGroupParams->myPMin->value(),
481 myGroupParams->myPMax->value(),
482 myGroupParams->myPStep->value(),
487 if (myBySelectionBtn->isChecked())
488 anObj = anOper->MakeSplineBezier(points.in(), myGroupPoints->CheckButton1->isChecked());
490 anObj = anOper->MakeCurveParametricNew(qUtf8Printable(myGroupParams->myXExpr->text()),
491 qUtf8Printable(myGroupParams->myYExpr->text()),
492 qUtf8Printable(myGroupParams->myZExpr->text()),
493 myGroupParams->myPMin->value(),
494 myGroupParams->myPMax->value(),
495 myGroupParams->myPStep->value(),
500 if (myBySelectionBtn->isChecked()) {
501 bool disableTangents = (myGroupPoints->CheckButton1->isChecked() ||
502 myGroupPoints->CheckButton2->isChecked());
503 if (!disableTangents && myGroupTangents->isChecked()) {
504 anObj = anOper->MakeSplineInterpolWithTangents(points.in(), myVec1.get(), myVec2.get());
507 anObj = anOper->MakeSplineInterpolation(points.in(), myGroupPoints->CheckButton1->isChecked(),
508 myGroupPoints->CheckButton2->isChecked());
511 anObj = anOper->MakeCurveParametricNew(qUtf8Printable(myGroupParams->myXExpr->text()),
512 qUtf8Printable(myGroupParams->myYExpr->text()),
513 qUtf8Printable(myGroupParams->myZExpr->text()),
514 myGroupParams->myPMin->value(),
515 myGroupParams->myPMax->value(),
516 myGroupParams->myPStep->value(),
517 GEOM::Interpolation);
522 if (!anObj->_is_nil()) {
523 if (myAnaliticalBtn->isChecked() && !IsPreview()) {
524 QStringList aParameters;
525 aParameters<<myGroupParams->myPMin->text();
526 aParameters<<myGroupParams->myPMax->text();
527 aParameters<<myGroupParams->myPStep->text();
528 anObj->SetParameters(aParameters.join(":").toUtf8().constData());
530 objects.push_back(anObj._retn());
536 //=================================================================================
537 // function : addSubshapesToStudy
538 // purpose : virtual method to add new SubObjects if local selection
539 //=================================================================================
540 void BasicGUI_CurveDlg::addSubshapesToStudy()
542 for ( int i = 0; i < myPoints.count(); i++ )
543 GEOMBase::PublishSubObject( myPoints[i].get() );
546 //=================================================================================
547 // function : getSourceObjects
548 // purpose : virtual method to get source objects
549 //=================================================================================
550 QList<GEOM::GeomObjPtr> BasicGUI_CurveDlg::getSourceObjects()
554 //=================================================================================
555 // function : CreationModeChanged
557 //=================================================================================
558 void BasicGUI_CurveDlg::CreationModeChanged()
560 const QObject* s = sender();
561 myGroupPoints->setVisible(myBySelectionBtn == s);
562 myGroupParams->setVisible(myBySelectionBtn != s);
564 ConstructorsClicked(getConstructorId());
567 //=================================================================================
568 // function : ValueChangedInSpinBox()
570 //=================================================================================
571 void BasicGUI_CurveDlg::ValueChangedInSpinBox (double/*theValue*/)
576 //=================================================================================
577 // function : ValueChangedInSpinBox()
579 //=================================================================================
580 void BasicGUI_CurveDlg::ValueChangedInSpinBox (int/*theValue*/)
585 //=================================================================================
586 // function : OnEditingFinished()
588 //=================================================================================
589 void BasicGUI_CurveDlg::OnEditingFinished()