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_MultiRotationDlg.cxx
25 // Author : Damien COQUERET
29 #include "TransformationGUI_MultiRotationDlg.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>
43 #include <qcheckbox.h>
46 #include "GEOMImpl_Types.hxx"
48 #include "utilities.h"
52 //=================================================================================
53 // class : TransformationGUI_MultiRotationDlg()
54 // purpose : Constructs a TransformationGUI_MultiRotationDlg 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_MultiRotationDlg::TransformationGUI_MultiRotationDlg
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_MULTIROTATION_SIMPLE")));
66 QPixmap image1(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_DOUBLE")));
67 QPixmap image2(aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
69 setCaption(tr("GEOM_MULTIROTATION_TITLE"));
71 /***************************************************************/
72 GroupConstructors->setTitle(tr("GEOM_MULTIROTATION"));
73 RadioButton1->setPixmap(image0);
74 RadioButton2->setPixmap(image1);
75 RadioButton3->close(TRUE);
77 GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
78 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_SIMPLE"));
79 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
80 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
81 GroupPoints->TextLabel3->setText(tr("GEOM_NB_TIMES"));
82 GroupPoints->PushButton1->setPixmap(image2);
83 GroupPoints->PushButton2->setPixmap(image2);
84 GroupPoints->LineEdit1->setReadOnly(true);
85 GroupPoints->LineEdit2->setReadOnly(true);
87 GroupDimensions = new DlgRef_2Sel4Spin1Check(this, "GroupDimensions");
88 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_DOUBLE"));
89 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
90 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR"));
91 GroupDimensions->TextLabel3->setText(tr("GEOM_ANGLE"));
92 GroupDimensions->TextLabel4->setText(tr("GEOM_NB_TIMES"));
93 GroupDimensions->TextLabel5->setText(tr("GEOM_STEP"));
94 GroupDimensions->TextLabel6->setText(tr("GEOM_NB_TIMES"));
95 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE"));
96 GroupDimensions->PushButton1->setPixmap(image2);
97 GroupDimensions->PushButton2->setPixmap(image2);
98 GroupDimensions->LineEdit1->setReadOnly(true);
99 GroupDimensions->LineEdit2->setReadOnly(true);
101 Layout1->addWidget(GroupPoints, 2, 0);
102 Layout1->addWidget(GroupDimensions, 2, 0);
103 /***************************************************************/
105 setHelpFileName("multi_rotation.htm");
111 //=================================================================================
112 // function : ~TransformationGUI_MultiRotationDlg()
113 // purpose : Destroys the object and frees any allocated resources
114 //=================================================================================
115 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
117 // no need to delete child widgets, Qt does it all for us
121 //=================================================================================
124 //=================================================================================
125 void TransformationGUI_MultiRotationDlg::Init()
127 /* Get setting of step value from file configuration */
128 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
129 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
131 double SpecificStep1 = 5;
132 double SpecificStep2 = 1;
133 /* min, max, step and decimals for spin boxes & initial values */
134 GroupPoints->SpinBox_DX->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep2, 10);
135 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
137 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep1, DBL_DIGITS_DISPLAY);
138 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep2, 10);
139 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
140 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep2, 10);
141 GroupDimensions->SpinBox_DX1->SetValue(myAng);
142 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
143 GroupDimensions->SpinBox_DX2->SetValue(myStep);
144 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
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)), this, SLOT(ConstructorsClicked(int)));
151 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
153 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
157 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
158 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
161 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
162 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
163 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
164 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
165 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
167 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
168 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
169 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
170 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
171 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
173 connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseAngle()));
175 connect(myGeomGUI->getApp()->selectionMgr(),
176 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
178 initName( tr( "GEOM_MULTIROTATION" ) );
179 ConstructorsClicked( 0 );
183 //=================================================================================
184 // function : ConstructorsClicked()
185 // purpose : Radio button management
186 //=================================================================================
187 void TransformationGUI_MultiRotationDlg::ConstructorsClicked(int constructorId)
189 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
193 myNbTimes1 = myNbTimes2 = 2;
195 globalSelection( GEOM_ALLSHAPES );
197 switch (constructorId)
199 case 0: /* Rotate simple */
201 GroupDimensions->hide();
205 myEditCurrentArgument = GroupPoints->LineEdit1;
206 GroupPoints->LineEdit1->setText("");
207 GroupPoints->LineEdit2->setText("");
209 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
213 case 1: /* Rotate double */
217 GroupDimensions->show();
219 myEditCurrentArgument = GroupDimensions->LineEdit1;
220 GroupDimensions->LineEdit1->setText("");
221 GroupDimensions->LineEdit2->setText("");
223 GroupDimensions->SpinBox_DX1->SetValue(myAng);
224 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
225 GroupDimensions->SpinBox_DX2->SetValue(myStep);
226 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
232 myEditCurrentArgument->setFocus();
233 myBase = myVector = GEOM::GEOM_Object::_nil();
234 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
235 this, SLOT(SelectionIntoArgument()));
239 //=================================================================================
240 // function : ClickOnOk()
242 //=================================================================================
243 void TransformationGUI_MultiRotationDlg::ClickOnOk()
245 if ( ClickOnApply() )
250 //=================================================================================
251 // function : ClickOnApply()
253 //=================================================================================
254 bool TransformationGUI_MultiRotationDlg::ClickOnApply()
260 ConstructorsClicked( getConstructorId() );
265 //=================================================================================
266 // function : SelectionIntoArgument()
267 // purpose : Called when selection as changed or other case
268 //=================================================================================
269 void TransformationGUI_MultiRotationDlg::SelectionIntoArgument()
271 myEditCurrentArgument->setText("");
273 if (IObjectCount() != 1) {
274 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
275 myEditCurrentArgument == GroupDimensions->LineEdit1)
276 myBase = GEOM::GEOM_Object::_nil();
277 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
278 myEditCurrentArgument == GroupDimensions->LineEdit2)
279 myVector = GEOM::GEOM_Object::_nil();
284 Standard_Boolean testResult = Standard_False;;
285 GEOM::GEOM_Object_var aSelectedObject =
286 GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
288 if (!testResult || CORBA::is_nil(aSelectedObject) || !GEOMBase::IsShape(aSelectedObject))
291 QString aName = GEOMBase::GetName( aSelectedObject );
293 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
294 myEditCurrentArgument == GroupDimensions->LineEdit1)
295 myBase = aSelectedObject;
296 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
297 myEditCurrentArgument == GroupDimensions->LineEdit2) {
298 if ( testResult && !aSelectedObject->_is_nil() )
303 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
305 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
306 TColStd_IndexedMapOfInteger aMap;
307 aSelMgr->GetIndexes( firstIObject(), aMap );
308 if ( aMap.Extent() == 1 )
310 int anIndex = aMap( 1 );
311 aName += QString(":edge_%1").arg(anIndex);
313 //Find SubShape Object in Father
314 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
316 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
317 GEOM::GEOM_IShapesOperations_var aShapesOp =
318 getGeomEngine()->GetIShapesOperations( getStudyId() );
319 myVector = aShapesOp->GetSubShape(aSelectedObject, anIndex);
322 myVector = aFindedObject; // get existing object
325 if (aShape.ShapeType() != TopAbs_EDGE) {
326 aSelectedObject = GEOM::GEOM_Object::_nil();
329 myVector = aSelectedObject;
335 myEditCurrentArgument->setText( aName );
341 //=================================================================================
342 // function : SetEditCurrentArgument()
344 //=================================================================================
345 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
347 QPushButton* send = (QPushButton*)sender();
348 globalSelection( GEOM_ALLSHAPES );
350 if(send == GroupPoints->PushButton1) {
351 myEditCurrentArgument = GroupPoints->LineEdit1;
353 else if(send == GroupPoints->PushButton2) {
354 myEditCurrentArgument = GroupPoints->LineEdit2;
355 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
357 else if(send == GroupDimensions->PushButton1) {
358 myEditCurrentArgument = GroupDimensions->LineEdit1;
360 else if(send == GroupDimensions->PushButton2) {
361 myEditCurrentArgument = GroupDimensions->LineEdit2;
362 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
365 myEditCurrentArgument->setFocus();
366 SelectionIntoArgument();
370 //=================================================================================
371 // function : LineEditReturnPressed()
373 //=================================================================================
374 void TransformationGUI_MultiRotationDlg::LineEditReturnPressed()
376 QLineEdit* send = (QLineEdit*)sender();
377 if(send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
378 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2)
380 myEditCurrentArgument = send;
381 GEOMBase_Skeleton::LineEditReturnPressed();
386 //=================================================================================
387 // function : ActivateThisDialog()
389 //=================================================================================
390 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
392 GEOMBase_Skeleton::ActivateThisDialog();
393 connect(myGeomGUI->getApp()->selectionMgr(),
394 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
396 ConstructorsClicked( getConstructorId() );
400 //=================================================================================
401 // function : enterEvent()
403 //=================================================================================
404 void TransformationGUI_MultiRotationDlg::enterEvent(QEvent* e)
406 if(!GroupConstructors->isEnabled())
407 ActivateThisDialog();
411 //=================================================================================
412 // function : ValueChangedInSpinBox()
414 //=================================================================================
415 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox(double newValue)
417 QObject* send = (QObject*)sender();
419 if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1)
420 myNbTimes1 = (int)newValue;
421 else if(send == GroupDimensions->SpinBox_DX1)
423 else if(send == GroupDimensions->SpinBox_DX2)
425 else if(send == GroupDimensions->SpinBox_DY2)
426 myNbTimes2 = (int)newValue;
432 //=================================================================================
433 // function : ReverseAngle()
434 // purpose : 'state' not used here
435 //=================================================================================
436 void TransformationGUI_MultiRotationDlg::ReverseAngle()
440 int aConstructorId = getConstructorId();
442 if(aConstructorId == 0)
443 GroupPoints->SpinBox_DX->SetValue(myAng);
444 else if(aConstructorId == 1)
445 GroupDimensions->SpinBox_DX1->SetValue(myAng);
451 //=================================================================================
452 // function : createOperation
454 //=================================================================================
455 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiRotationDlg::createOperation()
457 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
461 //=================================================================================
462 // function : isValid
464 //=================================================================================
465 bool TransformationGUI_MultiRotationDlg::isValid( QString& msg )
467 return !(myBase->_is_nil() || myVector->_is_nil());
470 //=================================================================================
471 // function : execute
473 //=================================================================================
474 bool TransformationGUI_MultiRotationDlg::execute( ObjectList& objects )
478 GEOM::GEOM_Object_var anObj;
480 switch ( getConstructorId() )
484 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
485 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
486 MultiRotate1D( myBase, myVector, myNbTimes1 );
493 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) )
495 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
496 MultiRotate2D( myBase, myVector, myAng, myNbTimes1, myStep, myNbTimes2 );
503 if ( !anObj->_is_nil() )
504 objects.push_back( anObj._retn() );
510 //=================================================================================
511 // function : closeEvent
513 //=================================================================================
514 void TransformationGUI_MultiRotationDlg::closeEvent( QCloseEvent* e )
516 // myGeomGUI->SetState( -1 );
517 GEOMBase_Skeleton::closeEvent( e );
520 //=================================================================================
521 // function : addSubshapeToStudy
522 // purpose : virtual method to add new SubObjects if local selection
523 //=================================================================================
524 void TransformationGUI_MultiRotationDlg::addSubshapesToStudy()
526 QMap<QString, GEOM::GEOM_Object_var> objMap;
528 switch (getConstructorId())
531 objMap[GroupPoints->LineEdit2->text()] = myVector;
534 objMap[GroupDimensions->LineEdit2->text()] = myVector;
537 addSubshapesToFather( objMap );