]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_MultiRotationDlg.cxx
Salome HOME
0020327: EDF 1018 GEOM : Missing MakeTangentPlaneOnFace in geompy
[modules/geom.git] / src / TransformationGUI / TransformationGUI_MultiRotationDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  GEOM GEOMGUI : GUI for Geometry component
23 //  File   : TransformationGUI_MultiRotationDlg.cxx
24 //  Author : Damien COQUERET
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include "TransformationGUI_MultiRotationDlg.h"
29
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
34
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS.hxx>
38 #include <TopExp.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
41
42 #include <qcheckbox.h>
43 #include <qlabel.h>
44
45 #include "GEOMImpl_Types.hxx"
46
47 #include "utilities.h"
48
49 using namespace std;
50
51 //=================================================================================
52 // class    : TransformationGUI_MultiRotationDlg()
53 // purpose  : Constructs a TransformationGUI_MultiRotationDlg which is a child of 'parent', with the
54 //            name 'name' and widget flags set to 'f'.
55 //            The dialog will by default be modeless, unless you set 'modal' to
56 //            TRUE to construct a modal dialog.
57 //=================================================================================
58 TransformationGUI_MultiRotationDlg::TransformationGUI_MultiRotationDlg
59   (GeometryGUI* theGeometryGUI, QWidget* parent,  const char* name, bool modal, WFlags fl)
60   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
61                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
62 {
63   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
64   QPixmap image0(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_SIMPLE")));
65   QPixmap image1(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_DOUBLE")));
66   QPixmap image2(aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
67
68   setCaption(tr("GEOM_MULTIROTATION_TITLE"));
69
70   /***************************************************************/
71   GroupConstructors->setTitle(tr("GEOM_MULTIROTATION"));
72   RadioButton1->setPixmap(image0);
73   RadioButton2->setPixmap(image1);
74   RadioButton3->close(TRUE);
75
76   GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
77   GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_SIMPLE"));
78   GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
79   GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
80   GroupPoints->TextLabel3->setText(tr("GEOM_NB_TIMES"));
81   GroupPoints->PushButton1->setPixmap(image2);
82   GroupPoints->PushButton2->setPixmap(image2);
83   GroupPoints->LineEdit1->setReadOnly(true);
84   GroupPoints->LineEdit2->setReadOnly(true);
85
86   GroupDimensions = new DlgRef_2Sel4Spin1Check(this, "GroupDimensions");
87   GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_DOUBLE"));
88   GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
89   GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR"));
90   GroupDimensions->TextLabel3->setText(tr("GEOM_ANGLE"));
91   GroupDimensions->TextLabel4->setText(tr("GEOM_NB_TIMES"));
92   GroupDimensions->TextLabel5->setText(tr("GEOM_STEP"));
93   GroupDimensions->TextLabel6->setText(tr("GEOM_NB_TIMES"));
94   GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE"));
95   GroupDimensions->PushButton1->setPixmap(image2);
96   GroupDimensions->PushButton2->setPixmap(image2);
97   GroupDimensions->LineEdit1->setReadOnly(true);
98   GroupDimensions->LineEdit2->setReadOnly(true);
99
100   Layout1->addWidget(GroupPoints, 2, 0);
101   Layout1->addWidget(GroupDimensions, 2, 0);
102   /***************************************************************/
103
104   setHelpFileName("multi_rotation_operation_page.html");
105
106   Init();
107 }
108
109
110 //=================================================================================
111 // function : ~TransformationGUI_MultiRotationDlg()
112 // purpose  : Destroys the object and frees any allocated resources
113 //=================================================================================
114 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
115 {
116   // no need to delete child widgets, Qt does it all for us
117 }
118
119
120 //=================================================================================
121 // function : Init()
122 // purpose  :
123 //=================================================================================
124 void TransformationGUI_MultiRotationDlg::Init()
125 {
126   /* Get setting of step value from file configuration */
127   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
128   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
129
130   double SpecificStep1 = 5;
131   double SpecificStep2 = 1;
132   /* min, max, step and decimals for spin boxes & initial values */
133   GroupPoints->SpinBox_DX->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep2, 10);
134   GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
135
136   GroupDimensions->SpinBox_DX1->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep1, DBL_DIGITS_DISPLAY);
137   GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep2, 10);
138   GroupDimensions->SpinBox_DX2->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
139   GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep2, 10);
140   GroupDimensions->SpinBox_DX1->SetValue(myAng);
141   GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
142   GroupDimensions->SpinBox_DX2->SetValue(myStep);
143   GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
144
145   /* signals and slots connections */
146   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
147   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
148   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
149
150   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152   connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
153   connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154
155   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
156   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
157   connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
158   connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159
160   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
161   connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
162   connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
163   connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
164   connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
165
166   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
167   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
168   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
169   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
170   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
171
172   connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseAngle()));
173
174   connect(myGeomGUI->getApp()->selectionMgr(),
175           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
176
177   initName( tr( "GEOM_MULTIROTATION" ) );
178   ConstructorsClicked( 0 );
179 }
180
181
182 //=================================================================================
183 // function : ConstructorsClicked()
184 // purpose  : Radio button management
185 //=================================================================================
186 void TransformationGUI_MultiRotationDlg::ConstructorsClicked(int constructorId)
187 {
188   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
189
190   myAng = 45.0;
191   myStep = 50.0;
192   myNbTimes1 = myNbTimes2 = 2;
193
194   globalSelection( GEOM_ALLSHAPES );
195
196   switch (constructorId)
197     {
198     case 0: /* Rotate simple */
199       {
200         GroupDimensions->hide();
201         resize(0, 0);
202         GroupPoints->show();
203
204         myEditCurrentArgument = GroupPoints->LineEdit1;
205         GroupPoints->LineEdit1->setText("");
206         GroupPoints->LineEdit2->setText("");
207
208         GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
209
210         break;
211       }
212     case 1: /* Rotate double */
213       {
214         GroupPoints->hide();
215         resize(0, 0);
216         GroupDimensions->show();
217
218         myEditCurrentArgument = GroupDimensions->LineEdit1;
219         GroupDimensions->LineEdit1->setText("");
220         GroupDimensions->LineEdit2->setText("");
221
222         GroupDimensions->SpinBox_DX1->SetValue(myAng);
223         GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
224         GroupDimensions->SpinBox_DX2->SetValue(myStep);
225         GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
226
227         break;
228       }
229     }
230
231   myEditCurrentArgument->setFocus();
232   myBase = myVector = GEOM::GEOM_Object::_nil();
233   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
234           this, SLOT(SelectionIntoArgument()));
235 }
236
237
238 //=================================================================================
239 // function : ClickOnOk()
240 // purpose  :
241 //=================================================================================
242 void TransformationGUI_MultiRotationDlg::ClickOnOk()
243 {
244   if ( ClickOnApply() )
245     ClickOnCancel();
246 }
247
248
249 //=================================================================================
250 // function : ClickOnApply()
251 // purpose  :
252 //=================================================================================
253 bool TransformationGUI_MultiRotationDlg::ClickOnApply()
254 {
255   if ( !onAccept() )
256     return false;
257
258   initName();
259   ConstructorsClicked( getConstructorId() );
260   return true;
261 }
262
263
264 //=================================================================================
265 // function : SelectionIntoArgument()
266 // purpose  : Called when selection as changed or other case
267 //=================================================================================
268 void TransformationGUI_MultiRotationDlg::SelectionIntoArgument()
269 {
270   myEditCurrentArgument->setText("");
271
272   if (IObjectCount() != 1) {
273     if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
274         myEditCurrentArgument == GroupDimensions->LineEdit1)
275       myBase = GEOM::GEOM_Object::_nil();
276     else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
277              myEditCurrentArgument == GroupDimensions->LineEdit2)
278       myVector = GEOM::GEOM_Object::_nil();
279     return;
280   }
281
282   // nbSel == 1
283   Standard_Boolean testResult = Standard_False;;
284   GEOM::GEOM_Object_var aSelectedObject =
285     GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
286
287   if (!testResult || CORBA::is_nil(aSelectedObject) || !GEOMBase::IsShape(aSelectedObject))
288     return;
289
290   QString aName = GEOMBase::GetName( aSelectedObject );
291
292   if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
293       myEditCurrentArgument == GroupDimensions->LineEdit1)
294     myBase = aSelectedObject;
295   else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
296            myEditCurrentArgument == GroupDimensions->LineEdit2) {
297     if ( testResult && !aSelectedObject->_is_nil() )
298         {
299           TopoDS_Shape aShape;
300           
301           
302           if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
303             {
304               LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
305               TColStd_IndexedMapOfInteger aMap;
306               aSelMgr->GetIndexes( firstIObject(), aMap );
307               if ( aMap.Extent() == 1 )
308                 {
309                   int anIndex = aMap( 1 );
310                   aName += QString(":edge_%1").arg(anIndex);
311                   
312                   //Find SubShape Object in Father
313                   GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
314                   
315                   if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
316                     GEOM::GEOM_IShapesOperations_var aShapesOp =
317                       getGeomEngine()->GetIShapesOperations( getStudyId() );
318                     myVector = aShapesOp->GetSubShape(aSelectedObject, anIndex);
319                   }
320                   else
321                     myVector = aFindedObject; // get existing object
322                 }
323               else {
324                 if (aShape.ShapeType() != TopAbs_EDGE) {
325                   aSelectedObject = GEOM::GEOM_Object::_nil();
326                   aName = "";
327                 }
328                 myVector = aSelectedObject;
329               }
330               
331             }
332         }
333   }
334   myEditCurrentArgument->setText( aName );
335
336   displayPreview();
337 }
338
339
340 //=================================================================================
341 // function : SetEditCurrentArgument()
342 // purpose  :
343 //=================================================================================
344 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
345 {
346   QPushButton* send = (QPushButton*)sender();
347   globalSelection( GEOM_ALLSHAPES );
348
349   if(send == GroupPoints->PushButton1) {
350     myEditCurrentArgument = GroupPoints->LineEdit1;
351   }
352   else if(send == GroupPoints->PushButton2) {
353     myEditCurrentArgument = GroupPoints->LineEdit2;
354     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
355   }
356   else if(send == GroupDimensions->PushButton1) {
357     myEditCurrentArgument = GroupDimensions->LineEdit1;
358   }
359   else if(send == GroupDimensions->PushButton2) {
360     myEditCurrentArgument = GroupDimensions->LineEdit2;
361     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
362   }
363
364   myEditCurrentArgument->setFocus();
365   SelectionIntoArgument();
366 }
367
368
369 //=================================================================================
370 // function : LineEditReturnPressed()
371 // purpose  :
372 //=================================================================================
373 void TransformationGUI_MultiRotationDlg::LineEditReturnPressed()
374 {
375   QLineEdit* send = (QLineEdit*)sender();
376   if(send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
377      send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2)
378     {
379       myEditCurrentArgument = send;
380       GEOMBase_Skeleton::LineEditReturnPressed();
381     }
382 }
383
384
385 //=================================================================================
386 // function : ActivateThisDialog()
387 // purpose  :
388 //=================================================================================
389 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
390 {
391   GEOMBase_Skeleton::ActivateThisDialog();
392   connect(myGeomGUI->getApp()->selectionMgr(),
393           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
394
395   ConstructorsClicked( getConstructorId() );
396 }
397
398
399 //=================================================================================
400 // function : enterEvent()
401 // purpose  :
402 //=================================================================================
403 void TransformationGUI_MultiRotationDlg::enterEvent(QEvent* e)
404 {
405   if(!GroupConstructors->isEnabled())
406     ActivateThisDialog();
407 }
408
409
410 //=================================================================================
411 // function : ValueChangedInSpinBox()
412 // purpose  :
413 //=================================================================================
414 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox(double newValue)
415 {
416   QObject* send = (QObject*)sender();
417
418   if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1)
419     myNbTimes1 = (int)newValue;
420   else if(send == GroupDimensions->SpinBox_DX1)
421     myAng = newValue;
422   else if(send == GroupDimensions->SpinBox_DX2)
423     myStep = newValue;
424   else if(send == GroupDimensions->SpinBox_DY2)
425     myNbTimes2 = (int)newValue;
426
427   displayPreview();
428 }
429
430
431 //=================================================================================
432 // function : ReverseAngle()
433 // purpose  : 'state' not used here
434 //=================================================================================
435 void TransformationGUI_MultiRotationDlg::ReverseAngle()
436 {
437   myAng = -myAng;
438
439   int aConstructorId = getConstructorId();
440
441   if(aConstructorId == 0)
442     GroupPoints->SpinBox_DX->SetValue(myAng);
443   else if(aConstructorId == 1)
444     GroupDimensions->SpinBox_DX1->SetValue(myAng);
445
446   displayPreview();
447 }
448
449
450 //=================================================================================
451 // function : createOperation
452 // purpose  :
453 //=================================================================================
454 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiRotationDlg::createOperation()
455 {
456   return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
457 }
458
459
460 //=================================================================================
461 // function : isValid
462 // purpose  :
463 //=================================================================================
464 bool TransformationGUI_MultiRotationDlg::isValid( QString& msg )
465 {
466   return !(myBase->_is_nil() || myVector->_is_nil());
467 }
468
469 //=================================================================================
470 // function : execute
471 // purpose  :
472 //=================================================================================
473 bool TransformationGUI_MultiRotationDlg::execute( ObjectList& objects )
474 {
475   bool res = false;
476
477   GEOM::GEOM_Object_var anObj;
478
479   switch ( getConstructorId() )
480     {
481     case 0 :
482       {
483         if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
484           anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
485             MultiRotate1D( myBase, myVector, myNbTimes1 );
486           res = true;
487         }
488         break;
489       }
490     case 1 :
491       {
492         if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) )
493           {
494             anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
495               MultiRotate2D( myBase, myVector, myAng, myNbTimes1, myStep, myNbTimes2 );
496             res = true;
497           }
498         break;
499       }
500     }
501
502   if ( !anObj->_is_nil() )
503     objects.push_back( anObj._retn() );
504
505   return res;
506 }
507
508
509 //=================================================================================
510 // function : closeEvent
511 // purpose  :
512 //=================================================================================
513 void  TransformationGUI_MultiRotationDlg::closeEvent( QCloseEvent* e )
514 {
515   // myGeomGUI->SetState( -1 );
516   GEOMBase_Skeleton::closeEvent( e );
517 }
518
519 //=================================================================================
520 // function : addSubshapeToStudy
521 // purpose  : virtual method to add new SubObjects if local selection
522 //=================================================================================
523 void TransformationGUI_MultiRotationDlg::addSubshapesToStudy()
524 {
525   QMap<QString, GEOM::GEOM_Object_var> objMap;
526   
527   switch (getConstructorId())
528     {
529     case 0:
530       objMap[GroupPoints->LineEdit2->text()] = myVector;
531       break;
532     case 1:
533       objMap[GroupDimensions->LineEdit2->text()] = myVector;
534       break;
535     }
536   addSubshapesToFather( objMap );
537 }