1 2 /////////////////////////////////////////////////////////// 3 // // 4 // SAGA // 5 // // 6 // System for Automated Geoscientific Analyses // 7 // // 8 // Application Programming Interface // 9 // // 10 // Library: SAGA_API // 11 // // 12 //-------------------------------------------------------// 13 // // 14 // dataobject.h // 15 // // 16 // Copyright (C) 2005 by Olaf Conrad // 17 // // 18 //-------------------------------------------------------// 19 // // 20 // This file is part of 'SAGA - System for Automated // 21 // Geoscientific Analyses'. // 22 // // 23 // This library is free software; you can redistribute // 24 // it and/or modify it under the terms of the GNU Lesser // 25 // General Public License as published by the Free // 26 // Software Foundation, either version 2.1 of the // 27 // License, or (at your option) any later version. // 28 // // 29 // This library is distributed in the hope that it will // 30 // be useful, but WITHOUT ANY WARRANTY; without even the // 31 // implied warranty of MERCHANTABILITY or FITNESS FOR A // 32 // PARTICULAR PURPOSE. See the GNU Lesser General Public // 33 // License for more details. // 34 // // 35 // You should have received a copy of the GNU Lesser // 36 // General Public License along with this program; if // 37 // not, see <http://www.gnu.org/licenses/>. // 38 // // 39 //-------------------------------------------------------// 40 // // 41 // contact: Olaf Conrad // 42 // Institute of Geography // 43 // University of Goettingen // 44 // Goldschmidtstr. 5 // 45 // 37077 Goettingen // 46 // Germany // 47 // // 48 // e-mail: oconrad@saga-gis.org // 49 // // 50 /////////////////////////////////////////////////////////// 51 52 //--------------------------------------------------------- 53 #ifndef HEADER_INCLUDED__SAGA_API__dataobject_H 54 #define HEADER_INCLUDED__SAGA_API__dataobject_H 55 56 57 /////////////////////////////////////////////////////////// 58 // // 59 // // 60 // // 61 /////////////////////////////////////////////////////////// 62 63 //--------------------------------------------------------- 64 /** \file dataobject.h 65 * Base class for data objects and related declarations. 66 * @see CSG_Data_Object 67 * @see CSG_History 68 */ 69 70 71 /////////////////////////////////////////////////////////// 72 // // 73 // // 74 // // 75 /////////////////////////////////////////////////////////// 76 77 //--------------------------------------------------------- 78 #include "mat_tools.h" 79 #include "metadata.h" 80 81 82 /////////////////////////////////////////////////////////// 83 // // 84 // Meta-Data // 85 // // 86 /////////////////////////////////////////////////////////// 87 88 //--------------------------------------------------------- 89 #define SG_META_SOURCE "SOURCE" 90 #define SG_META_FILEPATH "FILE" 91 #define SG_META_DATABASE "DATABASE" 92 #define SG_META_PROJECTION "PROJECTION" 93 #define SG_META_HISTORY "HISTORY" 94 95 96 /////////////////////////////////////////////////////////// 97 // // 98 // Data Objects // 99 // // 100 /////////////////////////////////////////////////////////// 101 102 //--------------------------------------------------------- 103 /** 104 * Definition of available data types. This is returned by 105 * the CSG_Data_Object::Get_ObjectType() function to allow 106 * type checking at run time. 107 * @see CSG_Data_Object 108 * @see CSG_Table 109 * @see CSG_PointCloud 110 * @see CSG_Shapes 111 * @see CSG_TIN 112 * @see CSG_Grid 113 * @see CSG_Grids 114 */ 115 //--------------------------------------------------------- 116 typedef enum ESG_Data_Object_Type 117 { 118 SG_DATAOBJECT_TYPE_Grid, 119 SG_DATAOBJECT_TYPE_Grids, 120 SG_DATAOBJECT_TYPE_Table, 121 SG_DATAOBJECT_TYPE_Shapes, 122 SG_DATAOBJECT_TYPE_TIN, 123 SG_DATAOBJECT_TYPE_PointCloud, 124 SG_DATAOBJECT_TYPE_Undefined 125 } 126 TSG_Data_Object_Type; 127 128 //--------------------------------------------------------- 129 #define DATAOBJECT_NOTSET ((void *)NULL) 130 #define DATAOBJECT_CREATE ((void *)1) 131 132 SAGA_API_DLL_EXPORT void * SG_Get_Create_Pointer (void); 133 134 //--------------------------------------------------------- 135 SAGA_API_DLL_EXPORT CSG_String SG_Get_DataObject_Identifier (TSG_Data_Object_Type Type); 136 SAGA_API_DLL_EXPORT CSG_String SG_Get_DataObject_Name (TSG_Data_Object_Type Type); 137 138 139 /////////////////////////////////////////////////////////// 140 // // 141 /////////////////////////////////////////////////////////// 142 143 //--------------------------------------------------------- 144 /** Set the default value for the number of maximum samples used for building data object statistics */ 145 SAGA_API_DLL_EXPORT bool SG_DataObject_Set_Max_Samples (sLong Max_Samples); 146 147 /** Get the default value for the number of maximum samples used for building data object statistics */ 148 SAGA_API_DLL_EXPORT sLong SG_DataObject_Get_Max_Samples (void); 149 150 151 /////////////////////////////////////////////////////////// 152 // // 153 /////////////////////////////////////////////////////////// 154 155 //--------------------------------------------------------- 156 SAGA_API_DLL_EXPORT void SG_Set_History_Depth (int Depth); 157 SAGA_API_DLL_EXPORT int SG_Get_History_Depth (void); 158 SAGA_API_DLL_EXPORT void SG_Set_History_Ignore_Lists (int Ignore); 159 SAGA_API_DLL_EXPORT int SG_Get_History_Ignore_Lists (void); 160 161 162 /////////////////////////////////////////////////////////// 163 // // 164 /////////////////////////////////////////////////////////// 165 166 //--------------------------------------------------------- 167 /** 168 * CSG_Data_Object is the base class for all types of data 169 * sets, which are provided by the SAGA API. 170 * @see CSG_Table 171 * @see CSG_Shapes 172 * @see CSG_TIN 173 * @see CSG_PointCloud 174 * @see CSG_Grid 175 * @see CSG_Grids 176 */ 177 //--------------------------------------------------------- 178 class SAGA_API_DLL_EXPORT CSG_Data_Object 179 { 180 public: 181 CSG_Data_Object(void); 182 virtual ~CSG_Data_Object(void); 183 184 virtual bool Destroy (void); 185 186 /// Returns the object type as defined by TSG_Data_Object_Type. Used for run time type checking. 187 virtual TSG_Data_Object_Type Get_ObjectType (void) const = 0; 188 189 virtual bool is_Valid (void) const = 0; 190 191 virtual bool Save (const CSG_String &File, int Format = 0) = 0; 192 virtual bool Save (const char *File, int Format = 0) = 0; 193 virtual bool Save (const wchar_t *File, int Format = 0) = 0; 194 195 /// If there is an associated file data can be reloaded with this command. 196 bool Reload (void); 197 198 /// Deletes all files associated with this data object if possible. Works only with native SAGA files. Returns true on success. 199 bool Delete (void); 200 201 void Set_File_Name (const CSG_String &FileName); 202 const SG_Char * Get_File_Name (bool bNative = true) const; 203 int Get_File_Type (void) const; 204 is_File_Native(void)205 bool is_File_Native (void) const { return( m_File_bNative ); } 206 207 virtual bool Assign (CSG_Data_Object *pObject); 208 209 void Set_Name (const CSG_String &Name); 210 void Fmt_Name (const char *Format, ...); 211 void Fmt_Name (const wchar_t *Format, ...); 212 const SG_Char * Get_Name (void) const; 213 214 void Set_Description (const CSG_String &Description); 215 const SG_Char * Get_Description (void) const; 216 217 virtual void Set_Modified (bool bOn = true) { m_bModified = bOn; if( bOn && m_pOwner ) m_pOwner->Set_Modified(bOn); } is_Modified(void)218 virtual bool is_Modified (void) const { return( m_bModified ); } 219 bool Update (bool bForce = false); 220 Get_Owner(void)221 CSG_Data_Object * Get_Owner (void) const { return( m_pOwner ); } Set_Owner(CSG_Data_Object * pOwner)222 void Set_Owner (CSG_Data_Object *pOwner) { m_pOwner = pOwner; } 223 Get_MetaData(void)224 CSG_MetaData & Get_MetaData (void) const { return( *m_pMD_Source ); } Get_MetaData_DB(void)225 CSG_MetaData & Get_MetaData_DB (void) const { return( *m_pMD_Database ); } Get_History(void)226 CSG_MetaData & Get_History (void) { return( *m_pMD_History ); } Get_History(void)227 const CSG_MetaData & Get_History (void) const { return( *m_pMD_History ); } 228 229 virtual const CSG_Rect & Get_Extent (void) = 0; 230 231 CSG_Projection & Get_Projection (void); 232 const CSG_Projection & Get_Projection (void) const; 233 asTable(void)234 class CSG_Table * asTable (void) { return( Get_ObjectType() == SG_DATAOBJECT_TYPE_Table ? (class CSG_Table *)this : NULL ); } asShapes(void)235 class CSG_Shapes * asShapes (void) { return( Get_ObjectType() == SG_DATAOBJECT_TYPE_Shapes ? (class CSG_Shapes *)this : NULL ); } asTIN(void)236 class CSG_TIN * asTIN (void) { return( Get_ObjectType() == SG_DATAOBJECT_TYPE_TIN ? (class CSG_TIN *)this : NULL ); } asPointCloud(void)237 class CSG_PointCloud * asPointCloud (void) { return( Get_ObjectType() == SG_DATAOBJECT_TYPE_PointCloud ? (class CSG_PointCloud *)this : NULL ); } asGrid(void)238 class CSG_Grid * asGrid (void) { return( Get_ObjectType() == SG_DATAOBJECT_TYPE_Grid ? (class CSG_Grid *)this : NULL ); } asGrids(void)239 class CSG_Grids * asGrids (void) { return( Get_ObjectType() == SG_DATAOBJECT_TYPE_Grids ? (class CSG_Grids *)this : NULL ); } 240 241 virtual bool Set_NoData_Value (double Value); 242 virtual bool Set_NoData_Value_Range (double Lower, double Upper); 243 double Get_NoData_Value (bool bUpper = false) const { return( m_NoData_Value[bUpper ? 1 : 0] ); } 244 is_NoData_Value(double Value)245 bool is_NoData_Value (double Value) const 246 { 247 return( SG_is_NaN(Value) || (m_NoData_Value[0] < m_NoData_Value[1] ? m_NoData_Value[0] <= Value && Value <= m_NoData_Value[1] : Value == m_NoData_Value[0]) ); 248 } 249 250 bool Save_History_to_Model (const CSG_String &File) const; 251 252 virtual bool Set_Max_Samples (sLong Max_Samples); Get_Max_Samples(void)253 sLong Get_Max_Samples (void) const { return( m_Max_Samples ); } 254 255 256 protected: 257 258 CSG_Data_Object *m_pOwner; 259 260 261 void Set_File_Name (const CSG_String &FileName, bool bNative); Set_File_Type(int Type)262 void Set_File_Type (int Type) { m_File_Type = Type; } 263 264 virtual bool On_Reload (void) = 0; 265 virtual bool On_Delete (void) = 0; 266 267 bool Load_MetaData (const CSG_String &FileName); 268 bool Load_MetaData (CSG_File &Stream); 269 bool Save_MetaData (const CSG_String &FileName); 270 bool Save_MetaData (CSG_File &Stream); 271 272 void Set_Update_Flag (bool bOn = true) { m_bUpdate = bOn; } Get_Update_Flag(void)273 bool Get_Update_Flag (void) { return( m_bUpdate ); } On_Update(void)274 virtual bool On_Update (void) { return( true ); } 275 virtual bool On_NoData_Changed (void); 276 277 278 private: 279 280 bool m_bModified, m_bUpdate, m_File_bNative; 281 282 int m_File_Type; 283 284 sLong m_Max_Samples; 285 286 double m_NoData_Value[2]; 287 288 CSG_String m_FileName, m_Name, m_Description; 289 290 291 CSG_MetaData m_MetaData, *m_pMD_Source, *m_pMD_History, *m_pMD_Database; 292 293 CSG_Projection m_Projection; 294 295 }; 296 297 298 /////////////////////////////////////////////////////////// 299 // // 300 // // 301 // // 302 /////////////////////////////////////////////////////////// 303 304 //--------------------------------------------------------- 305 #endif // #ifndef HEADER_INCLUDED__SAGA_API__dataobject_H 306