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>
45 #include <qapplication.h>
47 #include "GEOMImpl_Types.hxx"
49 #include "utilities.h"
53 //=================================================================================
54 // class : TransformationGUI_TranslationDlg()
55 // purpose : Constructs a TransformationGUI_TranslationDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 TransformationGUI_TranslationDlg::TransformationGUI_TranslationDlg
61 (GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
62 : GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
63 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
65 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
66 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSLATION_DXYZ")));
67 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSLATION_POINTS")));
68 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSLATION_VECTOR")));
69 QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
71 setCaption(tr("GEOM_TRANSLATION_TITLE"));
73 /***************************************************************/
74 GroupConstructors->setTitle(tr("GEOM_TRANSLATION"));
75 RadioButton1->setPixmap(image0);
76 RadioButton2->setPixmap(image1);
77 RadioButton3->setPixmap(image2);
79 RadioButton1->setChecked(true);
81 GroupPoints = new DlgRef_3Sel3Spin2Check(this, "GroupPoints");
82 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
83 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
84 GroupPoints->TextLabel3->setText(tr("GEOM_POINT_I").arg("2"));
85 GroupPoints->TextLabel4->setText(tr("GEOM_DX"));
86 GroupPoints->TextLabel5->setText(tr("GEOM_DY"));
87 GroupPoints->TextLabel6->setText(tr("GEOM_DZ"));
88 GroupPoints->PushButton1->setPixmap(image3);
89 GroupPoints->PushButton2->setPixmap(image3);
90 GroupPoints->PushButton3->setPixmap(image3);
91 GroupPoints->CheckBox1->setText(tr("Activate Distance"));
92 GroupPoints->CheckBox2->setText(tr("GEOM_CREATE_COPY"));
94 Layout1->addWidget(GroupPoints, 2, 0);
95 /***************************************************************/
97 setHelpFileName("translation_operation_page.html");
103 //=================================================================================
104 // function : ~TransformationGUI_TranslationDlg()
105 // purpose : Destroys the object and frees any allocated resources
106 //=================================================================================
107 TransformationGUI_TranslationDlg::~TransformationGUI_TranslationDlg()
109 // no need to delete child widgets, Qt does it all for us
113 //=================================================================================
116 //=================================================================================
117 void TransformationGUI_TranslationDlg::Init()
120 myEditCurrentArgument = GroupPoints->LineEdit1;
121 GroupPoints->LineEdit1->setReadOnly(true);
122 GroupPoints->LineEdit2->setReadOnly(true);
123 GroupPoints->LineEdit3->setReadOnly(true);
125 myVector = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
127 // Activate Create a Copy mode
128 GroupPoints->CheckBox2->setChecked(true);
129 CreateCopyModeChanged(true);
131 GroupBoxPublish->show();
133 /* Get setting of step value from file configuration */
134 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
135 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
137 /* min, max, step and decimals for spin boxes & initial values */
138 GroupPoints->SpinBox1->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
139 GroupPoints->SpinBox2->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
140 GroupPoints->SpinBox3->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
142 GroupPoints->SpinBox1->SetValue(0.0);
143 GroupPoints->SpinBox2->SetValue(0.0);
144 GroupPoints->SpinBox3->SetValue(0.0);
146 /* signals and slots connections */
147 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
148 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
149 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
151 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
153 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
155 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); //@ Delete ?
157 connect(GroupPoints->SpinBox1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
158 connect(GroupPoints->SpinBox2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
159 connect(GroupPoints->SpinBox3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
161 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox1, SLOT(SetStep(double)));
162 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox2, SLOT(SetStep(double)));
163 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox3, SLOT(SetStep(double)));
165 connect(GroupPoints->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(ActivateDistanceChanged(bool)));
166 connect(GroupPoints->CheckBox2, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
168 connect(myGeomGUI->getApp()->selectionMgr(),
169 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
171 initName( tr( "GEOM_TRANSLATION" ) );
173 ConstructorsClicked( 0 );
178 //=================================================================================
179 // function : ConstructorsClicked()
180 // purpose : Radio button management
181 //=================================================================================
182 void TransformationGUI_TranslationDlg::ConstructorsClicked(int constructorId)
185 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
187 myEditCurrentArgument = GroupPoints->LineEdit1;
190 switch (constructorId)
192 case 0: /* translation an object by dx, dy, dz */
194 GroupPoints->ShowRows(1,2,false);
195 GroupPoints->TextLabel6->setText(tr("GEOM_DZ"));
196 GroupPoints->CheckBox1->hide();
198 GroupPoints->ShowRows(3,5,true);
199 GroupPoints->SpinBox3->setEnabled(true);
202 case 1: /* translation an object by 2 points */
204 GroupPoints->ShowRows(3,5,false);
205 GroupPoints->CheckBox1->hide();
206 GroupPoints->TextLabel6->setText(tr("GEOM_DZ"));
208 GroupPoints->ShowRows(0,2,true);
209 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("1"));
210 GroupPoints->LineEdit2->clear();
211 GroupPoints->LineEdit3->clear();
212 GroupPoints->SpinBox3->setEnabled(true);
213 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
216 case 2: /* translation an object by vector */
218 GroupPoints->CheckBox1->show();
219 GroupPoints->TextLabel6->setText(tr("GEOM_DISTANCE"));
220 GroupPoints->ShowRows(2,4,false);
221 GroupPoints->SpinBox3->SetValue(0.0);
222 GroupPoints->SpinBox3->setEnabled(false);
224 GroupPoints->ShowRows(0,1,true);
225 GroupPoints->ShowRows(5,5,true);
226 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
227 GroupPoints->LineEdit2->clear();
228 myVector = GEOM::GEOM_Object::_nil();
229 ActivateDistanceChanged(GroupPoints->CheckBox1->isChecked());
234 myEditCurrentArgument->setFocus();
235 connect(myGeomGUI->getApp()->selectionMgr(),
236 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
238 qApp->processEvents();
240 resize(minimumSize());
244 //=================================================================================
245 // function : ClickOnOk()
247 //=================================================================================
248 void TransformationGUI_TranslationDlg::ClickOnOk()
250 if ( ClickOnApply() )
255 //=================================================================================
256 // function : ClickOnApply()
258 //=================================================================================
259 bool TransformationGUI_TranslationDlg::ClickOnApply()
261 if ( !onAccept(GroupPoints->CheckBox2->isChecked()) )
269 //=================================================================================
270 // function : SelectionIntoArgument()
271 // purpose : Called when selection as changed or other case
272 //=================================================================================
273 void TransformationGUI_TranslationDlg::SelectionIntoArgument()
275 myEditCurrentArgument->setText("");
278 if (myEditCurrentArgument == GroupPoints->LineEdit1)
280 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
287 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
288 if (!myObjects.length())
293 if (IObjectCount() != 1) {
294 if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
295 myPoint1 = GEOM::GEOM_Object::_nil();
296 else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
297 myVector = GEOM::GEOM_Object::_nil();
298 else if (myEditCurrentArgument == GroupPoints->LineEdit3)
299 myPoint2 = GEOM::GEOM_Object::_nil();
303 Standard_Boolean testResult = Standard_False;
304 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult);
306 if (!testResult || CORBA::is_nil( aSelectedObject ))
310 aName = GEOMBase::GetName( aSelectedObject );
311 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
313 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
314 if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
315 aNeedType = TopAbs_EDGE;
317 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
318 TColStd_IndexedMapOfInteger aMap;
319 aSelMgr->GetIndexes( firstIObject(), aMap );
320 if ( aMap.Extent() == 1 )
322 int anIndex = aMap( 1 );
323 if (aNeedType == TopAbs_EDGE)
324 aName += QString(":edge_%1").arg(anIndex);
326 aName += QString(":vertex_%1").arg(anIndex);
328 //Find SubShape Object in Father
329 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
331 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
332 GEOM::GEOM_IShapesOperations_var aShapesOp =
333 getGeomEngine()->GetIShapesOperations( getStudyId() );
334 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
337 aSelectedObject = aFindedObject;
339 else // Global Selection
341 if (aShape.ShapeType() != aNeedType) {
342 aSelectedObject = GEOM::GEOM_Object::_nil();
348 if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
349 myPoint1 = aSelectedObject;
350 else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
351 myVector = aSelectedObject;
352 else if (myEditCurrentArgument == GroupPoints->LineEdit3)
353 myPoint2 = aSelectedObject;
356 myEditCurrentArgument->setText( aName );
361 //=================================================================================
362 // function : LineEditReturnPressed()
364 //=================================================================================
365 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
367 QLineEdit* send = (QLineEdit*)sender();
368 if (send == GroupPoints->LineEdit1)
370 myEditCurrentArgument = send;
371 GEOMBase_Skeleton::LineEditReturnPressed();
376 //=================================================================================
377 // function : SetEditCurrentArgument()
379 //=================================================================================
380 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
382 QPushButton* send = (QPushButton*)sender();
385 if (send == GroupPoints->PushButton1) {
386 myEditCurrentArgument = GroupPoints->LineEdit1;
388 else if (send == GroupPoints->PushButton2) {
389 myEditCurrentArgument = GroupPoints->LineEdit2;
390 if (getConstructorId() == 1)
391 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
393 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
395 else if (send == GroupPoints->PushButton3) {
396 myEditCurrentArgument = GroupPoints->LineEdit3;
397 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
400 myEditCurrentArgument->setFocus();
401 SelectionIntoArgument();
405 //=================================================================================
406 // function : ActivateThisDialog()
408 //=================================================================================
409 void TransformationGUI_TranslationDlg::ActivateThisDialog()
411 GEOMBase_Skeleton::ActivateThisDialog();
413 connect(myGeomGUI->getApp()->selectionMgr(),
414 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
416 ConstructorsClicked( getConstructorId() );
420 //=================================================================================
421 // function : enterEvent()
423 //=================================================================================
424 void TransformationGUI_TranslationDlg::enterEvent(QEvent* e)
426 if (!GroupConstructors->isEnabled())
427 ActivateThisDialog();
431 //=================================================================================
432 // function : ValueChangedInSpinBox()
434 //=================================================================================
435 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox()
441 //=================================================================================
442 // function : createOperation
444 //=================================================================================
445 GEOM::GEOM_IOperations_ptr TransformationGUI_TranslationDlg::createOperation()
447 return getGeomEngine()->GetITransformOperations( getStudyId() );
451 //=================================================================================
452 // function : isValid
454 //=================================================================================
455 bool TransformationGUI_TranslationDlg::isValid( QString& msg )
457 int aConstructorId = getConstructorId();
459 switch (aConstructorId)
463 Handle(SALOME_InteractiveObject) IO = firstIObject();
464 Standard_Boolean testResult;
465 GEOM::GEOM_Object_var anObject = GEOMBase::ConvertIOinGEOMObject( IO, testResult );
466 if ( !testResult || anObject->_is_nil() )
469 return !(myObjects.length() == 0 );
474 return !(myObjects.length() == 0 || myPoint1->_is_nil() || myPoint2->_is_nil() );
479 return !(myObjects.length() == 0 || myVector->_is_nil());
482 default: return false;
486 //=================================================================================
487 // function : execute
489 //=================================================================================
490 bool TransformationGUI_TranslationDlg::execute( ObjectList& objects )
493 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox2->isChecked();
495 GEOM::GEOM_Object_var anObj;
497 switch ( getConstructorId() )
501 double dx = GroupPoints->SpinBox1->GetValue();
502 double dy = GroupPoints->SpinBox2->GetValue();
503 double dz = GroupPoints->SpinBox3->GetValue();
506 for (int i = 0; i < myObjects.length(); i++)
508 myCurrObject = myObjects[i];
509 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
510 TranslateDXDYDZCopy( myObjects[i], dx, dy, dz );
511 if ( !anObj->_is_nil() )
512 objects.push_back( anObj._retn() );
515 for (int i = 0; i < myObjects.length(); i++)
517 myCurrObject = myObjects[i];
518 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
519 TranslateDXDYDZ( myObjects[i], dx, dy, dz );
520 if ( !anObj->_is_nil() )
521 objects.push_back( anObj._retn() );
529 for (int i = 0; i < myObjects.length(); i++)
531 myCurrObject = myObjects[i];
532 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
533 TranslateTwoPointsCopy( myObjects[i], myPoint1, myPoint2 );
534 if ( !anObj->_is_nil() )
535 objects.push_back( anObj._retn() );
538 for (int i = 0; i < myObjects.length(); i++)
540 myCurrObject = myObjects[i];
541 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
542 TranslateTwoPoints( myObjects[i], myPoint1, myPoint2 );
543 if ( !anObj->_is_nil() )
544 objects.push_back( anObj._retn() );
551 bool byDistance = GroupPoints->CheckBox1->isChecked();
553 double aDistance = GroupPoints->SpinBox3->GetValue();
554 for (int i = 0; i < myObjects.length(); i++) {
555 myCurrObject = myObjects[i];
556 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
557 TranslateVectorDistance( myObjects[i], myVector, aDistance, toCreateCopy );
558 if ( !anObj->_is_nil() )
559 objects.push_back( anObj._retn() );
564 for (int i = 0; i < myObjects.length(); i++)
566 myCurrObject = myObjects[i];
567 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
568 TranslateVectorCopy( myObjects[i], myVector );
569 if ( !anObj->_is_nil() )
570 objects.push_back( anObj._retn() );
574 for (int i = 0; i < myObjects.length(); i++)
576 myCurrObject = myObjects[i];
577 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
578 TranslateVector( myObjects[i], myVector );
579 if ( !anObj->_is_nil() )
580 objects.push_back( anObj._retn() );
590 //=================================================================================
591 // function : restoreSubShapes
593 //=================================================================================
594 void TransformationGUI_TranslationDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
595 SALOMEDS::SObject_ptr theSObject)
597 if (CheckBoxRestoreSS->isChecked()) {
598 // we pass here the first operation argument (object) through the list of arguments
599 // because the rotation operation place its arguments in the data structure in another order,
600 // and we need to point the first argument directly
601 GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
603 anArgs[0] = myCurrObject;
604 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
605 /*theFindMethod=*/GEOM::FSM_Transformed,
606 /*theInheritFirstArg=*/true);
610 //=================================================================================
611 // function : CreateCopyModeChanged()
613 //=================================================================================
614 void TransformationGUI_TranslationDlg::CreateCopyModeChanged(bool isCreateCopy)
616 GroupBoxName->setEnabled(isCreateCopy);
619 //=================================================================================
620 // function : ActivateDistanceChanged()
622 //=================================================================================
623 void TransformationGUI_TranslationDlg::ActivateDistanceChanged(bool theEnable)
625 GroupPoints->SpinBox3->setEnabled(theEnable);
629 //=================================================================================
630 // function : addSubshapeToStudy
631 // purpose : virtual method to add new SubObjects if local selection
632 //=================================================================================
633 void TransformationGUI_TranslationDlg::addSubshapesToStudy()
635 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox2->isChecked();
637 QMap<QString, GEOM::GEOM_Object_var> objMap;
639 switch (getConstructorId())
644 objMap[GroupPoints->LineEdit2->text()] = myPoint1;
645 objMap[GroupPoints->LineEdit3->text()] = myPoint2;
648 objMap[GroupPoints->LineEdit2->text()] = myVector;
651 addSubshapesToFather( objMap );