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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : TransformationGUI_MultiRotationDlg.cxx
24 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 #include "TransformationGUI_MultiRotationDlg.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_MultiRotationDlg()
49 // purpose : Constructs a TransformationGUI_MultiRotationDlg 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_MultiRotationDlg::TransformationGUI_MultiRotationDlg
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_MULTIROTATION_SIMPLE")));
61 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MULTIROTATION_DOUBLE")));
62 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
64 setWindowTitle(tr("GEOM_MULTIROTATION_TITLE"));
66 /***************************************************************/
67 mainFrame()->GroupConstructors->setTitle(tr("GEOM_MULTIROTATION"));
68 mainFrame()->RadioButton1->setIcon(image0);
69 mainFrame()->RadioButton2->setIcon(image1);
70 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
71 mainFrame()->RadioButton3->close();
73 GroupPoints = new DlgRef_2Sel1SpinInt(centralWidget());
74 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_SIMPLE"));
75 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
76 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
77 GroupPoints->TextLabel3->setText(tr("GEOM_NB_TIMES"));
78 GroupPoints->PushButton1->setIcon(image2);
79 GroupPoints->PushButton2->setIcon(image2);
80 GroupPoints->LineEdit1->setReadOnly(true);
81 GroupPoints->LineEdit2->setReadOnly(true);
83 GroupDimensions = new DlgRef_2Sel4Spin1Check(centralWidget());
84 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_DOUBLE"));
85 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
86 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR"));
87 GroupDimensions->TextLabel3->setText(tr("GEOM_ANGLE"));
88 GroupDimensions->TextLabel4->setText(tr("GEOM_NB_TIMES"));
89 GroupDimensions->TextLabel5->setText(tr("GEOM_STEP"));
90 GroupDimensions->TextLabel6->setText(tr("GEOM_NB_TIMES"));
91 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE"));
92 GroupDimensions->PushButton1->setIcon(image2);
93 GroupDimensions->PushButton2->setIcon(image2);
94 GroupDimensions->LineEdit1->setReadOnly(true);
95 GroupDimensions->LineEdit2->setReadOnly(true);
97 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
98 layout->setMargin(0); layout->setSpacing(6);
99 layout->addWidget(GroupPoints);
100 layout->addWidget(GroupDimensions);
101 /***************************************************************/
103 setHelpFileName("multi_rotation_operation_page.html");
108 //=================================================================================
109 // function : ~TransformationGUI_MultiRotationDlg()
110 // purpose : Destroys the object and frees any allocated resources
111 //=================================================================================
112 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
114 // no need to delete child widgets, Qt does it all for us
117 //=================================================================================
120 //=================================================================================
121 void TransformationGUI_MultiRotationDlg::Init()
123 // Get setting of step value from file configuration
124 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
125 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
127 int SpecificStep1 = 5;
128 int SpecificStep2 = 1;
132 myNbTimes1 = myNbTimes2 = 2;
134 // min, max, step and decimals for spin boxes & initial values
135 initSpinBox(GroupPoints->SpinBox_DX, 1, 999, SpecificStep2);
136 GroupPoints->SpinBox_DX->setValue(myNbTimes1);
138 initSpinBox(GroupDimensions->SpinBox_DX1, COORD_MIN, COORD_MAX, SpecificStep1, "angle_precision" );
139 initSpinBox(GroupDimensions->SpinBox_DY1, 1, 999, SpecificStep2);
140 initSpinBox(GroupDimensions->SpinBox_DX2, COORD_MIN, COORD_MAX, step,"length_precision" );
141 initSpinBox(GroupDimensions->SpinBox_DY2, 1, 999, SpecificStep2);
142 GroupDimensions->SpinBox_DX1->setValue(myAng);
143 GroupDimensions->SpinBox_DY1->setValue(myNbTimes1);
144 GroupDimensions->SpinBox_DX2->setValue(myStep);
145 GroupDimensions->SpinBox_DY2->setValue(myNbTimes2);
147 GroupPoints->LineEdit1->setText("");
148 GroupPoints->LineEdit2->setText("");
150 GroupDimensions->LineEdit1->setText("");
151 GroupDimensions->LineEdit2->setText("");
156 mainFrame()->GroupBoxPublish->show();
158 // signals and slots connections
159 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
160 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
162 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
164 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
165 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
166 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
167 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
169 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
170 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
171 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
172 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
173 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
175 connect(GroupDimensions->SpinBox_DX1,SIGNAL(textChanged( const QString& )),
176 this, SLOT(TextValueChangedInSpinBox( const QString& )));
178 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
180 connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseAngle()));
182 initName(tr("GEOM_MULTIROTATION"));
184 ConstructorsClicked(0);
187 //=================================================================================
188 // function : SetDoubleSpinBoxStep()
189 // purpose : Double spin box management
190 //=================================================================================
191 void TransformationGUI_MultiRotationDlg::SetDoubleSpinBoxStep (double step)
193 GroupDimensions->SpinBox_DX2->setSingleStep(step);
195 // san: Commented so as not to override specific step settings
196 //GroupPoints->SpinBox_DX->setSingleStep((int)step);
197 //GroupDimensions->SpinBox_DX1->setSingleStep(step);
198 //GroupDimensions->SpinBox_DY1->setSingleStep((int)step);
199 //GroupDimensions->SpinBox_DY2->setSingleStep((int)step);
202 //=================================================================================
203 // function : ConstructorsClicked()
204 // purpose : Radio button management
205 //=================================================================================
206 void TransformationGUI_MultiRotationDlg::ConstructorsClicked (int constructorId)
208 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
210 switch (constructorId) {
211 case 0: // Rotate simple
213 GroupDimensions->hide();
216 GroupPoints->LineEdit1->setText("");
217 GroupPoints->LineEdit2->setText("");
221 GroupPoints->SpinBox_DX->setValue(myNbTimes1);
223 GroupPoints->PushButton1->click();
226 case 1: // Rotate double
229 GroupDimensions->show();
231 GroupDimensions->LineEdit1->setText("");
232 GroupDimensions->LineEdit2->setText("");
236 GroupDimensions->SpinBox_DX1->setValue(myAng);
237 GroupDimensions->SpinBox_DY1->setValue(myNbTimes1);
238 GroupDimensions->SpinBox_DX2->setValue(myStep);
239 GroupDimensions->SpinBox_DY2->setValue(myNbTimes2);
241 GroupDimensions->PushButton1->click();
246 qApp->processEvents();
248 resize(minimumSizeHint());
252 SelectionIntoArgument();
259 //=================================================================================
260 // function : ClickOnOk()
262 //=================================================================================
263 void TransformationGUI_MultiRotationDlg::ClickOnOk()
265 setIsApplyAndClose( true );
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()
293 TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupPoints->LineEdit2 ||
294 myEditCurrentArgument == GroupDimensions->LineEdit2 ) ?
295 TopAbs_EDGE : TopAbs_SHAPE;
296 GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
298 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
299 QString aName = GEOMBase::GetName( aSelectedObject.get() );
300 myEditCurrentArgument->setText( aName );
301 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
302 myBase = aSelectedObject;
304 GroupPoints->PushButton2->click();
306 else if ( myEditCurrentArgument == GroupPoints->LineEdit2) {
307 myVector = aSelectedObject;
309 GroupPoints->PushButton1->click();
311 else if ( myEditCurrentArgument == GroupDimensions->LineEdit1 ) {
312 myBase = aSelectedObject;
314 GroupDimensions->PushButton2->click();
316 else if ( myEditCurrentArgument == GroupDimensions->LineEdit2 ) {
317 myVector = aSelectedObject;
319 GroupDimensions->PushButton1->click();
323 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
324 myGeomGUI->getApp()->selectionMgr()->clearSelected();
325 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
326 this, SLOT(SelectionIntoArgument()));
329 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ||
330 myEditCurrentArgument == GroupDimensions->LineEdit1 )
332 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ||
333 myEditCurrentArgument == GroupDimensions->LineEdit2 )
335 myEditCurrentArgument->setText("");
341 //=================================================================================
342 // function : SetEditCurrentArgument()
344 //=================================================================================
345 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
347 QPushButton* send = (QPushButton*)sender();
349 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
350 globalSelection(GEOM_ALLSHAPES);
352 if (send == GroupPoints->PushButton1) {
353 myEditCurrentArgument = GroupPoints->LineEdit1;
355 GroupPoints->PushButton2->setDown(false);
356 GroupPoints->LineEdit2->setEnabled(false);
358 else if (send == GroupPoints->PushButton2) {
359 myEditCurrentArgument = GroupPoints->LineEdit2;
361 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
363 GroupPoints->PushButton1->setDown(false);
364 GroupPoints->LineEdit1->setEnabled(false);
366 else if (send == GroupDimensions->PushButton1) {
367 myEditCurrentArgument = GroupDimensions->LineEdit1;
369 GroupDimensions->PushButton2->setDown(false);
370 GroupDimensions->LineEdit2->setEnabled(false);
372 else if (send == GroupDimensions->PushButton2) {
373 myEditCurrentArgument = GroupDimensions->LineEdit2;
375 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
377 GroupDimensions->PushButton1->setDown(false);
378 GroupDimensions->LineEdit1->setEnabled(false);
380 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
381 this, SLOT(SelectionIntoArgument()));
384 myEditCurrentArgument->setEnabled(true);
385 myEditCurrentArgument->setFocus();
386 // after setFocus(), because it will be setDown(false) when loses focus
389 // seems we need it only to avoid preview disappearing, caused by selection mode change
393 //=================================================================================
394 // function : ActivateThisDialog()
396 //=================================================================================
397 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
399 GEOMBase_Skeleton::ActivateThisDialog();
400 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
401 this, SLOT( SelectionIntoArgument() ) );
403 ConstructorsClicked( getConstructorId() );
406 //=================================================================================
407 // function : enterEvent()
409 //=================================================================================
410 void TransformationGUI_MultiRotationDlg::enterEvent (QEvent*)
412 if (!mainFrame()->GroupConstructors->isEnabled())
413 ActivateThisDialog();
416 //=================================================================================
417 // function : TextValueChangedInSpinBox()
419 //=================================================================================
420 void TransformationGUI_MultiRotationDlg::TextValueChangedInSpinBox(const QString& s){
422 s.toDouble(&isDigit);
424 GroupDimensions->CheckButton1->setChecked(false);
425 GroupDimensions->CheckButton1->setEnabled(isDigit);
428 //=================================================================================
429 // function : ValueChangedInSpinBox()
431 //=================================================================================
432 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox (double newValue)
434 QObject* send = (QObject*)sender();
436 if (send == GroupDimensions->SpinBox_DX1)
438 else if (send == GroupDimensions->SpinBox_DX2)
444 //=================================================================================
445 // function : ValueChangedInSpinBox()
447 //=================================================================================
448 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox (int newValue)
450 QObject* send = (QObject*)sender();
452 if (send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1)
453 myNbTimes1 = newValue;
454 else if (send == GroupDimensions->SpinBox_DY2)
455 myNbTimes2 = newValue;
460 //=================================================================================
461 // function : ReverseAngle()
462 // purpose : 'state' not used here
463 //=================================================================================
464 void TransformationGUI_MultiRotationDlg::ReverseAngle()
468 int aConstructorId = getConstructorId();
470 if (aConstructorId == 1)
471 GroupDimensions->SpinBox_DX1->setValue(myAng);
476 //=================================================================================
477 // function : createOperation
479 //=================================================================================
480 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiRotationDlg::createOperation()
482 return getGeomEngine()->GetITransformOperations(getStudyId());
485 //=================================================================================
486 // function : isValid
488 //=================================================================================
489 bool TransformationGUI_MultiRotationDlg::isValid (QString& msg)
492 switch(getConstructorId()){
494 ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && myBase && myVector;
497 ok = GroupDimensions->SpinBox_DX1->isValid( msg, !IsPreview() ) &&
498 GroupDimensions->SpinBox_DY1->isValid( msg, !IsPreview() ) &&
499 GroupDimensions->SpinBox_DX2->isValid( msg, !IsPreview() ) &&
500 GroupDimensions->SpinBox_DY2->isValid( msg, !IsPreview() ) &&
509 //=================================================================================
510 // function : execute
512 //=================================================================================
513 bool TransformationGUI_MultiRotationDlg::execute (ObjectList& objects)
517 GEOM::GEOM_Object_var anObj;
518 QStringList aParameters;
520 GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
522 switch (getConstructorId()) {
524 if ( myBase && myVector ) {
525 anObj = anOper->MultiRotate1D(myBase.get(), myVector.get(), myNbTimes1);
527 aParameters<<GroupPoints->SpinBox_DX->text();
532 if ( myBase && myVector ) {
533 anObj = anOper->MultiRotate2D(myBase.get(), myVector.get(), myAng, myNbTimes1, myStep, myNbTimes2);
535 aParameters<<GroupDimensions->SpinBox_DX1->text();
536 aParameters<<GroupDimensions->SpinBox_DY1->text();
537 aParameters<<GroupDimensions->SpinBox_DX2->text();
538 aParameters<<GroupDimensions->SpinBox_DY2->text();
545 if (!anObj->_is_nil()) {
547 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
548 objects.push_back(anObj._retn());
554 //=================================================================================
555 // function : addSubshapeToStudy
556 // purpose : virtual method to add new SubObjects if local selection
557 //=================================================================================
558 void TransformationGUI_MultiRotationDlg::addSubshapesToStudy()
560 switch (getConstructorId()) {
563 GEOMBase::PublishSubObject( myVector.get() );
570 //=================================================================================
571 // function : restoreSubShapes
573 //=================================================================================
574 void TransformationGUI_MultiRotationDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
575 SALOMEDS::SObject_ptr theSObject)
577 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
578 // we pass here the first operation argument (object) through the list of arguments
579 // because the rotation operation place its arguments in the data structure in another order,
580 // and we need to point the first argument directly
581 GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
583 anArgs[0] = myBase.copy();
584 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
585 /*theFindMethod=*/GEOM::FSM_MultiTransformed,
586 /*theInheritFirstArg=*/true,
587 mainFrame()->CheckBoxAddPrefix->isChecked());