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