]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_MultiTranslationDlg.cxx
Salome HOME
NPAL17431: About WhatIs dialog box. Change default height to fit all output information.
[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(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
134   GroupPoints->SpinBox_DY->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep, 10);
135   GroupPoints->SpinBox_DX->SetValue(myStepU);
136   GroupPoints->SpinBox_DY->SetValue(myNbTimesU);
137
138   GroupDimensions->SpinBox_DX1->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
139   GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep, 10);
140   GroupDimensions->SpinBox_DX2->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
141   GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep, 10);
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   initName( tr( "GEOM_MULTITRANSLATION" ) );
186   ConstructorsClicked( 0 );
187 }
188
189
190 //=================================================================================
191 // function : ConstructorsClicked()
192 // purpose  : Radio button management
193 //=================================================================================
194 void TransformationGUI_MultiTranslationDlg::ConstructorsClicked(int constructorId)
195 {
196   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
197
198   myStepU = myStepV = 50.0;
199   myNbTimesU = myNbTimesV = 2;
200
201   globalSelection( GEOM_ALLSHAPES );
202
203   switch (constructorId)
204     {
205     case 0: /* Translate simple */
206       {
207         GroupDimensions->hide();
208         resize(0, 0);
209         GroupPoints->show();
210
211         myEditCurrentArgument = GroupPoints->LineEdit1;
212         GroupPoints->LineEdit1->setText("");
213         GroupPoints->LineEdit2->setText("");
214
215         GroupPoints->SpinBox_DX->SetValue(myStepU);
216         GroupPoints->SpinBox_DY->SetValue(myNbTimesU);
217         
218         break;
219       }
220     case 1: /* Translate double */
221       {
222         GroupPoints->hide();
223         resize(0, 0);
224         GroupDimensions->show();
225
226         myEditCurrentArgument = GroupDimensions->LineEdit1;
227         GroupDimensions->LineEdit1->setText("");
228         GroupDimensions->LineEdit2->setText("");
229         GroupDimensions->LineEdit3->setText("");
230
231         GroupDimensions->SpinBox_DX1->SetValue(myStepU);
232         GroupDimensions->SpinBox_DY1->SetValue(myNbTimesU);
233         GroupDimensions->SpinBox_DX2->SetValue(myStepV);
234         GroupDimensions->SpinBox_DY2->SetValue(myNbTimesV);
235         
236         myVectorV = GEOM::GEOM_Object::_nil();
237         break;
238       }
239     }
240
241   myEditCurrentArgument->setFocus();
242   myBase = myVectorU = GEOM::GEOM_Object::_nil();
243   connect(myGeomGUI->getApp()->selectionMgr(),
244           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
245 }
246
247
248 //=================================================================================
249 // function : ClickOnOk()
250 // purpose  :
251 //=================================================================================
252 void TransformationGUI_MultiTranslationDlg::ClickOnOk()
253 {
254   if ( ClickOnApply() )
255     ClickOnCancel();
256 }
257
258
259 //=================================================================================
260 // function : ClickOnApply()
261 // purpose  :
262 //=================================================================================
263 bool TransformationGUI_MultiTranslationDlg::ClickOnApply()
264 {
265   if ( !onAccept() )
266     return false;
267
268   initName();
269   ConstructorsClicked( getConstructorId() );
270   return true;
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 (IObjectCount() != 1) {
283     if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
284         myEditCurrentArgument == GroupDimensions->LineEdit1)
285       myBase = GEOM::GEOM_Object::_nil();
286     else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
287              myEditCurrentArgument == GroupDimensions->LineEdit2)
288       myVectorU = GEOM::GEOM_Object::_nil();
289     else if (myEditCurrentArgument == GroupDimensions->LineEdit3)
290       myVectorV = GEOM::GEOM_Object::_nil();
291     return;
292   }
293
294   // nbSel == 1
295   Standard_Boolean testResult = Standard_False;;
296   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
297
298   if ( !testResult || CORBA::is_nil( aSelectedObject ) || !GEOMBase::IsShape( aSelectedObject ) )
299     return;
300
301   if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
302       myEditCurrentArgument == GroupDimensions->LineEdit1)
303     myBase = aSelectedObject;
304   else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
305            myEditCurrentArgument == GroupDimensions->LineEdit2)
306     myVectorU = aSelectedObject;
307   else if (myEditCurrentArgument == GroupDimensions->LineEdit3)
308     myVectorV = aSelectedObject;
309
310   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
311
312   displayPreview();     
313 }
314
315
316 //=================================================================================
317 // function : SetEditCurrentArgument()
318 // purpose  :
319 //=================================================================================
320 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
321 {
322   QPushButton* send = (QPushButton*)sender();
323
324   if(send == GroupPoints->PushButton1) {
325     myEditCurrentArgument = GroupPoints->LineEdit1;
326     globalSelection( GEOM_ALLSHAPES );
327   }
328   else if(send == GroupPoints->PushButton2) {
329     myEditCurrentArgument = GroupPoints->LineEdit2;
330     globalSelection( GEOM_LINE  );
331   }
332   else if(send == GroupDimensions->PushButton1) {
333     myEditCurrentArgument = GroupDimensions->LineEdit1;
334     globalSelection( GEOM_ALLSHAPES );
335   }
336   else if(send == GroupDimensions->PushButton2) {
337     myEditCurrentArgument = GroupDimensions->LineEdit2;
338     globalSelection( GEOM_LINE  );
339   }
340   else if(send == GroupDimensions->PushButton3) {
341     myEditCurrentArgument = GroupDimensions->LineEdit3;
342     globalSelection( GEOM_LINE  );
343   }
344
345   myEditCurrentArgument->setFocus();
346   SelectionIntoArgument();
347 }
348
349
350 //=================================================================================
351 // function : LineEditReturnPressed()
352 // purpose  :
353 //=================================================================================
354 void TransformationGUI_MultiTranslationDlg::LineEditReturnPressed()
355 {
356   QLineEdit* send = (QLineEdit*)sender();
357   if(send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
358      send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2 ||
359                                        send == GroupDimensions->LineEdit3)
360     {
361       myEditCurrentArgument = send;
362       GEOMBase_Skeleton::LineEditReturnPressed();
363     }
364 }
365
366
367 //=================================================================================
368 // function : ActivateThisDialog()
369 // purpose  :
370 //=================================================================================
371 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
372 {
373   GEOMBase_Skeleton::ActivateThisDialog();
374   connect(myGeomGUI->getApp()->selectionMgr(),
375           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
376
377   ConstructorsClicked( getConstructorId() );
378 }
379
380
381 //=================================================================================
382 // function : enterEvent()
383 // purpose  :
384 //=================================================================================
385 void TransformationGUI_MultiTranslationDlg::enterEvent(QEvent* e)
386 {
387   if(!GroupConstructors->isEnabled())
388     ActivateThisDialog();
389 }
390
391
392 //=================================================================================
393 // function : ValueChangedInSpinBox()
394 // purpose  :
395 //=================================================================================
396 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox(double newValue)
397 {
398   QObject* send = (QObject*)sender();
399
400   switch(getConstructorId())
401     {
402     case 0 :
403       { 
404         if(send == GroupPoints->SpinBox_DX)
405           myStepU = newValue;
406         else if(send == GroupPoints->SpinBox_DY)
407           myNbTimesU = (int)newValue;
408         break;
409       }
410     case 1 :
411       { 
412         if(send == GroupDimensions->SpinBox_DX1)
413           myStepU = newValue;
414         else if(send == GroupDimensions->SpinBox_DY1)
415           myNbTimesU = (int)newValue;
416         else if(send == GroupDimensions->SpinBox_DX2)
417           myStepV = newValue;
418         else if(send == GroupDimensions->SpinBox_DY2)
419           myNbTimesV = (int)newValue;
420         break;
421       }
422     }
423
424   displayPreview();
425 }
426
427
428 //=================================================================================
429 // function : ReverseStepU()
430 // purpose  : 'state' not used here
431 //=================================================================================
432 void TransformationGUI_MultiTranslationDlg::ReverseStepU()
433 {
434   myStepU = -myStepU;
435
436   int aConstructorId = getConstructorId();
437
438   if(aConstructorId == 0)
439     GroupPoints->SpinBox_DX->SetValue(myStepU);
440   else if(aConstructorId == 1)
441     GroupDimensions->SpinBox_DX1->SetValue(myStepU);
442
443   displayPreview();
444 }
445
446
447 //=================================================================================
448 // function : ReverseStepV
449 // purpose  : 'state' not used here
450 //=================================================================================
451 void TransformationGUI_MultiTranslationDlg::ReverseStepV()
452 {
453   myStepV = -myStepV;
454
455   GroupDimensions->SpinBox_DX2->SetValue(myStepV);
456
457   displayPreview();
458 }
459
460
461 //=================================================================================
462 // function : createOperation
463 // purpose  :
464 //=================================================================================
465 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiTranslationDlg::createOperation()
466 {
467   return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
468 }
469
470
471 //=================================================================================
472 // function : isValid
473 // purpose  :
474 //=================================================================================
475 bool TransformationGUI_MultiTranslationDlg::isValid( QString& msg )
476 {
477   int aConstructorId = getConstructorId();
478
479   if(aConstructorId == 0)
480     return !(myBase->_is_nil() || myVectorU->_is_nil());
481   else if(aConstructorId == 1)
482     return !(myBase->_is_nil() || myVectorU->_is_nil() || myVectorV->_is_nil());
483   return 0;
484 }
485
486 //=================================================================================
487 // function : execute
488 // purpose  :
489 //=================================================================================
490 bool TransformationGUI_MultiTranslationDlg::execute( ObjectList& objects )
491 {
492   bool res = false;
493
494   GEOM::GEOM_Object_var anObj;
495
496   switch ( getConstructorId() )
497     {
498     case 0 :
499       {
500         if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) ) {
501           anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate1D( myBase, myVectorU, myStepU, myNbTimesU );
502           res = true;
503         }
504         break;
505       }
506     case 1 :
507       {
508         if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) && !CORBA::is_nil( myVectorV ) )
509           {
510             anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate2D( myBase, myVectorU, myStepU, myNbTimesU,
511                                                                                                           myVectorV, myStepV, myNbTimesV );
512             res = true;
513           }
514         break;
515       }
516     }
517
518   if ( !anObj->_is_nil() )
519     objects.push_back( anObj._retn() );
520
521   return res;
522 }
523
524
525 //=================================================================================
526 // function : closeEvent
527 // purpose  :
528 //=================================================================================
529 void  TransformationGUI_MultiTranslationDlg::closeEvent( QCloseEvent* e )
530 {
531   // myGeomGUI->SetState( -1 );
532   GEOMBase_Skeleton::closeEvent( e );
533 }