1 // Copyright (C) 2007-2012 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()
228 setIsApplyAndClose( true );
233 //=================================================================================
234 // function : ClickOnApply()
236 //=================================================================================
237 bool TransformationGUI_RotationDlg::ClickOnApply()
239 if (!onAccept(GroupPoints->CheckButton1->isChecked()))
244 // activate selection and connect selection manager
245 ConstructorsClicked(getConstructorId());
246 SelectionIntoArgument();
251 //=================================================================================
252 // function : SelectionIntoArgument()
253 // purpose : Called when selection is changed or on dialog initialization or activation
254 //=================================================================================
255 void TransformationGUI_RotationDlg::SelectionIntoArgument()
259 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
260 myObjects = getSelected( TopAbs_SHAPE, -1 );
261 if ( !myObjects.isEmpty() ) {
262 QString aName = myObjects.count() > 1 ? QString( "%1_objects").arg( myObjects.count() ) : GEOMBase::GetName( myObjects[0].get() );
263 myEditCurrentArgument->setText( aName );
266 myEditCurrentArgument->setText("");
270 TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0 ) ?
271 TopAbs_EDGE : TopAbs_VERTEX;
272 GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
274 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
275 QString aName = GEOMBase::GetName( aSelectedObject.get() );
276 myEditCurrentArgument->setText( aName );
277 if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
278 if ( getConstructorId() == 0 ) {
279 myAxis = aSelectedObject;
280 if ( myObjects.isEmpty() )
281 GroupPoints->PushButton1->click();
283 else if ( getConstructorId() == 1 ) {
284 myCentPoint = aSelectedObject;
286 GroupPoints->PushButton4->click();
287 else if ( !myPoint2 )
288 GroupPoints->PushButton5->click();
289 else if ( myObjects.isEmpty() )
290 GroupPoints->PushButton1->click();
293 else if ( myEditCurrentArgument == GroupPoints->LineEdit4 ) {
294 myPoint1 = aSelectedObject;
296 GroupPoints->PushButton5->click();
297 else if ( myObjects.isEmpty() )
298 GroupPoints->PushButton1->click();
299 else if ( !myCentPoint )
300 GroupPoints->PushButton2->click();
302 else if ( myEditCurrentArgument == GroupPoints->LineEdit5 ) {
303 myPoint2 = aSelectedObject;
304 if ( myObjects.isEmpty() )
305 GroupPoints->PushButton1->click();
306 else if ( !myCentPoint )
307 GroupPoints->PushButton2->click();
308 else if ( !myPoint1 )
309 GroupPoints->PushButton4->click();
313 if (myEditCurrentArgument == GroupPoints->LineEdit2 ) {
314 if ( getConstructorId() == 0 )
316 else if ( getConstructorId() == 1 )
317 myCentPoint.nullify();
319 else if ( myEditCurrentArgument == GroupPoints->LineEdit4 ) {
322 else if ( myEditCurrentArgument == GroupPoints->LineEdit5 ) {
325 myEditCurrentArgument->setText("");
332 //=================================================================================
333 // function : SetEditCurrentArgument()
335 //=================================================================================
336 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
338 QPushButton* send = (QPushButton*)sender();
340 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
343 if (send == GroupPoints->PushButton1) {
344 myEditCurrentArgument = GroupPoints->LineEdit1;
346 GroupPoints->PushButton2->setDown(false);
347 GroupPoints->PushButton4->setDown(false);
348 GroupPoints->PushButton5->setDown(false);
349 GroupPoints->LineEdit2->setEnabled(false);
350 GroupPoints->LineEdit4->setEnabled(false);
351 GroupPoints->LineEdit5->setEnabled(false);
353 else if (send == GroupPoints->PushButton2) {
354 myEditCurrentArgument = GroupPoints->LineEdit2;
356 GroupPoints->PushButton1->setDown(false);
357 GroupPoints->PushButton4->setDown(false);
358 GroupPoints->PushButton5->setDown(false);
359 GroupPoints->LineEdit1->setEnabled(false);
360 GroupPoints->LineEdit4->setEnabled(false);
361 GroupPoints->LineEdit5->setEnabled(false);
363 if (getConstructorId() == 0)
364 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
366 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
368 else if (send == GroupPoints->PushButton4) {
369 myEditCurrentArgument = GroupPoints->LineEdit4;
371 GroupPoints->PushButton1->setDown(false);
372 GroupPoints->PushButton2->setDown(false);
373 GroupPoints->PushButton5->setDown(false);
374 GroupPoints->LineEdit1->setEnabled(false);
375 GroupPoints->LineEdit2->setEnabled(false);
376 GroupPoints->LineEdit5->setEnabled(false);
378 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
380 else if (send == GroupPoints->PushButton5) {
381 myEditCurrentArgument = GroupPoints->LineEdit5;
383 GroupPoints->PushButton1->setDown(false);
384 GroupPoints->PushButton2->setDown(false);
385 GroupPoints->PushButton4->setDown(false);
386 GroupPoints->LineEdit1->setEnabled(false);
387 GroupPoints->LineEdit2->setEnabled(false);
388 GroupPoints->LineEdit4->setEnabled(false);
390 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
392 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
393 this, SLOT(SelectionIntoArgument()));
396 myEditCurrentArgument->setEnabled(true);
397 myEditCurrentArgument->setFocus();
398 // after setFocus(), because it will be setDown(false) when loses focus
401 // seems we need it only to avoid preview disappearing, caused by selection mode change
405 //=================================================================================
406 // function : ActivateThisDialog()
408 //=================================================================================
409 void TransformationGUI_RotationDlg::ActivateThisDialog()
411 GEOMBase_Skeleton::ActivateThisDialog();
412 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
413 this, SLOT( SelectionIntoArgument() ) );
415 ConstructorsClicked( getConstructorId() );
418 //=================================================================================
419 // function : enterEvent()
421 //=================================================================================
422 void TransformationGUI_RotationDlg::enterEvent (QEvent*)
424 if (!mainFrame()->GroupConstructors->isEnabled())
425 ActivateThisDialog();
428 void TransformationGUI_RotationDlg::TextValueChangedInSpinBox( const QString& s)
431 s.toDouble(&isDigit);
433 GroupPoints->CheckButton2->setChecked(false);
435 GroupPoints->CheckButton2->setEnabled(isDigit);
438 //=================================================================================
439 // function : ValueChangedInSpinBox()
441 //=================================================================================
442 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
447 //=================================================================================
448 // function : createOperation
450 //=================================================================================
451 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
453 return getGeomEngine()->GetITransformOperations(getStudyId());
456 //=================================================================================
457 // function : isValid
459 //=================================================================================
460 bool TransformationGUI_RotationDlg::isValid (QString& msg)
463 switch (getConstructorId()) {
465 ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && !myObjects.isEmpty() && myAxis;
468 ok = !myObjects.isEmpty() && myCentPoint && myPoint1 && myPoint2;
476 //=================================================================================
477 // function : execute
479 //=================================================================================
480 bool TransformationGUI_RotationDlg::execute (ObjectList& objects)
483 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
485 GEOM::GEOM_Object_var anObj;
487 GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
489 switch (getConstructorId()) {
492 QStringList aParameters;
493 aParameters<<GroupPoints->SpinBox_DX->text();
495 for (int i = 0; i < myObjects.count(); i++) {
496 myCurrObject = myObjects[i];
497 anObj = anOper->RotateCopy(myObjects[i].get(), myAxis.get(), GetAngle() * M_PI / 180.);
498 if (!anObj->_is_nil()) {
500 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
502 objects.push_back(anObj._retn());
507 for (int i = 0; i < myObjects.count(); i++) {
508 myCurrObject = myObjects[i];
509 anObj = anOper->Rotate(myObjects[i].get(), myAxis.get(), GetAngle() * M_PI / 180.);
510 if (!anObj->_is_nil()) {
512 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
513 updateAttributes(anObj, aParameters);
515 objects.push_back(anObj._retn());
525 for (int i = 0; i < myObjects.count(); i++) {
526 myCurrObject = myObjects[i];
527 anObj = anOper->RotateThreePointsCopy(myObjects[i].get(), myCentPoint.get(), myPoint1.get(), myPoint2.get());
528 if (!anObj->_is_nil())
529 objects.push_back(anObj._retn());
533 for (int i = 0; i < myObjects.count(); i++) {
534 myCurrObject = myObjects[i];
535 anObj = anOper->RotateThreePoints(myObjects[i].get(), myCentPoint.get(), myPoint1.get(), myPoint2.get());
536 if (!anObj->_is_nil())
537 objects.push_back(anObj._retn());
548 //=================================================================================
549 // function : restoreSubShapes
551 //=================================================================================
552 void TransformationGUI_RotationDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
553 SALOMEDS::SObject_ptr theSObject)
555 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
556 // we pass here the first operation argument (object) through the list of arguments
557 // because the rotation operation place its arguments in the data structure in another order,
558 // and we need to point the first argument directly
559 GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
561 anArgs[0] = myCurrObject.copy();
562 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
563 /*theFindMethod=*/GEOM::FSM_Transformed,
564 /*theInheritFirstArg=*/true,
565 mainFrame()->CheckBoxAddPrefix->isChecked());
569 //=================================================================================
570 // function : GetAngle()
572 //=================================================================================
573 double TransformationGUI_RotationDlg::GetAngle() const
575 return GroupPoints->SpinBox_DX->value();
578 //=================================================================================
579 // function : CreateCopyModeChanged()
581 //=================================================================================
582 void TransformationGUI_RotationDlg::CreateCopyModeChanged()
584 mainFrame()->GroupBoxName->setEnabled(GroupPoints->CheckButton1->isChecked());
587 //=================================================================================
588 // function : onReverse()
590 //=================================================================================
591 void TransformationGUI_RotationDlg::onReverse()
593 double anOldValue = GroupPoints->SpinBox_DX->value();
594 GroupPoints->SpinBox_DX->setValue(-anOldValue);
597 //=================================================================================
598 // function : addSubshapesToStudy
599 // purpose : virtual method to add new SubObjects if local selection
600 //=================================================================================
601 void TransformationGUI_RotationDlg::addSubshapesToStudy()
603 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
605 switch (getConstructorId()) {
607 GEOMBase::PublishSubObject( myAxis.get() );
610 GEOMBase::PublishSubObject( myCentPoint.get() );
611 GEOMBase::PublishSubObject( myPoint1.get() );
612 GEOMBase::PublishSubObject( myPoint2.get() );