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