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"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
36 #include <qcheckbox.h>
39 #include "GEOMImpl_Types.hxx"
41 #include "utilities.h"
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, WFlags fl)
54 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
55 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
57 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
58 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSLATION_DXYZ")));
59 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSLATION_POINTS")));
60 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSLATION_VECTOR")));
61 QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
63 setCaption(tr("GEOM_TRANSLATION_TITLE"));
65 /***************************************************************/
66 GroupConstructors->setTitle(tr("GEOM_TRANSLATION"));
67 RadioButton1->setPixmap(image0);
68 RadioButton2->setPixmap(image1);
69 RadioButton3->setPixmap(image2);
71 RadioButton1->setChecked(true);
73 GroupPoints = new DlgRef_3Sel3Spin1Check(this, "GroupPoints");
74 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
75 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
76 GroupPoints->TextLabel3->setText(tr("GEOM_POINT_I").arg("2"));
77 GroupPoints->TextLabel4->setText(tr("GEOM_DX"));
78 GroupPoints->TextLabel5->setText(tr("GEOM_DY"));
79 GroupPoints->TextLabel6->setText(tr("GEOM_DZ"));
80 GroupPoints->PushButton1->setPixmap(image3);
81 GroupPoints->PushButton2->setPixmap(image3);
82 GroupPoints->PushButton3->setPixmap(image3);
83 GroupPoints->CheckBox1->setText(tr("GEOM_CREATE_COPY"));
85 Layout1->addWidget(GroupPoints, 2, 0);
86 /***************************************************************/
88 setHelpFileName("translation.htm");
94 //=================================================================================
95 // function : ~TransformationGUI_TranslationDlg()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 TransformationGUI_TranslationDlg::~TransformationGUI_TranslationDlg()
100 // no need to delete child widgets, Qt does it all for us
104 //=================================================================================
107 //=================================================================================
108 void TransformationGUI_TranslationDlg::Init()
111 myEditCurrentArgument = GroupPoints->LineEdit1;
112 GroupPoints->LineEdit1->setReadOnly(true);
113 GroupPoints->LineEdit2->setReadOnly(true);
114 GroupPoints->LineEdit3->setReadOnly(true);
116 myVector = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
118 // Activate Create a Copy mode
119 GroupPoints->CheckBox1->setChecked(true);
120 CreateCopyModeChanged(true);
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 /* min, max, step and decimals for spin boxes & initial values */
127 GroupPoints->SpinBox1->RangeStepAndValidator(-999.999, 999.999, step, 3);
128 GroupPoints->SpinBox2->RangeStepAndValidator(-999.999, 999.999, step, 3);
129 GroupPoints->SpinBox3->RangeStepAndValidator(-999.999, 999.999, step, 3);
131 GroupPoints->SpinBox1->SetValue(0.0);
132 GroupPoints->SpinBox2->SetValue(0.0);
133 GroupPoints->SpinBox3->SetValue(0.0);
135 /* signals and slots connections */
136 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
137 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
138 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
140 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
144 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); //@ Delete ?
146 connect(GroupPoints->SpinBox1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
147 connect(GroupPoints->SpinBox2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
148 connect(GroupPoints->SpinBox3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
150 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox1, SLOT(SetStep(double)));
151 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox2, SLOT(SetStep(double)));
152 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox3, SLOT(SetStep(double)));
154 connect(GroupPoints->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
156 connect(myGeomGUI->getApp()->selectionMgr(),
157 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
159 initName( tr( "GEOM_TRANSLATION" ) );
160 ConstructorsClicked( 0 );
164 //=================================================================================
165 // function : ConstructorsClicked()
166 // purpose : Radio button management
167 //=================================================================================
168 void TransformationGUI_TranslationDlg::ConstructorsClicked(int constructorId)
170 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
172 myEditCurrentArgument = GroupPoints->LineEdit1;
175 switch (constructorId)
177 case 0: /* translation an object by dx, dy, dz */
179 GroupPoints->ShowRows(1,2,false);
181 GroupPoints->ShowRows(3,5,true);
184 case 1: /* translation an object by 2 points */
186 GroupPoints->ShowRows(3,5,false);
188 GroupPoints->ShowRows(0,2,true);
189 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("1"));
190 GroupPoints->LineEdit2->clear();
191 GroupPoints->LineEdit3->clear();
192 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
195 case 2: /* translation an object by vector */
197 GroupPoints->ShowRows(2,5,false);
199 GroupPoints->ShowRows(0,1,true);
200 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
201 GroupPoints->LineEdit2->clear();
202 myVector = GEOM::GEOM_Object::_nil();
207 myEditCurrentArgument->setFocus();
208 connect(myGeomGUI->getApp()->selectionMgr(),
209 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
213 //=================================================================================
214 // function : ClickOnOk()
216 //=================================================================================
217 void TransformationGUI_TranslationDlg::ClickOnOk()
219 if ( ClickOnApply() )
224 //=================================================================================
225 // function : ClickOnApply()
227 //=================================================================================
228 bool TransformationGUI_TranslationDlg::ClickOnApply()
230 if ( !onAccept(GroupPoints->CheckBox1->isChecked()) )
234 ConstructorsClicked( getConstructorId() );
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(selectedIO(), aName);
257 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
258 if (!myObjects.length())
263 if (IObjectCount() != 1) {
264 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
265 myPoint1 = GEOM::GEOM_Object::_nil();
266 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
267 myVector = GEOM::GEOM_Object::_nil();
268 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
269 myPoint2 = GEOM::GEOM_Object::_nil();
273 Standard_Boolean testResult = Standard_False;;
274 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
276 if (!testResult || CORBA::is_nil( aSelectedObject ))
279 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
280 myPoint1 = aSelectedObject;
281 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
282 myVector = aSelectedObject;
283 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
284 myPoint2 = aSelectedObject;
286 aName = GEOMBase::GetName( aSelectedObject );
289 myEditCurrentArgument->setText( aName );
295 //=================================================================================
296 // function : LineEditReturnPressed()
298 //=================================================================================
299 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
301 QLineEdit* send = (QLineEdit*)sender();
302 if(send == GroupPoints->LineEdit1)
304 myEditCurrentArgument = send;
305 GEOMBase_Skeleton::LineEditReturnPressed();
310 //=================================================================================
311 // function : SetEditCurrentArgument()
313 //=================================================================================
314 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
316 QPushButton* send = (QPushButton*)sender();
318 if(send == GroupPoints->PushButton1)
320 myEditCurrentArgument = GroupPoints->LineEdit1;
323 else if (send == GroupPoints->PushButton2)
325 myEditCurrentArgument = GroupPoints->LineEdit2;
326 getConstructorId() == 1 ? globalSelection( GEOM_POINT ) :
327 globalSelection( GEOM_LINE );
329 else if (send == GroupPoints->PushButton3)
331 myEditCurrentArgument = GroupPoints->LineEdit3;
332 globalSelection( GEOM_POINT );
335 myEditCurrentArgument->setFocus();
336 SelectionIntoArgument();
340 //=================================================================================
341 // function : ActivateThisDialog()
343 //=================================================================================
344 void TransformationGUI_TranslationDlg::ActivateThisDialog()
346 GEOMBase_Skeleton::ActivateThisDialog();
347 connect(myGeomGUI->getApp()->selectionMgr(),
348 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
350 ConstructorsClicked( getConstructorId() );
354 //=================================================================================
355 // function : enterEvent()
357 //=================================================================================
358 void TransformationGUI_TranslationDlg::enterEvent(QEvent* e)
360 if(!GroupConstructors->isEnabled())
361 ActivateThisDialog();
365 //=================================================================================
366 // function : ValueChangedInSpinBox()
368 //=================================================================================
369 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox()
375 //=================================================================================
376 // function : createOperation
378 //=================================================================================
379 GEOM::GEOM_IOperations_ptr TransformationGUI_TranslationDlg::createOperation()
381 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
385 //=================================================================================
386 // function : isValid
388 //=================================================================================
389 bool TransformationGUI_TranslationDlg::isValid( QString& msg )
391 int aConstructorId = getConstructorId();
393 switch (aConstructorId)
397 return !(myObjects.length() == 0 );
402 return !(myObjects.length() == 0 || myPoint1->_is_nil() || myPoint2->_is_nil() );
407 return !(myObjects.length() == 0 || myVector->_is_nil());
410 default: return false;
414 //=================================================================================
415 // function : execute
417 //=================================================================================
418 bool TransformationGUI_TranslationDlg::execute( ObjectList& objects )
421 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox1->isChecked();
423 GEOM::GEOM_Object_var anObj;
425 switch ( getConstructorId() )
429 double dx = GroupPoints->SpinBox1->GetValue();
430 double dy = GroupPoints->SpinBox2->GetValue();
431 double dz = GroupPoints->SpinBox3->GetValue();
434 for (int i = 0; i < myObjects.length(); i++)
436 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZCopy( myObjects[i], dx, dy, dz );
437 if ( !anObj->_is_nil() )
438 objects.push_back( anObj._retn() );
441 for (int i = 0; i < myObjects.length(); i++)
443 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZ( myObjects[i], dx, dy, dz );
444 if ( !anObj->_is_nil() )
445 objects.push_back( anObj._retn() );
453 for (int i = 0; i < myObjects.length(); i++)
455 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPointsCopy( myObjects[i], myPoint1, myPoint2 );
456 if ( !anObj->_is_nil() )
457 objects.push_back( anObj._retn() );
460 for (int i = 0; i < myObjects.length(); i++)
462 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPoints( myObjects[i], myPoint1, myPoint2 );
463 if ( !anObj->_is_nil() )
464 objects.push_back( anObj._retn() );
472 for (int i = 0; i < myObjects.length(); i++)
474 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateVectorCopy( myObjects[i], myVector );
475 if ( !anObj->_is_nil() )
476 objects.push_back( anObj._retn() );
479 for (int i = 0; i < myObjects.length(); i++)
481 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateVector( myObjects[i], myVector );
482 if ( !anObj->_is_nil() )
483 objects.push_back( anObj._retn() );
494 //=================================================================================
495 // function : closeEvent
497 //=================================================================================
498 void TransformationGUI_TranslationDlg::closeEvent( QCloseEvent* e )
500 // myGeomGUI->SetState( -1 );
501 GEOMBase_Skeleton::closeEvent( e );
505 //=================================================================================
506 // function : CreateCopyModeChanged()
508 //=================================================================================
509 void TransformationGUI_TranslationDlg::CreateCopyModeChanged(bool isCreateCopy)
511 GroupBoxName->setEnabled(isCreateCopy);