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 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_ROTATION")));
58 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
60 setCaption(tr("GEOM_ROTATION_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_ROTATION"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->close(TRUE);
66 RadioButton3->close(TRUE);
68 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
69 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
70 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
71 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
72 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
73 GroupPoints->LineEdit1->setReadOnly(true);
74 GroupPoints->LineEdit2->setReadOnly(true);
75 GroupPoints->PushButton1->setPixmap(image1);
76 GroupPoints->PushButton2->setPixmap(image1);
77 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
78 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
80 Layout1->addWidget(GroupPoints, 2, 0);
81 /***************************************************************/
83 double SpecificStep = 5;
84 /* min, max, step and decimals for spin boxes & initial values */
85 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, 3);
86 GroupPoints->SpinBox_DX->SetValue(anAngle);
88 // Activate Create a Copy mode
89 GroupPoints->CheckButton1->setChecked(true);
90 CreateCopyModeChanged(true);
92 /* signals and slots connections */
93 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
94 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
96 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
97 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
99 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
100 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
102 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
103 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
104 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
106 connect(myGeomGUI->getApp()->selectionMgr(),
107 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
109 setHelpFileName("rotation.htm");
115 //=================================================================================
116 // function : ~TransformationGUI_RotationDlg()
117 // purpose : Destroys the object and frees any allocated resources
118 //=================================================================================
119 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
121 // no need to delete child widgets, Qt does it all for us
125 //=================================================================================
128 //=================================================================================
129 void TransformationGUI_RotationDlg::Init()
132 myEditCurrentArgument = GroupPoints->LineEdit1;
133 GroupPoints->LineEdit2->clear();
135 myAxis = GEOM::GEOM_Object::_nil();
137 initName( tr( "GEOM_ROTATION" ) );
141 //=================================================================================
142 // function : ClickOnOk()
144 //=================================================================================
145 void TransformationGUI_RotationDlg::ClickOnOk()
147 if ( ClickOnApply() )
152 //=================================================================================
153 // function : ClickOnApply()
155 //=================================================================================
156 bool TransformationGUI_RotationDlg::ClickOnApply()
158 if ( !onAccept( GroupPoints->CheckButton1->isChecked()) )
166 //=================================================================================
167 // function : SelectionIntoArgument()
168 // purpose : Called when selection as changed or other case
169 //=================================================================================
170 void TransformationGUI_RotationDlg::SelectionIntoArgument()
172 myEditCurrentArgument->setText("");
175 if(myEditCurrentArgument == GroupPoints->LineEdit1)
177 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
183 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
184 if (!myObjects.length())
187 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
189 if(IObjectCount() != 1)
191 myAxis = GEOM::GEOM_Object::_nil();
194 Standard_Boolean testResult = Standard_False;
195 myAxis = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
196 if(!testResult || CORBA::is_nil( myAxis ))
198 aName = GEOMBase::GetName( myAxis );
200 myEditCurrentArgument->setText( aName );
206 //=================================================================================
207 // function : SetEditCurrentArgument()
209 //=================================================================================
210 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
212 QPushButton* send = (QPushButton*)sender();
214 if(send == GroupPoints->PushButton1) {
215 myEditCurrentArgument = GroupPoints->LineEdit1;
218 else if(send == GroupPoints->PushButton2) {
219 myEditCurrentArgument = GroupPoints->LineEdit2;
220 globalSelection( GEOM_LINE );
223 myEditCurrentArgument->setFocus();
224 SelectionIntoArgument();
228 //=================================================================================
229 // function : LineEditReturnPressed()
231 //=================================================================================
232 void TransformationGUI_RotationDlg::LineEditReturnPressed()
234 QLineEdit* send = (QLineEdit*)sender();
235 if(send == GroupPoints->LineEdit1 ||
236 send == GroupPoints->LineEdit2)
238 myEditCurrentArgument = send;
239 GEOMBase_Skeleton::LineEditReturnPressed();
244 //=================================================================================
245 // function : ActivateThisDialog()
247 //=================================================================================
248 void TransformationGUI_RotationDlg::ActivateThisDialog()
250 GEOMBase_Skeleton::ActivateThisDialog();
251 connect(myGeomGUI->getApp()->selectionMgr(),
252 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
254 GroupPoints->LineEdit1->setFocus();
255 myEditCurrentArgument = GroupPoints->LineEdit1;
256 GroupPoints->LineEdit2->clear();
257 myAxis = GEOM::GEOM_Object::_nil();
261 //=================================================================================
262 // function : enterEvent()
264 //=================================================================================
265 void TransformationGUI_RotationDlg::enterEvent(QEvent* e)
267 if (!GroupConstructors->isEnabled())
268 ActivateThisDialog();
272 //=================================================================================
273 // function : ValueChangedInSpinBox()
275 //=================================================================================
276 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
282 //=================================================================================
283 // function : createOperation
285 //=================================================================================
286 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
288 return getGeomEngine()->GetITransformOperations( getStudyId() );
292 //=================================================================================
293 // function : isValid
295 //=================================================================================
296 bool TransformationGUI_RotationDlg::isValid( QString& msg )
298 return !(myObjects.length() == 0 || myAxis->_is_nil());
302 //=================================================================================
303 // function : execute
305 //=================================================================================
306 bool TransformationGUI_RotationDlg::execute( ObjectList& objects )
310 GEOM::GEOM_Object_var anObj;
312 if (GroupPoints->CheckButton1->isChecked() || IsPreview())
313 for (int i = 0; i < myObjects.length(); i++)
315 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 );
316 if ( !anObj->_is_nil() )
317 objects.push_back( anObj._retn() );
320 for (int i = 0; i < myObjects.length(); i++)
322 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->Rotate( myObjects[i], myAxis, GetAngle() * PI180 );
323 if ( !anObj->_is_nil() )
324 objects.push_back( anObj._retn() );
332 //=================================================================================
333 // function : closeEvent
335 //=================================================================================
336 void TransformationGUI_RotationDlg::closeEvent( QCloseEvent* e )
338 GEOMBase_Skeleton::closeEvent( e );
342 //=================================================================================
343 // function : GetAngle()
345 //=================================================================================
346 double TransformationGUI_RotationDlg::GetAngle() const
348 return GroupPoints->SpinBox_DX->GetValue();
352 //=================================================================================
353 // function : CreateCopyModeChanged()
355 //=================================================================================
356 void TransformationGUI_RotationDlg::CreateCopyModeChanged(bool isCreateCopy)
358 this->GroupBoxName->setEnabled(isCreateCopy);
362 //=================================================================================
363 // function : onReverse()
365 //=================================================================================
366 void TransformationGUI_RotationDlg::onReverse()
368 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
369 GroupPoints->SpinBox_DX->SetValue( -anOldValue );