Salome HOME
Copyright update 2021
[tools/medcoupling.git] / src / MEDLoader / MEDFileMeshReadSelector.cxx
1 // Copyright (C) 2007-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 // Author : Anthony Geay (EDF R&D)
20
21 #include "MEDFileMeshReadSelector.hxx"
22
23 #include "InterpKernelException.hxx"
24
25 #include <sstream>
26
27 using namespace MEDCoupling;
28
29 MEDFileMeshReadSelector::MEDFileMeshReadSelector():_nb_coords_load_sessions(1),_code(0xFFFFFFFF)
30 {
31 }
32
33 MEDFileMeshReadSelector::MEDFileMeshReadSelector(unsigned int code):_code(code)
34 {
35 }
36
37 unsigned int MEDFileMeshReadSelector::getCode() const
38 {
39   return _code;
40 }
41
42 void MEDFileMeshReadSelector::setCode(unsigned int newCode)
43 {
44   _code=newCode;
45 }
46
47 void MEDFileMeshReadSelector::setNumberOfCoordsLoadSessions(mcIdType newNbOfCoordsLoadSessions)
48 {
49   if(newNbOfCoordsLoadSessions < 1)
50     throw INTERP_KERNEL::Exception("MEDFileMeshReadSelector::setNumberOfCoordsLoadSessions : input must be >= 1 !");
51   _nb_coords_load_sessions = newNbOfCoordsLoadSessions;
52 }
53
54 bool MEDFileMeshReadSelector::isCellFamilyFieldReading() const
55 {
56   return _code & 0x00000001;
57 }
58
59 bool MEDFileMeshReadSelector::isNodeFamilyFieldReading() const
60 {
61   return _code & 0x00000002;
62 }
63
64 bool MEDFileMeshReadSelector::isCellNameFieldReading() const
65 {
66   return _code & 0x00000004;
67 }
68
69 bool MEDFileMeshReadSelector::isNodeNameFieldReading() const
70 {
71   return _code & 0x00000008;
72 }
73
74 bool MEDFileMeshReadSelector::isCellNumFieldReading() const
75 {
76   return _code & 0x00000010;
77 }
78
79 bool MEDFileMeshReadSelector::isNodeNumFieldReading() const
80 {
81   return _code & 0x00000020;
82 }
83
84 bool MEDFileMeshReadSelector::isGlobalNodeNumFieldReading() const
85 {
86   return _code & 0x00000040;
87 }
88
89 void MEDFileMeshReadSelector::setCellFamilyFieldReading(bool b)
90 {
91   unsigned int code(_code & 0xFFFFFFFE);
92   unsigned int b2=b?1:0;
93   //b2<<=0;
94   code+=b2;
95   _code=code;
96 }
97
98 void MEDFileMeshReadSelector::setNodeFamilyFieldReading(bool b)
99 {
100   unsigned int code(_code & 0xFFFFFFFD);
101   unsigned int b2=b?1:0;
102   b2<<=1;
103   code+=b2;
104   _code=code;
105 }
106
107 void MEDFileMeshReadSelector::setCellNameFieldReading(bool b)
108 {
109   unsigned int code(_code & 0xFFFFFFFB);
110   unsigned int b2=b?1:0;
111   b2<<=2;
112   code+=b2;
113   _code=code;
114 }
115
116 void MEDFileMeshReadSelector::setNodeNameFieldReading(bool b)
117 {
118   unsigned int code(_code & 0xFFFFFFF7);
119   unsigned int b2=b?1:0;
120   b2<<=3;
121   code+=b2;
122   _code=code;
123 }
124
125 void MEDFileMeshReadSelector::setCellNumFieldReading(bool b)
126 {
127   unsigned int code(_code & 0xFFFFFFEF);
128   unsigned int b2=b?1:0;
129   b2<<=4;
130   code+=b2;
131   _code=code;
132 }
133
134 void MEDFileMeshReadSelector::setNodeNumFieldReading(bool b)
135 {
136   unsigned int code(_code & 0xFFFFFFDF);
137   unsigned int b2=b?1:0;
138   b2<<=5;
139   code+=b2;
140   _code=code;
141 }
142
143 void MEDFileMeshReadSelector::setGlobalNodeNumFieldReading(bool b)
144 {
145   unsigned int code(_code & 0xFFFFFFBF);
146   unsigned int b2=b?1:0;
147   b2<<=6;
148   code+=b2;
149   _code=code;
150 }
151
152 void MEDFileMeshReadSelector::reprAll(std::ostream& str) const
153 {
154   str << "MEDFileMeshReadSelector (code=" << _code << ") : \n";
155   str << "Number of coords load part sessions : " << this->_nb_coords_load_sessions << std::endl;
156   str << "Read family field on cells : " << ReprStatus(isCellFamilyFieldReading()) << std::endl;
157   str << "Read family field on nodes : " << ReprStatus(isNodeFamilyFieldReading()) << std::endl;
158   str << "Read name field on cells : " << ReprStatus(isCellNameFieldReading()) << std::endl;
159   str << "Read name field on nodes : " << ReprStatus(isNodeNameFieldReading()) << std::endl;
160   str << "Read number field on cells : " << ReprStatus(isCellNumFieldReading()) << std::endl;
161   str << "Read number field name on nodes : " << ReprStatus(isNodeNumFieldReading()) << std::endl;
162   str << "Read global number field name on nodes : " << ReprStatus(isGlobalNodeNumFieldReading());
163 }
164
165 std::string MEDFileMeshReadSelector::ReprStatus(bool v)
166 {
167   if(v)
168     return std::string("ON");
169   else
170     return std::string("OFF");
171 }
172