1 // Copyright (C) 2007-2016 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 //=================================================================================
51 // class : BasicGUI_CurveDlg()
52 // purpose : Constructs a BasicGUI_CurveDlg which is a child of 'parent', with the
53 // name 'name' and widget flags set to 'f'.
54 // The dialog will by default be modeless, unless you set 'modal' to
55 // TRUE to construct a modal dialog.
56 //=================================================================================
57 BasicGUI_CurveDlg::BasicGUI_CurveDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
58 bool modal, Qt::WindowFlags fl )
59 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
61 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_POLYLINE")));
62 QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SPLINE")));
63 QPixmap image3 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BEZIER")));
64 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
66 setWindowTitle(tr("GEOM_CURVE_TITLE"));
68 /***************************************************************/
69 mainFrame()->RadioButton1->setIcon(image0);
70 mainFrame()->RadioButton2->setIcon(image3);
71 mainFrame()->RadioButton3->setIcon(image2);
74 QGroupBox* creationModeGroup = new QGroupBox (this);
75 QButtonGroup* bg = new QButtonGroup (this);
77 creationModeGroup->setTitle(tr("GEOM_CURVE_CRMODE"));
78 QHBoxLayout * creationModeLayout = new QHBoxLayout (creationModeGroup);
79 myBySelectionBtn = new QRadioButton (tr("GEOM_CURVE_SELECTION") ,creationModeGroup);
80 myAnaliticalBtn = new QRadioButton (tr("GEOM_CURVE_ANALITICAL") ,creationModeGroup);
82 bg->addButton(myBySelectionBtn);
83 bg->addButton(myAnaliticalBtn);
85 creationModeLayout->addWidget(myBySelectionBtn);
86 creationModeLayout->addWidget(myAnaliticalBtn);
89 myGroupPoints = new DlgRef_1Sel3Check (centralWidget());
91 myGroupPoints->GroupBox1->setTitle(tr("GEOM_NODES"));
92 myGroupPoints->TextLabel1->setText(tr("GEOM_POINTS"));
93 myGroupPoints->PushButton1->setIcon(image1);
94 myGroupPoints->PushButton1->setDown(true);
96 myGroupPoints->LineEdit1->setReadOnly( true );
98 myGroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
99 myGroupPoints->CheckButton1->setChecked(false);
100 //myGroupPoints->CheckButton1->hide();
102 myGroupPoints->CheckButton2->setText( tr( "GEOM_IS_REORDER" ) );
103 myGroupPoints->CheckButton2->setChecked(false);
104 myGroupPoints->CheckButton2->hide();
106 myGroupPoints->CheckButton3->hide();
109 myGroupParams = new BasicGUI_ParamCurveWidget( centralWidget() );
111 // Tangents (only for Interpolation constructor and only not closed and no reordering)
112 myGroupTangents = new QGroupBox (this);
113 myGroupTangents->setCheckable(true);
114 myGroupTangents->setChecked(false);
115 myGroupTangents->setTitle(tr("GEOM_INTERPOL_TANGENTS"));
117 QGridLayout* tangentsLayout = new QGridLayout (myGroupTangents);
119 myPushBtnV1 = new QPushButton (myGroupTangents);
120 myPushBtnV2 = new QPushButton (myGroupTangents);
121 myPushBtnV1->setIcon(image1);
122 myPushBtnV2->setIcon(image1);
124 myLineEditV1 = new QLineEdit (myGroupTangents);
125 myLineEditV2 = new QLineEdit (myGroupTangents);
126 myLineEditV1->setReadOnly(true);
127 myLineEditV2->setReadOnly(true);
129 QLabel* aTextLabelV1 = new QLabel (myGroupTangents);
130 QLabel* aTextLabelV2 = new QLabel (myGroupTangents);
131 aTextLabelV1->setText(tr("GEOM_INTERPOL_FIRST_VEC"));
132 aTextLabelV2->setText(tr("GEOM_INTERPOL_LAST_VEC"));
134 tangentsLayout->addWidget(aTextLabelV1, 0, 0);
135 tangentsLayout->addWidget(myPushBtnV1 , 0, 1);
136 tangentsLayout->addWidget(myLineEditV1, 0, 2);
137 tangentsLayout->addWidget(aTextLabelV2, 1, 0);
138 tangentsLayout->addWidget(myPushBtnV2 , 1, 1);
139 tangentsLayout->addWidget(myLineEditV2, 1, 2);
142 QVBoxLayout* layout = new QVBoxLayout (centralWidget());
143 layout->setMargin(0);
144 layout->setSpacing(6);
145 layout->addWidget(creationModeGroup);
146 layout->addWidget(myGroupPoints);
147 layout->addWidget(myGroupParams);
148 layout->addWidget(myGroupTangents);
149 /***************************************************************/
151 setHelpFileName("create_curve_page.html");
156 //=================================================================================
157 // function : ~BasicGUI_CurveDlg()
158 // purpose : Destroys the object and frees any allocated resources
159 //=================================================================================
160 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
164 //=================================================================================
167 //=================================================================================
168 void BasicGUI_CurveDlg::Init()
171 showOnlyPreviewControl();
172 myBySelectionBtn->setChecked(true);
174 /* Get setting of step value from file configuration */
175 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
176 double step = resMgr ? resMgr->doubleValue( "Geometry", "SettingsGeomStep", 10. ) : 10.;
178 double aMax( 100. ), aMin( 0.0 );
180 /* min, max, step and decimals for spin boxes & initial values */
181 initSpinBox( myGroupParams->myPMin, COORD_MIN, COORD_MAX, step, "length_precision" );
182 initSpinBox( myGroupParams->myPMax, COORD_MIN, COORD_MAX, step, "length_precision" );
183 myGroupParams->myPStep->setValue( 10 );
184 myGroupParams->myPStep->setMaximum( 999 );
185 myGroupParams->myPStep->setSingleStep( 10 );
186 myGroupParams->myPMin->setValue( aMin );
187 myGroupParams->myPMax->setValue( aMax );
188 myGroupParams->myPStep->setValue( step );
189 myGroupParams->myXExpr->setText("t");
190 myGroupParams->myYExpr->setText("t");
191 myGroupParams->myZExpr->setText("t");
193 myGroupParams->hide();
195 /* signals and slots connections */
196 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
197 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
199 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
200 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
202 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
204 connect(myGroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
205 connect(myPushBtnV1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
206 connect(myPushBtnV2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
208 connect(myGroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CheckButtonToggled()));
209 connect(myGroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(CheckButtonToggled()));
210 connect(myGroupTangents, SIGNAL(toggled(bool)), this, SLOT(CheckButtonToggled()));
212 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
213 this, SLOT(SelectionIntoArgument()));
215 connect(myBySelectionBtn, SIGNAL(clicked()), this, SLOT(CreationModeChanged()));
216 connect(myAnaliticalBtn, SIGNAL(clicked()), this, SLOT(CreationModeChanged()));
218 connect(myGroupParams->myPMin, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
219 connect(myGroupParams->myPMax, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
220 connect(myGroupParams->myPStep, SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
222 connect(myGroupParams->myXExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
223 connect(myGroupParams->myYExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
224 connect(myGroupParams->myZExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()));
226 initName(tr("GEOM_CURVE"));
228 ConstructorsClicked(0);
231 //=================================================================================
232 // function : ConstructorsClicked()
234 //=================================================================================
235 void BasicGUI_CurveDlg::ConstructorsClicked (int id)
237 QString aTitle = tr(id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL");
238 mainFrame()->GroupConstructors->setTitle(aTitle);
240 if (id == 0) { // polyline (wire)
241 myGroupPoints->CheckButton1->setText( tr( "GEOM_BUILD_CLOSED_WIRE" ) );
242 myGroupPoints->CheckButton2->hide();
243 myGroupTangents->hide();
245 else if (id == 1) { // bezier
246 myGroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
247 myGroupPoints->CheckButton2->hide();
248 myGroupTangents->hide();
251 myGroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
252 myGroupPoints->CheckButton2->show();
253 myGroupTangents->setVisible(myBySelectionBtn->isChecked());
260 myGroupPoints->LineEdit1->setText("");
261 myLineEditV1->setText("");
262 myLineEditV2->setText("");
264 qApp->processEvents();
266 resize(minimumSizeHint());
268 myGroupPoints->PushButton1->click();
271 //=================================================================================
272 // function : SetEditCurrentArgument()
274 //=================================================================================
275 void BasicGUI_CurveDlg::SetEditCurrentArgument()
277 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
279 globalSelection(); // close local contexts, if any
281 if (sender() == myGroupPoints->PushButton1) {
282 myEditCurrentArgument = myGroupPoints->LineEdit1;
283 localSelection(TopAbs_VERTEX);
285 else if (sender() == myPushBtnV1) {
286 myEditCurrentArgument = myLineEditV1;
287 localSelection(TopAbs_EDGE);
289 else if (sender() == myPushBtnV2) {
290 myEditCurrentArgument = myLineEditV2;
291 localSelection(TopAbs_EDGE);
294 myEditCurrentArgument->setFocus();
296 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
297 this, SLOT(SelectionIntoArgument()));
299 SelectionIntoArgument();
302 //=================================================================================
303 // function : CheckButtonToggled()
305 //=================================================================================
306 void BasicGUI_CurveDlg::CheckButtonToggled()
308 if (sender() == myGroupTangents) {
309 if (myGroupTangents->isChecked())
310 myPushBtnV1->click();
312 myGroupPoints->PushButton1->click();
315 if (getConstructorId() == 2) { // Interpolation
316 bool disableTangents = (myGroupPoints->CheckButton1->isChecked() ||
317 myGroupPoints->CheckButton2->isChecked());
318 myGroupTangents->setEnabled(!disableTangents);
324 //=================================================================================
325 // function : ClickOnOk()
327 //=================================================================================
328 void BasicGUI_CurveDlg::ClickOnOk()
330 setIsApplyAndClose(true);
335 //=================================================================================
336 // function : ClickOnApply()
338 //=================================================================================
339 bool BasicGUI_CurveDlg::ClickOnApply()
345 ConstructorsClicked(getConstructorId());
349 void BasicGUI_CurveDlg::SelectionIntoArgument()
351 myEditCurrentArgument->setText("");
353 if (myEditCurrentArgument == myGroupPoints->LineEdit1) {
354 QList<GEOM::GeomObjPtr> points = getSelected(TopAbs_VERTEX, -1);
355 GEOMBase::Synchronize(myPoints, points);
356 if (!myPoints.isEmpty())
357 myGroupPoints->LineEdit1->setText(QString::number(myPoints.count()) + "_" +
358 tr("GEOM_POINT") + tr("_S_"));
361 QList<GEOM::GeomObjPtr> vecs = getSelected(TopAbs_EDGE, -1);
362 if (vecs.count() != 1) {
363 if (myEditCurrentArgument == myLineEditV1) myVec1.nullify();
364 else if (myEditCurrentArgument == myLineEditV2) myVec2.nullify();
367 if (myEditCurrentArgument == myLineEditV1) {
368 myVec1 = vecs.first();
370 else if (myEditCurrentArgument == myLineEditV2) {
371 myVec2 = vecs.first();
373 QString aName = GEOMBase::GetName(vecs.first().get());
374 myEditCurrentArgument->setText(aName);
381 //=================================================================================
382 // function : ActivateThisDialog()
384 //=================================================================================
385 void BasicGUI_CurveDlg::ActivateThisDialog()
387 GEOMBase_Skeleton::ActivateThisDialog();
389 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
390 this, SLOT(SelectionIntoArgument()));
392 ConstructorsClicked(getConstructorId());
395 //=================================================================================
396 // function : DeactivateActiveDialog()
397 // purpose : public slot to deactivate if active
398 //=================================================================================
399 void BasicGUI_CurveDlg::DeactivateActiveDialog()
401 // myGeomGUI->SetState( -1 );
402 GEOMBase_Skeleton::DeactivateActiveDialog();
405 //=================================================================================
406 // function : enterEvent()
408 //=================================================================================
409 void BasicGUI_CurveDlg::enterEvent (QEvent*)
411 if (!mainFrame()->GroupConstructors->isEnabled())
412 ActivateThisDialog();
415 //=================================================================================
416 // function : createOperation
418 //=================================================================================
419 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
421 return myGeomGUI->GetGeomGen()->GetICurvesOperations();
424 //=================================================================================
425 // function : isValid
427 //=================================================================================
428 bool BasicGUI_CurveDlg::isValid (QString& msg)
430 if (myBySelectionBtn->isChecked()) {
432 if (getConstructorId() == 2) { // Interpolation
433 bool disableTangents = (myGroupPoints->CheckButton1->isChecked() ||
434 myGroupPoints->CheckButton2->isChecked());
435 if (!disableTangents && myGroupTangents->isChecked()) {
436 ok = (myVec1 && myVec2);
437 if (!ok) msg = tr("GEOM_BOTH_TANGENTS_REQUIRED");
440 return ok && myPoints.count() > 1;
443 bool ok = myGroupParams->myPMin->isValid( msg, !IsPreview() ) &&
444 myGroupParams->myPMax->isValid( msg, !IsPreview() ) &&
445 myGroupParams->myPStep->isValid( msg, !IsPreview() );
446 ok &= !myGroupParams->myXExpr->text().isEmpty();
447 ok &= !myGroupParams->myYExpr->text().isEmpty();
448 ok &= !myGroupParams->myZExpr->text().isEmpty();
453 //=================================================================================
454 // function : execute
456 //=================================================================================
457 bool BasicGUI_CurveDlg::execute (ObjectList& objects)
461 GEOM::GEOM_Object_var anObj;
463 GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
465 GEOM::ListOfGO_var points = new GEOM::ListOfGO();
466 points->length(myPoints.count());
467 for (int i = 0; i < myPoints.count(); i++)
468 points[i] = myPoints[i].copy();
470 switch (getConstructorId()) {
472 if (myBySelectionBtn->isChecked())
473 anObj = anOper->MakePolyline(points.in(), myGroupPoints->CheckButton1->isChecked());
475 anObj = anOper->MakeCurveParametricNew(qUtf8Printable(myGroupParams->myXExpr->text()),
476 qUtf8Printable(myGroupParams->myYExpr->text()),
477 qUtf8Printable(myGroupParams->myZExpr->text()),
478 myGroupParams->myPMin->value(),
479 myGroupParams->myPMax->value(),
480 myGroupParams->myPStep->value(),
485 if (myBySelectionBtn->isChecked())
486 anObj = anOper->MakeSplineBezier(points.in(), myGroupPoints->CheckButton1->isChecked());
488 anObj = anOper->MakeCurveParametricNew(qUtf8Printable(myGroupParams->myXExpr->text()),
489 qUtf8Printable(myGroupParams->myYExpr->text()),
490 qUtf8Printable(myGroupParams->myZExpr->text()),
491 myGroupParams->myPMin->value(),
492 myGroupParams->myPMax->value(),
493 myGroupParams->myPStep->value(),
498 if (myBySelectionBtn->isChecked()) {
499 bool disableTangents = (myGroupPoints->CheckButton1->isChecked() ||
500 myGroupPoints->CheckButton2->isChecked());
501 if (!disableTangents && myGroupTangents->isChecked()) {
502 anObj = anOper->MakeSplineInterpolWithTangents(points.in(), myVec1.get(), myVec2.get());
505 anObj = anOper->MakeSplineInterpolation(points.in(), myGroupPoints->CheckButton1->isChecked(),
506 myGroupPoints->CheckButton2->isChecked());
509 anObj = anOper->MakeCurveParametricNew(qUtf8Printable(myGroupParams->myXExpr->text()),
510 qUtf8Printable(myGroupParams->myYExpr->text()),
511 qUtf8Printable(myGroupParams->myZExpr->text()),
512 myGroupParams->myPMin->value(),
513 myGroupParams->myPMax->value(),
514 myGroupParams->myPStep->value(),
515 GEOM::Interpolation);
520 if (!anObj->_is_nil()) {
521 if (myAnaliticalBtn->isChecked() && !IsPreview()) {
522 QStringList aParameters;
523 aParameters<<myGroupParams->myPMin->text();
524 aParameters<<myGroupParams->myPMax->text();
525 aParameters<<myGroupParams->myPStep->text();
526 anObj->SetParameters(aParameters.join(":").toUtf8().constData());
528 objects.push_back(anObj._retn());
534 //=================================================================================
535 // function : addSubshapesToStudy
536 // purpose : virtual method to add new SubObjects if local selection
537 //=================================================================================
538 void BasicGUI_CurveDlg::addSubshapesToStudy()
540 for ( int i = 0; i < myPoints.count(); i++ )
541 GEOMBase::PublishSubObject( myPoints[i].get() );
544 //=================================================================================
545 // function : getSourceObjects
546 // purpose : virtual method to get source objects
547 //=================================================================================
548 QList<GEOM::GeomObjPtr> BasicGUI_CurveDlg::getSourceObjects()
552 //=================================================================================
553 // function : CreationModeChanged
555 //=================================================================================
556 void BasicGUI_CurveDlg::CreationModeChanged()
558 const QObject* s = sender();
559 myGroupPoints->setVisible(myBySelectionBtn == s);
560 myGroupParams->setVisible(myBySelectionBtn != s);
562 ConstructorsClicked(getConstructorId());
565 //=================================================================================
566 // function : ValueChangedInSpinBox()
568 //=================================================================================
569 void BasicGUI_CurveDlg::ValueChangedInSpinBox (double/*theValue*/)
574 //=================================================================================
575 // function : ValueChangedInSpinBox()
577 //=================================================================================
578 void BasicGUI_CurveDlg::ValueChangedInSpinBox (int/*theValue*/)
583 //=================================================================================
584 // function : OnEditingFinished()
586 //=================================================================================
587 void BasicGUI_CurveDlg::OnEditingFinished()