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"
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_MultiRotationDlg()
47 // purpose : Constructs a TransformationGUI_MultiRotationDlg 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_MultiRotationDlg::TransformationGUI_MultiRotationDlg
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_MULTIROTATION_SIMPLE")));
59 QPixmap image1(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_DOUBLE")));
60 QPixmap image2(aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
62 setCaption(tr("GEOM_MULTIROTATION_TITLE"));
64 /***************************************************************/
65 GroupConstructors->setTitle(tr("GEOM_MULTIROTATION"));
66 RadioButton1->setPixmap(image0);
67 RadioButton2->setPixmap(image1);
68 RadioButton3->close(TRUE);
70 GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
71 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_SIMPLE"));
72 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
73 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
74 GroupPoints->TextLabel3->setText(tr("GEOM_NB_TIMES"));
75 GroupPoints->PushButton1->setPixmap(image2);
76 GroupPoints->PushButton2->setPixmap(image2);
77 GroupPoints->LineEdit1->setReadOnly(true);
78 GroupPoints->LineEdit2->setReadOnly(true);
80 GroupDimensions = new DlgRef_2Sel4Spin1Check(this, "GroupDimensions");
81 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_DOUBLE"));
82 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
83 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR"));
84 GroupDimensions->TextLabel3->setText(tr("GEOM_ANGLE"));
85 GroupDimensions->TextLabel4->setText(tr("GEOM_NB_TIMES"));
86 GroupDimensions->TextLabel5->setText(tr("GEOM_STEP"));
87 GroupDimensions->TextLabel6->setText(tr("GEOM_NB_TIMES"));
88 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE"));
89 GroupDimensions->PushButton1->setPixmap(image2);
90 GroupDimensions->PushButton2->setPixmap(image2);
91 GroupDimensions->LineEdit1->setReadOnly(true);
92 GroupDimensions->LineEdit2->setReadOnly(true);
94 Layout1->addWidget(GroupPoints, 2, 0);
95 Layout1->addWidget(GroupDimensions, 2, 0);
96 /***************************************************************/
98 setHelpFileName("multi_rotation.htm");
104 //=================================================================================
105 // function : ~TransformationGUI_MultiRotationDlg()
106 // purpose : Destroys the object and frees any allocated resources
107 //=================================================================================
108 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
110 // no need to delete child widgets, Qt does it all for us
114 //=================================================================================
117 //=================================================================================
118 void TransformationGUI_MultiRotationDlg::Init()
120 /* Get setting of step value from file configuration */
121 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
122 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
124 double SpecificStep1 = 5;
125 double SpecificStep2 = 1;
126 /* min, max, step and decimals for spin boxes & initial values */
127 GroupPoints->SpinBox_DX->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
128 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
130 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(-999.999, 999.999, SpecificStep1, 3);
131 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
132 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(-999.999, 999.999, step, 3);
133 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
134 GroupDimensions->SpinBox_DX1->SetValue(myAng);
135 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
136 GroupDimensions->SpinBox_DX2->SetValue(myStep);
137 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
139 /* signals and slots connections */
140 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
141 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
142 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
144 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
150 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
151 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
152 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
154 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
155 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
156 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
157 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
158 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
160 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
161 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
162 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
163 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
164 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
166 connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseAngle()));
168 connect(myGeomGUI->getApp()->selectionMgr(),
169 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
171 initName( tr( "GEOM_MULTIROTATION" ) );
172 ConstructorsClicked( 0 );
176 //=================================================================================
177 // function : ConstructorsClicked()
178 // purpose : Radio button management
179 //=================================================================================
180 void TransformationGUI_MultiRotationDlg::ConstructorsClicked(int constructorId)
182 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
186 myNbTimes1 = myNbTimes2 = 2;
188 globalSelection( GEOM_ALLSHAPES );
190 switch (constructorId)
192 case 0: /* Rotate simple */
194 GroupDimensions->hide();
198 myEditCurrentArgument = GroupPoints->LineEdit1;
199 GroupPoints->LineEdit1->setText("");
200 GroupPoints->LineEdit2->setText("");
202 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
206 case 1: /* Rotate double */
210 GroupDimensions->show();
212 myEditCurrentArgument = GroupDimensions->LineEdit1;
213 GroupDimensions->LineEdit1->setText("");
214 GroupDimensions->LineEdit2->setText("");
216 GroupDimensions->SpinBox_DX1->SetValue(myAng);
217 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
218 GroupDimensions->SpinBox_DX2->SetValue(myStep);
219 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
225 myEditCurrentArgument->setFocus();
226 myBase = myVector = GEOM::GEOM_Object::_nil();
227 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
228 this, SLOT(SelectionIntoArgument()));
232 //=================================================================================
233 // function : ClickOnOk()
235 //=================================================================================
236 void TransformationGUI_MultiRotationDlg::ClickOnOk()
238 if ( ClickOnApply() )
243 //=================================================================================
244 // function : ClickOnApply()
246 //=================================================================================
247 bool TransformationGUI_MultiRotationDlg::ClickOnApply()
253 ConstructorsClicked( getConstructorId() );
258 //=================================================================================
259 // function : SelectionIntoArgument()
260 // purpose : Called when selection as changed or other case
261 //=================================================================================
262 void TransformationGUI_MultiRotationDlg::SelectionIntoArgument()
264 myEditCurrentArgument->setText("");
266 if (IObjectCount() != 1) {
267 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
268 myEditCurrentArgument == GroupDimensions->LineEdit1)
269 myBase = GEOM::GEOM_Object::_nil();
270 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
271 myEditCurrentArgument == GroupDimensions->LineEdit2)
272 myVector = GEOM::GEOM_Object::_nil();
277 Standard_Boolean testResult = Standard_False;;
278 GEOM::GEOM_Object_var aSelectedObject =
279 GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
281 if (!testResult || CORBA::is_nil(aSelectedObject) || !GEOMBase::IsShape(aSelectedObject))
284 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
285 myEditCurrentArgument == GroupDimensions->LineEdit1)
286 myBase = aSelectedObject;
287 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
288 myEditCurrentArgument == GroupDimensions->LineEdit2)
289 myVector = aSelectedObject;
291 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
297 //=================================================================================
298 // function : SetEditCurrentArgument()
300 //=================================================================================
301 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
303 QPushButton* send = (QPushButton*)sender();
305 if(send == GroupPoints->PushButton1) {
306 myEditCurrentArgument = GroupPoints->LineEdit1;
307 globalSelection( GEOM_ALLSHAPES );
309 else if(send == GroupPoints->PushButton2) {
310 myEditCurrentArgument = GroupPoints->LineEdit2;
311 globalSelection( GEOM_LINE );
313 else if(send == GroupDimensions->PushButton1) {
314 myEditCurrentArgument = GroupDimensions->LineEdit1;
315 globalSelection( GEOM_ALLSHAPES );
317 else if(send == GroupDimensions->PushButton2) {
318 myEditCurrentArgument = GroupDimensions->LineEdit2;
319 globalSelection( GEOM_LINE );
322 myEditCurrentArgument->setFocus();
323 SelectionIntoArgument();
327 //=================================================================================
328 // function : LineEditReturnPressed()
330 //=================================================================================
331 void TransformationGUI_MultiRotationDlg::LineEditReturnPressed()
333 QLineEdit* send = (QLineEdit*)sender();
334 if(send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
335 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2)
337 myEditCurrentArgument = send;
338 GEOMBase_Skeleton::LineEditReturnPressed();
343 //=================================================================================
344 // function : ActivateThisDialog()
346 //=================================================================================
347 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
349 GEOMBase_Skeleton::ActivateThisDialog();
350 connect(myGeomGUI->getApp()->selectionMgr(),
351 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
353 ConstructorsClicked( getConstructorId() );
357 //=================================================================================
358 // function : enterEvent()
360 //=================================================================================
361 void TransformationGUI_MultiRotationDlg::enterEvent(QEvent* e)
363 if(!GroupConstructors->isEnabled())
364 ActivateThisDialog();
368 //=================================================================================
369 // function : ValueChangedInSpinBox()
371 //=================================================================================
372 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox(double newValue)
374 QObject* send = (QObject*)sender();
376 if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1)
377 myNbTimes1 = (int)newValue;
378 else if(send == GroupDimensions->SpinBox_DX1)
380 else if(send == GroupDimensions->SpinBox_DX2)
382 else if(send == GroupDimensions->SpinBox_DY2)
383 myNbTimes2 = (int)newValue;
389 //=================================================================================
390 // function : ReverseAngle()
391 // purpose : 'state' not used here
392 //=================================================================================
393 void TransformationGUI_MultiRotationDlg::ReverseAngle()
397 int aConstructorId = getConstructorId();
399 if(aConstructorId == 0)
400 GroupPoints->SpinBox_DX->SetValue(myAng);
401 else if(aConstructorId == 1)
402 GroupDimensions->SpinBox_DX1->SetValue(myAng);
408 //=================================================================================
409 // function : createOperation
411 //=================================================================================
412 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiRotationDlg::createOperation()
414 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
418 //=================================================================================
419 // function : isValid
421 //=================================================================================
422 bool TransformationGUI_MultiRotationDlg::isValid( QString& msg )
424 return !(myBase->_is_nil() || myVector->_is_nil());
427 //=================================================================================
428 // function : execute
430 //=================================================================================
431 bool TransformationGUI_MultiRotationDlg::execute( ObjectList& objects )
435 GEOM::GEOM_Object_var anObj;
437 switch ( getConstructorId() )
441 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
442 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
443 MultiRotate1D( myBase, myVector, myNbTimes1 );
450 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) )
452 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
453 MultiRotate2D( myBase, myVector, myAng, myNbTimes1, myStep, myNbTimes2 );
460 if ( !anObj->_is_nil() )
461 objects.push_back( anObj._retn() );
467 //=================================================================================
468 // function : closeEvent
470 //=================================================================================
471 void TransformationGUI_MultiRotationDlg::closeEvent( QCloseEvent* e )
473 // myGeomGUI->SetState( -1 );
474 GEOMBase_Skeleton::closeEvent( e );