Salome HOME
Merge remote branch 'origin/gdd/translations'
[modules/smesh.git] / src / MEDWrapper / Base / MED_CoordUtils.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "MED_CoordUtils.hxx"
23 #include "MED_Utilities.hxx"
24  
25 namespace MED
26 {
27
28   enum ECoordName{eX, eY, eZ, eNone};
29
30   template<ECoordName TCoordId>
31   TFloat 
32   GetCoord(const TCCoordSlice& theCoordSlice)
33   {
34     return theCoordSlice[TCoordId];
35   }
36
37   template<>
38   TFloat 
39   GetCoord<eNone>(const TCCoordSlice& theCoordSlice)
40   {
41     return 0.0;
42   }
43   
44   TGetCoord
45   aXYZGetCoord[3] = {
46     &GetCoord<eX>, 
47     &GetCoord<eY>, 
48     &GetCoord<eZ>
49   };
50   
51   TGetCoord
52   aXYGetCoord[3] = {
53     &GetCoord<eX>, 
54     &GetCoord<eY>, 
55     &GetCoord<eNone>
56   };
57   
58   TGetCoord
59   aYZGetCoord[3] = {
60     &GetCoord<eNone>,
61     &GetCoord<eX>, 
62     &GetCoord<eY>
63   };
64   
65   TGetCoord 
66   aXZGetCoord[3] = {
67     &GetCoord<eX>, 
68     &GetCoord<eNone>,
69     &GetCoord<eY>
70   };
71   
72   
73   TGetCoord 
74   aXGetCoord[3] = {
75     &GetCoord<eX>, 
76     &GetCoord<eNone>,
77     &GetCoord<eNone>
78   };
79   
80   TGetCoord
81   aYGetCoord[3] = {
82     &GetCoord<eNone>,
83     &GetCoord<eX>, 
84     &GetCoord<eNone>
85   };
86
87   TGetCoord
88   aZGetCoord[3] = {
89     &GetCoord<eNone>,
90     &GetCoord<eNone>,
91     &GetCoord<eX>
92   };
93
94   
95   //---------------------------------------------------------------
96   TCoordHelper
97   ::TCoordHelper(TGetCoord* theGetCoord):
98     myGetCoord(theGetCoord)
99   {}
100
101   TFloat 
102   TCoordHelper
103   ::GetCoord(TCCoordSlice& theCoordSlice, 
104              TInt theCoordId)
105   {
106     return (*myGetCoord[theCoordId])(theCoordSlice);
107   }
108
109
110   //---------------------------------------------------------------
111   PCoordHelper
112   GetCoordHelper(PNodeInfo theNodeInfo)
113   {
114     PCoordHelper aCoordHelper;
115     {
116       PMeshInfo aMeshInfo = theNodeInfo->GetMeshInfo();
117       TInt aMeshDimension = aMeshInfo->GetDim();
118       bool anIsDimPresent[3] = {false, false, false};
119       for(int iDim = 0; iDim < aMeshDimension; iDim++){
120         // PAL16857(SMESH not conform to the MED convention) ->
121         // 1D - always along X
122         // 2D - always in XOY plane
123         anIsDimPresent[iDim] = iDim < aMeshDimension;
124 //      std::string aName = theNodeInfo->GetCoordName(iDim);
125 //         if ( aName.size() > 1 ) // PAL12148, aName has size 8 or 16
126 //           aName = aName.substr(0,1);
127 //      if(aName == "x" || aName == "X")
128 //        anIsDimPresent[eX] = true;
129 //      else if(aName == "y" || aName == "Y")
130 //        anIsDimPresent[eY] = true;
131 //      else if(aName == "z" || aName == "Z")
132 //        anIsDimPresent[eZ] = true;
133       }
134
135       switch(aMeshDimension){
136       case 3:
137         aCoordHelper.reset(new TCoordHelper(aXYZGetCoord));
138         break;
139       case 2:
140         if(anIsDimPresent[eY] && anIsDimPresent[eZ])
141           aCoordHelper.reset(new TCoordHelper(aYZGetCoord));
142         else if(anIsDimPresent[eX] && anIsDimPresent[eZ])
143           aCoordHelper.reset(new TCoordHelper(aXZGetCoord));
144         else
145           aCoordHelper.reset(new TCoordHelper(aXYGetCoord));
146         break;
147       case 1:
148         if(anIsDimPresent[eY])
149           aCoordHelper.reset(new TCoordHelper(aYGetCoord));
150         else if(anIsDimPresent[eZ])
151           aCoordHelper.reset(new TCoordHelper(aZGetCoord));
152         else
153           aCoordHelper.reset(new TCoordHelper(aXGetCoord));
154         break;
155       }
156     }
157     return aCoordHelper;
158   }
159 }