1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : GHS3DPRLPluginGUI_HypothesisCreator.cxx
22 // Author : Christian VAN WAMBEKE (CEA) (from Hexotic plugin Lioka RAZAFINDRAZAKA)
25 #include "GHS3DPRLPluginGUI_HypothesisCreator.h"
27 #include <SMESHGUI_Utils.h>
28 #include <SMESHGUI_HypothesesUtils.h>
29 #include <SMESH_AdvOptionsWdg.h>
31 #include CORBA_SERVER_HEADER(GHS3DPRLPlugin_Algorithm)
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Tools.h>
36 #include <QtxIntSpinBox.h>
37 #include <QtxDoubleSpinBox.h>
41 #include <QGridLayout>
46 #include <QVBoxLayout>
48 GHS3DPRLPluginGUI_HypothesisCreator::GHS3DPRLPluginGUI_HypothesisCreator( const QString& theHypType )
49 : SMESHGUI_GenericHypothesisCreator( theHypType ),
52 //printf("Hypo creator GHS3DPRLPlugin !!!!!!!!!!!!!!!!!!!!!!!!!! RNV");
55 GHS3DPRLPluginGUI_HypothesisCreator::~GHS3DPRLPluginGUI_HypothesisCreator()
59 bool GHS3DPRLPluginGUI_HypothesisCreator::checkParams() const
61 GHS3DPRLHypothesisData data_old, data_new;
62 readParamsFromHypo( data_old );
63 readParamsFromWidgets( data_new );
64 bool res = storeParamsToHypo( data_new );
65 storeParamsToHypo( data_old );
69 QFrame* GHS3DPRLPluginGUI_HypothesisCreator::buildFrame()
71 QFrame* fr = new QFrame( 0 );
72 QVBoxLayout* lay = new QVBoxLayout( fr );
77 QTabWidget* tab = new QTabWidget( fr );
78 tab->setTabShape( QTabWidget::Rounded );
79 tab->setTabPosition( QTabWidget::North );
80 lay->addWidget( tab );
83 QWidget* GroupC1 = new QWidget();
84 lay->addWidget( GroupC1 );
86 QGridLayout* l = new QGridLayout( GroupC1 );
93 QLabel* aNameLab = new QLabel( tr( "SMESH_NAME" ), GroupC1 );
94 aNameLab->setWhatsThis( tr( "GHS3DPRL_WhatsThis_Name" ) );
95 l->addWidget( aNameLab, row, 0, 1, 1 );
96 myName = new QLineEdit( GroupC1 );
97 l->addWidget( myName, row++, 1, 1, 1 );
100 //GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis_var h =
101 //GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis::_narrow( initParamsHypothesis() );
103 QLabel* aMEDNameText = new QLabel( tr( "GHS3DPRL_MEDName" ), GroupC1 );
104 aMEDNameText->setWhatsThis( tr( "GHS3DPRL_WhatsThis_MEDName" ) );
105 l->addWidget( aMEDNameText, row, 0, 1, 1 );
106 myMEDName = new QLineEdit( GroupC1 );
107 l->addWidget( myMEDName, row++, 1, 1, 1 );
109 QLabel* aNbPartText = new QLabel( tr( "GHS3DPRL_NbPart" ), GroupC1 );
110 aNbPartText->setWhatsThis( tr( "GHS3DPRL_WhatsThis_NbPart" ) );
111 l->addWidget( aNbPartText, row, 0, 1, 1 );
112 myNbPart = new QtxIntSpinBox( GroupC1 );
113 l->addWidget( myNbPart, row++, 1, 1, 1 );
114 myNbPart->setMinimum( 1 );
115 myNbPart->setMaximum( 256 );
116 myNbPart->setSingleStep( 1 );
118 myKeepFiles = new QCheckBox( tr( "GHS3DPRL_KeepFiles" ), GroupC1 );
119 myKeepFiles->setWhatsThis( tr( "GHS3DPRL_WhatsThis_KeepFiles" ) );
120 l->addWidget( myKeepFiles, row++, 0, 1, 2 );
122 myBackground = new QCheckBox( tr( "GHS3DPRL_Background" ), GroupC1 );
123 myBackground->setWhatsThis( tr( "GHS3DPRL_WhatsThis_Background" ) );
124 l->addWidget( myBackground, row++, 0, 1, 2 );
126 myMultithread = new QCheckBox( tr( "GHS3DPRL_Multithread" ), GroupC1 );
127 myMultithread->setWhatsThis( tr( "GHS3DPRL_WhatsThis_Multithread" ) );
128 l->addWidget( myMultithread, row++, 0, 1, 2 );
130 //myToMeshHoles = new QCheckBox( tr( "GHS3DPRL_ToMeshHoles" ), GroupC1 );
131 //myToMeshHoles->setWhatsThis( tr( "GHS3DPRL_WhatsThis_ToMeshHoles" ) );
132 //l->addWidget( myToMeshHoles, row++, 0, 1, 2 );
134 //myToMergeSubdomains = new QCheckBox( tr( "GHS3DPRL_ToMergeSubdomains" ), GroupC1 );
135 //myToMergeSubdomains->setWhatsThis( tr( "GHS3DPRL_WhatsThis_ToMergeSubdomains" ) );
136 //l->addWidget( myToMergeSubdomains, row++, 0, 1, 2 );
138 QLabel* aGradationText = new QLabel( tr( "GHS3DPRL_Gradation" ), GroupC1 );
139 aGradationText->setWhatsThis( tr( "GHS3DPRL_WhatsThis_Gradation" ) );
140 l->addWidget( aGradationText, row, 0, 1, 1 );
141 myGradation = new QtxDoubleSpinBox( GroupC1 );
142 l->addWidget( myGradation, row++, 1, 1, 1 );
143 myGradation->setMinimum( 0 );
144 myGradation->setMaximum( 3 );
145 myGradation->setSingleStep( 0.01 );
147 QLabel* aMinSizeText = new QLabel( tr( "GHS3DPRL_MinSize" ), GroupC1 );
148 aMinSizeText->setWhatsThis( tr( "GHS3DPRL_WhatsThis_MinSize" ) );
149 l->addWidget( aMinSizeText, row, 0, 1, 1 );
150 myMinSize = new QtxDoubleSpinBox( GroupC1 );
151 l->addWidget( myMinSize, row++, 1, 1, 1 );
152 myMinSize->setMinimum( 0 );
153 //myMinSize->setMaximum( 999999 );
154 //myMinSize->setSingleStep( 1 );
156 QLabel* aMaxSizeText = new QLabel( tr( "GHS3DPRL_MaxSize" ), GroupC1 );
157 aMaxSizeText->setWhatsThis( tr( "GHS3DPRL_WhatsThis_MaxSize" ) );
158 l->addWidget( aMaxSizeText, row, 0, 1, 1 );
159 myMaxSize = new QtxDoubleSpinBox( GroupC1 );
160 l->addWidget( myMaxSize, row++, 1, 1, 1 );
161 myMaxSize->setMinimum( 0 );
162 //myMaxSize->setMaximum( 999999 );
163 //myMaxSize->setSingleStep( 1 );
167 myAdvTable = new SMESH_AdvOptionsWdg( fr );
170 tab->insertTab( 0, GroupC1, tr( "SMESH_ARGUMENTS" ));
171 tab->insertTab( 1, myAdvTable, tr( "SMESH_ADVANCED" ));
176 void GHS3DPRLPluginGUI_HypothesisCreator::retrieveParams() const
178 GHS3DPRLHypothesisData data;
179 readParamsFromHypo( data );
181 if ( myName ) myName->setText( data.myName );
182 myMEDName->setText( data.myMEDName );
183 myNbPart->setValue( data.myNbPart );
184 myKeepFiles->setChecked( data.myKeepFiles );
185 myBackground->setChecked( data.myBackground );
186 myMultithread->setChecked( data.myMultithread );
187 //myToMeshHoles->setChecked( data.myToMeshHoles );
188 //myToMergeSubdomains->setChecked( data.myToMergeSubdomains );
189 myGradation->setValue( data.myGradation );
190 myMinSize->setValue( data.myMinSize );
191 myMaxSize->setValue( data.myMaxSize );
192 myAdvTable->SetCustomOptions( data.myAdvOptions );
195 QString GHS3DPRLPluginGUI_HypothesisCreator::storeParams() const
197 GHS3DPRLHypothesisData data;
198 readParamsFromWidgets( data );
199 storeParamsToHypo( data );
202 valStr += tr( "GHS3DPRL_MEDName" ) + " = " + data.myMEDName + "; ";
203 valStr += tr( "GHS3DPRL_NbPart" ) + " = " + QString::number( data.myNbPart ) + "; ";
204 //valStr += tr( "GHS3DPRL_ToMeshHoles" ) + " = " + QString::number( data.myToMeshHoles ) + "; ";
205 //valStr += tr( "GHS3DPRL_ToMergeSubdomains" ) + " = " + QString::number( data.myToMergeSubdomains ) + "; ";
206 valStr += tr( "GHS3DPRL_Gradation" ) + " = " + QString::number( data.myGradation ) + "; ";
207 valStr += tr( "GHS3DPRL_MinSize" ) + " = " + QString::number( data.myMinSize ) + "; ";
208 valStr += tr( "GHS3DPRL_MaxSize" ) + " = " + QString::number( data.myMaxSize ) + "; ";
209 valStr += tr( "GHS3DPRL_KeepFiles" ) + " = " + QString::number( data.myKeepFiles ) + "; ";
210 valStr += tr( "GHS3DPRL_Background" ) + " = " + QString::number( data.myBackground ) + "; ";
211 valStr += tr( "GHS3DPRL_Multithread" ) + " = " + QString::number( data.myMultithread ) + "; ";
216 bool GHS3DPRLPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DPRLHypothesisData& h_data ) const
218 GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis_var h =
219 GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis::_narrow( initParamsHypothesis() );
221 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
222 h_data.myName = isCreation() && data ? hypName() : "";
223 h_data.myMEDName = SMESH::toQStr( h->GetMEDName() ); //"DOMAIN\0";
224 h_data.myNbPart = h->GetNbPart();
225 h_data.myKeepFiles = h->GetKeepFiles();
226 h_data.myBackground = h->GetBackground();
227 h_data.myMultithread = h->GetMultithread();
228 h_data.myGradation = h->GetGradation();
229 h_data.myMinSize = h->GetMinSize();
230 h_data.myMaxSize = h->GetMaxSize();
231 h_data.myAdvOptions = SMESH::toQStr( h->GetAdvancedOption() );
236 bool GHS3DPRLPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DPRLHypothesisData& h_data ) const
238 GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis_var h =
239 GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis::_narrow( hypothesis() );
245 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
247 h->SetMEDName ( h_data.myMEDName.toLatin1().constData() );
248 h->SetNbPart ( h_data.myNbPart );
249 h->SetKeepFiles ( h_data.myKeepFiles );
250 h->SetBackground ( h_data.myBackground );
251 h->SetMultithread ( h_data.myMultithread );
252 h->SetGradation ( h_data.myGradation );
253 h->SetMinSize ( h_data.myMinSize );
254 h->SetMaxSize ( h_data.myMaxSize );
255 h->SetAdvancedOption( h_data.myAdvOptions.toLatin1().constData() );
257 catch ( const SALOME::SALOME_Exception& ex )
259 SalomeApp_Tools::QtCatchCorbaException( ex );
265 bool GHS3DPRLPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DPRLHypothesisData& h_data ) const
267 h_data.myName = myName ? myName->text() : "";
268 h_data.myMEDName = myMEDName->text().simplified().replace(' ', '_');
269 h_data.myNbPart = myNbPart->value();
270 h_data.myKeepFiles = myKeepFiles->isChecked();
271 h_data.myBackground = myBackground->isChecked();
272 h_data.myMultithread= myMultithread->isChecked();
273 h_data.myGradation = myGradation->value();
274 h_data.myMinSize = myMinSize->value();
275 h_data.myMaxSize = myMaxSize->value();
276 h_data.myAdvOptions = myAdvTable->GetCustomOptions();
280 QString GHS3DPRLPluginGUI_HypothesisCreator::caption() const
282 return myIs3D ? tr( "GHS3DPRL_3D_TITLE" ) : tr( "GHS3DPRL_3D_TITLE" ); // ??? 3D/2D ???
285 QPixmap GHS3DPRLPluginGUI_HypothesisCreator::icon() const
287 QString hypIconName = myIs3D ? tr( "ICON_DLG_GHS3DPRL_PARAMETERS" ) : tr( "ICON_DLG_GHS3DPRL_PARAMETERS" ); // ??? 3D/2D ???
288 return SUIT_Session::session()->resourceMgr()->loadPixmap( "GHS3DPRLPlugin", hypIconName );
291 QString GHS3DPRLPluginGUI_HypothesisCreator::type() const
293 return myIs3D ? tr( "GHS3DPRL_3D_HYPOTHESIS" ): tr( "GHS3DPRL_3D_HYPOTHESIS" ); // ??? 3D/2D ???
296 QString GHS3DPRLPluginGUI_HypothesisCreator::helpPage() const
298 return "ghs3dprl_hypo_page.html";