Salome HOME
HAVE_NETGEN (#define) to remove an unresolved symbol when building without netgen
[modules/smesh.git] / src / SMESH / SMESH_HypothesisFactory.cxx
1 //  SMESH SMESH : implementaion of SMESH idl descriptions
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESH_HypothesisFactory.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 using namespace std;
31 #include "SMESH_HypothesisFactory.hxx"
32 #include "SMESH_Hypothesis.hxx"
33 #include "SMESH_HypothesisCreator.hxx"
34 #include "SMESH_Gen.hxx"
35
36 #include "utilities.h"
37
38 // Add new hypothesis here (include file)
39 //---------------------------------------
40 #include "SMESH_LocalLength.hxx"
41 #include "SMESH_LengthFromEdges.hxx"
42 #include "SMESH_NumberOfSegments.hxx"
43 #include "SMESH_MaxElementArea.hxx"
44 #include "SMESH_MaxElementVolume.hxx"
45 #include "SMESH_Regular_1D.hxx"
46 #include "SMESH_MEFISTO_2D.hxx"
47 #include "SMESH_Quadrangle_2D.hxx"
48 #include "SMESH_Hexa_3D.hxx"
49 #ifdef HAVE_NETGEN
50 #include "SMESH_NETGEN_3D.hxx"
51 #endif
52 //---------------------------------------
53
54 //=============================================================================
55 /*!
56  * Specific Hypothesis Creators are generated with a template which inherits a
57  * generic hypothesis creator. Each creator returns an hypothesis of the type
58  * given in the template. 
59  */
60 //=============================================================================
61
62 // template <class T> class HypothesisCreator: public GenericHypothesisCreator
63 // {
64 // public:
65 //   virtual T* Create (int hypId)
66 //   {
67 // //     return new T(hypId);
68 //   };
69
70 // };
71
72 //=============================================================================
73 /*!
74  * Constructor: instanciate specific hypothesis creators, fill a private map
75  * indexed by hypothesis names. THIS METHOD MUST BE COMPLETED WHEN A NEW
76  * HYPOTHESIS IS ADDED. 
77  * Specific hypothesis creator are defined with the above template.
78  * Hypothesis names are related to the corresponding class names:
79  * prefix = SMESH_ ; suffix = .
80  */
81 //=============================================================================
82
83 SMESH_HypothesisFactory::SMESH_HypothesisFactory()
84 {
85   _hypId = 0;
86
87 // Add new hypothesis here (creators)
88 //---------------------------------------
89 _creatorMap["LocalLength"] = new SMESH_HypothesisCreator<SMESH_LocalLength>;
90 _creatorMap["NumberOfSegments"] = new SMESH_HypothesisCreator<SMESH_NumberOfSegments>;
91 _creatorMap["LengthFromEdges"] = new SMESH_HypothesisCreator<SMESH_LengthFromEdges>;
92 _creatorMap["MaxElementArea"] = new SMESH_HypothesisCreator<SMESH_MaxElementArea>;
93 _creatorMap["MaxElementVolume"] = new SMESH_HypothesisCreator<SMESH_MaxElementVolume>;
94 _creatorMap["Regular_1D"] = new SMESH_HypothesisCreator<SMESH_Regular_1D>;
95 _creatorMap["MEFISTO_2D"] = new SMESH_HypothesisCreator<SMESH_MEFISTO_2D>;
96 _creatorMap["Quadrangle_2D"] = new SMESH_HypothesisCreator<SMESH_Quadrangle_2D>;
97 _creatorMap["Hexa_3D"] = new SMESH_HypothesisCreator<SMESH_Hexa_3D>;
98 #ifdef HAVE_NETGEN
99 _creatorMap["NETGEN_3D"] = new SMESH_HypothesisCreator<SMESH_NETGEN_3D>;
100 #endif
101 //---------------------------------------
102 }
103
104 //=============================================================================
105 /*!
106  * Destructor: deletes specific hypothesis creators instanciated in the
107  * constructor.
108  */
109 //=============================================================================
110
111 SMESH_HypothesisFactory::~SMESH_HypothesisFactory()
112 {
113   map<string, GenericHypothesisCreator*>::iterator it;
114   for (it = _creatorMap.begin(); it !=  _creatorMap.end(); it++)
115     {
116       delete (*it).second;
117     }
118   _creatorMap.clear();
119 }
120
121 //=============================================================================
122 /*!
123  *
124  */
125 //=============================================================================
126
127 SMESH_Hypothesis* SMESH_HypothesisFactory::Create(const char* anHypName,
128                                                   int studyId)
129   throw (SALOME_Exception)
130 {
131   MESSAGE("SMESH_HypothesisFactory::Create " << anHypName);
132   if (_creatorMap.find(anHypName) == _creatorMap.end())
133     throw(SALOME_Exception(LOCALIZED("bad hypothesis type name")));
134   SMESH_Hypothesis* myHyp = _creatorMap[anHypName]->Create(_hypId++,
135                                                            studyId,
136                                                            _gen);
137   return myHyp;
138 }
139
140 //=============================================================================
141 /*!
142  *
143  */
144 //=============================================================================
145
146 GenericHypothesisCreator*
147 SMESH_HypothesisFactory::GetCreator(const char* anHypName)
148   throw (SALOME_Exception)
149 {
150   MESSAGE("SMESH_HypothesisFactory::GetCreator " << anHypName);
151   if (_creatorMap.find(anHypName) == _creatorMap.end())
152     throw(SALOME_Exception(LOCALIZED("bad hypothesis type name")));
153   return _creatorMap[anHypName];
154 }
155
156 //=============================================================================
157 /*!
158  *
159  */
160 //=============================================================================
161
162 int SMESH_HypothesisFactory::GetANewId()
163 {
164   //MESSAGE("SMESH_HypothesisFactory::GetANewId");
165   return _hypId++;
166 }
167
168 //=============================================================================
169 /*!
170  *
171  */
172 //=============================================================================
173
174 void SMESH_HypothesisFactory::SetGen(SMESH_Gen* gen)
175 {
176   //MESSAGE("SMESH_HypothesisFactory::SetGen");
177   _gen = gen;
178 }
179