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 <qcheckbox.h>
39 #include "GEOMImpl_Types.hxx"
41 #include "utilities.h"
45 //=================================================================================
46 // class : TransformationGUI_RotationDlg()
47 // purpose : Constructs a TransformationGUI_RotationDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 TransformationGUI_RotationDlg::TransformationGUI_RotationDlg
53 (GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
54 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
55 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
57 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
58 QPixmap image0 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ROTATION")));
59 QPixmap image1 (aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
60 QPixmap image2 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ROTATION_THREE_POINTS")));
62 setCaption(tr("GEOM_ROTATION_TITLE"));
64 /***************************************************************/
65 GroupConstructors->setTitle(tr("GEOM_ROTATION"));
66 RadioButton1->setPixmap(image0);
67 RadioButton2->setPixmap(image2);
68 RadioButton3->close(TRUE);
70 GroupPoints = new DlgRef_4Sel1Spin2Check(this, "GroupPoints");
71 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
73 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
74 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
75 GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg("1"));
76 GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg("2"));
78 GroupPoints->LineEdit1->setReadOnly(true);
79 GroupPoints->LineEdit2->setReadOnly(true);
80 GroupPoints->LineEdit4->setReadOnly(true);
81 GroupPoints->LineEdit5->setReadOnly(true);
82 GroupPoints->PushButton1->setPixmap(image1);
83 GroupPoints->PushButton2->setPixmap(image1);
84 GroupPoints->PushButton4->setPixmap(image1);
85 GroupPoints->PushButton5->setPixmap(image1);
86 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
87 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
89 Layout1->addWidget(GroupPoints, 2, 0);
90 /***************************************************************/
92 double SpecificStep = 5;
93 /* min, max, step and decimals for spin boxes & initial values */
94 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, 3);
95 GroupPoints->SpinBox_DX->SetValue(anAngle);
97 // Activate Create a Copy mode
98 GroupPoints->CheckButton1->setChecked(true);
99 CreateCopyModeChanged(true);
101 /* signals and slots connections */
102 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
103 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
104 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
106 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
107 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
108 connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
109 connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
112 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
114 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
115 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
116 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
118 connect(myGeomGUI->getApp()->selectionMgr(),
119 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
121 setHelpFileName("rotation.htm");
127 //=================================================================================
128 // function : ~TransformationGUI_RotationDlg()
129 // purpose : Destroys the object and frees any allocated resources
130 //=================================================================================
131 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
133 // no need to delete child widgets, Qt does it all for us
137 //=================================================================================
140 //=================================================================================
141 void TransformationGUI_RotationDlg::Init()
144 myEditCurrentArgument = GroupPoints->LineEdit1;
145 GroupPoints->LineEdit2->clear();
147 myAxis = myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
149 initName( tr( "GEOM_ROTATION" ) );
150 ConstructorsClicked( 0 );
153 //=================================================================================
154 // function : ConstructorsClicked()
155 // purpose : Radio button management
156 //=================================================================================
157 void TransformationGUI_RotationDlg::ConstructorsClicked(int constructorId)
159 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
161 myEditCurrentArgument = GroupPoints->LineEdit1;
164 switch (constructorId)
166 case 0: /* rotation an object angle and axis */
168 GroupPoints->ShowRows(2,3,false);
170 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
171 GroupPoints->LineEdit2->clear();
172 GroupPoints->ShowRows(4,4,true);
173 myAxis = GEOM::GEOM_Object::_nil();
176 case 1: /* rotation an object by 3 points */
178 GroupPoints->ShowRows(4,4,false);
180 GroupPoints->ShowRows(2,3,true);
181 GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
182 GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg("1"));
183 GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg("2"));
184 GroupPoints->LineEdit2->clear();
185 myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
190 myEditCurrentArgument->setFocus();
191 connect(myGeomGUI->getApp()->selectionMgr(),
192 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
195 //=================================================================================
196 // function : ClickOnOk()
198 //=================================================================================
199 void TransformationGUI_RotationDlg::ClickOnOk()
201 if ( ClickOnApply() )
206 //=================================================================================
207 // function : ClickOnApply()
209 //=================================================================================
210 bool TransformationGUI_RotationDlg::ClickOnApply()
212 if ( !onAccept( GroupPoints->CheckButton1->isChecked()) )
220 //=================================================================================
221 // function : SelectionIntoArgument()
222 // purpose : Called when selection as changed or other case
223 //=================================================================================
224 void TransformationGUI_RotationDlg::SelectionIntoArgument()
226 myEditCurrentArgument->setText("");
229 if(myEditCurrentArgument == GroupPoints->LineEdit1)
231 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
237 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
238 if (!myObjects.length())
243 if(IObjectCount() != 1)
245 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
246 myAxis = GEOM::GEOM_Object::_nil();
247 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
248 myCentPoint = GEOM::GEOM_Object::_nil();
249 else if(myEditCurrentArgument == GroupPoints->LineEdit4)
250 myPoint1 = GEOM::GEOM_Object::_nil();
251 else if(myEditCurrentArgument == GroupPoints->LineEdit5)
252 myPoint2 = GEOM::GEOM_Object::_nil();
256 Standard_Boolean testResult = Standard_False;
257 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
258 if(!testResult || CORBA::is_nil( aSelectedObject ))
261 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
262 myAxis = aSelectedObject;
263 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
264 myCentPoint = aSelectedObject;
265 else if(myEditCurrentArgument == GroupPoints->LineEdit4)
266 myPoint1 = aSelectedObject;
267 else if(myEditCurrentArgument == GroupPoints->LineEdit5)
268 myPoint2 = aSelectedObject;
270 aName = GEOMBase::GetName( aSelectedObject );
272 myEditCurrentArgument->setText( aName );
278 //=================================================================================
279 // function : SetEditCurrentArgument()
281 //=================================================================================
282 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
284 QPushButton* send = (QPushButton*)sender();
286 if(send == GroupPoints->PushButton1) {
287 myEditCurrentArgument = GroupPoints->LineEdit1;
290 else if(send == GroupPoints->PushButton2) {
291 myEditCurrentArgument = GroupPoints->LineEdit2;
292 getConstructorId() == 0 ? globalSelection( GEOM_LINE ) :
293 globalSelection( GEOM_POINT );
295 else if (send == GroupPoints->PushButton4)
297 myEditCurrentArgument = GroupPoints->LineEdit4;
298 globalSelection( GEOM_POINT );
300 else if (send == GroupPoints->PushButton5)
302 myEditCurrentArgument = GroupPoints->LineEdit5;
303 globalSelection( GEOM_POINT );
306 myEditCurrentArgument->setFocus();
307 SelectionIntoArgument();
311 //=================================================================================
312 // function : LineEditReturnPressed()
314 //=================================================================================
315 void TransformationGUI_RotationDlg::LineEditReturnPressed()
317 QLineEdit* send = (QLineEdit*)sender();
318 if(send == GroupPoints->LineEdit1 ||
319 send == GroupPoints->LineEdit2)
321 myEditCurrentArgument = send;
322 GEOMBase_Skeleton::LineEditReturnPressed();
327 //=================================================================================
328 // function : ActivateThisDialog()
330 //=================================================================================
331 void TransformationGUI_RotationDlg::ActivateThisDialog()
333 GEOMBase_Skeleton::ActivateThisDialog();
334 connect(myGeomGUI->getApp()->selectionMgr(),
335 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
337 ConstructorsClicked( getConstructorId() );
341 //=================================================================================
342 // function : enterEvent()
344 //=================================================================================
345 void TransformationGUI_RotationDlg::enterEvent(QEvent* e)
347 if (!GroupConstructors->isEnabled())
348 ActivateThisDialog();
352 //=================================================================================
353 // function : ValueChangedInSpinBox()
355 //=================================================================================
356 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
362 //=================================================================================
363 // function : createOperation
365 //=================================================================================
366 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
368 return getGeomEngine()->GetITransformOperations( getStudyId() );
372 //=================================================================================
373 // function : isValid
375 //=================================================================================
376 bool TransformationGUI_RotationDlg::isValid( QString& msg )
378 switch (getConstructorId())
382 return !(myObjects.length() == 0 || myAxis->_is_nil());
387 return !(myObjects.length() == 0 || myCentPoint->_is_nil() || myPoint1->_is_nil() || myPoint2->_is_nil() );
390 default: return false;
395 //=================================================================================
396 // function : execute
398 //=================================================================================
399 bool TransformationGUI_RotationDlg::execute( ObjectList& objects )
402 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
404 GEOM::GEOM_Object_var anObj;
406 switch ( getConstructorId() )
411 for (int i = 0; i < myObjects.length(); i++)
413 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 );
414 if ( !anObj->_is_nil() )
415 objects.push_back( anObj._retn() );
418 for (int i = 0; i < myObjects.length(); i++)
420 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->Rotate( myObjects[i], myAxis, GetAngle() * PI180 );
421 if ( !anObj->_is_nil() )
422 objects.push_back( anObj._retn() );
430 for (int i = 0; i < myObjects.length(); i++)
432 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateThreePointsCopy( myObjects[i], myCentPoint, myPoint1, myPoint2 );
433 if ( !anObj->_is_nil() )
434 objects.push_back( anObj._retn() );
437 for (int i = 0; i < myObjects.length(); i++)
439 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateThreePoints( myObjects[i], myCentPoint, myPoint1, myPoint2 );
440 if ( !anObj->_is_nil() )
441 objects.push_back( anObj._retn() );
452 //=================================================================================
453 // function : closeEvent
455 //=================================================================================
456 void TransformationGUI_RotationDlg::closeEvent( QCloseEvent* e )
458 GEOMBase_Skeleton::closeEvent( e );
462 //=================================================================================
463 // function : GetAngle()
465 //=================================================================================
466 double TransformationGUI_RotationDlg::GetAngle() const
468 return GroupPoints->SpinBox_DX->GetValue();
472 //=================================================================================
473 // function : CreateCopyModeChanged()
475 //=================================================================================
476 void TransformationGUI_RotationDlg::CreateCopyModeChanged(bool isCreateCopy)
478 this->GroupBoxName->setEnabled(isCreateCopy);
482 //=================================================================================
483 // function : onReverse()
485 //=================================================================================
486 void TransformationGUI_RotationDlg::onReverse()
488 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
489 GroupPoints->SpinBox_DX->SetValue( -anOldValue );