1 // Copyright (C) 2007-2010 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : TransformationGUI_MultiRotationDlg.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
27 #include "TransformationGUI_MultiRotationDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Edge.hxx>
43 #include <TColStd_IndexedMapOfInteger.hxx>
44 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <GEOMImpl_Types.hxx>
48 //=================================================================================
49 // class : TransformationGUI_MultiRotationDlg()
50 // purpose : Constructs a TransformationGUI_MultiRotationDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 TransformationGUI_MultiRotationDlg::TransformationGUI_MultiRotationDlg
56 (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl)
57 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
60 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
61 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MULTIROTATION_SIMPLE")));
62 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MULTIROTATION_DOUBLE")));
63 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
65 setWindowTitle(tr("GEOM_MULTIROTATION_TITLE"));
67 /***************************************************************/
68 mainFrame()->GroupConstructors->setTitle(tr("GEOM_MULTIROTATION"));
69 mainFrame()->RadioButton1->setIcon(image0);
70 mainFrame()->RadioButton2->setIcon(image1);
71 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
72 mainFrame()->RadioButton3->close();
74 GroupPoints = new DlgRef_2Sel1SpinInt(centralWidget());
75 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_SIMPLE"));
76 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
77 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
78 GroupPoints->TextLabel3->setText(tr("GEOM_NB_TIMES"));
79 GroupPoints->PushButton1->setIcon(image2);
80 GroupPoints->PushButton2->setIcon(image2);
81 GroupPoints->LineEdit1->setReadOnly(true);
82 GroupPoints->LineEdit2->setReadOnly(true);
84 GroupDimensions = new DlgRef_2Sel4Spin1Check(centralWidget());
85 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_DOUBLE"));
86 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
87 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR"));
88 GroupDimensions->TextLabel3->setText(tr("GEOM_ANGLE"));
89 GroupDimensions->TextLabel4->setText(tr("GEOM_NB_TIMES"));
90 GroupDimensions->TextLabel5->setText(tr("GEOM_STEP"));
91 GroupDimensions->TextLabel6->setText(tr("GEOM_NB_TIMES"));
92 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE"));
93 GroupDimensions->PushButton1->setIcon(image2);
94 GroupDimensions->PushButton2->setIcon(image2);
95 GroupDimensions->LineEdit1->setReadOnly(true);
96 GroupDimensions->LineEdit2->setReadOnly(true);
98 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
99 layout->setMargin(0); layout->setSpacing(6);
100 layout->addWidget(GroupPoints);
101 layout->addWidget(GroupDimensions);
102 /***************************************************************/
104 setHelpFileName("multi_rotation_operation_page.html");
109 //=================================================================================
110 // function : ~TransformationGUI_MultiRotationDlg()
111 // purpose : Destroys the object and frees any allocated resources
112 //=================================================================================
113 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
115 // no need to delete child widgets, Qt does it all for us
118 //=================================================================================
121 //=================================================================================
122 void TransformationGUI_MultiRotationDlg::Init()
124 // Get setting of step value from file configuration
125 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
126 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
128 int SpecificStep1 = 5;
129 int SpecificStep2 = 1;
130 // min, max, step and decimals for spin boxes & initial values
131 initSpinBox(GroupPoints->SpinBox_DX, 1, 999, SpecificStep2);
132 GroupPoints->SpinBox_DX->setValue(myNbTimes1);
134 initSpinBox(GroupDimensions->SpinBox_DX1, COORD_MIN, COORD_MAX, SpecificStep1, "angle_precision" );
135 initSpinBox(GroupDimensions->SpinBox_DY1, 1, 999, SpecificStep2);
136 initSpinBox(GroupDimensions->SpinBox_DX2, COORD_MIN, COORD_MAX, step,"length_precision" );
137 initSpinBox(GroupDimensions->SpinBox_DY2, 1, 999, SpecificStep2);
138 GroupDimensions->SpinBox_DX1->setValue(myAng);
139 GroupDimensions->SpinBox_DY1->setValue(myNbTimes1);
140 GroupDimensions->SpinBox_DX2->setValue(myStep);
141 GroupDimensions->SpinBox_DY2->setValue(myNbTimes2);
146 myNbTimes1 = myNbTimes2 = 2;
148 GroupPoints->LineEdit1->setText("");
149 GroupPoints->LineEdit2->setText("");
151 GroupDimensions->LineEdit1->setText("");
152 GroupDimensions->LineEdit2->setText("");
154 myBase = myVector = GEOM::GEOM_Object::_nil();
156 // signals and slots connections
157 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
158 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
160 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
162 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
163 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
164 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
165 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
167 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
168 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
169 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
170 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
172 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
173 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
174 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
175 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
176 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
178 connect(GroupDimensions->SpinBox_DX1,SIGNAL(textChanged( const QString& )),
179 this, SLOT(TextValueChangedInSpinBox( const QString& )));
181 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
183 connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseAngle()));
185 initName(tr("GEOM_MULTIROTATION"));
187 ConstructorsClicked(0);
190 //=================================================================================
191 // function : SetDoubleSpinBoxStep()
192 // purpose : Double spin box management
193 //=================================================================================
194 void TransformationGUI_MultiRotationDlg::SetDoubleSpinBoxStep (double step)
196 GroupDimensions->SpinBox_DX2->setSingleStep(step);
198 // san: Commented so as not to override specific step settings
199 //GroupPoints->SpinBox_DX->setSingleStep((int)step);
200 //GroupDimensions->SpinBox_DX1->setSingleStep(step);
201 //GroupDimensions->SpinBox_DY1->setSingleStep((int)step);
202 //GroupDimensions->SpinBox_DY2->setSingleStep((int)step);
205 //=================================================================================
206 // function : ConstructorsClicked()
207 // purpose : Radio button management
208 //=================================================================================
209 void TransformationGUI_MultiRotationDlg::ConstructorsClicked (int constructorId)
211 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
213 switch (constructorId) {
214 case 0: // Rotate simple
216 GroupDimensions->hide();
219 GroupPoints->LineEdit1->setText("");
220 GroupPoints->LineEdit2->setText("");
221 myBase = myVector = GEOM::GEOM_Object::_nil();
223 GroupPoints->SpinBox_DX->setValue(myNbTimes1);
225 GroupPoints->PushButton1->click();
228 case 1: // Rotate double
231 GroupDimensions->show();
233 GroupDimensions->LineEdit1->setText("");
234 GroupDimensions->LineEdit2->setText("");
235 myBase = myVector = GEOM::GEOM_Object::_nil();
237 GroupDimensions->SpinBox_DX1->setValue(myAng);
238 GroupDimensions->SpinBox_DY1->setValue(myNbTimes1);
239 GroupDimensions->SpinBox_DX2->setValue(myStep);
240 GroupDimensions->SpinBox_DY2->setValue(myNbTimes2);
242 GroupDimensions->PushButton1->click();
247 qApp->processEvents();
249 resize(minimumSizeHint());
253 SelectionIntoArgument();
260 //=================================================================================
261 // function : ClickOnOk()
263 //=================================================================================
264 void TransformationGUI_MultiRotationDlg::ClickOnOk()
270 //=================================================================================
271 // function : ClickOnApply()
273 //=================================================================================
274 bool TransformationGUI_MultiRotationDlg::ClickOnApply()
280 // activate selection and connect selection manager
281 ConstructorsClicked(getConstructorId());
285 //=================================================================================
286 // function : SelectionIntoArgument()
287 // purpose : Called when selection is changed or on dialog initialization or activation
288 //=================================================================================
289 void TransformationGUI_MultiRotationDlg::SelectionIntoArgument()
292 myEditCurrentArgument->setText("");
294 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
295 myEditCurrentArgument == GroupDimensions->LineEdit1)
296 myBase = GEOM::GEOM_Object::_nil();
297 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
298 myEditCurrentArgument == GroupDimensions->LineEdit2)
299 myVector = GEOM::GEOM_Object::_nil();
301 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
302 SALOME_ListIO aSelList;
303 aSelMgr->selectedObjects(aSelList);
305 if (aSelList.Extent() != 1)
309 Standard_Boolean testResult = Standard_False;;
310 GEOM::GEOM_Object_var aSelectedObject =
311 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
313 if (!testResult || CORBA::is_nil(aSelectedObject) || !GEOMBase::IsShape(aSelectedObject))
316 QString aName = GEOMBase::GetName(aSelectedObject);
318 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
319 myEditCurrentArgument == GroupDimensions->LineEdit1)
320 myBase = aSelectedObject;
321 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
322 myEditCurrentArgument == GroupDimensions->LineEdit2) {
325 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) {
326 TColStd_IndexedMapOfInteger aMap;
327 aSelMgr->GetIndexes(aSelList.First(), aMap);
328 if (aMap.Extent() == 1) {
329 int anIndex = aMap(1);
330 aName += QString(":edge_%1").arg(anIndex);
332 //Find SubShape Object in Father
333 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
335 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
336 GEOM::GEOM_IShapesOperations_var aShapesOp =
337 getGeomEngine()->GetIShapesOperations(getStudyId());
338 myVector = aShapesOp->GetSubShape(aSelectedObject, anIndex);
341 myVector = aFindedObject; // get existing object
345 if (aShape.ShapeType() != TopAbs_EDGE) {
346 aSelectedObject = GEOM::GEOM_Object::_nil();
349 myVector = aSelectedObject;
353 myEditCurrentArgument->setText(aName);
355 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
356 if (!myBase->_is_nil() && myVector->_is_nil())
357 GroupPoints->PushButton2->click();
359 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
360 if (!myVector->_is_nil() && myBase->_is_nil())
361 GroupPoints->PushButton1->click();
363 else if (myEditCurrentArgument == GroupDimensions->LineEdit1) {
364 if (!myBase->_is_nil() && myVector->_is_nil())
365 GroupDimensions->PushButton2->click();
367 else if (myEditCurrentArgument == GroupDimensions->LineEdit2) {
368 if (!myVector->_is_nil() && myBase->_is_nil())
369 GroupDimensions->PushButton1->click();
373 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
374 myGeomGUI->getApp()->selectionMgr()->clearSelected();
375 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
376 this, SLOT(SelectionIntoArgument()));
381 //=================================================================================
382 // function : SetEditCurrentArgument()
384 //=================================================================================
385 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
387 QPushButton* send = (QPushButton*)sender();
389 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
390 globalSelection(GEOM_ALLSHAPES);
392 if (send == GroupPoints->PushButton1) {
393 myEditCurrentArgument = GroupPoints->LineEdit1;
395 GroupPoints->PushButton2->setDown(false);
396 GroupPoints->LineEdit2->setEnabled(false);
398 else if (send == GroupPoints->PushButton2) {
399 myEditCurrentArgument = GroupPoints->LineEdit2;
401 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
403 GroupPoints->PushButton1->setDown(false);
404 GroupPoints->LineEdit1->setEnabled(false);
406 else if (send == GroupDimensions->PushButton1) {
407 myEditCurrentArgument = GroupDimensions->LineEdit1;
409 GroupDimensions->PushButton2->setDown(false);
410 GroupDimensions->LineEdit2->setEnabled(false);
412 else if (send == GroupDimensions->PushButton2) {
413 myEditCurrentArgument = GroupDimensions->LineEdit2;
415 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
417 GroupDimensions->PushButton1->setDown(false);
418 GroupDimensions->LineEdit1->setEnabled(false);
420 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
421 this, SLOT(SelectionIntoArgument()));
424 myEditCurrentArgument->setEnabled(true);
425 myEditCurrentArgument->setFocus();
426 // after setFocus(), because it will be setDown(false) when loses focus
429 // seems we need it only to avoid preview disappearing, caused by selection mode change
433 //=================================================================================
434 // function : LineEditReturnPressed()
436 //=================================================================================
437 void TransformationGUI_MultiRotationDlg::LineEditReturnPressed()
439 QLineEdit* send = (QLineEdit*)sender();
440 if (send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
441 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2) {
442 myEditCurrentArgument = send;
443 GEOMBase_Skeleton::LineEditReturnPressed();
447 //=================================================================================
448 // function : ActivateThisDialog()
450 //=================================================================================
451 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
453 GEOMBase_Skeleton::ActivateThisDialog();
454 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
455 this, SLOT( SelectionIntoArgument() ) );
457 ConstructorsClicked( getConstructorId() );
460 //=================================================================================
461 // function : enterEvent()
463 //=================================================================================
464 void TransformationGUI_MultiRotationDlg::enterEvent (QEvent*)
466 if (!mainFrame()->GroupConstructors->isEnabled())
467 ActivateThisDialog();
470 //=================================================================================
471 // function : TextValueChangedInSpinBox()
473 //=================================================================================
474 void TransformationGUI_MultiRotationDlg::TextValueChangedInSpinBox(const QString& s){
476 s.toDouble(&isDigit);
478 GroupDimensions->CheckButton1->setChecked(false);
479 GroupDimensions->CheckButton1->setEnabled(isDigit);
482 //=================================================================================
483 // function : ValueChangedInSpinBox()
485 //=================================================================================
486 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox (double newValue)
488 QObject* send = (QObject*)sender();
490 if (send == GroupDimensions->SpinBox_DX1)
492 else if (send == GroupDimensions->SpinBox_DX2)
498 //=================================================================================
499 // function : ValueChangedInSpinBox()
501 //=================================================================================
502 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox (int newValue)
504 QObject* send = (QObject*)sender();
506 if (send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1)
507 myNbTimes1 = newValue;
508 else if (send == GroupDimensions->SpinBox_DY2)
509 myNbTimes2 = newValue;
514 //=================================================================================
515 // function : ReverseAngle()
516 // purpose : 'state' not used here
517 //=================================================================================
518 void TransformationGUI_MultiRotationDlg::ReverseAngle()
522 int aConstructorId = getConstructorId();
524 if (aConstructorId == 1)
525 GroupDimensions->SpinBox_DX1->setValue(myAng);
530 //=================================================================================
531 // function : createOperation
533 //=================================================================================
534 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiRotationDlg::createOperation()
536 return getGeomEngine()->GetITransformOperations(getStudyId());
539 //=================================================================================
540 // function : isValid
542 //=================================================================================
543 bool TransformationGUI_MultiRotationDlg::isValid (QString& msg)
546 switch(getConstructorId()){
548 ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
551 ok = GroupDimensions->SpinBox_DX1->isValid( msg, !IsPreview() ) && ok;
552 ok = GroupDimensions->SpinBox_DY1->isValid( msg, !IsPreview() ) && ok;
553 ok = GroupDimensions->SpinBox_DX2->isValid( msg, !IsPreview() ) && ok;
554 ok = GroupDimensions->SpinBox_DY2->isValid( msg, !IsPreview() ) && ok;
557 return !(myBase->_is_nil() || myVector->_is_nil()) && ok;
560 //=================================================================================
561 // function : execute
563 //=================================================================================
564 bool TransformationGUI_MultiRotationDlg::execute (ObjectList& objects)
568 GEOM::GEOM_Object_var anObj;
569 QStringList aParameters;
571 GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
573 switch (getConstructorId()) {
575 if (!CORBA::is_nil(myBase) && !CORBA::is_nil(myVector)) {
576 anObj = anOper->MultiRotate1D(myBase, myVector, myNbTimes1);
578 aParameters<<GroupPoints->SpinBox_DX->text();
583 if (!CORBA::is_nil(myBase) && !CORBA::is_nil(myVector)) {
584 anObj = anOper->MultiRotate2D(myBase, myVector, myAng, myNbTimes1, myStep, myNbTimes2);
586 aParameters<<GroupDimensions->SpinBox_DX1->text();
587 aParameters<<GroupDimensions->SpinBox_DY1->text();
588 aParameters<<GroupDimensions->SpinBox_DX2->text();
589 aParameters<<GroupDimensions->SpinBox_DY2->text();
596 if (!anObj->_is_nil()) {
598 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
599 objects.push_back(anObj._retn());
605 //=================================================================================
606 // function : addSubshapeToStudy
607 // purpose : virtual method to add new SubObjects if local selection
608 //=================================================================================
609 void TransformationGUI_MultiRotationDlg::addSubshapesToStudy()
611 QMap<QString, GEOM::GEOM_Object_var> objMap;
613 switch (getConstructorId()) {
615 objMap[GroupPoints->LineEdit2->text()] = myVector;
618 objMap[GroupDimensions->LineEdit2->text()] = myVector;
621 addSubshapesToFather(objMap);