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_RotationDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "TransformationGUI_RotationDlg.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>
37 #include <TopoDS_Edge.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <qcheckbox.h>
46 #include "GEOMImpl_Types.hxx"
48 #include "utilities.h"
52 //=================================================================================
53 // class : TransformationGUI_RotationDlg()
54 // purpose : Constructs a TransformationGUI_RotationDlg 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_RotationDlg::TransformationGUI_RotationDlg
60 (GeometryGUI* theGeometryGUI, QWidget* parent, 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 image0 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ROTATION")));
66 QPixmap image1 (aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
67 QPixmap image2 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ROTATION_THREE_POINTS")));
69 setCaption(tr("GEOM_ROTATION_TITLE"));
71 /***************************************************************/
72 GroupConstructors->setTitle(tr("GEOM_ROTATION"));
73 RadioButton1->setPixmap(image0);
74 RadioButton2->setPixmap(image2);
75 RadioButton3->close(TRUE);
77 GroupPoints = new DlgRef_4Sel1Spin2Check(this, "GroupPoints");
78 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
79 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
80 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
81 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
82 GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg("1"));
83 GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg("2"));
85 GroupPoints->LineEdit1->setReadOnly(true);
86 GroupPoints->LineEdit2->setReadOnly(true);
87 GroupPoints->LineEdit4->setReadOnly(true);
88 GroupPoints->LineEdit5->setReadOnly(true);
89 GroupPoints->PushButton1->setPixmap(image1);
90 GroupPoints->PushButton2->setPixmap(image1);
91 GroupPoints->PushButton4->setPixmap(image1);
92 GroupPoints->PushButton5->setPixmap(image1);
93 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
94 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
96 Layout1->addWidget(GroupPoints, 2, 0);
97 /***************************************************************/
100 double SpecificStep = 5;
101 /* min, max, step and decimals for spin boxes & initial values */
102 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
103 GroupPoints->SpinBox_DX->SetValue(anAngle);
105 // Activate Create a Copy mode
106 GroupPoints->CheckButton1->setChecked(true);
107 CreateCopyModeChanged(true);
109 GroupBoxPublish->show();
111 /* signals and slots connections */
112 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
113 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
114 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
116 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
117 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
118 connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
119 connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
122 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
124 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
125 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
126 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
128 connect(myGeomGUI->getApp()->selectionMgr(),
129 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
131 setHelpFileName("rotation_operation_page.html");
137 //=================================================================================
138 // function : ~TransformationGUI_RotationDlg()
139 // purpose : Destroys the object and frees any allocated resources
140 //=================================================================================
141 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
143 // no need to delete child widgets, Qt does it all for us
147 //=================================================================================
150 //=================================================================================
151 void TransformationGUI_RotationDlg::Init()
154 myEditCurrentArgument = GroupPoints->LineEdit1;
155 GroupPoints->LineEdit2->clear();
157 myAxis = myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
159 initName( tr( "GEOM_ROTATION" ) );
160 ConstructorsClicked( 0 );
163 //=================================================================================
164 // function : ConstructorsClicked()
165 // purpose : Radio button management
166 //=================================================================================
167 void TransformationGUI_RotationDlg::ConstructorsClicked(int constructorId)
169 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
171 myEditCurrentArgument = GroupPoints->LineEdit1;
174 switch (constructorId)
176 case 0: /* rotation an object angle and axis */
178 GroupPoints->ShowRows(2,3,false);
180 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
181 GroupPoints->LineEdit2->clear();
182 GroupPoints->ShowRows(4,4,true);
183 myAxis = GEOM::GEOM_Object::_nil();
186 case 1: /* rotation an object by 3 points */
188 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"));
194 GroupPoints->LineEdit2->clear();
195 GroupPoints->LineEdit4->clear();
196 GroupPoints->LineEdit5->clear();
197 myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
202 myEditCurrentArgument->setFocus();
203 connect(myGeomGUI->getApp()->selectionMgr(),
204 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
207 //=================================================================================
208 // function : ClickOnOk()
210 //=================================================================================
211 void TransformationGUI_RotationDlg::ClickOnOk()
213 if ( ClickOnApply() )
218 //=================================================================================
219 // function : ClickOnApply()
221 //=================================================================================
222 bool TransformationGUI_RotationDlg::ClickOnApply()
224 if ( !onAccept( GroupPoints->CheckButton1->isChecked()) )
228 ConstructorsClicked( getConstructorId() );
233 //=================================================================================
234 // function : SelectionIntoArgument()
235 // purpose : Called when selection as changed or other case
236 //=================================================================================
237 void TransformationGUI_RotationDlg::SelectionIntoArgument()
239 myEditCurrentArgument->setText("");
242 if(myEditCurrentArgument == GroupPoints->LineEdit1)
244 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
250 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
251 if (!myObjects.length())
256 if(IObjectCount() != 1)
258 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
259 myAxis = GEOM::GEOM_Object::_nil();
260 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
261 myCentPoint = GEOM::GEOM_Object::_nil();
262 else if(myEditCurrentArgument == GroupPoints->LineEdit4)
263 myPoint1 = GEOM::GEOM_Object::_nil();
264 else if(myEditCurrentArgument == GroupPoints->LineEdit5)
265 myPoint2 = GEOM::GEOM_Object::_nil();
269 Standard_Boolean testResult = Standard_False;
270 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
271 if(!testResult || CORBA::is_nil( aSelectedObject ))
274 aName = GEOMBase::GetName( aSelectedObject );
276 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
278 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
279 if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
280 aNeedType = TopAbs_EDGE;
282 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
283 TColStd_IndexedMapOfInteger aMap;
284 aSelMgr->GetIndexes( firstIObject(), aMap );
285 if ( aMap.Extent() == 1 )
287 int anIndex = aMap( 1 );
288 if (aNeedType == TopAbs_EDGE)
289 aName += QString(":edge_%1").arg(anIndex);
291 aName += QString(":vertex_%1").arg(anIndex);
293 //Find SubShape Object in Father
294 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
296 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
297 GEOM::GEOM_IShapesOperations_var aShapesOp =
298 getGeomEngine()->GetIShapesOperations( getStudyId() );
299 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
302 aSelectedObject = aFindedObject; // get Object from study
305 if (aShape.ShapeType() != aNeedType) {
306 aSelectedObject = GEOM::GEOM_Object::_nil();
312 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
313 myAxis = aSelectedObject;
314 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
315 myCentPoint = aSelectedObject;
316 else if(myEditCurrentArgument == GroupPoints->LineEdit4)
317 myPoint1 = aSelectedObject;
318 else if(myEditCurrentArgument == GroupPoints->LineEdit5)
319 myPoint2 = aSelectedObject;
322 myEditCurrentArgument->setText( aName );
328 //=================================================================================
329 // function : SetEditCurrentArgument()
331 //=================================================================================
332 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
334 QPushButton* send = (QPushButton*)sender();
337 if(send == GroupPoints->PushButton1) {
338 myEditCurrentArgument = GroupPoints->LineEdit1;
340 else if(send == GroupPoints->PushButton2) {
341 myEditCurrentArgument = GroupPoints->LineEdit2;
342 if (getConstructorId() == 0)
343 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
345 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
347 else if (send == GroupPoints->PushButton4)
349 myEditCurrentArgument = GroupPoints->LineEdit4;
350 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
352 else if (send == GroupPoints->PushButton5)
354 myEditCurrentArgument = GroupPoints->LineEdit5;
355 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
358 myEditCurrentArgument->setFocus();
359 SelectionIntoArgument();
363 //=================================================================================
364 // function : LineEditReturnPressed()
366 //=================================================================================
367 void TransformationGUI_RotationDlg::LineEditReturnPressed()
369 QLineEdit* send = (QLineEdit*)sender();
370 if(send == GroupPoints->LineEdit1 ||
371 send == GroupPoints->LineEdit2)
373 myEditCurrentArgument = send;
374 GEOMBase_Skeleton::LineEditReturnPressed();
379 //=================================================================================
380 // function : ActivateThisDialog()
382 //=================================================================================
383 void TransformationGUI_RotationDlg::ActivateThisDialog()
385 GEOMBase_Skeleton::ActivateThisDialog();
386 connect(myGeomGUI->getApp()->selectionMgr(),
387 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
389 ConstructorsClicked( getConstructorId() );
393 //=================================================================================
394 // function : enterEvent()
396 //=================================================================================
397 void TransformationGUI_RotationDlg::enterEvent(QEvent* e)
399 if (!GroupConstructors->isEnabled())
400 ActivateThisDialog();
404 //=================================================================================
405 // function : ValueChangedInSpinBox()
407 //=================================================================================
408 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
414 //=================================================================================
415 // function : createOperation
417 //=================================================================================
418 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
420 return getGeomEngine()->GetITransformOperations( getStudyId() );
424 //=================================================================================
425 // function : isValid
427 //=================================================================================
428 bool TransformationGUI_RotationDlg::isValid( QString& msg )
430 switch (getConstructorId())
434 return !(myObjects.length() == 0 || myAxis->_is_nil());
439 return !(myObjects.length() == 0 || myCentPoint->_is_nil() || myPoint1->_is_nil() || myPoint2->_is_nil() );
442 default: return false;
447 //=================================================================================
448 // function : execute
450 //=================================================================================
451 bool TransformationGUI_RotationDlg::execute( ObjectList& objects )
454 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
456 GEOM::GEOM_Object_var anObj;
458 switch ( getConstructorId() )
463 for (int i = 0; i < myObjects.length(); i++)
465 myCurrObject = myObjects[i];
466 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
467 RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 );
468 if ( !anObj->_is_nil() )
469 objects.push_back( anObj._retn() );
472 for (int i = 0; i < myObjects.length(); i++)
474 myCurrObject = myObjects[i];
475 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
476 Rotate( myObjects[i], myAxis, GetAngle() * PI180 );
477 if ( !anObj->_is_nil() )
478 objects.push_back( anObj._retn() );
486 for (int i = 0; i < myObjects.length(); i++)
488 myCurrObject = myObjects[i];
489 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
490 RotateThreePointsCopy( myObjects[i], myCentPoint, myPoint1, myPoint2 );
491 if ( !anObj->_is_nil() )
492 objects.push_back( anObj._retn() );
495 for (int i = 0; i < myObjects.length(); i++)
497 myCurrObject = myObjects[i];
498 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
499 RotateThreePoints( myObjects[i], myCentPoint, myPoint1, myPoint2 );
500 if ( !anObj->_is_nil() )
501 objects.push_back( anObj._retn() );
511 //=================================================================================
512 // function : restoreSubShapes
514 //=================================================================================
515 void TransformationGUI_RotationDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
516 SALOMEDS::SObject_ptr theSObject)
518 if (CheckBoxRestoreSS->isChecked()) {
519 // we pass here the first operation argument (object) through the list of arguments
520 // because the rotation operation place its arguments in the data structure in another order,
521 // and we need to point the first argument directly
522 GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
524 anArgs[0] = myCurrObject;
525 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
526 /*theFindMethod=*/GEOM::FSM_Transformed,
527 /*theInheritFirstArg=*/true);
531 //=================================================================================
532 // function : GetAngle()
534 //=================================================================================
535 double TransformationGUI_RotationDlg::GetAngle() const
537 return GroupPoints->SpinBox_DX->GetValue();
541 //=================================================================================
542 // function : CreateCopyModeChanged()
544 //=================================================================================
545 void TransformationGUI_RotationDlg::CreateCopyModeChanged(bool isCreateCopy)
547 this->GroupBoxName->setEnabled(isCreateCopy);
551 //=================================================================================
552 // function : onReverse()
554 //=================================================================================
555 void TransformationGUI_RotationDlg::onReverse()
557 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
558 GroupPoints->SpinBox_DX->SetValue( -anOldValue );
561 //=================================================================================
562 // function : addSubshapeToStudy
563 // purpose : virtual method to add new SubObjects if local selection
564 //=================================================================================
565 void TransformationGUI_RotationDlg::addSubshapesToStudy()
567 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
569 QMap<QString, GEOM::GEOM_Object_var> objMap;
570 switch (getConstructorId())
573 objMap[GroupPoints->LineEdit2->text()] = myAxis;
576 objMap[GroupPoints->LineEdit2->text()] = myCentPoint;
577 objMap[GroupPoints->LineEdit4->text()] = myPoint1;
578 objMap[GroupPoints->LineEdit5->text()] = myPoint2;
581 addSubshapesToFather( objMap );