Documentation for OpenFLUID 2.2.0
SpatialUnit.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 /**
33  @file SpatialUnit.hpp
34 
35  @author Jean-Christophe Fabre <jean-christophe.fabre@inra.fr>
36 */
37 
38 
39 #ifndef __OPENFLUID_CORE_SPATIALUNIT_HPP__
40 #define __OPENFLUID_CORE_SPATIALUNIT_HPP__
41 
42 
43 #include <map>
44 #include <string>
45 
46 #include <openfluid/dllexport.hpp>
51 
52 
53 class OGRGeometry;
54 
55 
56 namespace openfluid { namespace core {
57 
58 
59 /**
60  Type for a hashmap of lists of units, indexed by UnitClass
61 */
62 typedef std::map<UnitsClass_t,UnitsCollection> UnitsListByClassMap_t;
63 
64 
65 /**
66  Type for a list of pointers on Unit
67 
68  @cond OpenFLUID:completion
69  {
70  "contexts" : ["ANYWARE"],
71  "menupath" : ["Types", "Spatial domain"],
72  "title" : "List of pointers to spatial units",
73  "text" : "openfluid::core::UnitsPtrList_t %%SEL_START%%UnitsPtrList%%SEL_END%%"
74  }
75  @endcond
76 */
77 typedef std::list<SpatialUnit*> UnitsPtrList_t;
78 
79 
80 /**
81  Type for a map associating a unit class to a list of pointers on Unit
82 */
83 typedef std::map<UnitsClass_t,UnitsPtrList_t> LinkedUnitsListByClassMap_t;
84 
85 
86 /**
87  Class defining a spatial unit
88 
89  example of use:
90  @snippet misc/spatial.cpp spatialunit
91 
92  @cond OpenFLUID:completion
93  {
94  "contexts" : ["ANYWARE"],
95  "menupath" : ["Types", "Spatial domain"],
96  "title" : "Spatial unit",
97  "text" : "openfluid::core::SpatialUnit %%SEL_START%%Unit%%SEL_END%%"
98  }
99  @endcond
100 
101  @cond OpenFLUID:completion
102  {
103  "contexts" : ["ANYWARE"],
104  "menupath" : ["Types", "Spatial domain"],
105  "title" : "Pointer to spatial unit",
106  "text" : "openfluid::core::SpatialUnit* %%SEL_START%%UnitPtr%%SEL_END%%"
107  }
108  @endcond
109 */
111 {
112  private:
113 
114  UnitID_t m_ID;
115 
116  UnitsClass_t m_Class;
117 
118  openfluid::core::PcsOrd_t m_PcsOrder;
119 
120  LinkedUnitsListByClassMap_t m_FromUnits;
121 
122  LinkedUnitsListByClassMap_t m_ToUnits;
123 
124  LinkedUnitsListByClassMap_t m_ParentUnits;
125 
126  LinkedUnitsListByClassMap_t m_ChildrenUnits;
127 
128  Attributes m_Attributes;
129 
130  Variables m_Variables;
131 
132  EventsCollection m_Events;
133 
134  OGRGeometry* m_Geometry;
135 
136 
137  public:
138 
139  SpatialUnit() = delete;
140 
141  /*
142  Constructor
143  @param[in] aClass the class of the unit
144  @param[in] anID the ID of the unit
145  @param[in] aPcsOrder the process order of the unit
146  */
147  SpatialUnit(const UnitsClass_t& aClass, const UnitID_t anID, const PcsOrd_t aPcsOrder);
148 
149  /*
150  Destructor
151  */
153 
154  /**
155  Returns the process order of the unit
156  */
157  inline PcsOrd_t getProcessOrder() const
158  {
159  return m_PcsOrder;
160  };
161 
162  /**
163  Returns the ID of the unit
164  */
165  inline UnitID_t getID() const
166  {
167  return m_ID;
168  };
169 
170  /**
171  Returns the class of the unit
172  */
173  inline UnitsClass_t getClass() const
174  {
175  return m_Class;
176  };
177 
178  bool addToUnit(SpatialUnit* aUnit);
179 
180  bool addFromUnit(SpatialUnit* aUnit);
181 
183 
184  bool addChildUnit(SpatialUnit* aUnit);
185 
186  /**
187  Returns a list of units, of the requested class, connected to this unit.
188  Returns nullptr if no units of the requested class are connected to this unit.
189  @param[in] aClass the requested class
190  */
192 
193  const UnitsPtrList_t* toSpatialUnits(const UnitsClass_t& aClass) const;
194 
195  /**
196  @deprecated Since version 2.1.0. Use openfluid::core::SpatialUnit::toSpatialUnits(const UnitsClass_t&) instead
197  */
198  [[deprecated]] UnitsPtrList_t* getToUnits(const UnitsClass_t& aClass)
199  {
200  return toSpatialUnits(aClass);
201  }
202 
203  /**
204  @deprecated Since version 2.1.0.
205  Use openfluid::core::SpatialUnit::toSpatialUnits(const UnitsClass_t&) const instead
206  */
207  [[deprecated]] const UnitsPtrList_t* getToUnits(const UnitsClass_t& aClass) const
208  {
209  return toSpatialUnits(aClass);
210  }
211 
212  /**
213  Returns a list of units, of the requested class, connected from this unit.
214  Returns nullptr if no units of the requested class are connected from this unit.
215  @param[in] aClass the requested class
216  */
218 
219  const UnitsPtrList_t* fromSpatialUnits(const UnitsClass_t& aClass) const;
220 
221  /**
222  @deprecated Since version 2.1.0. Use openfluid::core::SpatialUnit::fromSpatialUnits(const UnitsClass_t&) instead
223  */
224  [[deprecated]] UnitsPtrList_t* getFromUnits(const UnitsClass_t& aClass)
225  {
226  return fromSpatialUnits(aClass);
227  }
228 
229  /**
230  @deprecated Since version 2.1.0.
231  Use openfluid::core::SpatialUnit::fromSpatialUnits(const UnitsClass_t&) const instead
232  */
233  const UnitsPtrList_t* getFromUnits(const UnitsClass_t& aClass) const
234  {
235  return fromSpatialUnits(aClass);
236  }
237 
238  /**
239  Returns a list of parent units of the requested class.
240  Returns nullptr if this unit has no parent
241  @param[in] aClass the requested class
242  */
244 
245  const UnitsPtrList_t* parentSpatialUnits(const UnitsClass_t& aClass) const;
246 
247  /**
248  @deprecated Since version 2.1.0. Use openfluid::core::SpatialUnit::parentSpatialUnits(const UnitsClass_t&) instead
249  */
250  [[deprecated]] UnitsPtrList_t* getParentUnits(const UnitsClass_t& aClass)
251  {
252  return parentSpatialUnits(aClass);
253  }
254 
255  /**
256  @deprecated Since version 2.1.0.
257  Use openfluid::core::SpatialUnit::parentSpatialUnits(const UnitsClass_t&) const instead
258  */
259  [[deprecated]] const UnitsPtrList_t* getParentUnits(const UnitsClass_t& aClass) const
260  {
261  return parentSpatialUnits(aClass);
262  }
263 
264  /**
265  Returns a list of children units of the requested class.
266  Returns nullptr if this unit has no child
267  @param[in] aClass the requested class
268  */
270 
271  const UnitsPtrList_t* childSpatialUnits(const UnitsClass_t& aClass) const;
272 
273  /**
274  @deprecated Since version 2.1.0. Use openfluid::core::SpatialUnit::childSpatialUnits(const UnitsClass_t&) instead
275  */
276  [[deprecated]] UnitsPtrList_t* getChildrenUnits(const UnitsClass_t& aClass)
277  {
278  return childSpatialUnits(aClass);
279  }
280 
281  /**
282  @deprecated Since version 2.1.0.
283  Use openfluid::core::SpatialUnit::childSpatialUnits(const UnitsClass_t&) const instead
284  */
285  [[deprecated]] const UnitsPtrList_t* getChildrenUnits(const UnitsClass_t& aClass) const
286  {
287  return childSpatialUnits(aClass);
288  }
289 
291  {
292  return &m_Attributes;
293  }
294 
295  inline const Attributes* attributes() const
296  {
297  return &m_Attributes;
298  }
299 
301  {
302  return &m_Variables;
303  }
304 
305  const Variables* variables() const
306  {
307  return &m_Variables;
308  }
309 
311  {
312  return &m_Events;
313  }
314 
315  inline const EventsCollection* events() const
316  {
317  return &m_Events;
318  }
319 
320  void streamContents(std::ostream& OStream);
321 
322  void setProcessOrder(unsigned int PcsOrder)
323  {
324  m_PcsOrder = PcsOrder;
325  }
326 
327  OGRGeometry* geometry()
328  {
329  return m_Geometry;
330  }
331 
332  const OGRGeometry* geometry() const
333  {
334  return m_Geometry;
335  }
336 
337  bool importGeometryFromWkt(const std::string& WKT);
338 
339  std::string exportGeometryToWkt() const;
340 
342 
343 };
344 
345 /**
346  @deprecated Since version 2.1.0. Use openfluid::core::SpatialUnit instead
347 */
348 [[deprecated]] typedef SpatialUnit Unit;
349 
350 
351 } } // namespace openfluid::core
352 
353 
354 #endif /* __OPENFLUID_CORE_SPATIALUNIT_HPP__ */
355 
Definition: Attributes.hpp:58
Definition: EventsCollection.hpp:71
Definition: SpatialUnit.hpp:111
const EventsCollection * events() const
Definition: SpatialUnit.hpp:315
const UnitsPtrList_t * getParentUnits(const UnitsClass_t &aClass) const
Definition: SpatialUnit.hpp:259
const UnitsPtrList_t * getChildrenUnits(const UnitsClass_t &aClass) const
Definition: SpatialUnit.hpp:285
UnitsClass_t getClass() const
Definition: SpatialUnit.hpp:173
void setProcessOrder(unsigned int PcsOrder)
Definition: SpatialUnit.hpp:322
const UnitsPtrList_t * fromSpatialUnits(const UnitsClass_t &aClass) const
UnitsPtrList_t * getToUnits(const UnitsClass_t &aClass)
Definition: SpatialUnit.hpp:198
bool addParentUnit(SpatialUnit *aUnit)
const UnitsPtrList_t * parentSpatialUnits(const UnitsClass_t &aClass) const
UnitsPtrList_t * getChildrenUnits(const UnitsClass_t &aClass)
Definition: SpatialUnit.hpp:276
std::string exportGeometryToWkt() const
bool addChildUnit(SpatialUnit *aUnit)
const Attributes * attributes() const
Definition: SpatialUnit.hpp:295
const UnitsPtrList_t * getToUnits(const UnitsClass_t &aClass) const
Definition: SpatialUnit.hpp:207
bool addToUnit(SpatialUnit *aUnit)
void streamContents(std::ostream &OStream)
const Variables * variables() const
Definition: SpatialUnit.hpp:305
const UnitsPtrList_t * childSpatialUnits(const UnitsClass_t &aClass) const
bool importGeometryFromWkt(const std::string &WKT)
SpatialUnit(const UnitsClass_t &aClass, const UnitID_t anID, const PcsOrd_t aPcsOrder)
const OGRGeometry * geometry() const
Definition: SpatialUnit.hpp:332
PcsOrd_t getProcessOrder() const
Definition: SpatialUnit.hpp:157
const UnitsPtrList_t * getFromUnits(const UnitsClass_t &aClass) const
Definition: SpatialUnit.hpp:233
UnitsPtrList_t * getFromUnits(const UnitsClass_t &aClass)
Definition: SpatialUnit.hpp:224
EventsCollection * events()
Definition: SpatialUnit.hpp:310
UnitsPtrList_t * fromSpatialUnits(const UnitsClass_t &aClass)
OGRGeometry * geometry()
Definition: SpatialUnit.hpp:327
const UnitsPtrList_t * toSpatialUnits(const UnitsClass_t &aClass) const
UnitID_t getID() const
Definition: SpatialUnit.hpp:165
UnitsPtrList_t * parentSpatialUnits(const UnitsClass_t &aClass)
UnitsPtrList_t * toSpatialUnits(const UnitsClass_t &aClass)
UnitsPtrList_t * getParentUnits(const UnitsClass_t &aClass)
Definition: SpatialUnit.hpp:250
Variables * variables()
Definition: SpatialUnit.hpp:300
bool addFromUnit(SpatialUnit *aUnit)
Attributes * attributes()
Definition: SpatialUnit.hpp:290
UnitsPtrList_t * childSpatialUnits(const UnitsClass_t &aClass)
Definition: Variables.hpp:53
#define OPENFLUID_API
Definition: dllexport.hpp:86
unsigned int UnitID_t
Definition: TypeDefs.hpp:70
std::map< UnitsClass_t, UnitsCollection > UnitsListByClassMap_t
Definition: SpatialUnit.hpp:62
SpatialUnit Unit
Definition: SpatialUnit.hpp:348
std::string UnitsClass_t
Definition: TypeDefs.hpp:98
std::map< UnitsClass_t, UnitsPtrList_t > LinkedUnitsListByClassMap_t
Definition: SpatialUnit.hpp:83
int PcsOrd_t
Definition: TypeDefs.hpp:84
std::list< SpatialUnit * > UnitsPtrList_t
Definition: SpatialUnit.hpp:77
Definition: ApplicationException.hpp:47