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);
266 GEOM::GEOM_Object_var aSelectedObject;
270 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
271 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName);
275 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myObjects);
276 if (!myObjects.length())
280 if (aSelList.Extent() != 1)
284 Standard_Boolean testResult = Standard_False;
285 aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
287 if (!testResult || CORBA::is_nil(aSelectedObject))
290 aName = GEOMBase::GetName(aSelectedObject);
292 // Get Selected object if selected subshape
294 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
296 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
297 if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
298 aNeedType = TopAbs_EDGE;
300 TColStd_IndexedMapOfInteger aMap;
301 aSelMgr->GetIndexes(aSelList.First(), aMap);
302 if (aMap.Extent() == 1)
304 int anIndex = aMap(1);
305 if (aNeedType == TopAbs_EDGE)
306 aName += QString(":edge_%1").arg(anIndex);
308 aName += QString(":vertex_%1").arg(anIndex);
310 //Find SubShape Object in Father
311 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
313 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
314 GEOM::GEOM_IShapesOperations_var aShapesOp =
315 getGeomEngine()->GetIShapesOperations(getStudyId());
316 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
319 aSelectedObject = aFindedObject; // get Object from study
322 else // Global Selection
324 if (aShape.ShapeType() != aNeedType) {
325 aSelectedObject = GEOM::GEOM_Object::_nil();
332 myEditCurrentArgument->setText(aName);
334 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
335 /* if (myObjects.length()) {
336 if (getConstructorId() == 0 && myAxis->_is_nil() || getConstructorId() == 1 && myCentPoint->_is_nil() )
337 GroupPoints->PushButton2->click();
338 }*/ // here commented, because multiple objects can be selected IPAL 21437
340 else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0) {
341 myAxis = aSelectedObject;
342 if (!myAxis->_is_nil() && !myObjects.length())
343 GroupPoints->PushButton1->click();
345 else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1) {
346 myCentPoint = aSelectedObject;
347 if (!myCentPoint->_is_nil() && myPoint1->_is_nil())
348 GroupPoints->PushButton4->click();
350 else if (myEditCurrentArgument == GroupPoints->LineEdit4) {
351 myPoint1 = aSelectedObject;
352 if (!myPoint1->_is_nil() && myPoint2->_is_nil())
353 GroupPoints->PushButton5->click();
355 else if (myEditCurrentArgument == GroupPoints->LineEdit5) {
356 myPoint2 = aSelectedObject;
357 if (!myPoint2->_is_nil() && !myObjects.length())
358 GroupPoints->PushButton1->click();
362 /* disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
363 myGeomGUI->getApp()->selectionMgr()->clearSelected();
364 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
365 this, SLOT(SelectionIntoArgument()));*/
366 // here commented, because multiple objects can be selected IPAL 21437
371 //=================================================================================
372 // function : SetEditCurrentArgument()
374 //=================================================================================
375 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
377 QPushButton* send = (QPushButton*)sender();
379 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
382 if (send == GroupPoints->PushButton1) {
383 myEditCurrentArgument = GroupPoints->LineEdit1;
385 GroupPoints->PushButton2->setDown(false);
386 GroupPoints->PushButton4->setDown(false);
387 GroupPoints->PushButton5->setDown(false);
388 GroupPoints->LineEdit2->setEnabled(false);
389 GroupPoints->LineEdit4->setEnabled(false);
390 GroupPoints->LineEdit5->setEnabled(false);
392 else if (send == GroupPoints->PushButton2) {
393 myEditCurrentArgument = GroupPoints->LineEdit2;
395 GroupPoints->PushButton1->setDown(false);
396 GroupPoints->PushButton4->setDown(false);
397 GroupPoints->PushButton5->setDown(false);
398 GroupPoints->LineEdit1->setEnabled(false);
399 GroupPoints->LineEdit4->setEnabled(false);
400 GroupPoints->LineEdit5->setEnabled(false);
402 if (getConstructorId() == 0)
403 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
405 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
407 else if (send == GroupPoints->PushButton4) {
408 myEditCurrentArgument = GroupPoints->LineEdit4;
410 GroupPoints->PushButton1->setDown(false);
411 GroupPoints->PushButton2->setDown(false);
412 GroupPoints->PushButton5->setDown(false);
413 GroupPoints->LineEdit1->setEnabled(false);
414 GroupPoints->LineEdit2->setEnabled(false);
415 GroupPoints->LineEdit5->setEnabled(false);
417 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
419 else if (send == GroupPoints->PushButton5) {
420 myEditCurrentArgument = GroupPoints->LineEdit5;
422 GroupPoints->PushButton1->setDown(false);
423 GroupPoints->PushButton2->setDown(false);
424 GroupPoints->PushButton4->setDown(false);
425 GroupPoints->LineEdit1->setEnabled(false);
426 GroupPoints->LineEdit2->setEnabled(false);
427 GroupPoints->LineEdit4->setEnabled(false);
429 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
431 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
432 this, SLOT(SelectionIntoArgument()));
435 myEditCurrentArgument->setEnabled(true);
436 myEditCurrentArgument->setFocus();
437 // after setFocus(), because it will be setDown(false) when loses focus
440 // seems we need it only to avoid preview disappearing, caused by selection mode change
444 //=================================================================================
445 // function : LineEditReturnPressed()
447 //=================================================================================
448 void TransformationGUI_RotationDlg::LineEditReturnPressed()
450 QLineEdit* send = (QLineEdit*)sender();
451 if (send == GroupPoints->LineEdit1 ||
452 send == GroupPoints->LineEdit2) {
453 myEditCurrentArgument = send;
454 GEOMBase_Skeleton::LineEditReturnPressed();
458 //=================================================================================
459 // function : ActivateThisDialog()
461 //=================================================================================
462 void TransformationGUI_RotationDlg::ActivateThisDialog()
464 GEOMBase_Skeleton::ActivateThisDialog();
465 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
466 this, SLOT( SelectionIntoArgument() ) );
468 ConstructorsClicked( getConstructorId() );
471 //=================================================================================
472 // function : enterEvent()
474 //=================================================================================
475 void TransformationGUI_RotationDlg::enterEvent (QEvent*)
477 if (!mainFrame()->GroupConstructors->isEnabled())
478 ActivateThisDialog();
481 void TransformationGUI_RotationDlg::TextValueChangedInSpinBox( const QString& s)
484 s.toDouble(&isDigit);
486 GroupPoints->CheckButton2->setChecked(false);
488 GroupPoints->CheckButton2->setEnabled(isDigit);
491 //=================================================================================
492 // function : ValueChangedInSpinBox()
494 //=================================================================================
495 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
500 //=================================================================================
501 // function : createOperation
503 //=================================================================================
504 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
506 return getGeomEngine()->GetITransformOperations(getStudyId());
509 //=================================================================================
510 // function : isValid
512 //=================================================================================
513 bool TransformationGUI_RotationDlg::isValid (QString& msg)
515 switch (getConstructorId()) {
517 bool ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() );
518 return myObjects.length() > 0 && !(myAxis->_is_nil()) && ok;
522 return myObjects.length() > 0 && !(myCentPoint->_is_nil() || myPoint1->_is_nil() || myPoint2->_is_nil());
530 //=================================================================================
531 // function : execute
533 //=================================================================================
534 bool TransformationGUI_RotationDlg::execute (ObjectList& objects)
537 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
539 GEOM::GEOM_Object_var anObj;
541 GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
543 switch (getConstructorId()) {
546 QStringList aParameters;
547 aParameters<<GroupPoints->SpinBox_DX->text();
549 for (int i = 0; i < myObjects.length(); i++) {
550 myCurrObject = myObjects[i];
551 anObj = anOper->RotateCopy(myObjects[i], myAxis, GetAngle() * PI180);
552 if (!anObj->_is_nil()) {
554 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
556 objects.push_back(anObj._retn());
561 for (int i = 0; i < myObjects.length(); i++) {
562 myCurrObject = myObjects[i];
563 anObj = anOper->Rotate(myObjects[i], myAxis, GetAngle() * PI180);
564 if (!anObj->_is_nil()) {
566 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
567 updateAttributes(anObj, aParameters);
569 objects.push_back(anObj._retn());
579 for (int i = 0; i < myObjects.length(); i++) {
580 myCurrObject = myObjects[i];
581 anObj = anOper->RotateThreePointsCopy(myObjects[i], myCentPoint, myPoint1, myPoint2);
582 if (!anObj->_is_nil())
583 objects.push_back(anObj._retn());
587 for (int i = 0; i < myObjects.length(); i++) {
588 myCurrObject = myObjects[i];
589 anObj = anOper->RotateThreePoints(myObjects[i], myCentPoint, myPoint1, myPoint2);
590 if (!anObj->_is_nil())
591 objects.push_back(anObj._retn());
602 //=================================================================================
603 // function : restoreSubShapes
605 //=================================================================================
606 void TransformationGUI_RotationDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
607 SALOMEDS::SObject_ptr theSObject)
609 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
610 // we pass here the first operation argument (object) through the list of arguments
611 // because the rotation operation place its arguments in the data structure in another order,
612 // and we need to point the first argument directly
613 GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
615 anArgs[0] = myCurrObject;
616 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
617 /*theFindMethod=*/GEOM::FSM_Transformed,
618 /*theInheritFirstArg=*/true);
622 //=================================================================================
623 // function : GetAngle()
625 //=================================================================================
626 double TransformationGUI_RotationDlg::GetAngle() const
628 return GroupPoints->SpinBox_DX->value();
631 //=================================================================================
632 // function : CreateCopyModeChanged()
634 //=================================================================================
635 void TransformationGUI_RotationDlg::CreateCopyModeChanged (bool isCreateCopy)
637 mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
640 //=================================================================================
641 // function : onReverse()
643 //=================================================================================
644 void TransformationGUI_RotationDlg::onReverse()
646 double anOldValue = GroupPoints->SpinBox_DX->value();
647 GroupPoints->SpinBox_DX->setValue(-anOldValue);
650 //=================================================================================
651 // function : addSubshapesToStudy
652 // purpose : virtual method to add new SubObjects if local selection
653 //=================================================================================
654 void TransformationGUI_RotationDlg::addSubshapesToStudy()
656 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
658 QMap<QString, GEOM::GEOM_Object_var> objMap;
659 switch (getConstructorId()) {
661 objMap[GroupPoints->LineEdit2->text()] = myAxis;
664 objMap[GroupPoints->LineEdit2->text()] = myCentPoint;
665 objMap[GroupPoints->LineEdit4->text()] = myPoint1;
666 objMap[GroupPoints->LineEdit5->text()] = myPoint2;
669 addSubshapesToFather(objMap);