Salome HOME
Merge from BR_V5_DEV 17Feb09
[plugins/hexoticplugin.git] / src / HexoticPlugin / HexoticPlugin_Hypothesis.cxx
1 //  Copyright (C) 2007-2008  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.
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 // File   : HexoticPlugin_Hypothesis.cxx
21 // Author : Lioka RAZAFINDRAZAKA (CEA)
22 // ---
23 //
24 #include <HexoticPlugin_Hypothesis.hxx>
25 #include <utilities.h>
26
27 //=============================================================================
28 /*!
29  *  
30  */
31 //=============================================================================
32 HexoticPlugin_Hypothesis::HexoticPlugin_Hypothesis (int hypId, int studyId,
33                                                     SMESH_Gen* gen)
34   : SMESH_Hypothesis(hypId, studyId, gen),
35     _hexesMinLevel( GetDefaultHexesMinLevel() ),
36     _hexesMaxLevel( GetDefaultHexesMaxLevel() ),
37     _hexoticQuadrangles( GetDefaultHexoticQuadrangles() ),
38     _hexoticIgnoreRidges( GetDefaultHexoticIgnoreRidges() ),
39     _hexoticInvalidElements( GetDefaultHexoticInvalidElements() ), 
40     _hexoticSharpAngleThreshold( GetDefaultHexoticSharpAngleThreshold() )
41 {
42   MESSAGE("HexoticPlugin_Hypothesis::HexoticPlugin_Hypothesis");
43   _name = "Hexotic_Parameters";
44   _param_algo_dim = 3;
45 }
46
47 //=============================================================================
48 /*!
49  *  
50  */
51 //=============================================================================
52
53 void HexoticPlugin_Hypothesis::SetHexesMinLevel(int theVal) {
54   if (theVal != _hexesMinLevel) {
55     _hexesMinLevel = theVal;
56     NotifySubMeshesHypothesisModification();
57   }
58 }
59
60 void HexoticPlugin_Hypothesis::SetHexesMaxLevel(int theVal) {
61   if (theVal != _hexesMaxLevel) {
62     _hexesMaxLevel = theVal;
63     NotifySubMeshesHypothesisModification();
64   }
65 }
66
67 void HexoticPlugin_Hypothesis::SetHexoticQuadrangles(bool theVal) {
68   if (theVal != _hexoticQuadrangles) {
69     _hexoticQuadrangles = theVal;
70     NotifySubMeshesHypothesisModification();
71   }
72 }
73
74 void HexoticPlugin_Hypothesis::SetHexoticIgnoreRidges(bool theVal) {
75   if (theVal != _hexoticIgnoreRidges) {
76     _hexoticIgnoreRidges = theVal;
77     NotifySubMeshesHypothesisModification();
78   }
79 }
80
81 void HexoticPlugin_Hypothesis::SetHexoticInvalidElements(bool theVal) {
82   if (theVal != _hexoticInvalidElements) {
83     _hexoticInvalidElements = theVal;
84     NotifySubMeshesHypothesisModification();
85   }
86 }
87
88 void HexoticPlugin_Hypothesis::SetHexoticSharpAngleThreshold(int theVal) {
89   if (theVal != _hexoticSharpAngleThreshold) {
90     _hexoticSharpAngleThreshold = theVal;
91     NotifySubMeshesHypothesisModification();
92   }
93 }
94
95 //=============================================================================
96 /*!
97  *  
98  */
99 //=============================================================================
100 std::ostream& HexoticPlugin_Hypothesis::SaveTo(std::ostream& save)
101 {
102   /*save << _hexesMinLevel << " " << _hexesMaxLevel;
103   save << " " << (int)_hexoticQuadrangles;
104   save << " " << (int)_hexoticIgnoreRidges;
105   save << " " << (int)_hexoticInvalidElements;
106   save << " " << _hexoticSharpAngleThreshold;
107   std::cout <<std::endl;
108   std::cout << "save : " << save << std::endl;
109   std::cout << std::endl;*/
110
111   //explicit outputs for future code compatibility of saved .hdf
112   //save without any whitespaces!
113   save<<"hexesMinLevel="<<_hexesMinLevel<<";"; 
114   save<<"hexesMaxLevel="<<_hexesMaxLevel<<";";
115   save<<"hexoticQuadrangles="<<(int)_hexoticQuadrangles<<";";
116   save<<"hexoticIgnoreRidges="<<(int)_hexoticIgnoreRidges<<";";
117   save<<"hexoticInvalidElements="<<(int)_hexoticInvalidElements<<";";
118   save<<"hexoticSharpAngleThreshold="<<_hexoticSharpAngleThreshold<<";";
119   return save;
120 }
121
122 //=============================================================================
123 /*!
124  *  
125  */
126 //=============================================================================
127 std::istream& HexoticPlugin_Hypothesis::LoadFrom(std::istream& load)
128 {
129    //explicit inputs for future code compatibility of saved .hdf
130    bool isOK = true;
131    std::string str1,str2,str3,str4;
132
133    //save without any whitespaces!
134    isOK = (load >> str1);
135    if (!(isOK)) {
136      //defaults values assumed
137      load.clear(std::ios::badbit | load.rdstate());
138      return load;
139    }
140    int pos = 0;
141    int len = str1.length();
142    while (pos < len) {
143       int found = str1.find(';',pos);
144       str2 = str1.substr(pos,found-pos);
145       int eqpos = str2.find('=',0);
146       str3 = str2.substr(0,eqpos);
147       str4 = str2.substr(eqpos+1);
148       pos = found + 1;
149
150       if (str3=="hexesMinLevel") _hexesMinLevel = atoi(str4.c_str());
151       if (str3=="hexesMaxLevel") _hexesMaxLevel = atoi(str4.c_str());
152       if (str3=="hexoticQuadrangles") _hexoticQuadrangles = (bool) atoi(str4.c_str());
153       if (str3=="hexoticIgnoreRidges") _hexoticIgnoreRidges = (bool) atoi(str4.c_str());
154       if (str3=="hexoticInvalidElements") _hexoticInvalidElements = (bool) atoi(str4.c_str());
155       if (str3=="hexoticSharpAngleThreshold") _hexoticSharpAngleThreshold = atoi(str4.c_str());
156    }
157    return load;
158 }
159
160 //=============================================================================
161 /*!
162  *  
163  */
164 //=============================================================================
165 std::ostream& operator <<(std::ostream& save, HexoticPlugin_Hypothesis& hyp)
166 {
167   return hyp.SaveTo( save );
168 }
169
170 //=============================================================================
171 /*!
172  *  
173  */
174 //=============================================================================
175 std::istream& operator >>(std::istream& load, HexoticPlugin_Hypothesis& hyp)
176 {
177   return hyp.LoadFrom( load );
178 }
179
180
181 //================================================================================
182 /*!
183  * \brief Does nothing
184  * \param theMesh - the built mesh
185  * \param theShape - the geometry of interest
186  * \retval bool - always false
187  */
188 //================================================================================
189 bool HexoticPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   theMesh,
190                                                    const TopoDS_Shape& theShape)
191 {
192   return false;
193 }
194 //================================================================================
195 /*!
196  * \brief Initialize my parameter values by default parameters.
197  *  \retval bool - true if parameter values have been successfully defined
198  */
199 //================================================================================
200
201 bool HexoticPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  /*dflts*/,
202                                                        const SMESH_Mesh* /*theMesh*/)
203 {
204   return false;
205 }
206
207 //=============================================================================
208 int HexoticPlugin_Hypothesis::GetDefaultHexesMinLevel()
209 {
210   return 3;
211 }
212
213 int HexoticPlugin_Hypothesis::GetDefaultHexesMaxLevel()
214 {
215   return 8;
216 }
217
218 bool HexoticPlugin_Hypothesis::GetDefaultHexoticQuadrangles()
219 {
220   return true;
221 }
222
223 bool HexoticPlugin_Hypothesis::GetDefaultHexoticIgnoreRidges()
224 {
225   return false;
226 }
227
228 bool HexoticPlugin_Hypothesis::GetDefaultHexoticInvalidElements()
229 {
230   return false;
231 }
232
233 int HexoticPlugin_Hypothesis::GetDefaultHexoticSharpAngleThreshold()
234 {
235   return 60;
236 }