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 /***************************************************************/
93 double SpecificStep = 5;
94 /* min, max, step and decimals for spin boxes & initial values */
95 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
96 GroupPoints->SpinBox_DX->SetValue(anAngle);
98 // Activate Create a Copy mode
99 GroupPoints->CheckButton1->setChecked(true);
100 CreateCopyModeChanged(true);
102 /* signals and slots connections */
103 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
104 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
105 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
107 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
108 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
109 connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
110 connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
112 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
113 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
115 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
116 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
117 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
119 connect(myGeomGUI->getApp()->selectionMgr(),
120 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
122 setHelpFileName("rotation.htm");
128 //=================================================================================
129 // function : ~TransformationGUI_RotationDlg()
130 // purpose : Destroys the object and frees any allocated resources
131 //=================================================================================
132 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
134 // no need to delete child widgets, Qt does it all for us
138 //=================================================================================
141 //=================================================================================
142 void TransformationGUI_RotationDlg::Init()
145 myEditCurrentArgument = GroupPoints->LineEdit1;
146 GroupPoints->LineEdit2->clear();
148 myAxis = myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
150 initName( tr( "GEOM_ROTATION" ) );
151 ConstructorsClicked( 0 );
154 //=================================================================================
155 // function : ConstructorsClicked()
156 // purpose : Radio button management
157 //=================================================================================
158 void TransformationGUI_RotationDlg::ConstructorsClicked(int constructorId)
160 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
162 myEditCurrentArgument = GroupPoints->LineEdit1;
165 switch (constructorId)
167 case 0: /* rotation an object angle and axis */
169 GroupPoints->ShowRows(2,3,false);
171 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
172 GroupPoints->LineEdit2->clear();
173 GroupPoints->ShowRows(4,4,true);
174 myAxis = GEOM::GEOM_Object::_nil();
177 case 1: /* rotation an object by 3 points */
179 GroupPoints->ShowRows(4,4,false);
181 GroupPoints->ShowRows(2,3,true);
182 GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
183 GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg("1"));
184 GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg("2"));
185 GroupPoints->LineEdit2->clear();
186 GroupPoints->LineEdit4->clear();
187 GroupPoints->LineEdit5->clear();
188 myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
193 myEditCurrentArgument->setFocus();
194 connect(myGeomGUI->getApp()->selectionMgr(),
195 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
198 //=================================================================================
199 // function : ClickOnOk()
201 //=================================================================================
202 void TransformationGUI_RotationDlg::ClickOnOk()
204 if ( ClickOnApply() )
209 //=================================================================================
210 // function : ClickOnApply()
212 //=================================================================================
213 bool TransformationGUI_RotationDlg::ClickOnApply()
215 if ( !onAccept( GroupPoints->CheckButton1->isChecked()) )
219 ConstructorsClicked( getConstructorId() );
224 //=================================================================================
225 // function : SelectionIntoArgument()
226 // purpose : Called when selection as changed or other case
227 //=================================================================================
228 void TransformationGUI_RotationDlg::SelectionIntoArgument()
230 myEditCurrentArgument->setText("");
233 if(myEditCurrentArgument == GroupPoints->LineEdit1)
235 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
241 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
242 if (!myObjects.length())
247 if(IObjectCount() != 1)
249 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
250 myAxis = GEOM::GEOM_Object::_nil();
251 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
252 myCentPoint = GEOM::GEOM_Object::_nil();
253 else if(myEditCurrentArgument == GroupPoints->LineEdit4)
254 myPoint1 = GEOM::GEOM_Object::_nil();
255 else if(myEditCurrentArgument == GroupPoints->LineEdit5)
256 myPoint2 = GEOM::GEOM_Object::_nil();
260 Standard_Boolean testResult = Standard_False;
261 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
262 if(!testResult || CORBA::is_nil( aSelectedObject ))
265 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
266 myAxis = aSelectedObject;
267 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
268 myCentPoint = aSelectedObject;
269 else if(myEditCurrentArgument == GroupPoints->LineEdit4)
270 myPoint1 = aSelectedObject;
271 else if(myEditCurrentArgument == GroupPoints->LineEdit5)
272 myPoint2 = aSelectedObject;
274 aName = GEOMBase::GetName( aSelectedObject );
276 myEditCurrentArgument->setText( aName );
282 //=================================================================================
283 // function : SetEditCurrentArgument()
285 //=================================================================================
286 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
288 QPushButton* send = (QPushButton*)sender();
290 if(send == GroupPoints->PushButton1) {
291 myEditCurrentArgument = GroupPoints->LineEdit1;
294 else if(send == GroupPoints->PushButton2) {
295 myEditCurrentArgument = GroupPoints->LineEdit2;
296 getConstructorId() == 0 ? globalSelection( GEOM_LINE ) :
297 globalSelection( GEOM_POINT );
299 else if (send == GroupPoints->PushButton4)
301 myEditCurrentArgument = GroupPoints->LineEdit4;
302 globalSelection( GEOM_POINT );
304 else if (send == GroupPoints->PushButton5)
306 myEditCurrentArgument = GroupPoints->LineEdit5;
307 globalSelection( GEOM_POINT );
310 myEditCurrentArgument->setFocus();
311 SelectionIntoArgument();
315 //=================================================================================
316 // function : LineEditReturnPressed()
318 //=================================================================================
319 void TransformationGUI_RotationDlg::LineEditReturnPressed()
321 QLineEdit* send = (QLineEdit*)sender();
322 if(send == GroupPoints->LineEdit1 ||
323 send == GroupPoints->LineEdit2)
325 myEditCurrentArgument = send;
326 GEOMBase_Skeleton::LineEditReturnPressed();
331 //=================================================================================
332 // function : ActivateThisDialog()
334 //=================================================================================
335 void TransformationGUI_RotationDlg::ActivateThisDialog()
337 GEOMBase_Skeleton::ActivateThisDialog();
338 connect(myGeomGUI->getApp()->selectionMgr(),
339 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
341 ConstructorsClicked( getConstructorId() );
345 //=================================================================================
346 // function : enterEvent()
348 //=================================================================================
349 void TransformationGUI_RotationDlg::enterEvent(QEvent* e)
351 if (!GroupConstructors->isEnabled())
352 ActivateThisDialog();
356 //=================================================================================
357 // function : ValueChangedInSpinBox()
359 //=================================================================================
360 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
366 //=================================================================================
367 // function : createOperation
369 //=================================================================================
370 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
372 return getGeomEngine()->GetITransformOperations( getStudyId() );
376 //=================================================================================
377 // function : isValid
379 //=================================================================================
380 bool TransformationGUI_RotationDlg::isValid( QString& msg )
382 switch (getConstructorId())
386 return !(myObjects.length() == 0 || myAxis->_is_nil());
391 return !(myObjects.length() == 0 || myCentPoint->_is_nil() || myPoint1->_is_nil() || myPoint2->_is_nil() );
394 default: return false;
399 //=================================================================================
400 // function : execute
402 //=================================================================================
403 bool TransformationGUI_RotationDlg::execute( ObjectList& objects )
406 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
408 GEOM::GEOM_Object_var anObj;
410 switch ( getConstructorId() )
415 for (int i = 0; i < myObjects.length(); i++)
417 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
418 RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 );
419 if ( !anObj->_is_nil() )
420 objects.push_back( anObj._retn() );
423 for (int i = 0; i < myObjects.length(); i++)
425 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
426 Rotate( myObjects[i], myAxis, GetAngle() * PI180 );
427 if ( !anObj->_is_nil() )
428 objects.push_back( anObj._retn() );
436 for (int i = 0; i < myObjects.length(); i++)
438 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
439 RotateThreePointsCopy( myObjects[i], myCentPoint, myPoint1, myPoint2 );
440 if ( !anObj->_is_nil() )
441 objects.push_back( anObj._retn() );
444 for (int i = 0; i < myObjects.length(); i++)
446 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
447 RotateThreePoints( myObjects[i], myCentPoint, myPoint1, myPoint2 );
448 if ( !anObj->_is_nil() )
449 objects.push_back( anObj._retn() );
460 //=================================================================================
461 // function : closeEvent
463 //=================================================================================
464 void TransformationGUI_RotationDlg::closeEvent( QCloseEvent* e )
466 GEOMBase_Skeleton::closeEvent( e );
470 //=================================================================================
471 // function : GetAngle()
473 //=================================================================================
474 double TransformationGUI_RotationDlg::GetAngle() const
476 return GroupPoints->SpinBox_DX->GetValue();
480 //=================================================================================
481 // function : CreateCopyModeChanged()
483 //=================================================================================
484 void TransformationGUI_RotationDlg::CreateCopyModeChanged(bool isCreateCopy)
486 this->GroupBoxName->setEnabled(isCreateCopy);
490 //=================================================================================
491 // function : onReverse()
493 //=================================================================================
494 void TransformationGUI_RotationDlg::onReverse()
496 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
497 GroupPoints->SpinBox_DX->SetValue( -anOldValue );