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_TranslationDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "TransformationGUI_TranslationDlg.h"
30 #include "DlgRef_3Sel3Spin1Check.h"
31 #include "DlgRef_SpinBox.h"
33 #include "GeometryGUI.h"
36 #include "SUIT_ResourceMgr.h"
37 #include "SUIT_Session.h"
38 #include "SalomeApp_Application.h"
39 #include "LightApp_SelectionMgr.h"
41 #include "GEOMImpl_Types.hxx"
45 //=================================================================================
46 // class : TransformationGUI_TranslationDlg()
47 // purpose : Constructs a TransformationGUI_TranslationDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 TransformationGUI_TranslationDlg::TransformationGUI_TranslationDlg
53 (GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
54 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
56 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
57 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSLATION_DXYZ")));
58 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSLATION_POINTS")));
59 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSLATION_VECTOR")));
60 QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
62 setWindowTitle(tr("GEOM_TRANSLATION_TITLE"));
64 /***************************************************************/
65 GroupConstructors->setTitle(tr("GEOM_TRANSLATION"));
66 RadioButton1->setIcon(image0);
67 RadioButton2->setIcon(image1);
68 RadioButton3->setIcon(image2);
70 RadioButton1->setChecked(true);
72 GroupPoints = new DlgRef_3Sel3Spin1Check(this, "GroupPoints");
73 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
74 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
75 GroupPoints->TextLabel3->setText(tr("GEOM_POINT_I").arg("2"));
76 GroupPoints->TextLabel4->setText(tr("GEOM_DX"));
77 GroupPoints->TextLabel5->setText(tr("GEOM_DY"));
78 GroupPoints->TextLabel6->setText(tr("GEOM_DZ"));
79 GroupPoints->PushButton1->setIcon(image3);
80 GroupPoints->PushButton2->setIcon(image3);
81 GroupPoints->PushButton3->setIcon(image3);
82 GroupPoints->CheckBox1->setText(tr("GEOM_CREATE_COPY"));
84 gridLayout1->addWidget(GroupPoints, 2, 0);
85 /***************************************************************/
87 setHelpFileName("translation.htm");
93 //=================================================================================
94 // function : ~TransformationGUI_TranslationDlg()
95 // purpose : Destroys the object and frees any allocated resources
96 //=================================================================================
97 TransformationGUI_TranslationDlg::~TransformationGUI_TranslationDlg()
99 // no need to delete child widgets, Qt does it all for us
103 //=================================================================================
106 //=================================================================================
107 void TransformationGUI_TranslationDlg::Init()
110 myEditCurrentArgument = GroupPoints->LineEdit1;
111 GroupPoints->LineEdit1->setReadOnly(true);
112 GroupPoints->LineEdit2->setReadOnly(true);
113 GroupPoints->LineEdit3->setReadOnly(true);
115 myVector = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
117 // Activate Create a Copy mode
118 GroupPoints->CheckBox1->setChecked(true);
119 CreateCopyModeChanged(true);
121 /* Get setting of step value from file configuration */
122 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
123 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
125 /* min, max, step and decimals for spin boxes & initial values */
126 GroupPoints->SpinBox1->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
127 GroupPoints->SpinBox2->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
128 GroupPoints->SpinBox3->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
130 GroupPoints->SpinBox1->SetValue(0.0);
131 GroupPoints->SpinBox2->SetValue(0.0);
132 GroupPoints->SpinBox3->SetValue(0.0);
134 /* signals and slots connections */
135 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
136 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
137 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
139 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); //@ Delete ?
145 connect(GroupPoints->SpinBox1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
146 connect(GroupPoints->SpinBox2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
147 connect(GroupPoints->SpinBox3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
149 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox1, SLOT(SetStep(double)));
150 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox2, SLOT(SetStep(double)));
151 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox3, SLOT(SetStep(double)));
153 connect(GroupPoints->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
155 connect(myGeomGUI->getApp()->selectionMgr(),
156 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
158 initName( tr( "GEOM_TRANSLATION" ).toLatin1().constData() );
159 ConstructorsClicked( 0 );
163 //=================================================================================
164 // function : ConstructorsClicked()
165 // purpose : Radio button management
166 //=================================================================================
167 void TransformationGUI_TranslationDlg::ConstructorsClicked(int constructorId)
169 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
171 myEditCurrentArgument = GroupPoints->LineEdit1;
174 switch (constructorId)
176 case 0: /* translation an object by dx, dy, dz */
178 GroupPoints->ShowRows(1,2,false);
180 GroupPoints->ShowRows(3,5,true);
183 case 1: /* translation an object by 2 points */
185 GroupPoints->ShowRows(3,5,false);
187 GroupPoints->ShowRows(0,2,true);
188 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("1"));
189 GroupPoints->LineEdit2->clear();
190 GroupPoints->LineEdit3->clear();
191 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
194 case 2: /* translation an object by vector */
196 GroupPoints->ShowRows(2,5,false);
198 GroupPoints->ShowRows(0,1,true);
199 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
200 GroupPoints->LineEdit2->clear();
201 myVector = GEOM::GEOM_Object::_nil();
206 myEditCurrentArgument->setFocus();
207 connect(myGeomGUI->getApp()->selectionMgr(),
208 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
212 //=================================================================================
213 // function : ClickOnOk()
215 //=================================================================================
216 void TransformationGUI_TranslationDlg::ClickOnOk()
218 if ( ClickOnApply() )
223 //=================================================================================
224 // function : ClickOnApply()
226 //=================================================================================
227 bool TransformationGUI_TranslationDlg::ClickOnApply()
229 if ( !onAccept(GroupPoints->CheckBox1->isChecked()) )
233 ConstructorsClicked( getConstructorId() );
238 //=================================================================================
239 // function : SelectionIntoArgument()
240 // purpose : Called when selection as changed or other case
241 //=================================================================================
242 void TransformationGUI_TranslationDlg::SelectionIntoArgument()
244 myEditCurrentArgument->setText("");
247 if(myEditCurrentArgument == GroupPoints->LineEdit1)
249 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
256 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
257 if (!myObjects.length())
262 if (IObjectCount() != 1) {
263 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
264 myPoint1 = GEOM::GEOM_Object::_nil();
265 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
266 myVector = GEOM::GEOM_Object::_nil();
267 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
268 myPoint2 = GEOM::GEOM_Object::_nil();
272 Standard_Boolean testResult = Standard_False;;
273 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
275 if (!testResult || CORBA::is_nil( aSelectedObject ))
278 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
279 myPoint1 = aSelectedObject;
280 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
281 myVector = aSelectedObject;
282 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
283 myPoint2 = aSelectedObject;
285 aName = GEOMBase::GetName( aSelectedObject );
288 myEditCurrentArgument->setText( aName );
294 //=================================================================================
295 // function : LineEditReturnPressed()
297 //=================================================================================
298 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
300 QLineEdit* send = (QLineEdit*)sender();
301 if(send == GroupPoints->LineEdit1)
303 myEditCurrentArgument = send;
304 GEOMBase_Skeleton::LineEditReturnPressed();
309 //=================================================================================
310 // function : SetEditCurrentArgument()
312 //=================================================================================
313 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
315 QPushButton* send = (QPushButton*)sender();
317 if(send == GroupPoints->PushButton1)
319 myEditCurrentArgument = GroupPoints->LineEdit1;
322 else if (send == GroupPoints->PushButton2)
324 myEditCurrentArgument = GroupPoints->LineEdit2;
325 getConstructorId() == 1 ? globalSelection( GEOM_POINT ) :
326 globalSelection( GEOM_LINE );
328 else if (send == GroupPoints->PushButton3)
330 myEditCurrentArgument = GroupPoints->LineEdit3;
331 globalSelection( GEOM_POINT );
334 myEditCurrentArgument->setFocus();
335 SelectionIntoArgument();
339 //=================================================================================
340 // function : ActivateThisDialog()
342 //=================================================================================
343 void TransformationGUI_TranslationDlg::ActivateThisDialog()
345 GEOMBase_Skeleton::ActivateThisDialog();
346 connect(myGeomGUI->getApp()->selectionMgr(),
347 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
349 ConstructorsClicked( getConstructorId() );
353 //=================================================================================
354 // function : enterEvent()
356 //=================================================================================
357 void TransformationGUI_TranslationDlg::enterEvent(QEvent* e)
359 if(!GroupConstructors->isEnabled())
360 ActivateThisDialog();
364 //=================================================================================
365 // function : ValueChangedInSpinBox()
367 //=================================================================================
368 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox()
374 //=================================================================================
375 // function : createOperation
377 //=================================================================================
378 GEOM::GEOM_IOperations_ptr TransformationGUI_TranslationDlg::createOperation()
380 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
384 //=================================================================================
385 // function : isValid
387 //=================================================================================
388 bool TransformationGUI_TranslationDlg::isValid( QString& msg )
390 int aConstructorId = getConstructorId();
392 switch (aConstructorId)
396 return !(myObjects.length() == 0 );
401 return !(myObjects.length() == 0 || myPoint1->_is_nil() || myPoint2->_is_nil() );
406 return !(myObjects.length() == 0 || myVector->_is_nil());
409 default: return false;
413 //=================================================================================
414 // function : execute
416 //=================================================================================
417 bool TransformationGUI_TranslationDlg::execute( ObjectList& objects )
420 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox1->isChecked();
422 GEOM::GEOM_Object_var anObj;
424 switch ( getConstructorId() )
428 double dx = GroupPoints->SpinBox1->GetValue();
429 double dy = GroupPoints->SpinBox2->GetValue();
430 double dz = GroupPoints->SpinBox3->GetValue();
433 for (int i = 0; i < myObjects.length(); i++)
435 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZCopy( myObjects[i], dx, dy, dz );
436 if ( !anObj->_is_nil() )
437 objects.push_back( anObj._retn() );
440 for (int i = 0; i < myObjects.length(); i++)
442 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZ( myObjects[i], dx, dy, dz );
443 if ( !anObj->_is_nil() )
444 objects.push_back( anObj._retn() );
452 for (int i = 0; i < myObjects.length(); i++)
454 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPointsCopy( myObjects[i], myPoint1, myPoint2 );
455 if ( !anObj->_is_nil() )
456 objects.push_back( anObj._retn() );
459 for (int i = 0; i < myObjects.length(); i++)
461 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPoints( myObjects[i], myPoint1, myPoint2 );
462 if ( !anObj->_is_nil() )
463 objects.push_back( anObj._retn() );
471 for (int i = 0; i < myObjects.length(); i++)
473 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateVectorCopy( myObjects[i], myVector );
474 if ( !anObj->_is_nil() )
475 objects.push_back( anObj._retn() );
478 for (int i = 0; i < myObjects.length(); i++)
480 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateVector( myObjects[i], myVector );
481 if ( !anObj->_is_nil() )
482 objects.push_back( anObj._retn() );
493 //=================================================================================
494 // function : closeEvent
496 //=================================================================================
497 void TransformationGUI_TranslationDlg::closeEvent( QCloseEvent* e )
499 // myGeomGUI->SetState( -1 );
500 GEOMBase_Skeleton::closeEvent( e );
504 //=================================================================================
505 // function : CreateCopyModeChanged()
507 //=================================================================================
508 void TransformationGUI_TranslationDlg::CreateCopyModeChanged(bool isCreateCopy)
510 GroupBoxName->setEnabled(isCreateCopy);