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_TranslationDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "TransformationGUI_TranslationDlg.h"
31 #include "QAD_Config.h"
32 #include "QAD_Desktop.h"
34 #include <qcheckbox.h>
36 #include "GEOMImpl_Types.hxx"
38 #include "utilities.h"
42 //=================================================================================
43 // class : TransformationGUI_TranslationDlg()
44 // purpose : Constructs a TransformationGUI_TranslationDlg 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_TranslationDlg::TransformationGUI_TranslationDlg(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_TRANSLATION_DXYZ")));
53 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_TRANSLATION_POINTS")));
54 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_TRANSLATION_VECTOR")));
55 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
57 setCaption(tr("GEOM_TRANSLATION_TITLE"));
59 /***************************************************************/
60 GroupConstructors->setTitle(tr("GEOM_TRANSLATION"));
61 RadioButton1->setPixmap(image0);
62 RadioButton2->setPixmap(image1);
63 RadioButton3->setPixmap(image2);
65 RadioButton1->setChecked(true);
67 GroupPoints = new DlgRef_3Sel3Spin1Check(this, "GroupPoints");
68 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
69 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
70 GroupPoints->TextLabel3->setText(tr("GEOM_POINT_I").arg("2"));
71 GroupPoints->TextLabel4->setText(tr("GEOM_DX"));
72 GroupPoints->TextLabel5->setText(tr("GEOM_DY"));
73 GroupPoints->TextLabel6->setText(tr("GEOM_DZ"));
74 GroupPoints->PushButton1->setPixmap(image3);
75 GroupPoints->PushButton2->setPixmap(image3);
76 GroupPoints->PushButton3->setPixmap(image3);
77 GroupPoints->CheckBox1->setText(tr("GEOM_CREATE_COPY"));
79 Layout1->addWidget(GroupPoints, 2, 0);
80 /***************************************************************/
86 //=================================================================================
87 // function : ~TransformationGUI_TranslationDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 TransformationGUI_TranslationDlg::~TransformationGUI_TranslationDlg()
92 // no need to delete child widgets, Qt does it all for us
96 //=================================================================================
99 //=================================================================================
100 void TransformationGUI_TranslationDlg::Init()
103 myEditCurrentArgument = GroupPoints->LineEdit1;
104 GroupPoints->LineEdit1->setReadOnly(true);
105 GroupPoints->LineEdit2->setReadOnly(true);
106 GroupPoints->LineEdit3->setReadOnly(true);
108 myVector = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
110 // Activate Create a Copy mode
111 GroupPoints->CheckBox1->setChecked(true);
112 CreateCopyModeChanged(true);
114 /* Get setting of step value from file configuration */
115 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
116 double step = St.toDouble();
118 /* min, max, step and decimals for spin boxes & initial values */
119 GroupPoints->SpinBox1->RangeStepAndValidator(-999.999, 999.999, step, 3);
120 GroupPoints->SpinBox2->RangeStepAndValidator(-999.999, 999.999, step, 3);
121 GroupPoints->SpinBox3->RangeStepAndValidator(-999.999, 999.999, step, 3);
123 GroupPoints->SpinBox1->SetValue(0.0);
124 GroupPoints->SpinBox2->SetValue(0.0);
125 GroupPoints->SpinBox3->SetValue(0.0);
127 /* signals and slots connections */
128 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
129 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
130 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
132 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
134 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); // MZN: Delete ?
138 connect(GroupPoints->SpinBox1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
139 connect(GroupPoints->SpinBox2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
140 connect(GroupPoints->SpinBox3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
142 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox1, SLOT(SetStep(double)));
143 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox2, SLOT(SetStep(double)));
144 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox3, SLOT(SetStep(double)));
146 connect(GroupPoints->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
148 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
150 initName( tr( "GEOM_TRANSLATION" ) );
151 ConstructorsClicked( 0 );
155 //=================================================================================
156 // function : ConstructorsClicked()
157 // purpose : Radio button management
158 //=================================================================================
159 void TransformationGUI_TranslationDlg::ConstructorsClicked(int constructorId)
161 disconnect( mySelection, 0, this, 0 );
163 myEditCurrentArgument = GroupPoints->LineEdit1;
166 switch (constructorId)
168 case 0: /* translation an object by dx, dy, dz */
170 GroupPoints->ShowRows(1,2,false);
172 GroupPoints->ShowRows(3,5,true);
175 case 1: /* translation an object by 2 points */
177 GroupPoints->ShowRows(3,5,false);
179 GroupPoints->ShowRows(0,2,true);
180 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("1"));
181 GroupPoints->LineEdit2->clear();
182 GroupPoints->LineEdit3->clear();
183 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
186 case 2: /* translation an object by vector */
188 GroupPoints->ShowRows(2,5,false);
190 GroupPoints->ShowRows(0,1,true);
191 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
192 GroupPoints->LineEdit2->clear();
193 myVector = GEOM::GEOM_Object::_nil();
198 myEditCurrentArgument->setFocus();
199 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
203 //=================================================================================
204 // function : ClickOnOk()
206 //=================================================================================
207 void TransformationGUI_TranslationDlg::ClickOnOk()
209 if ( ClickOnApply() )
214 //=================================================================================
215 // function : ClickOnApply()
217 //=================================================================================
218 bool TransformationGUI_TranslationDlg::ClickOnApply()
220 if ( !onAccept(GroupPoints->CheckBox1->isChecked()) )
224 ConstructorsClicked( getConstructorId() );
229 //=======================================================================
230 // function : ClickOnCancel()
232 //=======================================================================
233 void TransformationGUI_TranslationDlg::ClickOnCancel()
235 GEOMBase_Skeleton::ClickOnCancel();
239 //=================================================================================
240 // function : SelectionIntoArgument()
241 // purpose : Called when selection as changed or other case
242 //=================================================================================
243 void TransformationGUI_TranslationDlg::SelectionIntoArgument()
245 myEditCurrentArgument->setText("");
248 if(myEditCurrentArgument == GroupPoints->LineEdit1)
250 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(mySelection, aName);
256 GEOMBase::ConvertListOfIOInListOfGO(mySelection->StoredIObjects(), myObjects);
257 if (!myObjects.length())
260 aName = tr("%1_objects").arg(aNbSel);
264 if (mySelection->IObjectCount() != 1) {
265 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
266 myPoint1 = GEOM::GEOM_Object::_nil();
267 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
268 myVector = GEOM::GEOM_Object::_nil();
269 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
270 myPoint2 = GEOM::GEOM_Object::_nil();
274 Standard_Boolean testResult = Standard_False;;
275 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), testResult );
277 if (!testResult || CORBA::is_nil( aSelectedObject ))
280 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
281 myPoint1 = aSelectedObject;
282 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
283 myVector = aSelectedObject;
284 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
285 myPoint2 = aSelectedObject;
287 aName = GEOMBase::GetName( aSelectedObject );
290 myEditCurrentArgument->setText( aName );
296 //=================================================================================
297 // function : LineEditReturnPressed()
299 //=================================================================================
300 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
302 QLineEdit* send = (QLineEdit*)sender();
303 if(send == GroupPoints->LineEdit1)
305 myEditCurrentArgument = send;
306 GEOMBase_Skeleton::LineEditReturnPressed();
311 //=================================================================================
312 // function : SetEditCurrentArgument()
314 //=================================================================================
315 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
317 QPushButton* send = (QPushButton*)sender();
319 if(send == GroupPoints->PushButton1)
321 myEditCurrentArgument = GroupPoints->LineEdit1;
324 else if (send == GroupPoints->PushButton2)
326 myEditCurrentArgument = GroupPoints->LineEdit2;
327 getConstructorId() == 1 ? globalSelection( GEOM_POINT ) :
328 globalSelection( GEOM_LINE );
330 else if (send == GroupPoints->PushButton3)
332 myEditCurrentArgument = GroupPoints->LineEdit3;
333 globalSelection( GEOM_POINT );
336 myEditCurrentArgument->setFocus();
337 SelectionIntoArgument();
341 //=================================================================================
342 // function : ActivateThisDialog()
344 //=================================================================================
345 void TransformationGUI_TranslationDlg::ActivateThisDialog()
347 GEOMBase_Skeleton::ActivateThisDialog();
348 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
350 ConstructorsClicked( getConstructorId() );
354 //=================================================================================
355 // function : DeactivateActiveDialog()
356 // purpose : public slot to deactivate if active
357 //=================================================================================
358 void TransformationGUI_TranslationDlg::DeactivateActiveDialog()
360 GEOMBase_Skeleton::DeactivateActiveDialog();
364 //=================================================================================
365 // function : enterEvent()
367 //=================================================================================
368 void TransformationGUI_TranslationDlg::enterEvent(QEvent* e)
370 if(!GroupConstructors->isEnabled())
371 ActivateThisDialog();
375 //=================================================================================
376 // function : ValueChangedInSpinBox()
378 //=================================================================================
379 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox()
385 //=================================================================================
386 // function : createOperation
388 //=================================================================================
389 GEOM::GEOM_IOperations_ptr TransformationGUI_TranslationDlg::createOperation()
391 return getGeomEngine()->GetITransformOperations( getStudyId() );
395 //=================================================================================
396 // function : isValid
398 //=================================================================================
399 bool TransformationGUI_TranslationDlg::isValid( QString& msg )
401 int aConstructorId = getConstructorId();
403 switch (aConstructorId)
407 return !(myObjects.length() == 0 );
412 return !(myObjects.length() == 0 || myPoint1->_is_nil() || myPoint2->_is_nil() );
417 return !(myObjects.length() == 0 || myVector->_is_nil());
420 default: return false;
424 //=================================================================================
425 // function : execute
427 //=================================================================================
428 bool TransformationGUI_TranslationDlg::execute( ObjectList& objects )
431 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox1->isChecked();
433 GEOM::GEOM_Object_var anObj;
435 switch ( getConstructorId() )
439 double dx = GroupPoints->SpinBox1->GetValue();
440 double dy = GroupPoints->SpinBox2->GetValue();
441 double dz = GroupPoints->SpinBox3->GetValue();
444 for (int i = 0; i < myObjects.length(); i++)
446 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZCopy( myObjects[i], dx, dy, dz );
447 if ( !anObj->_is_nil() )
448 objects.push_back( anObj._retn() );
451 for (int i = 0; i < myObjects.length(); i++)
453 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZ( myObjects[i], dx, dy, dz );
454 if ( !anObj->_is_nil() )
455 objects.push_back( anObj._retn() );
463 for (int i = 0; i < myObjects.length(); i++)
465 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPointsCopy( myObjects[i], myPoint1, myPoint2 );
466 if ( !anObj->_is_nil() )
467 objects.push_back( anObj._retn() );
470 for (int i = 0; i < myObjects.length(); i++)
472 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPoints( myObjects[i], myPoint1, myPoint2 );
473 if ( !anObj->_is_nil() )
474 objects.push_back( anObj._retn() );
482 for (int i = 0; i < myObjects.length(); i++)
484 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateVectorCopy( myObjects[i], myVector );
485 if ( !anObj->_is_nil() )
486 objects.push_back( anObj._retn() );
489 for (int i = 0; i < myObjects.length(); i++)
491 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateVector( myObjects[i], myVector );
492 if ( !anObj->_is_nil() )
493 objects.push_back( anObj._retn() );
504 //=================================================================================
505 // function : closeEvent
507 //=================================================================================
508 void TransformationGUI_TranslationDlg::closeEvent( QCloseEvent* e )
510 myGeomGUI->SetState( -1 );
511 GEOMBase_Skeleton::closeEvent( e );
515 //=================================================================================
516 // function : CreateCopyModeChanged()
518 //=================================================================================
519 void TransformationGUI_TranslationDlg::CreateCopyModeChanged(bool isCreateCopy)
521 GroupBoxName->setEnabled(isCreateCopy);