1 | #include "axis.hpp" |
---|
2 | |
---|
3 | #include "attribute_template.hpp" |
---|
4 | #include "object_template.hpp" |
---|
5 | #include "group_template.hpp" |
---|
6 | #include "message.hpp" |
---|
7 | #include "type.hpp" |
---|
8 | #include "xmlioserver_spl.hpp" |
---|
9 | |
---|
10 | namespace xios { |
---|
11 | |
---|
12 | /// ////////////////////// Définitions ////////////////////// /// |
---|
13 | |
---|
14 | CAxis::CAxis(void) |
---|
15 | : CObjectTemplate<CAxis>() |
---|
16 | , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject() |
---|
17 | { /* Ne rien faire de plus */ } |
---|
18 | |
---|
19 | CAxis::CAxis(const StdString & id) |
---|
20 | : CObjectTemplate<CAxis>(id) |
---|
21 | , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject() |
---|
22 | { /* Ne rien faire de plus */ } |
---|
23 | |
---|
24 | CAxis::~CAxis(void) |
---|
25 | { /* Ne rien faire de plus */ } |
---|
26 | |
---|
27 | ///--------------------------------------------------------------- |
---|
28 | |
---|
29 | const std::set<StdString> & CAxis::getRelFiles(void) const |
---|
30 | { |
---|
31 | return (this->relFiles); |
---|
32 | } |
---|
33 | |
---|
34 | bool CAxis::IsWritten(const StdString & filename) const |
---|
35 | { |
---|
36 | return (this->relFiles.find(filename) != this->relFiles.end()); |
---|
37 | } |
---|
38 | |
---|
39 | void CAxis::addRelFile(const StdString & filename) |
---|
40 | { |
---|
41 | this->relFiles.insert(filename); |
---|
42 | } |
---|
43 | |
---|
44 | //---------------------------------------------------------------- |
---|
45 | |
---|
46 | StdString CAxis::GetName(void) { return (StdString("axis")); } |
---|
47 | StdString CAxis::GetDefName(void){ return (CAxis::GetName()); } |
---|
48 | ENodeType CAxis::GetType(void) { return (eAxis); } |
---|
49 | |
---|
50 | //---------------------------------------------------------------- |
---|
51 | |
---|
52 | void CAxis::checkAttributes(void) |
---|
53 | { |
---|
54 | if (this->isChecked) return; |
---|
55 | if (this->size.isEmpty()) |
---|
56 | ERROR("CAxis::checkAttributes(void)",<< "Attribut <size> of the axis must be specified") ; |
---|
57 | StdSize size = this->size.getValue(); |
---|
58 | |
---|
59 | if (!this->ibegin.isEmpty()) |
---|
60 | { |
---|
61 | StdSize ibegin = this->ibegin.getValue(); |
---|
62 | if ((ibegin < 0) || (ibegin > size-1)) |
---|
63 | ERROR("CAxis::checkAttributes(void)",<< "Attribut <ibegin> of the axis must be non-negative and smaller than size-1") ; |
---|
64 | } |
---|
65 | else this->ibegin.setValue(0); |
---|
66 | |
---|
67 | if (!this->ni.isEmpty()) |
---|
68 | { |
---|
69 | StdSize ni = this->ni.getValue(); |
---|
70 | if ((ni < 0) || (ni > size)) |
---|
71 | ERROR("CAxis::checkAttributes(void)",<< "Attribut <ni> of the axis must be non-negative and smaller than size") ; |
---|
72 | } |
---|
73 | else this->ni.setValue(size); |
---|
74 | |
---|
75 | StdSize zoom_begin,zoom_end, zoom_size ; |
---|
76 | |
---|
77 | // Maybe index begins at 0 (zero) |
---|
78 | zoom_begin = (this->zoom_begin.isEmpty()) ? 0 : this->zoom_begin.getValue() ; |
---|
79 | zoom_end = (this->zoom_end.isEmpty()) ? size-1 : this->zoom_end.getValue() ; |
---|
80 | zoom_size = (this->zoom_size.isEmpty()) ? size : this->zoom_size.getValue() ; |
---|
81 | |
---|
82 | if (this->zoom_begin.isEmpty()) zoom_begin=zoom_end-zoom_size+1 ; |
---|
83 | if (this->zoom_end.isEmpty()) zoom_end=zoom_begin+zoom_size-1 ; |
---|
84 | if (this->zoom_size.isEmpty()) zoom_size=zoom_end-zoom_begin+1 ; |
---|
85 | |
---|
86 | if ( (zoom_begin < 0) || (zoom_begin > size-1) || (zoom_end<0) || (zoom_end>size-1) || (zoom_size<1) || (zoom_size>size) || (zoom_begin>zoom_end)) |
---|
87 | ERROR("CAxis::checkAttributes(void)",<< "One or more attribut of <zoom_begin>, <zoom_end>, <zoom_size>, are not well specified") ; |
---|
88 | |
---|
89 | this->zoom_begin.setValue(zoom_begin) ; |
---|
90 | this->zoom_end.setValue(zoom_end) ; |
---|
91 | this->zoom_size.setValue(zoom_size) ; |
---|
92 | |
---|
93 | StdSize true_size = value.numElements(); |
---|
94 | if (size != true_size) |
---|
95 | ERROR("CAxis::checkAttributes(void)", |
---|
96 | << "The array \'value\' has a different size that the one defined by the \'size\' attribut") |
---|
97 | |
---|
98 | this->checkData(); |
---|
99 | this->checkMask(); |
---|
100 | this->isChecked = true; |
---|
101 | } |
---|
102 | |
---|
103 | void CAxis::checkData() |
---|
104 | { |
---|
105 | if (data_begin.isEmpty()) data_begin.setValue(0); |
---|
106 | if (!data_n.isEmpty() && data_n.getValue() <= 0) |
---|
107 | { |
---|
108 | ERROR("CAxis::checkData(void)", |
---|
109 | << "Data dimension is negative (data_n).") ; |
---|
110 | } |
---|
111 | else if (data_n.isEmpty()) |
---|
112 | data_n.setValue(ni.getValue()); |
---|
113 | |
---|
114 | if (data_index.isEmpty()) |
---|
115 | { |
---|
116 | int dn = data_n.getValue(); |
---|
117 | data_index.resize(dn); |
---|
118 | for (int i = 0; i < dn; ++i) data_index(i) = (i+1); |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | void CAxis::checkMask() |
---|
123 | { |
---|
124 | int begin_mask = 0, |
---|
125 | end_mask = ni.getValue()-1; |
---|
126 | |
---|
127 | if (!zoom_begin.isEmpty()) |
---|
128 | { |
---|
129 | int zoom_end = zoom_begin.getValue() + zoom_size.getValue() - 1; |
---|
130 | |
---|
131 | begin_mask = std::max(ibegin.getValue(), zoom_begin.getValue()); |
---|
132 | end_mask = std::min(ibegin.getValue() + ni.getValue()-1, zoom_end); |
---|
133 | |
---|
134 | begin_mask -= ibegin.getValue(); |
---|
135 | end_mask -= ibegin.getValue(); |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | if (!mask.isEmpty()) |
---|
140 | { |
---|
141 | if (mask.extent(0) != ni) |
---|
142 | ERROR("CAxis::checkMask(void)", |
---|
143 | <<"the mask has not the same size than the local axis"<<endl |
---|
144 | <<"Local size is "<<ni<<"x"<<endl |
---|
145 | <<"Mask size is "<<mask.extent(0)<<"x"); |
---|
146 | for (int i = 0; i < ni; ++i) |
---|
147 | { |
---|
148 | if (i < begin_mask && i > end_mask) mask(i) = false; |
---|
149 | } |
---|
150 | } |
---|
151 | else // (!mask.hasValue()) |
---|
152 | { // Si aucun masque n'est défini, |
---|
153 | // on en crée un nouveau qui valide l'intégralité du domaine. |
---|
154 | mask.resize(ni) ; |
---|
155 | for (int i = 0; i < ni.getValue(); ++i) |
---|
156 | { |
---|
157 | if (i >= begin_mask && i <= end_mask) |
---|
158 | mask(i) = true; |
---|
159 | else mask(i) = false; |
---|
160 | } |
---|
161 | } |
---|
162 | } |
---|
163 | |
---|
164 | DEFINE_REF_FUNC(Axis,axis) |
---|
165 | |
---|
166 | ///--------------------------------------------------------------- |
---|
167 | |
---|
168 | } // namespace xios |
---|