Added support for ENC atlases (catalogues)
[GPXSee.git] / src / map / ENC / atlasdata.cpp
blob712df3b9adee16044275d7585d8ded5838db1354
1 #include "atlasdata.h"
3 using namespace ENC;
5 bool AtlasData::pointCb(const QString *map, void *context)
7 PointCTX *ctx = (PointCTX*)context;
9 ctx->lock.lock();
11 MapData *cached = ctx->cache.object(map);
13 if (!cached) {
14 MapData *data = new MapData(*map);
15 data->points(ctx->rect, ctx->points);
16 if (!ctx->cache.insert(map, data))
17 delete data;
18 } else
19 cached->points(ctx->rect, ctx->points);
21 ctx->lock.unlock();
23 return true;
26 bool AtlasData::polyCb(const QString *map, void *context)
28 PolyCTX *ctx = (PolyCTX*)context;
30 ctx->lock.lock();
32 MapData *cached = ctx->cache.object(map);
34 if (!cached) {
35 MapData *data = new MapData(*map);
36 data->polygons(ctx->rect, ctx->polygons);
37 data->lines(ctx->rect, ctx->lines);
38 if (!ctx->cache.insert(map, data))
39 delete data;
40 } else {
41 cached->polygons(ctx->rect, ctx->polygons);
42 cached->lines(ctx->rect, ctx->lines);
45 ctx->lock.unlock();
47 return true;
50 AtlasData::~AtlasData()
52 MapTree::Iterator it;
53 for (_tree.GetFirst(it); !_tree.IsNull(it); _tree.GetNext(it))
54 delete _tree.GetAt(it);
57 void AtlasData::addMap(const RectC &bounds, const QString &path)
59 double min[2], max[2];
61 min[0] = bounds.left();
62 min[1] = bounds.bottom();
63 max[0] = bounds.right();
64 max[1] = bounds.top();
66 _tree.Insert(min, max, new QString(path));
69 void AtlasData::polys(const RectC &rect, QList<MapData::Poly> *polygons,
70 QList<MapData::Line> *lines)
72 double min[2], max[2];
73 PolyCTX polyCtx(rect, polygons, lines, _cache, _lock);
75 min[0] = rect.left();
76 min[1] = rect.bottom();
77 max[0] = rect.right();
78 max[1] = rect.top();
80 _tree.Search(min, max, polyCb, &polyCtx);
83 void AtlasData::points(const RectC &rect, QList<MapData::Point> *points)
85 double min[2], max[2];
86 PointCTX pointCtx(rect, points, _cache, _lock);
88 min[0] = rect.left();
89 min[1] = rect.bottom();
90 max[0] = rect.right();
91 max[1] = rect.top();
93 _tree.Search(min, max, pointCb, &pointCtx);