Salome HOME
correct a small bug found by the EDF developpement team (PN and AT) :
[modules/smesh.git] / src / SMESH_I / SMESH_HypothesisFactory_i.cxx
1 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
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_i.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESH_HypothesisFactory_i.hxx"
31 #include "SMESH_Hypothesis_i.hxx"
32
33 #include "Utils_CorbaException.hxx"
34 #include "utilities.h"
35
36 // Add new hypothesis here (include file)
37 //---------------------------------------
38 #include "SMESH_LocalLength_i.hxx"
39 #include "SMESH_NumberOfSegments_i.hxx"
40 #include "SMESH_LengthFromEdges_i.hxx"
41 #include "SMESH_MaxElementArea_i.hxx"
42 #include "SMESH_MaxElementVolume_i.hxx"
43 #include "SMESH_Regular_1D_i.hxx"
44 #include "SMESH_MEFISTO_2D_i.hxx"
45 #include "SMESH_Quadrangle_2D_i.hxx"
46 #include "SMESH_Hexa_3D_i.hxx"
47 #ifdef HAVE_NETGEN
48 #include "SMESH_NETGEN_3D_i.hxx"
49 #endif
50 //---------------------------------------
51
52 //=============================================================================
53 /*!
54  * Specific Hypothesis Creators are generated with a template which inherits a
55  * generic hypothesis creator. Each creator returns an hypothesis of the type
56  * given in the template. 
57  */
58 //=============================================================================
59
60 template <class T> class HypothesisCreator_i: public GenericHypothesisCreator_i
61 {
62 public:
63   virtual SMESH_Hypothesis_i* Create (const char* anHyp,
64                                       int studyId,
65                                       ::SMESH_Gen* genImpl) 
66   {
67     return new T(anHyp, studyId, genImpl);
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 = _i .
79  */
80 //=============================================================================
81
82 SMESH_HypothesisFactory_i::SMESH_HypothesisFactory_i()
83 {
84 // Add new hypothesis here (creators)
85 //---------------------------------------
86 _creatorMap["LocalLength"] = new HypothesisCreator_i<SMESH_LocalLength_i>;
87 _creatorMap["NumberOfSegments"] = new HypothesisCreator_i<SMESH_NumberOfSegments_i>;
88 _creatorMap["LengthFromEdges"] = new HypothesisCreator_i<SMESH_LengthFromEdges_i>;
89 _creatorMap["MaxElementArea"] = new HypothesisCreator_i<SMESH_MaxElementArea_i>;
90 _creatorMap["MaxElementVolume"] = new HypothesisCreator_i<SMESH_MaxElementVolume_i>;
91 _creatorMap["Regular_1D"] = new HypothesisCreator_i<SMESH_Regular_1D_i>;
92 _creatorMap["MEFISTO_2D"] = new HypothesisCreator_i<SMESH_MEFISTO_2D_i>;
93 _creatorMap["Quadrangle_2D"] = new HypothesisCreator_i<SMESH_Quadrangle_2D_i>;
94 _creatorMap["Hexa_3D"] = new HypothesisCreator_i<SMESH_Hexa_3D_i>;
95 #ifdef HAVE_NETGEN
96 _creatorMap["NETGEN_3D"] = new HypothesisCreator_i<SMESH_NETGEN_3D_i>;
97 #endif
98 //---------------------------------------
99 }
100
101 //=============================================================================
102 /*!
103  * Destructor: deletes specific hypothesis creators instanciated in the
104  * constructor.
105  */
106 //=============================================================================
107
108 SMESH_HypothesisFactory_i::~SMESH_HypothesisFactory_i()
109 {
110   map<string, GenericHypothesisCreator_i*>::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_i* SMESH_HypothesisFactory_i::Create(const char* anHyp,
125                                                       CORBA::Long studyId,
126                                                       ::SMESH_Gen* genImpl)
127   throw (SALOME::SALOME_Exception)
128 {
129   MESSAGE("SMESH_HypothesisFactory::Create " << anHyp);
130   if (_creatorMap.find(anHyp) == _creatorMap.end())
131     {
132       MESSAGE("levee exception CORBA");
133       THROW_SALOME_CORBA_EXCEPTION("bad hypothesis type name", \
134                                    SALOME::BAD_PARAM);
135     }
136   SMESH_Hypothesis_i* myHyp = _creatorMap[anHyp]->Create(anHyp,
137                                                          studyId,
138                                                          genImpl);
139   return myHyp;
140 }
141
142