Salome HOME
Update copyright
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_Hypothesis.hxx
1 // Copyright (C) 2007-2011  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 // ---
21 // File    : BLSURFPlugin_Hypothesis.hxx
22 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
23 //           & Aurelien ALLEAUME (DISTENE)
24 //           Size maps developement: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
25 // ---
26 //
27 #ifndef _BLSURFPlugin_Hypothesis_HXX_
28 #define _BLSURFPlugin_Hypothesis_HXX_
29
30 #include "SMESH_Hypothesis.hxx"
31 #include <vector>
32 #include <map>
33 #include <set>
34 #include <stdexcept>
35 #include <string>
36 #include <cstring>
37 #include <sstream>
38 #include <utilities.h>
39 #include "BLSURFPlugin_Attractor.hxx"
40
41 //  Parameters for work of BLSURF
42
43 class BLSURFPlugin_Hypothesis: public SMESH_Hypothesis
44 {
45 public:
46   BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen);
47
48   enum Topology {
49     FromCAD,
50     Process,
51     Process2
52   };
53
54   enum PhysicalMesh {
55     DefaultSize,
56     PhysicalUserDefined
57   };
58
59   enum GeometricMesh {
60     DefaultGeom,
61     UserDefined
62   };
63   
64   TopoDS_Shape entryToShape(std::string entry);
65
66   void SetTopology(Topology theTopology);
67   Topology GetTopology() const { return _topology; }
68
69   void SetPhysicalMesh(PhysicalMesh thePhysicalMesh);
70   PhysicalMesh GetPhysicalMesh() const { return _physicalMesh; }
71
72   void SetPhySize(double thePhySize);
73   double GetPhySize() const { return _phySize; }
74
75   void SetPhyMin(double theMinSize);
76   double GetPhyMin() const { return _phyMin; }
77
78   void SetPhyMax(double theMaxSize);
79   double GetPhyMax() const { return _phyMax; }
80
81   void SetGeometricMesh(GeometricMesh theGeometricMesh);
82   GeometricMesh GetGeometricMesh() const { return _geometricMesh; }
83
84   void SetAngleMeshS(double theAngle);
85   double GetAngleMeshS() const { return _angleMeshS; }
86
87   void SetAngleMeshC(double theAngle);
88   double GetAngleMeshC() const { return _angleMeshC; }
89
90   void SetGeoMin(double theMinSize);
91   double GetGeoMin() const { return _hgeoMin; }
92
93   void SetGeoMax(double theMaxSize);
94   double GetGeoMax() const { return _hgeoMax; }
95
96   void SetGradation(double theGradation);
97   double GetGradation() const { return _gradation; }
98
99   void SetQuadAllowed(bool theVal);
100   bool GetQuadAllowed() const { return _quadAllowed; }
101
102   void SetDecimesh(bool theVal);
103   bool GetDecimesh() const { return _decimesh; }
104
105   void SetVerbosity(int theVal);
106   int GetVerbosity() const { return _verb; }
107   
108   void ClearEntry(const std::string& entry);
109   void ClearSizeMaps();
110
111   typedef std::map<std::string,std::string> TSizeMap;
112
113   void SetSizeMapEntry(const std::string& entry,const std::string& sizeMap );
114   std::string  GetSizeMapEntry(const std::string& entry);
115   const TSizeMap& _GetSizeMapEntries() const { return _sizeMap; }
116   /*!
117    * \brief Return the size maps
118    */
119   static TSizeMap GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp);
120
121
122   void SetAttractorEntry(const std::string& entry,const std::string& attractor );
123   std::string GetAttractorEntry(const std::string& entry);
124   const TSizeMap& _GetAttractorEntries() const { return _attractors; };
125   /*!
126    * \brief Return the attractors
127    */
128   static TSizeMap GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp);
129
130
131 /*
132   void SetCustomSizeMapEntry(const std::string& entry,const std::string& sizeMap );
133   std::string  GetCustomSizeMapEntry(const std::string& entry);
134   void UnsetCustomSizeMap(const std::string& entry);
135   const TSizeMap& GetCustomSizeMapEntries() const { return _customSizeMap; }
136  */
137   
138   typedef std::map< std::string, BLSURFPlugin_Attractor* > TAttractorMap;
139   typedef std::map< std::string, std::vector<double> > TParamsMap; //TODO à finir 
140   
141   void SetClassAttractorEntry(const std::string& entry, const std::string& att_entry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius);
142   std::string  GetClassAttractorEntry(const std::string& entry);
143   const TAttractorMap& _GetClassAttractorEntries() const { return _classAttractors; }
144   /*!
145    * \brief Return the attractors entries
146    */
147   static TAttractorMap GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp);
148
149   /*!
150    * To set/get/unset an enforced vertex
151    */
152   // Name
153   typedef std::string TEnfName;
154   // Entry
155   typedef std::string TEntry;
156   // List of entries
157   typedef std::set<TEntry> TEntryList;
158   // Group name
159   typedef std::string TEnfGroupName;
160   // Coordinates
161   typedef std::vector<double> TEnfVertexCoords;
162   typedef std::set< TEnfVertexCoords > TEnfVertexCoordsList;
163
164   // Enforced vertex
165   struct TEnfVertex {
166     TEnfName name;
167     TEntry geomEntry;
168     TEnfVertexCoords coords;
169     TEnfGroupName grpName;
170     TEntryList faceEntries;
171   };
172     
173   struct CompareEnfVertices
174   {
175     bool operator () (const TEnfVertex* e1, const TEnfVertex* e2) const {
176       if (e1 && e2) {
177         if (e1->coords.size() && e2->coords.size())
178           return (e1->coords < e2->coords);
179         else
180           return (e1->geomEntry < e2->geomEntry);
181       }
182       return false;
183     }
184   };
185
186   // List of enforced vertices
187   typedef std::set< TEnfVertex*, CompareEnfVertices > TEnfVertexList;
188
189   // Map Face Entry / List of enforced vertices
190   typedef std::map< TEntry, TEnfVertexList > TFaceEntryEnfVertexListMap;
191
192   // Map Face Entry / List of coords
193   typedef std::map< TEntry, TEnfVertexCoordsList > TFaceEntryCoordsListMap;
194
195   // Map Face Entry / List of Vertex entry
196   typedef std::map< TEntry, TEntryList > TFaceEntryEnfVertexEntryListMap;
197   
198   // Map Coords / Enforced vertex
199   typedef std::map< TEnfVertexCoords, TEnfVertex* > TCoordsEnfVertexMap;
200
201   // Map Vertex entry / Enforced vertex
202   typedef std::map< TEntry, TEnfVertex* > TEnfVertexEntryEnfVertexMap;
203
204   typedef std::map< TEnfGroupName, std::set<int> > TGroupNameNodeIDMap;
205   /* TODO GROUPS
206   // Map Group Name / List of enforced vertices
207   typedef std::map< TEnfGroupName , TEnfVertexList > TGroupNameEnfVertexListMap;
208   */
209
210   
211   bool                  SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry, TEnfGroupName theGroupName,
212                                           double x = 0.0, double y = 0.0, double z = 0.0);
213   TEnfVertexList        GetEnfVertexList(const TEntry& theFaceEntry) throw (std::invalid_argument);
214   TEnfVertexCoordsList  GetEnfVertexCoordsList(const TEntry& theFaceEntry) throw (std::invalid_argument);
215   TEntryList            GetEnfVertexEntryList (const TEntry& theFaceEntry) throw (std::invalid_argument);
216   TEnfVertex*           GetEnfVertex(TEnfVertexCoords coords) throw (std::invalid_argument);
217   TEnfVertex*           GetEnfVertex(const TEntry& theEnfVertexEntry) throw (std::invalid_argument);
218   void                  AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID);
219   std::set<int>         GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument);
220   void                  RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument);
221   
222   bool ClearEnforcedVertex(const TEntry& theFaceEntry, double x = 0.0, double y = 0.0, double z = 0.0, const TEntry& theVertexEntry="") throw (std::invalid_argument);
223   bool ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument);
224
225   void ClearAllEnforcedVertices();
226
227   const TFaceEntryEnfVertexListMap  _GetAllEnforcedVerticesByFace() const { return _faceEntryEnfVertexListMap; }
228   const TEnfVertexList              _GetAllEnforcedVertices() const { return _enfVertexList; }
229
230   const TFaceEntryCoordsListMap     _GetAllCoordsByFace() const { return _faceEntryCoordsListMap; }
231   const TCoordsEnfVertexMap         _GetAllEnforcedVerticesByCoords() const { return _coordsEnfVertexMap; }
232
233   const TFaceEntryEnfVertexEntryListMap _GetAllEnfVertexEntriesByFace() const { return _faceEntryEnfVertexEntryListMap; }
234   const TEnfVertexEntryEnfVertexMap     _GetAllEnforcedVerticesByEnfVertexEntry() const { return _enfVertexEntryEnfVertexMap; }
235
236 //   TODO GROUPS
237 //   const TEnfVertexGroupNameMap _GetEnforcedVertexGroupNameMap() const { return _enfVertexGroupNameMap; }
238   
239
240   /*!
241    * \brief Return the enforced vertices
242    */
243   static TFaceEntryEnfVertexListMap       GetAllEnforcedVerticesByFace(const BLSURFPlugin_Hypothesis* hyp);
244   static TEnfVertexList                   GetAllEnforcedVertices(const BLSURFPlugin_Hypothesis* hyp);
245
246   static TFaceEntryCoordsListMap          GetAllCoordsByFace(const BLSURFPlugin_Hypothesis* hyp);
247   static TCoordsEnfVertexMap              GetAllEnforcedVerticesByCoords(const BLSURFPlugin_Hypothesis* hyp);
248
249   static TFaceEntryEnfVertexEntryListMap  GetAllEnfVertexEntriesByFace(const BLSURFPlugin_Hypothesis* hyp);
250   static TEnfVertexEntryEnfVertexMap      GetAllEnforcedVerticesByEnfVertexEntry(const BLSURFPlugin_Hypothesis* hyp);
251
252   
253   /*!
254     * \brief Set/get node group to an enforced vertex
255     */
256   /* TODO GROUPS
257   void SetEnforcedVertexGroupName(double x, double y, double z, const TEnfGroupName& groupName) throw (std::invalid_argument);
258   TEnfGroupName GetEnforcedVertexGroupName(double x, double y, double z) throw (std::invalid_argument);
259   TEnfVertexList GetEnforcedVertexByGroupName(TEnfGroupName& groupName) throw (std::invalid_argument);
260   */
261
262   static Topology        GetDefaultTopology();
263   static PhysicalMesh    GetDefaultPhysicalMesh();
264   static double          GetDefaultPhySize();
265   static double          GetDefaultMaxSize();
266   static double          GetDefaultMinSize();
267   static GeometricMesh   GetDefaultGeometricMesh();
268   static double          GetDefaultAngleMeshS();
269   static double          GetDefaultAngleMeshC() { return GetDefaultAngleMeshS(); }
270   static double          GetDefaultGradation();
271   static bool            GetDefaultQuadAllowed();
272   static bool            GetDefaultDecimesh();
273   static int             GetDefaultVerbosity() { return 10; }
274   static TSizeMap        GetDefaultSizeMap() { return TSizeMap();}
275   static TAttractorMap   GetDefaultAttractorMap() { return TAttractorMap(); }
276
277   static TFaceEntryEnfVertexListMap       GetDefaultFaceEntryEnfVertexListMap() { return TFaceEntryEnfVertexListMap(); }
278   static TEnfVertexList                   GetDefaultEnfVertexList() { return TEnfVertexList(); }
279   static TFaceEntryCoordsListMap          GetDefaultFaceEntryCoordsListMap() { return TFaceEntryCoordsListMap(); }
280   static TCoordsEnfVertexMap              GetDefaultCoordsEnfVertexMap() { return TCoordsEnfVertexMap(); }
281   static TFaceEntryEnfVertexEntryListMap  GetDefaultFaceEntryEnfVertexEntryListMap() { return TFaceEntryEnfVertexEntryListMap(); }
282   static TEnfVertexEntryEnfVertexMap      GetDefaultEnfVertexEntryEnfVertexMap() { return TEnfVertexEntryEnfVertexMap(); }
283   static TGroupNameNodeIDMap              GetDefaultGroupNameNodeIDMap() { return TGroupNameNodeIDMap(); }
284
285   /* TODO GROUPS
286   static TGroupNameEnfVertexListMap GetDefaultGroupNameEnfVertexListMap() { return TGroupNameEnfVertexListMap(); }
287   static TEnfVertexGroupNameMap     GetDefaultEnfVertexGroupNameMap() { return TEnfVertexGroupNameMap(); }
288   */
289
290   static double undefinedDouble() { return -1.0; }
291
292   typedef std::map< std::string, std::string > TOptionValues;
293   typedef std::set< std::string >              TOptionNames;
294
295   void SetOptionValue(const std::string& optionName,
296                       const std::string& optionValue) throw (std::invalid_argument);
297   std::string GetOptionValue(const std::string& optionName) throw (std::invalid_argument);
298   void ClearOption(const std::string& optionName);
299   const TOptionValues& GetOptionValues() const { return _option2value; }
300
301   // Persistence
302   virtual std::ostream & SaveTo(std::ostream & save);
303   virtual std::istream & LoadFrom(std::istream & load);
304   friend std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp);
305   friend std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp);
306
307   /*!
308    * \brief Does nothing
309    * \param theMesh - the built mesh
310    * \param theShape - the geometry of interest
311    * \retval bool - always false
312    */
313   virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
314
315   /*!
316    * \brief Initialize my parameter values by default parameters.
317    *  \retval bool - true if parameter values have been successfully defined
318    */
319   virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
320
321
322 private:
323   Topology        _topology;
324   PhysicalMesh    _physicalMesh;
325   double          _phySize, _phyMin, _phyMax;
326   GeometricMesh   _geometricMesh;
327   double          _angleMeshS, _angleMeshC, _hgeoMin, _hgeoMax;
328   double          _gradation;
329   bool            _quadAllowed;
330   bool            _decimesh;
331   int             _verb;
332   TOptionValues   _option2value;
333   TOptionNames    _doubleOptions, _charOptions;
334   TSizeMap        _sizeMap;
335   TSizeMap        _attractors;
336   TAttractorMap   _classAttractors;
337   TSizeMap        _attEntry;
338   TParamsMap      _attParams;
339
340   TFaceEntryEnfVertexListMap  _faceEntryEnfVertexListMap;
341   TEnfVertexList              _enfVertexList;
342   // maps to get "manual" enf vertex (through their coordinates)
343   TFaceEntryCoordsListMap     _faceEntryCoordsListMap;
344   TCoordsEnfVertexMap         _coordsEnfVertexMap;
345   // maps to get "geom" enf vertex (through their geom entries)
346   TFaceEntryEnfVertexEntryListMap _faceEntryEnfVertexEntryListMap;
347   TEnfVertexEntryEnfVertexMap     _enfVertexEntryEnfVertexMap;
348   TGroupNameNodeIDMap             _groupNameNodeIDMap;
349   
350   /* TODO GROUPS
351   TGroupNameEnfVertexListMap _groupNameEnfVertexListMap;
352   */
353 //   TSizeMap      _customSizeMap;
354 };
355
356 #endif