added new tools for creating APs, Beacons, GTP, POI, Fingerprints fixed selection issue changed new-element creation added missing layer parameters
155 lines
4.0 KiB
C++
155 lines
4.0 KiB
C++
#ifndef PAINTER_H
|
|
#define PAINTER_H
|
|
|
|
#include <QPainter>
|
|
#include <QBitmap>
|
|
|
|
#include <Indoor/geo/Point2.h>
|
|
#include <Indoor/geo/Point3.h>
|
|
|
|
#include "Scaler.h"
|
|
|
|
class Painter {
|
|
|
|
public:
|
|
|
|
Scaler& s;
|
|
QPainter* p;
|
|
int w;
|
|
int h;
|
|
|
|
public:
|
|
|
|
/** ctor */
|
|
Painter(Scaler& s, QPainter* p, int w, int h) : s(s), p(p), w(w), h(h) {
|
|
p->setPen(Qt::black);
|
|
p->setBrush(Qt::NoBrush);
|
|
}
|
|
|
|
int width() {return w;}
|
|
|
|
int height() {return h;}
|
|
|
|
void drawLine(const Point2 p1, const Point2 p2) {
|
|
p->drawLine(s.xms(p1.x), s.yms(p1.y), s.xms(p2.x), s.yms(p2.y));
|
|
}
|
|
void drawLine(const Point3 p1, const Point3 p2) {
|
|
p->drawLine(s.xms(p1.x), s.yms(p1.y), s.xms(p2.x), s.yms(p2.y));
|
|
}
|
|
|
|
float radToDeg(const float rad) const {
|
|
return rad * 180 / M_PI;
|
|
}
|
|
|
|
void drawArc(const Point2 center, const float radius, const float startAngleRad, const float spanAngleRad) {
|
|
const float wh = s.ms(radius) * 2;
|
|
const float x1 = s.xms(center.x) - wh/2;
|
|
const float y1 = s.yms(center.y) - wh/2;
|
|
p->drawArc(x1, y1, wh, wh, radToDeg(startAngleRad)*16, radToDeg(spanAngleRad)*16);
|
|
}
|
|
|
|
void drawCircle(const Point3 center) {
|
|
int r = 5;
|
|
p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r);
|
|
}
|
|
|
|
void drawCircle(const Point2 center) {
|
|
int r = 5;
|
|
p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r);
|
|
}
|
|
|
|
/** draw a dot at the given map coordinates */
|
|
void drawDot(const Point2 center) {
|
|
int r = 1;
|
|
p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r);
|
|
}
|
|
|
|
void drawCircle(const Point2 center, const float size_m) {
|
|
int r = s.ms(size_m);
|
|
p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r);
|
|
}
|
|
|
|
void drawCircle_px(const Point2 center, const float size_px) {
|
|
int r = size_px;
|
|
p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r);
|
|
}
|
|
|
|
void drawLine(const float x1, const float y1, const float x2, const float y2) {
|
|
p->drawLine(s.xms(x1), s.yms(y1), s.xms(x2), s.yms(y2));
|
|
}
|
|
|
|
void drawRect(const Point2 p1, const Point2 p2) {
|
|
drawRect(p1.x, p1.y, p2.x, p2.y);
|
|
}
|
|
|
|
void drawRect(const float x1, const float y1, const float x2, const float y2) {
|
|
float w = x2-x1;
|
|
float h = y1-y2;
|
|
p->drawRect(s.xms(x1), s.yms(y1), s.ms(w), s.ms(h));
|
|
}
|
|
|
|
void drawRect(const Point2 center) {
|
|
float r = s.sm(5); // 5 pixel
|
|
drawRect(center-Point2(r,r), center+Point2(r,r));
|
|
}
|
|
|
|
void drawText(const Point2 pos, const std::string& text) {
|
|
p->drawText(s.xms(pos.x), s.yms(pos.y), text.c_str());
|
|
}
|
|
|
|
void drawPolygon(const std::vector<Point2>& points) {
|
|
std::vector<QPointF> vec;
|
|
for (const Point2 p : points) {
|
|
vec.push_back(QPointF(s.xms(p.x), s.yms(p.y)));
|
|
}
|
|
p->drawPolygon(vec.data(), vec.size());
|
|
}
|
|
void drawPolygon(const std::vector<Point3>& points) {
|
|
std::vector<QPointF> vec;
|
|
for (const Point3 p : points) {
|
|
vec.push_back(QPointF(s.xms(p.x), s.yms(p.y)));
|
|
}
|
|
p->drawPolygon(vec.data(), vec.size());
|
|
}
|
|
|
|
void drawPixmap(const Point2 pt, const QPixmap& img) {
|
|
p->drawPixmap(s.xms(pt.x)-img.width()/2, s.yms(pt.y)-img.height()/2, img);
|
|
}
|
|
|
|
void drawImage(const Point2 pt, const QImage& img) {
|
|
p->drawImage(s.xms(pt.x)-img.width()/2, s.yms(pt.y)-img.height()/2, img);
|
|
}
|
|
|
|
void drawLength(Point2 p1, Point2 p2, const float len, const float offset = 0) {
|
|
if (p1.x < p2.x) {swap(p1, p2);}
|
|
const Point2 center_m = (p1 + p2) / 2;
|
|
Point2 dir_px = (p2 - p1).perpendicular().normalized() * (5+offset);
|
|
if (dir_px.x <= 0) {dir_px = -dir_px;}
|
|
const Point2 pos_m = center_m + dir_px / getScaler().getScale();
|
|
char buf[64]; sprintf(buf, "%.1f", len);
|
|
drawText(pos_m, buf);
|
|
}
|
|
|
|
void setBrush(const QBrush& brush) { p->setBrush(brush); }
|
|
void setBrush(const Qt::BrushStyle& brush) { p->setBrush(brush); }
|
|
|
|
void setPen(const QPen& pen) {p->setPen(pen); }
|
|
void setPen(const QColor& pen) {p->setPen(pen); }
|
|
void setPen(const Qt::PenStyle& pen) {p->setPen(pen); }
|
|
|
|
|
|
const QPen& getPen() {return p->pen();}
|
|
|
|
|
|
template <typename Pen, typename Brush> void setPenBrush(const Pen& pen, const Brush& brush) {setPen(pen); setBrush(brush);}
|
|
|
|
const Scaler& getScaler() {return s;}
|
|
|
|
private:
|
|
|
|
|
|
|
|
};
|
|
|
|
#endif // PAINTER_H
|