Salome HOME
updated copyright message
[plugins/ghs3dprlplugin.git] / src / gui / GHS3DPRLPluginGUI_HypothesisCreator.cxx
1 // Copyright (C) 2007-2023  CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // ---
21 // File   : GHS3DPRLPluginGUI_HypothesisCreator.cxx
22 // Author : Christian VAN WAMBEKE (CEA) (from Hexotic plugin Lioka RAZAFINDRAZAKA)
23 // ---
24 //
25 #include "GHS3DPRLPluginGUI_HypothesisCreator.h"
26
27 #include <SMESHGUI_Utils.h>
28 #include <SMESHGUI_HypothesesUtils.h>
29 #include <SMESH_AdvOptionsWdg.h>
30
31 #include CORBA_SERVER_HEADER(GHS3DPRLPlugin_Algorithm)
32
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Tools.h>
36 #include <QtxIntSpinBox.h>
37 #include <QtxDoubleSpinBox.h>
38
39 #include <QCheckBox>
40 #include <QFrame>
41 #include <QGridLayout>
42 #include <QGroupBox>
43 #include <QLabel>
44 #include <QLineEdit>
45 #include <QTabWidget>
46 #include <QVBoxLayout>
47
48 GHS3DPRLPluginGUI_HypothesisCreator::GHS3DPRLPluginGUI_HypothesisCreator( const QString& theHypType )
49 : SMESHGUI_GenericHypothesisCreator( theHypType ),
50   myIs3D( true )
51 {
52   //printf("Hypo creator GHS3DPRLPlugin !!!!!!!!!!!!!!!!!!!!!!!!!! RNV");
53 }
54
55 GHS3DPRLPluginGUI_HypothesisCreator::~GHS3DPRLPluginGUI_HypothesisCreator()
56 {
57 }
58
59 bool GHS3DPRLPluginGUI_HypothesisCreator::checkParams() const
60 {
61   GHS3DPRLHypothesisData data_old, data_new;
62   readParamsFromHypo( data_old );
63   readParamsFromWidgets( data_new );
64   bool res = storeParamsToHypo( data_new );
65   storeParamsToHypo( data_old );
66   return res;
67 }
68
69 QFrame* GHS3DPRLPluginGUI_HypothesisCreator::buildFrame()
70 {
71   QFrame* fr = new QFrame( 0 );
72   QVBoxLayout* lay = new QVBoxLayout( fr );
73   lay->setMargin( 5 );
74   lay->setSpacing( 0 );
75
76   // tab
77   QTabWidget* tab = new QTabWidget( fr );
78   tab->setTabShape( QTabWidget::Rounded );
79   tab->setTabPosition( QTabWidget::North );
80   lay->addWidget( tab );
81
82   // basic parameters
83   QWidget* GroupC1 = new QWidget();
84   lay->addWidget( GroupC1 );
85
86   QGridLayout* l = new QGridLayout( GroupC1 );
87   l->setSpacing( 6 );
88   l->setMargin( 11 );
89
90   int row = 0;
91   myName = 0;
92   if( isCreation() ) {
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 );
98   }
99
100   //GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis_var h =
101   //GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis::_narrow( initParamsHypothesis() );
102
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 );
108
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 );
117
118   myKeepFiles = new QCheckBox( tr( "GHS3DPRL_KeepFiles" ), GroupC1 );
119   myKeepFiles->setWhatsThis( tr( "GHS3DPRL_WhatsThis_KeepFiles" ) );
120   l->addWidget( myKeepFiles, row++, 0, 1, 2 );
121   
122   myBackground = new QCheckBox( tr( "GHS3DPRL_Background" ), GroupC1 );
123   myBackground->setWhatsThis( tr( "GHS3DPRL_WhatsThis_Background" ) );
124   l->addWidget( myBackground, row++, 0, 1, 2 );
125
126   myMultithread = new QCheckBox( tr( "GHS3DPRL_Multithread" ), GroupC1 );
127   myMultithread->setWhatsThis( tr( "GHS3DPRL_WhatsThis_Multithread" ) );
128   l->addWidget( myMultithread, row++, 0, 1, 2 );
129
130   //myToMeshHoles = new QCheckBox( tr( "GHS3DPRL_ToMeshHoles" ), GroupC1 );
131   //myToMeshHoles->setWhatsThis( tr( "GHS3DPRL_WhatsThis_ToMeshHoles" ) );
132   //l->addWidget( myToMeshHoles, row++, 0, 1, 2 );
133   
134   //myToMergeSubdomains = new QCheckBox( tr( "GHS3DPRL_ToMergeSubdomains" ), GroupC1 );
135   //myToMergeSubdomains->setWhatsThis( tr( "GHS3DPRL_WhatsThis_ToMergeSubdomains" ) );
136   //l->addWidget( myToMergeSubdomains, row++, 0, 1, 2 );
137
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 );
146
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 );
155
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 );
164
165   myIs3D = true;
166
167   myAdvTable = new SMESH_AdvOptionsWdg( fr );
168
169   // add tabs
170   tab->insertTab( 0, GroupC1, tr( "SMESH_ARGUMENTS" ));
171   tab->insertTab( 1, myAdvTable, tr( "SMESH_ADVANCED" ));
172
173   return fr;
174 }
175
176 void GHS3DPRLPluginGUI_HypothesisCreator::retrieveParams() const
177 {
178   GHS3DPRLHypothesisData data;
179   readParamsFromHypo( data );
180
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 );
193 }
194
195 QString GHS3DPRLPluginGUI_HypothesisCreator::storeParams() const
196 {
197   GHS3DPRLHypothesisData data;
198   readParamsFromWidgets( data );
199   storeParamsToHypo( data );
200
201   QString valStr;
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 ) + "; ";
212
213   return valStr;
214 }
215
216 bool GHS3DPRLPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DPRLHypothesisData& h_data ) const
217 {
218   GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis_var h =
219     GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis::_narrow( initParamsHypothesis() );
220
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() );
232
233   return true;
234 }
235
236 bool GHS3DPRLPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DPRLHypothesisData& h_data ) const
237 {
238   GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis_var h =
239     GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis::_narrow( hypothesis() );
240
241   bool ok = true;
242   try
243   {
244     if ( isCreation() )
245       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
246
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() );
256   }
257   catch ( const SALOME::SALOME_Exception& ex )
258   {
259     SalomeApp_Tools::QtCatchCorbaException( ex );
260     ok = false;
261   }
262   return ok;
263 }
264
265 bool GHS3DPRLPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DPRLHypothesisData& h_data ) const
266 {
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();
277   return true;
278 }
279
280 QString GHS3DPRLPluginGUI_HypothesisCreator::caption() const
281 {
282   return myIs3D ? tr( "GHS3DPRL_3D_TITLE" ) : tr( "GHS3DPRL_3D_TITLE" ); // ??? 3D/2D ???
283 }
284
285 QPixmap GHS3DPRLPluginGUI_HypothesisCreator::icon() const
286 {
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 );
289 }
290
291 QString GHS3DPRLPluginGUI_HypothesisCreator::type() const
292 {
293   return myIs3D ? tr( "GHS3DPRL_3D_HYPOTHESIS" ): tr( "GHS3DPRL_3D_HYPOTHESIS" ); // ??? 3D/2D ???
294 }
295
296 QString GHS3DPRLPluginGUI_HypothesisCreator::helpPage() const
297 {
298   return "ghs3dprl_hypo_page.html";
299 }
300