Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
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
61   setCaption(tr("GEOM_PRISM_TITLE"));
62
63   /***************************************************************/
64   GroupConstructors->setTitle(tr("GEOM_PRISM"));
65   RadioButton1->setPixmap(image0);
66   RadioButton2->close(TRUE);
67   RadioButton3->close(TRUE);
68
69   GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
70   GroupPoints->CheckButton1->hide();
71   GroupPoints->GroupBox1->setTitle(tr("GEOM_PRISM_BSV"));
72   GroupPoints->TextLabel1->setText(tr("GEOM_BASE"));
73   GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
74   GroupPoints->TextLabel3->setText(tr("GEOM_HEIGHT"));
75   GroupPoints->PushButton1->setPixmap(image1);
76   GroupPoints->PushButton2->setPixmap(image1);
77   GroupPoints->LineEdit1->setReadOnly( true );
78   GroupPoints->LineEdit2->setReadOnly( true );
79   GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
80
81   Layout1->addWidget(GroupPoints, 2, 0);
82   /***************************************************************/
83
84   setHelpFileName("extrusion.htm");
85
86   /* Initialisations */
87   Init();
88 }
89
90
91 //=================================================================================
92 // function : ~GenerationGUI_PrismDlg()
93 // purpose  : Destroys the object and frees any allocated resources
94 //=================================================================================
95 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
96 {  
97   /* no need to delete child widgets, Qt does it all for us */
98 }
99
100
101 //=================================================================================
102 // function : Init()
103 // purpose  :
104 //=================================================================================
105 void GenerationGUI_PrismDlg::Init()
106 {
107   /* init variables */
108   myEditCurrentArgument = GroupPoints->LineEdit1;
109   GroupPoints->LineEdit1->setReadOnly( true );
110   GroupPoints->LineEdit2->setReadOnly( true );
111
112   myOkBase = myOkVec = false;
113   
114   /* Get setting of step value from file configuration */
115   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
116   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
117
118   /* min, max, step and decimals for spin boxes & initial values */
119   GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, +999.999, step, 3);
120   GroupPoints->SpinBox_DX->SetValue(100.0);
121
122   /* signals and slots connections */
123   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
124   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125
126   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
127   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128
129   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
131
132   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
133   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
134
135   connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)),      this, SLOT(onReverse()));
136
137   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
138           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
139
140   initName(tr("GEOM_PRISM"));
141
142   globalSelection( GEOM_ALLSHAPES );
143 }
144
145
146 //=================================================================================
147 // function : ClickOnOk()
148 // purpose  :
149 //=================================================================================
150 void GenerationGUI_PrismDlg::ClickOnOk()
151 {
152   if ( ClickOnApply() )
153     ClickOnCancel();
154 }
155
156
157 //=================================================================================
158 // function : ClickOnApply()
159 // purpose  :
160 //=================================================================================
161 bool GenerationGUI_PrismDlg::ClickOnApply()
162 {
163   if ( !onAccept() )
164     return false;
165
166   initName();
167   return true;
168 }
169
170
171 //=================================================================================
172 // function : SelectionIntoArgument()
173 // purpose  : Called when selection has changed
174 //=================================================================================
175 void GenerationGUI_PrismDlg::SelectionIntoArgument()
176 {
177   erasePreview();
178   myEditCurrentArgument->setText("");
179   
180   if (IObjectCount() != 1) {
181     if (myEditCurrentArgument == GroupPoints->LineEdit1)
182       myOkBase = false;
183     else if (myEditCurrentArgument == GroupPoints->LineEdit2)
184       myOkVec = false;
185     return;
186   }
187
188   // nbSel == 1
189   Standard_Boolean testResult = Standard_False;
190   GEOM::GEOM_Object_ptr aSelectedObject =
191     GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
192
193   if (!testResult)
194     return;
195
196   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
197     myOkBase = false;
198     TopoDS_Shape S;
199     
200     if (!GEOMBase::GetShape(aSelectedObject, S) ||
201          S.ShapeType() <= 2)
202       return;
203
204     myBase = aSelectedObject;
205     myOkBase = true;
206   } else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
207     myVec = aSelectedObject;
208     myOkVec = true;
209   }
210   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
211
212   displayPreview();
213 }
214
215
216 //=================================================================================
217 // function : SetEditCurrentArgument()
218 // purpose  :
219 //=================================================================================
220 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
221 {
222   QPushButton* send = (QPushButton*)sender();
223   globalSelection( GEOM_ALLSHAPES );
224
225   if(send == GroupPoints->PushButton1) {
226     GroupPoints->LineEdit1->setFocus();
227     myEditCurrentArgument = GroupPoints->LineEdit1;
228   }
229   else if(send == GroupPoints->PushButton2) {
230     GroupPoints->LineEdit2->setFocus();
231     myEditCurrentArgument = GroupPoints->LineEdit2;
232     globalSelection( GEOM_LINE );
233   }
234   SelectionIntoArgument();
235 }
236
237
238 //=================================================================================
239 // function : LineEditReturnPressed()
240 // purpose  :
241 //=================================================================================
242 void GenerationGUI_PrismDlg::LineEditReturnPressed()
243 {
244   QLineEdit* send = (QLineEdit*)sender();
245   if(send == GroupPoints->LineEdit1 ||
246      send == GroupPoints->LineEdit2)
247     {
248       myEditCurrentArgument = send;
249       GEOMBase_Skeleton::LineEditReturnPressed();
250     }
251 }
252
253 //=================================================================================
254 // function : enterEvent()
255 // purpose  : when mouse enter onto the QWidget
256 //=================================================================================
257 void GenerationGUI_PrismDlg::enterEvent(QEvent * e)
258 {
259   if ( !GroupConstructors->isEnabled() )
260     ActivateThisDialog();
261 }
262
263
264 //=================================================================================
265 // function : ActivateThisDialog()
266 // purpose  :
267 //=================================================================================
268 void GenerationGUI_PrismDlg::ActivateThisDialog()
269 {
270   GEOMBase_Skeleton::ActivateThisDialog();
271   globalSelection( GEOM_ALLSHAPES );
272   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
273           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
274   GroupPoints->LineEdit1->setFocus();
275   myEditCurrentArgument = GroupPoints->LineEdit1;
276   displayPreview();
277 }
278
279
280 //=================================================================================
281 // function : ValueChangedInSpinBox()
282 // purpose  :
283 //=================================================================================
284 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
285 {
286   displayPreview();
287 }
288
289
290 //=================================================================================
291 // function : getHeight()
292 // purpose  :
293 //=================================================================================
294 double GenerationGUI_PrismDlg::getHeight() const
295 {
296   return GroupPoints->SpinBox_DX->GetValue();
297 }
298
299 //=================================================================================
300 // function : createOperation
301 // purpose  :
302 //=================================================================================
303 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
304 {
305   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
306 }
307
308 //=================================================================================
309 // function : isValid
310 // purpose  :
311 //=================================================================================
312 bool GenerationGUI_PrismDlg::isValid( QString& )
313 {
314   return myOkBase && myOkVec;
315 }
316
317 //=================================================================================
318 // function : execute
319 // purpose  :
320 //=================================================================================
321 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
322 {
323   GEOM::GEOM_Object_var anObj;
324
325   anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
326     MakePrismVecH(myBase, myVec, getHeight());
327
328   if ( !anObj->_is_nil() )
329     objects.push_back( anObj._retn() );
330
331   return true;
332 }
333
334
335 //=================================================================================
336 // function :  onReverse()
337 // purpose  :
338 //=================================================================================
339 void GenerationGUI_PrismDlg::onReverse()
340 {
341   double anOldValue = GroupPoints->SpinBox_DX->GetValue();
342   GroupPoints->SpinBox_DX->SetValue( -anOldValue );
343 }