Salome HOME
Update copyrights 2014.
[plugins/ghs3dprlplugin.git] / src / gui / GHS3DPRLPluginGUI_HypothesisCreator.cxx
1 // Copyright (C) 2007-2014  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 !!!!!!!!!!!!!!!!!!!!!!!!!! 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   myIs3D = true;
121
122   return fr;
123 }
124
125 void GHS3DPRLPluginGUI_HypothesisCreator::retrieveParams() const
126 {
127   GHS3DPRLHypothesisData data;
128   readParamsFromHypo( data );
129
130   if ( myName ) myName->setText( data.myName );
131   myMEDName->setText( data.myMEDName );
132   myNbPart->setValue( data.myNbPart );
133   myKeepFiles->setChecked( data.myKeepFiles );
134   myBackground->setChecked( data.myBackground );
135   myToMeshHoles->setChecked( data.myToMeshHoles );
136   //myNbPart->setEnabled( true );
137 }
138
139 QString GHS3DPRLPluginGUI_HypothesisCreator::storeParams() const
140 {
141   GHS3DPRLHypothesisData data;
142   readParamsFromWidgets( data );
143   storeParamsToHypo( data );
144
145   QString valStr;
146   valStr += tr( "GHS3DPRL_MEDName" ) + " = " + data.myMEDName + "; ";
147   valStr += tr( "GHS3DPRL_NbPart" ) + " = " + QString::number( data.myNbPart )   + "; ";
148   valStr += tr( "GHS3DPRL_ToMeshHoles" )  + " = " + QString::number( data.myToMeshHoles ) + "; ";
149   valStr += tr( "GHS3DPRL_KeepFiles" )  + " = " + QString::number( data.myKeepFiles ) + "; ";
150   valStr += tr( "GHS3DPRL_Background" )  + " = " + QString::number( data.myBackground ) + "; ";
151
152   return valStr;
153 }
154
155 bool GHS3DPRLPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DPRLHypothesisData& h_data ) const
156 {
157   GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis_var h =
158     GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis::_narrow( initParamsHypothesis() );
159
160   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
161   h_data.myName      = isCreation() && data ? hypName() : "";
162   h_data.myMEDName   = h->GetMEDName(); //"DOMAIN\0";
163   h_data.myNbPart    = h->GetNbPart();
164   h_data.myKeepFiles = h->GetKeepFiles();
165   h_data.myBackground = h->GetBackground();
166   h_data.myToMeshHoles = h->GetToMeshHoles();
167
168   return true;
169 }
170
171 bool GHS3DPRLPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DPRLHypothesisData& h_data ) const
172 {
173   GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis_var h =
174     GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis::_narrow( hypothesis() );
175
176   bool ok = true;
177   try
178   {
179     if ( isCreation() )
180       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
181
182     h->SetMEDName( h_data.myMEDName.toLatin1().constData() );
183     h->SetNbPart( h_data.myNbPart );
184     h->SetKeepFiles( h_data.myKeepFiles );
185     h->SetBackground( h_data.myBackground );
186     h->SetToMeshHoles( h_data.myToMeshHoles );
187   }
188   catch ( const SALOME::SALOME_Exception& ex )
189   {
190     SalomeApp_Tools::QtCatchCorbaException( ex );
191     ok = false;
192   }
193   return ok;
194 }
195
196 bool GHS3DPRLPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DPRLHypothesisData& h_data ) const
197 {
198   h_data.myName      = myName ? myName->text() : "";
199   h_data.myMEDName   = myMEDName->text().simplified().replace(' ', '_');
200   h_data.myNbPart    = myNbPart->value();
201   h_data.myKeepFiles = myKeepFiles->isChecked();
202   h_data.myBackground = myBackground->isChecked();
203   h_data.myToMeshHoles = myToMeshHoles->isChecked();
204   return true;
205 }
206
207 QString GHS3DPRLPluginGUI_HypothesisCreator::caption() const
208 {
209   return myIs3D ? tr( "GHS3DPRL_3D_TITLE" ) : tr( "GHS3DPRL_3D_TITLE" ); // ??? 3D/2D ???
210 }
211
212 QPixmap GHS3DPRLPluginGUI_HypothesisCreator::icon() const
213 {
214   QString hypIconName = myIs3D ? tr( "ICON_DLG_GHS3DPRL_PARAMETERS" ) : tr( "ICON_DLG_GHS3DPRL_PARAMETERS" ); // ??? 3D/2D ???
215   return SUIT_Session::session()->resourceMgr()->loadPixmap( "GHS3DPRLPlugin", hypIconName );
216 }
217
218 QString GHS3DPRLPluginGUI_HypothesisCreator::type() const
219 {
220   return myIs3D ? tr( "GHS3DPRL_3D_HYPOTHESIS" ): tr( "GHS3DPRL_3D_HYPOTHESIS" ); // ??? 3D/2D ???
221 }
222
223 QString GHS3DPRLPluginGUI_HypothesisCreator::helpPage() const
224 {
225   return "ghs3dprl_hypo_page.html";
226 }
227