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 "GEOMImpl_Types.hxx"
33 #include "QAD_Config.h"
34 #include "QAD_Desktop.h"
36 #include <qcheckbox.h>
38 #include "utilities.h"
42 //=================================================================================
43 // class : TransformationGUI_MultiRotationDlg()
44 // purpose : Constructs a TransformationGUI_MultiRotationDlg 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_MultiRotationDlg::TransformationGUI_MultiRotationDlg(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_MULTIROTATION_SIMPLE")));
53 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_DOUBLE")));
54 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
56 setCaption(tr("GEOM_MULTIROTATION_TITLE"));
58 /***************************************************************/
59 GroupConstructors->setTitle(tr("GEOM_MULTIROTATION"));
60 RadioButton1->setPixmap(image0);
61 RadioButton2->setPixmap(image1);
62 RadioButton3->close(TRUE);
64 GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
65 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_SIMPLE"));
66 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
67 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
68 GroupPoints->TextLabel3->setText(tr("GEOM_NB_TIMES"));
69 GroupPoints->PushButton1->setPixmap(image2);
70 GroupPoints->PushButton2->setPixmap(image2);
71 GroupPoints->LineEdit1->setReadOnly(true);
72 GroupPoints->LineEdit2->setReadOnly(true);
74 GroupDimensions = new DlgRef_2Sel4Spin1Check(this, "GroupDimensions");
75 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_DOUBLE"));
76 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
77 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR"));
78 GroupDimensions->TextLabel3->setText(tr("GEOM_ANGLE"));
79 GroupDimensions->TextLabel4->setText(tr("GEOM_NB_TIMES"));
80 GroupDimensions->TextLabel5->setText(tr("GEOM_STEP"));
81 GroupDimensions->TextLabel6->setText(tr("GEOM_NB_TIMES"));
82 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE"));
83 GroupDimensions->PushButton1->setPixmap(image2);
84 GroupDimensions->PushButton2->setPixmap(image2);
85 GroupDimensions->LineEdit1->setReadOnly(true);
86 GroupDimensions->LineEdit2->setReadOnly(true);
88 Layout1->addWidget(GroupPoints, 2, 0);
89 Layout1->addWidget(GroupDimensions, 2, 0);
90 /***************************************************************/
96 //=================================================================================
97 // function : ~TransformationGUI_MultiRotationDlg()
98 // purpose : Destroys the object and frees any allocated resources
99 //=================================================================================
100 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
102 // no need to delete child widgets, Qt does it all for us
106 //=================================================================================
109 //=================================================================================
110 void TransformationGUI_MultiRotationDlg::Init()
112 /* Get setting of step value from file configuration */
113 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
114 double step = St.toDouble();
116 double SpecificStep1 = 5;
117 double SpecificStep2 = 1;
118 /* min, max, step and decimals for spin boxes & initial values */
119 GroupPoints->SpinBox_DX->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
120 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
122 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(-999.999, 999.999, SpecificStep1, 3);
123 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
124 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(-999.999, 999.999, step, 3);
125 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
126 GroupDimensions->SpinBox_DX1->SetValue(myAng);
127 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
128 GroupDimensions->SpinBox_DX2->SetValue(myStep);
129 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
131 /* signals and slots connections */
132 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
133 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
134 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
136 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
143 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
144 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
147 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
148 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
149 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
150 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
152 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
153 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
154 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
155 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
156 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
158 connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseAngle()));
160 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
162 initName( tr( "GEOM_MULTIROTATION" ) );
163 ConstructorsClicked( 0 );
167 //=================================================================================
168 // function : ConstructorsClicked()
169 // purpose : Radio button management
170 //=================================================================================
171 void TransformationGUI_MultiRotationDlg::ConstructorsClicked(int constructorId)
173 disconnect(mySelection, 0, this, 0);
177 myNbTimes1 = myNbTimes2 = 2;
179 globalSelection( GEOM_ALLSHAPES );
181 switch (constructorId)
183 case 0: /* Rotate simple */
185 GroupDimensions->hide();
189 myEditCurrentArgument = GroupPoints->LineEdit1;
190 GroupPoints->LineEdit1->setText("");
191 GroupPoints->LineEdit2->setText("");
193 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
197 case 1: /* Rotate double */
201 GroupDimensions->show();
203 myEditCurrentArgument = GroupDimensions->LineEdit1;
204 GroupDimensions->LineEdit1->setText("");
205 GroupDimensions->LineEdit2->setText("");
207 GroupDimensions->SpinBox_DX1->SetValue(myAng);
208 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
209 GroupDimensions->SpinBox_DX2->SetValue(myStep);
210 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
216 myEditCurrentArgument->setFocus();
217 myBase = myVector = GEOM::GEOM_Object::_nil();
218 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
222 //=================================================================================
223 // function : ClickOnOk()
225 //=================================================================================
226 void TransformationGUI_MultiRotationDlg::ClickOnOk()
228 if ( ClickOnApply() )
233 //=================================================================================
234 // function : ClickOnApply()
236 //=================================================================================
237 bool TransformationGUI_MultiRotationDlg::ClickOnApply()
243 ConstructorsClicked( getConstructorId() );
248 //=======================================================================
249 // function : ClickOnCancel()
251 //=======================================================================
252 void TransformationGUI_MultiRotationDlg::ClickOnCancel()
254 GEOMBase_Skeleton::ClickOnCancel();
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(mySelection->IObjectCount() != 1) {
267 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
268 myBase = GEOM::GEOM_Object::_nil();
269 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
270 myVector = GEOM::GEOM_Object::_nil();
275 Standard_Boolean testResult = Standard_False;;
276 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), testResult );
278 if ( !testResult || CORBA::is_nil( aSelectedObject ) || !GEOMBase::IsShape( aSelectedObject ) )
282 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
283 myBase = aSelectedObject;
284 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
285 myVector = aSelectedObject;
287 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
293 //=================================================================================
294 // function : SetEditCurrentArgument()
296 //=================================================================================
297 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
299 QPushButton* send = (QPushButton*)sender();
301 if(send == GroupPoints->PushButton1) {
302 myEditCurrentArgument = GroupPoints->LineEdit1;
303 globalSelection( GEOM_ALLSHAPES );
305 else if(send == GroupPoints->PushButton2) {
306 myEditCurrentArgument = GroupPoints->LineEdit2;
307 globalSelection( GEOM_LINE );
309 else if(send == GroupDimensions->PushButton1) {
310 myEditCurrentArgument = GroupDimensions->LineEdit1;
311 globalSelection( GEOM_ALLSHAPES );
313 else if(send == GroupDimensions->PushButton2) {
314 myEditCurrentArgument = GroupDimensions->LineEdit2;
315 globalSelection( GEOM_LINE );
318 myEditCurrentArgument->setFocus();
319 SelectionIntoArgument();
323 //=================================================================================
324 // function : LineEditReturnPressed()
326 //=================================================================================
327 void TransformationGUI_MultiRotationDlg::LineEditReturnPressed()
329 QLineEdit* send = (QLineEdit*)sender();
330 if(send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
331 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2)
333 myEditCurrentArgument = send;
334 GEOMBase_Skeleton::LineEditReturnPressed();
339 //=================================================================================
340 // function : ActivateThisDialog()
342 //=================================================================================
343 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
345 GEOMBase_Skeleton::ActivateThisDialog();
346 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
348 ConstructorsClicked( getConstructorId() );
352 //=================================================================================
353 // function : DeactivateActiveDialog()
354 // purpose : public slot to deactivate if active
355 //=================================================================================
356 void TransformationGUI_MultiRotationDlg::DeactivateActiveDialog()
358 GEOMBase_Skeleton::DeactivateActiveDialog();
362 //=================================================================================
363 // function : enterEvent()
365 //=================================================================================
366 void TransformationGUI_MultiRotationDlg::enterEvent(QEvent* e)
368 if(!GroupConstructors->isEnabled())
369 ActivateThisDialog();
373 //=================================================================================
374 // function : ValueChangedInSpinBox()
376 //=================================================================================
377 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox(double newValue)
379 QObject* send = (QObject*)sender();
381 if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1)
382 myNbTimes1 = (int)newValue;
383 else if(send == GroupDimensions->SpinBox_DX1)
385 else if(send == GroupDimensions->SpinBox_DX2)
387 else if(send == GroupDimensions->SpinBox_DY2)
388 myNbTimes2 = (int)newValue;
394 //=================================================================================
395 // function : ReverseAngle()
396 // purpose : 'state' not used here
397 //=================================================================================
398 void TransformationGUI_MultiRotationDlg::ReverseAngle()
402 int aConstructorId = getConstructorId();
404 if(aConstructorId == 0)
405 GroupPoints->SpinBox_DX->SetValue(myAng);
406 else if(aConstructorId == 1)
407 GroupDimensions->SpinBox_DX1->SetValue(myAng);
413 //=================================================================================
414 // function : createOperation
416 //=================================================================================
417 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiRotationDlg::createOperation()
419 return getGeomEngine()->GetITransformOperations( getStudyId() );
423 //=================================================================================
424 // function : isValid
426 //=================================================================================
427 bool TransformationGUI_MultiRotationDlg::isValid( QString& msg )
429 return !(myBase->_is_nil() || myVector->_is_nil());
432 //=================================================================================
433 // function : execute
435 //=================================================================================
436 bool TransformationGUI_MultiRotationDlg::execute( ObjectList& objects )
440 GEOM::GEOM_Object_var anObj;
442 switch ( getConstructorId() )
446 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
447 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiRotate1D( myBase, myVector, myNbTimes1 );
454 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) )
456 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiRotate2D( myBase, myVector, myAng, myNbTimes1, myStep, myNbTimes2 );
463 if ( !anObj->_is_nil() )
464 objects.push_back( anObj._retn() );
470 //=================================================================================
471 // function : closeEvent
473 //=================================================================================
474 void TransformationGUI_MultiRotationDlg::closeEvent( QCloseEvent* e )
476 myGeomGUI->SetState( -1 );
477 GEOMBase_Skeleton::closeEvent( e );