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 /* signals and slots connections */
110 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
111 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
112 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
114 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
115 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
116 connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
117 connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
119 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
120 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
122 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
123 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
124 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
126 connect(myGeomGUI->getApp()->selectionMgr(),
127 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
129 setHelpFileName("rotation_operation_page.html");
135 //=================================================================================
136 // function : ~TransformationGUI_RotationDlg()
137 // purpose : Destroys the object and frees any allocated resources
138 //=================================================================================
139 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
141 // no need to delete child widgets, Qt does it all for us
145 //=================================================================================
148 //=================================================================================
149 void TransformationGUI_RotationDlg::Init()
152 myEditCurrentArgument = GroupPoints->LineEdit1;
153 GroupPoints->LineEdit2->clear();
155 myAxis = myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
157 initName( tr( "GEOM_ROTATION" ) );
158 ConstructorsClicked( 0 );
161 //=================================================================================
162 // function : ConstructorsClicked()
163 // purpose : Radio button management
164 //=================================================================================
165 void TransformationGUI_RotationDlg::ConstructorsClicked(int constructorId)
167 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
169 myEditCurrentArgument = GroupPoints->LineEdit1;
172 switch (constructorId)
174 case 0: /* rotation an object angle and axis */
176 GroupPoints->ShowRows(2,3,false);
178 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
179 GroupPoints->LineEdit2->clear();
180 GroupPoints->ShowRows(4,4,true);
181 myAxis = GEOM::GEOM_Object::_nil();
184 case 1: /* rotation an object by 3 points */
186 GroupPoints->ShowRows(4,4,false);
188 GroupPoints->ShowRows(2,3,true);
189 GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
190 GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg("1"));
191 GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg("2"));
192 GroupPoints->LineEdit2->clear();
193 GroupPoints->LineEdit4->clear();
194 GroupPoints->LineEdit5->clear();
195 myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
200 myEditCurrentArgument->setFocus();
201 connect(myGeomGUI->getApp()->selectionMgr(),
202 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
205 //=================================================================================
206 // function : ClickOnOk()
208 //=================================================================================
209 void TransformationGUI_RotationDlg::ClickOnOk()
211 if ( ClickOnApply() )
216 //=================================================================================
217 // function : ClickOnApply()
219 //=================================================================================
220 bool TransformationGUI_RotationDlg::ClickOnApply()
222 if ( !onAccept( GroupPoints->CheckButton1->isChecked()) )
226 ConstructorsClicked( getConstructorId() );
231 //=================================================================================
232 // function : SelectionIntoArgument()
233 // purpose : Called when selection as changed or other case
234 //=================================================================================
235 void TransformationGUI_RotationDlg::SelectionIntoArgument()
237 myEditCurrentArgument->setText("");
240 if(myEditCurrentArgument == GroupPoints->LineEdit1)
242 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
248 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
249 if (!myObjects.length())
254 if(IObjectCount() != 1)
256 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
257 myAxis = GEOM::GEOM_Object::_nil();
258 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
259 myCentPoint = GEOM::GEOM_Object::_nil();
260 else if(myEditCurrentArgument == GroupPoints->LineEdit4)
261 myPoint1 = GEOM::GEOM_Object::_nil();
262 else if(myEditCurrentArgument == GroupPoints->LineEdit5)
263 myPoint2 = GEOM::GEOM_Object::_nil();
267 Standard_Boolean testResult = Standard_False;
268 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
269 if(!testResult || CORBA::is_nil( aSelectedObject ))
272 aName = GEOMBase::GetName( aSelectedObject );
274 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
276 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
277 if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
278 aNeedType = TopAbs_EDGE;
280 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
281 TColStd_IndexedMapOfInteger aMap;
282 aSelMgr->GetIndexes( firstIObject(), aMap );
283 if ( aMap.Extent() == 1 )
285 int anIndex = aMap( 1 );
286 if (aNeedType == TopAbs_EDGE)
287 aName += QString(":edge_%1").arg(anIndex);
289 aName += QString(":vertex_%1").arg(anIndex);
291 //Find SubShape Object in Father
292 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
294 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
295 GEOM::GEOM_IShapesOperations_var aShapesOp =
296 getGeomEngine()->GetIShapesOperations( getStudyId() );
297 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
300 aSelectedObject = aFindedObject; // get Object from study
303 if (aShape.ShapeType() != aNeedType) {
304 aSelectedObject = GEOM::GEOM_Object::_nil();
310 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
311 myAxis = aSelectedObject;
312 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
313 myCentPoint = aSelectedObject;
314 else if(myEditCurrentArgument == GroupPoints->LineEdit4)
315 myPoint1 = aSelectedObject;
316 else if(myEditCurrentArgument == GroupPoints->LineEdit5)
317 myPoint2 = aSelectedObject;
320 myEditCurrentArgument->setText( aName );
326 //=================================================================================
327 // function : SetEditCurrentArgument()
329 //=================================================================================
330 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
332 QPushButton* send = (QPushButton*)sender();
335 if(send == GroupPoints->PushButton1) {
336 myEditCurrentArgument = GroupPoints->LineEdit1;
338 else if(send == GroupPoints->PushButton2) {
339 myEditCurrentArgument = GroupPoints->LineEdit2;
340 if (getConstructorId() == 0)
341 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
343 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
345 else if (send == GroupPoints->PushButton4)
347 myEditCurrentArgument = GroupPoints->LineEdit4;
348 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
350 else if (send == GroupPoints->PushButton5)
352 myEditCurrentArgument = GroupPoints->LineEdit5;
353 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
356 myEditCurrentArgument->setFocus();
357 SelectionIntoArgument();
361 //=================================================================================
362 // function : LineEditReturnPressed()
364 //=================================================================================
365 void TransformationGUI_RotationDlg::LineEditReturnPressed()
367 QLineEdit* send = (QLineEdit*)sender();
368 if(send == GroupPoints->LineEdit1 ||
369 send == GroupPoints->LineEdit2)
371 myEditCurrentArgument = send;
372 GEOMBase_Skeleton::LineEditReturnPressed();
377 //=================================================================================
378 // function : ActivateThisDialog()
380 //=================================================================================
381 void TransformationGUI_RotationDlg::ActivateThisDialog()
383 GEOMBase_Skeleton::ActivateThisDialog();
384 connect(myGeomGUI->getApp()->selectionMgr(),
385 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
387 ConstructorsClicked( getConstructorId() );
391 //=================================================================================
392 // function : enterEvent()
394 //=================================================================================
395 void TransformationGUI_RotationDlg::enterEvent(QEvent* e)
397 if (!GroupConstructors->isEnabled())
398 ActivateThisDialog();
402 //=================================================================================
403 // function : ValueChangedInSpinBox()
405 //=================================================================================
406 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
412 //=================================================================================
413 // function : createOperation
415 //=================================================================================
416 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
418 return getGeomEngine()->GetITransformOperations( getStudyId() );
422 //=================================================================================
423 // function : isValid
425 //=================================================================================
426 bool TransformationGUI_RotationDlg::isValid( QString& msg )
428 switch (getConstructorId())
432 return !(myObjects.length() == 0 || myAxis->_is_nil());
437 return !(myObjects.length() == 0 || myCentPoint->_is_nil() || myPoint1->_is_nil() || myPoint2->_is_nil() );
440 default: return false;
445 //=================================================================================
446 // function : execute
448 //=================================================================================
449 bool TransformationGUI_RotationDlg::execute( ObjectList& objects )
452 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
454 GEOM::GEOM_Object_var anObj;
456 switch ( getConstructorId() )
461 for (int i = 0; i < myObjects.length(); i++)
463 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
464 RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 );
465 if ( !anObj->_is_nil() )
466 objects.push_back( anObj._retn() );
469 for (int i = 0; i < myObjects.length(); i++)
471 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
472 Rotate( myObjects[i], myAxis, GetAngle() * PI180 );
473 if ( !anObj->_is_nil() )
474 objects.push_back( anObj._retn() );
482 for (int i = 0; i < myObjects.length(); i++)
484 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
485 RotateThreePointsCopy( myObjects[i], myCentPoint, myPoint1, myPoint2 );
486 if ( !anObj->_is_nil() )
487 objects.push_back( anObj._retn() );
490 for (int i = 0; i < myObjects.length(); i++)
492 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
493 RotateThreePoints( myObjects[i], myCentPoint, myPoint1, myPoint2 );
494 if ( !anObj->_is_nil() )
495 objects.push_back( anObj._retn() );
506 //=================================================================================
507 // function : closeEvent
509 //=================================================================================
510 void TransformationGUI_RotationDlg::closeEvent( QCloseEvent* e )
512 GEOMBase_Skeleton::closeEvent( e );
516 //=================================================================================
517 // function : GetAngle()
519 //=================================================================================
520 double TransformationGUI_RotationDlg::GetAngle() const
522 return GroupPoints->SpinBox_DX->GetValue();
526 //=================================================================================
527 // function : CreateCopyModeChanged()
529 //=================================================================================
530 void TransformationGUI_RotationDlg::CreateCopyModeChanged(bool isCreateCopy)
532 this->GroupBoxName->setEnabled(isCreateCopy);
536 //=================================================================================
537 // function : onReverse()
539 //=================================================================================
540 void TransformationGUI_RotationDlg::onReverse()
542 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
543 GroupPoints->SpinBox_DX->SetValue( -anOldValue );
546 //=================================================================================
547 // function : addSubshapeToStudy
548 // purpose : virtual method to add new SubObjects if local selection
549 //=================================================================================
550 void TransformationGUI_RotationDlg::addSubshapesToStudy()
552 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
554 QMap<QString, GEOM::GEOM_Object_var> objMap;
555 switch (getConstructorId())
558 objMap[GroupPoints->LineEdit2->text()] = myAxis;
561 objMap[GroupPoints->LineEdit2->text()] = myCentPoint;
562 objMap[GroupPoints->LineEdit4->text()] = myPoint1;
563 objMap[GroupPoints->LineEdit5->text()] = myPoint2;
566 addSubshapesToFather( objMap );