added elevator support

This commit is contained in:
2016-09-10 15:13:49 +02:00
parent fa06320219
commit 674f79c150
13 changed files with 353 additions and 14 deletions

View File

@@ -0,0 +1,111 @@
#ifndef MV2DELEMENTELEVATOR_H
#define MV2DELEMENTELEVATOR_H
#include "MV2DElement.h"
#include "HasMoveableNodes.h"
#include "MapViewElementHelper.h"
#include <Indoor/floorplan/v2/Floorplan.h>
#include "../../UIHelper.h"
class MV2DElementElevator : public MV2DElement, public HasMoveableNodes {
private:
Floorplan::Elevator* elevator;
public:
/** ctor with the AP to render/edit */
MV2DElementElevator(Floorplan::Elevator* elevator) : elevator(elevator) {;}
BBox2 getBoundingBox() const override {
BBox2 bbox;
const float max = std::max(elevator->width, elevator->depth);
bbox.add(Point2(elevator->center.x, elevator->center.y));
bbox.grow(Point2(max/2, max/2));
return bbox;
}
/** get the element's minimal distance (nearest whatsoever) to the given point */
float getMinDistanceXY(const Point2 p) const override {
// std::vector<Point2> points = elevator->getPoints().points;
// points.push_back(elevator->center);
// auto it minEl = std::min_element(points.begin(), points.end(),
return p.getDistance(elevator->center);
}
/** repaint me */
void paint(Painter& p) override {
// area
const Floorplan::Polygon2 poly = elevator->getPoints();
p.setPenBrush(Qt::gray, Qt::lightGray);
p.drawPolygon(poly.points);
// outline
QPen pen; pen.setWidth(2); pen.setColor(QColor(0,0,0));
p.setPenBrush(pen, Qt::NoBrush);
//p.drawLine(poly.points[0], poly.points[1]);
p.drawLine(poly.points[1], poly.points[2]);
p.drawLine(poly.points[2], poly.points[3]);
p.drawLine(poly.points[3], poly.points[0]);
if (selectedUserIdx == 0) {
p.setPenBrush(Qt::black, CFG::SEL_COLOR);
p.drawCircle(elevator->center);
} else if (hasFocus()) {
p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawCircle(elevator->center);
} else {
//p.setPenBrush(Qt::gray, Qt::NoBrush);
//p.drawCircle(elevator->center);
}
}
virtual std::vector<MoveableNode> getMoveableNodes() const override {
return { MoveableNode(0, elevator->center) };
}
virtual void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override {
(void) v;
if (userIdx == 0) {elevator->center.x = newPos.x; elevator->center.y = newPos.y;}
}
virtual void mousePressed(MapView2D* v, const Point2 p) override {
(void) v;
(void) p;
}
virtual void mouseMove(MapView2D* v, const Point2 p) override {
(void) v;
(void) p;
}
virtual void mouseReleased(MapView2D* v, const Point2 p) override {
(void) v;
(void) p;
}
virtual bool keyPressEvent(MapView2D* v, QKeyEvent *e) override {
(void) v;
(void) e;
return false;
}
virtual void onFocus() override {
;
}
virtual void onUnfocus() override {
;
}
};
#endif // MV2DELEMENTELEVATOR_H

View File

@@ -15,6 +15,8 @@ class MV2DElementFloorUnderlay : public MV2DElement {
private:
QImage img;
QImage imgScaled;
std::string tmpFile;
Floorplan::UnderlayImage* underlay;
BBox2 bbox;
@@ -58,9 +60,8 @@ public:
if (tmpFile != underlay->filename) {
img = QImage(underlay->filename.c_str());
if (img.size().width() == 0) {
missing();
}
if (img.size().width() == 0) { missing(); }
img = img.convertToFormat(QImage::Format_Grayscale8); // saves a huge amount of memory and should suffice
tmpFile = underlay->filename;
}
@@ -79,17 +80,39 @@ public:
float sy1 = p.s.yms(my1);
float sx2 = p.s.xms(mx2);
float sy2 = p.s.yms(my2);
float sw = std::abs(sx1-sx2);
float sh = std::abs(sy1-sy2);
float sw = std::round(std::abs(sx1-sx2));
float sh = std::round(std::abs(sy1-sy2));
const float origArea = img.width() * img.height();
const float scaledArea = sw*sh;
bbox = BBox2();
bbox.add(Point2(mx1, my1));
bbox.add(Point2(mx2, my2));
// if the to-be-displayed image is smaller than the input-one, use a pre-computed downscaled version
if (scaledArea < origArea) {
// does the cached downscaled image needs rebuild? (size changed)
if (imgScaled.width() != sw || imgScaled.height() != sh) {
imgScaled = img.scaled(sw, sh, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
} else {
imgScaled = QImage();
}
float opacity = p.p->opacity();
p.p->setOpacity(0.50f);
p.p->drawImage(QRectF(sx1, sy1-sh, sw, sh), img, QRectF(0,0,img.width(),img.height()));
// render downscaled image from cache? or use live-upscaling (faster, eats up less memory, ...)
if (imgScaled.width() > 0) {
p.p->drawImage(sx1, sy1-sh, imgScaled);
} else {
p.p->setRenderHint(QPainter::SmoothPixmapTransform, true);
p.p->drawImage(QRectF(sx1, sy1-sh, sw, sh), img, QRectF(0,0,img.width(),img.height()));
}
p.p->setOpacity(opacity);
// selected endpoint(s)?