Salome HOME
Import a new plugin, sent by Stephane LIAUZU
[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 <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 Fineness
51    {
52      VeryCoarse,
53      Coarse,
54      Moderate,
55      Fine,
56      VeryFine,
57      UserDefined
58    };
59
60 HexoticPluginGUI_HypothesisCreator::HexoticPluginGUI_HypothesisCreator( const QString& theHypType )
61 : SMESHGUI_GenericHypothesisCreator( theHypType ),
62   myIs3D(true)
63 {
64 }
65
66 HexoticPluginGUI_HypothesisCreator::~HexoticPluginGUI_HypothesisCreator()
67 {
68 }
69
70 bool HexoticPluginGUI_HypothesisCreator::checkParams() const
71 {
72   HexoticHypothesisData data_old, data_new;
73   readParamsFromHypo( data_old );
74   readParamsFromWidgets( data_new );
75   bool res = storeParamsToHypo( data_new );
76   return res;
77 }
78
79 QFrame* HexoticPluginGUI_HypothesisCreator::buildFrame()
80 {
81   QFrame* fr = new QFrame( 0, "myframe" );
82   QVBoxLayout* lay = new QVBoxLayout( fr, 5, 0 );
83
84   QGroupBox* GroupC1 = new QGroupBox( 2, Qt::Horizontal, fr, "GroupC1" );
85   lay->addWidget( GroupC1 );
86   
87   GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) );
88   GroupC1->layout()->setSpacing( 6 );
89   GroupC1->layout()->setMargin( 11 );
90   
91   myName = 0;
92   if( isCreation() ) {
93     new QLabel( tr( "SMESH_NAME" ), GroupC1 );
94     myName = new QLineEdit( GroupC1 );
95   }
96
97   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
98   HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( initParamsHypothesis() );
99
100   new QLabel( tr( "Hexotic_HEXES_MIN_LEVEL" ), GroupC1 );
101   myHexesMinLevel = new QtxIntSpinBox( GroupC1 );
102   // myHexesMinLevel->setMinValue( 3 );
103   myHexesMinLevel->setMinValue( h->GetHexesMinLevel() );
104   myHexesMinLevel->setMaxValue( 8 );
105   myHexesMinLevel->setLineStep( 1 );
106   
107   new QLabel( tr( "Hexotic_HEXES_MAX_LEVEL" ), GroupC1 );
108   myHexesMaxLevel = new QtxIntSpinBox( GroupC1 );
109   myHexesMaxLevel->setMinValue( 3 );
110   myHexesMaxLevel->setMaxValue( 8 );
111   myHexesMaxLevel->setLineStep( 1 );
112
113   myHexoticQuadrangles = new QCheckBox( tr( "Hexotic_QUADRANGLES" ), GroupC1 );
114   GroupC1->addSpace(0);
115   myIs3D = true;
116   
117   return fr;
118 }
119
120 void HexoticPluginGUI_HypothesisCreator::retrieveParams() const
121 {
122   HexoticHypothesisData data;
123   readParamsFromHypo( data );
124
125   if( myName )
126     myName->setText( data.myName );
127   myHexesMinLevel->setValue( data.myHexesMinLevel );
128   myHexesMaxLevel->setValue( data.myHexesMaxLevel );
129   myHexoticQuadrangles->setChecked( data.myHexoticQuadrangles );
130
131   myHexesMinLevel->setEnabled(true);
132   myHexesMaxLevel->setEnabled(true);
133 }
134
135 QString HexoticPluginGUI_HypothesisCreator::storeParams() const
136 {
137   HexoticHypothesisData data;
138   readParamsFromWidgets( data );
139   storeParamsToHypo( data );
140
141   QString valStr;
142   valStr += tr("Hexotic_SEG_MIN_SIZE") + " = " + QString::number( data.myHexesMinLevel )   + "; ";
143   valStr += tr("Hexotic_SEG_MAX_SIZE") + " = " + QString::number( data.myHexesMaxLevel ) + "; ";
144   valStr += tr("Hexotic_QUADRANGLES")  + " = " + QString::number( data.myHexoticQuadrangles ) + "; ";
145   
146   return valStr;
147 }
148
149 bool HexoticPluginGUI_HypothesisCreator::readParamsFromHypo( HexoticHypothesisData& h_data ) const
150 {
151   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
152     HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( initParamsHypothesis() );
153
154   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
155   h_data.myName = isCreation() && data ? data->Label : "";
156   h_data.myHexesMinLevel = h->GetHexesMinLevel();
157   h_data.myHexesMaxLevel = h->GetHexesMaxLevel();
158   h_data.myHexoticQuadrangles = h->GetHexoticQuadrangles();
159
160   return true;
161 }
162
163 bool HexoticPluginGUI_HypothesisCreator::storeParamsToHypo( const HexoticHypothesisData& h_data ) const
164 {
165   HexoticPlugin::HexoticPlugin_Hypothesis_var h =
166     HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( hypothesis() );
167
168   bool ok = true;
169   try
170   {
171     if( isCreation() )
172       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.latin1() );
173
174     h->SetHexesMinLevel( h_data.myHexesMinLevel );
175     h->SetHexesMaxLevel( h_data.myHexesMaxLevel );
176     h->SetHexoticQuadrangles( h_data.myHexoticQuadrangles );
177   }
178   catch(const SALOME::SALOME_Exception& ex)
179   {
180     SalomeApp_Tools::QtCatchCorbaException(ex);
181     ok = false;
182   }
183   return ok;
184 }
185
186 bool HexoticPluginGUI_HypothesisCreator::readParamsFromWidgets( HexoticHypothesisData& h_data ) const
187 {
188   h_data.myName          = myName ? myName->text() : "";
189   h_data.myHexesMinLevel = myHexesMinLevel->value();
190   h_data.myHexesMaxLevel = myHexesMaxLevel->value();
191   h_data.myHexoticQuadrangles = myHexoticQuadrangles->isChecked();
192   
193   return true;
194 }
195
196 QString HexoticPluginGUI_HypothesisCreator::caption() const
197 {
198   return tr( QString( "Hexotic_%1_TITLE" ).arg(myIs3D?QString("3D"):QString("3D")) );
199 }
200
201 QPixmap HexoticPluginGUI_HypothesisCreator::icon() const
202 {
203   QString hypIconName = tr( QString("ICON_DLG_Hexotic_PARAMETERS%1").arg(myIs3D?QString(""):QString("")) );
204   return SUIT_Session::session()->resourceMgr()->loadPixmap( "HexoticPlugin", hypIconName );
205 }
206
207 QString HexoticPluginGUI_HypothesisCreator::type() const
208 {
209   return tr( QString( "Hexotic_%1_HYPOTHESIS" ).arg(myIs3D?QString("3D"):QString("3D")) );
210 }