[219] | 1 | #include "axis.hpp" |
---|
| 2 | |
---|
[352] | 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" |
---|
[219] | 9 | |
---|
[335] | 10 | namespace xios { |
---|
[540] | 11 | |
---|
[219] | 12 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 13 | |
---|
| 14 | CAxis::CAxis(void) |
---|
| 15 | : CObjectTemplate<CAxis>() |
---|
[540] | 16 | , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject() |
---|
[219] | 17 | { /* Ne rien faire de plus */ } |
---|
| 18 | |
---|
| 19 | CAxis::CAxis(const StdString & id) |
---|
| 20 | : CObjectTemplate<CAxis>(id) |
---|
[540] | 21 | , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject() |
---|
[219] | 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; |
---|
[351] | 55 | if (this->size.isEmpty()) |
---|
| 56 | ERROR("CAxis::checkAttributes(void)",<< "Attribut <size> of the axis must be specified") ; |
---|
[219] | 57 | StdSize size = this->size.getValue(); |
---|
[540] | 58 | |
---|
[551] | 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 | |
---|
[351] | 75 | StdSize zoom_begin,zoom_end, zoom_size ; |
---|
[540] | 76 | |
---|
[551] | 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() ; |
---|
[351] | 80 | zoom_size = (this->zoom_size.isEmpty()) ? size : this->zoom_size.getValue() ; |
---|
[540] | 81 | |
---|
[351] | 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 ; |
---|
[540] | 85 | |
---|
[553] | 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)) |
---|
[351] | 87 | ERROR("CAxis::checkAttributes(void)",<< "One or more attribut of <zoom_begin>, <zoom_end>, <zoom_size>, are not well specified") ; |
---|
[551] | 88 | |
---|
[351] | 89 | this->zoom_begin.setValue(zoom_begin) ; |
---|
| 90 | this->zoom_end.setValue(zoom_end) ; |
---|
| 91 | this->zoom_size.setValue(zoom_size) ; |
---|
[540] | 92 | |
---|
[369] | 93 | StdSize true_size = value.numElements(); |
---|
[219] | 94 | if (size != true_size) |
---|
| 95 | ERROR("CAxis::checkAttributes(void)", |
---|
[421] | 96 | << "The array \'value\' has a different size that the one defined by the \'size\' attribut") |
---|
[219] | 97 | |
---|
[551] | 98 | this->checkData(); |
---|
| 99 | this->checkMask(); |
---|
[219] | 100 | this->isChecked = true; |
---|
| 101 | } |
---|
| 102 | |
---|
[551] | 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()) |
---|
[553] | 112 | data_n.setValue(ni.getValue()); |
---|
[551] | 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 | |
---|
[540] | 164 | DEFINE_REF_FUNC(Axis,axis) |
---|
| 165 | |
---|
[219] | 166 | ///--------------------------------------------------------------- |
---|
| 167 | |
---|
[335] | 168 | } // namespace xios |
---|