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