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