forked from dekz/cartographer
/
Cartographer.cs
159 lines (130 loc) · 4.15 KB
/
Cartographer.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using System.IO;
using EARTHLib;
namespace cartographer
{
public partial class Cartographer : Form
{
public EARTHLib.ApplicationGE ge = null; //new ApplicationGEClass();
public List<Electorate> m_Electorates = null;
#region COM Hacks
[DllImport("user32.dll")]
private static extern int SetParent(
int hWndChild,
int hWndParent);
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(
int hWnd,
int nCmdShow);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool PostMessage(
int hWnd,
uint Msg,
int wParam,
int lParam);
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
private static extern bool SetWindowPos(
int hWnd,
int hWndInsertAfter,
int X,
int Y,
int cx,
int cy,
uint uFlags);
[DllImport("user32.dll")]
private static extern int SendMessage(
int hWnd,
uint Msg,
int wParam,
int lParam);
private const int HWND_TOP = 0x0;
private const int WM_COMMAND = 0x0112;
private const int WM_QT_PAINT = 0xC2DC;
private const int WM_PAINT = 0x000F;
private const int WM_SIZE = 0x0005;
private const int SWP_FRAMECHANGED = 0x0020;
#endregion
public Cartographer()
{
m_Electorates = new List<Electorate>();
ge = new ApplicationGEClass();
ShowWindowAsync(ge.GetMainHwnd(), 0);
InitializeComponent();
SetParent(ge.GetRenderHwnd(), this.Handle.ToInt32());
ResizeGoogleControl();
ElectorateImporter g_elecImporter = new ElectorateImporter();
g_elecImporter.ParseXLS();
g_elecImporter.ParseMID("data/QLD_Federal_Electoral_Boundaries.mid");
g_elecImporter.ParseMIF("data/QLD_Federal_Electoral_Boundaries.mif");
m_Electorates = g_elecImporter.MergeData();
Dms _test = new Dms(-27.579269);
Console.Out.WriteLine(_test.m_minutes);
}
private void ResizeGoogleControl()
{
SendMessage(ge.GetMainHwnd(), WM_COMMAND, WM_PAINT, 0);
PostMessage(ge.GetMainHwnd(), WM_QT_PAINT, 0, 0);
SetWindowPos(
ge.GetMainHwnd(),
HWND_TOP,
0,
0,
(int)this.Width,
(int)this.Height,
SWP_FRAMECHANGED);
SendMessage(ge.GetRenderHwnd(), WM_COMMAND, WM_SIZE, 0);
}
private void Cartographer_Resize(object sender, EventArgs e)
{
ResizeGoogleControl();
}
private void loadKML_Click(object sender, EventArgs e)
{
String textFile = kmlData.Text;
string keeper = "";
if (File.Exists(textFile))
{
StreamReader sr = File.OpenText(textFile);
string lewl;
while ((lewl = sr.ReadLine()) != null)
{
keeper += lewl;
}
ge.LoadKmlData(ref keeper);
}
else
{
MessageBox.Show("File doesn't exist");
}
}
[DllImport("user32")]
public static extern int GetWindowThreadProcessId(int hwnd, ref int lpdwProcessId);
private void Form_Closing(object sender, FormClosingEventArgs e)
{
int PID = 0;
int handle = ge.GetMainHwnd();
GetWindowThreadProcessId(handle, ref PID);
Process process = null;
try
{
process = Process.GetProcessById(PID);
}
catch
{
//process not found
}
if (process != null)
{
process.Kill();
}
}
}
}