1 // Copyright (C) 2007-2008 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : TransformationGUI_ScaleDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "TransformationGUI_ScaleDlg.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
35 #include <TopoDS_Shape.hxx>
38 #include <TColStd_IndexedMapOfInteger.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
41 #include "DlgRef_SpinBox.h"
44 #include <qcheckbox.h>
46 #include "GEOMImpl_Types.hxx"
48 #include "utilities.h"
52 //=================================================================================
53 // class : TransformationGUI_ScaleDlg()
54 // purpose : Constructs a TransformationGUI_ScaleDlg 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 TransformationGUI_ScaleDlg::TransformationGUI_ScaleDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
60 const char* name, bool modal, WFlags fl)
61 : GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
62 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
64 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
65 QPixmap image1 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_SCALE")));
66 QPixmap image2 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_SCALE_ALONG_AXES")));
67 QPixmap image3 (aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
69 setCaption(tr("GEOM_SCALE_TITLE"));
72 GroupConstructors->setTitle(tr("GEOM_SCALE"));
73 RadioButton1->setPixmap(image1);
74 RadioButton2->setPixmap(image2);
75 RadioButton3->close(TRUE);
78 GroupBox1 = new QGroupBox (this, "GroupBox1");
79 GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
80 GroupBox1->setColumnLayout(0, Qt::Vertical);
81 GroupBox1->layout()->setSpacing(6);
82 GroupBox1->layout()->setMargin(11);
84 TextLabel1 = new QLabel (GroupBox1, "TextLabel1");
85 TextLabel1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
86 0, 0, TextLabel1->sizePolicy().hasHeightForWidth()));
88 TextLabel2 = new QLabel (GroupBox1, "TextLabel2");
89 TextLabel2->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
90 0, 0, TextLabel2->sizePolicy().hasHeightForWidth()));
92 PushButton1 = new QPushButton(GroupBox1, "PushButton1");
93 PushButton1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
94 0, 0, PushButton1->sizePolicy().hasHeightForWidth()));
96 PushButton2 = new QPushButton( GroupBox1, "PushButton2" );
97 PushButton2->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
98 0, 0, PushButton2->sizePolicy().hasHeightForWidth()));
100 LineEdit1 = new QLineEdit (GroupBox1, "LineEdit1");
101 LineEdit2 = new QLineEdit (GroupBox1, "LineEdit2");
103 TextLabel3 = new QLabel (GroupBox1, "TextLabel3");
104 TextLabel3->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
105 0, 0, TextLabel3->sizePolicy().hasHeightForWidth()));
107 TextLabel4 = new QLabel (GroupBox1, "TextLabel4");
108 TextLabel4->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
109 0, 0, TextLabel3->sizePolicy().hasHeightForWidth()));
111 TextLabel5 = new QLabel (GroupBox1, "TextLabel5");
112 TextLabel5->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
113 0, 0, TextLabel3->sizePolicy().hasHeightForWidth()));
115 SpinBox_FX = new DlgRef_SpinBox(GroupBox1, "SpinBox_FX");
116 SpinBox_FY = new DlgRef_SpinBox(GroupBox1, "SpinBox_FY");
117 SpinBox_FZ = new DlgRef_SpinBox(GroupBox1, "SpinBox_FZ");
119 CheckBoxCopy = new QCheckBox (GroupBox1, "CheckBoxCopy");
121 QSpacerItem* spacer = new QSpacerItem(0, 316, QSizePolicy::Minimum, QSizePolicy::Expanding);
124 OwnLayout = new QGridLayout (0, 1, 1, 0, 6, "Layout1");
126 OwnLayout->addWidget(TextLabel1, 0, 0);
127 OwnLayout->addWidget(TextLabel2, 1, 0);
129 OwnLayout->addWidget(PushButton1, 0, 1);
130 OwnLayout->addWidget(PushButton2, 1, 1);
132 OwnLayout->addMultiCellWidget(LineEdit1, 0, 0, 2, 3);
133 OwnLayout->addMultiCellWidget(LineEdit2, 1, 1, 2, 3);
135 OwnLayout->addWidget(TextLabel3, 2, 0);
136 OwnLayout->addWidget(TextLabel4, 3, 0);
137 OwnLayout->addWidget(TextLabel5, 4, 0);
139 OwnLayout->addWidget(SpinBox_FX, 2, 2);
140 OwnLayout->addWidget(SpinBox_FY, 3, 2);
141 OwnLayout->addWidget(SpinBox_FZ, 4, 2);
143 OwnLayout->addMultiCellWidget(CheckBoxCopy, 5, 5, 0, 3);
145 OwnLayout->addItem(spacer, 6, 2);
147 GroupBox1Layout = new QGridLayout (GroupBox1->layout());
148 GroupBox1Layout->setAlignment(Qt::AlignTop);
149 GroupBox1Layout->addLayout(OwnLayout, 0, 0);
151 Layout1->addWidget(GroupBox1, 2, 0);
153 // Text and pictures for own widgets
154 TextLabel1->setText(tr("GEOM_OBJECTS"));
155 TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
157 PushButton1->setPixmap(image3);
158 PushButton2->setPixmap(image3);
160 LineEdit1->setReadOnly( true );
161 LineEdit2->setReadOnly( true );
163 TextLabel3->setText(tr("GEOM_SCALE_FACTOR"));
164 TextLabel4->setText(tr("GEOM_SCALE_FACTOR_Y"));
165 TextLabel5->setText(tr("GEOM_SCALE_FACTOR_Z"));
167 // Min, max, step and decimals for spin boxes & initial values
168 double aFactor = 2.0;
169 double SpecificStep = 0.5;
170 SpinBox_FX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
171 SpinBox_FY->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
172 SpinBox_FZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
173 SpinBox_FX->SetValue(aFactor);
174 SpinBox_FY->SetValue(aFactor);
175 SpinBox_FZ->SetValue(aFactor);
178 setTabOrder(PushButton1, LineEdit1);
179 setTabOrder(LineEdit1, PushButton2);
180 setTabOrder(PushButton2, LineEdit2);
181 setTabOrder(LineEdit2 , SpinBox_FX);
182 setTabOrder(SpinBox_FX, SpinBox_FY);
183 setTabOrder(SpinBox_FY, SpinBox_FZ);
184 setTabOrder(SpinBox_FZ, CheckBoxCopy);
185 setTabOrder(CheckBoxCopy, CheckBoxRestoreSS);
187 // Modification of an existing object by offset is not allowed
188 CheckBoxCopy->hide();
190 // Activate Create a Copy mode
191 CheckBoxCopy->setText(tr("GEOM_CREATE_COPY"));
192 CheckBoxCopy->setChecked(true);
193 CreateCopyModeChanged(true);
195 // Allowed inheritance of children and visual properties by the scaling result
196 GroupBoxPublish->show();
198 // Signals and slots connections
199 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
200 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
201 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
203 connect(PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
204 connect(PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
206 connect(LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
207 connect(LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
209 connect(SpinBox_FX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
210 connect(SpinBox_FY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
211 connect(SpinBox_FZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
213 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), SpinBox_FX, SLOT(SetStep(double)));
214 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), SpinBox_FY, SLOT(SetStep(double)));
215 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), SpinBox_FZ, SLOT(SetStep(double)));
217 connect(CheckBoxCopy, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
219 connect(myGeomGUI->getApp()->selectionMgr(),
220 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
222 setHelpFileName("scale_operation_page.html");
227 //=================================================================================
228 // function : ~TransformationGUI_ScaleDlg()
229 // purpose : Destroys the object and frees any allocated resources
230 //=================================================================================
231 TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg()
233 /* no need to delete child widgets, Qt does it all for us */
236 //=================================================================================
239 //=================================================================================
240 void TransformationGUI_ScaleDlg::Init()
242 myEditCurrentArgument = LineEdit1;
245 myPoint = GEOM::GEOM_Object::_nil();
247 initName(tr("GEOM_SCALE"));
249 ConstructorsClicked(0);
252 //=================================================================================
253 // function : ConstructorsClicked()
254 // purpose : Radio button management
255 //=================================================================================
256 void TransformationGUI_ScaleDlg::ConstructorsClicked(int constructorId)
260 switch (constructorId)
262 case 0: /* translation an object by dx, dy, dz */
263 TextLabel3->setText(tr("GEOM_SCALE_FACTOR"));
270 case 1: /* translation an object by 2 points */
271 TextLabel3->setText(tr("GEOM_SCALE_FACTOR_X"));
282 //qApp->processEvents();
284 //resize(minimumSize());
288 //=================================================================================
289 // function : ClickOnOk()
291 //=================================================================================
292 void TransformationGUI_ScaleDlg::ClickOnOk()
298 //=================================================================================
299 // function : ClickOnApply()
301 //=================================================================================
302 bool TransformationGUI_ScaleDlg::ClickOnApply()
304 if (!onAccept(CheckBoxCopy->isChecked()))
308 initName(tr("GEOM_SCALE"));
312 //=================================================================================
313 // function : SelectionIntoArgument()
314 // purpose : Called when selection as changed or other case
315 //=================================================================================
316 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
319 myEditCurrentArgument->setText("");
322 if (myEditCurrentArgument == LineEdit1)
324 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
330 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
331 if (!myObjects.length())
334 else if (myEditCurrentArgument == LineEdit2)
336 GEOM::GEOM_Object_var aSelectedObject = GEOM::GEOM_Object::_nil();
337 if (IObjectCount() == 1)
339 Standard_Boolean testResult = Standard_False;
340 aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult);
343 aName = GEOMBase::GetName(aSelectedObject);
346 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
348 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
349 TColStd_IndexedMapOfInteger aMap;
350 aSelMgr->GetIndexes(firstIObject(), aMap);
351 if (aMap.Extent() == 1)
353 int anIndex = aMap( 1 );
354 aName += QString(":vertex_%1").arg(anIndex);
356 //Find SubShape Object in Father
357 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
359 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
360 GEOM::GEOM_IShapesOperations_var aShapesOp =
361 getGeomEngine()->GetIShapesOperations( getStudyId() );
362 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
363 aSelMgr->clearSelected();
366 aSelectedObject = aFindedObject; // get Object from study
370 if (aShape.ShapeType() != TopAbs_VERTEX) {
371 aSelectedObject = GEOM::GEOM_Object::_nil();
379 myPoint = aSelectedObject;
382 myEditCurrentArgument->setText(aName);
386 //=================================================================================
387 // function : LineEditReturnPressed()
389 //=================================================================================
390 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
392 QLineEdit* send = (QLineEdit*)sender();
393 if (send == LineEdit1 || send == LineEdit2)
395 myEditCurrentArgument = send;
396 GEOMBase_Skeleton::LineEditReturnPressed();
400 //=================================================================================
401 // function : SetEditCurrentArgument()
403 //=================================================================================
404 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
406 QPushButton* send = (QPushButton*)sender();
409 if (send == PushButton1) {
410 myEditCurrentArgument = LineEdit1;
412 else if (send == PushButton2) {
413 myEditCurrentArgument = LineEdit2;
414 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
417 myEditCurrentArgument->setFocus();
418 SelectionIntoArgument();
421 //=================================================================================
422 // function : ActivateThisDialog()
424 //=================================================================================
425 void TransformationGUI_ScaleDlg::ActivateThisDialog()
427 GEOMBase_Skeleton::ActivateThisDialog();
428 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
429 this, SLOT(SelectionIntoArgument()));
432 myEditCurrentArgument->setFocus();
433 if (myEditCurrentArgument == LineEdit2) {
434 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
438 //=================================================================================
439 // function : enterEvent()
441 //=================================================================================
442 void TransformationGUI_ScaleDlg::enterEvent (QEvent* e)
444 if (!GroupConstructors->isEnabled())
445 ActivateThisDialog();
448 //=================================================================================
449 // function : ValueChangedInSpinBox()
451 //=================================================================================
452 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox()
457 //=================================================================================
458 // function : createOperation
460 //=================================================================================
461 GEOM::GEOM_IOperations_ptr TransformationGUI_ScaleDlg::createOperation()
463 return myGeomGUI->GetGeomGen()->GetITransformOperations(getStudyId());
466 //=================================================================================
467 // function : isValid
469 //=================================================================================
470 bool TransformationGUI_ScaleDlg::isValid (QString& msg)
472 if (myObjects.length() > 0 && fabs(SpinBox_FX->GetValue()) > 0.00001)
474 // && !myPoint->_is_nil()
475 if (getConstructorId() == 0)
477 if (fabs(SpinBox_FY->GetValue()) > 0.00001 &&
478 fabs(SpinBox_FZ->GetValue()) > 0.00001)
484 //=================================================================================
485 // function : execute
487 //=================================================================================
488 bool TransformationGUI_ScaleDlg::execute (ObjectList& objects)
491 bool toCreateCopy = IsPreview() || CheckBoxCopy->isChecked();
493 GEOM::GEOM_Object_var anObj;
495 switch (getConstructorId())
501 for (int i = 0; i < myObjects.length(); i++)
503 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
504 ScaleShapeCopy(myObjects[i], myPoint, SpinBox_FX->GetValue());
505 if (!anObj->_is_nil())
506 objects.push_back(anObj._retn());
511 for (int i = 0; i < myObjects.length(); i++)
513 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
514 ScaleShape(myObjects[i], myPoint, SpinBox_FX->GetValue());
515 if (!anObj->_is_nil())
516 objects.push_back(anObj._retn());
525 for (int i = 0; i < myObjects.length(); i++)
527 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
528 ScaleShapeAlongAxesCopy(myObjects[i], myPoint, SpinBox_FX->GetValue(),
529 SpinBox_FY->GetValue(), SpinBox_FZ->GetValue());
530 if (!anObj->_is_nil())
531 objects.push_back(anObj._retn());
536 for (int i = 0; i < myObjects.length(); i++)
538 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
539 ScaleShapeAlongAxes(myObjects[i], myPoint, SpinBox_FX->GetValue(),
540 SpinBox_FY->GetValue(), SpinBox_FZ->GetValue());
541 if (!anObj->_is_nil())
542 objects.push_back(anObj._retn());
555 //=================================================================================
556 // function : restoreSubShapes
558 //=================================================================================
559 void TransformationGUI_ScaleDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
560 SALOMEDS::SObject_ptr theSObject)
562 if (CheckBoxRestoreSS->isChecked()) {
563 // empty list of arguments means that all arguments should be restored
564 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
565 /*theFindMethod=*/GEOM::FSM_Transformed,
566 /*theInheritFirstArg=*/true);
570 //=================================================================================
571 // function : CreateCopyModeChanged()
573 //=================================================================================
574 void TransformationGUI_ScaleDlg::CreateCopyModeChanged (bool isCreateCopy)
576 GroupBoxName->setEnabled(isCreateCopy);
579 //=================================================================================
580 // function : addSubshapesToStudy
581 // purpose : virtual method to add new SubObjects if local selection
582 //=================================================================================
583 void TransformationGUI_ScaleDlg::addSubshapesToStudy()
585 bool toCreateCopy = IsPreview() || CheckBoxCopy->isChecked();
588 if (!myPoint->_is_nil())
590 QMap<QString, GEOM::GEOM_Object_var> objMap;
591 objMap[LineEdit2->text()] = myPoint;
592 addSubshapesToFather(objMap);