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_MultiRotationDlg.cxx
24 // Author : Damien COQUERET
28 #include "TransformationGUI_MultiRotationDlg.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>
42 #include <qcheckbox.h>
45 #include "GEOMImpl_Types.hxx"
47 #include "utilities.h"
51 //=================================================================================
52 // class : TransformationGUI_MultiRotationDlg()
53 // purpose : Constructs a TransformationGUI_MultiRotationDlg which is a child of 'parent', with the
54 // name 'name' and widget flags set to 'f'.
55 // The dialog will by default be modeless, unless you set 'modal' to
56 // TRUE to construct a modal dialog.
57 //=================================================================================
58 TransformationGUI_MultiRotationDlg::TransformationGUI_MultiRotationDlg
59 (GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
60 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
61 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
63 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
64 QPixmap image0(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_SIMPLE")));
65 QPixmap image1(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_DOUBLE")));
66 QPixmap image2(aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
68 setCaption(tr("GEOM_MULTIROTATION_TITLE"));
70 /***************************************************************/
71 GroupConstructors->setTitle(tr("GEOM_MULTIROTATION"));
72 RadioButton1->setPixmap(image0);
73 RadioButton2->setPixmap(image1);
74 RadioButton3->close(TRUE);
76 GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
77 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_SIMPLE"));
78 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
79 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
80 GroupPoints->TextLabel3->setText(tr("GEOM_NB_TIMES"));
81 GroupPoints->PushButton1->setPixmap(image2);
82 GroupPoints->PushButton2->setPixmap(image2);
83 GroupPoints->LineEdit1->setReadOnly(true);
84 GroupPoints->LineEdit2->setReadOnly(true);
86 GroupDimensions = new DlgRef_2Sel4Spin1Check(this, "GroupDimensions");
87 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_DOUBLE"));
88 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
89 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR"));
90 GroupDimensions->TextLabel3->setText(tr("GEOM_ANGLE"));
91 GroupDimensions->TextLabel4->setText(tr("GEOM_NB_TIMES"));
92 GroupDimensions->TextLabel5->setText(tr("GEOM_STEP"));
93 GroupDimensions->TextLabel6->setText(tr("GEOM_NB_TIMES"));
94 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE"));
95 GroupDimensions->PushButton1->setPixmap(image2);
96 GroupDimensions->PushButton2->setPixmap(image2);
97 GroupDimensions->LineEdit1->setReadOnly(true);
98 GroupDimensions->LineEdit2->setReadOnly(true);
100 Layout1->addWidget(GroupPoints, 2, 0);
101 Layout1->addWidget(GroupDimensions, 2, 0);
102 /***************************************************************/
104 setHelpFileName("multi_rotation_operation_page.html");
110 //=================================================================================
111 // function : ~TransformationGUI_MultiRotationDlg()
112 // purpose : Destroys the object and frees any allocated resources
113 //=================================================================================
114 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
116 // no need to delete child widgets, Qt does it all for us
120 //=================================================================================
123 //=================================================================================
124 void TransformationGUI_MultiRotationDlg::Init()
126 /* Get setting of step value from file configuration */
127 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
128 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
130 double SpecificStep1 = 5;
131 double SpecificStep2 = 1;
132 /* min, max, step and decimals for spin boxes & initial values */
133 GroupPoints->SpinBox_DX->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep2, 10);
134 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
136 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep1, DBL_DIGITS_DISPLAY);
137 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep2, 10);
138 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
139 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep2, 10);
140 GroupDimensions->SpinBox_DX1->SetValue(myAng);
141 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
142 GroupDimensions->SpinBox_DX2->SetValue(myStep);
143 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
145 /* signals and slots connections */
146 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
147 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
148 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
150 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
153 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
155 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
156 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
157 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
158 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
160 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
161 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
162 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
163 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
164 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
166 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
167 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
168 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
169 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
170 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
172 connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseAngle()));
174 connect(myGeomGUI->getApp()->selectionMgr(),
175 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
177 initName( tr( "GEOM_MULTIROTATION" ) );
178 ConstructorsClicked( 0 );
182 //=================================================================================
183 // function : ConstructorsClicked()
184 // purpose : Radio button management
185 //=================================================================================
186 void TransformationGUI_MultiRotationDlg::ConstructorsClicked(int constructorId)
188 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
192 myNbTimes1 = myNbTimes2 = 2;
194 globalSelection( GEOM_ALLSHAPES );
196 switch (constructorId)
198 case 0: /* Rotate simple */
200 GroupDimensions->hide();
204 myEditCurrentArgument = GroupPoints->LineEdit1;
205 GroupPoints->LineEdit1->setText("");
206 GroupPoints->LineEdit2->setText("");
208 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
212 case 1: /* Rotate double */
216 GroupDimensions->show();
218 myEditCurrentArgument = GroupDimensions->LineEdit1;
219 GroupDimensions->LineEdit1->setText("");
220 GroupDimensions->LineEdit2->setText("");
222 GroupDimensions->SpinBox_DX1->SetValue(myAng);
223 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
224 GroupDimensions->SpinBox_DX2->SetValue(myStep);
225 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
231 myEditCurrentArgument->setFocus();
232 myBase = myVector = GEOM::GEOM_Object::_nil();
233 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
234 this, SLOT(SelectionIntoArgument()));
238 //=================================================================================
239 // function : ClickOnOk()
241 //=================================================================================
242 void TransformationGUI_MultiRotationDlg::ClickOnOk()
244 if ( ClickOnApply() )
249 //=================================================================================
250 // function : ClickOnApply()
252 //=================================================================================
253 bool TransformationGUI_MultiRotationDlg::ClickOnApply()
259 ConstructorsClicked( getConstructorId() );
264 //=================================================================================
265 // function : SelectionIntoArgument()
266 // purpose : Called when selection as changed or other case
267 //=================================================================================
268 void TransformationGUI_MultiRotationDlg::SelectionIntoArgument()
270 myEditCurrentArgument->setText("");
272 if (IObjectCount() != 1) {
273 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
274 myEditCurrentArgument == GroupDimensions->LineEdit1)
275 myBase = GEOM::GEOM_Object::_nil();
276 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
277 myEditCurrentArgument == GroupDimensions->LineEdit2)
278 myVector = GEOM::GEOM_Object::_nil();
283 Standard_Boolean testResult = Standard_False;;
284 GEOM::GEOM_Object_var aSelectedObject =
285 GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
287 if (!testResult || CORBA::is_nil(aSelectedObject) || !GEOMBase::IsShape(aSelectedObject))
290 QString aName = GEOMBase::GetName( aSelectedObject );
292 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
293 myEditCurrentArgument == GroupDimensions->LineEdit1)
294 myBase = aSelectedObject;
295 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
296 myEditCurrentArgument == GroupDimensions->LineEdit2) {
297 if ( testResult && !aSelectedObject->_is_nil() )
302 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
304 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
305 TColStd_IndexedMapOfInteger aMap;
306 aSelMgr->GetIndexes( firstIObject(), aMap );
307 if ( aMap.Extent() == 1 )
309 int anIndex = aMap( 1 );
310 aName += QString(":edge_%1").arg(anIndex);
312 //Find SubShape Object in Father
313 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
315 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
316 GEOM::GEOM_IShapesOperations_var aShapesOp =
317 getGeomEngine()->GetIShapesOperations( getStudyId() );
318 myVector = aShapesOp->GetSubShape(aSelectedObject, anIndex);
321 myVector = aFindedObject; // get existing object
324 if (aShape.ShapeType() != TopAbs_EDGE) {
325 aSelectedObject = GEOM::GEOM_Object::_nil();
328 myVector = aSelectedObject;
334 myEditCurrentArgument->setText( aName );
340 //=================================================================================
341 // function : SetEditCurrentArgument()
343 //=================================================================================
344 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
346 QPushButton* send = (QPushButton*)sender();
347 globalSelection( GEOM_ALLSHAPES );
349 if(send == GroupPoints->PushButton1) {
350 myEditCurrentArgument = GroupPoints->LineEdit1;
352 else if(send == GroupPoints->PushButton2) {
353 myEditCurrentArgument = GroupPoints->LineEdit2;
354 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
356 else if(send == GroupDimensions->PushButton1) {
357 myEditCurrentArgument = GroupDimensions->LineEdit1;
359 else if(send == GroupDimensions->PushButton2) {
360 myEditCurrentArgument = GroupDimensions->LineEdit2;
361 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
364 myEditCurrentArgument->setFocus();
365 SelectionIntoArgument();
369 //=================================================================================
370 // function : LineEditReturnPressed()
372 //=================================================================================
373 void TransformationGUI_MultiRotationDlg::LineEditReturnPressed()
375 QLineEdit* send = (QLineEdit*)sender();
376 if(send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
377 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2)
379 myEditCurrentArgument = send;
380 GEOMBase_Skeleton::LineEditReturnPressed();
385 //=================================================================================
386 // function : ActivateThisDialog()
388 //=================================================================================
389 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
391 GEOMBase_Skeleton::ActivateThisDialog();
392 connect(myGeomGUI->getApp()->selectionMgr(),
393 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
395 ConstructorsClicked( getConstructorId() );
399 //=================================================================================
400 // function : enterEvent()
402 //=================================================================================
403 void TransformationGUI_MultiRotationDlg::enterEvent(QEvent* e)
405 if(!GroupConstructors->isEnabled())
406 ActivateThisDialog();
410 //=================================================================================
411 // function : ValueChangedInSpinBox()
413 //=================================================================================
414 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox(double newValue)
416 QObject* send = (QObject*)sender();
418 if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1)
419 myNbTimes1 = (int)newValue;
420 else if(send == GroupDimensions->SpinBox_DX1)
422 else if(send == GroupDimensions->SpinBox_DX2)
424 else if(send == GroupDimensions->SpinBox_DY2)
425 myNbTimes2 = (int)newValue;
431 //=================================================================================
432 // function : ReverseAngle()
433 // purpose : 'state' not used here
434 //=================================================================================
435 void TransformationGUI_MultiRotationDlg::ReverseAngle()
439 int aConstructorId = getConstructorId();
441 if(aConstructorId == 0)
442 GroupPoints->SpinBox_DX->SetValue(myAng);
443 else if(aConstructorId == 1)
444 GroupDimensions->SpinBox_DX1->SetValue(myAng);
450 //=================================================================================
451 // function : createOperation
453 //=================================================================================
454 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiRotationDlg::createOperation()
456 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
460 //=================================================================================
461 // function : isValid
463 //=================================================================================
464 bool TransformationGUI_MultiRotationDlg::isValid( QString& msg )
466 return !(myBase->_is_nil() || myVector->_is_nil());
469 //=================================================================================
470 // function : execute
472 //=================================================================================
473 bool TransformationGUI_MultiRotationDlg::execute( ObjectList& objects )
477 GEOM::GEOM_Object_var anObj;
479 switch ( getConstructorId() )
483 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
484 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
485 MultiRotate1D( myBase, myVector, myNbTimes1 );
492 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) )
494 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
495 MultiRotate2D( myBase, myVector, myAng, myNbTimes1, myStep, myNbTimes2 );
502 if ( !anObj->_is_nil() )
503 objects.push_back( anObj._retn() );
509 //=================================================================================
510 // function : closeEvent
512 //=================================================================================
513 void TransformationGUI_MultiRotationDlg::closeEvent( QCloseEvent* e )
515 // myGeomGUI->SetState( -1 );
516 GEOMBase_Skeleton::closeEvent( e );
519 //=================================================================================
520 // function : addSubshapeToStudy
521 // purpose : virtual method to add new SubObjects if local selection
522 //=================================================================================
523 void TransformationGUI_MultiRotationDlg::addSubshapesToStudy()
525 QMap<QString, GEOM::GEOM_Object_var> objMap;
527 switch (getConstructorId())
530 objMap[GroupPoints->LineEdit2->text()] = myVector;
533 objMap[GroupDimensions->LineEdit2->text()] = myVector;
536 addSubshapesToFather( objMap );