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 "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_SelectionMgr.h"
38 #include "GEOMImpl_Types.hxx"
40 #include <qcheckbox.h>
42 #include "utilities.h"
46 //=================================================================================
47 // class : TransformationGUI_MultiTranslationDlg()
48 // purpose : Constructs a TransformationGUI_MultiTranslationDlg 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_MultiTranslationDlg::TransformationGUI_MultiTranslationDlg(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
54 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
56 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr("ICON_DLG_MULTITRANSLATION_SIMPLE")));
57 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr("ICON_DLG_MULTITRANSLATION_DOUBLE")));
58 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr("ICON_SELECT")));
60 setCaption(tr("GEOM_MULTITRANSLATION_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_MULTITRANSLATION"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->setPixmap(image1);
66 RadioButton3->close(TRUE);
68 GroupPoints = new DlgRef_2Sel2Spin1Check(this, "GroupPoints");
69 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_SIMPLE"));
70 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
71 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR_U"));
72 GroupPoints->TextLabel3->setText(tr("GEOM_STEP_U"));
73 GroupPoints->TextLabel4->setText(tr("GEOM_NB_TIMES_U"));
74 GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE_U"));
75 GroupPoints->PushButton1->setPixmap(image2);
76 GroupPoints->PushButton2->setPixmap(image2);
77 GroupPoints->LineEdit1->setReadOnly(true);
78 GroupPoints->LineEdit2->setReadOnly(true);
80 GroupDimensions = new DlgRef_3Sel4Spin2Check(this, "GroupDimensions");
81 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_DOUBLE"));
82 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
83 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR_U"));
84 GroupDimensions->TextLabel3->setText(tr("GEOM_VECTOR_V"));
85 GroupDimensions->TextLabel4->setText(tr("GEOM_STEP_U"));
86 GroupDimensions->TextLabel5->setText(tr("GEOM_NB_TIMES_U"));
87 GroupDimensions->TextLabel6->setText(tr("GEOM_STEP_V"));
88 GroupDimensions->TextLabel7->setText(tr("GEOM_NB_TIMES_V"));
89 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE_U"));
90 GroupDimensions->CheckButton2->setText(tr("GEOM_REVERSE_V"));
91 GroupDimensions->PushButton1->setPixmap(image2);
92 GroupDimensions->PushButton2->setPixmap(image2);
93 GroupDimensions->PushButton3->setPixmap(image2);
94 GroupDimensions->LineEdit1->setReadOnly(true);
95 GroupDimensions->LineEdit2->setReadOnly(true);
96 GroupDimensions->LineEdit3->setReadOnly(true);
98 Layout1->addWidget(GroupPoints, 2, 0);
99 Layout1->addWidget(GroupDimensions, 2, 0);
100 /***************************************************************/
106 //=================================================================================
107 // function : ~TransformationGUI_MultiTranslationDlg()
108 // purpose : Destroys the object and frees any allocated resources
109 //=================================================================================
110 TransformationGUI_MultiTranslationDlg::~TransformationGUI_MultiTranslationDlg()
112 // no need to delete child widgets, Qt does it all for us
116 //=================================================================================
119 //=================================================================================
120 void TransformationGUI_MultiTranslationDlg::Init()
122 /* Get setting of step value from file configuration */
123 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
124 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
126 double SpecificStep = 1;
127 /* min, max, step and decimals for spin boxes & initial values */
128 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
129 GroupPoints->SpinBox_DY->RangeStepAndValidator(1.0, 999.999, SpecificStep, 3);
130 GroupPoints->SpinBox_DX->SetValue(myStepU);
131 GroupPoints->SpinBox_DY->SetValue(myNbTimesU);
133 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(-999.999, 999.999, step, 3);
134 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, 999.999, SpecificStep, 3);
135 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(-999.999, 999.999, step, 3);
136 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, 999.999, SpecificStep, 3);
137 GroupDimensions->SpinBox_DX1->SetValue(myStepU);
138 GroupDimensions->SpinBox_DY1->SetValue(myNbTimesU);
139 GroupDimensions->SpinBox_DX2->SetValue(myStepV);
140 GroupDimensions->SpinBox_DY2->SetValue(myNbTimesV);
142 /* signals and slots connections */
143 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
144 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
145 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
147 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151 connect(GroupDimensions->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
153 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
154 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
155 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
156 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
157 connect(GroupDimensions->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
160 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
161 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
162 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
163 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
164 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
166 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
167 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
168 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
169 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
170 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
171 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
173 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
174 connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
175 connect(GroupDimensions->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(ReverseStepV()));
177 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
178 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
181 initName( tr( "GEOM_MULTITRANSLATION" ) );
182 ConstructorsClicked( 0 );
186 //=================================================================================
187 // function : ConstructorsClicked()
188 // purpose : Radio button management
189 //=================================================================================
190 void TransformationGUI_MultiTranslationDlg::ConstructorsClicked(int constructorId)
192 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
194 myStepU = myStepV = 50.0;
195 myNbTimesU = myNbTimesV = 2;
197 globalSelection( GEOM_ALLSHAPES );
199 switch (constructorId)
201 case 0: /* Translate simple */
203 GroupDimensions->hide();
207 myEditCurrentArgument = GroupPoints->LineEdit1;
208 GroupPoints->LineEdit1->setText("");
209 GroupPoints->LineEdit2->setText("");
211 GroupPoints->SpinBox_DX->SetValue(myStepU);
212 GroupPoints->SpinBox_DY->SetValue(myNbTimesU);
216 case 1: /* Translate double */
220 GroupDimensions->show();
222 myEditCurrentArgument = GroupDimensions->LineEdit1;
223 GroupDimensions->LineEdit1->setText("");
224 GroupDimensions->LineEdit2->setText("");
225 GroupDimensions->LineEdit3->setText("");
227 GroupDimensions->SpinBox_DX1->SetValue(myStepU);
228 GroupDimensions->SpinBox_DY1->SetValue(myNbTimesU);
229 GroupDimensions->SpinBox_DX2->SetValue(myStepV);
230 GroupDimensions->SpinBox_DY2->SetValue(myNbTimesV);
232 myVectorV = GEOM::GEOM_Object::_nil();
237 myEditCurrentArgument->setFocus();
238 myBase = myVectorU = GEOM::GEOM_Object::_nil();
239 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
240 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
244 //=================================================================================
245 // function : ClickOnOk()
247 //=================================================================================
248 void TransformationGUI_MultiTranslationDlg::ClickOnOk()
250 if ( ClickOnApply() )
255 //=================================================================================
256 // function : ClickOnApply()
258 //=================================================================================
259 bool TransformationGUI_MultiTranslationDlg::ClickOnApply()
265 ConstructorsClicked( getConstructorId() );
270 //=======================================================================
271 // function : ClickOnCancel()
273 //=======================================================================
274 void TransformationGUI_MultiTranslationDlg::ClickOnCancel()
276 GEOMBase_Skeleton::ClickOnCancel();
280 //=================================================================================
281 // function : SelectionIntoArgument()
282 // purpose : Called when selection as changed or other case
283 //=================================================================================
284 void TransformationGUI_MultiTranslationDlg::SelectionIntoArgument()
286 myEditCurrentArgument->setText("");
288 if(IObjectCount() != 1) {
289 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
290 myBase = GEOM::GEOM_Object::_nil();
291 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
292 myVectorU = GEOM::GEOM_Object::_nil();
293 else if(myEditCurrentArgument == GroupDimensions->LineEdit3)
294 myVectorV = GEOM::GEOM_Object::_nil();
299 Standard_Boolean testResult = Standard_False;;
300 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
302 if ( !testResult || CORBA::is_nil( aSelectedObject ) || !GEOMBase::IsShape( aSelectedObject ) )
305 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
306 myBase = aSelectedObject;
307 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
308 myVectorU = aSelectedObject;
309 else if(myEditCurrentArgument == GroupDimensions->LineEdit3)
310 myVectorV = aSelectedObject;
312 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
318 //=================================================================================
319 // function : SetEditCurrentArgument()
321 //=================================================================================
322 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
324 QPushButton* send = (QPushButton*)sender();
327 if(send == GroupPoints->PushButton1) {
328 myEditCurrentArgument = GroupPoints->LineEdit1;
329 globalSelection( GEOM_ALLSHAPES );
331 else if(send == GroupPoints->PushButton2) {
332 myEditCurrentArgument = GroupPoints->LineEdit2;
333 globalSelection( GEOM_LINE );
335 else if(send == GroupDimensions->PushButton1) {
336 myEditCurrentArgument = GroupDimensions->LineEdit1;
337 globalSelection( GEOM_ALLSHAPES );
339 else if(send == GroupDimensions->PushButton2) {
340 myEditCurrentArgument = GroupDimensions->LineEdit2;
341 globalSelection( GEOM_LINE );
343 else if(send == GroupDimensions->PushButton3) {
344 myEditCurrentArgument = GroupDimensions->LineEdit3;
345 globalSelection( GEOM_LINE );
348 myEditCurrentArgument->setFocus();
349 SelectionIntoArgument();
353 //=================================================================================
354 // function : LineEditReturnPressed()
356 //=================================================================================
357 void TransformationGUI_MultiTranslationDlg::LineEditReturnPressed()
359 QLineEdit* send = (QLineEdit*)sender();
360 if(send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
361 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2 ||
362 send == GroupDimensions->LineEdit3)
364 myEditCurrentArgument = send;
365 GEOMBase_Skeleton::LineEditReturnPressed();
370 //=================================================================================
371 // function : ActivateThisDialog()
373 //=================================================================================
374 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
376 GEOMBase_Skeleton::ActivateThisDialog();
377 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
378 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
380 ConstructorsClicked( getConstructorId() );
384 //=================================================================================
385 // function : DeactivateActiveDialog()
386 // purpose : public slot to deactivate if active
387 //=================================================================================
388 void TransformationGUI_MultiTranslationDlg::DeactivateActiveDialog()
390 GEOMBase_Skeleton::DeactivateActiveDialog();
394 //=================================================================================
395 // function : enterEvent()
397 //=================================================================================
398 void TransformationGUI_MultiTranslationDlg::enterEvent(QEvent* e)
400 if(!GroupConstructors->isEnabled())
401 ActivateThisDialog();
405 //=================================================================================
406 // function : ValueChangedInSpinBox()
408 //=================================================================================
409 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox(double newValue)
411 QObject* send = (QObject*)sender();
413 switch(getConstructorId())
417 if(send == GroupPoints->SpinBox_DX)
419 else if(send == GroupPoints->SpinBox_DY)
420 myNbTimesU = (int)newValue;
425 if(send == GroupDimensions->SpinBox_DX1)
427 else if(send == GroupDimensions->SpinBox_DY1)
428 myNbTimesU = (int)newValue;
429 else if(send == GroupDimensions->SpinBox_DX2)
431 else if(send == GroupDimensions->SpinBox_DY2)
432 myNbTimesV = (int)newValue;
441 //=================================================================================
442 // function : ReverseStepU()
443 // purpose : 'state' not used here
444 //=================================================================================
445 void TransformationGUI_MultiTranslationDlg::ReverseStepU()
449 int aConstructorId = getConstructorId();
451 if(aConstructorId == 0)
452 GroupPoints->SpinBox_DX->SetValue(myStepU);
453 else if(aConstructorId == 1)
454 GroupDimensions->SpinBox_DX1->SetValue(myStepU);
460 //=================================================================================
461 // function : ReverseStepV
462 // purpose : 'state' not used here
463 //=================================================================================
464 void TransformationGUI_MultiTranslationDlg::ReverseStepV()
468 GroupDimensions->SpinBox_DX2->SetValue(myStepV);
474 //=================================================================================
475 // function : createOperation
477 //=================================================================================
478 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiTranslationDlg::createOperation()
480 return myGeometryGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
484 //=================================================================================
485 // function : isValid
487 //=================================================================================
488 bool TransformationGUI_MultiTranslationDlg::isValid( QString& msg )
490 int aConstructorId = getConstructorId();
492 if(aConstructorId == 0)
493 return !(myBase->_is_nil() || myVectorU->_is_nil());
494 else if(aConstructorId == 1)
495 return !(myBase->_is_nil() || myVectorU->_is_nil() || myVectorV->_is_nil());
499 //=================================================================================
500 // function : execute
502 //=================================================================================
503 bool TransformationGUI_MultiTranslationDlg::execute( ObjectList& objects )
507 GEOM::GEOM_Object_var anObj;
509 switch ( getConstructorId() )
513 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) ) {
514 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate1D( myBase, myVectorU, myStepU, myNbTimesU );
521 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) && !CORBA::is_nil( myVectorV ) )
523 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate2D( myBase, myVectorU, myStepU, myNbTimesU,
524 myVectorV, myStepV, myNbTimesV );
531 if ( !anObj->_is_nil() )
532 objects.push_back( anObj._retn() );
538 //=================================================================================
539 // function : closeEvent
541 //=================================================================================
542 void TransformationGUI_MultiTranslationDlg::closeEvent( QCloseEvent* e )
544 // myGeomGUI->SetState( -1 );
545 GEOMBase_Skeleton::closeEvent( e );