109 lines
2.7 KiB
C++
109 lines
2.7 KiB
C++
#ifndef MV2DELEMENTFLOOROBSTACLELINE_H
|
|
#define MV2DELEMENTFLOOROBSTACLELINE_H
|
|
|
|
#include "MV2DElement.h"
|
|
#include "MapViewElementHelper.h"
|
|
#include <Indoor/floorplan/v2/Floorplan.h>
|
|
|
|
class MV2DElementFloorObstacleLine : public MV2DElement {
|
|
|
|
private:
|
|
|
|
int selPoint = -1;
|
|
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 (selPoint == 0) {p.drawCircle(fo->from);}
|
|
if (selPoint == 1) {p.drawCircle(fo->to);}
|
|
}
|
|
|
|
// line
|
|
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);
|
|
}
|
|
|
|
}
|
|
|
|
virtual void onFocus() override {
|
|
;
|
|
}
|
|
|
|
virtual void onUnfocus() override {
|
|
selPoint = -1; // clear selection
|
|
}
|
|
|
|
/** mouse pressed at the given point */
|
|
virtual void mousePressed(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 = Scaler::snap(_p, CFG::MOVE_SNAP_SIZE_M);
|
|
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;}
|
|
}
|
|
|
|
/** mouse released */
|
|
virtual void mouseReleased(MapView2D* v, const Point2 _p) override {
|
|
// (void) v;
|
|
// if (selPoint == -1) {return;}
|
|
// const Point3 p = Scaler::snap(_p, CFG::MOVE_SNAP_SIZE_M);
|
|
// 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;}
|
|
|
|
// 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;}
|
|
|
|
}
|
|
|
|
virtual bool keyPressEvent(MapView2D* v, QKeyEvent *e) override {
|
|
(void) v;
|
|
(void) e;
|
|
return false;
|
|
}
|
|
|
|
};
|
|
|
|
#endif // MV2DELEMENTFLOOROBSTACLELINE_H
|