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

Last change on this file since 168 was 168, checked in by hozdoba, 13 years ago
File size: 10.0 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 {
8namespace tree {
9   
10   /// ////////////////////// Définitions ////////////////////// ///
11
12   CDomain::CDomain(void)
13      : CObjectTemplate<CDomain>(), CDomainAttributes()
14      , isChecked(false), local_mask(new CMask()), relFiles()
15   { /* Ne rien faire de plus */ }
16
17   CDomain::CDomain(const StdString & id)
18      : CObjectTemplate<CDomain>(id), CDomainAttributes()
19      , isChecked(false), local_mask(new CMask()), relFiles()
20   { /* Ne rien faire de plus */ }
21
22   CDomain::~CDomain(void)
23   { /* Ne rien faire de plus */ }
24
25   ///---------------------------------------------------------------
26
27   const std::set<StdString> & CDomain::getRelFiles(void) const
28   {
29      return (this->relFiles);
30   }
31
32   bool CDomain::IsWritten(const StdString & filename) const
33   {
34      return (this->relFiles.find(filename) != this->relFiles.end());
35   }
36
37   void CDomain::addRelFile(const StdString & filename)
38   {
39      this->relFiles.insert(filename);
40   }
41
42   //----------------------------------------------------------------
43
44   StdString CDomain::GetName(void)   { return (StdString("domain")); }
45   StdString CDomain::GetDefName(void){ return (CDomain::GetName()); }
46   ENodeType CDomain::GetType(void)   { return (eDomain); }
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           
258            for(int count = 0, i = 0; i  < data_ni.getValue(); i++)
259               for(int j = 0; j < data_nj.getValue(); j++, count++)
260               { 
261                  (*__arri)[count] = i+1 ;
262                  (*__arrj)[count] = j+1 ;
263               }
264               
265            data_i_index.setValue(__arri) ;
266            data_j_index.setValue(__arrj) ;
267         }
268      }
269   }
270
271   //----------------------------------------------------------------
272
273   void CDomain::checkAttributes(void)
274   {
275      if (this->isChecked) return;
276
277      this->checkGlobalDomain();
278      this->checkLocalIDomain();
279      this->checkLocalJDomain();
280
281      this->checkMask();
282      this->checkDomainData();
283      this->checkCompression();
284      this->completeMask();
285
286      this->isChecked = true;
287   }
288
289   void CDomain::completeMask(void)
290   {
291      this->local_mask->resize(data_ni.getValue(), data_nj.getValue());
292      /*this->local_mask->setDataPosition
293         (data_dim.getValue(), data_ni.getValue(), data_nj.getValue(),
294          data_ibegin.getValue(), data_jbegin.getValue(), data_n_index.getValue(),
295          data_i_index.getValue(), data_j_index.getValue());*/
296   }
297
298   boost::shared_ptr<CMask> CDomain::getLocalMask(void) const
299   {
300      return (this->local_mask);
301   }
302   ///---------------------------------------------------------------
303
304} // namespace tree
305} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.