1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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
22 // File : TransformationGUI_ScaleDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25 #include "TransformationGUI_ScaleDlg.h"
28 #include <GeometryGUI.h>
31 #include <QtxDoubleSpinBox.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
38 #include <TopoDS_Shape.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <GEOMImpl_Types.hxx>
46 //=================================================================================
47 // class : TransformationGUI_ScaleDlg()
48 // purpose : Constructs a TransformationGUI_ScaleDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 TransformationGUI_ScaleDlg::TransformationGUI_ScaleDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
54 bool modal, Qt::WindowFlags fl)
55 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
58 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
59 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_SCALE")));
60 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_SCALE_ALONG_AXES")));
61 QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
63 setWindowTitle(tr("GEOM_SCALE_TITLE"));
66 mainFrame()->GroupConstructors->setTitle(tr("GEOM_SCALE"));
67 mainFrame()->RadioButton1->setIcon(image1);
68 mainFrame()->RadioButton2->setIcon(image2);
69 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
70 mainFrame()->RadioButton3->close();
73 GroupBox1 = new QGroupBox(tr("GEOM_ARGUMENTS"), this);
74 QGridLayout* OwnLayout = new QGridLayout(GroupBox1);
75 OwnLayout->setSpacing(6);
76 OwnLayout->setMargin(11);
78 TextLabel1 = new QLabel(tr("GEOM_OBJECTS"), GroupBox1);
79 PushButton1 = new QPushButton(GroupBox1);
80 PushButton1->setIcon(image3);
81 PushButton1->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
82 LineEdit1 = new QLineEdit(GroupBox1);
83 LineEdit1->setReadOnly(true);
84 LineEdit1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
86 TextLabel2 = new QLabel(tr("GEOM_CENTRAL_POINT"), GroupBox1);
87 PushButton2 = new QPushButton(GroupBox1);
88 PushButton2->setIcon(image3);
89 PushButton2->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
90 LineEdit2 = new QLineEdit(GroupBox1);
91 LineEdit2->setReadOnly(true);
92 LineEdit2->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
94 TextLabel3 = new QLabel(tr("GEOM_SCALE_FACTOR"), GroupBox1);
95 SpinBox_FX = new QtxDoubleSpinBox(GroupBox1);
97 TextLabel4 = new QLabel(tr("GEOM_SCALE_FACTOR_Y"), GroupBox1);
98 SpinBox_FY = new QtxDoubleSpinBox(GroupBox1);
100 TextLabel5 = new QLabel(tr("GEOM_SCALE_FACTOR_Z"), GroupBox1);
101 SpinBox_FZ = new QtxDoubleSpinBox(GroupBox1);
103 CheckBoxCopy = new QCheckBox(tr("GEOM_CREATE_COPY"), GroupBox1);
104 CheckBoxCopy->setChecked(true);
107 OwnLayout->addWidget(TextLabel1, 0, 0);
108 OwnLayout->addWidget(PushButton1, 0, 1);
109 OwnLayout->addWidget(LineEdit1, 0, 2, 1, 2);
110 OwnLayout->addWidget(TextLabel2, 1, 0);
111 OwnLayout->addWidget(PushButton2, 1, 1);
112 OwnLayout->addWidget(LineEdit2, 1, 2, 1, 2);
113 OwnLayout->addWidget(TextLabel3, 2, 0);
114 OwnLayout->addWidget(SpinBox_FX, 2, 2);
115 OwnLayout->addWidget(TextLabel4, 3, 0);
116 OwnLayout->addWidget(SpinBox_FY, 3, 2);
117 OwnLayout->addWidget(TextLabel5, 4, 0);
118 OwnLayout->addWidget(SpinBox_FZ, 4, 2);
119 OwnLayout->addWidget(CheckBoxCopy, 5, 0, 1, 4);
121 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
122 layout->setMargin(0); layout->setSpacing(6);
123 layout->addWidget(GroupBox1);
125 setHelpFileName("scale_operation_page.html");
127 // Modification of an existing object by offset is not allowed
128 CheckBoxCopy->hide();
130 // Activate Create a Copy mode
131 CreateCopyModeChanged(true);
133 // Allowed inheritance of children and visual properties by the scaling result
134 mainFrame()->GroupBoxPublish->show();
139 //=================================================================================
140 // function : ~TransformationGUI_ScaleDlg()
141 // purpose : Destroys the object and frees any allocated resources
142 //=================================================================================
143 TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg()
147 //=================================================================================
150 //=================================================================================
151 void TransformationGUI_ScaleDlg::Init()
153 // Min, max, step and decimals for spin boxes & initial values
154 double aFactor = 2.0;
155 double SpecificStep = 0.5;
157 initSpinBox(SpinBox_FX, COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
158 initSpinBox(SpinBox_FY, COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
159 initSpinBox(SpinBox_FZ, COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
160 SpinBox_FX->setValue(aFactor);
161 SpinBox_FY->setValue(aFactor);
162 SpinBox_FZ->setValue(aFactor);
165 LineEdit1->setText("");
166 LineEdit2->setText("");
168 myPoint = GEOM::GEOM_Object::_nil();
170 // Signals and slots connections
171 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
172 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
173 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
175 connect(PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
176 connect(PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
178 connect(LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
179 connect(LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
181 connect(SpinBox_FX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
182 connect(SpinBox_FY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
183 connect(SpinBox_FZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
185 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
187 connect(CheckBoxCopy, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
189 initName(tr("GEOM_SCALE"));
191 ConstructorsClicked(0);
194 //=================================================================================
195 // function : ConstructorsClicked()
196 // purpose : Radio button management
197 //=================================================================================
198 void TransformationGUI_ScaleDlg::ConstructorsClicked (int constructorId)
200 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
202 switch (constructorId) {
203 case 0: // translation an object by dx, dy, dz
204 TextLabel3->setText(tr("GEOM_SCALE_FACTOR"));
210 PushButton1->click();
212 case 1: // translation an object by 2 points
213 TextLabel3->setText(tr("GEOM_SCALE_FACTOR_X"));
219 PushButton1->click();
225 qApp->processEvents();
227 resize(minimumSize());
231 SelectionIntoArgument();
238 //=================================================================================
239 // function : ClickOnOk()
241 //=================================================================================
242 void TransformationGUI_ScaleDlg::ClickOnOk()
248 //=================================================================================
249 // function : ClickOnApply()
251 //=================================================================================
252 bool TransformationGUI_ScaleDlg::ClickOnApply()
254 if (!onAccept(CheckBoxCopy->isChecked()))
257 initName(tr("GEOM_SCALE"));
258 // activate selection and connect selection manager
259 ConstructorsClicked(getConstructorId());
263 //=================================================================================
264 // function : SelectionIntoArgument()
265 // purpose : Called when selection is changed or on dialog initialization or activation
266 //=================================================================================
267 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
270 myEditCurrentArgument->setText("");
272 if (myEditCurrentArgument == LineEdit1)
274 else if (myEditCurrentArgument == LineEdit2)
275 myPoint = GEOM::GEOM_Object::_nil();
277 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
278 SALOME_ListIO aSelList;
279 aSelMgr->selectedObjects(aSelList);
283 if (myEditCurrentArgument == LineEdit1)
285 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName);
289 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myObjects);
290 if (!myObjects.length())
293 myEditCurrentArgument->setText(aName);
295 else if (myEditCurrentArgument == LineEdit2)
297 GEOM::GEOM_Object_var aSelectedObject = GEOM::GEOM_Object::_nil();
298 if (aSelList.Extent() == 1)
300 Standard_Boolean testResult = Standard_False;
301 aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
304 aName = GEOMBase::GetName(aSelectedObject);
307 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
309 TColStd_IndexedMapOfInteger aMap;
310 aSelMgr->GetIndexes(aSelList.First(), aMap);
311 if (aMap.Extent() == 1)
313 int anIndex = aMap(1);
314 aName += QString(":vertex_%1").arg(anIndex);
316 //Find SubShape Object in Father
317 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
319 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
320 GEOM::GEOM_IShapesOperations_var aShapesOp =
321 getGeomEngine()->GetIShapesOperations(getStudyId());
322 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
325 aSelectedObject = aFindedObject; // get Object from study
327 else // Global Selection
329 if (aShape.ShapeType() != TopAbs_VERTEX) {
330 aSelectedObject = GEOM::GEOM_Object::_nil();
338 myPoint = aSelectedObject;
339 myEditCurrentArgument->setText(aName);
341 if (!myPoint->_is_nil() && !myObjects.length())
342 PushButton1->click();
346 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
347 myGeomGUI->getApp()->selectionMgr()->clearSelected();
348 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
349 this, SLOT(SelectionIntoArgument()));
354 //=================================================================================
355 // function : SetEditCurrentArgument()
357 //=================================================================================
358 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
360 QPushButton* send = (QPushButton*)sender();
362 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
365 if (send == PushButton1) {
366 myEditCurrentArgument = LineEdit1;
368 PushButton2->setDown(false);
369 LineEdit2->setEnabled(false);
371 else if (send == PushButton2) {
372 myEditCurrentArgument = LineEdit2;
374 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
376 PushButton1->setDown(false);
377 LineEdit1->setEnabled(false);
379 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
380 this, SLOT(SelectionIntoArgument()));
383 myEditCurrentArgument->setEnabled(true);
384 myEditCurrentArgument->setFocus();
385 // after setFocus(), because it will be setDown(false) when loses focus
388 // seems we need it only to avoid preview disappearing, caused by selection mode change
392 //=================================================================================
393 // function : LineEditReturnPressed()
395 //=================================================================================
396 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
398 QLineEdit* send = (QLineEdit*)sender();
399 if (send == LineEdit1 || send == LineEdit2)
401 myEditCurrentArgument = send;
402 GEOMBase_Skeleton::LineEditReturnPressed();
406 //=================================================================================
407 // function : ActivateThisDialog()
409 //=================================================================================
410 void TransformationGUI_ScaleDlg::ActivateThisDialog()
412 GEOMBase_Skeleton::ActivateThisDialog();
413 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
414 this, SLOT( SelectionIntoArgument() ) );
416 ConstructorsClicked( getConstructorId() );
419 //=================================================================================
420 // function : enterEvent()
422 //=================================================================================
423 void TransformationGUI_ScaleDlg::enterEvent (QEvent*)
425 if (!mainFrame()->GroupConstructors->isEnabled())
426 ActivateThisDialog();
429 //=================================================================================
430 // function : ValueChangedInSpinBox()
432 //=================================================================================
433 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox()
438 //=================================================================================
439 // function : SetDoubleSpinBoxStep()
440 // purpose : Double spin box management
441 //=================================================================================
442 void TransformationGUI_ScaleDlg::SetDoubleSpinBoxStep(double step)
444 SpinBox_FX->setSingleStep(step);
445 SpinBox_FY->setSingleStep(step);
446 SpinBox_FZ->setSingleStep(step);
449 //=================================================================================
450 // function : createOperation
452 //=================================================================================
453 GEOM::GEOM_IOperations_ptr TransformationGUI_ScaleDlg::createOperation()
455 return getGeomEngine()->GetITransformOperations(getStudyId());
458 //=================================================================================
459 // function : isValid
461 //=================================================================================
462 bool TransformationGUI_ScaleDlg::isValid (QString& /*msg*/)
464 if (myObjects.length() > 0 && fabs(SpinBox_FX->value()) > 0.00001)
466 // && !myPoint->_is_nil()
467 if (getConstructorId() == 0)
469 if (fabs(SpinBox_FY->value()) > 0.00001 &&
470 fabs(SpinBox_FZ->value()) > 0.00001)
476 //=================================================================================
477 // function : execute
479 //=================================================================================
480 bool TransformationGUI_ScaleDlg::execute (ObjectList& objects)
482 bool toCreateCopy = IsPreview() || CheckBoxCopy->isChecked();
484 GEOM::GEOM_Object_var anObj;
486 switch (getConstructorId())
492 for (int i = 0; i < myObjects.length(); i++)
494 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
495 ScaleShapeCopy(myObjects[i], myPoint, SpinBox_FX->value());
496 if (!anObj->_is_nil())
497 objects.push_back(anObj._retn());
502 for (int i = 0; i < myObjects.length(); i++)
504 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
505 ScaleShape(myObjects[i], myPoint, SpinBox_FX->value());
506 if (!anObj->_is_nil())
507 objects.push_back(anObj._retn());
516 for (int i = 0; i < myObjects.length(); i++)
518 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
519 ScaleShapeAlongAxesCopy(myObjects[i], myPoint, SpinBox_FX->value(),
520 SpinBox_FY->value(), SpinBox_FZ->value());
521 if (!anObj->_is_nil())
522 objects.push_back(anObj._retn());
527 for (int i = 0; i < myObjects.length(); i++)
529 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
530 ScaleShapeAlongAxes(myObjects[i], myPoint, SpinBox_FX->value(),
531 SpinBox_FY->value(), SpinBox_FZ->value());
532 if (!anObj->_is_nil())
533 objects.push_back(anObj._retn());
545 //=================================================================================
546 // function : restoreSubShapes
548 //=================================================================================
549 void TransformationGUI_ScaleDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
550 SALOMEDS::SObject_ptr theSObject)
552 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
553 // empty list of arguments means that all arguments should be restored
554 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
555 /*theFindMethod=*/GEOM::FSM_Transformed,
556 /*theInheritFirstArg=*/true);
560 //=================================================================================
561 // function : CreateCopyModeChanged()
563 //=================================================================================
564 void TransformationGUI_ScaleDlg::CreateCopyModeChanged (bool isCreateCopy)
566 mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
569 //=================================================================================
570 // function : addSubshapesToStudy
571 // purpose : virtual method to add new SubObjects if local selection
572 //=================================================================================
573 void TransformationGUI_ScaleDlg::addSubshapesToStudy()
575 bool toCreateCopy = IsPreview() || CheckBoxCopy->isChecked();
578 if (!myPoint->_is_nil())
580 QMap<QString, GEOM::GEOM_Object_var> objMap;
581 objMap[LineEdit2->text()] = myPoint;
582 addSubshapesToFather(objMap);