Salome HOME
ccb2df8027e84024b2304b4c8a77856913a479fc
[plugins/ghs3dprlplugin.git] / src / gui / GHS3DPRLPluginGUI_HypothesisCreator.cxx
1 //  GHS3DPRLPlugin GUI: GUI for plugged-in mesher GHS3DPRLPlugin
2 //
3 //  Copyright (C) 2003  CEA
4 //
5 //  This library is free software; you can redistribute it and/or
6 //  modify it under the terms of the GNU Lesser General Public
7 //  License as published by the Free Software Foundation; either
8 //  version 2.1 of the License.
9 //
10 //  This library is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 //  Lesser General Public License for more details.
14 //
15 //  You should have received a copy of the GNU Lesser General Public
16 //  License along with this library; if not, write to the Free Software
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 //
19 //  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
20 //
21 //
22 //
23 //  File   : GHS3DPRLPluginGUI_HypothesisCreator.cxx
24 //  Author  : Christian VAN WAMBEKE (CEA) (from Hexotic plugin Lioka RAZAFINDRAZAKA)
25 //  Module : GHS3DPRLPlugin
26 //  $Header:
27
28 #include "GHS3DPRLPluginGUI_HypothesisCreator.h"
29
30 #include <SMESHGUI_Utils.h>
31 #include <SMESHGUI_HypothesesUtils.h>
32
33 #include CORBA_SERVER_HEADER(GHS3DPRLPlugin_Algorithm)
34
35 #include <SUIT_Session.h>
36
37 #include <SalomeApp_Tools.h>
38
39 #include <QtxIntSpinBox.h>
40 #include <QtxComboBox.h>
41
42 #include <qlabel.h>
43 #include <qgroupbox.h>
44 #include <qframe.h>
45 #include <qlayout.h>
46 #include <qlineedit.h>
47 #include <qcheckbox.h>
48 #include <qwhatsthis.h>
49 #include <qpixmap.h>
50
51
52 GHS3DPRLPluginGUI_HypothesisCreator::GHS3DPRLPluginGUI_HypothesisCreator( const QString& theHypType )
53 : SMESHGUI_GenericHypothesisCreator( theHypType ),
54   myIs3D(true)
55 {
56 }
57
58 GHS3DPRLPluginGUI_HypothesisCreator::~GHS3DPRLPluginGUI_HypothesisCreator()
59 {
60 }
61
62 bool GHS3DPRLPluginGUI_HypothesisCreator::checkParams() const
63 {
64   GHS3DPRLHypothesisData data_old, data_new;
65   readParamsFromHypo( data_old );
66   readParamsFromWidgets( data_new );
67   bool res = storeParamsToHypo( data_new );
68   return res;
69 }
70
71 QFrame* GHS3DPRLPluginGUI_HypothesisCreator::buildFrame()
72 {
73   QString toto="myframe";
74   QFrame* fr = new QFrame( 0, "myframe" );
75   fr->setMinimumSize( QSize( 300, 140 ) );
76   QVBoxLayout* lay = new QVBoxLayout( fr, 5, 0 );
77
78   QGroupBox* GroupC1 = new QGroupBox( 2, Qt::Horizontal, fr, "GroupC1" );
79   lay->addWidget( GroupC1 );
80
81   GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) );
82   GroupC1->layout()->setSpacing( 6 );
83   GroupC1->layout()->setMargin( 11 );
84
85   myName = 0;
86   if( isCreation() ) {
87     myNameText = new QLabel( tr( "SMESH_NAME" ), GroupC1 );
88     QWhatsThis::add( myNameText, tr( "GHS3DPRL_WhatsThis_Name" ) );
89     myName = new QLineEdit( GroupC1 );
90   }
91
92   GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis_var h =
93   GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis::_narrow( initParamsHypothesis() );
94
95   myMEDNameText = new QLabel( tr( "GHS3DPRL_MEDName" ), GroupC1 );
96   QWhatsThis::add( myMEDNameText, tr( "GHS3DPRL_WhatsThis_MEDName" ) );
97   myMEDName = new QLineEdit( GroupC1 );
98   QLabel* myNbPartText = new QLabel( tr( "GHS3DPRL_NbPart" ), GroupC1 );
99   QWhatsThis::add( myNbPartText, tr( "GHS3DPRL_WhatsThis_NbPart" ) );
100   myNbPart = new QtxIntSpinBox( GroupC1 );
101   // myHexesMinLevel->setMinValue( 3 );
102   myNbPart->setMinValue( 1 );
103   myNbPart->setMaxValue( 256 );
104   myNbPart->setLineStep( 1 );
105
106   myKeepFiles = new QCheckBox( tr( "GHS3DPRL_KeepFiles" ), GroupC1 );
107   QWhatsThis::add( myKeepFiles, tr( "GHS3DPRL_WhatsThis_KeepFiles" ) );
108
109   GroupC1->addSpace(0);
110   myIs3D = true;
111
112   return fr;
113 }
114
115 void GHS3DPRLPluginGUI_HypothesisCreator::retrieveParams() const
116 {
117   GHS3DPRLHypothesisData data;
118   readParamsFromHypo( data );
119
120   if( myName ) myName->setText( data.myName );
121   myMEDName->setText( data.myMEDName );
122   myNbPart->setValue( data.myNbPart );
123   myKeepFiles->setChecked( data.myKeepFiles );
124   myNbPart->setEnabled(true);
125 }
126
127 QString GHS3DPRLPluginGUI_HypothesisCreator::storeParams() const
128 {
129   GHS3DPRLHypothesisData data;
130   readParamsFromWidgets( data );
131   storeParamsToHypo( data );
132
133   QString valStr;
134   valStr += tr("GHS3DPRL_MEDName") + " = " + data.myMEDName + "; ";
135   valStr += tr("GHS3DPRL_NbPart") + " = " + QString::number( data.myNbPart )   + "; ";
136   valStr += tr("GHS3DPRL_KeepFiles")  + " = " + QString::number( data.myKeepFiles ) + "; ";
137
138   return valStr;
139 }
140
141 bool GHS3DPRLPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DPRLHypothesisData& h_data ) const
142 {
143   GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis_var h =
144     GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis::_narrow( initParamsHypothesis() );
145
146   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
147   h_data.myName = isCreation() && data ? data->Label : "";
148   h_data.myMEDName = h->GetMEDName(); //"DOMAIN\0";
149   h_data.myNbPart = h->GetNbPart();
150   h_data.myKeepFiles = h->GetKeepFiles();
151
152   return true;
153 }
154
155 bool GHS3DPRLPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DPRLHypothesisData& h_data ) const
156 {
157   GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis_var h =
158     GHS3DPRLPlugin::GHS3DPRLPlugin_Hypothesis::_narrow( hypothesis() );
159
160   bool ok = true;
161   try
162   {
163     if( isCreation() )
164       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.latin1() );
165
166     h->SetMEDName( h_data.myMEDName );
167     h->SetNbPart( h_data.myNbPart );
168     h->SetKeepFiles( h_data.myKeepFiles );
169   }
170   catch(const SALOME::SALOME_Exception& ex)
171   {
172     SalomeApp_Tools::QtCatchCorbaException(ex);
173     ok = false;
174   }
175   return ok;
176 }
177
178 bool GHS3DPRLPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DPRLHypothesisData& h_data ) const
179 {
180   h_data.myName = myName ? myName->text() : "";
181   h_data.myMEDName = myMEDName->text();
182   h_data.myNbPart = myNbPart->value();
183   h_data.myKeepFiles = myKeepFiles->isChecked();
184
185   return true;
186 }
187
188 QString GHS3DPRLPluginGUI_HypothesisCreator::caption() const
189 {
190   return tr( QString( "GHS3DPRL_%1_TITLE" ).arg(myIs3D?QString("3D"):QString("3D")) );
191 }
192
193 QPixmap GHS3DPRLPluginGUI_HypothesisCreator::icon() const
194 {
195   QString hypIconName = tr( QString("ICON_DLG_GHS3DPRL_PARAMETERS%1").arg(myIs3D?QString(""):QString("")) );
196   return SUIT_Session::session()->resourceMgr()->loadPixmap( "GHS3DPRLPlugin", hypIconName );
197 }
198
199 QString GHS3DPRLPluginGUI_HypothesisCreator::type() const
200 {
201   return tr( QString( "GHS3DPRL_%1_HYPOTHESIS" ).arg(myIs3D?QString("3D"):QString("3D")) );
202 }