1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : TransformationGUI_MultiTranslationDlg.cxx
24 // Author : Damien COQUERET
28 #include "TransformationGUI_MultiTranslationDlg.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Edge.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
44 #include "GEOMImpl_Types.hxx"
46 #include <qcheckbox.h>
48 #include "utilities.h"
52 //=================================================================================
53 // class : TransformationGUI_MultiTranslationDlg()
54 // purpose : Constructs a TransformationGUI_MultiTranslationDlg 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_MultiTranslationDlg::TransformationGUI_MultiTranslationDlg
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_MULTITRANSLATION_SIMPLE")));
66 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MULTITRANSLATION_DOUBLE")));
67 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
69 setCaption(tr("GEOM_MULTITRANSLATION_TITLE"));
71 /***************************************************************/
72 GroupConstructors->setTitle(tr("GEOM_MULTITRANSLATION"));
73 RadioButton1->setPixmap(image0);
74 RadioButton2->setPixmap(image1);
75 RadioButton3->close(TRUE);
77 GroupPoints = new DlgRef_2Sel2Spin1Check(this, "GroupPoints");
78 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_SIMPLE"));
79 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
80 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR_U"));
81 GroupPoints->TextLabel3->setText(tr("GEOM_STEP_U"));
82 GroupPoints->TextLabel4->setText(tr("GEOM_NB_TIMES_U"));
83 GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE_U"));
84 GroupPoints->PushButton1->setPixmap(image2);
85 GroupPoints->PushButton2->setPixmap(image2);
86 GroupPoints->LineEdit1->setReadOnly(true);
87 GroupPoints->LineEdit2->setReadOnly(true);
89 GroupDimensions = new DlgRef_3Sel4Spin2Check(this, "GroupDimensions");
90 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_DOUBLE"));
91 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
92 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR_U"));
93 GroupDimensions->TextLabel3->setText(tr("GEOM_VECTOR_V"));
94 GroupDimensions->TextLabel4->setText(tr("GEOM_STEP_U"));
95 GroupDimensions->TextLabel5->setText(tr("GEOM_NB_TIMES_U"));
96 GroupDimensions->TextLabel6->setText(tr("GEOM_STEP_V"));
97 GroupDimensions->TextLabel7->setText(tr("GEOM_NB_TIMES_V"));
98 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE_U"));
99 GroupDimensions->CheckButton2->setText(tr("GEOM_REVERSE_V"));
100 GroupDimensions->PushButton1->setPixmap(image2);
101 GroupDimensions->PushButton2->setPixmap(image2);
102 GroupDimensions->PushButton3->setPixmap(image2);
103 GroupDimensions->LineEdit1->setReadOnly(true);
104 GroupDimensions->LineEdit2->setReadOnly(true);
105 GroupDimensions->LineEdit3->setReadOnly(true);
107 Layout1->addWidget(GroupPoints, 2, 0);
108 Layout1->addWidget(GroupDimensions, 2, 0);
109 /***************************************************************/
111 setHelpFileName("multi_translation_operation_page.html");
117 //=================================================================================
118 // function : ~TransformationGUI_MultiTranslationDlg()
119 // purpose : Destroys the object and frees any allocated resources
120 //=================================================================================
121 TransformationGUI_MultiTranslationDlg::~TransformationGUI_MultiTranslationDlg()
123 // no need to delete child widgets, Qt does it all for us
127 //=================================================================================
130 //=================================================================================
131 void TransformationGUI_MultiTranslationDlg::Init()
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 double SpecificStep = 1;
138 /* min, max, step and decimals for spin boxes & initial values */
139 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
140 GroupPoints->SpinBox_DY->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep, 10);
141 GroupPoints->SpinBox_DX->SetValue(myStepU);
142 GroupPoints->SpinBox_DY->SetValue(myNbTimesU);
144 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
145 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep, 10);
146 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
147 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep, 10);
148 GroupDimensions->SpinBox_DX1->SetValue(myStepU);
149 GroupDimensions->SpinBox_DY1->SetValue(myNbTimesU);
150 GroupDimensions->SpinBox_DX2->SetValue(myStepV);
151 GroupDimensions->SpinBox_DY2->SetValue(myNbTimesV);
153 /* signals and slots connections */
154 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
155 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
156 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
158 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
159 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
160 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
161 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
162 connect(GroupDimensions->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
164 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
165 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
166 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
167 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
168 connect(GroupDimensions->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
170 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
171 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
172 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
173 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
174 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
175 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
177 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
178 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
179 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
180 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
181 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
182 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
184 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
185 connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
186 connect(GroupDimensions->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(ReverseStepV()));
188 connect(myGeomGUI->getApp()->selectionMgr(),
189 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
191 initName( tr( "GEOM_MULTITRANSLATION" ) );
192 ConstructorsClicked( 0 );
196 //=================================================================================
197 // function : ConstructorsClicked()
198 // purpose : Radio button management
199 //=================================================================================
200 void TransformationGUI_MultiTranslationDlg::ConstructorsClicked(int constructorId)
202 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
204 myStepU = myStepV = 50.0;
205 myNbTimesU = myNbTimesV = 2;
207 globalSelection( GEOM_ALLSHAPES );
209 switch (constructorId)
211 case 0: /* Translate simple */
213 GroupDimensions->hide();
217 myEditCurrentArgument = GroupPoints->LineEdit1;
218 GroupPoints->LineEdit1->setText("");
219 GroupPoints->LineEdit2->setText("");
221 GroupPoints->SpinBox_DX->SetValue(myStepU);
222 GroupPoints->SpinBox_DY->SetValue(myNbTimesU);
226 case 1: /* Translate double */
230 GroupDimensions->show();
232 myEditCurrentArgument = GroupDimensions->LineEdit1;
233 GroupDimensions->LineEdit1->setText("");
234 GroupDimensions->LineEdit2->setText("");
235 GroupDimensions->LineEdit3->setText("");
237 GroupDimensions->SpinBox_DX1->SetValue(myStepU);
238 GroupDimensions->SpinBox_DY1->SetValue(myNbTimesU);
239 GroupDimensions->SpinBox_DX2->SetValue(myStepV);
240 GroupDimensions->SpinBox_DY2->SetValue(myNbTimesV);
242 myVectorV = GEOM::GEOM_Object::_nil();
247 myEditCurrentArgument->setFocus();
248 myBase = myVectorU = GEOM::GEOM_Object::_nil();
249 connect(myGeomGUI->getApp()->selectionMgr(),
250 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
254 //=================================================================================
255 // function : ClickOnOk()
257 //=================================================================================
258 void TransformationGUI_MultiTranslationDlg::ClickOnOk()
260 if ( ClickOnApply() )
265 //=================================================================================
266 // function : ClickOnApply()
268 //=================================================================================
269 bool TransformationGUI_MultiTranslationDlg::ClickOnApply()
275 ConstructorsClicked( getConstructorId() );
280 //=================================================================================
281 // function : SelectionIntoArgument()
282 // purpose : Called when selection as changed or other case
283 //=================================================================================
284 void TransformationGUI_MultiTranslationDlg::SelectionIntoArgument()
286 myEditCurrentArgument->setText("");
288 if (IObjectCount() != 1) {
289 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
290 myEditCurrentArgument == GroupDimensions->LineEdit1)
291 myBase = GEOM::GEOM_Object::_nil();
292 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
293 myEditCurrentArgument == GroupDimensions->LineEdit2)
294 myVectorU = GEOM::GEOM_Object::_nil();
295 else if (myEditCurrentArgument == GroupDimensions->LineEdit3)
296 myVectorV = GEOM::GEOM_Object::_nil();
301 Standard_Boolean testResult = Standard_False;;
302 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
304 if ( !testResult || CORBA::is_nil( aSelectedObject ) || !GEOMBase::IsShape( aSelectedObject ) )
307 QString aName = GEOMBase::GetName( aSelectedObject );
309 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
310 myEditCurrentArgument == GroupDimensions->LineEdit1)
311 myBase = aSelectedObject;
312 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
313 myEditCurrentArgument == GroupDimensions->LineEdit2 ||
314 myEditCurrentArgument == GroupDimensions->LineEdit3 ) {
315 if ( testResult && !aSelectedObject->_is_nil() )
319 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
321 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
322 TColStd_IndexedMapOfInteger aMap;
323 aSelMgr->GetIndexes( firstIObject(), aMap );
324 if ( aMap.Extent() == 1 )
326 int anIndex = aMap( 1 );
327 aName += QString(":edge_%1").arg(anIndex);
329 //Find SubShape Object in Father
330 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
332 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
333 GEOM::GEOM_IShapesOperations_var aShapesOp =
334 getGeomEngine()->GetIShapesOperations( getStudyId() );
335 if ( myEditCurrentArgument == GroupDimensions->LineEdit3 )
336 myVectorV = aShapesOp->GetSubShape(aSelectedObject, anIndex);
338 myVectorU = aShapesOp->GetSubShape(aSelectedObject, anIndex);
341 if ( myEditCurrentArgument == GroupDimensions->LineEdit3 )
342 myVectorV = aFindedObject;
344 myVectorU = aFindedObject;
348 if (aShape.ShapeType() != TopAbs_EDGE) {
349 aSelectedObject = GEOM::GEOM_Object::_nil();
352 if ( myEditCurrentArgument == GroupDimensions->LineEdit3 )
353 myVectorV = aSelectedObject;
355 myVectorU = aSelectedObject;
361 myEditCurrentArgument->setText( aName );
367 //=================================================================================
368 // function : SetEditCurrentArgument()
370 //=================================================================================
371 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
373 QPushButton* send = (QPushButton*)sender();
374 globalSelection( GEOM_ALLSHAPES );
376 if(send == GroupPoints->PushButton1) {
377 myEditCurrentArgument = GroupPoints->LineEdit1;
379 else if(send == GroupPoints->PushButton2) {
380 myEditCurrentArgument = GroupPoints->LineEdit2;
381 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
383 else if(send == GroupDimensions->PushButton1) {
384 myEditCurrentArgument = GroupDimensions->LineEdit1;
386 else if(send == GroupDimensions->PushButton2) {
387 myEditCurrentArgument = GroupDimensions->LineEdit2;
388 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
390 else if(send == GroupDimensions->PushButton3) {
391 myEditCurrentArgument = GroupDimensions->LineEdit3;
392 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
395 myEditCurrentArgument->setFocus();
396 SelectionIntoArgument();
400 //=================================================================================
401 // function : LineEditReturnPressed()
403 //=================================================================================
404 void TransformationGUI_MultiTranslationDlg::LineEditReturnPressed()
406 QLineEdit* send = (QLineEdit*)sender();
407 if(send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
408 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2 ||
409 send == GroupDimensions->LineEdit3)
411 myEditCurrentArgument = send;
412 GEOMBase_Skeleton::LineEditReturnPressed();
417 //=================================================================================
418 // function : ActivateThisDialog()
420 //=================================================================================
421 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
423 GEOMBase_Skeleton::ActivateThisDialog();
424 connect(myGeomGUI->getApp()->selectionMgr(),
425 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
427 ConstructorsClicked( getConstructorId() );
431 //=================================================================================
432 // function : enterEvent()
434 //=================================================================================
435 void TransformationGUI_MultiTranslationDlg::enterEvent(QEvent* e)
437 if(!GroupConstructors->isEnabled())
438 ActivateThisDialog();
442 //=================================================================================
443 // function : ValueChangedInSpinBox()
445 //=================================================================================
446 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox(double newValue)
448 QObject* send = (QObject*)sender();
450 switch(getConstructorId())
454 if(send == GroupPoints->SpinBox_DX)
456 else if(send == GroupPoints->SpinBox_DY)
457 myNbTimesU = (int)newValue;
462 if(send == GroupDimensions->SpinBox_DX1)
464 else if(send == GroupDimensions->SpinBox_DY1)
465 myNbTimesU = (int)newValue;
466 else if(send == GroupDimensions->SpinBox_DX2)
468 else if(send == GroupDimensions->SpinBox_DY2)
469 myNbTimesV = (int)newValue;
478 //=================================================================================
479 // function : ReverseStepU()
480 // purpose : 'state' not used here
481 //=================================================================================
482 void TransformationGUI_MultiTranslationDlg::ReverseStepU()
486 int aConstructorId = getConstructorId();
488 if(aConstructorId == 0)
489 GroupPoints->SpinBox_DX->SetValue(myStepU);
490 else if(aConstructorId == 1)
491 GroupDimensions->SpinBox_DX1->SetValue(myStepU);
497 //=================================================================================
498 // function : ReverseStepV
499 // purpose : 'state' not used here
500 //=================================================================================
501 void TransformationGUI_MultiTranslationDlg::ReverseStepV()
505 GroupDimensions->SpinBox_DX2->SetValue(myStepV);
511 //=================================================================================
512 // function : createOperation
514 //=================================================================================
515 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiTranslationDlg::createOperation()
517 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
521 //=================================================================================
522 // function : isValid
524 //=================================================================================
525 bool TransformationGUI_MultiTranslationDlg::isValid( QString& msg )
527 int aConstructorId = getConstructorId();
529 if(aConstructorId == 0)
530 return !(myBase->_is_nil() || myVectorU->_is_nil());
531 else if(aConstructorId == 1)
532 return !(myBase->_is_nil() || myVectorU->_is_nil() || myVectorV->_is_nil());
536 //=================================================================================
537 // function : execute
539 //=================================================================================
540 bool TransformationGUI_MultiTranslationDlg::execute( ObjectList& objects )
544 GEOM::GEOM_Object_var anObj;
546 switch ( getConstructorId() )
550 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) ) {
551 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate1D( myBase, myVectorU, myStepU, myNbTimesU );
558 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) && !CORBA::is_nil( myVectorV ) )
560 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate2D( myBase, myVectorU, myStepU, myNbTimesU,
561 myVectorV, myStepV, myNbTimesV );
568 if ( !anObj->_is_nil() )
569 objects.push_back( anObj._retn() );
575 //=================================================================================
576 // function : closeEvent
578 //=================================================================================
579 void TransformationGUI_MultiTranslationDlg::closeEvent( QCloseEvent* e )
581 // myGeomGUI->SetState( -1 );
582 GEOMBase_Skeleton::closeEvent( e );
585 //=================================================================================
586 // function : addSubshapeToStudy
587 // purpose : virtual method to add new SubObjects if local selection
588 //=================================================================================
589 void TransformationGUI_MultiTranslationDlg::addSubshapesToStudy()
591 QMap<QString, GEOM::GEOM_Object_var> objMap;
593 switch (getConstructorId())
596 objMap[GroupPoints->LineEdit2->text()] = myVectorU;
599 objMap[GroupDimensions->LineEdit2->text()] = myVectorU;
600 objMap[GroupDimensions->LineEdit3->text()] = myVectorV;
603 addSubshapesToFather( objMap );