Salome HOME
NRI : Add KERNEL includes and libs.
[modules/smesh.git] / src / SMESH / SMESH_HypothesisFactory.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : SMESH_HypothesisFactory.cxx
4 // Created   : mer mai 15 13:45:50 CEST 2002
5 // Author    : Paul RASCLE, EDF
6 // Project   : SALOME
7 // Copyright : EDF 2002
8 // $Header$
9 //=============================================================================
10 using namespace std;
11
12 #include "SMESH_HypothesisFactory.hxx"
13 #include "SMESH_Hypothesis.hxx"
14 #include "SMESH_HypothesisCreator.hxx"
15 #include "SMESH_Gen.hxx"
16
17 #include "utilities.h"
18
19 // Add new hypothesis here (include file)
20 //---------------------------------------
21 #include "SMESH_LocalLength.hxx"
22 #include "SMESH_LengthFromEdges.hxx"
23 #include "SMESH_NumberOfSegments.hxx"
24 #include "SMESH_MaxElementArea.hxx"
25 #include "SMESH_Regular_1D.hxx"
26 #include "SMESH_MEFISTO_2D.hxx"
27 #include "SMESH_Quadrangle_2D.hxx"
28 #include "SMESH_Hexa_3D.hxx"
29
30 //---------------------------------------
31
32 //=============================================================================
33 /*!
34  * Specific Hypothesis Creators are generated with a template which inherits a
35  * generic hypothesis creator. Each creator returns an hypothesis of the type
36  * given in the template. 
37  */
38 //=============================================================================
39
40 // template <class T> class HypothesisCreator: public GenericHypothesisCreator
41 // {
42 // public:
43 //   virtual T* Create (int hypId)
44 //   {
45 // //     return new T(hypId);
46 //   };
47
48 // };
49
50 //=============================================================================
51 /*!
52  * Constructor: instanciate specific hypothesis creators, fill a private map
53  * indexed by hypothesis names. THIS METHOD MUST BE COMPLETED WHEN A NEW
54  * HYPOTHESIS IS ADDED. 
55  * Specific hypothesis creator are defined with the above template.
56  * Hypothesis names are related to the corresponding class names:
57  * prefix = SMESH_ ; suffix = .
58  */
59 //=============================================================================
60
61 SMESH_HypothesisFactory::SMESH_HypothesisFactory()
62 {
63   _hypId = 0;
64
65 // Add new hypothesis here (creators)
66 //---------------------------------------
67 _creatorMap["LocalLength"] = new SMESH_HypothesisCreator<SMESH_LocalLength>;
68 _creatorMap["NumberOfSegments"] = new SMESH_HypothesisCreator<SMESH_NumberOfSegments>;
69 _creatorMap["LengthFromEdges"] = new SMESH_HypothesisCreator<SMESH_LengthFromEdges>;
70 _creatorMap["MaxElementArea"] = new SMESH_HypothesisCreator<SMESH_MaxElementArea>;
71 _creatorMap["Regular_1D"] = new SMESH_HypothesisCreator<SMESH_Regular_1D>;
72 _creatorMap["MEFISTO_2D"] = new SMESH_HypothesisCreator<SMESH_MEFISTO_2D>;
73 _creatorMap["Quadrangle_2D"] = new SMESH_HypothesisCreator<SMESH_Quadrangle_2D>;
74 _creatorMap["Hexa_3D"] = new SMESH_HypothesisCreator<SMESH_Hexa_3D>;
75
76 //---------------------------------------
77 }
78
79 //=============================================================================
80 /*!
81  * Destructor: deletes specific hypothesis creators instanciated in the
82  * constructor.
83  */
84 //=============================================================================
85
86 SMESH_HypothesisFactory::~SMESH_HypothesisFactory()
87 {
88   map<string, GenericHypothesisCreator*>::iterator it;
89   for (it = _creatorMap.begin(); it !=  _creatorMap.end(); it++)
90     {
91       delete (*it).second;
92     }
93   _creatorMap.clear();
94 }
95
96 //=============================================================================
97 /*!
98  *
99  */
100 //=============================================================================
101
102 SMESH_Hypothesis* SMESH_HypothesisFactory::Create(const char* anHypName,
103                                                   int studyId)
104   throw (SALOME_Exception)
105 {
106   MESSAGE("SMESH_HypothesisFactory::Create " << anHypName);
107   if (_creatorMap.find(anHypName) == _creatorMap.end())
108     throw(SALOME_Exception(LOCALIZED("bad hypothesis type name")));
109   SMESH_Hypothesis* myHyp = _creatorMap[anHypName]->Create(_hypId++,
110                                                            studyId,
111                                                            _gen);
112   return myHyp;
113 }
114
115 //=============================================================================
116 /*!
117  *
118  */
119 //=============================================================================
120
121 GenericHypothesisCreator*
122 SMESH_HypothesisFactory::GetCreator(const char* anHypName)
123   throw (SALOME_Exception)
124 {
125   MESSAGE("SMESH_HypothesisFactory::GetCreator " << anHypName);
126   if (_creatorMap.find(anHypName) == _creatorMap.end())
127     throw(SALOME_Exception(LOCALIZED("bad hypothesis type name")));
128   return _creatorMap[anHypName];
129 }
130
131 //=============================================================================
132 /*!
133  *
134  */
135 //=============================================================================
136
137 int SMESH_HypothesisFactory::GetANewId()
138 {
139   //MESSAGE("SMESH_HypothesisFactory::GetANewId");
140   return _hypId++;
141 }
142
143 //=============================================================================
144 /*!
145  *
146  */
147 //=============================================================================
148
149 void SMESH_HypothesisFactory::SetGen(SMESH_Gen* gen)
150 {
151   //MESSAGE("SMESH_HypothesisFactory::SetGen");
152   _gen = gen;
153 }
154