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 "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(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
55 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_TRANSLATION_DXYZ")));
56 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_TRANSLATION_POINTS")));
57 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_TRANSLATION_VECTOR")));
58 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
60 setCaption(tr("GEOM_TRANSLATION_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_TRANSLATION"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->setPixmap(image1);
66 RadioButton3->setPixmap(image2);
68 RadioButton1->setChecked(true);
70 GroupPoints = new DlgRef_3Sel3Spin1Check(this, "GroupPoints");
71 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
73 GroupPoints->TextLabel3->setText(tr("GEOM_POINT_I").arg("2"));
74 GroupPoints->TextLabel4->setText(tr("GEOM_DX"));
75 GroupPoints->TextLabel5->setText(tr("GEOM_DY"));
76 GroupPoints->TextLabel6->setText(tr("GEOM_DZ"));
77 GroupPoints->PushButton1->setPixmap(image3);
78 GroupPoints->PushButton2->setPixmap(image3);
79 GroupPoints->PushButton3->setPixmap(image3);
80 GroupPoints->CheckBox1->setText(tr("GEOM_CREATE_COPY"));
82 Layout1->addWidget(GroupPoints, 2, 0);
83 /***************************************************************/
89 //=================================================================================
90 // function : ~TransformationGUI_TranslationDlg()
91 // purpose : Destroys the object and frees any allocated resources
92 //=================================================================================
93 TransformationGUI_TranslationDlg::~TransformationGUI_TranslationDlg()
95 // no need to delete child widgets, Qt does it all for us
99 //=================================================================================
102 //=================================================================================
103 void TransformationGUI_TranslationDlg::Init()
106 myEditCurrentArgument = GroupPoints->LineEdit1;
107 GroupPoints->LineEdit1->setReadOnly(true);
108 GroupPoints->LineEdit2->setReadOnly(true);
109 GroupPoints->LineEdit3->setReadOnly(true);
111 myVector = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
113 // Activate Create a Copy mode
114 GroupPoints->CheckBox1->setChecked(true);
115 CreateCopyModeChanged(true);
117 /* Get setting of step value from file configuration */
118 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
119 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
121 /* min, max, step and decimals for spin boxes & initial values */
122 GroupPoints->SpinBox1->RangeStepAndValidator(-999.999, 999.999, step, 3);
123 GroupPoints->SpinBox2->RangeStepAndValidator(-999.999, 999.999, step, 3);
124 GroupPoints->SpinBox3->RangeStepAndValidator(-999.999, 999.999, step, 3);
126 GroupPoints->SpinBox1->SetValue(0.0);
127 GroupPoints->SpinBox2->SetValue(0.0);
128 GroupPoints->SpinBox3->SetValue(0.0);
130 /* signals and slots connections */
131 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
132 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
133 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
135 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); //@ Delete ?
141 connect(GroupPoints->SpinBox1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
142 connect(GroupPoints->SpinBox2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
143 connect(GroupPoints->SpinBox3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
145 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox1, SLOT(SetStep(double)));
146 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox2, SLOT(SetStep(double)));
147 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox3, SLOT(SetStep(double)));
149 connect(GroupPoints->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
151 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
152 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
154 initName( tr( "GEOM_TRANSLATION" ) );
155 ConstructorsClicked( 0 );
159 //=================================================================================
160 // function : ConstructorsClicked()
161 // purpose : Radio button management
162 //=================================================================================
163 void TransformationGUI_TranslationDlg::ConstructorsClicked(int constructorId)
165 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
167 myEditCurrentArgument = GroupPoints->LineEdit1;
170 switch (constructorId)
172 case 0: /* translation an object by dx, dy, dz */
174 GroupPoints->ShowRows(1,2,false);
176 GroupPoints->ShowRows(3,5,true);
179 case 1: /* translation an object by 2 points */
181 GroupPoints->ShowRows(3,5,false);
183 GroupPoints->ShowRows(0,2,true);
184 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("1"));
185 GroupPoints->LineEdit2->clear();
186 GroupPoints->LineEdit3->clear();
187 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
190 case 2: /* translation an object by vector */
192 GroupPoints->ShowRows(2,5,false);
194 GroupPoints->ShowRows(0,1,true);
195 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
196 GroupPoints->LineEdit2->clear();
197 myVector = GEOM::GEOM_Object::_nil();
202 myEditCurrentArgument->setFocus();
203 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
204 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
208 //=================================================================================
209 // function : ClickOnOk()
211 //=================================================================================
212 void TransformationGUI_TranslationDlg::ClickOnOk()
214 if ( ClickOnApply() )
219 //=================================================================================
220 // function : ClickOnApply()
222 //=================================================================================
223 bool TransformationGUI_TranslationDlg::ClickOnApply()
225 if ( !onAccept(GroupPoints->CheckBox1->isChecked()) )
229 ConstructorsClicked( getConstructorId() );
234 //=======================================================================
235 // function : ClickOnCancel()
237 //=======================================================================
238 void TransformationGUI_TranslationDlg::ClickOnCancel()
240 GEOMBase_Skeleton::ClickOnCancel();
244 //=================================================================================
245 // function : SelectionIntoArgument()
246 // purpose : Called when selection as changed or other case
247 //=================================================================================
248 void TransformationGUI_TranslationDlg::SelectionIntoArgument()
250 myEditCurrentArgument->setText("");
253 if(myEditCurrentArgument == GroupPoints->LineEdit1)
255 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
262 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
263 if (!myObjects.length())
268 if (IObjectCount() != 1) {
269 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
270 myPoint1 = GEOM::GEOM_Object::_nil();
271 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
272 myVector = GEOM::GEOM_Object::_nil();
273 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
274 myPoint2 = GEOM::GEOM_Object::_nil();
278 Standard_Boolean testResult = Standard_False;;
279 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
281 if (!testResult || CORBA::is_nil( aSelectedObject ))
284 if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
285 myPoint1 = aSelectedObject;
286 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
287 myVector = aSelectedObject;
288 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
289 myPoint2 = aSelectedObject;
291 aName = GEOMBase::GetName( aSelectedObject );
294 myEditCurrentArgument->setText( aName );
300 //=================================================================================
301 // function : LineEditReturnPressed()
303 //=================================================================================
304 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
306 QLineEdit* send = (QLineEdit*)sender();
307 if(send == GroupPoints->LineEdit1)
309 myEditCurrentArgument = send;
310 GEOMBase_Skeleton::LineEditReturnPressed();
315 //=================================================================================
316 // function : SetEditCurrentArgument()
318 //=================================================================================
319 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
321 QPushButton* send = (QPushButton*)sender();
323 if(send == GroupPoints->PushButton1)
325 myEditCurrentArgument = GroupPoints->LineEdit1;
328 else if (send == GroupPoints->PushButton2)
330 myEditCurrentArgument = GroupPoints->LineEdit2;
331 getConstructorId() == 1 ? globalSelection( GEOM_POINT ) :
332 globalSelection( GEOM_LINE );
334 else if (send == GroupPoints->PushButton3)
336 myEditCurrentArgument = GroupPoints->LineEdit3;
337 globalSelection( GEOM_POINT );
340 myEditCurrentArgument->setFocus();
341 SelectionIntoArgument();
345 //=================================================================================
346 // function : ActivateThisDialog()
348 //=================================================================================
349 void TransformationGUI_TranslationDlg::ActivateThisDialog()
351 GEOMBase_Skeleton::ActivateThisDialog();
352 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
353 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
355 ConstructorsClicked( getConstructorId() );
359 //=================================================================================
360 // function : DeactivateActiveDialog()
361 // purpose : public slot to deactivate if active
362 //=================================================================================
363 void TransformationGUI_TranslationDlg::DeactivateActiveDialog()
365 GEOMBase_Skeleton::DeactivateActiveDialog();
369 //=================================================================================
370 // function : enterEvent()
372 //=================================================================================
373 void TransformationGUI_TranslationDlg::enterEvent(QEvent* e)
375 if(!GroupConstructors->isEnabled())
376 ActivateThisDialog();
380 //=================================================================================
381 // function : ValueChangedInSpinBox()
383 //=================================================================================
384 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox()
390 //=================================================================================
391 // function : createOperation
393 //=================================================================================
394 GEOM::GEOM_IOperations_ptr TransformationGUI_TranslationDlg::createOperation()
396 return myGeometryGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
400 //=================================================================================
401 // function : isValid
403 //=================================================================================
404 bool TransformationGUI_TranslationDlg::isValid( QString& msg )
406 int aConstructorId = getConstructorId();
408 switch (aConstructorId)
412 return !(myObjects.length() == 0 );
417 return !(myObjects.length() == 0 || myPoint1->_is_nil() || myPoint2->_is_nil() );
422 return !(myObjects.length() == 0 || myVector->_is_nil());
425 default: return false;
429 //=================================================================================
430 // function : execute
432 //=================================================================================
433 bool TransformationGUI_TranslationDlg::execute( ObjectList& objects )
436 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox1->isChecked();
438 GEOM::GEOM_Object_var anObj;
440 switch ( getConstructorId() )
444 double dx = GroupPoints->SpinBox1->GetValue();
445 double dy = GroupPoints->SpinBox2->GetValue();
446 double dz = GroupPoints->SpinBox3->GetValue();
449 for (int i = 0; i < myObjects.length(); i++)
451 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZCopy( myObjects[i], dx, dy, dz );
452 if ( !anObj->_is_nil() )
453 objects.push_back( anObj._retn() );
456 for (int i = 0; i < myObjects.length(); i++)
458 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZ( myObjects[i], dx, dy, dz );
459 if ( !anObj->_is_nil() )
460 objects.push_back( anObj._retn() );
468 for (int i = 0; i < myObjects.length(); i++)
470 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPointsCopy( myObjects[i], myPoint1, myPoint2 );
471 if ( !anObj->_is_nil() )
472 objects.push_back( anObj._retn() );
475 for (int i = 0; i < myObjects.length(); i++)
477 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPoints( myObjects[i], myPoint1, myPoint2 );
478 if ( !anObj->_is_nil() )
479 objects.push_back( anObj._retn() );
487 for (int i = 0; i < myObjects.length(); i++)
489 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateVectorCopy( myObjects[i], myVector );
490 if ( !anObj->_is_nil() )
491 objects.push_back( anObj._retn() );
494 for (int i = 0; i < myObjects.length(); i++)
496 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateVector( myObjects[i], myVector );
497 if ( !anObj->_is_nil() )
498 objects.push_back( anObj._retn() );
509 //=================================================================================
510 // function : closeEvent
512 //=================================================================================
513 void TransformationGUI_TranslationDlg::closeEvent( QCloseEvent* e )
515 // myGeomGUI->SetState( -1 );
516 GEOMBase_Skeleton::closeEvent( e );
520 //=================================================================================
521 // function : CreateCopyModeChanged()
523 //=================================================================================
524 void TransformationGUI_TranslationDlg::CreateCopyModeChanged(bool isCreateCopy)
526 GroupBoxName->setEnabled(isCreateCopy);