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