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_RotationDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "TransformationGUI_RotationDlg.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_RotationDlg()
50 // purpose : Constructs a TransformationGUI_RotationDlg 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_RotationDlg::TransformationGUI_RotationDlg
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_ROTATION")));
62 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
63 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_ROTATION_THREE_POINTS")));
65 setWindowTitle(tr("GEOM_ROTATION_TITLE"));
67 /***************************************************************/
68 mainFrame()->GroupConstructors->setTitle(tr("GEOM_ROTATION"));
69 mainFrame()->RadioButton1->setIcon(image0);
70 mainFrame()->RadioButton2->setIcon(image2);
71 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
72 mainFrame()->RadioButton3->close();
74 GroupPoints = new DlgRef_4Sel1Spin2Check(centralWidget());
75 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
76 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
77 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
78 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
79 GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg(1));
80 GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg(2));
82 GroupPoints->LineEdit1->setReadOnly(true);
83 GroupPoints->LineEdit2->setReadOnly(true);
84 GroupPoints->LineEdit4->setReadOnly(true);
85 GroupPoints->LineEdit5->setReadOnly(true);
86 GroupPoints->PushButton1->setIcon(image1);
87 GroupPoints->PushButton2->setIcon(image1);
88 GroupPoints->PushButton4->setIcon(image1);
89 GroupPoints->PushButton5->setIcon(image1);
90 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
91 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
93 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
94 layout->setMargin(0); layout->setSpacing(6);
95 layout->addWidget(GroupPoints);
96 /***************************************************************/
98 setHelpFileName("rotation_operation_page.html");
100 // Activate Create a Copy mode
101 GroupPoints->CheckButton1->setChecked(true);
102 CreateCopyModeChanged();
107 //=================================================================================
108 // function : ~TransformationGUI_RotationDlg()
109 // purpose : Destroys the object and frees any allocated resources
110 //=================================================================================
111 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
113 // no need to delete child widgets, Qt does it all for us
116 //=================================================================================
119 //=================================================================================
120 void TransformationGUI_RotationDlg::Init()
123 double SpecificStep = 5;
125 // min, max, step and decimals for spin boxes & initial values
126 initSpinBox(GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, SpecificStep, "angle_precision" );
127 GroupPoints->SpinBox_DX->setValue(anAngle);
130 GroupPoints->LineEdit1->setText("");
131 GroupPoints->LineEdit2->setText("");
132 GroupPoints->LineEdit4->setText("");
133 GroupPoints->LineEdit5->setText("");
137 myCentPoint.nullify();
141 mainFrame()->GroupBoxPublish->show();
143 // signals and slots connections
144 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
145 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
147 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
149 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151 connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152 connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
156 connect(GroupPoints->SpinBox_DX, SIGNAL(textChanged( const QString& )),
157 this, SLOT(TextValueChangedInSpinBox( const QString&)));
159 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged()));
160 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
162 initName(tr("GEOM_ROTATION"));
164 ConstructorsClicked(0);
167 //=================================================================================
168 // function : ConstructorsClicked()
169 // purpose : Radio button management
170 //=================================================================================
171 void TransformationGUI_RotationDlg::ConstructorsClicked (int constructorId)
173 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
175 switch (constructorId) {
176 case 0: // rotation an object angle and axis
178 GroupPoints->ShowRows(2, 3, false);
179 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
180 GroupPoints->LineEdit2->clear();
181 GroupPoints->ShowRows(4, 4, true);
185 GroupPoints->PushButton1->click();
188 case 1: // rotation an object by 3 points
190 GroupPoints->ShowRows(4, 4, false);
191 GroupPoints->ShowRows(2, 3, true);
192 GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
193 GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg(1));
194 GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg(2));
196 GroupPoints->LineEdit2->clear();
197 GroupPoints->LineEdit4->clear();
198 GroupPoints->LineEdit5->clear();
200 myCentPoint.nullify();
204 GroupPoints->PushButton1->click();
209 qApp->processEvents();
211 resize(minimumSizeHint());
215 SelectionIntoArgument();
222 //=================================================================================
223 // function : ClickOnOk()
225 //=================================================================================
226 void TransformationGUI_RotationDlg::ClickOnOk()
232 //=================================================================================
233 // function : ClickOnApply()
235 //=================================================================================
236 bool TransformationGUI_RotationDlg::ClickOnApply()
238 if (!onAccept(GroupPoints->CheckButton1->isChecked()))
244 myEditCurrentArgument = GroupPoints->LineEdit1;
245 myEditCurrentArgument->setText("");
246 myGeomGUI->getApp()->selectionMgr()->clearSelected();
248 // activate selection and connect selection manager
249 ConstructorsClicked(getConstructorId());
253 //=================================================================================
254 // function : SelectionIntoArgument()
255 // purpose : Called when selection is changed or on dialog initialization or activation
256 //=================================================================================
257 void TransformationGUI_RotationDlg::SelectionIntoArgument()
261 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
262 myObjects = getSelected( TopAbs_SHAPE, -1 );
263 if ( !myObjects.isEmpty() ) {
264 QString aName = myObjects.count() > 1 ? QString( "%1_objects").arg( myObjects.count() ) : GEOMBase::GetName( myObjects[0].get() );
265 myEditCurrentArgument->setText( aName );
268 myEditCurrentArgument->setText("");
272 TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0 ) ?
273 TopAbs_EDGE : TopAbs_VERTEX;
274 GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
276 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
277 QString aName = GEOMBase::GetName( aSelectedObject.get() );
278 myEditCurrentArgument->setText( aName );
279 if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
280 if ( getConstructorId() == 0 ) {
281 myAxis = aSelectedObject;
282 if ( myObjects.isEmpty() )
283 GroupPoints->PushButton1->click();
285 else if ( getConstructorId() == 1 ) {
286 myCentPoint = aSelectedObject;
288 GroupPoints->PushButton4->click();
289 else if ( !myPoint2 )
290 GroupPoints->PushButton5->click();
291 else if ( myObjects.isEmpty() )
292 GroupPoints->PushButton1->click();
295 else if ( myEditCurrentArgument == GroupPoints->LineEdit4 ) {
296 myPoint1 = aSelectedObject;
298 GroupPoints->PushButton5->click();
299 else if ( myObjects.isEmpty() )
300 GroupPoints->PushButton1->click();
301 else if ( !myCentPoint )
302 GroupPoints->PushButton2->click();
304 else if ( myEditCurrentArgument == GroupPoints->LineEdit5 ) {
305 myPoint2 = aSelectedObject;
306 if ( myObjects.isEmpty() )
307 GroupPoints->PushButton1->click();
308 else if ( !myCentPoint )
309 GroupPoints->PushButton2->click();
310 else if ( !myPoint1 )
311 GroupPoints->PushButton4->click();
315 if (myEditCurrentArgument == GroupPoints->LineEdit2 ) {
316 if ( getConstructorId() == 0 )
318 else if ( getConstructorId() == 1 )
319 myCentPoint.nullify();
321 else if ( myEditCurrentArgument == GroupPoints->LineEdit4 ) {
324 else if ( myEditCurrentArgument == GroupPoints->LineEdit5 ) {
327 myEditCurrentArgument->setText("");
334 //=================================================================================
335 // function : SetEditCurrentArgument()
337 //=================================================================================
338 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
340 QPushButton* send = (QPushButton*)sender();
342 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
345 if (send == GroupPoints->PushButton1) {
346 myEditCurrentArgument = GroupPoints->LineEdit1;
348 GroupPoints->PushButton2->setDown(false);
349 GroupPoints->PushButton4->setDown(false);
350 GroupPoints->PushButton5->setDown(false);
351 GroupPoints->LineEdit2->setEnabled(false);
352 GroupPoints->LineEdit4->setEnabled(false);
353 GroupPoints->LineEdit5->setEnabled(false);
355 else if (send == GroupPoints->PushButton2) {
356 myEditCurrentArgument = GroupPoints->LineEdit2;
358 GroupPoints->PushButton1->setDown(false);
359 GroupPoints->PushButton4->setDown(false);
360 GroupPoints->PushButton5->setDown(false);
361 GroupPoints->LineEdit1->setEnabled(false);
362 GroupPoints->LineEdit4->setEnabled(false);
363 GroupPoints->LineEdit5->setEnabled(false);
365 if (getConstructorId() == 0)
366 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
368 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
370 else if (send == GroupPoints->PushButton4) {
371 myEditCurrentArgument = GroupPoints->LineEdit4;
373 GroupPoints->PushButton1->setDown(false);
374 GroupPoints->PushButton2->setDown(false);
375 GroupPoints->PushButton5->setDown(false);
376 GroupPoints->LineEdit1->setEnabled(false);
377 GroupPoints->LineEdit2->setEnabled(false);
378 GroupPoints->LineEdit5->setEnabled(false);
380 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
382 else if (send == GroupPoints->PushButton5) {
383 myEditCurrentArgument = GroupPoints->LineEdit5;
385 GroupPoints->PushButton1->setDown(false);
386 GroupPoints->PushButton2->setDown(false);
387 GroupPoints->PushButton4->setDown(false);
388 GroupPoints->LineEdit1->setEnabled(false);
389 GroupPoints->LineEdit2->setEnabled(false);
390 GroupPoints->LineEdit4->setEnabled(false);
392 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
394 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
395 this, SLOT(SelectionIntoArgument()));
398 myEditCurrentArgument->setEnabled(true);
399 myEditCurrentArgument->setFocus();
400 // after setFocus(), because it will be setDown(false) when loses focus
403 // seems we need it only to avoid preview disappearing, caused by selection mode change
407 //=================================================================================
408 // function : ActivateThisDialog()
410 //=================================================================================
411 void TransformationGUI_RotationDlg::ActivateThisDialog()
413 GEOMBase_Skeleton::ActivateThisDialog();
414 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
415 this, SLOT( SelectionIntoArgument() ) );
417 ConstructorsClicked( getConstructorId() );
420 //=================================================================================
421 // function : enterEvent()
423 //=================================================================================
424 void TransformationGUI_RotationDlg::enterEvent (QEvent*)
426 if (!mainFrame()->GroupConstructors->isEnabled())
427 ActivateThisDialog();
430 void TransformationGUI_RotationDlg::TextValueChangedInSpinBox( const QString& s)
433 s.toDouble(&isDigit);
435 GroupPoints->CheckButton2->setChecked(false);
437 GroupPoints->CheckButton2->setEnabled(isDigit);
440 //=================================================================================
441 // function : ValueChangedInSpinBox()
443 //=================================================================================
444 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
449 //=================================================================================
450 // function : createOperation
452 //=================================================================================
453 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
455 return getGeomEngine()->GetITransformOperations(getStudyId());
458 //=================================================================================
459 // function : isValid
461 //=================================================================================
462 bool TransformationGUI_RotationDlg::isValid (QString& msg)
465 switch (getConstructorId()) {
467 ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && !myObjects.isEmpty() && myAxis;
470 ok = !myObjects.isEmpty() && myCentPoint && myPoint1 && myPoint2;
478 //=================================================================================
479 // function : execute
481 //=================================================================================
482 bool TransformationGUI_RotationDlg::execute (ObjectList& objects)
485 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
487 GEOM::GEOM_Object_var anObj;
489 GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
491 switch (getConstructorId()) {
494 QStringList aParameters;
495 aParameters<<GroupPoints->SpinBox_DX->text();
497 for (int i = 0; i < myObjects.count(); i++) {
498 myCurrObject = myObjects[i];
499 anObj = anOper->RotateCopy(myObjects[i].get(), myAxis.get(), GetAngle() * PI180);
500 if (!anObj->_is_nil()) {
502 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
504 objects.push_back(anObj._retn());
509 for (int i = 0; i < myObjects.count(); i++) {
510 myCurrObject = myObjects[i];
511 anObj = anOper->Rotate(myObjects[i].get(), myAxis.get(), GetAngle() * PI180);
512 if (!anObj->_is_nil()) {
514 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
515 updateAttributes(anObj, aParameters);
517 objects.push_back(anObj._retn());
527 for (int i = 0; i < myObjects.count(); i++) {
528 myCurrObject = myObjects[i];
529 anObj = anOper->RotateThreePointsCopy(myObjects[i].get(), myCentPoint.get(), myPoint1.get(), myPoint2.get());
530 if (!anObj->_is_nil())
531 objects.push_back(anObj._retn());
535 for (int i = 0; i < myObjects.count(); i++) {
536 myCurrObject = myObjects[i];
537 anObj = anOper->RotateThreePoints(myObjects[i].get(), myCentPoint.get(), myPoint1.get(), myPoint2.get());
538 if (!anObj->_is_nil())
539 objects.push_back(anObj._retn());
550 //=================================================================================
551 // function : restoreSubShapes
553 //=================================================================================
554 void TransformationGUI_RotationDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
555 SALOMEDS::SObject_ptr theSObject)
557 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
558 // we pass here the first operation argument (object) through the list of arguments
559 // because the rotation operation place its arguments in the data structure in another order,
560 // and we need to point the first argument directly
561 GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
563 anArgs[0] = myCurrObject.copy();
564 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
565 /*theFindMethod=*/GEOM::FSM_Transformed,
566 /*theInheritFirstArg=*/true,
567 mainFrame()->CheckBoxAddPrefix->isChecked());
571 //=================================================================================
572 // function : GetAngle()
574 //=================================================================================
575 double TransformationGUI_RotationDlg::GetAngle() const
577 return GroupPoints->SpinBox_DX->value();
580 //=================================================================================
581 // function : CreateCopyModeChanged()
583 //=================================================================================
584 void TransformationGUI_RotationDlg::CreateCopyModeChanged()
586 mainFrame()->GroupBoxName->setEnabled(GroupPoints->CheckButton1->isChecked());
589 //=================================================================================
590 // function : onReverse()
592 //=================================================================================
593 void TransformationGUI_RotationDlg::onReverse()
595 double anOldValue = GroupPoints->SpinBox_DX->value();
596 GroupPoints->SpinBox_DX->setValue(-anOldValue);
599 //=================================================================================
600 // function : addSubshapesToStudy
601 // purpose : virtual method to add new SubObjects if local selection
602 //=================================================================================
603 void TransformationGUI_RotationDlg::addSubshapesToStudy()
605 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
607 switch (getConstructorId()) {
609 GEOMBase::PublishSubObject( myAxis.get() );
612 GEOMBase::PublishSubObject( myCentPoint.get() );
613 GEOMBase::PublishSubObject( myPoint1.get() );
614 GEOMBase::PublishSubObject( myPoint2.get() );