]> SALOME platform Git repositories - plugins/blsurfplugin.git/blob - src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.cxx
1 //  BLSURFPlugin GUI: GUI for plugged-in mesher BLSURFPlugin
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   : BLSURFPluginGUI_HypothesisCreator.cxx
24 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
25 //  Module : BLSURFPlugin
26 //  $Header: 
27
28 #include "BLSURFPluginGUI_HypothesisCreator.h"
29
30 #include <SMESHGUI_Utils.h>
31 #include <SMESHGUI_HypothesesUtils.h>
32
33 #include CORBA_SERVER_HEADER(BLSURFPlugin_Algorithm)
34
35 #include <SUIT_Session.h>
36
37 #include <SalomeApp_Tools.h>
38
39 #include <QtxDblSpinBox.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 <qpixmap.h>
49
50 enum Topology {
51     FromCAD,
52     Process,
53     Process2
54   };
55
56
57 enum PhysicalMesh
58   {
59     DefaultSize,
60     PhysicalUserDefined
61   };
62
63 enum GeometricMesh
64   {
65     DefaultGeom,
66     UserDefined
67   };
68
69 BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator( const QString& theHypType )
70 : SMESHGUI_GenericHypothesisCreator( theHypType ),
71   myIs2D(true)
72 {
73 }
74
75 BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
76 {
77 }
78
79 bool BLSURFPluginGUI_HypothesisCreator::checkParams() const
80 {
81   BlsurfHypothesisData data_old, data_new;
82   readParamsFromHypo( data_old );
83   readParamsFromWidgets( data_new );
84   bool res = storeParamsToHypo( data_new );
85   return res;
86 }
87
88 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
89 {
90   QFrame* fr = new QFrame( 0, "myframe" );
91   QVBoxLayout* lay = new QVBoxLayout( fr, 5, 0 );
92
93   QGroupBox* GroupC1 = new QGroupBox( 2, Qt::Horizontal, fr, "GroupC1" );
94   lay->addWidget( GroupC1 );
95   
96   GroupC1->setTitle( tr( "SMESH_ARGUMENTS"  ) );
97   GroupC1->layout()->setSpacing( 6 );
98   GroupC1->layout()->setMargin( 11 );
99   
100   myName = 0;
101   if( isCreation() ) {
102     new QLabel( tr( "SMESH_NAME" ), GroupC1 );
103     myName = new QLineEdit( GroupC1 );
104   }
105
106   new QLabel( tr( "BLSURF_TOPOLOGY" ), GroupC1 );
107   myTopology = new QtxComboBox( GroupC1 );
108   QStringList topologyTypes;
109   topologyTypes.append( QObject::tr( "BLSURF_TOPOLOGY_CAD" ) );
110   topologyTypes.append( QObject::tr( "BLSURF_TOPOLOGY_PROCESS" ) );
111   topologyTypes.append( QObject::tr( "BLSURF_TOPOLOGY_PROCESS2" ) );
112   myTopology->insertStringList( topologyTypes );
113
114   new QLabel( tr( "BLSURF_PHY_MESH" ), GroupC1 );
115   myPhysicalMesh = new QtxComboBox( GroupC1 );
116   QStringList physicalTypes;
117   physicalTypes.append( QObject::tr( "BLSURF_DEFAULT_USER" ) );
118   physicalTypes.append( QObject::tr( "BLSURF_CUSTOM_USER" ) );
119   myPhysicalMesh->insertStringList( physicalTypes );
120
121   new QLabel( tr( "BLSURF_HPHYDEF" ), GroupC1 );
122   myPhySize = new QtxDblSpinBox( GroupC1 );
123   myPhySize->setMinValue( 1e-02 );
124   myPhySize->setMaxValue( 1e+02 );
125   myPhySize->setLineStep( 1 );
126
127   new QLabel( tr( "BLSURF_GEOM_MESH" ), GroupC1 );
128   myGeometricMesh = new QtxComboBox( GroupC1 );
129   QStringList types;
130   types.append( QObject::tr( "BLSURF_DEFAULT_GEOM" ) );
131   types.append( QObject::tr( "BLSURF_CUSTOM_GEOM" ) );
132   myGeometricMesh->insertStringList( types );
133
134 //   new QLabel( tr( "BLSURF_GROWTH_RATE" ), GroupC1 );
135 //   myGrowthRate = new QtxDblSpinBox( GroupC1 );
136 //   myGrowthRate->setMinValue( 0.1 );
137 //   myGrowthRate->setMaxValue( 10 );
138 //   myGrowthRate->setLineStep( 0.1 );
139
140   new QLabel( tr( "BLSURF_ANGLE_MESH_S" ), GroupC1 );
141   myAngleMeshS = new QtxDblSpinBox( GroupC1 );
142   myAngleMeshS->setMinValue( 0 );
143   myAngleMeshS->setMaxValue( 16 );
144   myAngleMeshS->setLineStep( 0.5 );
145   
146   new QLabel( tr( "BLSURF_GRADATION" ), GroupC1 );
147   myGradation = new QtxDblSpinBox( GroupC1 );
148   myGradation->setMinValue( 1.1 );
149   myGradation->setMaxValue( 2.5 );
150   myGradation->setLineStep( 0.1 );
151
152 //   new QLabel( tr( "BLSURF_SEG_PER_RADIUS" ), GroupC1 );
153 //   myNbSegPerRadius = new QtxDblSpinBox( GroupC1 );
154 //   myNbSegPerRadius->setMinValue( 0.2 );
155 //   myNbSegPerRadius->setMaxValue( 5.0 );
156
157   myAllowQuadrangles = new QCheckBox( tr( "BLSURF_ALLOW_QUADRANGLES" ), GroupC1 );
158   GroupC1->addSpace(0);
159 //   myIs2D = true;
160
161   myDecimesh = new QCheckBox( tr( "BLSURF_DECIMESH" ), GroupC1 );
162   GroupC1->addSpace(0);
163
164   connect( myGeometricMesh, SIGNAL( activated( int ) ), this, SLOT( onGeometricMeshChanged() ) );
165   connect( myPhysicalMesh,  SIGNAL( activated( int ) ), this, SLOT( onPhysicalMeshChanged() ) );
166
167   return fr;
168 }
169
170 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
171 {
172   BlsurfHypothesisData data;
173   readParamsFromHypo( data );
174
175   if( myName )
176     myName->setText( data.myName );
177   myTopology->setCurrentItem( data.myTopology );
178   myPhysicalMesh->setCurrentItem( data.myPhysicalMesh );
179   myPhySize->setValue( data.myPhySize );
180   myGeometricMesh->setCurrentItem( data.myGeometricMesh );
181   myAngleMeshS->setValue( data.myAngleMeshS);
182   myGradation->setValue( data.myGradation);
183   myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
184   myDecimesh->setChecked( data.myDecimesh );
185
186   // update widgets
187
188   bool isPhysicalCustom = (myPhysicalMesh->currentItem() == PhysicalUserDefined);
189   myPhySize->setEnabled(isPhysicalCustom);
190
191   bool isCustom = (myGeometricMesh->currentItem() == UserDefined);
192   myAngleMeshS->setEnabled(isCustom);
193   myGradation->setEnabled(isCustom);
194 }
195
196 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
197 {
198   BlsurfHypothesisData data;
199   readParamsFromWidgets( data );
200   storeParamsToHypo( data );
201
202   QString guiHyp;
203   guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( data.myTopology ) + "; ";
204   guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( data.myPhysicalMesh ) + "; ";
205   guiHyp += tr("BLSURF_HPHYDEF") + " = " + QString::number( data.myPhySize ) + "; ";
206   guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( data.myGeometricMesh ) + "; ";
207   guiHyp += tr("BLSURF_ANGLE_MESH_S") + " = " + QString::number( data.myAngleMeshS ) + "; ";
208   guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( data.myGradation ) + "; ";
209   guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(data.myAllowQuadrangles ? "yes" : "no") + "; ";
210   guiHyp += tr("BLSURF_DECIMESH") + " = " + QString(data.myDecimesh ? "yes" : "no") + "; ";
211
212   cout << "guiHyp : " << guiHyp << endl;
213
214   return guiHyp;
215 }
216
217 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
218 {
219   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
220     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
221
222   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
223   h_data.myName = isCreation() && data ? data->Label : "";
224
225   h_data.myTopology = (int) h->GetTopology();
226   h_data.myPhysicalMesh = (int) h->GetPhysicalMesh();
227   h_data.myPhySize = h->GetPhySize();
228   h_data.myGeometricMesh = (int) h->GetGeometricMesh();
229   h_data.myAngleMeshS = h->GetAngleMeshS();
230   h_data.myGradation = h->GetGradation();
231   h_data.myAllowQuadrangles = h->GetQuadAllowed();
232   h_data.myDecimesh = h->GetDecimesh();
233
234   return true;
235 }
236
237 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
238 {
239   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
240     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
241
242   bool ok = true;
243   try
244   {
245     if( isCreation() )
246       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.latin1() );
247
248     h->SetTopology( (int) h_data.myTopology );
249     h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
250     h->SetPhySize( h_data.myPhySize );
251     h->SetGeometricMesh( (int) h_data.myGeometricMesh );
252     h->SetGradation( h_data.myGradation );
253     h->SetQuadAllowed( h_data.myAllowQuadrangles );
254     h->SetDecimesh( h_data.myDecimesh );
255
256     if( (int) h_data.myPhysicalMesh == PhysicalUserDefined )
257       h->SetPhySize( h_data.myPhySize );
258
259     if( (int) h_data.myGeometricMesh == UserDefined )
260       h->SetAngleMeshS( h_data.myAngleMeshS );
261   }
262   catch(const SALOME::SALOME_Exception& ex)
263   {
264     SalomeApp_Tools::QtCatchCorbaException(ex);
265     ok = false;
266   }
267   return ok;
268 }
269
270 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
271 {
272   h_data.myName             = myName ? myName->text() : "";
273   h_data.myTopology         = myTopology->currentItem();
274   h_data.myPhysicalMesh     = myPhysicalMesh->currentItem();
275   h_data.myPhySize          = myPhySize->value();
276   h_data.myGeometricMesh    = myGeometricMesh->currentItem();
277   h_data.myAngleMeshS       = myAngleMeshS->value();
278   h_data.myGradation        = myGradation->value();
279   h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
280   h_data.myDecimesh         = myDecimesh->isChecked();
281
282   return true;
283 }
284
285 void BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged() {
286   bool isCustom = (myPhysicalMesh->currentItem() == PhysicalUserDefined);
287   myPhySize->setEnabled(isCustom);
288
289   if ( ! isCustom ) {
290     double aPhySize;
291     switch( myPhysicalMesh->currentItem() ) {
292       case DefaultSize:
293       default:
294         aPhySize = 10;
295         break;
296       }
297     myPhySize->setValue( aPhySize );
298   }
299 }
300
301 void BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged() {
302   bool isCustom = (myGeometricMesh->currentItem() == UserDefined);
303   myAngleMeshS->setEnabled(isCustom);
304   myGradation->setEnabled(isCustom);
305
306   if ( ! isCustom ) {
307     double aAngleMeshS, aGradation;
308     switch( myGeometricMesh->currentItem() ) {
309       case DefaultGeom:
310       default:
311         aAngleMeshS = 8;
312         aGradation = 1.1;
313         break;
314       }
315     myAngleMeshS->setValue( aAngleMeshS );
316     myGradation->setValue( aGradation );
317   }
318 }
319
320 QString BLSURFPluginGUI_HypothesisCreator::caption() const
321 {
322   return tr( QString( "BLSURF_%1_TITLE" ).arg(myIs2D?QString("2D"):QString("3D")) );
323 }
324
325 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
326 {
327   QString hypIconName = tr( QString("ICON_DLG_BLSURF_PARAMETERS%1").arg(myIs2D?QString(""):QString("")) );
328   return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", hypIconName );
329 }
330
331 QString BLSURFPluginGUI_HypothesisCreator::type() const
332 {
333   return tr( QString( "BLSURF_%1_HYPOTHESIS" ).arg(myIs2D?QString("2D"):QString("3D")) );
334 }