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