]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_RotationDlg.cxx
Salome HOME
NPAL17431: About WhatIs dialog box. Change default height to fit all output information.
[modules/geom.git] / src / TransformationGUI / TransformationGUI_RotationDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  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 //
23 //
24 //  File   : TransformationGUI_RotationDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "TransformationGUI_RotationDlg.h"
30
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
35
36 #include <qcheckbox.h>
37 #include <qlabel.h>
38
39 #include "GEOMImpl_Types.hxx"
40
41 #include "utilities.h"
42
43 using namespace std;
44
45 //=================================================================================
46 // class    : TransformationGUI_RotationDlg()
47 // purpose  : Constructs a TransformationGUI_RotationDlg which is a child of 'parent', with the
48 //            name 'name' and widget flags set to 'f'.
49 //            The dialog will by default be modeless, unless you set 'modal' to
50 //            TRUE to construct a modal dialog.
51 //=================================================================================
52 TransformationGUI_RotationDlg::TransformationGUI_RotationDlg
53   (GeometryGUI* theGeometryGUI, QWidget* parent,  const char* name, bool modal, WFlags fl)
54   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
55                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
56 {
57   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
58   QPixmap image0 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ROTATION")));
59   QPixmap image1 (aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
60   QPixmap image2 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ROTATION_THREE_POINTS")));
61
62   setCaption(tr("GEOM_ROTATION_TITLE"));
63
64   /***************************************************************/
65   GroupConstructors->setTitle(tr("GEOM_ROTATION"));
66   RadioButton1->setPixmap(image0);
67   RadioButton2->setPixmap(image2);
68   RadioButton3->close(TRUE);
69
70   GroupPoints = new DlgRef_4Sel1Spin2Check(this, "GroupPoints");
71   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
73   GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
74   GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
75   GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg("1"));
76   GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg("2"));
77
78   GroupPoints->LineEdit1->setReadOnly(true);
79   GroupPoints->LineEdit2->setReadOnly(true);
80   GroupPoints->LineEdit4->setReadOnly(true);
81   GroupPoints->LineEdit5->setReadOnly(true);
82   GroupPoints->PushButton1->setPixmap(image1);
83   GroupPoints->PushButton2->setPixmap(image1);
84   GroupPoints->PushButton4->setPixmap(image1);
85   GroupPoints->PushButton5->setPixmap(image1);
86   GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
87   GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
88
89   Layout1->addWidget(GroupPoints, 2, 0);
90   /***************************************************************/
91
92   double anAngle = 0;
93   double SpecificStep = 5;
94   /* min, max, step and decimals for spin boxes & initial values */
95   GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
96   GroupPoints->SpinBox_DX->SetValue(anAngle);
97
98   // Activate Create a Copy mode
99   GroupPoints->CheckButton1->setChecked(true);
100   CreateCopyModeChanged(true);
101
102   /* signals and slots connections */
103   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
104   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
105   connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
106
107   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
108   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
109   connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
110   connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111
112   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
113   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
114
115   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
116   connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
117   connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
118
119   connect(myGeomGUI->getApp()->selectionMgr(),
120           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
121
122   setHelpFileName("rotation.htm");
123
124   Init();
125 }
126
127
128 //=================================================================================
129 // function : ~TransformationGUI_RotationDlg()
130 // purpose  : Destroys the object and frees any allocated resources
131 //=================================================================================
132 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
133 {
134   // no need to delete child widgets, Qt does it all for us
135 }
136
137
138 //=================================================================================
139 // function : Init()
140 // purpose  :
141 //=================================================================================
142 void TransformationGUI_RotationDlg::Init()
143 {
144   /* init variables */
145   myEditCurrentArgument = GroupPoints->LineEdit1;
146   GroupPoints->LineEdit2->clear();
147
148   myAxis = myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
149
150   initName( tr( "GEOM_ROTATION" ) );
151   ConstructorsClicked( 0 );
152 }
153
154 //=================================================================================
155 // function : ConstructorsClicked()
156 // purpose  : Radio button management
157 //=================================================================================
158 void TransformationGUI_RotationDlg::ConstructorsClicked(int constructorId)
159 {
160   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
161
162   myEditCurrentArgument = GroupPoints->LineEdit1;
163   globalSelection();
164
165   switch (constructorId)
166     {
167     case 0: /* rotation an object angle and axis */
168       {
169         GroupPoints->ShowRows(2,3,false);
170         resize(0,0);
171         GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
172         GroupPoints->LineEdit2->clear();
173         GroupPoints->ShowRows(4,4,true);
174         myAxis = GEOM::GEOM_Object::_nil();
175         break;
176       }
177     case 1: /* rotation an object by 3 points */
178       {
179         GroupPoints->ShowRows(4,4,false);
180         resize(0,0);
181         GroupPoints->ShowRows(2,3,true);
182         GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
183         GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg("1"));
184         GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg("2"));
185         GroupPoints->LineEdit2->clear();
186         GroupPoints->LineEdit4->clear();
187         GroupPoints->LineEdit5->clear();
188         myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
189         break;
190       }
191     }
192
193   myEditCurrentArgument->setFocus();
194   connect(myGeomGUI->getApp()->selectionMgr(),
195           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
196 }
197
198 //=================================================================================
199 // function : ClickOnOk()
200 // purpose  :
201 //=================================================================================
202 void TransformationGUI_RotationDlg::ClickOnOk()
203 {
204   if ( ClickOnApply() )
205     ClickOnCancel();
206 }
207
208
209 //=================================================================================
210 // function : ClickOnApply()
211 // purpose  :
212 //=================================================================================
213 bool TransformationGUI_RotationDlg::ClickOnApply()
214 {
215   if ( !onAccept( GroupPoints->CheckButton1->isChecked()) )
216     return false;
217
218   initName();
219   ConstructorsClicked( getConstructorId() );
220   return true;
221 }
222
223
224 //=================================================================================
225 // function : SelectionIntoArgument()
226 // purpose  : Called when selection as changed or other case
227 //=================================================================================
228 void TransformationGUI_RotationDlg::SelectionIntoArgument()
229 {
230   myEditCurrentArgument->setText("");
231   QString aName;
232
233   if(myEditCurrentArgument == GroupPoints->LineEdit1)
234     {
235       int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
236       if(aNbSel < 1)
237         {
238           myObjects.length(0);
239           return;
240         }
241       GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
242       if (!myObjects.length())
243         return;
244     }
245   else
246     {
247       if(IObjectCount() != 1)
248         {
249           if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
250             myAxis = GEOM::GEOM_Object::_nil();
251           else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
252             myCentPoint  = GEOM::GEOM_Object::_nil();
253           else if(myEditCurrentArgument == GroupPoints->LineEdit4)
254             myPoint1 = GEOM::GEOM_Object::_nil();
255           else if(myEditCurrentArgument == GroupPoints->LineEdit5)
256             myPoint2 = GEOM::GEOM_Object::_nil();
257           return;
258         }
259
260       Standard_Boolean testResult = Standard_False;
261       GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
262       if(!testResult || CORBA::is_nil( aSelectedObject ))
263         return;
264
265       if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
266         myAxis = aSelectedObject;
267       else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
268         myCentPoint = aSelectedObject;
269       else if(myEditCurrentArgument == GroupPoints->LineEdit4)
270         myPoint1 = aSelectedObject;
271       else if(myEditCurrentArgument == GroupPoints->LineEdit5)
272         myPoint2 = aSelectedObject;
273
274       aName = GEOMBase::GetName( aSelectedObject );
275     }
276   myEditCurrentArgument->setText( aName );
277
278   displayPreview();
279 }
280
281
282 //=================================================================================
283 // function : SetEditCurrentArgument()
284 // purpose  :
285 //=================================================================================
286 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
287 {
288   QPushButton* send = (QPushButton*)sender();
289
290   if(send == GroupPoints->PushButton1) {
291     myEditCurrentArgument = GroupPoints->LineEdit1;
292     globalSelection();
293   }
294   else if(send == GroupPoints->PushButton2) {
295     myEditCurrentArgument = GroupPoints->LineEdit2;
296     getConstructorId() == 0 ? globalSelection( GEOM_LINE ) :
297                               globalSelection( GEOM_POINT  );
298   }
299   else if (send == GroupPoints->PushButton4)
300     {
301       myEditCurrentArgument = GroupPoints->LineEdit4;
302       globalSelection( GEOM_POINT );
303     }
304   else if (send == GroupPoints->PushButton5)
305     {
306       myEditCurrentArgument = GroupPoints->LineEdit5;
307       globalSelection( GEOM_POINT );
308     }
309
310   myEditCurrentArgument->setFocus();
311   SelectionIntoArgument();
312 }
313
314
315 //=================================================================================
316 // function : LineEditReturnPressed()
317 // purpose  :
318 //=================================================================================
319 void TransformationGUI_RotationDlg::LineEditReturnPressed()
320 {
321   QLineEdit* send = (QLineEdit*)sender();
322   if(send == GroupPoints->LineEdit1 ||
323      send == GroupPoints->LineEdit2)
324     {
325       myEditCurrentArgument = send;
326       GEOMBase_Skeleton::LineEditReturnPressed();
327     }
328 }
329
330
331 //=================================================================================
332 // function : ActivateThisDialog()
333 // purpose  :
334 //=================================================================================
335 void TransformationGUI_RotationDlg::ActivateThisDialog()
336 {
337   GEOMBase_Skeleton::ActivateThisDialog();
338   connect(myGeomGUI->getApp()->selectionMgr(),
339           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
340
341   ConstructorsClicked( getConstructorId() );
342 }
343
344
345 //=================================================================================
346 // function : enterEvent()
347 // purpose  :
348 //=================================================================================
349 void TransformationGUI_RotationDlg::enterEvent(QEvent* e)
350 {
351   if (!GroupConstructors->isEnabled())
352     ActivateThisDialog();
353 }
354
355
356 //=================================================================================
357 // function : ValueChangedInSpinBox()
358 // purpose  :
359 //=================================================================================
360 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
361 {
362   displayPreview();
363 }
364
365
366 //=================================================================================
367 // function : createOperation
368 // purpose  :
369 //=================================================================================
370 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
371 {
372   return getGeomEngine()->GetITransformOperations( getStudyId() );
373 }
374
375
376 //=================================================================================
377 // function : isValid
378 // purpose  :
379 //=================================================================================
380 bool TransformationGUI_RotationDlg::isValid( QString& msg )
381 {
382   switch (getConstructorId())
383     {
384     case 0:
385       {
386         return !(myObjects.length() == 0 || myAxis->_is_nil());
387         break;
388       }
389     case 1:
390       {
391         return !(myObjects.length() == 0 || myCentPoint->_is_nil() || myPoint1->_is_nil() || myPoint2->_is_nil() );
392         break;
393       }
394     default: return false;
395     }
396 }
397
398
399 //=================================================================================
400 // function : execute
401 // purpose  :
402 //=================================================================================
403 bool TransformationGUI_RotationDlg::execute( ObjectList& objects )
404 {
405   bool res = false;
406   bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
407
408   GEOM::GEOM_Object_var anObj;
409
410   switch ( getConstructorId() )
411     {
412     case 0 :
413       {
414         if (toCreateCopy)
415           for (int i = 0; i < myObjects.length(); i++)
416             {
417               anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
418                 RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 );
419               if ( !anObj->_is_nil() )
420                 objects.push_back( anObj._retn() );
421             }
422         else
423           for (int i = 0; i < myObjects.length(); i++)
424             {
425               anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
426                 Rotate( myObjects[i], myAxis, GetAngle() * PI180 );
427               if ( !anObj->_is_nil() )
428                 objects.push_back( anObj._retn() );
429             }
430         res = true;
431         break;
432       }
433     case 1 :
434       {
435         if (toCreateCopy)
436           for (int i = 0; i < myObjects.length(); i++)
437             {
438               anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
439                 RotateThreePointsCopy( myObjects[i], myCentPoint, myPoint1, myPoint2 );
440               if ( !anObj->_is_nil() )
441                 objects.push_back( anObj._retn() );
442             }
443         else
444           for (int i = 0; i < myObjects.length(); i++)
445             {
446               anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
447                 RotateThreePoints( myObjects[i], myCentPoint, myPoint1, myPoint2 );     
448               if ( !anObj->_is_nil() )
449                 objects.push_back( anObj._retn() );
450             }
451         res = true;
452         break;
453       }
454     }
455
456   return res;
457 }
458
459
460 //=================================================================================
461 // function : closeEvent
462 // purpose  :
463 //=================================================================================
464 void TransformationGUI_RotationDlg::closeEvent( QCloseEvent* e )
465 {
466   GEOMBase_Skeleton::closeEvent( e );
467 }
468
469
470 //=================================================================================
471 // function : GetAngle()
472 // purpose  :
473 //=================================================================================
474 double TransformationGUI_RotationDlg::GetAngle() const
475 {
476   return GroupPoints->SpinBox_DX->GetValue();
477 }
478
479
480 //=================================================================================
481 // function :  CreateCopyModeChanged()
482 // purpose  :
483 //=================================================================================
484 void TransformationGUI_RotationDlg::CreateCopyModeChanged(bool isCreateCopy)
485 {
486   this->GroupBoxName->setEnabled(isCreateCopy);
487 }
488
489
490 //=================================================================================
491 // function :  onReverse()
492 // purpose  :
493 //=================================================================================
494 void TransformationGUI_RotationDlg::onReverse()
495 {
496   double anOldValue = GroupPoints->SpinBox_DX->GetValue();
497   GroupPoints->SpinBox_DX->SetValue( -anOldValue );
498 }