]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_ArchimedeDlg.cxx
Salome HOME
SALOME PAL V1_4_1
[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   buttonApply->setFocus();
156   QAD_Application::getDesktop()->putInfo(tr(""));
157   if(myOkIO)
158     myOperationGUI->Archimede(myIO, myWeight, myWaterDensity, myMeshingDeflection);
159   return;
160 }
161
162
163 //=================================================================================
164 // function : SelectionIntoArgument()
165 // purpose  : Called when selection as changed or other case
166 //=================================================================================
167 void OperationGUI_ArchimedeDlg::SelectionIntoArgument()
168 {
169   myEditCurrentArgument->setText("");
170   QString aString = ""; /* name of selection */
171
172   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
173   if (nbSel != 1) {
174     myOkIO = false;
175     return;
176   }
177   else {
178     myEditCurrentArgument->setText(aString);
179     myIO = mySelection->firstIObject();
180     myOkIO = true;
181   }
182   return; 
183 }
184
185
186 //=================================================================================
187 // function : LineEditReturnPressed()
188 // purpose  :
189 //=================================================================================
190 void OperationGUI_ArchimedeDlg::LineEditReturnPressed()
191 {
192   QLineEdit* send = (QLineEdit*)sender();
193   if(send == GroupPoints->LineEdit1)
194     myEditCurrentArgument = GroupPoints->LineEdit1;
195   else
196     return;
197
198   GEOMBase_Skeleton::LineEditReturnPressed();
199   return;
200 }
201
202
203 //=================================================================================
204 // function : SetEditCurrentArgument()
205 // purpose  :
206 //=================================================================================
207 void OperationGUI_ArchimedeDlg::SetEditCurrentArgument()
208 {    
209   QPushButton* send = (QPushButton*)sender();
210
211   if(send == GroupPoints->PushButton1) {
212     GroupPoints->LineEdit1->setFocus();
213     myEditCurrentArgument = GroupPoints->LineEdit1;
214     this->SelectionIntoArgument();
215   }
216
217   return;
218 }
219
220
221 //=================================================================================
222 // function : ActivateThisDialog()
223 // purpose  :
224 //=================================================================================
225 void OperationGUI_ArchimedeDlg::ActivateThisDialog()
226 {
227   GEOMBase_Skeleton::ActivateThisDialog();
228   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
229   return;
230 }
231
232
233 //=================================================================================
234 // function : enterEvent()
235 // purpose  :
236 //=================================================================================
237 void OperationGUI_ArchimedeDlg::enterEvent(QEvent* e)
238 {
239   if(GroupConstructors->isEnabled())
240     return;
241   this->ActivateThisDialog();
242   return;
243 }
244
245
246 //=================================================================================
247 // function : ValueChangedInSpinBox()
248 // purpose  :
249 //=================================================================================
250 void OperationGUI_ArchimedeDlg::ValueChangedInSpinBox(double newValue)
251 {
252   QObject* send = (QObject*)sender();
253
254   if(send == GroupPoints->SpinBox_DX)
255     myWeight = newValue;
256   else if(send == GroupPoints->SpinBox_DY)
257     myWaterDensity = newValue;
258   else if(send == GroupPoints->SpinBox_DZ)
259     myMeshingDeflection = newValue;
260
261   return;
262 }