This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
IndoorMap/mapview/2D/MV2DElementElevator.h
2017-11-08 18:11:28 +01:00

131 lines
3.6 KiB
C++

#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::IndoorMap* map;
Floorplan::Floor* floor;
Floorplan::Elevator* elevator;
public:
/** ctor with the AP to render/edit */
MV2DElementElevator(Floorplan::IndoorMap* map, Floorplan::Floor* floor, Floorplan::Elevator* elevator) : map(map), floor(floor), 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 */
ClickDist 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 ClickDist(p.getDistance(elevator->center), ClickDistType::DIRECT);
}
/** 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));
if (!elevatorEndConnected(map, floor, elevator)) {pen.setColor(QColor(255,0,0));}
if (elevator->height_m == 0) {pen.setColor(QColor(255,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);
p.drawCircle_px(elevator->center, 3);
}
}
/** is the given elevator's end connected to ANY of the floorplan's floors? */
static inline bool elevatorEndConnected(const Floorplan::IndoorMap* map, const Floorplan::Floor* floor, const Floorplan::Elevator* e) {
const int elevatorEnd_cm = std::round( (floor->atHeight + e->height_m) * 100 );
std::vector<int> floorsAtHeight_cm;
for (const Floorplan::Floor* f : map->floors) {
const int height_cm = std::round(f->atHeight*100);
floorsAtHeight_cm.push_back(height_cm);
}
const bool connected = std::find(floorsAtHeight_cm.begin(), floorsAtHeight_cm.end(), elevatorEnd_cm) != floorsAtHeight_cm.end();
return connected;
}
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