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