forked from tomojitakasu/RTKLIB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeview.cpp
435 lines (410 loc) · 13.8 KB
/
geview.cpp
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
//---------------------------------------------------------------------------
// geview.c: google earth view
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <mshtml.h>
#include "rtklib.h"
#include "geview.h"
#include "plotmain.h"
#define RTKPLOT_GE_FILE L"rtkplot_ge.htm"
#define TIMEOUT_GE 5000 // timeout of GE load (ms)
#define MAXTRACKS 4096 // max number of track poitnts
#define INIT_RANGE 4.322 // initial range (km)
#define MIN_RANGE 0.01 // min range (km)
#define MAX_RANGE 20000.0 // max range (km)
#define TILT_ANGLE 70.0 // tilt angle (deg)
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)>(y)?(x):(y))
#define ATAN2(x,y) ((x)*(x)+(y)*(y)>1E-12?atan2(x,y):0.0)
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SHDocVw_OCX"
#pragma resource "*.dfm"
TGoogleEarthView *GoogleEarthView;
//---------------------------------------------------------------------------
__fastcall TGoogleEarthView::TGoogleEarthView(TComponent* Owner)
: TForm(Owner)
{
State=0;
Expand=Rotate=0;
Lat=Lon=LatSet=LonSet=0.0;
Range=RangeSet=0.0;
Heading=HeadingSet=0.0;
Clear();
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::FormCreate(TObject *Sender)
{
UnicodeString url,exe,dir=L".";
wchar_t *p,*q;
exe=Application->ExeName; // exe directory
p=exe.c_str();
if ((q=wcsrchr(p,L'\\'))) {
dir=exe.SubString(1,q-p);
}
url=L"file://"+dir+L"\\"+RTKPLOT_GE_FILE;
WebBrowser->Navigate(url.c_str());
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::Timer1Timer(TObject *Sender)
{
IHTMLDocument3 *doc=NULL;
IHTMLElement *ele1=NULL,*ele2=NULL;
VARIANT var;
double lat,lon,range,heading;
int state;
if (!WebBrowser->Document) return;
WebBrowser->Document->QueryInterface(IID_IHTMLDocument3,(void **)&doc);
if (!doc) return;
doc->getElementById(L"state",&ele1);
doc->getElementById(L"view", &ele2);
doc->Release();
if (!ele1||!ele2) return;
VariantInit(&var);
if (ele1->getAttribute(L"value",0,&var)!=S_OK||
swscanf(var.bstrVal,L"%d",&state)<1||
ele2->getAttribute(L"value",0,&var)!=S_OK||
swscanf(var.bstrVal,L"%lf,%lf,%lf,%lf",&lat,&lon,&range,&heading)<4) {
VariantClear(&var);
return;
}
VariantClear(&var);
Lat=lat;
Lon=lon;
Range=range;
Heading=heading;
if (!State&&state) {
State=state;
UpdateOpts();
if (LatSet!=0.0||LonSet!=0.0) {
SetView(LatSet,LonSet,RangeSet,HeadingSet);
Plot->Refresh_GEView();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::BtnCloseClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::BtnOpt1Click(TObject *Sender)
{
UpdateOpts();
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::BtnHeadingClick(TObject *Sender)
{
if (!BtnHeading->Down) SetHeading(0.0);
UpdateEnable();
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::BtnFixCentClick(TObject *Sender)
{
Plot->Refresh_GEView();
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::BtnEnaAltClick(TObject *Sender)
{
UpdateOpts();
Plot->Refresh_GEView();
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::BtnGENormClick(TObject *Sender)
{
ExecFunc("SetTilt(0.0)");
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::BtnGETiltClick(TObject *Sender)
{
AnsiString f;
ExecFunc(f.sprintf("SetTilt(%.1f)",TILT_ANGLE));
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::BtnShrinkMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
Timer1->Enabled=false;
Timer2->Enabled=true;
Expand=1;
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::BtnShrinkMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
Expand=0;
Timer1->Enabled=true;
Timer2->Enabled=false;
ExecFunc("UpdateState()");
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::BtnExpandMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
Timer1->Enabled=false;
Timer2->Enabled=true;
Expand=-1;
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::BtnExpandMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
Expand=0;
Timer1->Enabled=true;
Timer2->Enabled=false;
ExecFunc("UpdateState()");
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::BtnRotLMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
Timer1->Enabled=false;
Timer2->Enabled=true;
Rotate=1;
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::BtnRotLMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
Rotate=0;
Timer1->Enabled=true;
Timer2->Enabled=false;
ExecFunc("UpdateState()");
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::BtnRotRMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
Timer1->Enabled=false;
Timer2->Enabled=true;
Rotate=-1;
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::BtnRotRMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
Rotate=0;
Timer1->Enabled=true;
Timer2->Enabled=false;
ExecFunc("UpdateState()");
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::Timer2Timer(TObject *Sender)
{
if (Expand) {
if (Expand>0) Range=MIN(MAX_RANGE,Range*1.05);
else Range=MAX(MIN_RANGE,Range/1.05);
SetRange(Range);
}
if (Rotate) {
if (Rotate>0) Heading+=3.0;
else Heading-=3.0;
if (Heading> 180.0) Heading-=360.0;
else if (Heading<-180.0) Heading+=360.0;
SetHeading(Heading);
}
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::Clear(void)
{
MarkVis[0]=MarkVis[1]=TrackVis[0]=TrackVis[1]=0;
MarkPos[0][0]=MarkPos[0][1]=0.0;
MarkPos[1][0]=MarkPos[1][1]=0.0;
ExecFunc("ClearTrack(1)");
ExecFunc("ClearTrack(2)");
ExecFunc("SetMark(1,0.0,0.0)");
ExecFunc("SetMark(2,0.0,0.0)");
}
// --------------------------------------------------------------------------
void __fastcall TGoogleEarthView::SetView(double lat, double lon, double range,
double heading)
{
AnsiString f;
if (range<=0.0) range=RangeSet<=0.0?INIT_RANGE:RangeSet;
LatSet=lat; LonSet=lon; RangeSet=range; HeadingSet=heading;
ExecFunc(f.sprintf("SetView(%.9f,%.9f,%.3f,%.1f)",lat,lon,range,heading));
}
// --------------------------------------------------------------------------
void __fastcall TGoogleEarthView::SetCent(double lat, double lon)
{
AnsiString f;
ExecFunc(f.sprintf("SetCent(%.9f,%.9f)",lat,lon));
}
// --------------------------------------------------------------------------
void __fastcall TGoogleEarthView::SetRange(double range)
{
AnsiString f;
ExecFunc(f.sprintf("SetRange(%.3f)",range));
}
/// --------------------------------------------------------------------------
void __fastcall TGoogleEarthView::SetHeading(double angle)
{
AnsiString f;
ExecFunc(f.sprintf("SetHeading(%.2f)",angle));
}
// --------------------------------------------------------------------------
void __fastcall TGoogleEarthView::SetMark(int index, const double *pos)
{
AnsiString f;
if (index<1||2<index) return;
MarkPos[index-1][0]=pos[0]*R2D;
MarkPos[index-1][1]=pos[1]*R2D;
ExecFunc(f.sprintf("SetMark(%d,%.9f,%.9f,%.3f)",index,pos[0]*R2D,
pos[1]*R2D,pos[2]));
if (BtnFixCent->Down) {
SetCent(pos[0]*R2D,pos[1]*R2D);
}
}
// --------------------------------------------------------------------------
void __fastcall TGoogleEarthView::ShowMark(int index)
{
AnsiString f;
if (index<1||2<index) return;
ExecFunc(f.sprintf("ShowMark(%d)",index));
MarkVis[index-1]=1;
UpdateEnable();
}
// --------------------------------------------------------------------------
void __fastcall TGoogleEarthView::HideMark(int index)
{
AnsiString f;
if (index<1||2<index) return;
ExecFunc(f.sprintf("HideMark(%d)",index));
MarkVis[index-1]=0;
UpdateEnable();
}
// --------------------------------------------------------------------------
void __fastcall TGoogleEarthView::ClearTrack(int index)
{
AnsiString f;
if (index<1||2<index) return;
ExecFunc(f.sprintf("ClearTrack(%d)",index));
TrackVis[index-1]=0;
UpdateEnable();
}
// --------------------------------------------------------------------------
int __fastcall TGoogleEarthView::UpdateTrack(int index, solbuf_t *sol)
{
AnsiString f;
sol_t *data;
double prev[3]={0},pos[3];
int i,j,intv;
if (index<1||2<index||!State||sol->n<=0) return 0;
Screen->Cursor=crHourGlass;
ClearTrack(index);
intv=sol->n/MAXTRACKS+1; // interval to reduce points
for (i=0;data=getsol(sol,i);i++) {
if (i%intv!=0) continue;
ecef2pos(data->rr,pos);
if (fabs(pos[0]-prev[0])<1E-8&&fabs(pos[1]-prev[1])<1E-8) continue;
prev[0]=pos[0];
prev[1]=pos[1];
ExecFunc(f.sprintf("AddTrack(%d,%.9f,%.9f)",index,pos[0]*R2D,
pos[1]*R2D));
}
Screen->Cursor=crDefault;
UpdateEnable();
return 1;
}
// --------------------------------------------------------------------------
void __fastcall TGoogleEarthView::ShowTrack(int index)
{
AnsiString f;
if (index<1||2<index) return;
ExecFunc(f.sprintf("ShowTrack(%d)",index));
TrackVis[index-1]=1;
UpdateEnable();
}
// --------------------------------------------------------------------------
void __fastcall TGoogleEarthView::HideTrack(int index)
{
AnsiString f;
if (index<1||2<index) return;
ExecFunc(f.sprintf("HideTrack(%d)",index));
TrackVis[index-1]=0;
UpdateEnable();
}
// ----------------------------------------------------------------------------
void __fastcall TGoogleEarthView::UpdatePoint(void)
{
AnsiString f;
double pos[3];
int i;
ExecFunc("ClearPoint()");
for (i=0;i<Plot->NWayPnt;i++) {
ecef2pos(Plot->PntPos[i],pos);
ExecFunc(f.sprintf("AddPoint('%s',%.9f,%.9f,%.2f)",Plot->PntName[i],
pos[0]*R2D,pos[1]*R2D,pos[2]));
}
}
// --------------------------------------------------------------------------
void __fastcall TGoogleEarthView::ShowPoint(void)
{
ExecFunc("ShowPoint()");
}
// --------------------------------------------------------------------------
void __fastcall TGoogleEarthView::HidePoint(void)
{
ExecFunc("HidePoint()");
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::SetOpts(const int *opts)
{
TSpeedButton *btn[]={
BtnOpt1,BtnOpt2,BtnOpt3,BtnOpt4,BtnOpt5,BtnOpt6,BtnOpt7,BtnOpt8,
BtnOpt9,BtnEnaAlt,BtnHeading
};
for (int i=0;i<11;i++) {
btn[i]->Down=opts[i];
}
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::GetOpts(int *opts)
{
TSpeedButton *btn[]={
BtnOpt1,BtnOpt2,BtnOpt3,BtnOpt4,BtnOpt5,BtnOpt6,BtnOpt7,BtnOpt8,
BtnOpt9,BtnEnaAlt,BtnHeading
};
for (int i=0;i<11;i++) {
opts[i]=btn[i]->Down;
}
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::UpdateOpts(void)
{
AnsiString f;
int opts[12];
GetOpts(opts);
ExecFunc(f.sprintf("SetOpts(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)",opts[0],
opts[1],opts[2],opts[3],opts[4],opts[5],opts[6],opts[7],opts[8],
opts[9]));
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::UpdateEnable(void)
{
BtnFixCent->Enabled=MarkVis[0]||MarkVis[1];
BtnEnaAlt ->Enabled=MarkVis[0]||MarkVis[1];
BtnRotR ->Enabled=!BtnHeading->Down;
BtnRotL ->Enabled=!BtnHeading->Down;
}
//---------------------------------------------------------------------------
void __fastcall TGoogleEarthView::ExecFunc(AnsiString func)
{
IHTMLWindow2 *win;
IHTMLDocument2 *doc=NULL;
VARIANT var;
HRESULT hr;
wchar_t func_w[256]={0};
if (State!=1||!WebBrowser->Document) return;
WebBrowser->Document->QueryInterface(IID_IHTMLDocument2,(void **)&doc);
if (!doc) return;
hr=doc->get_parentWindow(&win);
doc->Release();
if (hr!=S_OK) return;
VariantInit(&var);
::MultiByteToWideChar(CP_UTF8,0,func.c_str(),-1,func_w,512);
hr=win->execScript(func_w,L"javascript",&var);
VariantClear(&var);
}
//---------------------------------------------------------------------------