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