Salome HOME
88a50b02997b1d361b096ae6c941b424f64532f5
[modules/smesh.git] / src / MEDWrapper / MEDCoupling_Wrapper.cxx
1 // Copyright (C) 2021  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "MEDCoupling_Wrapper.hxx"
21 #include "MED_TStructures.hxx"
22
23 using namespace MED;
24 using namespace MEDCoupling;
25
26 //Copie directe
27 PMeshInfo MCTWrapper::CrMeshInfo(TInt theDim,
28             TInt theSpaceDim,
29             const std::string& theValue,
30             EMaillage theType,
31             const std::string& theDesc)
32 {
33   return PMeshInfo(new TTMeshInfo(theDim, theSpaceDim, theValue, theType, theDesc));
34 }
35
36 void MCTWrapper::SetMeshInfo(const TMeshInfo& theInfo)
37 {
38   _mesh_name = theInfo.GetName();
39   _mesh_dim = theInfo.GetDim();
40   _space_dim = theInfo.GetSpaceDim();
41 }
42
43 //Copie directe
44 PNodeInfo MCTWrapper::CrNodeInfo(const PMeshInfo& theMeshInfo,
45               TInt theNbElem,
46               EModeSwitch theMode,
47               ERepere theSystem,
48               EBooleen theIsElemNum,
49               EBooleen theIsElemNames)
50 {
51   return PNodeInfo(new TTNodeInfo
52                     (theMeshInfo,
53                     theNbElem,
54                     theMode,
55                     theSystem,
56                     theIsElemNum,
57                     theIsElemNames));
58 }
59
60 void MCTWrapper::SetNodeInfo(const TNodeInfo& theInfo)
61 {
62   MED::TNodeInfo& anInfo = const_cast<MED::TNodeInfo&>(theInfo);
63   MED::PNodeCoord aCoord(anInfo.myCoord);
64   MED::TInt aNbElem(anInfo.myNbElem);
65   std::string aCoordNames(anInfo.myCoordNames.data());
66   std::string aCoordUnits(anInfo.myCoordUnits.data());
67   std::vector<std::string> comps( DataArray::SplitStringInChuncks(aCoordNames,MED_SNAME_SIZE) );
68   std::vector<std::string> units( DataArray::SplitStringInChuncks(aCoordUnits,MED_SNAME_SIZE) );
69   std::size_t nbComps( comps.size() );
70   if( nbComps != units.size() )
71     THROW_IK_EXCEPTION("MCTWrapper::SetNodeInfo : mismatch length " << nbComps << " != " << units.size() << " !");
72   std::vector<std::string> compUnits(nbComps);
73   for( std::size_t i = 0 ; i < nbComps ; ++i )
74   {
75     compUnits[i] = DataArray::BuildInfoFromVarAndUnit(comps[i],units[i]) ;
76   }
77   _coords = DataArrayDouble::New();
78   _coords->alloc(aNbElem,this->_space_dim);
79   std::copy(aCoord->data(),aCoord->data()+aNbElem*this->_space_dim,_coords->getPointer());
80   _coords->setInfoOnComponents(compUnits);
81 }
82
83 void MCTWrapper::GetFamilyInfo(TInt theFamId, TFamilyInfo& theInfo)
84 {
85   std::string aFamilyName(theInfo.myName.data());
86   MED::TInt aFamilyId(theInfo.myId);
87   std::string aGroupNames(theInfo.myGroupNames.data());
88 }
89
90 //copie
91   PFamilyInfo
92   MCTWrapper::CrFamilyInfo(const PMeshInfo& theMeshInfo,
93                  const std::string& theValue,
94                  TInt theId,
95                  const MED::TStringSet& theGroupNames,
96                  const MED::TStringVector& theAttrDescs,
97                  const MED::TIntVector& theAttrIds,
98                  const MED::TIntVector& theAttrVals)
99   {
100     return PFamilyInfo(new TTFamilyInfo
101                        (theMeshInfo,
102                         theValue,
103                         theId,
104                         theGroupNames,
105                         theAttrDescs,
106                         theAttrIds,
107                         theAttrVals));
108   }
109
110   //copie
111   PPolygoneInfo
112   MCTWrapper::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
113                    EEntiteMaillage theEntity,
114                    EGeometrieElement theGeom,
115                    TInt theNbElem,
116                    TInt theConnSize,
117                    EConnectivite theConnMode,
118                    EBooleen theIsElemNum,
119                    EBooleen theIsElemNames)
120   {
121     return PPolygoneInfo(new TTPolygoneInfo
122                          (theMeshInfo,
123                           theEntity,
124                           theGeom,
125                           theNbElem,
126                           theConnSize,
127                           theConnMode,
128                           theIsElemNum,
129                           theIsElemNames));
130   }
131
132   //copie
133   PPolygoneInfo
134   MCTWrapper
135   ::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
136                    EEntiteMaillage theEntity,
137                    EGeometrieElement theGeom,
138                    const TIntVector& theIndexes,
139                    const TIntVector& theConnectivities,
140                    EConnectivite theConnMode,
141                    const TIntVector& theFamilyNums,
142                    const TIntVector& theElemNums,
143                    const TStringVector& theElemNames)
144   {
145     return PPolygoneInfo(new TTPolygoneInfo
146                          (theMeshInfo,
147                           theEntity,
148                           theGeom,
149                           theIndexes,
150                           theConnectivities,
151                           theConnMode,
152                           theFamilyNums,
153                           theElemNums,
154                           theElemNames));
155   }
156
157   //copie
158   PPolyedreInfo
159   MCTWrapper
160   ::CrPolyedreInfo(const PMeshInfo& theMeshInfo,
161                    EEntiteMaillage theEntity,
162                    EGeometrieElement theGeom,
163                    TInt theNbElem,
164                    TInt theNbFaces,
165                    TInt theConnSize,
166                    EConnectivite theConnMode,
167                    EBooleen theIsElemNum,
168                    EBooleen theIsElemNames)
169   {
170     return PPolyedreInfo(new TTPolyedreInfo
171                          (theMeshInfo,
172                           theEntity,
173                           theGeom,
174                           theNbElem,
175                           theNbFaces,
176                           theConnSize,
177                           theConnMode,
178                           theIsElemNum,
179                           theIsElemNames));
180   }
181
182 //copie
183     PBallInfo
184   MCTWrapper
185   ::CrBallInfo(const PMeshInfo& theMeshInfo,
186                TInt theNbBalls,
187                EBooleen theIsElemNum)
188   {
189     return PBallInfo(new TTBallInfo(theMeshInfo, theNbBalls, theIsElemNum));
190   }
191
192     PCellInfo
193   MCTWrapper
194   ::CrCellInfo(const PMeshInfo& theMeshInfo,
195                EEntiteMaillage theEntity,
196                EGeometrieElement theGeom,
197                TInt theNbElem,
198                EConnectivite theConnMode,
199                EBooleen theIsElemNum,
200                EBooleen theIsElemNames,
201                EModeSwitch theMode)
202   {
203     return PCellInfo(new TTCellInfo
204                      (theMeshInfo,
205                       theEntity,
206                       theGeom,
207                       theNbElem,
208                       theConnMode,
209                       theIsElemNum,
210                       theIsElemNames,
211                       theMode));
212   }