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/elements/MV2DElementFloorObstacleDoor.h
2016-07-04 15:11:10 +02:00

147 lines
3.7 KiB
C++

#ifndef MV2DELEMENTFLOOROBSTACLEDOOR_H
#define MV2DELEMENTFLOOROBSTACLEDOOR_H
#include "MV2DElement.h"
#include "MapViewElementHelper.h"
#include "HasMoveableNodes.h"
#include <Indoor/floorplan/v2/Floorplan.h>
class MV2DElementFloorObstacleDoor : public MV2DElement, public HasMoveableNodes {
private:
//int selPoint = -1;
Floorplan::FloorObstacleDoor* fo;
public:
/** ctor */
MV2DElementFloorObstacleDoor(Floorplan::FloorObstacleDoor* fo) : fo(fo) {;}
/** get the element's 3D bounding box */
BBox2 getBoundingBox() const override {
BBox2 bbox;
bbox.add(fo->from);
bbox.add(fo->to);
return bbox;
}
/** get the element's minimal distance (nearest whatsoever) to the given point */
float getMinDistanceXY(const Point2 p) const override {
return MapElementHelper::getLineDistanceXY(fo->from, fo->to, p);
}
/** repaint me */
void paint(Painter& p) override {
// selected endpoints?
if (hasFocus()) {
p.setPenBrush(Qt::NoPen, CFG::SEL_COLOR);
if (selectedUserIdx == 0) {p.drawCircle(fo->from);}
if (selectedUserIdx == 1) {p.drawCircle(fo->to);}
}
QPen pen;
pen.setColor(QColor(0.5,0.5,0.5));
pen.setStyle(Qt::PenStyle::DotLine);
p.setPenBrush(pen, Qt::NoBrush);
// opening indicator
const float open = (fo->swap) ? (-M_PI * 0.5) : (+M_PI * 0.5);
const float len = (fo->to - fo->from).length();
const float angle1 = std::atan2(fo->to.y-fo->from.y, fo->to.x-fo->from.x);
const float angle2 = angle1 + open;
const Point2 pOpen = Point2( std::cos(angle2) * len, std::sin(angle2) * len ) + fo->from;
pen.setWidth(2); p.setPen(pen);
p.drawLine(fo->from, fo->to);
pen.setWidth(1); p.setPen(pen);
p.drawLine(fo->from, pOpen);
p.drawArc(fo->from, len, angle1, open);
// available endpoints
if (hasFocus()) {
p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawCircle(fo->from);
p.drawCircle(fo->to);
}
}
virtual void onFocus() override {
;
}
virtual void onUnfocus() override {
selectedUserIdx = -1; // clear selection
}
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;
}
/** mouse moved to the given point */
// virtual void mouseMove(MapView2D* v, const Point2 _p) override {
// (void) v;
// if (selPoint == -1) {return;}
// const Point2 p = v->getScaler().snap(_p);
// if (selPoint == 0) {fo->from.x = p.x; fo->from.y = p.y;}
// if (selPoint == 1) {fo->to.x = p.x; fo->to.y = p.y;}
// emit v->onElementChange(this);
// }
/** mouse released */
// virtual void mouseReleased(MapView2D* v, const Point2 _p) override {
// // select a new point on mouse-release (more robust than on mouse-press)
// const float t = v->getScaler().sm(CFG::SEL_THRESHOLD_SIZE_PX);
// const float l1 = _p.getDistance(fo->from);
// const float l2 = _p.getDistance(fo->to);
// if (l1 < l2 && l1 <= t) {selPoint = 0;}
// else if (l2 < l1 && l2 <= t) {selPoint = 1;}
// else {selPoint = -1;}
// }
/** get a list of all nodes that are selectable / moveable */
virtual std::vector<MoveableNode> getMoveableNodes() const override {
std::vector<MoveableNode> nodes = {
MoveableNode(0, fo->from),
MoveableNode(1, fo->to)
};
return nodes;
}
/** the given node was moved */
virtual void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override {
switch (userIdx) {
case 0: fo->from = newPos; break;
case 1: fo->to = newPos; break;
}
emit v->onElementChange(this);
}
virtual bool keyPressEvent(MapView2D* v, QKeyEvent *e) override {
(void) v;
(void) e;
return false;
}
};
#endif // MV2DELEMENTFLOOROBSTACLEDOOR_H