Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_Parameters.cxx
1 //  SMESH StdMeshersGUI : GUI for standard meshers
2 //
3 //  Copyright (C) 2003  CEA
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 //  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
20 //
21 //
22 //
23 //  File   : StdMeshersGUI_Parameters.cxx
24 //  Module : SMESH
25 //  $Header$
26
27 #include "StdMeshersGUI_Parameters.h"
28
29 #include <qobject.h>
30
31 using namespace std;
32
33 //=======================================================================
34 //function : HasParameters
35 //purpose  : 
36 //=======================================================================
37
38 bool StdMeshersGUI_Parameters::HasParameters (const QString& hypType)
39 {
40   return ((hypType.compare("LocalLength") == 0) ||
41           (hypType.compare("NumberOfSegments") == 0) ||
42           (hypType.compare("MaxElementArea") == 0) ||
43           (hypType.compare("MaxElementVolume") == 0) ||
44           (hypType.compare("StartEndLength") == 0) ||
45           (hypType.compare("Deflection1D") == 0) ||
46           (hypType.compare("Arithmetic1D") == 0));
47 }
48
49 //=======================================================================
50 //function : GetParameters
51 //purpose  : 
52 //=======================================================================
53
54 #define DOUBLE_PARAM(v,l,b,t,s,d) SMESHGUI_aParameterPtr(new SMESHGUI_doubleParameter(v,l,b,t,s,d))
55 #define INT_PARAM(v,l,b,t) SMESHGUI_aParameterPtr(new SMESHGUI_intParameter(v,l,b,t))
56
57 void StdMeshersGUI_Parameters::GetParameters (const QString&                 hypType,
58                                               list<SMESHGUI_aParameterPtr> & paramList )
59 {
60   paramList.clear();
61
62   if (hypType.compare("LocalLength") == 0)
63   {
64     paramList.push_back( DOUBLE_PARAM (1.0,
65                                        QObject::tr("SMESH_LOCAL_LENGTH_PARAM"),
66                                        0.001, 999.999, 1.0, 3));
67   }
68   else if (hypType.compare("NumberOfSegments") == 0)
69   {
70     paramList.push_back ( INT_PARAM (3,
71                                      QObject::tr("SMESH_NB_SEGMENTS_PARAM"),
72                                      1, 9999 ));
73   }
74   else if (hypType.compare("Arithmetic1D") == 0)
75   {
76     paramList.push_back( DOUBLE_PARAM ( 1.0,
77                                       QObject::tr("SMESH_START_LENGTH_PARAM"), 
78                                       1.0E-5, 1E6, 1, 6));
79     paramList.push_back( DOUBLE_PARAM ( 10.0,
80                                        QObject::tr("SMESH_END_LENGTH_PARAM"),
81                                        1.0E-5, 1E6, 1, 6));
82   }
83   else if (hypType.compare("MaxElementArea") == 0)
84   {
85     paramList.push_back( DOUBLE_PARAM (1.0,
86                                        QObject::tr("SMESH_MAX_ELEMENT_AREA_PARAM"), 
87                                        0.001, 999999.999, 1.0, 3));
88   }
89   else if (hypType.compare("MaxElementVolume") == 0)
90   {
91     paramList.push_back( DOUBLE_PARAM ( 1.0,
92                                        QObject::tr("SMESH_MAX_ELEMENT_VOLUME_PARAM"), 
93                                        0.001, 999999.999, 1.0, 3));
94   }
95   else if (hypType.compare("StartEndLength") == 0)
96   {
97     paramList.push_back( DOUBLE_PARAM ( 1.0,
98                                       QObject::tr("SMESH_START_LENGTH_PARAM"), 
99                                       1.0E-5, 1E6, 1, 6));
100     paramList.push_back( DOUBLE_PARAM ( 10.0,
101                                        QObject::tr("SMESH_END_LENGTH_PARAM"),
102                                        1.0E-5, 1E6, 1, 6));
103   }
104   else if (hypType.compare("Deflection1D") == 0)
105   {
106     paramList.push_back( DOUBLE_PARAM ( 1.0,
107                                        QObject::tr("SMESH_DEFLECTION1D_PARAM"), 
108                                        1.0E-5, 1E6, 1, 6));
109   }
110 }
111   
112 //=======================================================================
113 //function : GetParameters
114 //purpose  : 
115 //=======================================================================
116
117 void StdMeshersGUI_Parameters::GetParameters (SMESH::SMESH_Hypothesis_ptr    theHyp,
118                                               list<SMESHGUI_aParameterPtr> & paramList )
119 {
120   paramList.clear();
121
122   if (theHyp->_is_nil()) return;
123
124   QString hypType = theHyp->GetName();
125
126   if (hypType.compare("LocalLength") == 0)
127   {
128     StdMeshers::StdMeshers_LocalLength_var LL =
129       StdMeshers::StdMeshers_LocalLength::_narrow(theHyp);
130     double length = LL->GetLength();
131     paramList.push_back( DOUBLE_PARAM (length,
132                                        QObject::tr("SMESH_LOCAL_LENGTH_PARAM"),
133                                        0.001, 999.999, 1.0, 3));
134   }
135   else if (hypType.compare("NumberOfSegments") == 0)
136   {
137     StdMeshers::StdMeshers_NumberOfSegments_var NOS =
138       StdMeshers::StdMeshers_NumberOfSegments::_narrow(theHyp);
139     int NbSeg = NOS->GetNumberOfSegments() ;
140     paramList.push_back ( INT_PARAM (NbSeg,
141                                      QObject::tr("SMESH_NB_SEGMENTS_PARAM"),
142                                      1, 9999 ));
143   }
144   else if (hypType.compare("Arithmetic1D") == 0)
145   {
146     StdMeshers::StdMeshers_Arithmetic1D_var hyp =
147       StdMeshers::StdMeshers_Arithmetic1D::_narrow(theHyp);
148     double begLength = hyp->GetLength( true ) ;
149     double endLength = hyp->GetLength( false ) ;
150     paramList.push_back( DOUBLE_PARAM ( begLength,
151                                       QObject::tr("SMESH_START_LENGTH_PARAM"), 
152                                       1.0E-5, 1E6, 1, 6));
153     paramList.push_back( DOUBLE_PARAM ( endLength,
154                                       QObject::tr("SMESH_END_LENGTH_PARAM"),
155                                       1.0E-5, 1E6, 1, 6));
156   }
157   else if (hypType.compare("MaxElementArea") == 0)
158   {
159     StdMeshers::StdMeshers_MaxElementArea_var MEA =
160       StdMeshers::StdMeshers_MaxElementArea::_narrow(theHyp);
161     double MaxArea = MEA->GetMaxElementArea();
162     paramList.push_back( DOUBLE_PARAM (MaxArea,
163                                        QObject::tr("SMESH_MAX_ELEMENT_AREA_PARAM"), 
164                                        0.001, 999999.999, 1.0, 3));
165   }
166   else if (hypType.compare("MaxElementVolume") == 0)
167   {
168     StdMeshers::StdMeshers_MaxElementVolume_var MEV =
169       StdMeshers::StdMeshers_MaxElementVolume::_narrow(theHyp);
170     double MaxVolume = MEV->GetMaxElementVolume() ;
171     paramList.push_back( DOUBLE_PARAM ( MaxVolume,
172                                        QObject::tr("SMESH_MAX_ELEMENT_VOLUME_PARAM"), 
173                                        0.001, 999999.999, 1.0, 3));
174   }
175   else if (hypType.compare("StartEndLength") == 0)
176   {
177     StdMeshers::StdMeshers_StartEndLength_var hyp =
178       StdMeshers::StdMeshers_StartEndLength::_narrow(theHyp);
179     double begLength = hyp->GetLength( true ) ;
180     double endLength = hyp->GetLength( false ) ;
181     paramList.push_back( DOUBLE_PARAM ( begLength,
182                                       QObject::tr("SMESH_START_LENGTH_PARAM"), 
183                                       1.0E-5, 1E6, 1, 6));
184     paramList.push_back( DOUBLE_PARAM ( endLength,
185                                       QObject::tr("SMESH_END_LENGTH_PARAM"),
186                                       1.0E-5, 1E6, 1, 6));
187   }
188   else if (hypType.compare("Deflection1D") == 0)
189   {
190     StdMeshers::StdMeshers_Deflection1D_var hyp =
191       StdMeshers::StdMeshers_Deflection1D::_narrow(theHyp);
192     double value = hyp->GetDeflection() ;
193     paramList.push_back( DOUBLE_PARAM ( value,
194                                       QObject::tr("SMESH_DEFLECTION1D_PARAM"), 
195                                       1.0E-5, 1E6, 1, 6));
196   }  
197 }
198
199 //=======================================================================
200 //function : GetParameters
201 //purpose  : 
202 //=======================================================================  
203 void StdMeshersGUI_Parameters::GetParameters (SMESH::SMESH_Hypothesis_ptr         hyp,
204                                               list<SMESHGUI_aParameterPtr> &      paramList,
205                                               QString&                            params)
206 {
207   params = "";
208   list<SMESHGUI_aParameterPtr>::iterator paramIt = paramList.begin();
209   for ( ; paramIt != paramList.end(); paramIt++) {
210     int aIntValue;
211     double aDoubleValue;
212     if (params.compare("")) params += " ; ";
213     if ((*paramIt)->GetType() == SMESHGUI_aParameter::INT) {
214       (*paramIt)->GetNewInt(aIntValue);
215       params += QString::number(aIntValue);;
216     }
217     else {
218       (*paramIt)->GetNewDouble(aDoubleValue);
219         params += QString::number(aDoubleValue);
220     }
221   }
222 }
223
224 //=======================================================================
225 //function : SetParameters
226 //purpose  : 
227 //=======================================================================
228
229 bool StdMeshersGUI_Parameters::SetParameters(SMESH::SMESH_Hypothesis_ptr          theHyp,
230                                              const list<SMESHGUI_aParameterPtr> & paramList )
231 {
232   if (theHyp->_is_nil() || paramList.empty()) return false;
233
234   bool modified = false;
235
236   QString hypType = theHyp->GetName();
237
238   if (hypType.compare("LocalLength") == 0)
239   {
240     StdMeshers::StdMeshers_LocalLength_var LL =
241       StdMeshers::StdMeshers_LocalLength::_narrow(theHyp);
242     double length = LL->GetLength();
243     modified = paramList.front()->GetNewDouble( length );
244     LL->SetLength(length);
245   }
246   else if (hypType.compare("NumberOfSegments") == 0)
247   {
248     StdMeshers::StdMeshers_NumberOfSegments_var NOS =
249       StdMeshers::StdMeshers_NumberOfSegments::_narrow(theHyp);
250     int NbSeg = NOS->GetNumberOfSegments();
251     modified = paramList.front()->GetNewInt( NbSeg );
252     NOS->SetNumberOfSegments(NbSeg);
253   }
254   else if (hypType.compare("Arithmetic1D") == 0)
255   {
256     if ( paramList.size() != 2 )
257       return false;
258     StdMeshers::StdMeshers_Arithmetic1D_var hyp =
259       StdMeshers::StdMeshers_Arithmetic1D::_narrow(theHyp);
260     double begLength = hyp->GetLength( true ) ;
261     double endLength = hyp->GetLength( false ) ;
262     modified = paramList.front()->GetNewDouble( begLength );
263     modified = paramList.back()->GetNewDouble( endLength ) || modified;
264     hyp->SetLength( begLength, true );
265     hyp->SetLength( endLength, false );
266   }
267   else if (hypType.compare("MaxElementArea") == 0)
268   {
269     StdMeshers::StdMeshers_MaxElementArea_var MEA =
270       StdMeshers::StdMeshers_MaxElementArea::_narrow(theHyp);
271     double MaxArea = MEA->GetMaxElementArea();
272     modified = paramList.front()->GetNewDouble( MaxArea );
273     MEA->SetMaxElementArea(MaxArea);
274   }
275   else if (hypType.compare("MaxElementVolume") == 0)
276   {
277     StdMeshers::StdMeshers_MaxElementVolume_var MEV =
278       StdMeshers::StdMeshers_MaxElementVolume::_narrow(theHyp);
279     double MaxVolume = MEV->GetMaxElementVolume() ;
280     modified = paramList.front()->GetNewDouble( MaxVolume );
281     MEV->SetMaxElementVolume(MaxVolume);
282   }
283   else if (hypType.compare("StartEndLength") == 0)
284   {
285     if ( paramList.size() != 2 )
286       return false;
287     StdMeshers::StdMeshers_StartEndLength_var hyp =
288       StdMeshers::StdMeshers_StartEndLength::_narrow(theHyp);
289     double begLength = hyp->GetLength( true ) ;
290     double endLength = hyp->GetLength( false ) ;
291     modified = paramList.front()->GetNewDouble( begLength );
292     modified = paramList.back()->GetNewDouble( endLength ) || modified;
293     hyp->SetLength( begLength, true );
294     hyp->SetLength( endLength, false );
295   }
296   else if (hypType.compare("Deflection1D") == 0)
297   {
298     StdMeshers::StdMeshers_Deflection1D_var hyp =
299       StdMeshers::StdMeshers_Deflection1D::_narrow(theHyp);
300     double value = hyp->GetDeflection() ;
301     modified = paramList.front()->GetNewDouble( value );
302     hyp->SetDeflection( value );
303   }
304   return modified ;
305 }
306