]> SALOME platform Git repositories - plugins/hexoticplugin.git/blob - src/GUI/HexoticPluginGUI_HypothesisCreator.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0.
[plugins/hexoticplugin.git] / src / GUI / HexoticPluginGUI_HypothesisCreator.cxx
1 //  HexoticPlugin GUI: GUI for plugged-in mesher HexoticPlugin
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   : HexoticPluginGUI_HypothesisCreator.cxx
24 // Author  : Lioka RAZAFINDRAZAKA (CEA)
25 //  Module : HexoticPlugin
26 //  $Header: 
27
28 #include "HexoticPluginGUI_HypothesisCreator.h"
29
30 #include <SMESHGUI_Utils.h>
31 #include <SMESHGUI_HypothesesUtils.h>
32
33 #include CORBA_SERVER_HEADER(HexoticPlugin_Algorithm)
34
35 #include <SUIT_Session.h>
36
37 #include <SalomeApp_Tools.h>
38
39 #include <QtxIntSpinBox.h>
40 #include <QtxDblSpinBox.h>
41
42 #include <QtxComboBox.h>
43
44 #include <qlabel.h>
45 #include <qgroupbox.h>
46 #include <qframe.h>
47 #include <qlayout.h>
48 #include <qlineedit.h>
49 #include <qcheckbox.h>
50 #include <qpixmap.h>
51
52  enum Fineness
53    {
54      VeryCoarse,
55      Coarse,
56      Moderate,
57      Fine,
58      VeryFine,
59      UserDefined
60    };
61
62 HexoticPluginGUI_HypothesisCreator::HexoticPluginGUI_HypothesisCreator( const QString& theHypType )
63 : SMESHGUI_GenericHypothesisCreator( theHypType ),
64   myIs3D(true)
65 {
66 }
67
68 HexoticPluginGUI_HypothesisCreator::~HexoticPluginGUI_HypothesisCreator()
69 {
70 }
71
72 bool HexoticPluginGUI_HypothesisCreator::checkParams() const
73 {
74   HexoticHypothesisData data_old, data_new;
75   readParamsFromHypo( data_old );
76   readParamsFromWidgets( data_new );
77   bool res = storeParamsToHypo( data_new );
78   return res;
79 }
80
81 QFrame* HexoticPluginGUI_HypothesisCreator::buildFrame()
82 {
83   QFrame* fr = new QFrame( 0, "myframe" );
84   QVBoxLayout* lay = new QVBoxLayout( fr, 7, 0 );
85
86   QGroupBox* GroupC1 = new QGroupBox( 2, Qt::Horizontal, fr, "GroupC1" );
87   lay->addWidget( GroupC1 );
88   
89   GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) );
90   GroupC1->layout()->setSpacing( 6 );
91   GroupC1->layout()->setMargin( 11 );
92   
93   myName = 0;
94   if( isCreation() ) {
95     new QLabel( tr( "SMESH_NAME" ), GroupC1 );
96     myName = new QLineEdit( GroupC1 );
97   }
98
99   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
100   HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( initParamsHypothesis() );
101
102   new QLabel( tr( "Hexotic_HEXES_MIN_LEVEL" ), GroupC1 );
103   myHexesMinLevel = new QtxIntSpinBox( GroupC1 );
104   // myHexesMinLevel->setMinValue( 3 );
105   myHexesMinLevel->setMinValue( h->GetHexesMinLevel() );
106   myHexesMinLevel->setMaxValue( 10 );
107   myHexesMinLevel->setLineStep( 1 );
108   
109   new QLabel( tr( "Hexotic_HEXES_MAX_LEVEL" ), GroupC1 );
110   myHexesMaxLevel = new QtxIntSpinBox( GroupC1 );
111   myHexesMaxLevel->setMinValue( 3 );
112   myHexesMaxLevel->setMaxValue( 10 );
113   myHexesMaxLevel->setLineStep( 1 );
114
115   myHexoticQuadrangles = new QCheckBox( tr( "Hexotic_QUADRANGLES" ), GroupC1 );
116   GroupC1->addSpace(0);
117   myIs3D = true;
118
119   myHexoticIgnoreRidges = new QCheckBox( tr( "Hexotic_IGNORE_RIDGES" ), GroupC1 );
120   GroupC1->addSpace(0);
121
122   myHexoticInvalidElements = new QCheckBox( tr( "Hexotic_INVALID_ELEMENTS" ), GroupC1 );
123   GroupC1->addSpace(0);
124
125   new QLabel( tr( "Hexotic_SHARP_ANGLE_THRESHOLD" ), GroupC1 );
126   myHexoticSharpAngleThreshold = new QtxIntSpinBox( GroupC1 );
127   myHexoticSharpAngleThreshold->setMinValue( 0 );
128   myHexoticSharpAngleThreshold->setMaxValue( 90 );
129   myHexoticSharpAngleThreshold->setLineStep( 1 );
130
131   return fr;
132 }
133
134 void HexoticPluginGUI_HypothesisCreator::retrieveParams() const
135 {
136   HexoticHypothesisData data;
137   readParamsFromHypo( data );
138
139   if( myName )
140     myName->setText( data.myName );
141   myHexesMinLevel->setValue( data.myHexesMinLevel );
142   myHexesMaxLevel->setValue( data.myHexesMaxLevel );
143   myHexoticSharpAngleThreshold->setValue( data.myHexoticSharpAngleThreshold );
144
145   myHexoticQuadrangles->setChecked( data.myHexoticQuadrangles );
146   myHexoticIgnoreRidges->setChecked( data.myHexoticIgnoreRidges );
147   myHexoticInvalidElements->setChecked( data.myHexoticInvalidElements );
148
149   myHexesMinLevel->setEnabled(true);
150   myHexesMaxLevel->setEnabled(true);
151   myHexoticSharpAngleThreshold->setEnabled(true);
152 }
153
154 QString HexoticPluginGUI_HypothesisCreator::storeParams() const
155 {
156   HexoticHypothesisData data;
157   readParamsFromWidgets( data );
158   storeParamsToHypo( data );
159
160   QString valStr;
161   valStr += tr("Hexotic_SEG_MIN_SIZE") + " = " + QString::number( data.myHexesMinLevel )   + "; ";
162   valStr += tr("Hexotic_SEG_MAX_SIZE") + " = " + QString::number( data.myHexesMaxLevel ) + "; ";
163   valStr += tr("Hexotic_QUADRANGLES")  + " = " + QString::number( data.myHexoticQuadrangles ) + "; ";
164   valStr += tr("Hexotic_IGNORE_RIDGES")  + " = " + QString::number( data.myHexoticIgnoreRidges ) + "; ";
165   valStr += tr("Hexotic_INVALID_ELEMENTS")  + " = " + QString::number( data.myHexoticInvalidElements ) + "; ";
166   valStr += tr("Hexotic_SHARP_ANGLE_THRESHOLD") + " = " + QString::number( data.myHexoticSharpAngleThreshold ) + "; ";
167
168   return valStr;
169 }
170
171 bool HexoticPluginGUI_HypothesisCreator::readParamsFromHypo( HexoticHypothesisData& h_data ) const
172 {
173   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
174     HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( initParamsHypothesis() );
175
176   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
177   h_data.myName = isCreation() && data ? data->Label : "";
178   h_data.myHexesMinLevel = h->GetHexesMinLevel();
179   h_data.myHexesMaxLevel = h->GetHexesMaxLevel();
180   h_data.myHexoticQuadrangles = h->GetHexoticQuadrangles();
181   h_data.myHexoticIgnoreRidges = h->GetHexoticIgnoreRidges();
182   h_data.myHexoticInvalidElements = h->GetHexoticInvalidElements();
183   h_data.myHexoticSharpAngleThreshold = h->GetHexoticSharpAngleThreshold();
184
185   return true;
186 }
187
188 bool HexoticPluginGUI_HypothesisCreator::storeParamsToHypo( const HexoticHypothesisData& h_data ) const
189 {
190   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
191     HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( hypothesis() );
192
193   bool ok = true;
194   try
195   {
196     if( isCreation() )
197       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.latin1() );
198
199     h->SetHexesMinLevel( h_data.myHexesMinLevel );
200     h->SetHexesMaxLevel( h_data.myHexesMaxLevel );
201     h->SetHexoticQuadrangles( h_data.myHexoticQuadrangles );
202     h->SetHexoticIgnoreRidges( h_data.myHexoticIgnoreRidges );
203     h->SetHexoticInvalidElements( h_data.myHexoticInvalidElements );
204     h->SetHexoticSharpAngleThreshold( h_data.myHexoticSharpAngleThreshold );
205   }
206   catch(const SALOME::SALOME_Exception& ex)
207   {
208     SalomeApp_Tools::QtCatchCorbaException(ex);
209     ok = false;
210   }
211   return ok;
212 }
213
214 bool HexoticPluginGUI_HypothesisCreator::readParamsFromWidgets( HexoticHypothesisData& h_data ) const
215 {
216   h_data.myName          = myName ? myName->text() : "";
217   h_data.myHexesMinLevel = myHexesMinLevel->value();
218   h_data.myHexesMaxLevel = myHexesMaxLevel->value();
219   h_data.myHexoticQuadrangles = myHexoticQuadrangles->isChecked();
220   h_data.myHexoticIgnoreRidges = myHexoticIgnoreRidges->isChecked();
221   h_data.myHexoticInvalidElements = myHexoticInvalidElements->isChecked();
222   h_data.myHexoticSharpAngleThreshold = myHexoticSharpAngleThreshold->value();
223
224   return true;
225 }
226
227 QString HexoticPluginGUI_HypothesisCreator::caption() const
228 {
229   return tr( QString( "Hexotic_%1_TITLE" ).arg(myIs3D?QString("3D"):QString("3D")) );
230 }
231
232 QPixmap HexoticPluginGUI_HypothesisCreator::icon() const
233 {
234   QString hypIconName = tr( QString("ICON_DLG_Hexotic_PARAMETERS%1").arg(myIs3D?QString(""):QString("")) );
235   return SUIT_Session::session()->resourceMgr()->loadPixmap( "HexoticPlugin", hypIconName );
236 }
237
238 QString HexoticPluginGUI_HypothesisCreator::type() const
239 {
240   return tr( QString( "Hexotic_%1_HYPOTHESIS" ).arg(myIs3D?QString("3D"):QString("3D")) );
241 }