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_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 "SalomeApp_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(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
55 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_SIMPLE")));
56 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_DOUBLE")));
57 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
59 setCaption(tr("GEOM_MULTIROTATION_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_MULTIROTATION"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->setPixmap(image1);
65 RadioButton3->close(TRUE);
67 GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
68 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_SIMPLE"));
69 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
70 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
71 GroupPoints->TextLabel3->setText(tr("GEOM_NB_TIMES"));
72 GroupPoints->PushButton1->setPixmap(image2);
73 GroupPoints->PushButton2->setPixmap(image2);
74 GroupPoints->LineEdit1->setReadOnly(true);
75 GroupPoints->LineEdit2->setReadOnly(true);
77 GroupDimensions = new DlgRef_2Sel4Spin1Check(this, "GroupDimensions");
78 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_DOUBLE"));
79 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
80 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR"));
81 GroupDimensions->TextLabel3->setText(tr("GEOM_ANGLE"));
82 GroupDimensions->TextLabel4->setText(tr("GEOM_NB_TIMES"));
83 GroupDimensions->TextLabel5->setText(tr("GEOM_STEP"));
84 GroupDimensions->TextLabel6->setText(tr("GEOM_NB_TIMES"));
85 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE"));
86 GroupDimensions->PushButton1->setPixmap(image2);
87 GroupDimensions->PushButton2->setPixmap(image2);
88 GroupDimensions->LineEdit1->setReadOnly(true);
89 GroupDimensions->LineEdit2->setReadOnly(true);
91 Layout1->addWidget(GroupPoints, 2, 0);
92 Layout1->addWidget(GroupDimensions, 2, 0);
93 /***************************************************************/
99 //=================================================================================
100 // function : ~TransformationGUI_MultiRotationDlg()
101 // purpose : Destroys the object and frees any allocated resources
102 //=================================================================================
103 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
105 // no need to delete child widgets, Qt does it all for us
109 //=================================================================================
112 //=================================================================================
113 void TransformationGUI_MultiRotationDlg::Init()
115 /* Get setting of step value from file configuration */
116 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
117 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
119 double SpecificStep1 = 5;
120 double SpecificStep2 = 1;
121 /* min, max, step and decimals for spin boxes & initial values */
122 GroupPoints->SpinBox_DX->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
123 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
125 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(-999.999, 999.999, SpecificStep1, 3);
126 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
127 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(-999.999, 999.999, step, 3);
128 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
129 GroupDimensions->SpinBox_DX1->SetValue(myAng);
130 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
131 GroupDimensions->SpinBox_DX2->SetValue(myStep);
132 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
134 /* signals and slots connections */
135 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
136 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
137 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
139 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
144 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
149 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
150 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
151 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
152 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
153 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
155 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
156 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
157 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
158 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
159 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
161 connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseAngle()));
163 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
164 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
166 initName( tr( "GEOM_MULTIROTATION" ) );
167 ConstructorsClicked( 0 );
171 //=================================================================================
172 // function : ConstructorsClicked()
173 // purpose : Radio button management
174 //=================================================================================
175 void TransformationGUI_MultiRotationDlg::ConstructorsClicked(int constructorId)
177 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
181 myNbTimes1 = myNbTimes2 = 2;
183 globalSelection( GEOM_ALLSHAPES );
185 switch (constructorId)
187 case 0: /* Rotate simple */
189 GroupDimensions->hide();
193 myEditCurrentArgument = GroupPoints->LineEdit1;
194 GroupPoints->LineEdit1->setText("");
195 GroupPoints->LineEdit2->setText("");
197 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
201 case 1: /* Rotate double */
205 GroupDimensions->show();
207 myEditCurrentArgument = GroupDimensions->LineEdit1;
208 GroupDimensions->LineEdit1->setText("");
209 GroupDimensions->LineEdit2->setText("");
211 GroupDimensions->SpinBox_DX1->SetValue(myAng);
212 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
213 GroupDimensions->SpinBox_DX2->SetValue(myStep);
214 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
220 myEditCurrentArgument->setFocus();
221 myBase = myVector = GEOM::GEOM_Object::_nil();
222 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
226 //=================================================================================
227 // function : ClickOnOk()
229 //=================================================================================
230 void TransformationGUI_MultiRotationDlg::ClickOnOk()
232 if ( ClickOnApply() )
237 //=================================================================================
238 // function : ClickOnApply()
240 //=================================================================================
241 bool TransformationGUI_MultiRotationDlg::ClickOnApply()
247 ConstructorsClicked( getConstructorId() );
252 //=======================================================================
253 // function : ClickOnCancel()
255 //=======================================================================
256 void TransformationGUI_MultiRotationDlg::ClickOnCancel()
258 GEOMBase_Skeleton::ClickOnCancel();
262 //=================================================================================
263 // function : SelectionIntoArgument()
264 // purpose : Called when selection as changed or other case
265 //=================================================================================
266 void TransformationGUI_MultiRotationDlg::SelectionIntoArgument()
268 myEditCurrentArgument->setText("");
270 if(IObjectCount() != 1) {
271 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
272 myBase = GEOM::GEOM_Object::_nil();
273 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
274 myVector = GEOM::GEOM_Object::_nil();
279 Standard_Boolean testResult = Standard_False;;
280 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
282 if ( !testResult || CORBA::is_nil( aSelectedObject ) || !GEOMBase::IsShape( aSelectedObject ) )
286 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
287 myBase = aSelectedObject;
288 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || 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(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
351 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
353 ConstructorsClicked( getConstructorId() );
357 //=================================================================================
358 // function : DeactivateActiveDialog()
359 // purpose : public slot to deactivate if active
360 //=================================================================================
361 void TransformationGUI_MultiRotationDlg::DeactivateActiveDialog()
363 GEOMBase_Skeleton::DeactivateActiveDialog();
367 //=================================================================================
368 // function : enterEvent()
370 //=================================================================================
371 void TransformationGUI_MultiRotationDlg::enterEvent(QEvent* e)
373 if(!GroupConstructors->isEnabled())
374 ActivateThisDialog();
378 //=================================================================================
379 // function : ValueChangedInSpinBox()
381 //=================================================================================
382 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox(double newValue)
384 QObject* send = (QObject*)sender();
386 if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1)
387 myNbTimes1 = (int)newValue;
388 else if(send == GroupDimensions->SpinBox_DX1)
390 else if(send == GroupDimensions->SpinBox_DX2)
392 else if(send == GroupDimensions->SpinBox_DY2)
393 myNbTimes2 = (int)newValue;
399 //=================================================================================
400 // function : ReverseAngle()
401 // purpose : 'state' not used here
402 //=================================================================================
403 void TransformationGUI_MultiRotationDlg::ReverseAngle()
407 int aConstructorId = getConstructorId();
409 if(aConstructorId == 0)
410 GroupPoints->SpinBox_DX->SetValue(myAng);
411 else if(aConstructorId == 1)
412 GroupDimensions->SpinBox_DX1->SetValue(myAng);
418 //=================================================================================
419 // function : createOperation
421 //=================================================================================
422 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiRotationDlg::createOperation()
424 return myGeometryGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
428 //=================================================================================
429 // function : isValid
431 //=================================================================================
432 bool TransformationGUI_MultiRotationDlg::isValid( QString& msg )
434 return !(myBase->_is_nil() || myVector->_is_nil());
437 //=================================================================================
438 // function : execute
440 //=================================================================================
441 bool TransformationGUI_MultiRotationDlg::execute( ObjectList& objects )
445 GEOM::GEOM_Object_var anObj;
447 switch ( getConstructorId() )
451 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
452 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiRotate1D( myBase, myVector, myNbTimes1 );
459 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) )
461 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiRotate2D( myBase, myVector, myAng, myNbTimes1, myStep, myNbTimes2 );
468 if ( !anObj->_is_nil() )
469 objects.push_back( anObj._retn() );
475 //=================================================================================
476 // function : closeEvent
478 //=================================================================================
479 void TransformationGUI_MultiRotationDlg::closeEvent( QCloseEvent* e )
481 // myGeomGUI->SetState( -1 );
482 GEOMBase_Skeleton::closeEvent( e );