]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_RevolDlg.cxx
Salome HOME
Using files from package LightApp instead of SalomeApp
[modules/geom.git] / src / GenerationGUI / GenerationGUI_RevolDlg.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_RevolDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "GenerationGUI_RevolDlg.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 <gp_Lin.hxx>
37 #include <BRepAdaptor_Curve.hxx>
38 #include <BRepPrimAPI_MakeRevol.hxx>
39 #include <TopExp_Explorer.hxx>
40 #include <Standard_ErrorHandler.hxx>
41 #include "GEOMImpl_Types.hxx"
42
43 #include <qlabel.h>
44 #include <qcheckbox.h>
45
46 #include "utilities.h"
47
48 //=================================================================================
49 // class    : GenerationGUI_RevolDlg()
50 // purpose  : Constructs a GenerationGUI_RevolDlg which is a child of 'parent', with the 
51 //            name 'name' and widget flags set to 'f'.
52 //            The dialog will by default be modeless, unless you set 'modal' to
53 //            TRUE to construct a modal dialog.
54 //=================================================================================
55 GenerationGUI_RevolDlg::GenerationGUI_RevolDlg(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
56   :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
57 {
58   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_REVOL")));
59   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
60
61   setCaption(tr("GEOM_REVOLUTION_TITLE"));
62
63   /***************************************************************/
64   GroupConstructors->setTitle(tr("GEOM_REVOLUTION"));
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_ARGUMENTS"));
72   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
73   GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
74   GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
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   /* Initialisations */
85   Init();
86 }
87
88
89 //=================================================================================
90 // function : ~GenerationGUI_RevolDlg()
91 // purpose  : Destroys the object and frees any allocated resources
92 //=================================================================================
93 GenerationGUI_RevolDlg::~GenerationGUI_RevolDlg()
94 {
95   // no need to delete child widgets, Qt does it all for us
96 }
97
98
99 //=================================================================================
100 // function : Init()
101 // purpose  :
102 //=================================================================================
103 void GenerationGUI_RevolDlg::Init()
104 {
105   /* init variables */
106   myEditCurrentArgument = GroupPoints->LineEdit1;
107   GroupPoints->LineEdit1->setReadOnly( true );
108   GroupPoints->LineEdit2->setReadOnly( true );
109
110   myOkBase = myOkAxis = false;
111
112   double SpecificStep = 5;
113   /* min, max, step and decimals for spin boxes & initial values */
114   GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
115   GroupPoints->SpinBox_DX->SetValue(45.0);
116
117   /* signals and slots connections */
118   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
119   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
120
121   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
122   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123
124   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
126
127   connect(GroupPoints->SpinBox_DX,   SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
128   connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)),        this, SLOT(onReverse()));
129
130   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
131    
132   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
133           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
134
135   initName(tr("GEOM_REVOLUTION"));
136
137   globalSelection( GEOM_ALLSHAPES );
138 }
139
140
141 //=================================================================================
142 // function : ClickOnOk()
143 // purpose  :
144 //=================================================================================
145 void GenerationGUI_RevolDlg::ClickOnOk()
146 {
147   if ( ClickOnApply() )
148     ClickOnCancel();
149 }
150
151
152 //=================================================================================
153 // function : ClickOnApply()
154 // purpose  :
155 //=================================================================================
156 bool GenerationGUI_RevolDlg::ClickOnApply()
157 {
158   if ( !onAccept() )
159     return false;
160
161   initName();
162   return true;
163 }
164
165 //=======================================================================
166 //function : isAcceptableBase
167 //purpose  : return true if theBase can be used as algo argument
168 //=======================================================================
169
170 static bool isAcceptableBase(const TopoDS_Shape& theBase)
171 {
172   switch ( theBase.ShapeType() ) {
173   case TopAbs_VERTEX:
174   case TopAbs_EDGE:
175   case TopAbs_WIRE:
176   case TopAbs_FACE:
177   case TopAbs_SHELL:
178     return true;
179   case TopAbs_SOLID:
180   case TopAbs_COMPSOLID:
181     return false;
182   case TopAbs_COMPOUND: {
183     TopExp_Explorer exp( theBase, TopAbs_SOLID);
184     return !exp.More();
185   }
186   default:
187     return false;
188   }
189   return false;
190 }
191
192 //=================================================================================
193 // function : SelectionIntoArgument()
194 // purpose  : Called when selection as changed or other case
195 //=================================================================================
196 void GenerationGUI_RevolDlg::SelectionIntoArgument()
197 {
198   erasePreview();
199   myEditCurrentArgument->setText("");
200   
201   if(IObjectCount() != 1) {
202     if(myEditCurrentArgument == GroupPoints->LineEdit1)
203       myOkBase = false;        
204     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
205       myOkAxis = false;
206     return;
207   }
208   
209   // nbSel == 1
210   Standard_Boolean testResult = Standard_False;
211   GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
212   
213   if (!testResult)
214     return;
215
216   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
217     TopoDS_Shape S;
218     myOkBase = false;
219     
220     if ( !GEOMBase::GetShape(aSelectedObject, S) || !isAcceptableBase( S ) )
221       return;
222     
223     myBase = aSelectedObject;
224     myOkBase = true;
225   }
226   else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
227     myAxis = aSelectedObject;
228     myOkAxis = true;
229   }
230   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
231
232   displayPreview();
233 }
234
235
236 //=================================================================================
237 // function : SetEditCurrentArgument()
238 // purpose  :
239 //=================================================================================
240 void GenerationGUI_RevolDlg::SetEditCurrentArgument()
241 {
242   QPushButton* send = (QPushButton*)sender();
243   globalSelection( GEOM_ALLSHAPES );
244
245   if(send == GroupPoints->PushButton1) {
246     GroupPoints->LineEdit1->setFocus();
247     myEditCurrentArgument = GroupPoints->LineEdit1;
248   }
249   else if(send == GroupPoints->PushButton2) {
250     GroupPoints->LineEdit2->setFocus();
251     myEditCurrentArgument = GroupPoints->LineEdit2;
252     globalSelection( GEOM_LINE );
253   }
254   SelectionIntoArgument();
255 }
256
257
258 //=================================================================================
259 // function : LineEditReturnPressed()
260 // purpose  :
261 //=================================================================================
262 void GenerationGUI_RevolDlg::LineEditReturnPressed()
263 {  
264   QLineEdit* send = (QLineEdit*)sender();
265   if(send == GroupPoints->LineEdit1 ||
266      send == GroupPoints->LineEdit2)
267     {
268       myEditCurrentArgument = send;
269       GEOMBase_Skeleton::LineEditReturnPressed();
270     }
271 }
272
273
274 //=================================================================================
275 // function : ActivateThisDialog()
276 // purpose  :
277 //=================================================================================
278 void GenerationGUI_RevolDlg::ActivateThisDialog()
279 {
280   GEOMBase_Skeleton::ActivateThisDialog();
281   globalSelection( GEOM_ALLSHAPES );
282   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
283   GroupPoints->LineEdit1->setFocus();
284   myEditCurrentArgument = GroupPoints->LineEdit1;
285   displayPreview();
286 }
287
288
289 //=================================================================================
290 // function : enterEvent()
291 // purpose  :
292 //=================================================================================
293 void GenerationGUI_RevolDlg::enterEvent(QEvent* e)
294 {
295   if ( !GroupConstructors->isEnabled() )
296     ActivateThisDialog();
297 }
298
299
300 //=================================================================================
301 // function : ValueChangedInSpinBox()
302 // purpose  :
303 //=================================================================================
304 void GenerationGUI_RevolDlg::ValueChangedInSpinBox()
305 {
306   displayPreview();
307 }
308
309
310 //=================================================================================
311 // function : getAngle()
312 // purpose  :
313 //=================================================================================
314 double GenerationGUI_RevolDlg::getAngle() const
315 {
316   return GroupPoints->SpinBox_DX->GetValue();
317 }
318
319 //=================================================================================
320 // function : createOperation
321 // purpose  :
322 //=================================================================================
323 GEOM::GEOM_IOperations_ptr GenerationGUI_RevolDlg::createOperation()
324 {
325   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
326 }
327
328 //=================================================================================
329 // function : isValid
330 // purpose  :
331 //=================================================================================
332 bool GenerationGUI_RevolDlg::isValid( QString& )
333 {
334   return myOkBase && myOkAxis;
335 }
336
337 //=================================================================================
338 // function : execute
339 // purpose  :
340 //=================================================================================
341 bool GenerationGUI_RevolDlg::execute( ObjectList& objects )
342 {
343   GEOM::GEOM_Object_var anObj;
344
345   anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
346     getOperation() )->MakeRevolutionAxisAngle( myBase, myAxis, getAngle() * PI180 );
347
348   if ( !anObj->_is_nil() )
349     objects.push_back( anObj._retn() );
350
351   return true;
352 }
353
354
355 //=================================================================================
356 // function :  onReverse()
357 // purpose  :
358 //=================================================================================
359 void GenerationGUI_RevolDlg::onReverse()
360 {
361   double anOldValue = GroupPoints->SpinBox_DX->GetValue();
362   GroupPoints->SpinBox_DX->SetValue( -anOldValue );
363 }