]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_PrismDlg.cxx
Salome HOME
NPAL17269: Performance pb. when creating a group with GUI.
[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   myPoint1 = myPoint2 = myBase = myVec = GEOM::GEOM_Object::_nil();
127   myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
128
129   /* Get setting of step value from file configuration */
130   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
131   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
132
133   /* min, max, step and decimals for spin boxes & initial values */
134   GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
135   GroupPoints->SpinBox_DX->SetValue(100.0);
136
137   /* signals and slots connections */
138   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
139   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
140
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
146   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
148
149   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
150   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
151           GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
152
153   connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
154
155
156   connect(GroupPoints2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
157   connect(GroupPoints2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158   connect(GroupPoints2->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
159
160   connect(GroupPoints2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
161   connect(GroupPoints2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162   connect(GroupPoints2->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
163
164
165   connect(myGeomGUI->getApp()->selectionMgr(),
166           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
167
168   initName(tr("GEOM_EXTRUSION"));
169   ConstructorsClicked(0);
170 }
171
172
173 //=================================================================================
174 // function : ConstructorsClicked()
175 // purpose  : Radio button management
176 //=================================================================================
177 void GenerationGUI_PrismDlg::ConstructorsClicked(int constructorId)
178 {
179   erasePreview();
180   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
181
182   switch (constructorId)
183   {
184   case 0:
185     {
186       globalSelection( GEOM_ALLSHAPES );
187
188       GroupPoints2->hide();
189       resize(0, 0);
190       GroupPoints->show();
191
192       myEditCurrentArgument = GroupPoints->LineEdit1;
193       GroupPoints->LineEdit1->setText(GroupPoints2->LineEdit1->text()); // keep base
194       GroupPoints->LineEdit2->setText("");
195       myVec = GEOM::GEOM_Object::_nil();
196       myOkVec = false;
197
198       break;
199     }
200   case 1:
201     {
202       globalSelection( GEOM_ALLSHAPES );
203
204       GroupPoints->hide();
205       resize(0, 0);
206       GroupPoints2->show();
207
208       myEditCurrentArgument = GroupPoints2->LineEdit1;
209       GroupPoints2->LineEdit1->setText(GroupPoints->LineEdit1->text()); // keep base
210       GroupPoints2->LineEdit2->setText("");
211       GroupPoints2->LineEdit3->setText("");
212       myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
213       myOkPnt1 = myOkPnt2 = false;
214
215       break;
216     }
217   }
218
219   myEditCurrentArgument->setFocus();
220   connect(myGeomGUI->getApp()->selectionMgr(),
221           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
222
223   if (!myOkBase)
224     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   }
291   else // getConstructorId()==1 - extrusion using 2 points
292   {
293     if (IObjectCount() != 1) {
294       if (myEditCurrentArgument == GroupPoints2->LineEdit1)
295         myOkBase = false;
296       else if (myEditCurrentArgument == GroupPoints2->LineEdit2) {
297         myPoint1 = GEOM::GEOM_Object::_nil();
298         myOkPnt1 = false;
299       }
300       else if (myEditCurrentArgument == GroupPoints2->LineEdit3) {
301         myPoint2 = GEOM::GEOM_Object::_nil();
302         myOkPnt2 = false;
303       }
304       return;
305     }
306
307     // nbSel == 1
308     Standard_Boolean testResult = Standard_False;
309     GEOM::GEOM_Object_var aSelectedObject =
310       GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
311
312     if (!testResult || CORBA::is_nil( aSelectedObject ))
313       return;
314
315     if (myEditCurrentArgument == GroupPoints2->LineEdit1) {
316       myBase = aSelectedObject;
317       myOkBase = true;
318     }
319     else if (myEditCurrentArgument == GroupPoints2->LineEdit2) {
320       myPoint1 = aSelectedObject;
321       myOkPnt1 = true;
322     }
323     else if (myEditCurrentArgument == GroupPoints2->LineEdit3) {
324       myPoint2 = aSelectedObject;
325       myOkPnt2 = true;
326     }
327
328     myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
329   }
330
331   displayPreview();
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   if (getConstructorId() == 0)
454     // by vector and height
455     return (myOkBase && myOkVec);
456
457   // by two points
458   return (myOkBase && myOkPnt1 && myOkPnt2);
459 }
460
461 //=================================================================================
462 // function : execute
463 // purpose  :
464 //=================================================================================
465 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
466 {
467   GEOM::GEOM_Object_var anObj;
468
469   switch ( getConstructorId() )
470   {
471   case 0:
472     {
473       anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
474         MakePrismVecH(myBase, myVec, getHeight());
475       break;
476     }
477   case 1:
478     {
479       anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
480         MakePrismTwoPnt(myBase, myPoint1, myPoint2);
481       break;
482     }
483   }
484   if ( !anObj->_is_nil() )
485     objects.push_back( anObj._retn() );
486
487   return true;
488 }
489
490
491 //=================================================================================
492 // function :  onReverse()
493 // purpose  :
494 //=================================================================================
495 void GenerationGUI_PrismDlg::onReverse()
496 {
497   double anOldValue = GroupPoints->SpinBox_DX->GetValue();
498   GroupPoints->SpinBox_DX->SetValue( -anOldValue );
499 }