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_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 "LightApp_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
54 (GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
55 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
56 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
58 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
59 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MULTITRANSLATION_SIMPLE")));
60 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MULTITRANSLATION_DOUBLE")));
61 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
63 setCaption(tr("GEOM_MULTITRANSLATION_TITLE"));
65 /***************************************************************/
66 GroupConstructors->setTitle(tr("GEOM_MULTITRANSLATION"));
67 RadioButton1->setPixmap(image0);
68 RadioButton2->setPixmap(image1);
69 RadioButton3->close(TRUE);
71 GroupPoints = new DlgRef_2Sel2Spin1Check(this, "GroupPoints");
72 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_SIMPLE"));
73 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
74 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR_U"));
75 GroupPoints->TextLabel3->setText(tr("GEOM_STEP_U"));
76 GroupPoints->TextLabel4->setText(tr("GEOM_NB_TIMES_U"));
77 GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE_U"));
78 GroupPoints->PushButton1->setPixmap(image2);
79 GroupPoints->PushButton2->setPixmap(image2);
80 GroupPoints->LineEdit1->setReadOnly(true);
81 GroupPoints->LineEdit2->setReadOnly(true);
83 GroupDimensions = new DlgRef_3Sel4Spin2Check(this, "GroupDimensions");
84 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_DOUBLE"));
85 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
86 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR_U"));
87 GroupDimensions->TextLabel3->setText(tr("GEOM_VECTOR_V"));
88 GroupDimensions->TextLabel4->setText(tr("GEOM_STEP_U"));
89 GroupDimensions->TextLabel5->setText(tr("GEOM_NB_TIMES_U"));
90 GroupDimensions->TextLabel6->setText(tr("GEOM_STEP_V"));
91 GroupDimensions->TextLabel7->setText(tr("GEOM_NB_TIMES_V"));
92 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE_U"));
93 GroupDimensions->CheckButton2->setText(tr("GEOM_REVERSE_V"));
94 GroupDimensions->PushButton1->setPixmap(image2);
95 GroupDimensions->PushButton2->setPixmap(image2);
96 GroupDimensions->PushButton3->setPixmap(image2);
97 GroupDimensions->LineEdit1->setReadOnly(true);
98 GroupDimensions->LineEdit2->setReadOnly(true);
99 GroupDimensions->LineEdit3->setReadOnly(true);
101 Layout1->addWidget(GroupPoints, 2, 0);
102 Layout1->addWidget(GroupDimensions, 2, 0);
103 /***************************************************************/
105 setHelpFileName("multi_translation.htm");
111 //=================================================================================
112 // function : ~TransformationGUI_MultiTranslationDlg()
113 // purpose : Destroys the object and frees any allocated resources
114 //=================================================================================
115 TransformationGUI_MultiTranslationDlg::~TransformationGUI_MultiTranslationDlg()
117 // no need to delete child widgets, Qt does it all for us
121 //=================================================================================
124 //=================================================================================
125 void TransformationGUI_MultiTranslationDlg::Init()
127 /* Get setting of step value from file configuration */
128 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
129 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
131 double SpecificStep = 1;
132 /* min, max, step and decimals for spin boxes & initial values */
133 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
134 GroupPoints->SpinBox_DY->RangeStepAndValidator(1.0, COORD_MAX, SpecificStep, 3);
135 GroupPoints->SpinBox_DX->SetValue(myStepU);
136 GroupPoints->SpinBox_DY->SetValue(myNbTimesU);
138 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
139 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, COORD_MAX, SpecificStep, 3);
140 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
141 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, COORD_MAX, SpecificStep, 3);
142 GroupDimensions->SpinBox_DX1->SetValue(myStepU);
143 GroupDimensions->SpinBox_DY1->SetValue(myNbTimesU);
144 GroupDimensions->SpinBox_DX2->SetValue(myStepV);
145 GroupDimensions->SpinBox_DY2->SetValue(myNbTimesV);
147 /* signals and slots connections */
148 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
149 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
150 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
152 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
153 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
155 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156 connect(GroupDimensions->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
160 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
161 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162 connect(GroupDimensions->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
164 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
165 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
166 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
167 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
168 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
169 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
171 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
172 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
173 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
174 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
175 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
176 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
178 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
179 connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
180 connect(GroupDimensions->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(ReverseStepV()));
182 connect(myGeomGUI->getApp()->selectionMgr(),
183 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
186 initName( tr( "GEOM_MULTITRANSLATION" ) );
187 ConstructorsClicked( 0 );
191 //=================================================================================
192 // function : ConstructorsClicked()
193 // purpose : Radio button management
194 //=================================================================================
195 void TransformationGUI_MultiTranslationDlg::ConstructorsClicked(int constructorId)
197 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
199 myStepU = myStepV = 50.0;
200 myNbTimesU = myNbTimesV = 2;
202 globalSelection( GEOM_ALLSHAPES );
204 switch (constructorId)
206 case 0: /* Translate simple */
208 GroupDimensions->hide();
212 myEditCurrentArgument = GroupPoints->LineEdit1;
213 GroupPoints->LineEdit1->setText("");
214 GroupPoints->LineEdit2->setText("");
216 GroupPoints->SpinBox_DX->SetValue(myStepU);
217 GroupPoints->SpinBox_DY->SetValue(myNbTimesU);
221 case 1: /* Translate double */
225 GroupDimensions->show();
227 myEditCurrentArgument = GroupDimensions->LineEdit1;
228 GroupDimensions->LineEdit1->setText("");
229 GroupDimensions->LineEdit2->setText("");
230 GroupDimensions->LineEdit3->setText("");
232 GroupDimensions->SpinBox_DX1->SetValue(myStepU);
233 GroupDimensions->SpinBox_DY1->SetValue(myNbTimesU);
234 GroupDimensions->SpinBox_DX2->SetValue(myStepV);
235 GroupDimensions->SpinBox_DY2->SetValue(myNbTimesV);
237 myVectorV = GEOM::GEOM_Object::_nil();
242 myEditCurrentArgument->setFocus();
243 myBase = myVectorU = GEOM::GEOM_Object::_nil();
244 connect(myGeomGUI->getApp()->selectionMgr(),
245 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
249 //=================================================================================
250 // function : ClickOnOk()
252 //=================================================================================
253 void TransformationGUI_MultiTranslationDlg::ClickOnOk()
255 if ( ClickOnApply() )
260 //=================================================================================
261 // function : ClickOnApply()
263 //=================================================================================
264 bool TransformationGUI_MultiTranslationDlg::ClickOnApply()
270 ConstructorsClicked( getConstructorId() );
275 //=================================================================================
276 // function : SelectionIntoArgument()
277 // purpose : Called when selection as changed or other case
278 //=================================================================================
279 void TransformationGUI_MultiTranslationDlg::SelectionIntoArgument()
281 myEditCurrentArgument->setText("");
283 if(IObjectCount() != 1) {
284 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
285 myBase = GEOM::GEOM_Object::_nil();
286 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
287 myVectorU = GEOM::GEOM_Object::_nil();
288 else if(myEditCurrentArgument == GroupDimensions->LineEdit3)
289 myVectorV = GEOM::GEOM_Object::_nil();
294 Standard_Boolean testResult = Standard_False;;
295 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
297 if ( !testResult || CORBA::is_nil( aSelectedObject ) || !GEOMBase::IsShape( aSelectedObject ) )
300 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
301 myBase = aSelectedObject;
302 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
303 myVectorU = aSelectedObject;
304 else if(myEditCurrentArgument == GroupDimensions->LineEdit3)
305 myVectorV = aSelectedObject;
307 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
313 //=================================================================================
314 // function : SetEditCurrentArgument()
316 //=================================================================================
317 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
319 QPushButton* send = (QPushButton*)sender();
322 if(send == GroupPoints->PushButton1) {
323 myEditCurrentArgument = GroupPoints->LineEdit1;
324 globalSelection( GEOM_ALLSHAPES );
326 else if(send == GroupPoints->PushButton2) {
327 myEditCurrentArgument = GroupPoints->LineEdit2;
328 globalSelection( GEOM_LINE );
330 else if(send == GroupDimensions->PushButton1) {
331 myEditCurrentArgument = GroupDimensions->LineEdit1;
332 globalSelection( GEOM_ALLSHAPES );
334 else if(send == GroupDimensions->PushButton2) {
335 myEditCurrentArgument = GroupDimensions->LineEdit2;
336 globalSelection( GEOM_LINE );
338 else if(send == GroupDimensions->PushButton3) {
339 myEditCurrentArgument = GroupDimensions->LineEdit3;
340 globalSelection( GEOM_LINE );
343 myEditCurrentArgument->setFocus();
344 SelectionIntoArgument();
348 //=================================================================================
349 // function : LineEditReturnPressed()
351 //=================================================================================
352 void TransformationGUI_MultiTranslationDlg::LineEditReturnPressed()
354 QLineEdit* send = (QLineEdit*)sender();
355 if(send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
356 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2 ||
357 send == GroupDimensions->LineEdit3)
359 myEditCurrentArgument = send;
360 GEOMBase_Skeleton::LineEditReturnPressed();
365 //=================================================================================
366 // function : ActivateThisDialog()
368 //=================================================================================
369 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
371 GEOMBase_Skeleton::ActivateThisDialog();
372 connect(myGeomGUI->getApp()->selectionMgr(),
373 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
375 ConstructorsClicked( getConstructorId() );
379 //=================================================================================
380 // function : enterEvent()
382 //=================================================================================
383 void TransformationGUI_MultiTranslationDlg::enterEvent(QEvent* e)
385 if(!GroupConstructors->isEnabled())
386 ActivateThisDialog();
390 //=================================================================================
391 // function : ValueChangedInSpinBox()
393 //=================================================================================
394 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox(double newValue)
396 QObject* send = (QObject*)sender();
398 switch(getConstructorId())
402 if(send == GroupPoints->SpinBox_DX)
404 else if(send == GroupPoints->SpinBox_DY)
405 myNbTimesU = (int)newValue;
410 if(send == GroupDimensions->SpinBox_DX1)
412 else if(send == GroupDimensions->SpinBox_DY1)
413 myNbTimesU = (int)newValue;
414 else if(send == GroupDimensions->SpinBox_DX2)
416 else if(send == GroupDimensions->SpinBox_DY2)
417 myNbTimesV = (int)newValue;
426 //=================================================================================
427 // function : ReverseStepU()
428 // purpose : 'state' not used here
429 //=================================================================================
430 void TransformationGUI_MultiTranslationDlg::ReverseStepU()
434 int aConstructorId = getConstructorId();
436 if(aConstructorId == 0)
437 GroupPoints->SpinBox_DX->SetValue(myStepU);
438 else if(aConstructorId == 1)
439 GroupDimensions->SpinBox_DX1->SetValue(myStepU);
445 //=================================================================================
446 // function : ReverseStepV
447 // purpose : 'state' not used here
448 //=================================================================================
449 void TransformationGUI_MultiTranslationDlg::ReverseStepV()
453 GroupDimensions->SpinBox_DX2->SetValue(myStepV);
459 //=================================================================================
460 // function : createOperation
462 //=================================================================================
463 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiTranslationDlg::createOperation()
465 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
469 //=================================================================================
470 // function : isValid
472 //=================================================================================
473 bool TransformationGUI_MultiTranslationDlg::isValid( QString& msg )
475 int aConstructorId = getConstructorId();
477 if(aConstructorId == 0)
478 return !(myBase->_is_nil() || myVectorU->_is_nil());
479 else if(aConstructorId == 1)
480 return !(myBase->_is_nil() || myVectorU->_is_nil() || myVectorV->_is_nil());
484 //=================================================================================
485 // function : execute
487 //=================================================================================
488 bool TransformationGUI_MultiTranslationDlg::execute( ObjectList& objects )
492 GEOM::GEOM_Object_var anObj;
494 switch ( getConstructorId() )
498 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) ) {
499 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate1D( myBase, myVectorU, myStepU, myNbTimesU );
506 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) && !CORBA::is_nil( myVectorV ) )
508 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate2D( myBase, myVectorU, myStepU, myNbTimesU,
509 myVectorV, myStepV, myNbTimesV );
516 if ( !anObj->_is_nil() )
517 objects.push_back( anObj._retn() );
523 //=================================================================================
524 // function : closeEvent
526 //=================================================================================
527 void TransformationGUI_MultiTranslationDlg::closeEvent( QCloseEvent* e )
529 // myGeomGUI->SetState( -1 );
530 GEOMBase_Skeleton::closeEvent( e );