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_RotationDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "TransformationGUI_RotationDlg.h"
29 #include <GeometryGUI.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>
39 #include <TopoDS_Edge.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
45 #include <GEOMImpl_Types.hxx>
47 //=================================================================================
48 // class : TransformationGUI_RotationDlg()
49 // purpose : Constructs a TransformationGUI_RotationDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 TransformationGUI_RotationDlg::TransformationGUI_RotationDlg
55 (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl)
56 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
59 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
60 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_ROTATION")));
61 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
62 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_ROTATION_THREE_POINTS")));
64 setWindowTitle(tr("GEOM_ROTATION_TITLE"));
66 /***************************************************************/
67 mainFrame()->GroupConstructors->setTitle(tr("GEOM_ROTATION"));
68 mainFrame()->RadioButton1->setIcon(image0);
69 mainFrame()->RadioButton2->setIcon(image2);
70 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
71 mainFrame()->RadioButton3->close();
73 GroupPoints = new DlgRef_4Sel1Spin2Check(centralWidget());
74 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
75 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
76 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
77 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
78 GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg(1));
79 GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg(2));
81 GroupPoints->LineEdit1->setReadOnly(true);
82 GroupPoints->LineEdit2->setReadOnly(true);
83 GroupPoints->LineEdit4->setReadOnly(true);
84 GroupPoints->LineEdit5->setReadOnly(true);
85 GroupPoints->PushButton1->setIcon(image1);
86 GroupPoints->PushButton2->setIcon(image1);
87 GroupPoints->PushButton4->setIcon(image1);
88 GroupPoints->PushButton5->setIcon(image1);
89 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
90 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
92 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
93 layout->setMargin(0); layout->setSpacing(6);
94 layout->addWidget(GroupPoints);
95 /***************************************************************/
97 setHelpFileName("rotation_operation_page.html");
99 // Activate Create a Copy mode
100 GroupPoints->CheckButton1->setChecked(true);
101 CreateCopyModeChanged(true);
106 //=================================================================================
107 // function : ~TransformationGUI_RotationDlg()
108 // purpose : Destroys the object and frees any allocated resources
109 //=================================================================================
110 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
112 // no need to delete child widgets, Qt does it all for us
115 //=================================================================================
118 //=================================================================================
119 void TransformationGUI_RotationDlg::Init()
122 double SpecificStep = 5;
124 // min, max, step and decimals for spin boxes & initial values
125 initSpinBox(GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, SpecificStep, 3); // VSR: TODO: DBL_DIGITS_DISPLAY
126 GroupPoints->SpinBox_DX->setValue(anAngle);
129 GroupPoints->LineEdit1->setText("");
130 GroupPoints->LineEdit2->setText("");
131 GroupPoints->LineEdit4->setText("");
132 GroupPoints->LineEdit5->setText("");
134 myAxis = myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
136 mainFrame()->GroupBoxPublish->show();
138 // signals and slots connections
139 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
140 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
142 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
144 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147 connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
150 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
152 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
154 connect(GroupPoints->SpinBox_DX, SIGNAL(textChanged( const QString& )),
155 this, SLOT(TextValueChangedInSpinBox( const QString&)));
157 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
158 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
160 initName(tr("GEOM_ROTATION"));
162 ConstructorsClicked(0);
165 //=================================================================================
166 // function : ConstructorsClicked()
167 // purpose : Radio button management
168 //=================================================================================
169 void TransformationGUI_RotationDlg::ConstructorsClicked (int constructorId)
171 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
173 switch (constructorId) {
174 case 0: // rotation an object angle and axis
176 GroupPoints->ShowRows(2, 3, false);
177 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
178 GroupPoints->LineEdit2->clear();
179 GroupPoints->ShowRows(4, 4, true);
181 myAxis = GEOM::GEOM_Object::_nil();
183 GroupPoints->PushButton1->click();
186 case 1: // rotation an object by 3 points
188 GroupPoints->ShowRows(4, 4, false);
189 GroupPoints->ShowRows(2, 3, true);
190 GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
191 GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg(1));
192 GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg(2));
194 GroupPoints->LineEdit2->clear();
195 GroupPoints->LineEdit4->clear();
196 GroupPoints->LineEdit5->clear();
198 myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
200 GroupPoints->PushButton1->click();
205 qApp->processEvents();
207 resize(minimumSizeHint());
211 SelectionIntoArgument();
218 //=================================================================================
219 // function : ClickOnOk()
221 //=================================================================================
222 void TransformationGUI_RotationDlg::ClickOnOk()
228 //=================================================================================
229 // function : ClickOnApply()
231 //=================================================================================
232 bool TransformationGUI_RotationDlg::ClickOnApply()
234 if (!onAccept(GroupPoints->CheckButton1->isChecked()))
238 // activate selection and connect selection manager
239 ConstructorsClicked(getConstructorId());
243 //=================================================================================
244 // function : SelectionIntoArgument()
245 // purpose : Called when selection is changed or on dialog initialization or activation
246 //=================================================================================
247 void TransformationGUI_RotationDlg::SelectionIntoArgument()
250 myEditCurrentArgument->setText("");
252 if (myEditCurrentArgument == GroupPoints->LineEdit1)
254 else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
255 myAxis = GEOM::GEOM_Object::_nil();
256 else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
257 myCentPoint = GEOM::GEOM_Object::_nil();
258 else if (myEditCurrentArgument == GroupPoints->LineEdit4)
259 myPoint1 = GEOM::GEOM_Object::_nil();
260 else if (myEditCurrentArgument == GroupPoints->LineEdit5)
261 myPoint2 = GEOM::GEOM_Object::_nil();
263 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
264 SALOME_ListIO aSelList;
265 aSelMgr->selectedObjects(aSelList);
269 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
270 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName);
274 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myObjects);
275 if (!myObjects.length())
278 myEditCurrentArgument->setText(aName);
281 if (aSelList.Extent() != 1)
285 Standard_Boolean testResult = Standard_False;
286 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
288 if (!testResult || CORBA::is_nil(aSelectedObject))
291 aName = GEOMBase::GetName(aSelectedObject);
293 // Get Selected object if selected subshape
295 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
297 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
298 if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
299 aNeedType = TopAbs_EDGE;
301 TColStd_IndexedMapOfInteger aMap;
302 aSelMgr->GetIndexes(aSelList.First(), aMap);
303 if (aMap.Extent() == 1)
305 int anIndex = aMap(1);
306 if (aNeedType == TopAbs_EDGE)
307 aName += QString(":edge_%1").arg(anIndex);
309 aName += QString(":vertex_%1").arg(anIndex);
311 //Find SubShape Object in Father
312 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
314 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
315 GEOM::GEOM_IShapesOperations_var aShapesOp =
316 getGeomEngine()->GetIShapesOperations(getStudyId());
317 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
320 aSelectedObject = aFindedObject; // get Object from study
323 else // Global Selection
325 if (aShape.ShapeType() != aNeedType) {
326 aSelectedObject = GEOM::GEOM_Object::_nil();
332 myEditCurrentArgument->setText(aName);
334 if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0) {
335 myAxis = aSelectedObject;
336 if (!myAxis->_is_nil() && !myObjects.length())
337 GroupPoints->PushButton1->click();
339 else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1) {
340 myCentPoint = aSelectedObject;
341 if (!myCentPoint->_is_nil() && myPoint1->_is_nil())
342 GroupPoints->PushButton4->click();
344 else if (myEditCurrentArgument == GroupPoints->LineEdit4) {
345 myPoint1 = aSelectedObject;
346 if (!myPoint1->_is_nil() && myPoint2->_is_nil())
347 GroupPoints->PushButton5->click();
349 else if (myEditCurrentArgument == GroupPoints->LineEdit5) {
350 myPoint2 = aSelectedObject;
351 if (!myPoint2->_is_nil() && !myObjects.length())
352 GroupPoints->PushButton1->click();
357 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
358 myGeomGUI->getApp()->selectionMgr()->clearSelected();
359 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
360 this, SLOT(SelectionIntoArgument()));
365 //=================================================================================
366 // function : SetEditCurrentArgument()
368 //=================================================================================
369 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
371 QPushButton* send = (QPushButton*)sender();
373 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
376 if (send == GroupPoints->PushButton1) {
377 myEditCurrentArgument = GroupPoints->LineEdit1;
379 GroupPoints->PushButton2->setDown(false);
380 GroupPoints->LineEdit2->setEnabled(false);
382 else if (send == GroupPoints->PushButton2) {
383 myEditCurrentArgument = GroupPoints->LineEdit2;
385 GroupPoints->PushButton1->setDown(false);
386 GroupPoints->PushButton4->setDown(false);
387 GroupPoints->PushButton5->setDown(false);
388 GroupPoints->LineEdit1->setEnabled(false);
389 GroupPoints->LineEdit4->setEnabled(false);
390 GroupPoints->LineEdit5->setEnabled(false);
392 if (getConstructorId() == 0)
393 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
395 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
397 else if (send == GroupPoints->PushButton4) {
398 myEditCurrentArgument = GroupPoints->LineEdit4;
400 GroupPoints->PushButton1->setDown(false);
401 GroupPoints->PushButton2->setDown(false);
402 GroupPoints->PushButton5->setDown(false);
403 GroupPoints->LineEdit1->setEnabled(false);
404 GroupPoints->LineEdit2->setEnabled(false);
405 GroupPoints->LineEdit5->setEnabled(false);
407 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
409 else if (send == GroupPoints->PushButton5) {
410 myEditCurrentArgument = GroupPoints->LineEdit5;
412 GroupPoints->PushButton1->setDown(false);
413 GroupPoints->PushButton2->setDown(false);
414 GroupPoints->PushButton4->setDown(false);
415 GroupPoints->LineEdit1->setEnabled(false);
416 GroupPoints->LineEdit2->setEnabled(false);
417 GroupPoints->LineEdit4->setEnabled(false);
419 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
421 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
422 this, SLOT(SelectionIntoArgument()));
425 myEditCurrentArgument->setEnabled(true);
426 myEditCurrentArgument->setFocus();
427 // after setFocus(), because it will be setDown(false) when loses focus
430 // seems we need it only to avoid preview disappearing, caused by selection mode change
434 //=================================================================================
435 // function : LineEditReturnPressed()
437 //=================================================================================
438 void TransformationGUI_RotationDlg::LineEditReturnPressed()
440 QLineEdit* send = (QLineEdit*)sender();
441 if (send == GroupPoints->LineEdit1 ||
442 send == GroupPoints->LineEdit2) {
443 myEditCurrentArgument = send;
444 GEOMBase_Skeleton::LineEditReturnPressed();
448 //=================================================================================
449 // function : ActivateThisDialog()
451 //=================================================================================
452 void TransformationGUI_RotationDlg::ActivateThisDialog()
454 GEOMBase_Skeleton::ActivateThisDialog();
455 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
456 this, SLOT( SelectionIntoArgument() ) );
458 ConstructorsClicked( getConstructorId() );
461 //=================================================================================
462 // function : enterEvent()
464 //=================================================================================
465 void TransformationGUI_RotationDlg::enterEvent (QEvent*)
467 if (!mainFrame()->GroupConstructors->isEnabled())
468 ActivateThisDialog();
471 void TransformationGUI_RotationDlg::TextValueChangedInSpinBox( const QString& s)
474 s.toDouble(&isDigit);
476 GroupPoints->CheckButton2->setChecked(false);
478 GroupPoints->CheckButton2->setEnabled(isDigit);
481 //=================================================================================
482 // function : ValueChangedInSpinBox()
484 //=================================================================================
485 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
490 //=================================================================================
491 // function : createOperation
493 //=================================================================================
494 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
496 return getGeomEngine()->GetITransformOperations(getStudyId());
499 //=================================================================================
500 // function : isValid
502 //=================================================================================
503 bool TransformationGUI_RotationDlg::isValid (QString& msg)
505 switch (getConstructorId()) {
507 bool ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() );
508 return myObjects.length() > 0 && !(myAxis->_is_nil()) && ok;
512 return myObjects.length() > 0 && !(myCentPoint->_is_nil() || myPoint1->_is_nil() || myPoint2->_is_nil());
520 //=================================================================================
521 // function : execute
523 //=================================================================================
524 bool TransformationGUI_RotationDlg::execute (ObjectList& objects)
527 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
529 GEOM::GEOM_Object_var anObj;
531 switch (getConstructorId()) {
534 QStringList aParameters;
535 aParameters<<GroupPoints->SpinBox_DX->text();
537 for (int i = 0; i < myObjects.length(); i++) {
538 myCurrObject = myObjects[i];
539 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
540 RotateCopy(myObjects[i], myAxis, GetAngle() * PI180);
541 if (!anObj->_is_nil()) {
543 anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters));
545 objects.push_back(anObj._retn());
550 for (int i = 0; i < myObjects.length(); i++) {
551 myCurrObject = myObjects[i];
552 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
553 Rotate(myObjects[i], myAxis, GetAngle() * PI180);
554 if (!anObj->_is_nil()) {
556 anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters));
557 updateAttributes(anObj, aParameters);
559 objects.push_back(anObj._retn());
569 for (int i = 0; i < myObjects.length(); i++) {
570 myCurrObject = myObjects[i];
571 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
572 RotateThreePointsCopy(myObjects[i], myCentPoint, myPoint1, myPoint2);
573 if (!anObj->_is_nil())
574 objects.push_back(anObj._retn());
578 for (int i = 0; i < myObjects.length(); i++) {
579 myCurrObject = myObjects[i];
580 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
581 RotateThreePoints(myObjects[i], myCentPoint, myPoint1, myPoint2);
582 if (!anObj->_is_nil())
583 objects.push_back(anObj._retn());
594 //=================================================================================
595 // function : restoreSubShapes
597 //=================================================================================
598 void TransformationGUI_RotationDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
599 SALOMEDS::SObject_ptr theSObject)
601 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
602 // we pass here the first operation argument (object) through the list of arguments
603 // because the rotation operation place its arguments in the data structure in another order,
604 // and we need to point the first argument directly
605 GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
607 anArgs[0] = myCurrObject;
608 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
609 /*theFindMethod=*/GEOM::FSM_Transformed,
610 /*theInheritFirstArg=*/true);
614 //=================================================================================
615 // function : GetAngle()
617 //=================================================================================
618 double TransformationGUI_RotationDlg::GetAngle() const
620 return GroupPoints->SpinBox_DX->value();
623 //=================================================================================
624 // function : CreateCopyModeChanged()
626 //=================================================================================
627 void TransformationGUI_RotationDlg::CreateCopyModeChanged (bool isCreateCopy)
629 mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
632 //=================================================================================
633 // function : onReverse()
635 //=================================================================================
636 void TransformationGUI_RotationDlg::onReverse()
638 double anOldValue = GroupPoints->SpinBox_DX->value();
639 GroupPoints->SpinBox_DX->setValue(-anOldValue);
642 //=================================================================================
643 // function : addSubshapesToStudy
644 // purpose : virtual method to add new SubObjects if local selection
645 //=================================================================================
646 void TransformationGUI_RotationDlg::addSubshapesToStudy()
648 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
650 QMap<QString, GEOM::GEOM_Object_var> objMap;
651 switch (getConstructorId()) {
653 objMap[GroupPoints->LineEdit2->text()] = myAxis;
656 objMap[GroupPoints->LineEdit2->text()] = myCentPoint;
657 objMap[GroupPoints->LineEdit4->text()] = myPoint1;
658 objMap[GroupPoints->LineEdit5->text()] = myPoint2;
661 addSubshapesToFather(objMap);