]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_ArchimedeDlg.cxx
Salome HOME
77468ea95ea3fade45d41d16b14a272360ea6263
[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 using namespace std;
30 #include "OperationGUI_ArchimedeDlg.h"
31
32 #include "QAD_Config.h"
33
34 //=================================================================================
35 // class    : OperationGUI_ArchimedeDlg()
36 // purpose  : Constructs a OperationGUI_ArchimedeDlg which is a child of 'parent', with the 
37 //            name 'name' and widget flags set to 'f'.
38 //            The dialog will by default be modeless, unless you set 'modal' to
39 //            TRUE to construct a modal dialog.
40 //=================================================================================
41 OperationGUI_ArchimedeDlg::OperationGUI_ArchimedeDlg(QWidget* parent,  const char* name, OperationGUI* theOperationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
42   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
43 {
44   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_ARCHIMEDE")));
45   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
46   
47   setCaption(tr("GEOM_ARCHIMEDE_TITLE"));
48
49   /***************************************************************/
50   GroupConstructors->setTitle(tr("GEOM_ARCHIMEDE"));
51   RadioButton1->setPixmap(image0);
52   RadioButton2->close(TRUE);
53   RadioButton3->close(TRUE);
54
55   GroupPoints = new DlgRef_1Sel3Spin(this, "GroupPoints");
56   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
57   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
58   GroupPoints->TextLabel2->setText(tr("GEOM_WEIGHT"));
59   GroupPoints->TextLabel3->setText(tr("GEOM_WATER_DENSITY"));
60   GroupPoints->TextLabel4->setText(tr("GEOM_MESHING_DEFLECTION"));
61   GroupPoints->PushButton1->setPixmap(image1);
62
63   Layout1->addWidget(GroupPoints, 1, 0);
64   /***************************************************************/
65
66   /* Initialisations */
67   myOperationGUI = theOperationGUI;
68   Init();
69 }
70
71
72 //=================================================================================
73 // function : ~OperationGUI_ArchimedeDlg()
74 // purpose  : Destroys the object and frees any allocated resources
75 //=================================================================================
76 OperationGUI_ArchimedeDlg::~OperationGUI_ArchimedeDlg()
77 {
78   // no need to delete child widgets, Qt does it all for us
79 }
80
81
82 //=================================================================================
83 // function : Init()
84 // purpose  :
85 //=================================================================================
86 void OperationGUI_ArchimedeDlg::Init()
87 {
88   /* init variables */
89   myEditCurrentArgument = GroupPoints->LineEdit1;
90
91   myWeight = 100.0;
92   myWaterDensity = 1.0;
93   myMeshingDeflection = 0.01;
94   myOkIO = false;
95
96   /* Get setting of step value from file configuration */
97   QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
98   step = St.toDouble();
99
100
101   double SpecificStep1 = 0.1;
102   double SpecificStep2 = 0.01;
103   /* min, max, step and decimals for spin boxes & initial values */
104   GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 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(myWeight);
109   GroupPoints->SpinBox_DY->SetValue(myWaterDensity);
110   GroupPoints->SpinBox_DZ->SetValue(myMeshingDeflection);
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->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
117   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
118
119   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
120   connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
121   connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
122
123   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
124   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
125   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, SLOT(SetStep(double)));
126   
127   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
128
129   /* displays Dialog */
130   GroupPoints->show();
131   this->show();
132
133   return;
134 }
135
136
137 //=================================================================================
138 // function : ClickOnOk()
139 // purpose  :
140 //=================================================================================
141 void OperationGUI_ArchimedeDlg::ClickOnOk()
142 {
143   this->ClickOnApply();
144   ClickOnCancel();
145   return;
146 }
147
148
149 //=================================================================================
150 // function : ClickOnApply()
151 // purpose  :
152 //=================================================================================
153 void OperationGUI_ArchimedeDlg::ClickOnApply()
154 {
155   QAD_Application::getDesktop()->putInfo(tr(""));
156   if(myOkIO)
157     myOperationGUI->Archimede(myIO, myWeight, myWaterDensity, myMeshingDeflection);
158   return;
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   QString aString = ""; /* name of selection */
170
171   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
172   if (nbSel != 1) {
173     myOkIO = false;
174     return;
175   }
176   else {
177     myEditCurrentArgument->setText(aString);
178     myIO = mySelection->firstIObject();
179     myOkIO = true;
180   }
181   return; 
182 }
183
184
185 //=================================================================================
186 // function : LineEditReturnPressed()
187 // purpose  :
188 //=================================================================================
189 void OperationGUI_ArchimedeDlg::LineEditReturnPressed()
190 {
191   QLineEdit* send = (QLineEdit*)sender();
192   if(send == GroupPoints->LineEdit1)
193     myEditCurrentArgument = GroupPoints->LineEdit1;
194   else
195     return;
196
197   GEOMBase_Skeleton::LineEditReturnPressed();
198   return;
199 }
200
201
202 //=================================================================================
203 // function : SetEditCurrentArgument()
204 // purpose  :
205 //=================================================================================
206 void OperationGUI_ArchimedeDlg::SetEditCurrentArgument()
207 {    
208   QPushButton* send = (QPushButton*)sender();
209
210   if(send == GroupPoints->PushButton1) {
211     GroupPoints->LineEdit1->setFocus();
212     myEditCurrentArgument = GroupPoints->LineEdit1;
213     this->SelectionIntoArgument();
214   }
215
216   return;
217 }
218
219
220 //=================================================================================
221 // function : ActivateThisDialog()
222 // purpose  :
223 //=================================================================================
224 void OperationGUI_ArchimedeDlg::ActivateThisDialog()
225 {
226   GEOMBase_Skeleton::ActivateThisDialog();
227   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
228   return;
229 }
230
231
232 //=================================================================================
233 // function : enterEvent()
234 // purpose  :
235 //=================================================================================
236 void OperationGUI_ArchimedeDlg::enterEvent(QEvent* e)
237 {
238   if(GroupConstructors->isEnabled())
239     return;
240   this->ActivateThisDialog();
241   return;
242 }
243
244
245 //=================================================================================
246 // function : ValueChangedInSpinBox()
247 // purpose  :
248 //=================================================================================
249 void OperationGUI_ArchimedeDlg::ValueChangedInSpinBox(double newValue)
250 {
251   QObject* send = (QObject*)sender();
252
253   if(send == GroupPoints->SpinBox_DX)
254     myWeight = newValue;
255   else if(send == GroupPoints->SpinBox_DY)
256     myWaterDensity = newValue;
257   else if(send == GroupPoints->SpinBox_DZ)
258     myMeshingDeflection = newValue;
259
260   return;
261 }