1 // Copyright (C) 2007-2010 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : TransformationGUI_RotationDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "TransformationGUI_RotationDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Edge.hxx>
43 #include <TColStd_IndexedMapOfInteger.hxx>
44 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <GEOMImpl_Types.hxx>
48 //=================================================================================
49 // class : TransformationGUI_RotationDlg()
50 // purpose : Constructs a TransformationGUI_RotationDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 TransformationGUI_RotationDlg::TransformationGUI_RotationDlg
56 (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl)
57 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
60 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
61 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_ROTATION")));
62 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
63 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_ROTATION_THREE_POINTS")));
65 setWindowTitle(tr("GEOM_ROTATION_TITLE"));
67 /***************************************************************/
68 mainFrame()->GroupConstructors->setTitle(tr("GEOM_ROTATION"));
69 mainFrame()->RadioButton1->setIcon(image0);
70 mainFrame()->RadioButton2->setIcon(image2);
71 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
72 mainFrame()->RadioButton3->close();
74 GroupPoints = new DlgRef_4Sel1Spin2Check(centralWidget());
75 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
76 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
77 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
78 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
79 GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg(1));
80 GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg(2));
82 GroupPoints->LineEdit1->setReadOnly(true);
83 GroupPoints->LineEdit2->setReadOnly(true);
84 GroupPoints->LineEdit4->setReadOnly(true);
85 GroupPoints->LineEdit5->setReadOnly(true);
86 GroupPoints->PushButton1->setIcon(image1);
87 GroupPoints->PushButton2->setIcon(image1);
88 GroupPoints->PushButton4->setIcon(image1);
89 GroupPoints->PushButton5->setIcon(image1);
90 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
91 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
93 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
94 layout->setMargin(0); layout->setSpacing(6);
95 layout->addWidget(GroupPoints);
96 /***************************************************************/
98 setHelpFileName("rotation_operation_page.html");
100 // Activate Create a Copy mode
101 GroupPoints->CheckButton1->setChecked(true);
102 CreateCopyModeChanged(true);
107 //=================================================================================
108 // function : ~TransformationGUI_RotationDlg()
109 // purpose : Destroys the object and frees any allocated resources
110 //=================================================================================
111 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
113 // no need to delete child widgets, Qt does it all for us
116 //=================================================================================
119 //=================================================================================
120 void TransformationGUI_RotationDlg::Init()
123 double SpecificStep = 5;
125 // min, max, step and decimals for spin boxes & initial values
126 initSpinBox(GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, SpecificStep, "angle_precision" );
127 GroupPoints->SpinBox_DX->setValue(anAngle);
130 GroupPoints->LineEdit1->setText("");
131 GroupPoints->LineEdit2->setText("");
132 GroupPoints->LineEdit4->setText("");
133 GroupPoints->LineEdit5->setText("");
135 myAxis = myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
137 mainFrame()->GroupBoxPublish->show();
139 // signals and slots connections
140 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
141 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
143 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
145 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147 connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148 connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
151 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
153 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
155 connect(GroupPoints->SpinBox_DX, SIGNAL(textChanged( const QString& )),
156 this, SLOT(TextValueChangedInSpinBox( const QString&)));
158 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
159 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
161 initName(tr("GEOM_ROTATION"));
163 ConstructorsClicked(0);
166 //=================================================================================
167 // function : ConstructorsClicked()
168 // purpose : Radio button management
169 //=================================================================================
170 void TransformationGUI_RotationDlg::ConstructorsClicked (int constructorId)
172 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
174 switch (constructorId) {
175 case 0: // rotation an object angle and axis
177 GroupPoints->ShowRows(2, 3, false);
178 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
179 GroupPoints->LineEdit2->clear();
180 GroupPoints->ShowRows(4, 4, true);
182 myAxis = GEOM::GEOM_Object::_nil();
184 GroupPoints->PushButton1->click();
187 case 1: // rotation an object by 3 points
189 GroupPoints->ShowRows(4, 4, false);
190 GroupPoints->ShowRows(2, 3, true);
191 GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
192 GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg(1));
193 GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg(2));
195 GroupPoints->LineEdit2->clear();
196 GroupPoints->LineEdit4->clear();
197 GroupPoints->LineEdit5->clear();
199 myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
201 GroupPoints->PushButton1->click();
206 qApp->processEvents();
208 resize(minimumSizeHint());
212 SelectionIntoArgument();
219 //=================================================================================
220 // function : ClickOnOk()
222 //=================================================================================
223 void TransformationGUI_RotationDlg::ClickOnOk()
229 //=================================================================================
230 // function : ClickOnApply()
232 //=================================================================================
233 bool TransformationGUI_RotationDlg::ClickOnApply()
235 if (!onAccept(GroupPoints->CheckButton1->isChecked()))
241 myEditCurrentArgument = GroupPoints->LineEdit1;
242 myEditCurrentArgument->setText("");
243 myGeomGUI->getApp()->selectionMgr()->clearSelected();
245 // activate selection and connect selection manager
246 ConstructorsClicked(getConstructorId());
250 //=================================================================================
251 // function : SelectionIntoArgument()
252 // purpose : Called when selection is changed or on dialog initialization or activation
253 //=================================================================================
254 void TransformationGUI_RotationDlg::SelectionIntoArgument()
257 myEditCurrentArgument->setText("");
259 if (myEditCurrentArgument == GroupPoints->LineEdit1)
261 else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
262 myAxis = GEOM::GEOM_Object::_nil();
263 else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
264 myCentPoint = GEOM::GEOM_Object::_nil();
265 else if (myEditCurrentArgument == GroupPoints->LineEdit4)
266 myPoint1 = GEOM::GEOM_Object::_nil();
267 else if (myEditCurrentArgument == GroupPoints->LineEdit5)
268 myPoint2 = GEOM::GEOM_Object::_nil();
270 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
271 SALOME_ListIO aSelList;
272 aSelMgr->selectedObjects(aSelList);
273 GEOM::GEOM_Object_var aSelectedObject;
277 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
278 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName);
282 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myObjects);
283 if (!myObjects.length())
287 if (aSelList.Extent() != 1)
291 Standard_Boolean testResult = Standard_False;
292 aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
294 if (!testResult || CORBA::is_nil(aSelectedObject))
297 aName = GEOMBase::GetName(aSelectedObject);
299 // Get Selected object if selected subshape
301 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
303 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
304 if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
305 aNeedType = TopAbs_EDGE;
307 TColStd_IndexedMapOfInteger aMap;
308 aSelMgr->GetIndexes(aSelList.First(), aMap);
309 if (aMap.Extent() == 1)
311 int anIndex = aMap(1);
312 if (aNeedType == TopAbs_EDGE)
313 aName += QString(":edge_%1").arg(anIndex);
315 aName += QString(":vertex_%1").arg(anIndex);
317 //Find SubShape Object in Father
318 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
320 if (aFindedObject->_is_nil()) { // Object not found in study
321 GEOM::GEOM_IShapesOperations_var aShapesOp =
322 getGeomEngine()->GetIShapesOperations(getStudyId());
323 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
326 aSelectedObject = aFindedObject; // get Object from study
329 else // Global Selection
331 if (aShape.ShapeType() != aNeedType) {
332 aSelectedObject = GEOM::GEOM_Object::_nil();
339 myEditCurrentArgument->setText(aName);
341 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
342 /* if (myObjects.length()) {
343 if (getConstructorId() == 0 && myAxis->_is_nil() || getConstructorId() == 1 && myCentPoint->_is_nil() )
344 GroupPoints->PushButton2->click();
345 }*/ // here commented, because multiple objects can be selected IPAL 21437
347 else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0) {
348 myAxis = aSelectedObject;
349 if (!myAxis->_is_nil() && !myObjects.length())
350 GroupPoints->PushButton1->click();
352 else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1) {
353 myCentPoint = aSelectedObject;
354 if (!myCentPoint->_is_nil() && myPoint1->_is_nil())
355 GroupPoints->PushButton4->click();
357 else if (myEditCurrentArgument == GroupPoints->LineEdit4) {
358 myPoint1 = aSelectedObject;
359 if (!myPoint1->_is_nil() && myPoint2->_is_nil())
360 GroupPoints->PushButton5->click();
362 else if (myEditCurrentArgument == GroupPoints->LineEdit5) {
363 myPoint2 = aSelectedObject;
364 if (!myPoint2->_is_nil() && !myObjects.length())
365 GroupPoints->PushButton1->click();
369 /* disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
370 myGeomGUI->getApp()->selectionMgr()->clearSelected();
371 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
372 this, SLOT(SelectionIntoArgument()));*/
373 // here commented, because multiple objects can be selected IPAL 21437
378 //=================================================================================
379 // function : SetEditCurrentArgument()
381 //=================================================================================
382 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
384 QPushButton* send = (QPushButton*)sender();
386 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
389 if (send == GroupPoints->PushButton1) {
390 myEditCurrentArgument = GroupPoints->LineEdit1;
392 GroupPoints->PushButton2->setDown(false);
393 GroupPoints->PushButton4->setDown(false);
394 GroupPoints->PushButton5->setDown(false);
395 GroupPoints->LineEdit2->setEnabled(false);
396 GroupPoints->LineEdit4->setEnabled(false);
397 GroupPoints->LineEdit5->setEnabled(false);
399 else if (send == GroupPoints->PushButton2) {
400 myEditCurrentArgument = GroupPoints->LineEdit2;
402 GroupPoints->PushButton1->setDown(false);
403 GroupPoints->PushButton4->setDown(false);
404 GroupPoints->PushButton5->setDown(false);
405 GroupPoints->LineEdit1->setEnabled(false);
406 GroupPoints->LineEdit4->setEnabled(false);
407 GroupPoints->LineEdit5->setEnabled(false);
409 if (getConstructorId() == 0)
410 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
412 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
414 else if (send == GroupPoints->PushButton4) {
415 myEditCurrentArgument = GroupPoints->LineEdit4;
417 GroupPoints->PushButton1->setDown(false);
418 GroupPoints->PushButton2->setDown(false);
419 GroupPoints->PushButton5->setDown(false);
420 GroupPoints->LineEdit1->setEnabled(false);
421 GroupPoints->LineEdit2->setEnabled(false);
422 GroupPoints->LineEdit5->setEnabled(false);
424 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
426 else if (send == GroupPoints->PushButton5) {
427 myEditCurrentArgument = GroupPoints->LineEdit5;
429 GroupPoints->PushButton1->setDown(false);
430 GroupPoints->PushButton2->setDown(false);
431 GroupPoints->PushButton4->setDown(false);
432 GroupPoints->LineEdit1->setEnabled(false);
433 GroupPoints->LineEdit2->setEnabled(false);
434 GroupPoints->LineEdit4->setEnabled(false);
436 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
438 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
439 this, SLOT(SelectionIntoArgument()));
442 myEditCurrentArgument->setEnabled(true);
443 myEditCurrentArgument->setFocus();
444 // after setFocus(), because it will be setDown(false) when loses focus
447 // seems we need it only to avoid preview disappearing, caused by selection mode change
451 //=================================================================================
452 // function : LineEditReturnPressed()
454 //=================================================================================
455 void TransformationGUI_RotationDlg::LineEditReturnPressed()
457 QLineEdit* send = (QLineEdit*)sender();
458 if (send == GroupPoints->LineEdit1 ||
459 send == GroupPoints->LineEdit2) {
460 myEditCurrentArgument = send;
461 GEOMBase_Skeleton::LineEditReturnPressed();
465 //=================================================================================
466 // function : ActivateThisDialog()
468 //=================================================================================
469 void TransformationGUI_RotationDlg::ActivateThisDialog()
471 GEOMBase_Skeleton::ActivateThisDialog();
472 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
473 this, SLOT( SelectionIntoArgument() ) );
475 ConstructorsClicked( getConstructorId() );
478 //=================================================================================
479 // function : enterEvent()
481 //=================================================================================
482 void TransformationGUI_RotationDlg::enterEvent (QEvent*)
484 if (!mainFrame()->GroupConstructors->isEnabled())
485 ActivateThisDialog();
488 void TransformationGUI_RotationDlg::TextValueChangedInSpinBox( const QString& s)
491 s.toDouble(&isDigit);
493 GroupPoints->CheckButton2->setChecked(false);
495 GroupPoints->CheckButton2->setEnabled(isDigit);
498 //=================================================================================
499 // function : ValueChangedInSpinBox()
501 //=================================================================================
502 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
507 //=================================================================================
508 // function : createOperation
510 //=================================================================================
511 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
513 return getGeomEngine()->GetITransformOperations(getStudyId());
516 //=================================================================================
517 // function : isValid
519 //=================================================================================
520 bool TransformationGUI_RotationDlg::isValid (QString& msg)
522 switch (getConstructorId()) {
524 bool ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() );
525 return myObjects.length() > 0 && !(myAxis->_is_nil()) && ok;
529 return myObjects.length() > 0 && !(myCentPoint->_is_nil() || myPoint1->_is_nil() || myPoint2->_is_nil());
537 //=================================================================================
538 // function : execute
540 //=================================================================================
541 bool TransformationGUI_RotationDlg::execute (ObjectList& objects)
544 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
546 GEOM::GEOM_Object_var anObj;
548 GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
550 switch (getConstructorId()) {
553 QStringList aParameters;
554 aParameters<<GroupPoints->SpinBox_DX->text();
556 for (int i = 0; i < myObjects.length(); i++) {
557 myCurrObject = myObjects[i];
558 anObj = anOper->RotateCopy(myObjects[i], myAxis, GetAngle() * PI180);
559 if (!anObj->_is_nil()) {
561 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
563 objects.push_back(anObj._retn());
568 for (int i = 0; i < myObjects.length(); i++) {
569 myCurrObject = myObjects[i];
570 anObj = anOper->Rotate(myObjects[i], myAxis, GetAngle() * PI180);
571 if (!anObj->_is_nil()) {
573 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
574 updateAttributes(anObj, aParameters);
576 objects.push_back(anObj._retn());
586 for (int i = 0; i < myObjects.length(); i++) {
587 myCurrObject = myObjects[i];
588 anObj = anOper->RotateThreePointsCopy(myObjects[i], myCentPoint, myPoint1, myPoint2);
589 if (!anObj->_is_nil())
590 objects.push_back(anObj._retn());
594 for (int i = 0; i < myObjects.length(); i++) {
595 myCurrObject = myObjects[i];
596 anObj = anOper->RotateThreePoints(myObjects[i], myCentPoint, myPoint1, myPoint2);
597 if (!anObj->_is_nil())
598 objects.push_back(anObj._retn());
609 //=================================================================================
610 // function : restoreSubShapes
612 //=================================================================================
613 void TransformationGUI_RotationDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
614 SALOMEDS::SObject_ptr theSObject)
616 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
617 // we pass here the first operation argument (object) through the list of arguments
618 // because the rotation operation place its arguments in the data structure in another order,
619 // and we need to point the first argument directly
620 GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
622 anArgs[0] = myCurrObject;
623 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
624 /*theFindMethod=*/GEOM::FSM_Transformed,
625 /*theInheritFirstArg=*/true,
626 mainFrame()->CheckBoxAddPrefix->isChecked());
630 //=================================================================================
631 // function : GetAngle()
633 //=================================================================================
634 double TransformationGUI_RotationDlg::GetAngle() const
636 return GroupPoints->SpinBox_DX->value();
639 //=================================================================================
640 // function : CreateCopyModeChanged()
642 //=================================================================================
643 void TransformationGUI_RotationDlg::CreateCopyModeChanged (bool isCreateCopy)
645 mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
648 //=================================================================================
649 // function : onReverse()
651 //=================================================================================
652 void TransformationGUI_RotationDlg::onReverse()
654 double anOldValue = GroupPoints->SpinBox_DX->value();
655 GroupPoints->SpinBox_DX->setValue(-anOldValue);
658 //=================================================================================
659 // function : addSubshapesToStudy
660 // purpose : virtual method to add new SubObjects if local selection
661 //=================================================================================
662 void TransformationGUI_RotationDlg::addSubshapesToStudy()
664 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
666 QMap<QString, GEOM::GEOM_Object_var> objMap;
667 switch (getConstructorId()) {
669 objMap[GroupPoints->LineEdit2->text()] = myAxis;
672 objMap[GroupPoints->LineEdit2->text()] = myCentPoint;
673 objMap[GroupPoints->LineEdit4->text()] = myPoint1;
674 objMap[GroupPoints->LineEdit5->text()] = myPoint2;
677 addSubshapesToFather(objMap);