Salome HOME
Join modifications from branch BR_3_1_0deb
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_StdHypothesisCreator.cxx
1 //  SMESH StdMeshersGUI : GUI for plugged-in 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_StdHypothesisCreator.cxx
24 //  Author : Alexander SOLOVYOV
25 //  Module : SMESH
26 //  $Header: /home/server/cvs/SMESH/SMESH_SRC/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx
27
28 #include "StdMeshersGUI_StdHypothesisCreator.h"
29
30 #include <SMESHGUI.h>
31 #include <SMESHGUI_SpinBox.h>
32 #include <SMESHGUI_HypothesesUtils.h>
33 #include <SMESHGUI_Utils.h>
34
35 #include <SUIT_ResourceMgr.h>
36
37 #include <SALOMEconfig.h>
38 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
39 #include CORBA_SERVER_HEADER(SMESH_Mesh)
40
41 #include <qpixmap.h>
42
43
44 const double VALUE_MAX = 1.0e+15, // COORD_MAX
45              VALUE_MAX_2  = VALUE_MAX * VALUE_MAX,
46              VALUE_MAX_3  = VALUE_MAX_2 * VALUE_MAX,
47              VALUE_SMALL = 1.0e-15,
48              VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
49              VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
50
51 StdMeshersGUI_StdHypothesisCreator::StdMeshersGUI_StdHypothesisCreator( const QString& type )
52 : SMESHGUI_GenericHypothesisCreator( type )
53 {
54 }
55
56 StdMeshersGUI_StdHypothesisCreator::~StdMeshersGUI_StdHypothesisCreator()
57 {
58 }
59
60 QFrame* StdMeshersGUI_StdHypothesisCreator::buildFrame()
61 {
62   return buildStdFrame();
63 }
64
65 bool StdMeshersGUI_StdHypothesisCreator::checkParams() const
66 {
67   return true;
68 }
69
70 void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const
71 {
72   //here this method must be empty because buildStdParam sets values itself
73 }
74
75 void StdMeshersGUI_StdHypothesisCreator::storeParams() const
76 {
77   ListOfStdParams params;
78   bool res = getStdParamFromDlg( params );
79   if( isCreation() )
80   {
81     SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().latin1() );
82     params.remove( params.begin() );
83   }
84
85   if( res && !params.isEmpty() )
86   {
87     if( hypType()=="LocalLength" )
88     {
89       StdMeshers::StdMeshers_LocalLength_var h =
90         StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
91
92       h->SetLength( params[0].myValue.toDouble() );
93     }
94     else if( hypType()=="Arithmetic1D" )
95     {
96       StdMeshers::StdMeshers_Arithmetic1D_var h =
97         StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
98
99       h->SetLength( params[0].myValue.toDouble(), true );
100       h->SetLength( params[1].myValue.toDouble(), false );
101     }
102     else if( hypType()=="MaxElementArea" )
103     {
104       StdMeshers::StdMeshers_MaxElementArea_var h =
105         StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
106
107       h->SetMaxElementArea( params[0].myValue.toDouble() );
108     }
109     else if( hypType()=="MaxElementVolume" )
110     {
111       StdMeshers::StdMeshers_MaxElementVolume_var h =
112         StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
113
114       h->SetMaxElementVolume( params[0].myValue.toDouble() );
115     }
116     else if( hypType()=="StartEndLength" )
117     {
118       StdMeshers::StdMeshers_StartEndLength_var h =
119         StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
120
121       h->SetLength( params[0].myValue.toDouble(), true );
122       h->SetLength( params[1].myValue.toDouble(), false );
123     }
124     else if( hypType()=="Deflection1D" )
125     {
126       StdMeshers::StdMeshers_Deflection1D_var h =
127         StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
128
129       h->SetDeflection( params[0].myValue.toDouble() );
130     }
131   }
132 }
133
134 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
135 {
136   bool res = true;
137   SMESHGUI_GenericHypothesisCreator::StdParam item;
138
139   p.clear();
140   if( isCreation() )
141   {
142     HypothesisData* data = SMESH::GetHypothesisData( hypType() );
143     item.myName = tr( "SMESH_NAME" );
144     item.myValue = data ? data->Label : QString();
145     p.append( item );
146   }
147
148   if( hypType()=="LocalLength" )
149   {
150     StdMeshers::StdMeshers_LocalLength_var h =
151       StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
152
153     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
154     item.myValue = isCreation() ? 1.0 : h->GetLength();
155     p.append( item );
156   }
157   else if( hypType()=="Arithmetic1D" )
158   {
159     StdMeshers::StdMeshers_Arithmetic1D_var h =
160       StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
161
162     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
163     item.myValue = isCreation() ? 1.0 : h->GetLength( true );
164     p.append( item );
165     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
166     item.myValue = isCreation() ? 10.0 : h->GetLength( false );
167     p.append( item );
168   }
169   else if( hypType()=="MaxElementArea" )
170   {
171     StdMeshers::StdMeshers_MaxElementArea_var h =
172       StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
173
174     item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
175     item.myValue = isCreation() ? 1.0 : h->GetMaxElementArea();
176     p.append( item );
177   }
178   else if( hypType()=="MaxElementVolume" )
179   {
180     StdMeshers::StdMeshers_MaxElementVolume_var h =
181       StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
182
183     item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
184     item.myValue = isCreation() ? 1.0 : h->GetMaxElementVolume();
185     p.append( item );
186   }
187   else if( hypType()=="StartEndLength" )
188   {
189     StdMeshers::StdMeshers_StartEndLength_var h =
190       StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
191
192     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
193     item.myValue = isCreation() ? 1.0 : h->GetLength( true );
194     p.append( item );
195     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
196     item.myValue = isCreation() ? 10.0 : h->GetLength( false );
197     p.append( item );
198   }
199   else if( hypType()=="Deflection1D" )
200   {
201     StdMeshers::StdMeshers_Deflection1D_var h =
202       StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
203
204     item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
205     item.myValue = isCreation() ? 1.0 : h->GetDeflection();
206     p.append( item );
207   }
208   else
209     res = false;
210   return res;
211 }
212
213 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget( QWidget* w, const int ) const
214 {
215   SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
216   if( hypType()=="LocalLength" &&  sb )
217   {
218     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
219   }
220   else if( hypType()=="Arithmetic1D" && sb )
221   {
222     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
223   }
224   else if( hypType()=="MaxElementArea" && sb )
225   {
226     sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
227   }
228   else if( hypType()=="MaxElementVolume" && sb )
229   {
230     sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
231   }
232   else if( hypType()=="StartEndLength" && sb )
233   {
234     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
235   }
236   else if( hypType()=="Deflection1D" && sb )
237   {
238     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
239   }
240 }
241
242 QString StdMeshersGUI_StdHypothesisCreator::caption() const
243 {
244   return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ) );
245 }
246
247 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
248 {
249   QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ) );
250   return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
251 }
252
253 QString StdMeshersGUI_StdHypothesisCreator::type() const
254 {
255   return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ) );
256 }
257
258 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
259 {
260   static QMap<QString,QString>  types;
261   if( types.isEmpty() )
262   {
263     types.insert( "LocalLength", "LOCAL_LENGTH" );
264     types.insert( "NumberOfSegments", "NB_SEGMENTS" );
265     types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
266     types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
267     types.insert( "StartEndLength", "START_END_LENGTH" );
268     types.insert( "Deflection1D", "DEFLECTION1D" );
269     types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
270   }
271
272   QString res;
273   if( types.contains( t ) )
274     res = types[ t ];
275
276   return res;
277 }