Salome HOME
Moving *all* CMake detection files to common CONFIGURATION repo: udapte CMakeLists
[plugins/ghs3dprlplugin.git] / src / gui / GHS3DPRLPluginGUI_HypothesisCreator.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
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
30 #include CORBA_SERVER_HEADER(GHS3DPRLPlugin_Algorithm)
31
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Tools.h>
35 #include <QtxIntSpinBox.h>
36 #include <QtxDoubleSpinBox.h>
37
38 #include <QFrame>
39 #include <QGroupBox>
40 #include <QLabel>
41 #include <QLineEdit>
42 #include <QCheckBox>
43 #include <QVBoxLayout>
44 #include <QGridLayout>
45
46 GHS3DPRLPluginGUI_HypothesisCreator::GHS3DPRLPluginGUI_HypothesisCreator( const QString& theHypType )
47 : SMESHGUI_GenericHypothesisCreator( theHypType ),
48   myIs3D( true )
49 {
50   //printf("Hypo creator GHS3DPRLPlugin !!!!!!!!!!!!!!!!!!!!!!!!!! RNV");
51 }
52
53 GHS3DPRLPluginGUI_HypothesisCreator::~GHS3DPRLPluginGUI_HypothesisCreator()
54 {
55 }
56
57 bool GHS3DPRLPluginGUI_HypothesisCreator::checkParams() const
58 {
59   GHS3DPRLHypothesisData data_old, data_new;
60   readParamsFromHypo( data_old );
61   readParamsFromWidgets( data_new );
62   bool res = storeParamsToHypo( data_new );
63   storeParamsToHypo( data_old );
64   return res;
65 }
66
67 QFrame* GHS3DPRLPluginGUI_HypothesisCreator::buildFrame()
68 {
69   QFrame* fr = new QFrame( 0 );
70   QVBoxLayout* lay = new QVBoxLayout( fr );
71   lay->setMargin( 5 );
72   lay->setSpacing( 0 );
73
74   QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
75   lay->addWidget( GroupC1 );
76
77   QGridLayout* l = new QGridLayout( GroupC1 );
78   l->setSpacing( 6 );
79   l->setMargin( 11 );
80
81   int row = 0;
82   myName = 0;
83   if( isCreation() ) {
84     QLabel* aNameLab = new QLabel( tr( "SMESH_NAME" ), GroupC1 );
85     aNameLab->setWhatsThis( tr( "GHS3DPRL_WhatsThis_Name" ) );
86     l->addWidget( aNameLab, row, 0, 1, 1 );
87     myName = new QLineEdit( GroupC1 );
88     l->addWidget( myName, row++, 1, 1, 1 );
89   }
90
91   //GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis_var h =
92   //GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis::_narrow( initParamsHypothesis() );
93
94   QLabel* aMEDNameText = new QLabel( tr( "GHS3DPRL_MEDName" ), GroupC1 );
95   aMEDNameText->setWhatsThis( tr( "GHS3DPRL_WhatsThis_MEDName" ) );
96   l->addWidget( aMEDNameText, row, 0, 1, 1 );
97   myMEDName = new QLineEdit( GroupC1 );
98   l->addWidget( myMEDName, row++, 1, 1, 1 );
99
100   QLabel* aNbPartText = new QLabel( tr( "GHS3DPRL_NbPart" ), GroupC1 );
101   aNbPartText->setWhatsThis( tr( "GHS3DPRL_WhatsThis_NbPart" ) );
102   l->addWidget( aNbPartText, row, 0, 1, 1 );
103   myNbPart = new QtxIntSpinBox( GroupC1 );
104   l->addWidget( myNbPart, row++, 1, 1, 1 );
105   myNbPart->setMinimum( 1 );
106   myNbPart->setMaximum( 256 );
107   myNbPart->setSingleStep( 1 );
108
109   myKeepFiles = new QCheckBox( tr( "GHS3DPRL_KeepFiles" ), GroupC1 );
110   myKeepFiles->setWhatsThis( tr( "GHS3DPRL_WhatsThis_KeepFiles" ) );
111   l->addWidget( myKeepFiles, row++, 0, 1, 2 );
112   
113   myBackground = new QCheckBox( tr( "GHS3DPRL_Background" ), GroupC1 );
114   myBackground->setWhatsThis( tr( "GHS3DPRL_WhatsThis_Background" ) );
115   l->addWidget( myBackground, row++, 0, 1, 2 );
116
117   myMultithread = new QCheckBox( tr( "GHS3DPRL_Multithread" ), GroupC1 );
118   myMultithread->setWhatsThis( tr( "GHS3DPRL_WhatsThis_Multithread" ) );
119   l->addWidget( myMultithread, row++, 0, 1, 2 );
120
121   //myToMeshHoles = new QCheckBox( tr( "GHS3DPRL_ToMeshHoles" ), GroupC1 );
122   //myToMeshHoles->setWhatsThis( tr( "GHS3DPRL_WhatsThis_ToMeshHoles" ) );
123   //l->addWidget( myToMeshHoles, row++, 0, 1, 2 );
124   
125   //myToMergeSubdomains = new QCheckBox( tr( "GHS3DPRL_ToMergeSubdomains" ), GroupC1 );
126   //myToMergeSubdomains->setWhatsThis( tr( "GHS3DPRL_WhatsThis_ToMergeSubdomains" ) );
127   //l->addWidget( myToMergeSubdomains, row++, 0, 1, 2 );
128
129   QLabel* aGradationText = new QLabel( tr( "GHS3DPRL_Gradation" ), GroupC1 );
130   aGradationText->setWhatsThis( tr( "GHS3DPRL_WhatsThis_Gradation" ) );
131   l->addWidget( aGradationText, row, 0, 1, 1 );
132   myGradation = new QtxDoubleSpinBox( GroupC1 );
133   l->addWidget( myGradation, row++, 1, 1, 1 );
134   myGradation->setMinimum( 0 );
135   myGradation->setMaximum( 3 );
136   myGradation->setSingleStep( 0.01 );
137
138   QLabel* aMinSizeText = new QLabel( tr( "GHS3DPRL_MinSize" ), GroupC1 );
139   aMinSizeText->setWhatsThis( tr( "GHS3DPRL_WhatsThis_MinSize" ) );
140   l->addWidget( aMinSizeText, row, 0, 1, 1 );
141   myMinSize = new QtxDoubleSpinBox( GroupC1 );
142   l->addWidget( myMinSize, row++, 1, 1, 1 );
143   myMinSize->setMinimum( 0 );
144   //myMinSize->setMaximum( 999999 );
145   //myMinSize->setSingleStep( 1 );
146
147   QLabel* aMaxSizeText = new QLabel( tr( "GHS3DPRL_MaxSize" ), GroupC1 );
148   aMaxSizeText->setWhatsThis( tr( "GHS3DPRL_WhatsThis_MaxSize" ) );
149   l->addWidget( aMaxSizeText, row, 0, 1, 1 );
150   myMaxSize = new QtxDoubleSpinBox( GroupC1 );
151   l->addWidget( myMaxSize, row++, 1, 1, 1 );
152   myMaxSize->setMinimum( 0 );
153   //myMaxSize->setMaximum( 999999 );
154   //myMaxSize->setSingleStep( 1 );
155
156   myIs3D = true;
157
158   return fr;
159 }
160
161 void GHS3DPRLPluginGUI_HypothesisCreator::retrieveParams() const
162 {
163   GHS3DPRLHypothesisData data;
164   readParamsFromHypo( data );
165
166   if ( myName ) myName->setText( data.myName );
167   myMEDName->setText( data.myMEDName );
168   myNbPart->setValue( data.myNbPart );
169   myKeepFiles->setChecked( data.myKeepFiles );
170   myBackground->setChecked( data.myBackground );
171   myMultithread->setChecked( data.myMultithread );
172   //myToMeshHoles->setChecked( data.myToMeshHoles );
173   //myToMergeSubdomains->setChecked( data.myToMergeSubdomains );
174   myGradation->setValue( data.myGradation );
175   myMinSize->setValue( data.myMinSize );
176   myMaxSize->setValue( data.myMaxSize );
177 }
178
179 QString GHS3DPRLPluginGUI_HypothesisCreator::storeParams() const
180 {
181   GHS3DPRLHypothesisData data;
182   readParamsFromWidgets( data );
183   storeParamsToHypo( data );
184
185   QString valStr;
186   valStr += tr( "GHS3DPRL_MEDName" ) + " = " + data.myMEDName + "; ";
187   valStr += tr( "GHS3DPRL_NbPart" ) + " = " + QString::number( data.myNbPart )   + "; ";
188   //valStr += tr( "GHS3DPRL_ToMeshHoles" )  + " = " + QString::number( data.myToMeshHoles ) + "; ";
189   //valStr += tr( "GHS3DPRL_ToMergeSubdomains" )  + " = " + QString::number( data.myToMergeSubdomains ) + "; ";
190   valStr += tr( "GHS3DPRL_Gradation" )  + " = " + QString::number( data.myGradation ) + "; ";
191   valStr += tr( "GHS3DPRL_MinSize" )  + " = " + QString::number( data.myMinSize ) + "; ";
192   valStr += tr( "GHS3DPRL_MaxSize" )  + " = " + QString::number( data.myMaxSize ) + "; ";
193   valStr += tr( "GHS3DPRL_KeepFiles" )  + " = " + QString::number( data.myKeepFiles ) + "; ";
194   valStr += tr( "GHS3DPRL_Background" )  + " = " + QString::number( data.myBackground ) + "; ";
195   valStr += tr( "GHS3DPRL_Multithread" )  + " = " + QString::number( data.myMultithread ) + "; ";
196
197   return valStr;
198 }
199
200 bool GHS3DPRLPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DPRLHypothesisData& h_data ) const
201 {
202   GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis_var h =
203     GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis::_narrow( initParamsHypothesis() );
204
205   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
206   h_data.myName      = isCreation() && data ? hypName() : "";
207   h_data.myMEDName   = h->GetMEDName(); //"DOMAIN\0";
208   h_data.myNbPart    = h->GetNbPart();
209   h_data.myKeepFiles = h->GetKeepFiles();
210   h_data.myBackground = h->GetBackground();
211   h_data.myMultithread = h->GetMultithread();
212   //h_data.myToMeshHoles = h->GetToMeshHoles();
213   //h_data.myToMergeSubdomains = h->GetToMergeSubdomains();
214   h_data.myGradation = h->GetGradation();
215   h_data.myMinSize = h->GetMinSize();
216   h_data.myMaxSize = h->GetMaxSize();
217
218   return true;
219 }
220
221 bool GHS3DPRLPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DPRLHypothesisData& h_data ) const
222 {
223   GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis_var h =
224     GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis::_narrow( hypothesis() );
225
226   bool ok = true;
227   try
228   {
229     if ( isCreation() )
230       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
231
232     h->SetMEDName( h_data.myMEDName.toLatin1().constData() );
233     h->SetNbPart( h_data.myNbPart );
234     h->SetKeepFiles( h_data.myKeepFiles );
235     h->SetBackground( h_data.myBackground );
236     h->SetMultithread( h_data.myMultithread );
237     //h->SetToMeshHoles( h_data.myToMeshHoles );
238     //h->SetToMergeSubdomains( h_data.myToMergeSubdomains );
239     h->SetGradation( h_data.myGradation );
240     h->SetMinSize( h_data.myMinSize );
241     h->SetMaxSize( h_data.myMaxSize );
242   }
243   catch ( const SALOME::SALOME_Exception& ex )
244   {
245     SalomeApp_Tools::QtCatchCorbaException( ex );
246     ok = false;
247   }
248   return ok;
249 }
250
251 bool GHS3DPRLPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DPRLHypothesisData& h_data ) const
252 {
253   h_data.myName      = myName ? myName->text() : "";
254   h_data.myMEDName   = myMEDName->text().simplified().replace(' ', '_');
255   h_data.myNbPart    = myNbPart->value();
256   h_data.myKeepFiles = myKeepFiles->isChecked();
257   h_data.myBackground = myBackground->isChecked();
258   //h_data.myToMeshHoles = myToMeshHoles->isChecked();
259   //h_data.myToMergeSubdomains = myToMergeSubdomains->isChecked();
260   h_data.myGradation = myGradation->value();
261   h_data.myMinSize = myMinSize->value();
262   h_data.myMaxSize = myMaxSize->value();
263   return true;
264 }
265
266 QString GHS3DPRLPluginGUI_HypothesisCreator::caption() const
267 {
268   return myIs3D ? tr( "GHS3DPRL_3D_TITLE" ) : tr( "GHS3DPRL_3D_TITLE" ); // ??? 3D/2D ???
269 }
270
271 QPixmap GHS3DPRLPluginGUI_HypothesisCreator::icon() const
272 {
273   QString hypIconName = myIs3D ? tr( "ICON_DLG_GHS3DPRL_PARAMETERS" ) : tr( "ICON_DLG_GHS3DPRL_PARAMETERS" ); // ??? 3D/2D ???
274   return SUIT_Session::session()->resourceMgr()->loadPixmap( "GHS3DPRLPlugin", hypIconName );
275 }
276
277 QString GHS3DPRLPluginGUI_HypothesisCreator::type() const
278 {
279   return myIs3D ? tr( "GHS3DPRL_3D_HYPOTHESIS" ): tr( "GHS3DPRL_3D_HYPOTHESIS" ); // ??? 3D/2D ???
280 }
281
282 QString GHS3DPRLPluginGUI_HypothesisCreator::helpPage() const
283 {
284   return "ghs3dprl_hypo_page.html";
285 }
286