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.cpp
2018-10-25 12:15:13 +02:00

101 lines
3.0 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © Copyright 2014 Urheberrechtshinweis
* Alle Rechte vorbehalten / All Rights Reserved
*
* Programmcode ist urheberrechtlich geschuetzt.
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
* Keine Verwendung ohne explizite Genehmigung.
* (vgl. § 106 ff UrhG / § 97 UrhG)
*/
#include "MV2DElementElevator.h"
#include "MV2DElement.h"
#include "HasMoveableNodes.h"
#include "MapViewElementHelper.h"
#include <Indoor/floorplan/v2/Floorplan.h>
#include "../../UIHelper.h"
/** 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;
}
MV2DElementElevator::MV2DElementElevator(Floorplan::IndoorMap* map, Floorplan::Floor* floor, Floorplan::Elevator* elevator) : map(map), floor(floor), elevator(elevator) {
;
}
BBox2 MV2DElementElevator::getBoundingBox() const {
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;
}
ClickDist MV2DElementElevator::getMinDistanceXY(const Point2 p) const {
// 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);
}
void MV2DElementElevator::paint(Painter& p) {
// 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]);
}
std::vector<MoveableNode> MV2DElementElevator::getMoveableNodes() const {
return { MoveableNode(0, elevator->center) };
}
void MV2DElementElevator::onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) {
(void) v;
if (userIdx == 0) {elevator->center.x = newPos.x; elevator->center.y = newPos.y;}
}
void MV2DElementElevator::onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
void MV2DElementElevator::onFocus() {
;
}
void MV2DElementElevator::onUnfocus() {
;
}