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_MultiTranslationDlg.cxx
25 // Author : Damien COQUERET
29 #include "TransformationGUI_MultiTranslationDlg.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_MultiTranslationDlg()
44 // purpose : Constructs a TransformationGUI_MultiTranslationDlg 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_MultiTranslationDlg::TransformationGUI_MultiTranslationDlg(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_MULTITRANSLATION_SIMPLE")));
53 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_MULTITRANSLATION_DOUBLE")));
54 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
56 setCaption(tr("GEOM_MULTITRANSLATION_TITLE"));
58 /***************************************************************/
59 GroupConstructors->setTitle(tr("GEOM_MULTITRANSLATION"));
60 RadioButton1->setPixmap(image0);
61 RadioButton2->setPixmap(image1);
62 RadioButton3->close(TRUE);
64 GroupPoints = new DlgRef_2Sel2Spin1Check(this, "GroupPoints");
65 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_SIMPLE"));
66 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
67 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR_U"));
68 GroupPoints->TextLabel3->setText(tr("GEOM_STEP_U"));
69 GroupPoints->TextLabel4->setText(tr("GEOM_NB_TIMES_U"));
70 GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE_U"));
71 GroupPoints->PushButton1->setPixmap(image2);
72 GroupPoints->PushButton2->setPixmap(image2);
73 GroupPoints->LineEdit1->setReadOnly(true);
74 GroupPoints->LineEdit2->setReadOnly(true);
76 GroupDimensions = new DlgRef_3Sel4Spin2Check(this, "GroupDimensions");
77 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_DOUBLE"));
78 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
79 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR_U"));
80 GroupDimensions->TextLabel3->setText(tr("GEOM_VECTOR_V"));
81 GroupDimensions->TextLabel4->setText(tr("GEOM_STEP_U"));
82 GroupDimensions->TextLabel5->setText(tr("GEOM_NB_TIMES_U"));
83 GroupDimensions->TextLabel6->setText(tr("GEOM_STEP_V"));
84 GroupDimensions->TextLabel7->setText(tr("GEOM_NB_TIMES_V"));
85 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE_U"));
86 GroupDimensions->CheckButton2->setText(tr("GEOM_REVERSE_V"));
87 GroupDimensions->PushButton1->setPixmap(image2);
88 GroupDimensions->PushButton2->setPixmap(image2);
89 GroupDimensions->PushButton3->setPixmap(image2);
90 GroupDimensions->LineEdit1->setReadOnly(true);
91 GroupDimensions->LineEdit2->setReadOnly(true);
92 GroupDimensions->LineEdit3->setReadOnly(true);
94 Layout1->addWidget(GroupPoints, 2, 0);
95 Layout1->addWidget(GroupDimensions, 2, 0);
96 /***************************************************************/
102 //=================================================================================
103 // function : ~TransformationGUI_MultiTranslationDlg()
104 // purpose : Destroys the object and frees any allocated resources
105 //=================================================================================
106 TransformationGUI_MultiTranslationDlg::~TransformationGUI_MultiTranslationDlg()
108 // no need to delete child widgets, Qt does it all for us
112 //=================================================================================
115 //=================================================================================
116 void TransformationGUI_MultiTranslationDlg::Init()
118 /* Get setting of step value from file configuration */
119 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
120 double step = St.toDouble();
122 double SpecificStep = 1;
123 /* min, max, step and decimals for spin boxes & initial values */
124 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
125 GroupPoints->SpinBox_DY->RangeStepAndValidator(1.0, 999.999, SpecificStep, 3);
126 GroupPoints->SpinBox_DX->SetValue(myStepU);
127 GroupPoints->SpinBox_DY->SetValue(myNbTimesU);
129 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(-999.999, 999.999, step, 3);
130 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, 999.999, SpecificStep, 3);
131 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(-999.999, 999.999, step, 3);
132 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, 999.999, SpecificStep, 3);
133 GroupDimensions->SpinBox_DX1->SetValue(myStepU);
134 GroupDimensions->SpinBox_DY1->SetValue(myNbTimesU);
135 GroupDimensions->SpinBox_DX2->SetValue(myStepV);
136 GroupDimensions->SpinBox_DY2->SetValue(myNbTimesV);
138 /* signals and slots connections */
139 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
140 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
141 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
143 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
144 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147 connect(GroupDimensions->PushButton3, 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()));
153 connect(GroupDimensions->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
155 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
156 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
157 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
158 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
159 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
160 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
162 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
163 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
164 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
165 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
166 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
167 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
169 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
170 connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
171 connect(GroupDimensions->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(ReverseStepV()));
173 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
176 initName( tr( "GEOM_MULTITRANSLATION" ) );
177 ConstructorsClicked( 0 );
181 //=================================================================================
182 // function : ConstructorsClicked()
183 // purpose : Radio button management
184 //=================================================================================
185 void TransformationGUI_MultiTranslationDlg::ConstructorsClicked(int constructorId)
187 disconnect(mySelection, 0, this, 0);
189 myStepU = myStepV = 50.0;
190 myNbTimesU = myNbTimesV = 2;
194 switch (constructorId)
196 case 0: /* Translate simple */
198 GroupDimensions->hide();
202 myEditCurrentArgument = GroupPoints->LineEdit1;
203 GroupPoints->LineEdit1->setText("");
204 GroupPoints->LineEdit2->setText("");
206 GroupPoints->SpinBox_DX->SetValue(myStepU);
207 GroupPoints->SpinBox_DY->SetValue(myNbTimesU);
211 case 1: /* Translate double */
215 GroupDimensions->show();
217 myEditCurrentArgument = GroupDimensions->LineEdit1;
218 GroupDimensions->LineEdit1->setText("");
219 GroupDimensions->LineEdit2->setText("");
220 GroupDimensions->LineEdit3->setText("");
222 GroupDimensions->SpinBox_DX1->SetValue(myStepU);
223 GroupDimensions->SpinBox_DY1->SetValue(myNbTimesU);
224 GroupDimensions->SpinBox_DX2->SetValue(myStepV);
225 GroupDimensions->SpinBox_DY2->SetValue(myNbTimesV);
227 myVectorV = GEOM::GEOM_Object::_nil();
232 myEditCurrentArgument->setFocus();
233 myBase = myVectorU = GEOM::GEOM_Object::_nil();
234 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
238 //=================================================================================
239 // function : ClickOnOk()
241 //=================================================================================
242 void TransformationGUI_MultiTranslationDlg::ClickOnOk()
244 if ( ClickOnApply() )
249 //=================================================================================
250 // function : ClickOnApply()
252 //=================================================================================
253 bool TransformationGUI_MultiTranslationDlg::ClickOnApply()
259 ConstructorsClicked( getConstructorId() );
264 //=======================================================================
265 // function : ClickOnCancel()
267 //=======================================================================
268 void TransformationGUI_MultiTranslationDlg::ClickOnCancel()
270 GEOMBase_Skeleton::ClickOnCancel();
274 //=================================================================================
275 // function : SelectionIntoArgument()
276 // purpose : Called when selection as changed or other case
277 //=================================================================================
278 void TransformationGUI_MultiTranslationDlg::SelectionIntoArgument()
280 myEditCurrentArgument->setText("");
282 if(mySelection->IObjectCount() != 1) {
283 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
284 myBase = GEOM::GEOM_Object::_nil();
285 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
286 myVectorU = GEOM::GEOM_Object::_nil();
287 else if(myEditCurrentArgument == GroupDimensions->LineEdit3)
288 myVectorV = GEOM::GEOM_Object::_nil();
293 Standard_Boolean testResult = Standard_False;;
294 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), testResult );
296 if (!testResult || CORBA::is_nil( aSelectedObject ))
299 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
300 myBase = aSelectedObject;
301 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
302 myVectorU = aSelectedObject;
303 else if(myEditCurrentArgument == GroupDimensions->LineEdit3)
304 myVectorV = aSelectedObject;
306 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
312 //=================================================================================
313 // function : SetEditCurrentArgument()
315 //=================================================================================
316 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
318 QPushButton* send = (QPushButton*)sender();
321 if(send == GroupPoints->PushButton1) {
322 myEditCurrentArgument = GroupPoints->LineEdit1;
325 else if(send == GroupPoints->PushButton2) {
326 myEditCurrentArgument = GroupPoints->LineEdit2;
327 globalSelection( GEOM_LINE );
329 else if(send == GroupDimensions->PushButton1) {
330 myEditCurrentArgument = GroupDimensions->LineEdit1;
333 else if(send == GroupDimensions->PushButton2) {
334 myEditCurrentArgument = GroupDimensions->LineEdit2;
335 globalSelection( GEOM_LINE );
337 else if(send == GroupDimensions->PushButton3) {
338 myEditCurrentArgument = GroupDimensions->LineEdit3;
339 globalSelection( GEOM_LINE );
342 myEditCurrentArgument->setFocus();
343 SelectionIntoArgument();
347 //=================================================================================
348 // function : LineEditReturnPressed()
350 //=================================================================================
351 void TransformationGUI_MultiTranslationDlg::LineEditReturnPressed()
353 QLineEdit* send = (QLineEdit*)sender();
354 if(send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
355 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2 ||
356 send == GroupDimensions->LineEdit3)
358 myEditCurrentArgument = send;
359 GEOMBase_Skeleton::LineEditReturnPressed();
364 //=================================================================================
365 // function : ActivateThisDialog()
367 //=================================================================================
368 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
370 GEOMBase_Skeleton::ActivateThisDialog();
371 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
373 ConstructorsClicked( getConstructorId() );
377 //=================================================================================
378 // function : DeactivateActiveDialog()
379 // purpose : public slot to deactivate if active
380 //=================================================================================
381 void TransformationGUI_MultiTranslationDlg::DeactivateActiveDialog()
383 GEOMBase_Skeleton::DeactivateActiveDialog();
387 //=================================================================================
388 // function : enterEvent()
390 //=================================================================================
391 void TransformationGUI_MultiTranslationDlg::enterEvent(QEvent* e)
393 if(!GroupConstructors->isEnabled())
394 ActivateThisDialog();
398 //=================================================================================
399 // function : ValueChangedInSpinBox()
401 //=================================================================================
402 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox(double newValue)
404 QObject* send = (QObject*)sender();
406 switch(getConstructorId())
410 if(send == GroupPoints->SpinBox_DX)
412 else if(send == GroupPoints->SpinBox_DY)
413 myNbTimesU = (int)newValue;
418 if(send == GroupDimensions->SpinBox_DX1)
420 else if(send == GroupDimensions->SpinBox_DY1)
421 myNbTimesU = (int)newValue;
422 else if(send == GroupDimensions->SpinBox_DX2)
424 else if(send == GroupDimensions->SpinBox_DY2)
425 myNbTimesV = (int)newValue;
434 //=================================================================================
435 // function : ReverseStepU()
436 // purpose : 'state' not used here
437 //=================================================================================
438 void TransformationGUI_MultiTranslationDlg::ReverseStepU()
442 int aConstructorId = getConstructorId();
444 if(aConstructorId == 0)
445 GroupPoints->SpinBox_DX->SetValue(myStepU);
446 else if(aConstructorId == 1)
447 GroupDimensions->SpinBox_DX1->SetValue(myStepU);
453 //=================================================================================
454 // function : ReverseStepV
455 // purpose : 'state' not used here
456 //=================================================================================
457 void TransformationGUI_MultiTranslationDlg::ReverseStepV()
461 GroupDimensions->SpinBox_DX2->SetValue(myStepV);
467 //=================================================================================
468 // function : createOperation
470 //=================================================================================
471 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiTranslationDlg::createOperation()
473 return getGeomEngine()->GetITransformOperations( getStudyId() );
477 //=================================================================================
478 // function : isValid
480 //=================================================================================
481 bool TransformationGUI_MultiTranslationDlg::isValid( QString& msg )
483 int aConstructorId = getConstructorId();
485 if(aConstructorId == 0)
486 return !(myBase->_is_nil() || myVectorU->_is_nil());
487 else if(aConstructorId == 1)
488 return !(myBase->_is_nil() || myVectorU->_is_nil() || myVectorV->_is_nil());
492 //=================================================================================
493 // function : execute
495 //=================================================================================
496 bool TransformationGUI_MultiTranslationDlg::execute( ObjectList& objects )
500 GEOM::GEOM_Object_var anObj;
502 switch ( getConstructorId() )
506 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) ) {
507 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate1D( myBase, myVectorU, myStepU, myNbTimesU );
514 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) && !CORBA::is_nil( myVectorV ) )
516 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate2D( myBase, myVectorU, myStepU, myNbTimesU,
517 myVectorV, myStepV, myNbTimesV );
524 if ( !anObj->_is_nil() )
525 objects.push_back( anObj._retn() );
531 //=================================================================================
532 // function : closeEvent
534 //=================================================================================
535 void TransformationGUI_MultiTranslationDlg::closeEvent( QCloseEvent* e )
537 myGeomGUI->SetState( -1 );
538 GEOMBase_Skeleton::closeEvent( e );