-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.cs
192 lines (175 loc) · 8.02 KB
/
Config.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
using System;
using System.Drawing;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using ProtoBuf;
namespace KMZPOIfromOSM
{
[ProtoContract]
public class Config
{
[ProtoMember(1)]
public string importFileName = "";
[ProtoMember(2)]
public string dictionaryFileName = AppDomain.CurrentDomain.BaseDirectory.Trim('\\')+@"\OSM\dictionary.json";
[ProtoMember(3)]
public string catalogFileName = AppDomain.CurrentDomain.BaseDirectory.Trim('\\') + @"\OSM\catalog.json";
[ProtoMember(4)]
public string iconsFileName = AppDomain.CurrentDomain.BaseDirectory.Trim('\\') + @"\mapicons\poi_marker.zip";
[ProtoMember(5)]
public int hierarchyIndex = -1;
[ProtoMember(6)]
public byte saveNoCategory = 2; // 0 - Don Not Save, 1 - NoCategory, 2 - NoCategory and No Values But Keys, 3 - NoCategory and No Values But Keys List
public static string[] saveNoCategoryList = new string[] { "Don't Save", "NoCategory", "NoCategory and NoValuesButKeys", "NoCategory and No Values But Keys List" };
[ProtoMember(7)]
public int updateStatusEvery = 3;
[ProtoMember(8)]
public bool onlyHasTags = true;
[ProtoMember(9)]
public bool onlyHasName = true;
[ProtoMember(10)]
public bool fullCatName = true;
[ProtoMember(11)]
public Dictionary<string, string> onlyWithTags = new Dictionary<string, string>();
[ProtoMember(12)]
public Dictionary<string, string> onlyOneOfTags = new Dictionary<string, string>();
[ProtoMember(13)]
public DateTime onlyMdfAfter = DateTime.MinValue;
[ProtoMember(14)]
public DateTime onlyMdfBefore = DateTime.MaxValue;
[ProtoMember(15)]
public List<string> onlyOfUser = new List<string>();
[ProtoMember(16)]
public List<int> onlyVersion = new List<int>();
[ProtoMember(17)]
public double[] onlyInBox = null; // min lat, min Lon, max lat, lax lon
[ProtoMember(18)]
public string onlyInPolygon = null;
[ProtoMember(19)]
public string onlybyRoute = null;
[ProtoMember(20)]
public int onlybyRtDist = 1000;
[ProtoMember(21)]
public int onlybyRLOR = 0; // 0 - [A] All Placemarks in Route Buffer (Left & Right) // 1 - [R] Placemarks by Right side only // 2 - [L] Placemarks by Left side only
public static string[] onlybyRLORList = new string[] { "[A] All Placemarks in Route Buffer (Left & Right)", "[R] Placemarks by Right side only", "[L] Placemarks by Left side only" };
[ProtoMember(22)]
public bool onlyOneCategory = true;
[ProtoMember(23)]
public bool onlyOneButValues = true;
[ProtoMember(24)]
public bool onlyAllTags = false;
[ProtoMember(25)]
public string hasText = null;
public Regex hasTextRegex = null;
public PointF[] _in_polygon = null;
public PointF[] _in_route = null;
public OSMDictionary osmDict = new OSMDictionary();
public OSMCatalog osmCat = new OSMCatalog();
public OSMCatalogHierarchyList osmHier = new OSMCatalogHierarchyList();
public List<string> iconList = new List<string>(new string[] { "noicon", "nocategory", "novalues" });
public long noValueButKeyCatsCount = 0;
public byte currentStatus = 0; // 0 - idle, 1 - read, 2 - read ok, 3 - read bad, 4 - ask for exit, 5 - exited, 6 - read stop
public long total_nodes = 0;
public long added_nodes = 0;
public string tmpDir = AppDomain.CurrentDomain.BaseDirectory.Trim('\\') + @"\TMP_KMZPOIfromOSM\";
public string imgDir = AppDomain.CurrentDomain.BaseDirectory.Trim('\\') + @"\TMP_KMZPOIfromOSM\images\";
public void Save(string fileName)
{
string gdn = Path.GetDirectoryName(fileName);
if ((gdn == "") || (gdn == fileName) || (!fileName.Contains("\\")))
fileName = AppDomain.CurrentDomain.BaseDirectory.Trim('\\') + @"\" + fileName;
FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
ProtoBuf.Serializer.Serialize<Config>(fs, this);
fs.Close();
}
public static Config Load(string fileName, bool emptyIfNoFile)
{
Config result = new Config();
string gdn = Path.GetDirectoryName(fileName);
if ((gdn == "") || (gdn == fileName) || (!fileName.Contains("\\")))
fileName = AppDomain.CurrentDomain.BaseDirectory.Trim('\\') + @"\" + fileName;
if (!File.Exists(fileName))
{
if (emptyIfNoFile)
return result;
else
return null;
};
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
result = ProtoBuf.Serializer.Deserialize<Config>(fs);
fs.Close();
if (!File.Exists(result.importFileName)) result.importFileName = "";
if (!File.Exists(result.dictionaryFileName)) result.dictionaryFileName = "";
if (!File.Exists(result.catalogFileName)) result.catalogFileName = "";
if (!File.Exists(result.iconsFileName)) result.iconsFileName = "";
if (!File.Exists(result.onlyInPolygon)) result.onlyInPolygon = "";
if (!File.Exists(result.onlybyRoute)) result.onlybyRoute = "";
return result;
}
public event EventHandler onReloadHierarchy;
public void ReloadHierarchy()
{
ReloadHierarchy(false);
}
public void ReloadHierarchy(bool onlyBasic)
{
osmDict = new OSMDictionary();
if ((!String.IsNullOrEmpty(dictionaryFileName)) && (File.Exists(dictionaryFileName)))
{ try { osmDict = OSMDictionary.ReadFromFile(dictionaryFileName); } catch { }; };
osmCat = new OSMCatalog();
if ((!String.IsNullOrEmpty(catalogFileName)) && (File.Exists(catalogFileName)))
{ try { osmCat = OSMCatalog.ReadFromFile(catalogFileName); } catch { }; };
osmCat.dict = osmDict;
osmHier = osmCat.GetHierarchy(hierarchyIndex, onlyBasic, saveNoCategory);
iconList = new List<string>(new string[] { "noicon", "nocategory", "novalues" });
noValueButKeyCatsCount = 0;
currentStatus = 0;
total_nodes = 0;
added_nodes = 0;
_in_route = null;
_in_polygon = null;
if (onReloadHierarchy != null)
onReloadHierarchy(this, null);
}
public event EventHandler onReloadProperties;
public void ReloadProperties()
{
if (onReloadProperties != null)
onReloadProperties(this, null);
}
public void PrepareForRead()
{
ReloadHierarchy(true);
LoadPolygonsAndRoutes();
}
private void LoadPolygonsAndRoutes()
{
if((!String.IsNullOrEmpty(this.onlyInPolygon)) && (File.Exists(this.onlyInPolygon)))
{
try
{
string tof = "";
this._in_polygon = UTILS.loadpolyfull(this.onlyInPolygon, out tof);
}
catch
{
this._in_polygon = null;
};
};
if ((!String.IsNullOrEmpty(this.onlybyRoute)) && (File.Exists(this.onlybyRoute)))
{
try
{
string tof = "";
this._in_route = UTILS.loadroute(this.onlybyRoute, out tof);
}
catch
{
this._in_route = null;
};
};
}
}
}