]> SALOME platform Git repositories - modules/med.git/blob - src/MEDWrapper/Base/MED_Structures.cxx
Salome HOME
update after merging trhe branches CEA_V3_0_x, OCC_V3_1_0_a1_x, and the main
[modules/med.git] / src / MEDWrapper / Base / MED_Structures.cxx
1 //  Copyright (C) 2003  CEA/DEN, EDF R&D
2 //
3 //
4 //
5 //  File   : VISU_Structure.cxx
6 //  Author : Eugeny NIKOLAEV
7 //  Module : VISU
8
9 #include "MED_Structures.hxx"
10 #include "MED_Utilities.hxx"
11 using namespace MED;
12
13 #if defined __GNUC__
14   #if __GNUC__ == 2
15     #define __GNUC_2__
16   #endif
17 #endif
18
19 #if defined __GNUC_2__
20 #define GETINDEX(anArray,ind) anArray[ind]
21 #else
22 #define GETINDEX(anArray,ind) anArray.at(ind)
23 #endif
24
25 namespace MED{
26
27   TInt GetNbNodes(EGeometrieElement typmai)
28   {
29     return typmai%100;
30   }
31
32   template<>
33   TInt GetNbConn<eV2_1>(EGeometrieElement typmai,
34                         EEntiteMaillage typent,
35                         TInt mdim)
36   {
37     TInt nsup = 0;
38
39     if(typent == eMAILLE){
40       TInt edim = typmai / 100;
41       if(mdim  == 2 || mdim == 3)
42         if(edim == 1)
43           nsup = 1;
44       
45       if(mdim == 3)
46         if (edim == 2)
47           nsup = 1;
48     }
49
50     return nsup + typmai%100;
51   }
52
53   template<>
54   TInt GetNbConn<eV2_2>(EGeometrieElement typmai,
55                         EEntiteMaillage typent,
56                         TInt mdim)
57   {
58     return typmai%100;
59   }
60
61   std::string GetString(TInt theId, TInt theStep, 
62                         const TString& theString)
63   {
64     const char* aPos = &GETINDEX(theString,theId*theStep);
65     TInt aSize = std::min(TInt(strlen(aPos)),theStep);
66     return std::string(aPos,aSize);
67   }
68
69   void SetString(TInt theId, TInt theStep, 
70                  TString& theString, 
71                  const std::string& theValue)
72   {
73     TInt aSize = std::min(TInt(theValue.size()+1),theStep);
74     char* aPos = &GETINDEX(theString,theId*theStep);
75     strncpy(aPos,theValue.c_str(),aSize);
76   }
77
78 }
79
80 //---------------------------------------------------------------
81 TInt TFamilyInfo::GetAttrId(TInt theId) const {
82   return GETINDEX(myAttrId,theId);
83 }
84
85 TInt TFamilyInfo::GetAttrVal(TInt theId) const {
86   return GETINDEX(myAttrVal,theId);
87 }
88
89 void TFamilyInfo::SetAttrId(TInt theId,TInt theVal) {
90   GETINDEX(myAttrId,theId) = theVal;
91 }
92
93 void TFamilyInfo::SetAttrVal(TInt theId,TInt theVal) {
94   GETINDEX(myAttrVal,theId) = theVal;
95 }
96
97 //---------------------------------------------------------------
98 TInt TElemInfo::GetFamNum(TInt theId) const {
99   return GETINDEX(myFamNum,theId);
100 }
101
102 TInt TElemInfo::GetElemNum(TInt theId) const {
103   return GETINDEX(myElemNum,theId);
104 }
105
106 void TElemInfo::SetFamNum(TInt theId,TInt theVal) {
107   GETINDEX(myFamNum,theId) = theVal;
108 }
109
110 //---------------------------------------------------------------
111 TFloat TNodeInfo::GetNodeCoord(TInt theId,TInt theComp) const {
112   return GETINDEX(myCoord,myMeshInfo->myDim*theId + theComp);
113 }
114
115 void TNodeInfo::SetNodeCoord(TInt theId,TInt theComp,TFloat theVal) {
116   GETINDEX(myCoord,myMeshInfo->myDim*theId + theComp) = theVal;
117 }
118
119 //---------------------------------------------------------------
120 TInt TCellInfo::GetConn(TInt theElemId, TInt theConnId) const {
121   return GETINDEX(myConn,GetConnDim()*theElemId + theConnId);
122 }
123
124 void TCellInfo::SetConn(TInt theElemId, TInt theConnId, TInt theVal){
125   GETINDEX(myConn,GetConnDim()*theElemId + theConnId) = theVal;
126 }
127
128 TConstConnSlice 
129 TCellInfo::GetConnSlice(TInt theElemId) const
130 {
131   return TConstConnSlice(myConn,std::slice(GetConnDim()*theElemId,GetNbNodes(myTGeom),1));
132 }
133
134 TConnSlice 
135 TCellInfo::GetConnSlice(TInt theElemId)
136 {
137   return TConnSlice(myConn,std::slice(GetConnDim()*theElemId,GetNbNodes(myTGeom),1));
138 }
139
140 //---------------------------------------------------------------
141 TInt TPolygoneInfo::GetNbConn(TInt theElemId) const {
142   TInt i1 = GETINDEX(myIndex,theElemId);
143   TInt i2 = GETINDEX(myIndex,theElemId+1);
144   TInt ret = i2 - i1;
145   return ret;
146 }
147
148 //---------------------------------------------------------------
149 TInt TPolyedreInfo::GetNbConn(TInt theElemId) const {
150   TInt ind1 = GETINDEX(myIndex,theElemId);
151   TInt ind2 = GETINDEX(myIndex,theElemId+1);
152
153   TInt inf1 = GETINDEX(myFacesIndex,ind1-1);
154   TInt inf2 = GETINDEX(myFacesIndex,ind2-1);
155
156   TInt ret = inf2-inf1;
157   return ret;
158 }
159
160 //---------------------------------------------------------------
161 TFloat TTimeStampVal::GetVal(EGeometrieElement theGeom, TInt theId, 
162                              TInt theComp, TInt theGauss) const {
163   TInt aNbComp = myTimeStampInfo->myFieldInfo->myNbComp;
164   TInt aNbGauss = myTimeStampInfo->myNbGauss;
165   TInt aStep = aNbComp*aNbGauss;
166   TMeshValue::const_iterator anIter = myMeshValue.find(theGeom);
167   if(anIter != myMeshValue.end()){
168     TFloat aRet=GETINDEX(anIter->second,theId*aStep + theComp*aNbGauss + theGauss);
169     return aRet;
170   }
171   return TFloat();
172 }
173
174 void TTimeStampVal::SetVal(EGeometrieElement theGeom, TInt theId, 
175                            TInt theComp, TFloat theVal, TInt theGauss)
176 {
177   TInt aNbComp = myTimeStampInfo->myFieldInfo->myNbComp;
178   TInt aNbGauss = myTimeStampInfo->myNbGauss;
179   TInt aStep = aNbComp*aNbGauss;
180   GETINDEX(myMeshValue[theGeom],theId*aStep + theComp*aNbGauss + theGauss) = theVal;
181 }