Salome HOME
Merge from V6_main (04/10/2012)
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_Hypothesis.hxx
1 // Copyright (C) 2007-2012  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     PreCAD
53   };
54
55   enum PhysicalMesh {
56     DefaultSize,
57     PhysicalUserDefined,
58     SizeMap
59   };
60
61   enum GeometricMesh {
62     DefaultGeom,
63     UserDefined
64   };
65
66   static const char* GetHypType() { return "BLSURF_Parameters"; }
67   
68   TopoDS_Shape entryToShape(std::string entry);
69
70   void SetTopology(Topology theTopology);
71   Topology GetTopology() const { return _topology; }
72
73   void SetPhysicalMesh(PhysicalMesh thePhysicalMesh);
74   PhysicalMesh GetPhysicalMesh() const { return _physicalMesh; }
75
76   void SetPhySize(double thePhySize);
77   double GetPhySize() const { return _phySize; }
78
79   void SetPhyMin(double theMinSize);
80   double GetPhyMin() const { return _phyMin; }
81
82   void SetPhyMax(double theMaxSize);
83   double GetPhyMax() const { return _phyMax; }
84
85   void SetGeometricMesh(GeometricMesh theGeometricMesh);
86   GeometricMesh GetGeometricMesh() const { return _geometricMesh; }
87
88   void SetAngleMeshS(double theAngle);
89   double GetAngleMeshS() const { return _angleMeshS; }
90
91   void SetAngleMeshC(double theAngle);
92   double GetAngleMeshC() const { return _angleMeshC; }
93
94   void SetGeoMin(double theMinSize);
95   double GetGeoMin() const { return _hgeoMin; }
96
97   void SetGeoMax(double theMaxSize);
98   double GetGeoMax() const { return _hgeoMax; }
99
100   void SetGradation(double theGradation);
101   double GetGradation() const { return _gradation; }
102
103   void SetQuadAllowed(bool theVal);
104   bool GetQuadAllowed() const { return _quadAllowed; }
105
106   void SetDecimesh(bool theVal);
107   bool GetDecimesh() const { return _decimesh; }
108
109   void SetVerbosity(int theVal);
110   int GetVerbosity() const { return _verb; }
111   
112   void ClearEntry(const std::string& entry);
113   void ClearSizeMaps();
114
115   void SetPreCADMergeEdges(bool theVal);
116   bool GetPreCADMergeEdges() const { return _preCADMergeEdges; }
117
118   void SetPreCADRemoveNanoEdges(bool theVal);
119   bool GetPreCADRemoveNanoEdges() const { return _preCADRemoveNanoEdges; }
120
121   void SetPreCADDiscardInput(bool theVal);
122   bool GetPreCADDiscardInput() const { return _preCADDiscardInput; }
123
124   void SetPreCADEpsNano(double theVal);
125   double GetPreCADEpsNano() const { return _preCADEpsNano; }
126     
127   typedef std::map<std::string,std::string> TSizeMap;
128
129   void SetSizeMapEntry(const std::string& entry,const std::string& sizeMap );
130   std::string  GetSizeMapEntry(const std::string& entry);
131   const TSizeMap& _GetSizeMapEntries() const { return _sizeMap; }
132   /*!
133    * \brief Return the size maps
134    */
135   static TSizeMap GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp);
136
137
138   void SetAttractorEntry(const std::string& entry,const std::string& attractor );
139   std::string GetAttractorEntry(const std::string& entry);
140   const TSizeMap& _GetAttractorEntries() const { return _attractors; };
141   /*!
142    * \brief Return the attractors
143    */
144   static TSizeMap GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp);
145
146
147 /*
148   void SetCustomSizeMapEntry(const std::string& entry,const std::string& sizeMap );
149   std::string  GetCustomSizeMapEntry(const std::string& entry);
150   void UnsetCustomSizeMap(const std::string& entry);
151   const TSizeMap& GetCustomSizeMapEntries() const { return _customSizeMap; }
152  */
153   
154   typedef std::map< std::string, BLSURFPlugin_Attractor* > TAttractorMap;
155   typedef std::map< std::string, std::vector<double> > TParamsMap; //TODO à finir 
156   
157   void SetClassAttractorEntry(const std::string& entry, const std::string& att_entry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius);
158   std::string  GetClassAttractorEntry(const std::string& entry);
159   const TAttractorMap& _GetClassAttractorEntries() const { return _classAttractors; }
160   /*!
161    * \brief Return the attractors entries
162    */
163   static TAttractorMap GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp);
164
165   /*!
166    * To set/get/unset an enforced vertex
167    */
168   // Name
169   typedef std::string TEnfName;
170   // Entry
171   typedef std::string TEntry;
172   // List of entries
173   typedef std::set<TEntry> TEntryList;
174   // Group name
175   typedef std::string TEnfGroupName;
176   // Coordinates
177   typedef std::vector<double> TEnfVertexCoords;
178   typedef std::set< TEnfVertexCoords > TEnfVertexCoordsList;
179
180   // Enforced vertex
181   struct TEnfVertex {
182     TEnfName name;
183     TEntry geomEntry;
184     TEnfVertexCoords coords;
185     TEnfGroupName grpName;
186     TEntryList faceEntries;
187     TopoDS_Vertex vertex;
188   };
189     
190   struct CompareEnfVertices
191   {
192     bool operator () (const TEnfVertex* e1, const TEnfVertex* e2) const {
193       if (e1 && e2) {
194         if (e1->coords.size() && e2->coords.size())
195           return (e1->coords < e2->coords);
196         else
197           return (e1->geomEntry < e2->geomEntry);
198       }
199       return false;
200     }
201   };
202
203   // List of enforced vertices
204   typedef std::set< TEnfVertex*, CompareEnfVertices > TEnfVertexList;
205
206   // Map Face Entry / List of enforced vertices
207   typedef std::map< TEntry, TEnfVertexList > TFaceEntryEnfVertexListMap;
208
209   // List of Face Entry with internal enforced vertices activated
210   typedef std::set< TEntry > TFaceEntryInternalVerticesList;
211
212   // Map Face Entry / List of coords
213   typedef std::map< TEntry, TEnfVertexCoordsList > TFaceEntryCoordsListMap;
214
215   // Map Face Entry / List of Vertex entry
216   typedef std::map< TEntry, TEntryList > TFaceEntryEnfVertexEntryListMap;
217   
218   // Map Coords / Enforced vertex
219   typedef std::map< TEnfVertexCoords, TEnfVertex* > TCoordsEnfVertexMap;
220
221   // Map Vertex entry / Enforced vertex
222   typedef std::map< TEntry, TEnfVertex* > TEnfVertexEntryEnfVertexMap;
223
224   typedef std::map< TEnfGroupName, std::set<int> > TGroupNameNodeIDMap;
225   /* TODO GROUPS
226   // Map Group Name / List of enforced vertices
227   typedef std::map< TEnfGroupName , TEnfVertexList > TGroupNameEnfVertexListMap;
228   */
229
230   
231   bool                  SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry, TEnfGroupName theGroupName,
232                                           double x = 0.0, double y = 0.0, double z = 0.0);
233   TEnfVertexList        GetEnfVertexList(const TEntry& theFaceEntry) throw (std::invalid_argument);
234   TEnfVertexCoordsList  GetEnfVertexCoordsList(const TEntry& theFaceEntry) throw (std::invalid_argument);
235   TEntryList            GetEnfVertexEntryList (const TEntry& theFaceEntry) throw (std::invalid_argument);
236   TEnfVertex*           GetEnfVertex(TEnfVertexCoords coords) throw (std::invalid_argument);
237   TEnfVertex*           GetEnfVertex(const TEntry& theEnfVertexEntry) throw (std::invalid_argument);
238   void                  AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID);
239   std::set<int>         GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument);
240   void                  RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument);
241   
242   bool ClearEnforcedVertex(const TEntry& theFaceEntry, double x = 0.0, double y = 0.0, double z = 0.0, const TEntry& theVertexEntry="") throw (std::invalid_argument);
243   bool ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument);
244
245   void ClearAllEnforcedVertices();
246
247   const TFaceEntryEnfVertexListMap  _GetAllEnforcedVerticesByFace() const { return _faceEntryEnfVertexListMap; }
248   const TEnfVertexList              _GetAllEnforcedVertices() const { return _enfVertexList; }
249
250   const TFaceEntryCoordsListMap     _GetAllCoordsByFace() const { return _faceEntryCoordsListMap; }
251   const TCoordsEnfVertexMap         _GetAllEnforcedVerticesByCoords() const { return _coordsEnfVertexMap; }
252
253   const TFaceEntryEnfVertexEntryListMap _GetAllEnfVertexEntriesByFace() const { return _faceEntryEnfVertexEntryListMap; }
254   const TEnfVertexEntryEnfVertexMap     _GetAllEnforcedVerticesByEnfVertexEntry() const { return _enfVertexEntryEnfVertexMap; }
255
256 //   TODO GROUPS
257 //   const TEnfVertexGroupNameMap _GetEnforcedVertexGroupNameMap() const { return _enfVertexGroupNameMap; }
258   
259
260   /*!
261    * \brief Return the enforced vertices
262    */
263   static TFaceEntryEnfVertexListMap       GetAllEnforcedVerticesByFace(const BLSURFPlugin_Hypothesis* hyp);
264   static TEnfVertexList                   GetAllEnforcedVertices(const BLSURFPlugin_Hypothesis* hyp);
265
266   static TFaceEntryCoordsListMap          GetAllCoordsByFace(const BLSURFPlugin_Hypothesis* hyp);
267   static TCoordsEnfVertexMap              GetAllEnforcedVerticesByCoords(const BLSURFPlugin_Hypothesis* hyp);
268
269   static TFaceEntryEnfVertexEntryListMap  GetAllEnfVertexEntriesByFace(const BLSURFPlugin_Hypothesis* hyp);
270   static TEnfVertexEntryEnfVertexMap      GetAllEnforcedVerticesByEnfVertexEntry(const BLSURFPlugin_Hypothesis* hyp);
271
272   /*!
273    * \brief Internal enforced vertices
274    */
275   void SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices);
276   const bool _GetInternalEnforcedVertexAllFaces() const { return _enforcedInternalVerticesAllFaces; }
277   static bool GetInternalEnforcedVertexAllFaces( const BLSURFPlugin_Hypothesis* hyp );
278   void SetInternalEnforcedVertexAllFacesGroup(TEnfGroupName theGroupName);
279   const TEnfGroupName _GetInternalEnforcedVertexAllFacesGroup() const { return _enforcedInternalVerticesAllFacesGroup; }
280   static TEnfGroupName GetInternalEnforcedVertexAllFacesGroup( const BLSURFPlugin_Hypothesis* hyp );
281
282 //  Enable internal enforced vertices on specific face if requested by user
283 //  static TFaceEntryInternalVerticesList GetDefaultFaceEntryInternalVerticesMap() { return TFaceEntryInternalVerticesList(); }
284 //  const TFaceEntryInternalVerticesList  _GetAllInternalEnforcedVerticesByFace() const { return _faceEntryInternalVerticesList; }
285 //  static TFaceEntryInternalVerticesList GetAllInternalEnforcedVerticesByFace(const BLSURFPlugin_Hypothesis* hyp);
286 //  void SetInternalEnforcedVertex(TEntry theFaceEntry, bool toEnforceInternalVertices, TEnfGroupName theGroupName);
287 //  bool GetInternalEnforcedVertex(const TEntry& theFaceEntry);
288
289   static Topology        GetDefaultTopology();
290   static PhysicalMesh    GetDefaultPhysicalMesh();
291   static double          GetDefaultPhySize();
292   static double          GetDefaultMaxSize();
293   static double          GetDefaultMinSize();
294   static GeometricMesh   GetDefaultGeometricMesh();
295   static double          GetDefaultAngleMeshS();
296   static double          GetDefaultAngleMeshC() { return GetDefaultAngleMeshS(); }
297   static double          GetDefaultGradation();
298   static bool            GetDefaultQuadAllowed();
299   static bool            GetDefaultDecimesh();
300   static int             GetDefaultVerbosity() { return 10; }
301   // PreCAD
302   static bool            GetDefaultPreCADMergeEdges() { return false; }
303   static bool            GetDefaultPreCADRemoveNanoEdges() { return false; }
304   static bool            GetDefaultPreCADDiscardInput() { return false; }
305   static double          GetDefaultPreCADEpsNano();
306   
307   static TSizeMap        GetDefaultSizeMap() { return TSizeMap();}
308   static TAttractorMap   GetDefaultAttractorMap() { return TAttractorMap(); }
309
310   static TFaceEntryEnfVertexListMap       GetDefaultFaceEntryEnfVertexListMap() { return TFaceEntryEnfVertexListMap(); }
311   static TEnfVertexList                   GetDefaultEnfVertexList() { return TEnfVertexList(); }
312   static TFaceEntryCoordsListMap          GetDefaultFaceEntryCoordsListMap() { return TFaceEntryCoordsListMap(); }
313   static TCoordsEnfVertexMap              GetDefaultCoordsEnfVertexMap() { return TCoordsEnfVertexMap(); }
314   static TFaceEntryEnfVertexEntryListMap  GetDefaultFaceEntryEnfVertexEntryListMap() { return TFaceEntryEnfVertexEntryListMap(); }
315   static TEnfVertexEntryEnfVertexMap      GetDefaultEnfVertexEntryEnfVertexMap() { return TEnfVertexEntryEnfVertexMap(); }
316   static TGroupNameNodeIDMap              GetDefaultGroupNameNodeIDMap() { return TGroupNameNodeIDMap(); }
317
318   static bool            GetDefaultInternalEnforcedVertex();
319
320   /* TODO GROUPS
321   static TGroupNameEnfVertexListMap GetDefaultGroupNameEnfVertexListMap() { return TGroupNameEnfVertexListMap(); }
322   static TEnfVertexGroupNameMap     GetDefaultEnfVertexGroupNameMap() { return TEnfVertexGroupNameMap(); }
323   */
324
325   static double undefinedDouble() { return -1.0; }
326
327   typedef std::map< std::string, std::string > TOptionValues;
328   typedef std::set< std::string >              TOptionNames;
329
330   void SetOptionValue(const std::string& optionName,
331                       const std::string& optionValue) throw (std::invalid_argument);
332   void SetPreCADOptionValue(const std::string& optionName,
333                             const std::string& optionValue) throw (std::invalid_argument);
334   std::string GetOptionValue(const std::string& optionName) throw (std::invalid_argument);
335   std::string GetPreCADOptionValue(const std::string& optionName) throw (std::invalid_argument);
336   void ClearOption(const std::string& optionName);
337   void ClearPreCADOption(const std::string& optionName);
338   const TOptionValues& GetOptionValues() const { return _option2value; }
339   const TOptionValues& GetPreCADOptionValues() const { return _preCADoption2value; }
340
341   /*!
342     * Sets the file for export resulting mesh in GMF format
343     */
344 //   void SetGMFFile(const std::string& theFileName, bool isBinary);
345   void SetGMFFile(const std::string& theFileName);
346   std::string GetGMFFile() const { return _GMFFileName; }
347   static std::string GetDefaultGMFFile();
348 //   bool GetGMFFileMode() const { return _GMFFileMode; }
349   
350   // Persistence
351   virtual std::ostream & SaveTo(std::ostream & save);
352   virtual std::istream & LoadFrom(std::istream & load);
353   friend std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp);
354   friend std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp);
355
356   /*!
357    * \brief Does nothing
358    * \param theMesh - the built mesh
359    * \param theShape - the geometry of interest
360    * \retval bool - always false
361    */
362   virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
363
364   /*!
365    * \brief Initialize my parameter values by default parameters.
366    *  \retval bool - true if parameter values have been successfully defined
367    */
368   virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
369
370
371 private:
372   Topology        _topology;
373   PhysicalMesh    _physicalMesh;
374   double          _phySize, _phyMin, _phyMax;
375   GeometricMesh   _geometricMesh;
376   double          _angleMeshS, _angleMeshC, _hgeoMin, _hgeoMax;
377   double          _gradation;
378   bool            _quadAllowed;
379   bool            _decimesh;
380   int             _verb;
381   
382   bool            _preCADMergeEdges;
383   bool            _preCADRemoveNanoEdges;
384   bool            _preCADDiscardInput;
385   double          _preCADEpsNano;
386   
387   TOptionValues   _option2value, _preCADoption2value;
388   TOptionNames    _doubleOptions, _charOptions, _preCADdoubleOptions, _preCADcharOptions;
389   TSizeMap        _sizeMap;
390   TSizeMap        _attractors;
391   TAttractorMap   _classAttractors;
392   TSizeMap        _attEntry;
393   TParamsMap      _attParams;
394
395   TFaceEntryEnfVertexListMap  _faceEntryEnfVertexListMap;
396   TEnfVertexList              _enfVertexList;
397   // maps to get "manual" enf vertex (through their coordinates)
398   TFaceEntryCoordsListMap     _faceEntryCoordsListMap;
399   TCoordsEnfVertexMap         _coordsEnfVertexMap;
400   // maps to get "geom" enf vertex (through their geom entries)
401   TFaceEntryEnfVertexEntryListMap _faceEntryEnfVertexEntryListMap;
402   TEnfVertexEntryEnfVertexMap     _enfVertexEntryEnfVertexMap;
403   TGroupNameNodeIDMap             _groupNameNodeIDMap;
404   
405 //  Enable internal enforced vertices on specific face if requested by user
406 //  TFaceEntryInternalVerticesList  _faceEntryInternalVerticesList;
407   bool            _enforcedInternalVerticesAllFaces;
408   TEnfGroupName   _enforcedInternalVerticesAllFacesGroup;
409   
410   std::string     _GMFFileName;
411 //   bool            _GMFFileMode;
412
413 //   TSizeMap      _customSizeMap;
414 };
415
416 #endif