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