Salome HOME
NRI : First integration.
[modules/smesh.git] / src / SMESH_I / SMESH_HypothesisFactory_i.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : SMESH_HypothesisFactory_i.cxx
4 // Created   : dim mai 19 22:02:42 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_i.hxx"
13 #include "SMESH_Hypothesis_i.hxx"
14
15 #include "Utils_CorbaException.hxx"
16 #include "utilities.h"
17
18 // Add new hypothesis here (include file)
19 //---------------------------------------
20 #include "SMESH_LocalLength_i.hxx"
21 #include "SMESH_NumberOfSegments_i.hxx"
22 #include "SMESH_MaxElementArea_i.hxx"
23 #include "SMESH_Regular_1D_i.hxx"
24 #include "SMESH_MEFISTO_2D_i.hxx"
25 #include "SMESH_Quadrangle_2D_i.hxx"
26 #include "SMESH_Hexa_3D_i.hxx"
27
28 //---------------------------------------
29
30 //=============================================================================
31 /*!
32  * Specific Hypothesis Creators are generated with a template which inherits a
33  * generic hypothesis creator. Each creator returns an hypothesis of the type
34  * given in the template. 
35  */
36 //=============================================================================
37
38 template <class T> class HypothesisCreator_i: public GenericHypothesisCreator_i
39 {
40 public:
41   virtual SMESH_Hypothesis_i* Create (const char* anHyp,
42                                       int studyId,
43                                       ::SMESH_Gen* genImpl) 
44   {
45     return new T(anHyp, studyId, genImpl);
46   };
47 };
48
49 //=============================================================================
50 /*!
51  * Constructor: instanciate specific hypothesis creators, fill a private map
52  * indexed by hypothesis names. THIS METHOD MUST BE COMPLETED WHEN A NEW
53  * HYPOTHESIS IS ADDED. 
54  * Specific hypothesis creator are defined with the above template.
55  * Hypothesis names are related to the corresponding class names:
56  * prefix = SMESH_ ; suffix = _i .
57  */
58 //=============================================================================
59
60 SMESH_HypothesisFactory_i::SMESH_HypothesisFactory_i()
61 {
62 // Add new hypothesis here (creators)
63 //---------------------------------------
64 _creatorMap["LocalLength"] = new HypothesisCreator_i<SMESH_LocalLength_i>;
65 _creatorMap["NumberOfSegments"] = new HypothesisCreator_i<SMESH_NumberOfSegments_i>;
66 _creatorMap["MaxElementArea"] = new HypothesisCreator_i<SMESH_MaxElementArea_i>;
67 _creatorMap["Regular_1D"] = new HypothesisCreator_i<SMESH_Regular_1D_i>;
68 _creatorMap["MEFISTO_2D"] = new HypothesisCreator_i<SMESH_MEFISTO_2D_i>;
69 _creatorMap["Quadrangle_2D"] = new HypothesisCreator_i<SMESH_Quadrangle_2D_i>;
70 _creatorMap["Hexa_3D"] = new HypothesisCreator_i<SMESH_Hexa_3D_i>;
71
72 //---------------------------------------
73 }
74
75 //=============================================================================
76 /*!
77  * Destructor: deletes specific hypothesis creators instanciated in the
78  * constructor.
79  */
80 //=============================================================================
81
82 SMESH_HypothesisFactory_i::~SMESH_HypothesisFactory_i()
83 {
84   map<string, GenericHypothesisCreator_i*>::iterator it;
85   for (it = _creatorMap.begin(); it !=  _creatorMap.end(); it++)
86     {
87       delete (*it).second;
88     }
89   _creatorMap.clear();
90 }
91
92 //=============================================================================
93 /*!
94  *
95  */
96 //=============================================================================
97
98 SMESH_Hypothesis_i* SMESH_HypothesisFactory_i::Create(const char* anHyp,
99                                                       CORBA::Long studyId,
100                                                       ::SMESH_Gen* genImpl)
101   throw (SALOME::SALOME_Exception)
102 {
103   MESSAGE("SMESH_HypothesisFactory::Create " << anHyp);
104   if (_creatorMap.find(anHyp) == _creatorMap.end())
105     {
106       MESSAGE("levee exception CORBA");
107       THROW_SALOME_CORBA_EXCEPTION("bad hypothesis type name", \
108                                    SALOME::BAD_PARAM);
109     }
110   SMESH_Hypothesis_i* myHyp = _creatorMap[anHyp]->Create(anHyp,
111                                                          studyId,
112                                                          genImpl);
113   return myHyp;
114 }
115
116