source: XMLIO_V2/dev/dev_rv/src/node/domain.cpp @ 141

Last change on this file since 141 was 141, checked in by hozdoba, 13 years ago

Mise à jour depuis un autre dépôt

File size: 10.6 KB
Line 
1#include "domain.hpp"
2
3#include "attribute_template_impl.hpp"
4#include "object_template_impl.hpp"
5#include "group_template_impl.hpp"
6
7namespace xmlioserver
8{
9   namespace tree
10   {
11      /// ////////////////////// Définitions ////////////////////// ///
12
13      CDomain::CDomain(void)
14         : CObjectTemplate<CDomain>(), CDomainAttributes()
15         , isChecked(false), local_mask(new CMask()), relFiles()
16      { /* Ne rien faire de plus */ }
17
18      CDomain::CDomain(const StdString & id)
19         : CObjectTemplate<CDomain>(id), CDomainAttributes()
20         , isChecked(false), local_mask(new CMask()), relFiles()
21      { /* Ne rien faire de plus */ }
22
23      CDomain::~CDomain(void)
24      { /* Ne rien faire de plus */ }
25
26      ///---------------------------------------------------------------
27
28      const std::set<StdString> & CDomain::getRelFiles(void) const
29      {
30         return (this->relFiles);
31      }
32
33      bool CDomain::IsWritten(const StdString & filename) const
34      {
35         return (this->relFiles.find(filename) != this->relFiles.end());
36      }
37
38      void CDomain::addRelFile(const StdString & filename)
39      {
40         this->relFiles.insert(filename);
41      }
42
43      //----------------------------------------------------------------
44
45      StdString CDomain::GetName(void)   { return (StdString("domain")); }
46      StdString CDomain::GetDefName(void){ return (CDomain::GetName()); }
47
48      //----------------------------------------------------------------
49
50      void CDomain::checkGlobalDomain(void)
51      {
52         if ((ni_glo.isEmpty() || ni_glo.getValue() <= 0 ) ||
53             (ni_glo.isEmpty() || nj_glo.getValue() <= 0 ))
54            ERROR("CDomain::checkAttributes(void)",
55                  << "Le domaine global est mal défini,"
56                  << " vérifiez les valeurs de \'ni_glo\' et \'nj_glo\' !") ;
57      }
58
59
60      //----------------------------------------------------------------
61
62      void CDomain::checkLocalIDomain(void)
63      {
64         if (!ni.isEmpty() && !ibegin.isEmpty() && iend.isEmpty())
65            iend.setValue(ibegin.getValue() + ni.getValue() - 1) ;
66
67         else if (!ni.isEmpty() && !iend.isEmpty()   && ibegin.isEmpty())
68            ibegin.setValue( - ni.getValue() + iend.getValue() + 1) ;
69
70         else if (!ibegin.isEmpty() && !iend.isEmpty() && ni.isEmpty())
71            ni.setValue(iend.getValue() - ibegin.getValue() + 1) ;
72
73         else if (!ibegin.isEmpty() && !iend.isEmpty() &&
74                  !ni.isEmpty() && (iend.getValue() != ibegin.getValue() + ni.getValue() - 1))
75         {
76            ERROR("CDomain::checkAttributes(void)",
77                  << "Le domaine est mal défini,"
78                  << " iend est différent de (ibegin + ni - 1) !") ;
79         }
80         else
81         {
82            ERROR("CDomain::checkAttributes(void)",
83                  << "Le domaine est mal défini,"
84                  << " deux valeurs au moins parmis iend, ibegin, ni doivent être définies !") ;
85         }
86
87
88         if (ni.getValue() < 0 || ibegin.getValue() > iend.getValue() ||
89             ibegin.getValue() < 1 || iend.getValue() > ni_glo.getValue())
90            ERROR("CDomain::checkAttributes(void)",
91                  << "Domaine local mal défini,"
92                  << " vérifiez les valeurs ni, ni_glo, ibegin, iend") ;
93
94      }
95
96      //----------------------------------------------------------------
97
98      void CDomain::checkLocalJDomain(void)
99      {
100         if (!nj.isEmpty() && !jbegin.isEmpty() && jend.isEmpty())
101            jend.setValue(jbegin.getValue() + nj.getValue() - 1) ;
102
103         else if (!nj.isEmpty() && !jend.isEmpty() && jbegin.isEmpty())
104            jbegin.setValue( - nj.getValue() + jend.getValue() + 1) ;
105
106         else if (!jbegin.isEmpty() && !jend.isEmpty() && nj.isEmpty())
107            nj.setValue(jend.getValue() - jbegin.getValue() + 1) ;
108
109         else if (!jbegin.isEmpty() && !jend.isEmpty() &&
110                  !nj.isEmpty() && (jend.getValue() != jbegin.getValue() + nj.getValue() - 1))
111         {
112            ERROR("CDomain::checkAttributes(void)",
113                  << "Le domaine est mal défini,"
114                  << " iend est différent de (jbegin + nj - 1) !") ;
115         }
116         else
117         {
118            ERROR("CDomain::checkAttributes(void)",
119                  << "Le domaine est mal défini,"
120                  << " deux valeurs au moins parmis jend, jbegin, nj doivent être définies !") ;
121         }
122
123         if (nj.getValue() < 0 || jbegin.getValue() > jend.getValue() ||
124             jbegin.getValue() < 1 || jend.getValue() > nj_glo.getValue())
125            ERROR("CDomain::checkAttributes(void)",
126                  << "Domaine local mal défini,"
127                  << " vérifiez les valeurs nj, nj_glo, jbegin, jend") ;
128      }
129
130
131      //----------------------------------------------------------------
132
133      void CDomain::checkMask(void)
134      {
135         if (!mask.isEmpty())
136         {
137            unsigned int niu = ni.getValue(), nju = nj.getValue();
138            if ((mask.getValue()->shape()[0] != niu) ||
139                (mask.getValue()->shape()[1] != nju))
140               ERROR("CDomain::checkAttributes(void)",
141                     <<"Le masque n'a pas la même taille que le domaine local") ;
142         }
143         else // (!mask.hasValue())
144         { // Si aucun masque n'est défini,
145           // on en crée un nouveau qui valide l'intégralité du domaine.
146            ARRAY_CREATE(__arr, bool, 2, [ni.getValue()][nj.getValue()]);
147            for (int i = 0; i < ni.getValue(); i++)
148               for (int j = 0; j < nj.getValue(); j++)
149                  (*__arr)[i][j] = true;
150            mask.setValue(__arr);
151         }
152
153      }
154
155
156      //----------------------------------------------------------------
157
158      void CDomain::checkDomainData(void)
159      {
160         if (!data_dim.isEmpty() &&
161            !(data_dim.getValue() == 1 || data_dim.getValue() == 2))
162         {
163            ERROR("CDomain::checkAttributes(void)",
164                  << "Dimension des données non comptatible (doit être 1 ou 2) !") ;
165         }
166         else if (data_dim.isEmpty())
167         {
168            ERROR("CDomain::checkAttributes(void)",
169                  << "Dimension des données non définie !") ;
170         }
171
172         if (data_ibegin.isEmpty())
173            data_ibegin.setValue(0) ;
174         if (data_jbegin.isEmpty() && (data_dim.getValue() == 2))
175              data_jbegin.setValue(0) ;
176
177         if (!data_ni.isEmpty() && (data_ni.getValue() <= 0))
178         {
179            ERROR("CDomain::checkAttributes(void)",
180                  << "Dimension des données négative (data_ni).") ;
181         }
182         else if (data_ni.isEmpty())
183         {
184            data_ni.setValue((data_dim.getValue() == 1)
185                              ? (ni.getValue() * nj.getValue())
186                              : ni.getValue());
187         }
188
189         if (data_dim.getValue() == 2)
190         {
191            if (!data_nj.isEmpty() && (data_nj.getValue() <= 0) )
192            {
193               ERROR("CDomain::checkAttributes(void)",
194                     << "Dimension des données négative (data_nj).") ;
195            }
196            else if (data_nj.isEmpty())
197               data_nj.setValue(nj.getValue()) ;
198         }
199
200      }
201
202      //----------------------------------------------------------------
203
204      void CDomain::checkCompression(void)
205      {
206         if (!data_i_index.isEmpty())
207         {
208            int ssize = data_i_index.getValue()->size();
209            if (!data_n_index.isEmpty() &&
210               (data_n_index.getValue() != ssize))
211            {
212               ERROR("CDomain::checkAttributes(void)",
213                     <<"Dimension data_i_index incompatible avec data_n_index.") ;
214            }
215            else if (data_n_index.isEmpty())
216               data_n_index.setValue(ssize) ;
217
218            if (data_dim.getValue() == 2)
219            {
220               if (!data_j_index.isEmpty() &&
221                  (data_j_index.getValue()->size() != data_i_index.getValue()->size()))
222               {
223                  ERROR("CDomain::checkAttributes(void)",
224                        <<"Dimension data_j_index incompatible avec data_i_index.") ;
225               }
226               else if (data_j_index.isEmpty())
227               {
228                  ERROR("CDomain::checkAttributes(void)",
229                        <<"La donnée data_j_index doit être renseignée !") ;
230               }
231            }
232         }
233         else
234         {
235            if (!data_n_index.isEmpty() ||
236               ((data_dim.getValue() == 2) && (!data_j_index.isEmpty())))
237               ERROR("CDomain::checkAttributes(void)", << "data_i_index non défini") ;
238         }
239
240         if (data_n_index.isEmpty())
241         { // -> bloc re-vérifié OK
242            if (data_dim.getValue() == 1)
243            {
244               const int dni = data_ni.getValue();
245               ARRAY_CREATE(__arri, int, 1, [dni]);
246               data_n_index.setValue(dni);
247               for (int i = 0; i < dni; i++)
248                  (*__arri)[i] = i+1 ;
249               data_i_index.setValue(__arri) ;
250            }
251            else   // (data_dim == 2)
252            {
253               const int dni = data_ni.getValue() * data_nj.getValue();
254               ARRAY_CREATE(__arri, int, 1, [dni]);
255               ARRAY_CREATE(__arrj, int, 1, [dni]);
256               data_n_index.setValue(dni);
257               for(int count = 0, i = 0; i  < data_ni.getValue(); i++)
258                  for(int j = 0; j < data_nj.getValue(); j++, count++)
259               { (*__arri)[count] = i+1 ;  (*__arrj)[count] = j+1 ; }
260               data_i_index.setValue(__arri) ;
261               data_j_index.setValue(__arrj) ;
262            }
263         }
264      }
265
266      //----------------------------------------------------------------
267
268      void CDomain::checkAttributes(void)
269      {
270         if (this->isChecked) return;
271
272         this->checkGlobalDomain();
273         this->checkLocalIDomain();
274         this->checkLocalJDomain();
275
276         this->checkMask();
277         this->checkDomainData();
278         this->checkCompression();
279         this->completeMask();
280
281         this->isChecked = true;
282      }
283
284      void CDomain::completeMask(void)
285      {
286         this->local_mask->resize(data_ni.getValue(), data_nj.getValue());
287         /*this->local_mask->setDataPosition
288            (data_dim.getValue(), data_ni.getValue(), data_nj.getValue(),
289             data_ibegin.getValue(), data_jbegin.getValue(), data_n_index.getValue(),
290             data_i_index.getValue(), data_j_index.getValue());*/
291      }
292
293      boost::shared_ptr<CMask> CDomain::getLocalMask(void) const
294      {
295         return (this->local_mask);
296      }
297      ///---------------------------------------------------------------
298
299   } // namespace tree
300} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.