#ifndef MV2DELEMENTFLOOROBSTACLELINE_H #define MV2DELEMENTFLOOROBSTACLELINE_H #include "MV2DElement.h" #include "HasMoveableNodes.h" #include "MapViewElementHelper.h" #include #include 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 onFocus() override { ; } void onUnfocus() override { selectedUserIdx = -1; // clear selection } virtual std::vector 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