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_MultiRotationDlg.cxx
25 // Author : Damien COQUERET
29 #include "TransformationGUI_MultiRotationDlg.h"
30 #include "DlgRef_2Sel4Spin1Check.h"
31 #include "DlgRef_2Sel1Spin.h"
32 #include "DlgRef_SpinBox.h"
34 #include "GeometryGUI.h"
37 #include "SUIT_ResourceMgr.h"
38 #include "SUIT_Session.h"
39 #include "SalomeApp_Application.h"
40 #include "LightApp_SelectionMgr.h"
42 #include "GEOMImpl_Types.hxx"
46 //=================================================================================
47 // class : TransformationGUI_MultiRotationDlg()
48 // purpose : Constructs a TransformationGUI_MultiRotationDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 TransformationGUI_MultiRotationDlg::TransformationGUI_MultiRotationDlg
54 (GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
55 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
57 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
58 QPixmap image0(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_SIMPLE")));
59 QPixmap image1(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_DOUBLE")));
60 QPixmap image2(aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
62 setWindowTitle(tr("GEOM_MULTIROTATION_TITLE"));
64 /***************************************************************/
65 GroupConstructors->setTitle(tr("GEOM_MULTIROTATION"));
66 RadioButton1->setIcon(image0);
67 RadioButton2->setIcon(image1);
68 RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
69 RadioButton3->close();
71 GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
72 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_SIMPLE"));
73 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
74 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
75 GroupPoints->TextLabel3->setText(tr("GEOM_NB_TIMES"));
76 GroupPoints->PushButton1->setIcon(image2);
77 GroupPoints->PushButton2->setIcon(image2);
78 GroupPoints->LineEdit1->setReadOnly(true);
79 GroupPoints->LineEdit2->setReadOnly(true);
81 GroupDimensions = new DlgRef_2Sel4Spin1Check(this, "GroupDimensions");
82 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_DOUBLE"));
83 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
84 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR"));
85 GroupDimensions->TextLabel3->setText(tr("GEOM_ANGLE"));
86 GroupDimensions->TextLabel4->setText(tr("GEOM_NB_TIMES"));
87 GroupDimensions->TextLabel5->setText(tr("GEOM_STEP"));
88 GroupDimensions->TextLabel6->setText(tr("GEOM_NB_TIMES"));
89 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE"));
90 GroupDimensions->PushButton1->setIcon(image2);
91 GroupDimensions->PushButton2->setIcon(image2);
92 GroupDimensions->LineEdit1->setReadOnly(true);
93 GroupDimensions->LineEdit2->setReadOnly(true);
95 gridLayout1->addWidget(GroupPoints, 2, 0);
96 gridLayout1->addWidget(GroupDimensions, 2, 0);
97 /***************************************************************/
99 setHelpFileName("multi_rotation.htm");
105 //=================================================================================
106 // function : ~TransformationGUI_MultiRotationDlg()
107 // purpose : Destroys the object and frees any allocated resources
108 //=================================================================================
109 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
111 // no need to delete child widgets, Qt does it all for us
115 //=================================================================================
118 //=================================================================================
119 void TransformationGUI_MultiRotationDlg::Init()
121 /* Get setting of step value from file configuration */
122 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
123 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
125 double SpecificStep1 = 5;
126 double SpecificStep2 = 1;
127 /* min, max, step and decimals for spin boxes & initial values */
128 GroupPoints->SpinBox_DX->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep2, 3);
129 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
131 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep1, 3);
132 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep2, 3);
133 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
134 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep2, 3);
135 GroupDimensions->SpinBox_DX1->SetValue(myAng);
136 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
137 GroupDimensions->SpinBox_DX2->SetValue(myStep);
138 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
140 /* signals and slots connections */
141 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
142 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
143 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
145 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
151 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
152 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
153 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
155 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
156 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
157 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
158 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
159 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
161 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
162 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
163 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
164 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
165 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
167 connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseAngle()));
169 connect(myGeomGUI->getApp()->selectionMgr(),
170 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
172 initName( tr( "GEOM_MULTIROTATION" ).toLatin1().constData() );
173 ConstructorsClicked( 0 );
177 //=================================================================================
178 // function : ConstructorsClicked()
179 // purpose : Radio button management
180 //=================================================================================
181 void TransformationGUI_MultiRotationDlg::ConstructorsClicked(int constructorId)
183 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
187 myNbTimes1 = myNbTimes2 = 2;
189 globalSelection( GEOM_ALLSHAPES );
191 switch (constructorId)
193 case 0: /* Rotate simple */
195 GroupDimensions->hide();
199 myEditCurrentArgument = GroupPoints->LineEdit1;
200 GroupPoints->LineEdit1->setText("");
201 GroupPoints->LineEdit2->setText("");
203 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
207 case 1: /* Rotate double */
211 GroupDimensions->show();
213 myEditCurrentArgument = GroupDimensions->LineEdit1;
214 GroupDimensions->LineEdit1->setText("");
215 GroupDimensions->LineEdit2->setText("");
217 GroupDimensions->SpinBox_DX1->SetValue(myAng);
218 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
219 GroupDimensions->SpinBox_DX2->SetValue(myStep);
220 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
226 myEditCurrentArgument->setFocus();
227 myBase = myVector = GEOM::GEOM_Object::_nil();
228 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
229 this, SLOT(SelectionIntoArgument()));
233 //=================================================================================
234 // function : ClickOnOk()
236 //=================================================================================
237 void TransformationGUI_MultiRotationDlg::ClickOnOk()
239 if ( ClickOnApply() )
244 //=================================================================================
245 // function : ClickOnApply()
247 //=================================================================================
248 bool TransformationGUI_MultiRotationDlg::ClickOnApply()
254 ConstructorsClicked( getConstructorId() );
259 //=================================================================================
260 // function : SelectionIntoArgument()
261 // purpose : Called when selection as changed or other case
262 //=================================================================================
263 void TransformationGUI_MultiRotationDlg::SelectionIntoArgument()
265 myEditCurrentArgument->setText("");
267 if (IObjectCount() != 1) {
268 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
269 myEditCurrentArgument == GroupDimensions->LineEdit1)
270 myBase = GEOM::GEOM_Object::_nil();
271 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
272 myEditCurrentArgument == GroupDimensions->LineEdit2)
273 myVector = GEOM::GEOM_Object::_nil();
278 Standard_Boolean testResult = Standard_False;;
279 GEOM::GEOM_Object_var aSelectedObject =
280 GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
282 if (!testResult || CORBA::is_nil(aSelectedObject) || !GEOMBase::IsShape(aSelectedObject))
285 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
286 myEditCurrentArgument == GroupDimensions->LineEdit1)
287 myBase = aSelectedObject;
288 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
289 myEditCurrentArgument == GroupDimensions->LineEdit2)
290 myVector = aSelectedObject;
292 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
298 //=================================================================================
299 // function : SetEditCurrentArgument()
301 //=================================================================================
302 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
304 QPushButton* send = (QPushButton*)sender();
306 if(send == GroupPoints->PushButton1) {
307 myEditCurrentArgument = GroupPoints->LineEdit1;
308 globalSelection( GEOM_ALLSHAPES );
310 else if(send == GroupPoints->PushButton2) {
311 myEditCurrentArgument = GroupPoints->LineEdit2;
312 globalSelection( GEOM_LINE );
314 else if(send == GroupDimensions->PushButton1) {
315 myEditCurrentArgument = GroupDimensions->LineEdit1;
316 globalSelection( GEOM_ALLSHAPES );
318 else if(send == GroupDimensions->PushButton2) {
319 myEditCurrentArgument = GroupDimensions->LineEdit2;
320 globalSelection( GEOM_LINE );
323 myEditCurrentArgument->setFocus();
324 SelectionIntoArgument();
328 //=================================================================================
329 // function : LineEditReturnPressed()
331 //=================================================================================
332 void TransformationGUI_MultiRotationDlg::LineEditReturnPressed()
334 QLineEdit* send = (QLineEdit*)sender();
335 if(send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
336 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2)
338 myEditCurrentArgument = send;
339 GEOMBase_Skeleton::LineEditReturnPressed();
344 //=================================================================================
345 // function : ActivateThisDialog()
347 //=================================================================================
348 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
350 GEOMBase_Skeleton::ActivateThisDialog();
351 connect(myGeomGUI->getApp()->selectionMgr(),
352 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
354 ConstructorsClicked( getConstructorId() );
358 //=================================================================================
359 // function : enterEvent()
361 //=================================================================================
362 void TransformationGUI_MultiRotationDlg::enterEvent(QEvent* e)
364 if(!GroupConstructors->isEnabled())
365 ActivateThisDialog();
369 //=================================================================================
370 // function : ValueChangedInSpinBox()
372 //=================================================================================
373 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox(double newValue)
375 QObject* send = (QObject*)sender();
377 if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1)
378 myNbTimes1 = (int)newValue;
379 else if(send == GroupDimensions->SpinBox_DX1)
381 else if(send == GroupDimensions->SpinBox_DX2)
383 else if(send == GroupDimensions->SpinBox_DY2)
384 myNbTimes2 = (int)newValue;
390 //=================================================================================
391 // function : ReverseAngle()
392 // purpose : 'state' not used here
393 //=================================================================================
394 void TransformationGUI_MultiRotationDlg::ReverseAngle()
398 int aConstructorId = getConstructorId();
400 if(aConstructorId == 0)
401 GroupPoints->SpinBox_DX->SetValue(myAng);
402 else if(aConstructorId == 1)
403 GroupDimensions->SpinBox_DX1->SetValue(myAng);
409 //=================================================================================
410 // function : createOperation
412 //=================================================================================
413 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiRotationDlg::createOperation()
415 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
419 //=================================================================================
420 // function : isValid
422 //=================================================================================
423 bool TransformationGUI_MultiRotationDlg::isValid( QString& msg )
425 return !(myBase->_is_nil() || myVector->_is_nil());
428 //=================================================================================
429 // function : execute
431 //=================================================================================
432 bool TransformationGUI_MultiRotationDlg::execute( ObjectList& objects )
436 GEOM::GEOM_Object_var anObj;
438 switch ( getConstructorId() )
442 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
443 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
444 MultiRotate1D( myBase, myVector, myNbTimes1 );
451 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) )
453 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
454 MultiRotate2D( myBase, myVector, myAng, myNbTimes1, myStep, myNbTimes2 );
461 if ( !anObj->_is_nil() )
462 objects.push_back( anObj._retn() );
468 //=================================================================================
469 // function : closeEvent
471 //=================================================================================
472 void TransformationGUI_MultiRotationDlg::closeEvent( QCloseEvent* e )
474 // myGeomGUI->SetState( -1 );
475 GEOMBase_Skeleton::closeEvent( e );