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
kazu 535e410ae9 added new param-editing to APs and Beacons
changed drawing for better debuging
changed layer editing
option to add and delete layers
some minor changes
2016-11-29 21:31:20 +01:00

118 lines
2.8 KiB
C++

#ifndef MV2DELEMENTFLOOROBSTACLELINE_H
#define MV2DELEMENTFLOOROBSTACLELINE_H
#include "MV2DElement.h"
#include "HasMoveableNodes.h"
#include "MapViewElementHelper.h"
#include <Indoor/floorplan/v2/Floorplan.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 */
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);}
}
p.setPenBrush(MapElementHelper::getPen(fo->material, fo->type, hasFocus()), Qt::NoBrush);
p.drawLine(fo->from, fo->to);
// // door?
// if (fo->type == Floorplan::ObstacleType::DOOR) {
// paintDoor(p);
// } else {
// p.setPenBrush(MapElementHelper::getPen(fo->material, fo->type, hasFocus()), Qt::NoBrush);
// p.drawLine(fo->from, fo->to);
// }
// available endpoints
if (hasFocus()) {
p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawCircle(fo->from);
p.drawCircle(fo->to);
} else {
//p.setPenBrush(Qt::NoPen, Qt::black);
p.drawCircle(fo->from, 0.1);
p.drawCircle(fo->to, 0.1);
}
}
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);
}
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;}
}
};
#endif // MV2DELEMENTFLOOROBSTACLELINE_H