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_MultiTranslationDlg.cxx
25 // Author : Damien COQUERET
29 #include "TransformationGUI_MultiTranslationDlg.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>
45 #include "GEOMImpl_Types.hxx"
47 #include <qcheckbox.h>
49 #include "utilities.h"
53 //=================================================================================
54 // class : TransformationGUI_MultiTranslationDlg()
55 // purpose : Constructs a TransformationGUI_MultiTranslationDlg 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_MultiTranslationDlg::TransformationGUI_MultiTranslationDlg
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_MULTITRANSLATION_SIMPLE")));
67 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MULTITRANSLATION_DOUBLE")));
68 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
70 setCaption(tr("GEOM_MULTITRANSLATION_TITLE"));
72 /***************************************************************/
73 GroupConstructors->setTitle(tr("GEOM_MULTITRANSLATION"));
74 RadioButton1->setPixmap(image0);
75 RadioButton2->setPixmap(image1);
76 RadioButton3->close(TRUE);
78 GroupPoints = new DlgRef_2Sel2Spin1Check(this, "GroupPoints");
79 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_SIMPLE"));
80 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
81 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR_U"));
82 GroupPoints->TextLabel3->setText(tr("GEOM_STEP_U"));
83 GroupPoints->TextLabel4->setText(tr("GEOM_NB_TIMES_U"));
84 GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE_U"));
85 GroupPoints->PushButton1->setPixmap(image2);
86 GroupPoints->PushButton2->setPixmap(image2);
87 GroupPoints->LineEdit1->setReadOnly(true);
88 GroupPoints->LineEdit2->setReadOnly(true);
90 GroupDimensions = new DlgRef_3Sel4Spin2Check(this, "GroupDimensions");
91 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_DOUBLE"));
92 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
93 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR_U"));
94 GroupDimensions->TextLabel3->setText(tr("GEOM_VECTOR_V"));
95 GroupDimensions->TextLabel4->setText(tr("GEOM_STEP_U"));
96 GroupDimensions->TextLabel5->setText(tr("GEOM_NB_TIMES_U"));
97 GroupDimensions->TextLabel6->setText(tr("GEOM_STEP_V"));
98 GroupDimensions->TextLabel7->setText(tr("GEOM_NB_TIMES_V"));
99 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE_U"));
100 GroupDimensions->CheckButton2->setText(tr("GEOM_REVERSE_V"));
101 GroupDimensions->PushButton1->setPixmap(image2);
102 GroupDimensions->PushButton2->setPixmap(image2);
103 GroupDimensions->PushButton3->setPixmap(image2);
104 GroupDimensions->LineEdit1->setReadOnly(true);
105 GroupDimensions->LineEdit2->setReadOnly(true);
106 GroupDimensions->LineEdit3->setReadOnly(true);
108 Layout1->addWidget(GroupPoints, 2, 0);
109 Layout1->addWidget(GroupDimensions, 2, 0);
110 /***************************************************************/
112 setHelpFileName("multi_translation_operation_page.html");
118 //=================================================================================
119 // function : ~TransformationGUI_MultiTranslationDlg()
120 // purpose : Destroys the object and frees any allocated resources
121 //=================================================================================
122 TransformationGUI_MultiTranslationDlg::~TransformationGUI_MultiTranslationDlg()
124 // no need to delete child widgets, Qt does it all for us
128 //=================================================================================
131 //=================================================================================
132 void TransformationGUI_MultiTranslationDlg::Init()
134 /* Get setting of step value from file configuration */
135 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
136 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
138 double SpecificStep = 1;
139 /* min, max, step and decimals for spin boxes & initial values */
140 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
141 GroupPoints->SpinBox_DY->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep, 10);
142 GroupPoints->SpinBox_DX->SetValue(myStepU);
143 GroupPoints->SpinBox_DY->SetValue(myNbTimesU);
145 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
146 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep, 10);
147 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
148 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep, 10);
149 GroupDimensions->SpinBox_DX1->SetValue(myStepU);
150 GroupDimensions->SpinBox_DY1->SetValue(myNbTimesU);
151 GroupDimensions->SpinBox_DX2->SetValue(myStepV);
152 GroupDimensions->SpinBox_DY2->SetValue(myNbTimesV);
154 /* signals and slots connections */
155 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
156 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
157 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
159 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
160 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
161 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
162 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
163 connect(GroupDimensions->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
165 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
166 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
167 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
168 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
169 connect(GroupDimensions->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
171 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
172 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
173 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
174 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
175 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
176 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
178 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
179 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
180 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
181 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
182 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
183 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
185 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
186 connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
187 connect(GroupDimensions->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(ReverseStepV()));
189 connect(myGeomGUI->getApp()->selectionMgr(),
190 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
192 initName( tr( "GEOM_MULTITRANSLATION" ) );
193 ConstructorsClicked( 0 );
197 //=================================================================================
198 // function : ConstructorsClicked()
199 // purpose : Radio button management
200 //=================================================================================
201 void TransformationGUI_MultiTranslationDlg::ConstructorsClicked(int constructorId)
203 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
205 myStepU = myStepV = 50.0;
206 myNbTimesU = myNbTimesV = 2;
208 globalSelection( GEOM_ALLSHAPES );
210 switch (constructorId)
212 case 0: /* Translate simple */
214 GroupDimensions->hide();
218 myEditCurrentArgument = GroupPoints->LineEdit1;
219 GroupPoints->LineEdit1->setText("");
220 GroupPoints->LineEdit2->setText("");
222 GroupPoints->SpinBox_DX->SetValue(myStepU);
223 GroupPoints->SpinBox_DY->SetValue(myNbTimesU);
227 case 1: /* Translate double */
231 GroupDimensions->show();
233 myEditCurrentArgument = GroupDimensions->LineEdit1;
234 GroupDimensions->LineEdit1->setText("");
235 GroupDimensions->LineEdit2->setText("");
236 GroupDimensions->LineEdit3->setText("");
238 GroupDimensions->SpinBox_DX1->SetValue(myStepU);
239 GroupDimensions->SpinBox_DY1->SetValue(myNbTimesU);
240 GroupDimensions->SpinBox_DX2->SetValue(myStepV);
241 GroupDimensions->SpinBox_DY2->SetValue(myNbTimesV);
243 myVectorV = GEOM::GEOM_Object::_nil();
248 myEditCurrentArgument->setFocus();
249 myBase = myVectorU = GEOM::GEOM_Object::_nil();
250 connect(myGeomGUI->getApp()->selectionMgr(),
251 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
255 //=================================================================================
256 // function : ClickOnOk()
258 //=================================================================================
259 void TransformationGUI_MultiTranslationDlg::ClickOnOk()
261 if ( ClickOnApply() )
266 //=================================================================================
267 // function : ClickOnApply()
269 //=================================================================================
270 bool TransformationGUI_MultiTranslationDlg::ClickOnApply()
276 ConstructorsClicked( getConstructorId() );
281 //=================================================================================
282 // function : SelectionIntoArgument()
283 // purpose : Called when selection as changed or other case
284 //=================================================================================
285 void TransformationGUI_MultiTranslationDlg::SelectionIntoArgument()
287 myEditCurrentArgument->setText("");
289 if (IObjectCount() != 1) {
290 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
291 myEditCurrentArgument == GroupDimensions->LineEdit1)
292 myBase = GEOM::GEOM_Object::_nil();
293 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
294 myEditCurrentArgument == GroupDimensions->LineEdit2)
295 myVectorU = GEOM::GEOM_Object::_nil();
296 else if (myEditCurrentArgument == GroupDimensions->LineEdit3)
297 myVectorV = GEOM::GEOM_Object::_nil();
302 Standard_Boolean testResult = Standard_False;;
303 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
305 if ( !testResult || CORBA::is_nil( aSelectedObject ) || !GEOMBase::IsShape( aSelectedObject ) )
308 QString aName = GEOMBase::GetName( aSelectedObject );
310 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
311 myEditCurrentArgument == GroupDimensions->LineEdit1)
312 myBase = aSelectedObject;
313 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
314 myEditCurrentArgument == GroupDimensions->LineEdit2 ||
315 myEditCurrentArgument == GroupDimensions->LineEdit3 ) {
316 if ( testResult && !aSelectedObject->_is_nil() )
320 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
322 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
323 TColStd_IndexedMapOfInteger aMap;
324 aSelMgr->GetIndexes( firstIObject(), aMap );
325 if ( aMap.Extent() == 1 )
327 int anIndex = aMap( 1 );
328 aName += QString(":edge_%1").arg(anIndex);
330 //Find SubShape Object in Father
331 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
333 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
334 GEOM::GEOM_IShapesOperations_var aShapesOp =
335 getGeomEngine()->GetIShapesOperations( getStudyId() );
336 if ( myEditCurrentArgument == GroupDimensions->LineEdit3 )
337 myVectorV = aShapesOp->GetSubShape(aSelectedObject, anIndex);
339 myVectorU = aShapesOp->GetSubShape(aSelectedObject, anIndex);
342 if ( myEditCurrentArgument == GroupDimensions->LineEdit3 )
343 myVectorV = aFindedObject;
345 myVectorU = aFindedObject;
349 if (aShape.ShapeType() != TopAbs_EDGE) {
350 aSelectedObject = GEOM::GEOM_Object::_nil();
353 if ( myEditCurrentArgument == GroupDimensions->LineEdit3 )
354 myVectorV = aSelectedObject;
356 myVectorU = aSelectedObject;
362 myEditCurrentArgument->setText( aName );
368 //=================================================================================
369 // function : SetEditCurrentArgument()
371 //=================================================================================
372 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
374 QPushButton* send = (QPushButton*)sender();
375 globalSelection( GEOM_ALLSHAPES );
377 if(send == GroupPoints->PushButton1) {
378 myEditCurrentArgument = GroupPoints->LineEdit1;
380 else if(send == GroupPoints->PushButton2) {
381 myEditCurrentArgument = GroupPoints->LineEdit2;
382 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
384 else if(send == GroupDimensions->PushButton1) {
385 myEditCurrentArgument = GroupDimensions->LineEdit1;
387 else if(send == GroupDimensions->PushButton2) {
388 myEditCurrentArgument = GroupDimensions->LineEdit2;
389 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
391 else if(send == GroupDimensions->PushButton3) {
392 myEditCurrentArgument = GroupDimensions->LineEdit3;
393 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
396 myEditCurrentArgument->setFocus();
397 SelectionIntoArgument();
401 //=================================================================================
402 // function : LineEditReturnPressed()
404 //=================================================================================
405 void TransformationGUI_MultiTranslationDlg::LineEditReturnPressed()
407 QLineEdit* send = (QLineEdit*)sender();
408 if(send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
409 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2 ||
410 send == GroupDimensions->LineEdit3)
412 myEditCurrentArgument = send;
413 GEOMBase_Skeleton::LineEditReturnPressed();
418 //=================================================================================
419 // function : ActivateThisDialog()
421 //=================================================================================
422 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
424 GEOMBase_Skeleton::ActivateThisDialog();
425 connect(myGeomGUI->getApp()->selectionMgr(),
426 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
428 ConstructorsClicked( getConstructorId() );
432 //=================================================================================
433 // function : enterEvent()
435 //=================================================================================
436 void TransformationGUI_MultiTranslationDlg::enterEvent(QEvent* e)
438 if(!GroupConstructors->isEnabled())
439 ActivateThisDialog();
443 //=================================================================================
444 // function : ValueChangedInSpinBox()
446 //=================================================================================
447 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox(double newValue)
449 QObject* send = (QObject*)sender();
451 switch(getConstructorId())
455 if(send == GroupPoints->SpinBox_DX)
457 else if(send == GroupPoints->SpinBox_DY)
458 myNbTimesU = (int)newValue;
463 if(send == GroupDimensions->SpinBox_DX1)
465 else if(send == GroupDimensions->SpinBox_DY1)
466 myNbTimesU = (int)newValue;
467 else if(send == GroupDimensions->SpinBox_DX2)
469 else if(send == GroupDimensions->SpinBox_DY2)
470 myNbTimesV = (int)newValue;
479 //=================================================================================
480 // function : ReverseStepU()
481 // purpose : 'state' not used here
482 //=================================================================================
483 void TransformationGUI_MultiTranslationDlg::ReverseStepU()
487 int aConstructorId = getConstructorId();
489 if(aConstructorId == 0)
490 GroupPoints->SpinBox_DX->SetValue(myStepU);
491 else if(aConstructorId == 1)
492 GroupDimensions->SpinBox_DX1->SetValue(myStepU);
498 //=================================================================================
499 // function : ReverseStepV
500 // purpose : 'state' not used here
501 //=================================================================================
502 void TransformationGUI_MultiTranslationDlg::ReverseStepV()
506 GroupDimensions->SpinBox_DX2->SetValue(myStepV);
512 //=================================================================================
513 // function : createOperation
515 //=================================================================================
516 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiTranslationDlg::createOperation()
518 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
522 //=================================================================================
523 // function : isValid
525 //=================================================================================
526 bool TransformationGUI_MultiTranslationDlg::isValid( QString& msg )
528 int aConstructorId = getConstructorId();
530 if(aConstructorId == 0)
531 return !(myBase->_is_nil() || myVectorU->_is_nil());
532 else if(aConstructorId == 1)
533 return !(myBase->_is_nil() || myVectorU->_is_nil() || myVectorV->_is_nil());
537 //=================================================================================
538 // function : execute
540 //=================================================================================
541 bool TransformationGUI_MultiTranslationDlg::execute( ObjectList& objects )
545 GEOM::GEOM_Object_var anObj;
547 switch ( getConstructorId() )
551 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) ) {
552 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate1D( myBase, myVectorU, myStepU, myNbTimesU );
559 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) && !CORBA::is_nil( myVectorV ) )
561 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate2D( myBase, myVectorU, myStepU, myNbTimesU,
562 myVectorV, myStepV, myNbTimesV );
569 if ( !anObj->_is_nil() )
570 objects.push_back( anObj._retn() );
576 //=================================================================================
577 // function : closeEvent
579 //=================================================================================
580 void TransformationGUI_MultiTranslationDlg::closeEvent( QCloseEvent* e )
582 // myGeomGUI->SetState( -1 );
583 GEOMBase_Skeleton::closeEvent( e );
586 //=================================================================================
587 // function : addSubshapeToStudy
588 // purpose : virtual method to add new SubObjects if local selection
589 //=================================================================================
590 void TransformationGUI_MultiTranslationDlg::addSubshapesToStudy()
592 QMap<QString, GEOM::GEOM_Object_var> objMap;
594 switch (getConstructorId())
597 objMap[GroupPoints->LineEdit2->text()] = myVectorU;
600 objMap[GroupDimensions->LineEdit2->text()] = myVectorU;
601 objMap[GroupDimensions->LineEdit3->text()] = myVectorV;
604 addSubshapesToFather( objMap );