1 // SMESH StdMeshersGUI : GUI for standard meshers
3 // Copyright (C) 2003 CEA
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.
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.
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
19 // See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
23 // File : StdMeshersGUI_Parameters.cxx
27 #include "StdMeshersGUI_Parameters.h"
33 //=======================================================================
34 //function : HasParameters
36 //=======================================================================
38 bool StdMeshersGUI_Parameters::HasParameters (const QString& hypType)
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));
49 //=======================================================================
50 //function : GetParameters
52 //=======================================================================
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))
57 void StdMeshersGUI_Parameters::GetParameters (const QString& hypType,
58 list<SMESHGUI_aParameterPtr> & paramList )
62 if (hypType.compare("LocalLength") == 0)
64 paramList.push_back( DOUBLE_PARAM (1.0,
65 QObject::tr("SMESH_LOCAL_LENGTH_PARAM"),
66 0.001, 999.999, 1.0, 3));
68 else if (hypType.compare("NumberOfSegments") == 0)
70 paramList.push_back ( INT_PARAM (3,
71 QObject::tr("SMESH_NB_SEGMENTS_PARAM"),
74 else if (hypType.compare("Arithmetic1D") == 0)
76 paramList.push_back( DOUBLE_PARAM ( 1.0,
77 QObject::tr("SMESH_START_LENGTH_PARAM"),
79 paramList.push_back( DOUBLE_PARAM ( 10.0,
80 QObject::tr("SMESH_END_LENGTH_PARAM"),
83 else if (hypType.compare("MaxElementArea") == 0)
85 paramList.push_back( DOUBLE_PARAM (1.0,
86 QObject::tr("SMESH_MAX_ELEMENT_AREA_PARAM"),
87 0.001, 999999.999, 1.0, 3));
89 else if (hypType.compare("MaxElementVolume") == 0)
91 paramList.push_back( DOUBLE_PARAM ( 1.0,
92 QObject::tr("SMESH_MAX_ELEMENT_VOLUME_PARAM"),
93 0.001, 999999.999, 1.0, 3));
95 else if (hypType.compare("StartEndLength") == 0)
97 paramList.push_back( DOUBLE_PARAM ( 1.0,
98 QObject::tr("SMESH_START_LENGTH_PARAM"),
100 paramList.push_back( DOUBLE_PARAM ( 10.0,
101 QObject::tr("SMESH_END_LENGTH_PARAM"),
104 else if (hypType.compare("Deflection1D") == 0)
106 paramList.push_back( DOUBLE_PARAM ( 1.0,
107 QObject::tr("SMESH_DEFLECTION1D_PARAM"),
112 //=======================================================================
113 //function : GetParameters
115 //=======================================================================
117 void StdMeshersGUI_Parameters::GetParameters (SMESH::SMESH_Hypothesis_ptr theHyp,
118 list<SMESHGUI_aParameterPtr> & paramList )
122 if (theHyp->_is_nil()) return;
124 QString hypType = theHyp->GetName();
126 if (hypType.compare("LocalLength") == 0)
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));
135 else if (hypType.compare("NumberOfSegments") == 0)
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"),
144 else if (hypType.compare("Arithmetic1D") == 0)
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"),
153 paramList.push_back( DOUBLE_PARAM ( endLength,
154 QObject::tr("SMESH_END_LENGTH_PARAM"),
157 else if (hypType.compare("MaxElementArea") == 0)
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));
166 else if (hypType.compare("MaxElementVolume") == 0)
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));
175 else if (hypType.compare("StartEndLength") == 0)
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"),
184 paramList.push_back( DOUBLE_PARAM ( endLength,
185 QObject::tr("SMESH_END_LENGTH_PARAM"),
188 else if (hypType.compare("Deflection1D") == 0)
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"),
199 //=======================================================================
200 //function : GetParameters
202 //=======================================================================
203 void StdMeshersGUI_Parameters::GetParameters (SMESH::SMESH_Hypothesis_ptr hyp,
204 list<SMESHGUI_aParameterPtr> & paramList,
208 list<SMESHGUI_aParameterPtr>::iterator paramIt = paramList.begin();
209 for ( ; paramIt != paramList.end(); paramIt++) {
212 if (params.compare("")) params += " ; ";
213 if ((*paramIt)->GetType() == SMESHGUI_aParameter::INT) {
214 (*paramIt)->GetNewInt(aIntValue);
215 params += QString::number(aIntValue);;
218 (*paramIt)->GetNewDouble(aDoubleValue);
219 params += QString::number(aDoubleValue);
224 //=======================================================================
225 //function : SetParameters
227 //=======================================================================
229 bool StdMeshersGUI_Parameters::SetParameters(SMESH::SMESH_Hypothesis_ptr theHyp,
230 const list<SMESHGUI_aParameterPtr> & paramList )
232 if (theHyp->_is_nil() || paramList.empty()) return false;
234 bool modified = false;
236 QString hypType = theHyp->GetName();
238 if (hypType.compare("LocalLength") == 0)
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);
246 else if (hypType.compare("NumberOfSegments") == 0)
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);
254 else if (hypType.compare("Arithmetic1D") == 0)
256 if ( paramList.size() != 2 )
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 );
267 else if (hypType.compare("MaxElementArea") == 0)
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);
275 else if (hypType.compare("MaxElementVolume") == 0)
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);
283 else if (hypType.compare("StartEndLength") == 0)
285 if ( paramList.size() != 2 )
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 );
296 else if (hypType.compare("Deflection1D") == 0)
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 );