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"
30 #include <qcheckbox.h>
32 #include "QAD_Desktop.h"
34 #include "GEOMImpl_Types.hxx"
36 #include <qcheckbox.h>
38 #include "utilities.h"
42 //=================================================================================
43 // class : TransformationGUI_RotationDlg()
44 // purpose : Constructs a TransformationGUI_RotationDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 TransformationGUI_RotationDlg::TransformationGUI_RotationDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
50 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
52 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_ROTATION")));
53 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
55 setCaption(tr("GEOM_ROTATION_TITLE"));
57 /***************************************************************/
58 GroupConstructors->setTitle(tr("GEOM_ROTATION"));
59 RadioButton1->setPixmap(image0);
60 RadioButton2->close(TRUE);
61 RadioButton3->close(TRUE);
63 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
64 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
65 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
66 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
67 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
68 GroupPoints->LineEdit1->setReadOnly(true);
69 GroupPoints->LineEdit2->setReadOnly(true);
70 GroupPoints->PushButton1->setPixmap(image1);
71 GroupPoints->PushButton2->setPixmap(image1);
72 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
73 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
75 Layout1->addWidget(GroupPoints, 2, 0);
76 /***************************************************************/
78 double SpecificStep = 5;
79 /* min, max, step and decimals for spin boxes & initial values */
80 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
81 GroupPoints->SpinBox_DX->SetValue(anAngle);
83 // Activate Create a Copy mode
84 GroupPoints->CheckButton1->setChecked(true);
85 CreateCopyModeChanged(true);
87 /* signals and slots connections */
88 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
89 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
91 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
92 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
94 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
95 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
97 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
98 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
99 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
101 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
107 //=================================================================================
108 // function : ~TransformationGUI_RotationDlg()
109 // purpose : Destroys the object and frees any allocated resources
110 //=================================================================================
111 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
113 // no need to delete child widgets, Qt does it all for us
117 //=================================================================================
120 //=================================================================================
121 void TransformationGUI_RotationDlg::Init()
124 myEditCurrentArgument = GroupPoints->LineEdit1;
125 GroupPoints->LineEdit2->clear();
127 myAxis = GEOM::GEOM_Object::_nil();
129 initName( tr( "GEOM_ROTATION" ) );
133 //=================================================================================
134 // function : ClickOnOk()
136 //=================================================================================
137 void TransformationGUI_RotationDlg::ClickOnOk()
139 if ( ClickOnApply() )
144 //=================================================================================
145 // function : ClickOnApply()
147 //=================================================================================
148 bool TransformationGUI_RotationDlg::ClickOnApply()
150 if ( !onAccept( GroupPoints->CheckButton1->isChecked()) )
158 //=======================================================================
159 // function : ClickOnCancel()
161 //=======================================================================
162 void TransformationGUI_RotationDlg::ClickOnCancel()
164 GEOMBase_Skeleton::ClickOnCancel();
168 //=================================================================================
169 // function : SelectionIntoArgument()
170 // purpose : Called when selection as changed or other case
171 //=================================================================================
172 void TransformationGUI_RotationDlg::SelectionIntoArgument()
174 myEditCurrentArgument->setText("");
177 if(myEditCurrentArgument == GroupPoints->LineEdit1)
179 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(mySelection, aName);
185 GEOMBase::ConvertListOfIOInListOfGO(mySelection->StoredIObjects(), myObjects);
186 if (!myObjects.length())
189 aName = tr("%1_objects").arg(aNbSel);
191 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
193 if(mySelection->IObjectCount() != 1)
195 myAxis = GEOM::GEOM_Object::_nil();
198 Standard_Boolean testResult = Standard_False;
199 myAxis = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), testResult );
200 if(!testResult || CORBA::is_nil( myAxis ))
202 aName = GEOMBase::GetName( myAxis );
204 myEditCurrentArgument->setText( aName );
210 //=================================================================================
211 // function : SetEditCurrentArgument()
213 //=================================================================================
214 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
216 QPushButton* send = (QPushButton*)sender();
218 if(send == GroupPoints->PushButton1) {
219 myEditCurrentArgument = GroupPoints->LineEdit1;
222 else if(send == GroupPoints->PushButton2) {
223 myEditCurrentArgument = GroupPoints->LineEdit2;
224 globalSelection( GEOM_LINE );
227 myEditCurrentArgument->setFocus();
228 SelectionIntoArgument();
232 //=================================================================================
233 // function : LineEditReturnPressed()
235 //=================================================================================
236 void TransformationGUI_RotationDlg::LineEditReturnPressed()
238 QLineEdit* send = (QLineEdit*)sender();
239 if(send == GroupPoints->LineEdit1 ||
240 send == GroupPoints->LineEdit2)
242 myEditCurrentArgument = send;
243 GEOMBase_Skeleton::LineEditReturnPressed();
248 //=================================================================================
249 // function : ActivateThisDialog()
251 //=================================================================================
252 void TransformationGUI_RotationDlg::ActivateThisDialog()
254 GEOMBase_Skeleton::ActivateThisDialog();
255 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
257 GroupPoints->LineEdit1->setFocus();
258 myEditCurrentArgument = GroupPoints->LineEdit1;
259 GroupPoints->LineEdit2->clear();
260 myAxis = GEOM::GEOM_Object::_nil();
264 //=================================================================================
265 // function : DeactivateActiveDialog()
266 // purpose : public slot to deactivate if active
267 //=================================================================================
268 void TransformationGUI_RotationDlg::DeactivateActiveDialog()
270 GEOMBase_Skeleton::DeactivateActiveDialog();
274 //=================================================================================
275 // function : enterEvent()
277 //=================================================================================
278 void TransformationGUI_RotationDlg::enterEvent(QEvent* e)
280 if (!GroupConstructors->isEnabled())
281 ActivateThisDialog();
285 //=================================================================================
286 // function : ValueChangedInSpinBox()
288 //=================================================================================
289 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
295 //=================================================================================
296 // function : createOperation
298 //=================================================================================
299 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
301 return getGeomEngine()->GetITransformOperations( getStudyId() );
305 //=================================================================================
306 // function : isValid
308 //=================================================================================
309 bool TransformationGUI_RotationDlg::isValid( QString& msg )
311 return !(myObjects.length() == 0 || myAxis->_is_nil());
315 //=================================================================================
316 // function : execute
318 //=================================================================================
319 bool TransformationGUI_RotationDlg::execute( ObjectList& objects )
323 GEOM::GEOM_Object_var anObj;
325 if (GroupPoints->CheckButton1->isChecked() || IsPreview())
326 for (int i = 0; i < myObjects.length(); i++)
328 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 );
329 if ( !anObj->_is_nil() )
330 objects.push_back( anObj._retn() );
333 for (int i = 0; i < myObjects.length(); i++)
335 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->Rotate( myObjects[i], myAxis, GetAngle() * PI180 );
336 if ( !anObj->_is_nil() )
337 objects.push_back( anObj._retn() );
345 //=================================================================================
346 // function : closeEvent
348 //=================================================================================
349 void TransformationGUI_RotationDlg::closeEvent( QCloseEvent* e )
351 GEOMBase_Skeleton::closeEvent( e );
355 //=================================================================================
356 // function : GetAngle()
358 //=================================================================================
359 double TransformationGUI_RotationDlg::GetAngle() const
361 return GroupPoints->SpinBox_DX->GetValue();
365 //=================================================================================
366 // function : CreateCopyModeChanged()
368 //=================================================================================
369 void TransformationGUI_RotationDlg::CreateCopyModeChanged(bool isCreateCopy)
371 this->GroupBoxName->setEnabled(isCreateCopy);
375 //=================================================================================
376 // function : onReverse()
378 //=================================================================================
379 void TransformationGUI_RotationDlg::onReverse()
381 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
382 GroupPoints->SpinBox_DX->SetValue( -anOldValue );