Salome HOME
Using files from package LightApp instead of SalomeApp
[modules/geom.git] / src / OperationGUI / OperationGUI_ArchimedeDlg.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   : OperationGUI_ArchimedeDlg.cxx
25 //  Author : Nicolas REJNERI 
26 //  Module : GEOM
27 //  $Header$
28
29 #include "OperationGUI_ArchimedeDlg.h"
30 #include "DlgRef_1Sel3Spin.h"
31
32 #include "SUIT_Desktop.h"
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "LightApp_SelectionMgr.h"
36
37 #include <qlabel.h>
38
39 //=================================================================================
40 // class    : OperationGUI_ArchimedeDlg()
41 // purpose  : Constructs a OperationGUI_ArchimedeDlg which is a child of 'parent', with the 
42 //            name 'name' and widget flags set to 'f'.
43 //            The dialog will by default be modeless, unless you set 'modal' to
44 //            TRUE to construct a modal dialog.
45 //=================================================================================
46 OperationGUI_ArchimedeDlg::OperationGUI_ArchimedeDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
47 : GEOMBase_Skeleton( parent, "ArchimedeDlg", false,
48                      WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
49 {
50   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_ARCHIMEDE")));
51   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
52   
53   setCaption(tr("GEOM_ARCHIMEDE_TITLE"));
54
55   /***************************************************************/
56   GroupConstructors->setTitle(tr("GEOM_ARCHIMEDE"));
57   RadioButton1->setPixmap(image0);
58   RadioButton2->close(TRUE);
59   RadioButton3->close(TRUE);
60
61   GroupPoints = new DlgRef_1Sel3Spin(this, "GroupPoints");
62   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
63   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
64   GroupPoints->TextLabel2->setText(tr("GEOM_WEIGHT"));
65   GroupPoints->TextLabel3->setText(tr("GEOM_WATER_DENSITY"));
66   GroupPoints->TextLabel4->setText(tr("GEOM_MESHING_DEFLECTION"));
67   GroupPoints->PushButton1->setPixmap(image1);
68   GroupPoints->LineEdit1->setReadOnly( true );
69
70   Layout1->addWidget(GroupPoints, 2, 0);
71   /***************************************************************/
72
73   /* Initialisations */
74   Init();
75 }
76
77
78 //=================================================================================
79 // function : ~OperationGUI_ArchimedeDlg()
80 // purpose  : Destroys the object and frees any allocated resources
81 //=================================================================================
82 OperationGUI_ArchimedeDlg::~OperationGUI_ArchimedeDlg()
83 {
84   // no need to delete child widgets, Qt does it all for us
85 }
86
87
88 //=================================================================================
89 // function : Init()
90 // purpose  :
91 //=================================================================================
92 void OperationGUI_ArchimedeDlg::Init()
93 {
94   /* init variables */
95   myEditCurrentArgument = GroupPoints->LineEdit1;
96
97   /* Get setting of myStep value from file configuration */
98   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
99   double myStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
100
101   double SpecificStep1 = 0.1;
102   double SpecificStep2 = 0.01;
103   /* min, max, myStep and decimals for spin boxes & initial values */
104   GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, myStep, 3);
105   GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, SpecificStep1, 3);
106   GroupPoints->SpinBox_DZ->RangeStepAndValidator(0.001, 999.999, SpecificStep2, 3);
107
108   GroupPoints->SpinBox_DX->SetValue( 100.0 );
109   GroupPoints->SpinBox_DY->SetValue( 1.0 );
110   GroupPoints->SpinBox_DZ->SetValue( 0.01 );
111
112   /* signals and slots connections */
113   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
114   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
115
116   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
117
118   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
119   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
120   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, SLOT(SetStep(double)));
121   
122   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
123           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
124   
125   initName( tr( "GEOM_ARCHIMEDE" ) );
126   
127   globalSelection( GEOM_ALLSHAPES );
128
129   SelectionIntoArgument();
130   
131   /* displays Dialog */
132   GroupPoints->show();
133   this->show();
134 }
135
136
137 //=================================================================================
138 // function : ClickOnOk()
139 // purpose  :
140 //=================================================================================
141 void OperationGUI_ArchimedeDlg::ClickOnOk()
142 {
143   if ( ClickOnApply() )
144     ClickOnCancel();
145 }
146
147
148 //=================================================================================
149 // function : ClickOnApply()
150 // purpose  :
151 //=================================================================================
152 bool OperationGUI_ArchimedeDlg::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 as changed or other case
165 //=================================================================================
166 void OperationGUI_ArchimedeDlg::SelectionIntoArgument()
167 {
168   myEditCurrentArgument->setText( "" );
169   myShape = GEOM::GEOM_Object::_nil();
170   
171   if ( IObjectCount() != 1 )
172     return;
173
174   Standard_Boolean testResult = Standard_False;
175   myShape = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
176
177   if ( !testResult || myShape->_is_nil() || !GEOMBase::IsShape( myShape ) )
178   {
179     myShape = GEOM::GEOM_Object::_nil();
180     return;
181   }
182
183   myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
184 }
185
186
187 //=================================================================================
188 // function : LineEditReturnPressed()
189 // purpose  :
190 //=================================================================================
191 void OperationGUI_ArchimedeDlg::LineEditReturnPressed()
192 {
193   QLineEdit* send = (QLineEdit*)sender();
194   if(send == GroupPoints->LineEdit1)
195     myEditCurrentArgument = GroupPoints->LineEdit1;
196   else
197     return;
198
199   GEOMBase_Skeleton::LineEditReturnPressed();
200   return;
201 }
202
203 //=================================================================================
204 // function : ActivateThisDialog()
205 // purpose  :
206 //=================================================================================
207 void OperationGUI_ArchimedeDlg::ActivateThisDialog()
208 {
209   GEOMBase_Skeleton::ActivateThisDialog();
210   globalSelection( GEOM_ALLSHAPES );
211   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
212           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
213   return;
214 }
215
216
217 //=================================================================================
218 // function : enterEvent()
219 // purpose  :
220 //=================================================================================
221 void OperationGUI_ArchimedeDlg::enterEvent(QEvent* e)
222 {
223   if(GroupConstructors->isEnabled())
224     return;
225   this->ActivateThisDialog();
226   return;
227 }
228
229
230 //=================================================================================
231 // function : createOperation
232 // purpose  :
233 //=================================================================================
234 GEOM::GEOM_IOperations_ptr OperationGUI_ArchimedeDlg::createOperation()
235 {
236   return getGeomEngine()->GetILocalOperations( getStudyId() );
237 }
238
239 //=================================================================================
240 // function : isValid
241 // purpose  :
242 //=================================================================================
243 bool OperationGUI_ArchimedeDlg::isValid( QString& )
244 {
245   return !myShape->_is_nil();
246 }
247
248 //=================================================================================
249 // function : execute
250 // purpose  :
251 //=================================================================================
252 bool OperationGUI_ArchimedeDlg::execute( ObjectList& objects )
253 {
254   GEOM::GEOM_Object_var anObj;
255
256   double aWeight         = GroupPoints->SpinBox_DX->GetValue();
257   double aWaterDensity   = GroupPoints->SpinBox_DY->GetValue();
258   double aMeshDeflection = GroupPoints->SpinBox_DZ->GetValue();
259   
260   anObj = GEOM::GEOM_ILocalOperations::_narrow(
261     getOperation() )->MakeArchimede( myShape, aWeight, aWaterDensity, aMeshDeflection );
262
263   if ( !anObj->_is_nil() )
264     objects.push_back( anObj._retn() );
265
266   return true;
267 }