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/MV2DElementFloorObstacleLine.h
2018-04-04 17:14:37 +02:00

142 lines
3.3 KiB
C++

#ifndef MV2DELEMENTFLOOROBSTACLELINE_H
#define MV2DELEMENTFLOOROBSTACLELINE_H
#include "MV2DElement.h"
#include "HasMoveableNodes.h"
#include "MapViewElementHelper.h"
#include <Indoor/floorplan/v2/Floorplan.h>
#include <stdio.h>
class MV2DElementFloorObstacleLine : public MV2DElement, public HasMoveableNodes {
private:
Floorplan::FloorObstacleLine* fo;
public:
/** ctor */
MV2DElementFloorObstacleLine(Floorplan::FloorObstacleLine* 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 */
ClickDist 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);}
}
// convert wall's thickness from meter to pixels
const float thickness_px = p.s.ms(fo->thickness_m);
// remember the old pen
QPen pen = p.getPen();
// see notes within MapElementHelper!
// lines only get thicker, but not longer!
p.setPenBrush(MapElementHelper::getPen(fo->material, fo->type, hasFocus(), thickness_px), Qt::NoBrush);
p.drawLine(fo->from, fo->to);
// reset the old pen
p.setPen(pen);
// available endpoints
if (hasFocus()) {
p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawCircle(fo->from);
p.drawCircle(fo->to);
// obstacle length
p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawLength(fo->from, fo->to, fo->from.getDistance(fo->to), thickness_px/2);
} else {
//p.setPenBrush(Qt::NoPen, Qt::black);
p.drawCircle_px(fo->from, 3);
p.drawCircle_px(fo->to, 3);
}
}
// void paintDoor(Painter& p) {
// 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 = M_PI / 4;
// 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;
// p.drawLine(fo->from, fo->to);
// p.drawLine(fo->from, pOpen);
// p.drawArc(fo->from, len, angle1, open);
// //p.drawLine(fo->to, pOpen);
// // obstacle length
// p.setPenBrush(Qt::black, Qt::NoBrush);
// p.drawLength(fo->from, fo->to, fo->from.getDistance(fo->to));
// }
void onFocus() override {
;
}
void onUnfocus() override {
selectedUserIdx = -1; // clear selection
}
virtual std::vector<MoveableNode> getMoveableNodes() const override {
return {
MoveableNode(0, fo->from),
MoveableNode(1, fo->to)
};
}
void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override {
(void) v;
if (userIdx == 0) {fo->from.x = newPos.x; fo->from.y = newPos.y;}
if (userIdx == 1) {fo->to.x = newPos.x; fo->to.y = newPos.y;}
}
void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
};
#endif // MV2DELEMENTFLOOROBSTACLELINE_H