ToolMap
Loading...
Searching...
No Matches
database_tm.h
1/***************************************************************************
2 database_tm.h
3 extension of the database class for ToolMap
4 -------------------
5 copyright : (C) 2007 CREALP Lucien Schreiber
6 ***************************************************************************/
7
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17// comment doxygen
18
19#ifndef DATABASE_TM_H
20#define DATABASE_TM_H
21
22// For compilers that support precompilation, includes "wx/wx.h".
23#include <wx/wxprec.h>
24
25// Include wxWidgets' headers
26#ifndef WX_PRECOMP
27#include <wx/wx.h>
28#endif
29
30#include "database.h"
31
32#include "../core/prjdefmemmanage.h" // for transfering data directely
33#include "../core/projectdefmemory.h" // for transfering data directely
34#include "../core/tmsnappingmemory.h" // for snapping defintions.
35#include "../core/wxdirpickerctrlbest.h" // for PATH_ERROR definition;
36#include "../gis/tmlayermanager.h" // GIS definition
37#include "../gui/projectproperties_dlg.h" // for scale RANK function
38#include "../gui/shortcut_defs.h" // for key definitions (F1,...)
39
41
42// TABLES NAMES
43const wxString TABLE_NAME_LAYERS = _T("thematic_layers");
44const wxString TABLE_NAME_OBJECTS = _T("dmn_layer_object");
45const wxString TABLE_NAME_LAYER_AT = _T("layer_at");
46const wxString TABLE_NAME_PRJ_SETTINGS = _T("prj_settings");
47const wxString TABLE_NAME_LAYER_TYPE = _T("dmn_layer_type");
48const wxString TABLE_NAME_SCALE = _T("zoom_level");
49const wxString TABLE_NAME_TOC = _T("prj_toc");
50const wxString TABLE_NAME_QUERIES = _T("prj_queries");
51const wxString TABLE_NAME_SHORTCUT_DMN = _T("dmn_shortcut_key");
52const wxString TABLE_NAME_SHORTCUT_LIST = _T("shortcut_list");
53const wxString TABLE_NAME_SNAPPING = _T("prj_snapping");
54const wxString TABLE_NAME_STAT = _T("prj_stats");
55const wxString TABLE_NAME_LANG_DEF = _T("lang_def");
56const wxString TABLE_NAME_AT_LIST = _T("dmn_layer_attribut");
57const wxString TABLE_NAME_AT_MIX = _T("dmn_attribut_value");
58const wxString TABLE_NAME_AT_CATALOG = _T("dmn_catalog");
59const wxString TABLE_NAME_EXPORT_POLY = _T("export_poly");
60
61const wxString TABLE_NAME_GIS_GENERIC[] = {_T("generic_lines"), _T("generic_points"), _T("generic_labels"),
62 _T("generic_notes"), _T("generic_frame")};
63
64static const int TABLE_NAME_GIS_GENERIC_NUMBER = 5;
65
66const wxString TABLE_NAME_GIS_ATTRIBUTION[] = {_T("generic_aat"), _T("generic_pat"), _T("generic_lat"),
67 _T("generic_notes")};
68
69// DATABASE VERSION IS
70const int TM_DATABASE_VERSION = 233;
71
72enum tmDB_OPEN_STATUS {
73 tmDB_OPEN_FAILED = 0,
74 tmDB_OPEN_OK = 1,
75 tmDB_OPEN_FAILED_NOT_TM_DB = 2,
76 tmDB_OPEN_ERR_NOT_FOUND = 3,
77 tmDB_OPEN_FAILED_WRONG_VERSION = 100
78};
79
80class DataBaseTM : public DataBase {
81 private:
82 int m_iDBLayerIndex;
83
84 // field operations private (creation)
85 bool AddTableIfNotExist(const wxString& TableName);
86
87 bool DeleteTableIfExist(const wxString& TableName);
88
89 // general database operations
90 bool FillLayerTableTypeData();
91
92 bool FillDefaultScaleData();
93
94 bool FillShortCutTable();
95
96 // bool TableEmpty (const wxString & tablename);
97 bool CreateEmptyTMDatabase();
98 // bool _AddEnumField(ProjectDefMemoryFields * field, int layerindex);
99
100 public:
101 DataBaseTM();
102
103 ~DataBaseTM();
104
105 // utility function
106 bool CreateLangDefData();
107
108 // database operations
109 bool TableExist(const wxString& tablename); //[TESTED]
110 int OpenTMDatabase(const wxString& pathname); //[TESTED]
111 bool CreateTMDatabase(PrjDefMemManage* pPrjDefinition); //[TESTED]
112
113 // Database project operations
115
116 bool SetProjectData(PrjDefMemManage* pPrjDefinition);
117
118 bool GetProjectData(PrjDefMemManage* pPrjDefinition);
119
121
122 int GetDatabaseToolMapVersion(); //[TESTED]
123
124 bool SetProjectExportData(int iExportType, const wxString& spath);
125
126 bool SetProjectLastExported(const wxArrayString& layers);
127
128 bool SetProjectBackupPath(const wxString& spath);
129
130 int GetProjectExportData(int& iExportType, wxString& spath);
131
132 wxArrayString GetProjectLastExported();
133
134 int GetProjectBackupPath(wxString& spath);
135
136 // Database layer operations
137 bool AddLayer(ProjectDefMemoryLayers* myLayer);
138
140
141 void SetActiveLayerId(ProjectDefMemoryLayers* myLayer);
142
143 int GetActiveLayerId() {
144 return m_iDBLayerIndex;
145 }
146
147 int GetNextLayer(ProjectDefMemoryLayers* myLayer);
148
149 bool UpdateLayer(ProjectDefMemoryLayers* myLayer, wxString& sSqlSentence);
150
151 bool DeleteLayer(const wxArrayLong& deletelist, PrjDefMemManage* projectdef, wxString& sSqlSentence);
152
153 int GetLayerID(TOC_GENERIC_NAME layertype);
154
155 // Database object operations
156 bool AddObject(ProjectDefMemoryObjects* myObject, int DBlayerIndex = -1);
157
158 bool EditObject(ProjectDefMemoryObjects* myObject);
159
160 bool DataBaseGetNextResultAsObject(ProjectDefMemoryObjects* object, int ilayertype);
161
162 int DeleteMultipleObjects(PrjDefMemManage* pProjet);
163
164 void DeleteLayersObjects(int iLayer, wxString& sSqlSentence);
165
166 bool LoadLayerObjects(ProjectDefMemoryLayers* layer);
167
168 // field operations
169 bool AddField(ProjectDefMemoryFields* myField);
170
171 bool GetFields(PrjMemFieldArray& fieldarray, ProjectDefMemoryLayers* actuallayer);
172
174
175 bool UpdateField(ProjectDefMemoryFields* myField, int iLayer, wxString& sSqlSentence);
176
177 bool DeleteField(wxArrayString& myFields, int iLayer, wxString& sSqlSentence);
178
179 bool DeleteFields(int iLayer);
180
181 // database query
182 bool GetObjectListByLayerType(int ilayertype, bool bOrder = FALSE);
183
184 wxArrayString GetLayerNameByType(int ilayertype);
185
186 // database Scale operations
187 long GetNextScaleValue(long& DBindex, bool bFirst);
188
189 bool EditScale(ProjectDefMemoryScale* myScaleObj);
190
191 int DeleteMultipleScales(PrjDefMemManage* pProjet);
192
193 // database rank operations
194 bool SetRank(ListGenReport* list, int icol, const wxString& stable, const wxString& sfield,
195 bool bStringType = FALSE, const wxString& rankfield = _T("RANK"));
196
197 bool SetScaleRank(ScaleList* list, int icol, const wxString& stable, const wxString& sfield,
198 const wxString& rankfield = _T("RANK"));
199
200 // projects operations
201 PrjDefMemManage* GetProjectDataFromDB();
202
204
205 // database TOC operations
207
208 tmLayerProperties* GetNextTOCEntry(bool userelativepath);
209
210 long AddTOCLayer(tmLayerProperties* item);
211
212 bool RemoveTOCLayer(const long& itemid);
213
214 void PrepareTOCStatusUpdate(wxString& sentence, tmLayerProperties* item, int itemRank = 0,
215 const wxString& symbology = wxEmptyString);
216
217 // database query operations
218 bool GetNextQueries(long& qid, wxString& name, wxString& description, bool bfirst);
219
220 bool GetQueriesById(const long& qid, int& target, wxString& name, wxString& description);
221
222 bool EditQueries(int target, const wxString& name, const wxString& description, long qid = -1);
223
224 bool DeleteQuery(long qid);
225
226 // database shortcut operations
227 bool GetNextShortcutByLayerType(int layer_type, wxString& key, wxString& description, bool bFirstLoop);
228
229 bool GetAllUnusedShortcuts(wxArrayString& keylist);
230
231 bool GetNextShortCutObject(long& shortcutid, const int& key, bool bFirstLoop);
232
233 bool EditShortcut(int shortcutkey, const wxString& description, const wxArrayLong& types);
234
235 bool DeleteShortcut(int shortcutkey);
236
237 bool GetNextShortcutFull(bool bFirstLoop, int& layertype, int& key, wxString& description, long& shortcutvalue);
238
239 // database snapping operations
240 bool GetNextSnapping(long& lid, wxString& layername, int& snapstatus, bool bfirstloop);
241
242 bool GetValidLayersForSnapping(wxArrayLong& lids, wxArrayString& lnames);
243
244 bool AddLayersSnapping(const wxArrayLong& lids, int snappingstatus);
245
246 bool DeleteLayerSnapping(int layersid);
247
248 bool SaveSnappingAllStatus(tmSnappingMemory* snapmemory);
249
250 // database snapping tolerence operations
251 bool SetSnappingTolerence(int iTolerence);
252
254
255 // database geometry operations
256 bool GeometryDelete(wxArrayLong* selected, int layertype);
257
258 long GeometrySave(OGRGeometry* geometry, int layertype);
259
260 bool GeometryUpdate(OGRGeometry* geometry, long oid, int layertype);
261
262 OGRGeometry* GeometryLoad(long oid, int layertype);
263
264 // attribution operations
265 bool DeleteAttribution(wxArrayLong* selected, int layertype);
266
267 wxArrayLong GetObjectsFromFeature(long selectedfeature, int layertype);
268
269 long GetSelectedLayerId(long ojectid);
270
271 bool DeleteAdvancedAttribution(long selectedobject, long selectedlayerid);
272
273 bool SaveBezierSettings(BezierSettingsData* data);
274
275 bool LoadBezierSettings(BezierSettingsData* data);
276
277 // static path convertion
278 static bool ConvertPath(wxString& path);
279};
280
281#endif
Definition beziersettings_dlg.h:31
Definition database_tm.h:80
bool IsProjectDataDefined()
Check if project data are defined.
Definition database_tm.cpp:459
bool UpdateDataBaseProject(PrjDefMemManage *pProjDef)
Update database.
Definition database_tm.cpp:1875
bool DeleteAttribution(wxArrayLong *selected, int layertype)
Delete attribution from the database.
Definition database_tm.cpp:2762
bool EditObject(ProjectDefMemoryObjects *myObject)
Insert or update an object.
Definition database_tm.cpp:994
bool GetNextShortcutByLayerType(int layer_type, wxString &key, wxString &description, bool bFirstLoop)
Load shortcut from the DB based on layer type.
Definition database_tm.cpp:2300
bool InitTOCGenericLayers()
Init the TOC.
Definition database_tm.cpp:2010
bool GeometryDelete(wxArrayLong *selected, int layertype)
Delete geometry from the database.
Definition database_tm.cpp:2666
bool SaveSnappingAllStatus(tmSnappingMemory *snapmemory)
Save snapping status to the database.
Definition database_tm.cpp:2593
bool GetFields(PrjMemFieldArray &fieldarray, ProjectDefMemoryLayers *actuallayer)
Get all fields for specified layer.
Definition database_tm.cpp:1319
bool SetScaleRank(ScaleList *list, int icol, const wxString &stable, const wxString &sfield, const wxString &rankfield=_T("RANK"))
Update a rank field for scale table.
Definition database_tm.cpp:1795
bool SetRank(ListGenReport *list, int icol, const wxString &stable, const wxString &sfield, bool bStringType=FALSE, const wxString &rankfield=_T("RANK"))
Update a rank field.
Definition database_tm.cpp:1750
int GetProjectBackupPath(wxString &spath)
Get the backup path from the database.
Definition database_tm.cpp:738
bool GetAllUnusedShortcuts(wxArrayString &keylist)
Get All unused shortcut key.
Definition database_tm.cpp:2337
bool DeleteLayer(const wxArrayLong &deletelist, PrjDefMemManage *projectdef, wxString &sSqlSentence)
Prepare statement for deleting layer(s)
Definition database_tm.cpp:909
bool GetQueriesById(const long &qid, int &target, wxString &name, wxString &description)
Get a queries by ID.
Definition database_tm.cpp:2208
bool AddLayersSnapping(const wxArrayLong &lids, int snappingstatus)
Save new snapping layers into database.
Definition database_tm.cpp:2558
bool GetNextSnapping(long &lid, wxString &layername, int &snapstatus, bool bfirstloop)
Get the snapping from database.
Definition database_tm.cpp:2488
bool SetSnappingTolerence(int iTolerence)
Save the tolerence into database.
Definition database_tm.cpp:2626
bool DeleteLayerSnapping(int layersid)
Delete a snapping layer from the database.
Definition database_tm.cpp:2580
bool DeleteQuery(long qid)
Delete a query.
Definition database_tm.cpp:2279
bool GetNextQueries(long &qid, wxString &name, wxString &description, bool bfirst)
Get all queries.
Definition database_tm.cpp:2159
void DeleteLayersObjects(int iLayer, wxString &sSqlSentence)
Delete all objects from a layer.
Definition database_tm.cpp:1091
bool GetProjectData(PrjDefMemManage *pPrjDefinition)
Retrieve basic project data.
Definition database_tm.cpp:515
int GetLayerID(TOC_GENERIC_NAME layertype)
Return the layer ID based on layer type.
Definition database_tm.cpp:947
bool RemoveTOCLayer(const long &itemid)
Delete a TOC item from the database.
Definition database_tm.cpp:2116
bool AddLayerPolygonDefaultBorder(ProjectDefMemoryLayers *myLayer)
Add border default value for polygons layer.
Definition database_tm.cpp:784
bool UpdateField(ProjectDefMemoryFields *myField, int iLayer, wxString &sSqlSentence)
Prepare statement for updating fields.
Definition database_tm.cpp:1410
bool GetObjectListByLayerType(int ilayertype, bool bOrder=FALSE)
Retrive objects from the object table.
Definition database_tm.cpp:1604
int GetSnappingTolerence()
Get the tolerence from the database.
Definition database_tm.cpp:2642
bool UpdateLayer(ProjectDefMemoryLayers *myLayer, wxString &sSqlSentence)
Prepare statement for updating layer.
Definition database_tm.cpp:863
bool EditShortcut(int shortcutkey, const wxString &description, const wxArrayLong &types)
Append or edit a shortcut.
Definition database_tm.cpp:2412
bool EditQueries(int target, const wxString &name, const wxString &description, long qid=-1)
Edit or add a query.
Definition database_tm.cpp:2241
bool GetNextShortCutObject(long &shortcutid, const int &key, bool bFirstLoop)
Get checked values for given shortcut key.
Definition database_tm.cpp:2365
int GetProjectExportData(int &iExportType, wxString &spath)
Get the export data from the database.
Definition database_tm.cpp:673
bool DeleteShortcut(int shortcutkey)
Delete specified shortcut.
Definition database_tm.cpp:2391
tmLayerProperties * GetNextTOCEntry(bool userelativepath)
Get entry from the TOC.
Definition database_tm.cpp:2047
bool DeleteField(wxArrayString &myFields, int iLayer, wxString &sSqlSentence)
Prepare statement for deleting.
Definition database_tm.cpp:1500
long AddTOCLayer(tmLayerProperties *item)
Add TOC item to the database.
Definition database_tm.cpp:2083
wxArrayString GetLayerNameByType(int ilayertype)
Return list of layers name for selected type.
Definition database_tm.cpp:1635
int GetFieldsFromDB(PrjDefMemManage *myPrj)
Fill an existing project with fields.
Definition database_tm.cpp:1192
bool GetValidLayersForSnapping(wxArrayLong &lids, wxArrayString &lnames)
Get all layers valid for snapping.
Definition database_tm.cpp:2525
bool InitProjectWithStartingWizard(PrjDefMemManage *pPrjDefinition)
Definition database_tm.cpp:569
bool GetNextShortcutFull(bool bFirstLoop, int &layertype, int &key, wxString &description, long &shortcutvalue)
Get Full informations for shortcuts.
Definition database_tm.cpp:2445
Definition database.h:55
Manage a report list.
Definition listgenreport.h:63
Definition prjdefmemmanage.h:54
Storing Fields property in memory.
Definition projectdefmemory.h:198
Storing layers properties in memory.
Definition projectdefmemory.h:246
Storing object properties in memory.
Definition projectdefmemory.h:168
Definition projectdefmemory.h:276
Definition projectproperties_dlg.h:117
Storing object of layer type.
Definition tmlayerproperties.h:47
Store snapping status into memory.
Definition tmsnappingmemory.h:59
Definition of class DataBase.