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