7 #include "color_handler.h"
9 #include "model/own_ship.h"
10 #include "model/routeman.h"
11 #include "track_gui.h"
12 #include "glChartCanvas.h"
15 extern wxColour g_colourTrackLineColour;
17 extern wxColor GetDimColor(wxColor c);
18 extern bool g_bHighliteTracks;
26 cc->GetCanvasPointPix(m_point.m_lat, m_point.m_lon, &r);
29 pen = g_pRouteMan->GetRoutePointPen();
34 wxRect r1(r.x - sx2, r.y - sy2, sx2 * 2, sy2 * 2);
43 wxColour hi_colour = pen->GetColour();
44 unsigned char transparency = 100;
47 AlphaBlending(dc, r.x + hilitebox.x, r.y + hilitebox.y, hilitebox.width,
48 hilitebox.height, radius, hi_colour, transparency);
51 void TrackGui::Finalize() {
52 if (m_track.SubTracks.size())
57 int n = m_track.TrackPoints.size() - 1;
60 std::vector<SubTrack> new_level;
63 for (
int i = 0; i < n; i++) {
64 new_level[i].m_box.SetFromSegment(
65 m_track.TrackPoints[i]->m_lat, m_track.TrackPoints[i]->m_lon,
66 m_track.TrackPoints[i + 1]->m_lat,
67 m_track.TrackPoints[i + 1]->m_lon);
68 new_level[i].m_scale = 0;
71 for (
int i = 0; i < n; i++) {
73 new_level[i].m_box = m_track.SubTracks[level - 1][p].m_box;
74 if (p + 1 < (
int)m_track.SubTracks[level - 1].size())
75 new_level[i].m_box.Expand(m_track.SubTracks[level - 1][p + 1].m_box);
77 int left = i << level;
78 int right = wxMin(left + (1 << level), m_track.TrackPoints.size() - 1);
79 new_level[i].m_scale = m_track.ComputeScale(left, right);
82 m_track.SubTracks.push_back(new_level);
84 if (n > 1 && n & 1) n++;
94 std::list<std::list<wxPoint> > &pointlists,
97 if (!m_track.IsVisible() || m_track.GetnPoints() == 0)
return;
100 Segments(cc, pointlists, box, VP.view_scale_ppm);
102 if(GetnPoints() > 40000) {
103 double t = sw.GetTime();
105 for(std::list< std::list<wxPoint> >::iterator lines = pointlists.begin();
106 lines != pointlists.end(); lines++) {
107 if(lines->size() > 1)
111 printf(
"assemble time %f %f segments %f seg/ms\n", sw.GetTime(), c, c/t);
117 if (m_track.IsRunning()) {
118 std::list<wxPoint> new_list;
119 pointlists.push_back(new_list);
120 AddPointToList(cc, pointlists, m_track.TrackPoints.size() - 1);
122 cc->GetCanvasPointPix(gLat, gLon, &r);
123 pointlists.back().push_back(r);
129 std::list<std::list<wxPoint> > pointlists;
130 GetPointLists(cc, pointlists, VP, box);
132 if (!pointlists.size())
return;
135 wxColour basic_colour;
136 if (m_track.IsRunning())
137 basic_colour = GetGlobalColor(_T (
"URED" ));
139 basic_colour = GetDimColor(g_colourTrackLineColour);
141 wxPenStyle style = wxPENSTYLE_SOLID;
142 int width = g_pRouteMan->GetTrackPen()->GetWidth();
144 if (m_track.m_style != wxPENSTYLE_INVALID) style = m_track.m_style;
145 if (m_track.m_width != WIDTH_UNDEFINED) width = m_track.m_width;
146 if (m_track.m_Colour == wxEmptyString) {
149 if(m_track.GetName().StartsWith(
"AIS"))
150 col = GetGlobalColor(_T (
"TEAL1" ));
152 for (
unsigned int i = 0; i <
sizeof(::GpxxColorNames) /
sizeof(wxString);
154 if (m_track.m_Colour == ::GpxxColorNames[i]) {
155 col = ::GpxxColors[i];
164 if (g_bHighliteTracks) {
165 double radius_meters = 20;
166 double scale = VP.view_scale_ppm;
167 radius = wxMax((radius_meters * wxMin(
scale, 1.1)), 6.0);
168 if (
scale < 0.004) radius = 0;
172 wxPen p = *wxThePenList->FindOrCreatePen(col, width, style);
174 if(glChartCanvas::dash_map.find(style) != glChartCanvas::dash_map.end()) {
175 p.SetDashes(2, &glChartCanvas::dash_map[style][0]);
179 dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(col, wxBRUSHSTYLE_SOLID));
180 for (std::list<std::list<wxPoint> >::iterator lines = pointlists.begin();
181 lines != pointlists.end(); lines++) {
183 wxPoint *points =
new wxPoint[lines->size()];
185 for (std::list<wxPoint>::iterator line = lines->begin();
186 line != lines->end(); line++) {
191 int hilite_width = radius;
192 if (hilite_width >= 1.0) {
194 wxPen psave = dc.GetPen();
196 wxColor trackLine_dim_colour = GetDimColor(g_colourTrackLineColour);
197 wxColour hilt(trackLine_dim_colour.Red(), trackLine_dim_colour.Green(),
198 trackLine_dim_colour.Blue(), 128);
199 wxPen HiPen(hilt, hilite_width, wxPENSTYLE_SOLID);
202 dc.StrokeLines(i, points);
206 dc.StrokeLines(i, points);
208 dc.StrokeLines(i, points);
214 if (m_track.m_HighlightedTrackPoint >= 0)
215 TrackPointGui(m_track.TrackPoints[m_track.m_HighlightedTrackPoint]).Draw(cc, dc);
220 std::list<std::list<wxPoint> > &pointlists,
221 const LLBBox &box,
double scale) {
222 if (!m_track.SubTracks.size())
return;
224 int level = m_track.SubTracks.size() - 1, last = -2;
225 Assemble(cc, pointlists, box, 1 /
scale /
scale, last, level, 0);
231 std::list<std::list<wxPoint> > &pointlists,
232 const LLBBox &box,
double scale,
int &last,
int level,
234 if (pos == (
int)m_track.SubTracks[level].size())
return;
236 SubTrack &s = m_track.SubTracks[level][pos];
237 if (box.IntersectOut(s.m_box))
return;
239 if (s.m_scale <
scale) {
242 if (last < pos - 1) {
243 std::list<wxPoint> new_list;
244 pointlists.push_back(new_list);
247 if (last < pos) AddPointToList(cc, pointlists, pos);
248 last = wxMin(pos + (1 << level), m_track.TrackPoints.size() - 1);
249 AddPointToList(cc, pointlists, last);
251 Assemble(cc, pointlists, box,
scale, last, level - 1, pos << 1);
252 Assemble(cc, pointlists, box,
scale, last, level - 1, (pos << 1) + 1);
257 std::list<std::list<wxPoint> > &pointlists,
int n) {
258 wxPoint r(INVALID_COORD, INVALID_COORD);
259 if ((
size_t)n < m_track.TrackPoints.size())
260 cc->GetCanvasPointPix(m_track.TrackPoints[n]->m_lat, m_track.TrackPoints[n]->m_lon, &r);
262 std::list<wxPoint> &pointlist = pointlists.back();
263 if (r.x == INVALID_COORD) {
264 if (pointlist.size()) {
265 std::list<wxPoint> new_list;
266 pointlists.push_back(new_list);
271 if (pointlist.size() == 0)
272 pointlist.push_back(r);
274 wxPoint l = pointlist.back();
276 if ((abs(r.x - l.x) > 1) || (abs(r.y - l.y) > 1)) pointlist.push_back(r);