109 lines
2.6 KiB
C++
109 lines
2.6 KiB
C++
#ifndef MV2DELEMENTFLOOROBSTACLECIRCLE_H
|
|
#define MV2DELEMENTFLOOROBSTACLECIRCLE_H
|
|
|
|
|
|
#include "MV2DElement.h"
|
|
#include "MapViewElementHelper.h"
|
|
#include <Indoor/floorplan/v2/Floorplan.h>
|
|
|
|
class MV2DElementFloorObstacleCircle : public MV2DElement {
|
|
|
|
private:
|
|
|
|
int selPoint = -1;
|
|
Floorplan::FloorObstacleCircle* c;
|
|
|
|
public:
|
|
|
|
/** ctor */
|
|
MV2DElementFloorObstacleCircle(Floorplan::FloorObstacleCircle* c) : c(c) {;}
|
|
|
|
/** get the element's 3D bounding box */
|
|
BBox2 getBoundingBox() const override {
|
|
BBox2 bbox;
|
|
bbox.add(c->center);
|
|
bbox.grow(Point2(c->radius, c->radius));
|
|
return bbox;
|
|
}
|
|
|
|
/** get the element's minimal distance (nearest whatsoever) to the given point */
|
|
float getMinDistanceXY(const Point2 p) const override {
|
|
return std::min(p.getDistance(getSelPoints()[0]), p.getDistance(getSelPoints()[1]));
|
|
}
|
|
|
|
|
|
/** repaint me */
|
|
void paint(Painter& p) override {
|
|
|
|
QPen pen;// = MapElementHelper::getPen(c->material, c->type, hasFocus());
|
|
|
|
p.setPenBrush(pen, Qt::NoBrush);
|
|
p.drawCircle(c->center, c->radius);
|
|
|
|
//QBrush brush = MapElementHelper::getBru(c->material, c->type, _focused);
|
|
|
|
// selected endpoints?
|
|
if (hasFocus()) {
|
|
p.setPenBrush(Qt::NoPen, CFG::SEL_COLOR);
|
|
if (selPoint == 0) {p.drawCircle(getSelPoints()[0]);}
|
|
if (selPoint == 1) {p.drawCircle(getSelPoints()[1]);}
|
|
}
|
|
|
|
// available endpoints
|
|
if (hasFocus()) {
|
|
p.setPenBrush(Qt::black, Qt::NoBrush);
|
|
p.drawCircle(getSelPoints()[0]);
|
|
p.drawCircle(getSelPoints()[1]);
|
|
}
|
|
|
|
}
|
|
|
|
std::vector<Point2> getSelPoints() const {
|
|
return {c->center, (c->center + Point2(c->radius,0))};
|
|
}
|
|
|
|
virtual void onFocus() override {
|
|
;
|
|
}
|
|
|
|
virtual void onUnfocus() override {
|
|
selPoint = -1;
|
|
}
|
|
|
|
/** 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 = v->getScaler().snap(_p);
|
|
if (selPoint == 0) {c->center = p;}
|
|
if (selPoint == 1) {c->radius = p.getDistance(c->center);}
|
|
}
|
|
|
|
/** mouse released */
|
|
virtual void mouseReleased(MapView2D* v, const Point2 _p) override {
|
|
const float t = v->getScaler().sm(CFG::SEL_THRESHOLD_SIZE_PX);
|
|
const float l1 = _p.getDistance(getSelPoints()[0]);
|
|
const float l2 = _p.getDistance(getSelPoints()[1]);
|
|
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 // MV2DELEMENTFLOOROBSTACLECIRCLE_H
|