Salome HOME
updating or adding when merging in the main trunk with the version in the
[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 #include "SMESH_NETGEN_3D.hxx"
50
51 //---------------------------------------
52
53 //=============================================================================
54 /*!
55  * Specific Hypothesis Creators are generated with a template which inherits a
56  * generic hypothesis creator. Each creator returns an hypothesis of the type
57  * given in the template. 
58  */
59 //=============================================================================
60
61 // template <class T> class HypothesisCreator: public GenericHypothesisCreator
62 // {
63 // public:
64 //   virtual T* Create (int hypId)
65 //   {
66 // //     return new T(hypId);
67 //   };
68
69 // };
70
71 //=============================================================================
72 /*!
73  * Constructor: instanciate specific hypothesis creators, fill a private map
74  * indexed by hypothesis names. THIS METHOD MUST BE COMPLETED WHEN A NEW
75  * HYPOTHESIS IS ADDED. 
76  * Specific hypothesis creator are defined with the above template.
77  * Hypothesis names are related to the corresponding class names:
78  * prefix = SMESH_ ; suffix = .
79  */
80 //=============================================================================
81
82 SMESH_HypothesisFactory::SMESH_HypothesisFactory()
83 {
84   _hypId = 0;
85
86 // Add new hypothesis here (creators)
87 //---------------------------------------
88 _creatorMap["LocalLength"] = new SMESH_HypothesisCreator<SMESH_LocalLength>;
89 _creatorMap["NumberOfSegments"] = new SMESH_HypothesisCreator<SMESH_NumberOfSegments>;
90 _creatorMap["LengthFromEdges"] = new SMESH_HypothesisCreator<SMESH_LengthFromEdges>;
91 _creatorMap["MaxElementArea"] = new SMESH_HypothesisCreator<SMESH_MaxElementArea>;
92 _creatorMap["MaxElementVolume"] = new SMESH_HypothesisCreator<SMESH_MaxElementVolume>;
93 _creatorMap["Regular_1D"] = new SMESH_HypothesisCreator<SMESH_Regular_1D>;
94 _creatorMap["MEFISTO_2D"] = new SMESH_HypothesisCreator<SMESH_MEFISTO_2D>;
95 _creatorMap["Quadrangle_2D"] = new SMESH_HypothesisCreator<SMESH_Quadrangle_2D>;
96 _creatorMap["Hexa_3D"] = new SMESH_HypothesisCreator<SMESH_Hexa_3D>;
97 _creatorMap["NETGEN_3D"] = new SMESH_HypothesisCreator<SMESH_NETGEN_3D>;
98 //---------------------------------------
99 }
100
101 //=============================================================================
102 /*!
103  * Destructor: deletes specific hypothesis creators instanciated in the
104  * constructor.
105  */
106 //=============================================================================
107
108 SMESH_HypothesisFactory::~SMESH_HypothesisFactory()
109 {
110   map<string, GenericHypothesisCreator*>::iterator it;
111   for (it = _creatorMap.begin(); it !=  _creatorMap.end(); it++)
112     {
113       delete (*it).second;
114     }
115   _creatorMap.clear();
116 }
117
118 //=============================================================================
119 /*!
120  *
121  */
122 //=============================================================================
123
124 SMESH_Hypothesis* SMESH_HypothesisFactory::Create(const char* anHypName,
125                                                   int studyId)
126   throw (SALOME_Exception)
127 {
128   MESSAGE("SMESH_HypothesisFactory::Create " << anHypName);
129   if (_creatorMap.find(anHypName) == _creatorMap.end())
130     throw(SALOME_Exception(LOCALIZED("bad hypothesis type name")));
131   SMESH_Hypothesis* myHyp = _creatorMap[anHypName]->Create(_hypId++,
132                                                            studyId,
133                                                            _gen);
134   return myHyp;
135 }
136
137 //=============================================================================
138 /*!
139  *
140  */
141 //=============================================================================
142
143 GenericHypothesisCreator*
144 SMESH_HypothesisFactory::GetCreator(const char* anHypName)
145   throw (SALOME_Exception)
146 {
147   MESSAGE("SMESH_HypothesisFactory::GetCreator " << anHypName);
148   if (_creatorMap.find(anHypName) == _creatorMap.end())
149     throw(SALOME_Exception(LOCALIZED("bad hypothesis type name")));
150   return _creatorMap[anHypName];
151 }
152
153 //=============================================================================
154 /*!
155  *
156  */
157 //=============================================================================
158
159 int SMESH_HypothesisFactory::GetANewId()
160 {
161   //MESSAGE("SMESH_HypothesisFactory::GetANewId");
162   return _hypId++;
163 }
164
165 //=============================================================================
166 /*!
167  *
168  */
169 //=============================================================================
170
171 void SMESH_HypothesisFactory::SetGen(SMESH_Gen* gen)
172 {
173   //MESSAGE("SMESH_HypothesisFactory::SetGen");
174   _gen = gen;
175 }
176