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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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(QWidget* parent, const char* name, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_ROTATION")));
56 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_ROTATION_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_ROTATION"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->close(TRUE);
64 RadioButton3->close(TRUE);
66 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
67 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
69 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
70 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
71 GroupPoints->LineEdit1->setReadOnly(true);
72 GroupPoints->LineEdit2->setReadOnly(true);
73 GroupPoints->PushButton1->setPixmap(image1);
74 GroupPoints->PushButton2->setPixmap(image1);
75 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
76 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
78 Layout1->addWidget(GroupPoints, 2, 0);
79 /***************************************************************/
81 double SpecificStep = 5;
82 /* min, max, step and decimals for spin boxes & initial values */
83 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
84 GroupPoints->SpinBox_DX->SetValue(anAngle);
86 // Activate Create a Copy mode
87 GroupPoints->CheckButton1->setChecked(true);
88 CreateCopyModeChanged(true);
90 /* signals and slots connections */
91 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
92 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
94 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
95 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
97 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
98 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
100 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
101 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
102 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
104 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
105 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
111 //=================================================================================
112 // function : ~TransformationGUI_RotationDlg()
113 // purpose : Destroys the object and frees any allocated resources
114 //=================================================================================
115 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
117 // no need to delete child widgets, Qt does it all for us
121 //=================================================================================
124 //=================================================================================
125 void TransformationGUI_RotationDlg::Init()
128 myEditCurrentArgument = GroupPoints->LineEdit1;
129 GroupPoints->LineEdit2->clear();
131 myAxis = GEOM::GEOM_Object::_nil();
133 initName( tr( "GEOM_ROTATION" ) );
137 //=================================================================================
138 // function : ClickOnOk()
140 //=================================================================================
141 void TransformationGUI_RotationDlg::ClickOnOk()
143 if ( ClickOnApply() )
148 //=================================================================================
149 // function : ClickOnApply()
151 //=================================================================================
152 bool TransformationGUI_RotationDlg::ClickOnApply()
154 if ( !onAccept( GroupPoints->CheckButton1->isChecked()) )
162 //=======================================================================
163 // function : ClickOnCancel()
165 //=======================================================================
166 void TransformationGUI_RotationDlg::ClickOnCancel()
168 GEOMBase_Skeleton::ClickOnCancel();
172 //=================================================================================
173 // function : SelectionIntoArgument()
174 // purpose : Called when selection as changed or other case
175 //=================================================================================
176 void TransformationGUI_RotationDlg::SelectionIntoArgument()
178 myEditCurrentArgument->setText("");
181 if(myEditCurrentArgument == GroupPoints->LineEdit1)
183 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
189 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
190 if (!myObjects.length())
193 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
195 if(IObjectCount() != 1)
197 myAxis = GEOM::GEOM_Object::_nil();
200 Standard_Boolean testResult = Standard_False;
201 myAxis = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
202 if(!testResult || CORBA::is_nil( myAxis ))
204 aName = GEOMBase::GetName( myAxis );
206 myEditCurrentArgument->setText( aName );
212 //=================================================================================
213 // function : SetEditCurrentArgument()
215 //=================================================================================
216 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
218 QPushButton* send = (QPushButton*)sender();
220 if(send == GroupPoints->PushButton1) {
221 myEditCurrentArgument = GroupPoints->LineEdit1;
224 else if(send == GroupPoints->PushButton2) {
225 myEditCurrentArgument = GroupPoints->LineEdit2;
226 globalSelection( GEOM_LINE );
229 myEditCurrentArgument->setFocus();
230 SelectionIntoArgument();
234 //=================================================================================
235 // function : LineEditReturnPressed()
237 //=================================================================================
238 void TransformationGUI_RotationDlg::LineEditReturnPressed()
240 QLineEdit* send = (QLineEdit*)sender();
241 if(send == GroupPoints->LineEdit1 ||
242 send == GroupPoints->LineEdit2)
244 myEditCurrentArgument = send;
245 GEOMBase_Skeleton::LineEditReturnPressed();
250 //=================================================================================
251 // function : ActivateThisDialog()
253 //=================================================================================
254 void TransformationGUI_RotationDlg::ActivateThisDialog()
256 GEOMBase_Skeleton::ActivateThisDialog();
257 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
258 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
260 GroupPoints->LineEdit1->setFocus();
261 myEditCurrentArgument = GroupPoints->LineEdit1;
262 GroupPoints->LineEdit2->clear();
263 myAxis = GEOM::GEOM_Object::_nil();
267 //=================================================================================
268 // function : DeactivateActiveDialog()
269 // purpose : public slot to deactivate if active
270 //=================================================================================
271 void TransformationGUI_RotationDlg::DeactivateActiveDialog()
273 GEOMBase_Skeleton::DeactivateActiveDialog();
277 //=================================================================================
278 // function : enterEvent()
280 //=================================================================================
281 void TransformationGUI_RotationDlg::enterEvent(QEvent* e)
283 if (!GroupConstructors->isEnabled())
284 ActivateThisDialog();
288 //=================================================================================
289 // function : ValueChangedInSpinBox()
291 //=================================================================================
292 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
298 //=================================================================================
299 // function : createOperation
301 //=================================================================================
302 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
304 return getGeomEngine()->GetITransformOperations( getStudyId() );
308 //=================================================================================
309 // function : isValid
311 //=================================================================================
312 bool TransformationGUI_RotationDlg::isValid( QString& msg )
314 return !(myObjects.length() == 0 || myAxis->_is_nil());
318 //=================================================================================
319 // function : execute
321 //=================================================================================
322 bool TransformationGUI_RotationDlg::execute( ObjectList& objects )
326 GEOM::GEOM_Object_var anObj;
328 if (GroupPoints->CheckButton1->isChecked() || IsPreview())
329 for (int i = 0; i < myObjects.length(); i++)
331 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 );
332 if ( !anObj->_is_nil() )
333 objects.push_back( anObj._retn() );
336 for (int i = 0; i < myObjects.length(); i++)
338 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->Rotate( myObjects[i], myAxis, GetAngle() * PI180 );
339 if ( !anObj->_is_nil() )
340 objects.push_back( anObj._retn() );
348 //=================================================================================
349 // function : closeEvent
351 //=================================================================================
352 void TransformationGUI_RotationDlg::closeEvent( QCloseEvent* e )
354 GEOMBase_Skeleton::closeEvent( e );
358 //=================================================================================
359 // function : GetAngle()
361 //=================================================================================
362 double TransformationGUI_RotationDlg::GetAngle() const
364 return GroupPoints->SpinBox_DX->GetValue();
368 //=================================================================================
369 // function : CreateCopyModeChanged()
371 //=================================================================================
372 void TransformationGUI_RotationDlg::CreateCopyModeChanged(bool isCreateCopy)
374 this->GroupBoxName->setEnabled(isCreateCopy);
378 //=================================================================================
379 // function : onReverse()
381 //=================================================================================
382 void TransformationGUI_RotationDlg::onReverse()
384 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
385 GroupPoints->SpinBox_DX->SetValue( -anOldValue );