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
24 // File : TransformationGUI_ScaleDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "TransformationGUI_ScaleDlg.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
36 #include <TopoDS_Shape.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
42 #include "DlgRef_SpinBox.h"
45 #include <qcheckbox.h>
47 #include "GEOMImpl_Types.hxx"
49 #include "utilities.h"
53 //=================================================================================
54 // class : TransformationGUI_ScaleDlg()
55 // purpose : Constructs a TransformationGUI_ScaleDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 TransformationGUI_ScaleDlg::TransformationGUI_ScaleDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
61 const char* name, bool modal, WFlags fl)
62 : GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
63 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
65 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
66 QPixmap image1 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_SCALE")));
67 QPixmap image2 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_SCALE_ALONG_AXES")));
68 QPixmap image3 (aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
70 setCaption(tr("GEOM_SCALE_TITLE"));
73 GroupConstructors->setTitle(tr("GEOM_SCALE"));
74 RadioButton1->setPixmap(image1);
75 RadioButton2->setPixmap(image2);
76 RadioButton3->close(TRUE);
79 GroupBox1 = new QGroupBox (this, "GroupBox1");
80 GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
81 GroupBox1->setColumnLayout(0, Qt::Vertical);
82 GroupBox1->layout()->setSpacing(6);
83 GroupBox1->layout()->setMargin(11);
85 TextLabel1 = new QLabel (GroupBox1, "TextLabel1");
86 TextLabel1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
87 0, 0, TextLabel1->sizePolicy().hasHeightForWidth()));
89 TextLabel2 = new QLabel (GroupBox1, "TextLabel2");
90 TextLabel2->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
91 0, 0, TextLabel2->sizePolicy().hasHeightForWidth()));
93 PushButton1 = new QPushButton(GroupBox1, "PushButton1");
94 PushButton1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
95 0, 0, PushButton1->sizePolicy().hasHeightForWidth()));
97 PushButton2 = new QPushButton( GroupBox1, "PushButton2" );
98 PushButton2->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
99 0, 0, PushButton2->sizePolicy().hasHeightForWidth()));
101 LineEdit1 = new QLineEdit (GroupBox1, "LineEdit1");
102 LineEdit2 = new QLineEdit (GroupBox1, "LineEdit2");
104 TextLabel3 = new QLabel (GroupBox1, "TextLabel3");
105 TextLabel3->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
106 0, 0, TextLabel3->sizePolicy().hasHeightForWidth()));
108 TextLabel4 = new QLabel (GroupBox1, "TextLabel4");
109 TextLabel4->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
110 0, 0, TextLabel3->sizePolicy().hasHeightForWidth()));
112 TextLabel5 = new QLabel (GroupBox1, "TextLabel5");
113 TextLabel5->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
114 0, 0, TextLabel3->sizePolicy().hasHeightForWidth()));
116 SpinBox_FX = new DlgRef_SpinBox(GroupBox1, "SpinBox_FX");
117 SpinBox_FY = new DlgRef_SpinBox(GroupBox1, "SpinBox_FY");
118 SpinBox_FZ = new DlgRef_SpinBox(GroupBox1, "SpinBox_FZ");
120 CheckBoxCopy = new QCheckBox (GroupBox1, "CheckBoxCopy");
122 QSpacerItem* spacer = new QSpacerItem(0, 316, QSizePolicy::Minimum, QSizePolicy::Expanding);
125 OwnLayout = new QGridLayout (0, 1, 1, 0, 6, "Layout1");
127 OwnLayout->addWidget(TextLabel1, 0, 0);
128 OwnLayout->addWidget(TextLabel2, 1, 0);
130 OwnLayout->addWidget(PushButton1, 0, 1);
131 OwnLayout->addWidget(PushButton2, 1, 1);
133 OwnLayout->addMultiCellWidget(LineEdit1, 0, 0, 2, 3);
134 OwnLayout->addMultiCellWidget(LineEdit2, 1, 1, 2, 3);
136 OwnLayout->addWidget(TextLabel3, 2, 0);
137 OwnLayout->addWidget(TextLabel4, 3, 0);
138 OwnLayout->addWidget(TextLabel5, 4, 0);
140 OwnLayout->addWidget(SpinBox_FX, 2, 2);
141 OwnLayout->addWidget(SpinBox_FY, 3, 2);
142 OwnLayout->addWidget(SpinBox_FZ, 4, 2);
144 OwnLayout->addMultiCellWidget(CheckBoxCopy, 5, 5, 0, 3);
146 OwnLayout->addItem(spacer, 6, 2);
148 GroupBox1Layout = new QGridLayout (GroupBox1->layout());
149 GroupBox1Layout->setAlignment(Qt::AlignTop);
150 GroupBox1Layout->addLayout(OwnLayout, 0, 0);
152 Layout1->addWidget(GroupBox1, 2, 0);
154 // Text and pictures for own widgets
155 TextLabel1->setText(tr("GEOM_OBJECTS"));
156 TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
158 PushButton1->setPixmap(image3);
159 PushButton2->setPixmap(image3);
161 LineEdit1->setReadOnly( true );
162 LineEdit2->setReadOnly( true );
164 TextLabel3->setText(tr("GEOM_SCALE_FACTOR"));
165 TextLabel4->setText(tr("GEOM_SCALE_FACTOR_Y"));
166 TextLabel5->setText(tr("GEOM_SCALE_FACTOR_Z"));
168 // Min, max, step and decimals for spin boxes & initial values
169 double aFactor = 2.0;
170 double SpecificStep = 0.5;
171 SpinBox_FX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
172 SpinBox_FY->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
173 SpinBox_FZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
174 SpinBox_FX->SetValue(aFactor);
175 SpinBox_FY->SetValue(aFactor);
176 SpinBox_FZ->SetValue(aFactor);
179 setTabOrder(PushButton1, LineEdit1);
180 setTabOrder(LineEdit1, PushButton2);
181 setTabOrder(PushButton2, LineEdit2);
182 setTabOrder(LineEdit2 , SpinBox_FX);
183 setTabOrder(SpinBox_FX, SpinBox_FY);
184 setTabOrder(SpinBox_FY, SpinBox_FZ);
185 setTabOrder(SpinBox_FZ, CheckBoxCopy);
186 setTabOrder(CheckBoxCopy, CheckBoxRestoreSS);
188 // Modification of an existing object by offset is not allowed
189 CheckBoxCopy->hide();
191 // Activate Create a Copy mode
192 CheckBoxCopy->setText(tr("GEOM_CREATE_COPY"));
193 CheckBoxCopy->setChecked(true);
194 CreateCopyModeChanged(true);
196 // Allowed inheritance of children and visual properties by the scaling result
197 GroupBoxPublish->show();
199 // Signals and slots connections
200 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
201 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
202 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
204 connect(PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
205 connect(PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
207 connect(LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
208 connect(LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
210 connect(SpinBox_FX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
211 connect(SpinBox_FY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
212 connect(SpinBox_FZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
214 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), SpinBox_FX, SLOT(SetStep(double)));
215 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), SpinBox_FY, SLOT(SetStep(double)));
216 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), SpinBox_FZ, SLOT(SetStep(double)));
218 connect(CheckBoxCopy, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
220 connect(myGeomGUI->getApp()->selectionMgr(),
221 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
223 setHelpFileName("scale_operation_page.html");
228 //=================================================================================
229 // function : ~TransformationGUI_ScaleDlg()
230 // purpose : Destroys the object and frees any allocated resources
231 //=================================================================================
232 TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg()
234 /* no need to delete child widgets, Qt does it all for us */
237 //=================================================================================
240 //=================================================================================
241 void TransformationGUI_ScaleDlg::Init()
243 myEditCurrentArgument = LineEdit1;
246 myPoint = GEOM::GEOM_Object::_nil();
248 initName(tr("GEOM_SCALE"));
250 ConstructorsClicked(0);
253 //=================================================================================
254 // function : ConstructorsClicked()
255 // purpose : Radio button management
256 //=================================================================================
257 void TransformationGUI_ScaleDlg::ConstructorsClicked(int constructorId)
261 switch (constructorId)
263 case 0: /* translation an object by dx, dy, dz */
264 TextLabel3->setText(tr("GEOM_SCALE_FACTOR"));
271 case 1: /* translation an object by 2 points */
272 TextLabel3->setText(tr("GEOM_SCALE_FACTOR_X"));
283 //qApp->processEvents();
285 //resize(minimumSize());
289 //=================================================================================
290 // function : ClickOnOk()
292 //=================================================================================
293 void TransformationGUI_ScaleDlg::ClickOnOk()
299 //=================================================================================
300 // function : ClickOnApply()
302 //=================================================================================
303 bool TransformationGUI_ScaleDlg::ClickOnApply()
305 if (!onAccept(CheckBoxCopy->isChecked()))
309 initName(tr("GEOM_SCALE"));
313 //=================================================================================
314 // function : SelectionIntoArgument()
315 // purpose : Called when selection as changed or other case
316 //=================================================================================
317 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
320 myEditCurrentArgument->setText("");
323 if (myEditCurrentArgument == LineEdit1)
325 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
331 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
332 if (!myObjects.length())
335 else if (myEditCurrentArgument == LineEdit2)
337 GEOM::GEOM_Object_var aSelectedObject = GEOM::GEOM_Object::_nil();
338 if (IObjectCount() == 1)
340 Standard_Boolean testResult = Standard_False;
341 aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult);
344 aName = GEOMBase::GetName(aSelectedObject);
347 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
349 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
350 TColStd_IndexedMapOfInteger aMap;
351 aSelMgr->GetIndexes(firstIObject(), aMap);
352 if (aMap.Extent() == 1)
354 int anIndex = aMap( 1 );
355 aName += QString(":vertex_%1").arg(anIndex);
357 //Find SubShape Object in Father
358 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
360 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
361 GEOM::GEOM_IShapesOperations_var aShapesOp =
362 getGeomEngine()->GetIShapesOperations( getStudyId() );
363 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
364 aSelMgr->clearSelected();
367 aSelectedObject = aFindedObject; // get Object from study
371 if (aShape.ShapeType() != TopAbs_VERTEX) {
372 aSelectedObject = GEOM::GEOM_Object::_nil();
380 myPoint = aSelectedObject;
383 myEditCurrentArgument->setText(aName);
387 //=================================================================================
388 // function : LineEditReturnPressed()
390 //=================================================================================
391 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
393 QLineEdit* send = (QLineEdit*)sender();
394 if (send == LineEdit1 || send == LineEdit2)
396 myEditCurrentArgument = send;
397 GEOMBase_Skeleton::LineEditReturnPressed();
401 //=================================================================================
402 // function : SetEditCurrentArgument()
404 //=================================================================================
405 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
407 QPushButton* send = (QPushButton*)sender();
410 if (send == PushButton1) {
411 myEditCurrentArgument = LineEdit1;
413 else if (send == PushButton2) {
414 myEditCurrentArgument = LineEdit2;
415 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
418 myEditCurrentArgument->setFocus();
419 SelectionIntoArgument();
422 //=================================================================================
423 // function : ActivateThisDialog()
425 //=================================================================================
426 void TransformationGUI_ScaleDlg::ActivateThisDialog()
428 GEOMBase_Skeleton::ActivateThisDialog();
429 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
430 this, SLOT(SelectionIntoArgument()));
433 myEditCurrentArgument->setFocus();
434 if (myEditCurrentArgument == LineEdit2) {
435 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
439 //=================================================================================
440 // function : enterEvent()
442 //=================================================================================
443 void TransformationGUI_ScaleDlg::enterEvent (QEvent* e)
445 if (!GroupConstructors->isEnabled())
446 ActivateThisDialog();
449 //=================================================================================
450 // function : ValueChangedInSpinBox()
452 //=================================================================================
453 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox()
458 //=================================================================================
459 // function : createOperation
461 //=================================================================================
462 GEOM::GEOM_IOperations_ptr TransformationGUI_ScaleDlg::createOperation()
464 return myGeomGUI->GetGeomGen()->GetITransformOperations(getStudyId());
467 //=================================================================================
468 // function : isValid
470 //=================================================================================
471 bool TransformationGUI_ScaleDlg::isValid (QString& msg)
473 if (myObjects.length() > 0 && fabs(SpinBox_FX->GetValue()) > 0.00001)
475 // && !myPoint->_is_nil()
476 if (getConstructorId() == 0)
478 if (fabs(SpinBox_FY->GetValue()) > 0.00001 &&
479 fabs(SpinBox_FZ->GetValue()) > 0.00001)
485 //=================================================================================
486 // function : execute
488 //=================================================================================
489 bool TransformationGUI_ScaleDlg::execute (ObjectList& objects)
492 bool toCreateCopy = IsPreview() || CheckBoxCopy->isChecked();
494 GEOM::GEOM_Object_var anObj;
496 switch (getConstructorId())
502 for (int i = 0; i < myObjects.length(); i++)
504 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
505 ScaleShapeCopy(myObjects[i], myPoint, SpinBox_FX->GetValue());
506 if (!anObj->_is_nil())
507 objects.push_back(anObj._retn());
512 for (int i = 0; i < myObjects.length(); i++)
514 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
515 ScaleShape(myObjects[i], myPoint, SpinBox_FX->GetValue());
516 if (!anObj->_is_nil())
517 objects.push_back(anObj._retn());
526 for (int i = 0; i < myObjects.length(); i++)
528 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
529 ScaleShapeAlongAxesCopy(myObjects[i], myPoint, SpinBox_FX->GetValue(),
530 SpinBox_FY->GetValue(), SpinBox_FZ->GetValue());
531 if (!anObj->_is_nil())
532 objects.push_back(anObj._retn());
537 for (int i = 0; i < myObjects.length(); i++)
539 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
540 ScaleShapeAlongAxes(myObjects[i], myPoint, SpinBox_FX->GetValue(),
541 SpinBox_FY->GetValue(), SpinBox_FZ->GetValue());
542 if (!anObj->_is_nil())
543 objects.push_back(anObj._retn());
556 //=================================================================================
557 // function : restoreSubShapes
559 //=================================================================================
560 void TransformationGUI_ScaleDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
561 SALOMEDS::SObject_ptr theSObject)
563 if (CheckBoxRestoreSS->isChecked()) {
564 // empty list of arguments means that all arguments should be restored
565 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
566 /*theFindMethod=*/GEOM::FSM_Transformed,
567 /*theInheritFirstArg=*/true);
571 //=================================================================================
572 // function : CreateCopyModeChanged()
574 //=================================================================================
575 void TransformationGUI_ScaleDlg::CreateCopyModeChanged (bool isCreateCopy)
577 GroupBoxName->setEnabled(isCreateCopy);
580 //=================================================================================
581 // function : addSubshapesToStudy
582 // purpose : virtual method to add new SubObjects if local selection
583 //=================================================================================
584 void TransformationGUI_ScaleDlg::addSubshapesToStudy()
586 bool toCreateCopy = IsPreview() || CheckBoxCopy->isChecked();
589 if (!myPoint->_is_nil())
591 QMap<QString, GEOM::GEOM_Object_var> objMap;
592 objMap[LineEdit2->text()] = myPoint;
593 addSubshapesToFather(objMap);