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 <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <qcheckbox.h>
46 #include "GEOMImpl_Types.hxx"
48 #include "utilities.h"
52 //=================================================================================
53 // class : TransformationGUI_TranslationDlg()
54 // purpose : Constructs a TransformationGUI_TranslationDlg which is a child of 'parent', with the
55 // name 'name' and widget flags set to 'f'.
56 // The dialog will by default be modeless, unless you set 'modal' to
57 // TRUE to construct a modal dialog.
58 //=================================================================================
59 TransformationGUI_TranslationDlg::TransformationGUI_TranslationDlg
60 (GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
61 : GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
62 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
64 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
65 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSLATION_DXYZ")));
66 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSLATION_POINTS")));
67 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSLATION_VECTOR")));
68 QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
70 setCaption(tr("GEOM_TRANSLATION_TITLE"));
72 /***************************************************************/
73 GroupConstructors->setTitle(tr("GEOM_TRANSLATION"));
74 RadioButton1->setPixmap(image0);
75 RadioButton2->setPixmap(image1);
76 RadioButton3->setPixmap(image2);
78 RadioButton1->setChecked(true);
80 GroupPoints = new DlgRef_3Sel3Spin1Check(this, "GroupPoints");
81 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
82 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
83 GroupPoints->TextLabel3->setText(tr("GEOM_POINT_I").arg("2"));
84 GroupPoints->TextLabel4->setText(tr("GEOM_DX"));
85 GroupPoints->TextLabel5->setText(tr("GEOM_DY"));
86 GroupPoints->TextLabel6->setText(tr("GEOM_DZ"));
87 GroupPoints->PushButton1->setPixmap(image3);
88 GroupPoints->PushButton2->setPixmap(image3);
89 GroupPoints->PushButton3->setPixmap(image3);
90 GroupPoints->CheckBox1->setText(tr("GEOM_CREATE_COPY"));
92 Layout1->addWidget(GroupPoints, 2, 0);
93 /***************************************************************/
95 setHelpFileName("translation.htm");
101 //=================================================================================
102 // function : ~TransformationGUI_TranslationDlg()
103 // purpose : Destroys the object and frees any allocated resources
104 //=================================================================================
105 TransformationGUI_TranslationDlg::~TransformationGUI_TranslationDlg()
107 // no need to delete child widgets, Qt does it all for us
111 //=================================================================================
114 //=================================================================================
115 void TransformationGUI_TranslationDlg::Init()
118 myEditCurrentArgument = GroupPoints->LineEdit1;
119 GroupPoints->LineEdit1->setReadOnly(true);
120 GroupPoints->LineEdit2->setReadOnly(true);
121 GroupPoints->LineEdit3->setReadOnly(true);
123 myVector = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
125 // Activate Create a Copy mode
126 GroupPoints->CheckBox1->setChecked(true);
127 CreateCopyModeChanged(true);
129 /* Get setting of step value from file configuration */
130 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
131 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
133 /* min, max, step and decimals for spin boxes & initial values */
134 GroupPoints->SpinBox1->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
135 GroupPoints->SpinBox2->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
136 GroupPoints->SpinBox3->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
138 GroupPoints->SpinBox1->SetValue(0.0);
139 GroupPoints->SpinBox2->SetValue(0.0);
140 GroupPoints->SpinBox3->SetValue(0.0);
142 /* signals and slots connections */
143 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
144 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
145 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
147 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); //@ Delete ?
153 connect(GroupPoints->SpinBox1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
154 connect(GroupPoints->SpinBox2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
155 connect(GroupPoints->SpinBox3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
157 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox1, SLOT(SetStep(double)));
158 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox2, SLOT(SetStep(double)));
159 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox3, SLOT(SetStep(double)));
161 connect(GroupPoints->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
163 connect(myGeomGUI->getApp()->selectionMgr(),
164 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
166 initName( tr( "GEOM_TRANSLATION" ) );
167 ConstructorsClicked( 0 );
171 //=================================================================================
172 // function : ConstructorsClicked()
173 // purpose : Radio button management
174 //=================================================================================
175 void TransformationGUI_TranslationDlg::ConstructorsClicked(int constructorId)
178 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
180 myEditCurrentArgument = GroupPoints->LineEdit1;
183 switch (constructorId)
185 case 0: /* translation an object by dx, dy, dz */
187 GroupPoints->ShowRows(1,2,false);
189 GroupPoints->ShowRows(3,5,true);
192 case 1: /* translation an object by 2 points */
194 GroupPoints->ShowRows(3,5,false);
196 GroupPoints->ShowRows(0,2,true);
197 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("1"));
198 GroupPoints->LineEdit2->clear();
199 GroupPoints->LineEdit3->clear();
200 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
203 case 2: /* translation an object by vector */
205 GroupPoints->ShowRows(2,5,false);
207 GroupPoints->ShowRows(0,1,true);
208 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
209 GroupPoints->LineEdit2->clear();
210 myVector = GEOM::GEOM_Object::_nil();
215 myEditCurrentArgument->setFocus();
216 connect(myGeomGUI->getApp()->selectionMgr(),
217 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
221 //=================================================================================
222 // function : ClickOnOk()
224 //=================================================================================
225 void TransformationGUI_TranslationDlg::ClickOnOk()
227 if ( ClickOnApply() )
232 //=================================================================================
233 // function : ClickOnApply()
235 //=================================================================================
236 bool TransformationGUI_TranslationDlg::ClickOnApply()
238 if ( !onAccept(GroupPoints->CheckBox1->isChecked()) )
246 //=================================================================================
247 // function : SelectionIntoArgument()
248 // purpose : Called when selection as changed or other case
249 //=================================================================================
250 void TransformationGUI_TranslationDlg::SelectionIntoArgument()
252 myEditCurrentArgument->setText("");
255 if (myEditCurrentArgument == GroupPoints->LineEdit1)
257 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
264 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
265 if (!myObjects.length())
270 if (IObjectCount() != 1) {
271 if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
272 myPoint1 = GEOM::GEOM_Object::_nil();
273 else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
274 myVector = GEOM::GEOM_Object::_nil();
275 else if (myEditCurrentArgument == GroupPoints->LineEdit3)
276 myPoint2 = GEOM::GEOM_Object::_nil();
280 Standard_Boolean testResult = Standard_False;
281 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult);
283 if (!testResult || CORBA::is_nil( aSelectedObject ))
287 aName = GEOMBase::GetName( aSelectedObject );
288 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
290 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
291 if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
292 aNeedType = TopAbs_EDGE;
294 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
295 TColStd_IndexedMapOfInteger aMap;
296 aSelMgr->GetIndexes( firstIObject(), aMap );
297 if ( aMap.Extent() == 1 )
299 int anIndex = aMap( 1 );
300 if (aNeedType == TopAbs_EDGE)
301 aName += QString(":edge_%1").arg(anIndex);
303 aName += QString(":vertex_%1").arg(anIndex);
305 //Find SubShape Object in Father
306 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
308 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
309 GEOM::GEOM_IShapesOperations_var aShapesOp =
310 getGeomEngine()->GetIShapesOperations( getStudyId() );
311 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
314 aSelectedObject = aFindedObject;
315 } else // Global Selection
317 if (aShape.ShapeType() != aNeedType) {
318 aSelectedObject = GEOM::GEOM_Object::_nil();
324 if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
325 myPoint1 = aSelectedObject;
326 else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
327 myVector = aSelectedObject;
328 else if (myEditCurrentArgument == GroupPoints->LineEdit3)
329 myPoint2 = aSelectedObject;
332 myEditCurrentArgument->setText( aName );
337 //=================================================================================
338 // function : LineEditReturnPressed()
340 //=================================================================================
341 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
343 QLineEdit* send = (QLineEdit*)sender();
344 if (send == GroupPoints->LineEdit1)
346 myEditCurrentArgument = send;
347 GEOMBase_Skeleton::LineEditReturnPressed();
352 //=================================================================================
353 // function : SetEditCurrentArgument()
355 //=================================================================================
356 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
358 QPushButton* send = (QPushButton*)sender();
361 if (send == GroupPoints->PushButton1) {
362 myEditCurrentArgument = GroupPoints->LineEdit1;
364 else if (send == GroupPoints->PushButton2) {
365 myEditCurrentArgument = GroupPoints->LineEdit2;
366 if (getConstructorId() == 1)
367 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
369 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
371 else if (send == GroupPoints->PushButton3) {
372 myEditCurrentArgument = GroupPoints->LineEdit3;
373 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
376 myEditCurrentArgument->setFocus();
377 SelectionIntoArgument();
381 //=================================================================================
382 // function : ActivateThisDialog()
384 //=================================================================================
385 void TransformationGUI_TranslationDlg::ActivateThisDialog()
387 GEOMBase_Skeleton::ActivateThisDialog();
389 connect(myGeomGUI->getApp()->selectionMgr(),
390 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
392 ConstructorsClicked( getConstructorId() );
396 //=================================================================================
397 // function : enterEvent()
399 //=================================================================================
400 void TransformationGUI_TranslationDlg::enterEvent(QEvent* e)
402 if (!GroupConstructors->isEnabled())
403 ActivateThisDialog();
407 //=================================================================================
408 // function : ValueChangedInSpinBox()
410 //=================================================================================
411 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox()
417 //=================================================================================
418 // function : createOperation
420 //=================================================================================
421 GEOM::GEOM_IOperations_ptr TransformationGUI_TranslationDlg::createOperation()
423 return getGeomEngine()->GetITransformOperations( getStudyId() );
427 //=================================================================================
428 // function : isValid
430 //=================================================================================
431 bool TransformationGUI_TranslationDlg::isValid( QString& msg )
433 int aConstructorId = getConstructorId();
435 switch (aConstructorId)
439 return !(myObjects.length() == 0 );
444 return !(myObjects.length() == 0 || myPoint1->_is_nil() || myPoint2->_is_nil() );
449 return !(myObjects.length() == 0 || myVector->_is_nil());
452 default: return false;
456 //=================================================================================
457 // function : execute
459 //=================================================================================
460 bool TransformationGUI_TranslationDlg::execute( ObjectList& objects )
463 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox1->isChecked();
465 GEOM::GEOM_Object_var anObj;
467 switch ( getConstructorId() )
471 double dx = GroupPoints->SpinBox1->GetValue();
472 double dy = GroupPoints->SpinBox2->GetValue();
473 double dz = GroupPoints->SpinBox3->GetValue();
476 for (int i = 0; i < myObjects.length(); i++)
478 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
479 TranslateDXDYDZCopy( myObjects[i], dx, dy, dz );
480 if ( !anObj->_is_nil() )
481 objects.push_back( anObj._retn() );
484 for (int i = 0; i < myObjects.length(); i++)
486 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
487 TranslateDXDYDZ( myObjects[i], dx, dy, dz );
488 if ( !anObj->_is_nil() )
489 objects.push_back( anObj._retn() );
497 for (int i = 0; i < myObjects.length(); i++)
499 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
500 TranslateTwoPointsCopy( myObjects[i], myPoint1, myPoint2 );
501 if ( !anObj->_is_nil() )
502 objects.push_back( anObj._retn() );
505 for (int i = 0; i < myObjects.length(); i++)
507 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
508 TranslateTwoPoints( myObjects[i], myPoint1, myPoint2 );
509 if ( !anObj->_is_nil() )
510 objects.push_back( anObj._retn() );
518 for (int i = 0; i < myObjects.length(); i++)
520 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
521 TranslateVectorCopy( myObjects[i], myVector );
522 if ( !anObj->_is_nil() )
523 objects.push_back( anObj._retn() );
526 for (int i = 0; i < myObjects.length(); i++)
528 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
529 TranslateVector( myObjects[i], myVector );
530 if ( !anObj->_is_nil() )
531 objects.push_back( anObj._retn() );
542 //=================================================================================
543 // function : CreateCopyModeChanged()
545 //=================================================================================
546 void TransformationGUI_TranslationDlg::CreateCopyModeChanged(bool isCreateCopy)
548 GroupBoxName->setEnabled(isCreateCopy);
551 //=================================================================================
552 // function : addSubshapeToStudy
553 // purpose : virtual method to add new SubObjects if local selection
554 //=================================================================================
555 void TransformationGUI_TranslationDlg::addSubshapesToStudy()
557 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox1->isChecked();
559 QMap<QString, GEOM::GEOM_Object_var> objMap;
561 switch (getConstructorId())
566 objMap[GroupPoints->LineEdit2->text()] = myPoint1;
567 objMap[GroupPoints->LineEdit3->text()] = myPoint2;
570 objMap[GroupPoints->LineEdit2->text()] = myVector;
573 addSubshapesToFather( objMap );