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"
37 #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(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
128 GroupPoints->SpinBox2->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
129 GroupPoints->SpinBox3->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
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)
171 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
173 myEditCurrentArgument = GroupPoints->LineEdit1;
176 switch (constructorId)
178 case 0: /* translation an object by dx, dy, dz */
180 GroupPoints->ShowRows(1,2,false);
182 GroupPoints->ShowRows(3,5,true);
185 case 1: /* translation an object by 2 points */
187 GroupPoints->ShowRows(3,5,false);
189 GroupPoints->ShowRows(0,2,true);
190 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("1"));
191 GroupPoints->LineEdit2->clear();
192 GroupPoints->LineEdit3->clear();
193 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
196 case 2: /* translation an object by vector */
198 GroupPoints->ShowRows(2,5,false);
200 GroupPoints->ShowRows(0,1,true);
201 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
202 GroupPoints->LineEdit2->clear();
203 myVector = GEOM::GEOM_Object::_nil();
208 myEditCurrentArgument->setFocus();
209 connect(myGeomGUI->getApp()->selectionMgr(),
210 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
214 //=================================================================================
215 // function : ClickOnOk()
217 //=================================================================================
218 void TransformationGUI_TranslationDlg::ClickOnOk()
220 if ( ClickOnApply() )
225 //=================================================================================
226 // function : ClickOnApply()
228 //=================================================================================
229 bool TransformationGUI_TranslationDlg::ClickOnApply()
231 if ( !onAccept(GroupPoints->CheckBox1->isChecked()) )
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 );
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) {
318 myEditCurrentArgument = GroupPoints->LineEdit1;
321 else if (send == GroupPoints->PushButton2) {
322 myEditCurrentArgument = GroupPoints->LineEdit2;
323 getConstructorId() == 1 ? globalSelection( GEOM_POINT ) :
324 globalSelection( GEOM_LINE );
326 else if (send == GroupPoints->PushButton3) {
327 myEditCurrentArgument = GroupPoints->LineEdit3;
328 globalSelection( GEOM_POINT );
331 myEditCurrentArgument->setFocus();
332 SelectionIntoArgument();
336 //=================================================================================
337 // function : ActivateThisDialog()
339 //=================================================================================
340 void TransformationGUI_TranslationDlg::ActivateThisDialog()
342 GEOMBase_Skeleton::ActivateThisDialog();
344 connect(myGeomGUI->getApp()->selectionMgr(),
345 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
347 ConstructorsClicked( getConstructorId() );
351 //=================================================================================
352 // function : enterEvent()
354 //=================================================================================
355 void TransformationGUI_TranslationDlg::enterEvent(QEvent* e)
357 if (!GroupConstructors->isEnabled())
358 ActivateThisDialog();
362 //=================================================================================
363 // function : ValueChangedInSpinBox()
365 //=================================================================================
366 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox()
372 //=================================================================================
373 // function : createOperation
375 //=================================================================================
376 GEOM::GEOM_IOperations_ptr TransformationGUI_TranslationDlg::createOperation()
378 return getGeomEngine()->GetITransformOperations( getStudyId() );
382 //=================================================================================
383 // function : isValid
385 //=================================================================================
386 bool TransformationGUI_TranslationDlg::isValid( QString& msg )
388 int aConstructorId = getConstructorId();
390 switch (aConstructorId)
394 return !(myObjects.length() == 0 );
399 return !(myObjects.length() == 0 || myPoint1->_is_nil() || myPoint2->_is_nil() );
404 return !(myObjects.length() == 0 || myVector->_is_nil());
407 default: return false;
411 //=================================================================================
412 // function : execute
414 //=================================================================================
415 bool TransformationGUI_TranslationDlg::execute( ObjectList& objects )
418 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox1->isChecked();
420 GEOM::GEOM_Object_var anObj;
422 switch ( getConstructorId() )
426 double dx = GroupPoints->SpinBox1->GetValue();
427 double dy = GroupPoints->SpinBox2->GetValue();
428 double dz = GroupPoints->SpinBox3->GetValue();
431 for (int i = 0; i < myObjects.length(); i++)
433 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
434 TranslateDXDYDZCopy( myObjects[i], dx, dy, dz );
435 if ( !anObj->_is_nil() )
436 objects.push_back( anObj._retn() );
439 for (int i = 0; i < myObjects.length(); i++)
441 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
442 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() )->
455 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() )->
463 TranslateTwoPoints( myObjects[i], myPoint1, myPoint2 );
464 if ( !anObj->_is_nil() )
465 objects.push_back( anObj._retn() );
473 for (int i = 0; i < myObjects.length(); i++)
475 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
476 TranslateVectorCopy( myObjects[i], myVector );
477 if ( !anObj->_is_nil() )
478 objects.push_back( anObj._retn() );
481 for (int i = 0; i < myObjects.length(); i++)
483 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
484 TranslateVector( myObjects[i], myVector );
485 if ( !anObj->_is_nil() )
486 objects.push_back( anObj._retn() );
497 //=================================================================================
498 // function : CreateCopyModeChanged()
500 //=================================================================================
501 void TransformationGUI_TranslationDlg::CreateCopyModeChanged(bool isCreateCopy)
503 GroupBoxName->setEnabled(isCreateCopy);