1 // SMESH StdMeshersGUI : GUI for plugged-in 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_StdHypothesisCreator.cxx
24 // Author : Alexander SOLOVYOV
26 // $Header: /home/server/cvs/SMESH/SMESH_SRC/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx
28 #include "StdMeshersGUI_StdHypothesisCreator.h"
31 #include <SMESHGUI_SpinBox.h>
32 #include <SMESHGUI_HypothesesUtils.h>
33 #include <SMESHGUI_Utils.h>
35 #include <SUIT_ResourceMgr.h>
37 #include <SALOMEconfig.h>
38 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
39 #include CORBA_SERVER_HEADER(SMESH_Mesh)
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;
51 StdMeshersGUI_StdHypothesisCreator::StdMeshersGUI_StdHypothesisCreator( const QString& type )
52 : SMESHGUI_GenericHypothesisCreator( type )
56 StdMeshersGUI_StdHypothesisCreator::~StdMeshersGUI_StdHypothesisCreator()
60 QFrame* StdMeshersGUI_StdHypothesisCreator::buildFrame()
62 return buildStdFrame();
65 bool StdMeshersGUI_StdHypothesisCreator::checkParams() const
70 void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const
72 //here this method must be empty because buildStdParam sets values itself
75 void StdMeshersGUI_StdHypothesisCreator::storeParams() const
77 ListOfStdParams params;
78 bool res = getStdParamFromDlg( params );
81 SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().latin1() );
82 params.remove( params.begin() );
85 if( res && !params.isEmpty() )
87 if( hypType()=="LocalLength" )
89 StdMeshers::StdMeshers_LocalLength_var h =
90 StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
92 h->SetLength( params[0].myValue.toDouble() );
94 else if( hypType()=="Arithmetic1D" )
96 StdMeshers::StdMeshers_Arithmetic1D_var h =
97 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
99 h->SetLength( params[0].myValue.toDouble(), true );
100 h->SetLength( params[1].myValue.toDouble(), false );
102 else if( hypType()=="MaxElementArea" )
104 StdMeshers::StdMeshers_MaxElementArea_var h =
105 StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
107 h->SetMaxElementArea( params[0].myValue.toDouble() );
109 else if( hypType()=="MaxElementVolume" )
111 StdMeshers::StdMeshers_MaxElementVolume_var h =
112 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
114 h->SetMaxElementVolume( params[0].myValue.toDouble() );
116 else if( hypType()=="StartEndLength" )
118 StdMeshers::StdMeshers_StartEndLength_var h =
119 StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
121 h->SetLength( params[0].myValue.toDouble(), true );
122 h->SetLength( params[1].myValue.toDouble(), false );
124 else if( hypType()=="Deflection1D" )
126 StdMeshers::StdMeshers_Deflection1D_var h =
127 StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
129 h->SetDeflection( params[0].myValue.toDouble() );
134 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
137 SMESHGUI_GenericHypothesisCreator::StdParam item;
142 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
143 item.myName = tr( "SMESH_NAME" );
144 item.myValue = data ? data->Label : QString();
148 if( hypType()=="LocalLength" )
150 StdMeshers::StdMeshers_LocalLength_var h =
151 StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
153 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
154 item.myValue = isCreation() ? 1.0 : h->GetLength();
157 else if( hypType()=="Arithmetic1D" )
159 StdMeshers::StdMeshers_Arithmetic1D_var h =
160 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
162 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
163 item.myValue = isCreation() ? 1.0 : h->GetLength( true );
165 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
166 item.myValue = isCreation() ? 10.0 : h->GetLength( false );
169 else if( hypType()=="MaxElementArea" )
171 StdMeshers::StdMeshers_MaxElementArea_var h =
172 StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
174 item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
175 item.myValue = isCreation() ? 1.0 : h->GetMaxElementArea();
178 else if( hypType()=="MaxElementVolume" )
180 StdMeshers::StdMeshers_MaxElementVolume_var h =
181 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
183 item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
184 item.myValue = isCreation() ? 1.0 : h->GetMaxElementVolume();
187 else if( hypType()=="StartEndLength" )
189 StdMeshers::StdMeshers_StartEndLength_var h =
190 StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
192 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
193 item.myValue = isCreation() ? 1.0 : h->GetLength( true );
195 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
196 item.myValue = isCreation() ? 10.0 : h->GetLength( false );
199 else if( hypType()=="Deflection1D" )
201 StdMeshers::StdMeshers_Deflection1D_var h =
202 StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
204 item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
205 item.myValue = isCreation() ? 1.0 : h->GetDeflection();
213 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget( QWidget* w, const int ) const
215 SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
216 if( hypType()=="LocalLength" && sb )
218 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
220 else if( hypType()=="Arithmetic1D" && sb )
222 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
224 else if( hypType()=="MaxElementArea" && sb )
226 sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
228 else if( hypType()=="MaxElementVolume" && sb )
230 sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
232 else if( hypType()=="StartEndLength" && sb )
234 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
236 else if( hypType()=="Deflection1D" && sb )
238 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
242 QString StdMeshersGUI_StdHypothesisCreator::caption() const
244 return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ) );
247 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
249 QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ) );
250 return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
253 QString StdMeshersGUI_StdHypothesisCreator::type() const
255 return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ) );
258 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
260 static QMap<QString,QString> types;
261 if( types.isEmpty() )
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" );
273 if( types.contains( t ) )