1 // Copyright (C) 2007-2011 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_RotationDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "TransformationGUI_RotationDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Edge.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
45 #include <GEOMImpl_Types.hxx>
47 //=================================================================================
48 // class : TransformationGUI_RotationDlg()
49 // purpose : Constructs a TransformationGUI_RotationDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 TransformationGUI_RotationDlg::TransformationGUI_RotationDlg
55 (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl)
56 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
59 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
60 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_ROTATION")));
61 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
62 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_ROTATION_THREE_POINTS")));
64 setWindowTitle(tr("GEOM_ROTATION_TITLE"));
66 /***************************************************************/
67 mainFrame()->GroupConstructors->setTitle(tr("GEOM_ROTATION"));
68 mainFrame()->RadioButton1->setIcon(image0);
69 mainFrame()->RadioButton2->setIcon(image2);
70 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
71 mainFrame()->RadioButton3->close();
73 GroupPoints = new DlgRef_4Sel1Spin2Check(centralWidget());
74 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
75 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
76 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
77 GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
78 GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg(1));
79 GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg(2));
81 GroupPoints->LineEdit1->setReadOnly(true);
82 GroupPoints->LineEdit2->setReadOnly(true);
83 GroupPoints->LineEdit4->setReadOnly(true);
84 GroupPoints->LineEdit5->setReadOnly(true);
85 GroupPoints->PushButton1->setIcon(image1);
86 GroupPoints->PushButton2->setIcon(image1);
87 GroupPoints->PushButton4->setIcon(image1);
88 GroupPoints->PushButton5->setIcon(image1);
89 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
90 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
92 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
93 layout->setMargin(0); layout->setSpacing(6);
94 layout->addWidget(GroupPoints);
95 /***************************************************************/
97 setHelpFileName("rotation_operation_page.html");
99 // Activate Create a Copy mode
100 GroupPoints->CheckButton1->setChecked(true);
101 CreateCopyModeChanged();
106 //=================================================================================
107 // function : ~TransformationGUI_RotationDlg()
108 // purpose : Destroys the object and frees any allocated resources
109 //=================================================================================
110 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
112 // no need to delete child widgets, Qt does it all for us
115 //=================================================================================
118 //=================================================================================
119 void TransformationGUI_RotationDlg::Init()
122 double SpecificStep = 5;
124 // min, max, step and decimals for spin boxes & initial values
125 initSpinBox(GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, SpecificStep, "angle_precision" );
126 GroupPoints->SpinBox_DX->setValue(anAngle);
129 GroupPoints->LineEdit1->setText("");
130 GroupPoints->LineEdit2->setText("");
131 GroupPoints->LineEdit4->setText("");
132 GroupPoints->LineEdit5->setText("");
136 myCentPoint.nullify();
140 mainFrame()->GroupBoxPublish->show();
142 // signals and slots connections
143 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
144 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
146 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
148 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150 connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151 connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
153 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
155 connect(GroupPoints->SpinBox_DX, SIGNAL(textChanged( const QString& )),
156 this, SLOT(TextValueChangedInSpinBox( const QString&)));
158 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged()));
159 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
161 initName(tr("GEOM_ROTATION"));
163 ConstructorsClicked(0);
166 //=================================================================================
167 // function : ConstructorsClicked()
168 // purpose : Radio button management
169 //=================================================================================
170 void TransformationGUI_RotationDlg::ConstructorsClicked (int constructorId)
172 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
174 switch (constructorId) {
175 case 0: // rotation an object angle and axis
177 GroupPoints->ShowRows(2, 3, false);
178 GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
179 GroupPoints->LineEdit2->clear();
180 GroupPoints->ShowRows(4, 4, true);
184 GroupPoints->PushButton1->click();
187 case 1: // rotation an object by 3 points
189 GroupPoints->ShowRows(4, 4, false);
190 GroupPoints->ShowRows(2, 3, true);
191 GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
192 GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg(1));
193 GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg(2));
195 GroupPoints->LineEdit2->clear();
196 GroupPoints->LineEdit4->clear();
197 GroupPoints->LineEdit5->clear();
199 myCentPoint.nullify();
203 GroupPoints->PushButton1->click();
208 qApp->processEvents();
210 resize(minimumSizeHint());
214 SelectionIntoArgument();
221 //=================================================================================
222 // function : ClickOnOk()
224 //=================================================================================
225 void TransformationGUI_RotationDlg::ClickOnOk()
227 setIsApplyAndClose( true );
232 //=================================================================================
233 // function : ClickOnApply()
235 //=================================================================================
236 bool TransformationGUI_RotationDlg::ClickOnApply()
238 if (!onAccept(GroupPoints->CheckButton1->isChecked()))
243 // activate selection and connect selection manager
244 ConstructorsClicked(getConstructorId());
245 SelectionIntoArgument();
250 //=================================================================================
251 // function : SelectionIntoArgument()
252 // purpose : Called when selection is changed or on dialog initialization or activation
253 //=================================================================================
254 void TransformationGUI_RotationDlg::SelectionIntoArgument()
258 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
259 myObjects = getSelected( TopAbs_SHAPE, -1 );
260 if ( !myObjects.isEmpty() ) {
261 QString aName = myObjects.count() > 1 ? QString( "%1_objects").arg( myObjects.count() ) : GEOMBase::GetName( myObjects[0].get() );
262 myEditCurrentArgument->setText( aName );
265 myEditCurrentArgument->setText("");
269 TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0 ) ?
270 TopAbs_EDGE : TopAbs_VERTEX;
271 GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
273 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
274 QString aName = GEOMBase::GetName( aSelectedObject.get() );
275 myEditCurrentArgument->setText( aName );
276 if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
277 if ( getConstructorId() == 0 ) {
278 myAxis = aSelectedObject;
279 if ( myObjects.isEmpty() )
280 GroupPoints->PushButton1->click();
282 else if ( getConstructorId() == 1 ) {
283 myCentPoint = aSelectedObject;
285 GroupPoints->PushButton4->click();
286 else if ( !myPoint2 )
287 GroupPoints->PushButton5->click();
288 else if ( myObjects.isEmpty() )
289 GroupPoints->PushButton1->click();
292 else if ( myEditCurrentArgument == GroupPoints->LineEdit4 ) {
293 myPoint1 = aSelectedObject;
295 GroupPoints->PushButton5->click();
296 else if ( myObjects.isEmpty() )
297 GroupPoints->PushButton1->click();
298 else if ( !myCentPoint )
299 GroupPoints->PushButton2->click();
301 else if ( myEditCurrentArgument == GroupPoints->LineEdit5 ) {
302 myPoint2 = aSelectedObject;
303 if ( myObjects.isEmpty() )
304 GroupPoints->PushButton1->click();
305 else if ( !myCentPoint )
306 GroupPoints->PushButton2->click();
307 else if ( !myPoint1 )
308 GroupPoints->PushButton4->click();
312 if (myEditCurrentArgument == GroupPoints->LineEdit2 ) {
313 if ( getConstructorId() == 0 )
315 else if ( getConstructorId() == 1 )
316 myCentPoint.nullify();
318 else if ( myEditCurrentArgument == GroupPoints->LineEdit4 ) {
321 else if ( myEditCurrentArgument == GroupPoints->LineEdit5 ) {
324 myEditCurrentArgument->setText("");
331 //=================================================================================
332 // function : SetEditCurrentArgument()
334 //=================================================================================
335 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
337 QPushButton* send = (QPushButton*)sender();
339 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
342 if (send == GroupPoints->PushButton1) {
343 myEditCurrentArgument = GroupPoints->LineEdit1;
345 GroupPoints->PushButton2->setDown(false);
346 GroupPoints->PushButton4->setDown(false);
347 GroupPoints->PushButton5->setDown(false);
348 GroupPoints->LineEdit2->setEnabled(false);
349 GroupPoints->LineEdit4->setEnabled(false);
350 GroupPoints->LineEdit5->setEnabled(false);
352 else if (send == GroupPoints->PushButton2) {
353 myEditCurrentArgument = GroupPoints->LineEdit2;
355 GroupPoints->PushButton1->setDown(false);
356 GroupPoints->PushButton4->setDown(false);
357 GroupPoints->PushButton5->setDown(false);
358 GroupPoints->LineEdit1->setEnabled(false);
359 GroupPoints->LineEdit4->setEnabled(false);
360 GroupPoints->LineEdit5->setEnabled(false);
362 if (getConstructorId() == 0)
363 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
365 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
367 else if (send == GroupPoints->PushButton4) {
368 myEditCurrentArgument = GroupPoints->LineEdit4;
370 GroupPoints->PushButton1->setDown(false);
371 GroupPoints->PushButton2->setDown(false);
372 GroupPoints->PushButton5->setDown(false);
373 GroupPoints->LineEdit1->setEnabled(false);
374 GroupPoints->LineEdit2->setEnabled(false);
375 GroupPoints->LineEdit5->setEnabled(false);
377 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
379 else if (send == GroupPoints->PushButton5) {
380 myEditCurrentArgument = GroupPoints->LineEdit5;
382 GroupPoints->PushButton1->setDown(false);
383 GroupPoints->PushButton2->setDown(false);
384 GroupPoints->PushButton4->setDown(false);
385 GroupPoints->LineEdit1->setEnabled(false);
386 GroupPoints->LineEdit2->setEnabled(false);
387 GroupPoints->LineEdit4->setEnabled(false);
389 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
391 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
392 this, SLOT(SelectionIntoArgument()));
395 myEditCurrentArgument->setEnabled(true);
396 myEditCurrentArgument->setFocus();
397 // after setFocus(), because it will be setDown(false) when loses focus
400 // seems we need it only to avoid preview disappearing, caused by selection mode change
404 //=================================================================================
405 // function : ActivateThisDialog()
407 //=================================================================================
408 void TransformationGUI_RotationDlg::ActivateThisDialog()
410 GEOMBase_Skeleton::ActivateThisDialog();
411 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
412 this, SLOT( SelectionIntoArgument() ) );
414 ConstructorsClicked( getConstructorId() );
417 //=================================================================================
418 // function : enterEvent()
420 //=================================================================================
421 void TransformationGUI_RotationDlg::enterEvent (QEvent*)
423 if (!mainFrame()->GroupConstructors->isEnabled())
424 ActivateThisDialog();
427 void TransformationGUI_RotationDlg::TextValueChangedInSpinBox( const QString& s)
430 s.toDouble(&isDigit);
432 GroupPoints->CheckButton2->setChecked(false);
434 GroupPoints->CheckButton2->setEnabled(isDigit);
437 //=================================================================================
438 // function : ValueChangedInSpinBox()
440 //=================================================================================
441 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
446 //=================================================================================
447 // function : createOperation
449 //=================================================================================
450 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
452 return getGeomEngine()->GetITransformOperations(getStudyId());
455 //=================================================================================
456 // function : isValid
458 //=================================================================================
459 bool TransformationGUI_RotationDlg::isValid (QString& msg)
462 switch (getConstructorId()) {
464 ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && !myObjects.isEmpty() && myAxis;
467 ok = !myObjects.isEmpty() && myCentPoint && myPoint1 && myPoint2;
475 //=================================================================================
476 // function : execute
478 //=================================================================================
479 bool TransformationGUI_RotationDlg::execute (ObjectList& objects)
482 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
484 GEOM::GEOM_Object_var anObj;
486 GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
488 switch (getConstructorId()) {
491 QStringList aParameters;
492 aParameters<<GroupPoints->SpinBox_DX->text();
494 for (int i = 0; i < myObjects.count(); i++) {
495 myCurrObject = myObjects[i];
496 anObj = anOper->RotateCopy(myObjects[i].get(), myAxis.get(), GetAngle() * M_PI / 180.);
497 if (!anObj->_is_nil()) {
499 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
501 objects.push_back(anObj._retn());
506 for (int i = 0; i < myObjects.count(); i++) {
507 myCurrObject = myObjects[i];
508 anObj = anOper->Rotate(myObjects[i].get(), myAxis.get(), GetAngle() * M_PI / 180.);
509 if (!anObj->_is_nil()) {
511 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
512 updateAttributes(anObj, aParameters);
514 objects.push_back(anObj._retn());
524 for (int i = 0; i < myObjects.count(); i++) {
525 myCurrObject = myObjects[i];
526 anObj = anOper->RotateThreePointsCopy(myObjects[i].get(), myCentPoint.get(), myPoint1.get(), myPoint2.get());
527 if (!anObj->_is_nil())
528 objects.push_back(anObj._retn());
532 for (int i = 0; i < myObjects.count(); i++) {
533 myCurrObject = myObjects[i];
534 anObj = anOper->RotateThreePoints(myObjects[i].get(), myCentPoint.get(), myPoint1.get(), myPoint2.get());
535 if (!anObj->_is_nil())
536 objects.push_back(anObj._retn());
547 //=================================================================================
548 // function : restoreSubShapes
550 //=================================================================================
551 void TransformationGUI_RotationDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
552 SALOMEDS::SObject_ptr theSObject)
554 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
555 // we pass here the first operation argument (object) through the list of arguments
556 // because the rotation operation place its arguments in the data structure in another order,
557 // and we need to point the first argument directly
558 GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
560 anArgs[0] = myCurrObject.copy();
561 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
562 /*theFindMethod=*/GEOM::FSM_Transformed,
563 /*theInheritFirstArg=*/true,
564 mainFrame()->CheckBoxAddPrefix->isChecked());
568 //=================================================================================
569 // function : GetAngle()
571 //=================================================================================
572 double TransformationGUI_RotationDlg::GetAngle() const
574 return GroupPoints->SpinBox_DX->value();
577 //=================================================================================
578 // function : CreateCopyModeChanged()
580 //=================================================================================
581 void TransformationGUI_RotationDlg::CreateCopyModeChanged()
583 mainFrame()->GroupBoxName->setEnabled(GroupPoints->CheckButton1->isChecked());
586 //=================================================================================
587 // function : onReverse()
589 //=================================================================================
590 void TransformationGUI_RotationDlg::onReverse()
592 double anOldValue = GroupPoints->SpinBox_DX->value();
593 GroupPoints->SpinBox_DX->setValue(-anOldValue);
596 //=================================================================================
597 // function : addSubshapesToStudy
598 // purpose : virtual method to add new SubObjects if local selection
599 //=================================================================================
600 void TransformationGUI_RotationDlg::addSubshapesToStudy()
602 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
604 switch (getConstructorId()) {
606 GEOMBase::PublishSubObject( myAxis.get() );
609 GEOMBase::PublishSubObject( myCentPoint.get() );
610 GEOMBase::PublishSubObject( myPoint1.get() );
611 GEOMBase::PublishSubObject( myPoint2.get() );