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.cpp
kazu 5d002c3f2b added more cpp files for faster compile speeds
removed many obsolte elements
many improvements and fixes
2018-07-20 15:00:43 +02:00

93 lines
2.3 KiB
C++

#include "MV2DElementFloorObstacleLine.h"
#include "MV2DElement.h"
#include "HasMoveableNodes.h"
#include "MapViewElementHelper.h"
#include <Indoor/floorplan/v2/Floorplan.h>
#include <stdio.h>
MV2DElementFloorObstacleLine::MV2DElementFloorObstacleLine(Floorplan::FloorObstacleLine* fo) : fo(fo) {
;
}
BBox2 MV2DElementFloorObstacleLine::getBoundingBox() const {
BBox2 bbox;
bbox.add(fo->from);
bbox.add(fo->to);
return bbox;
}
ClickDist MV2DElementFloorObstacleLine::getMinDistanceXY(const Point2 p) const {
return MapElementHelper::getLineDistanceXY(fo->from, fo->to, p);
}
void MV2DElementFloorObstacleLine::paint(Painter& p) {
// DEPRECATED
// // 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 pen3
//p.setPen(pen);
// length info
if (hasFocus()) {
// obstacle length
p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawLength(fo->from, fo->to, fo->from.getDistance(fo->to), thickness_px/2);
}
// DEPRECATED
// // available endpoints
// p.drawNode(fo->from, hasFocus(), hasFocus() && selectedUserIdx == 0);
// p.drawNode(fo->to, hasFocus(), hasFocus() && selectedUserIdx == 1);
}
void MV2DElementFloorObstacleLine::onFocus() {
;
}
void MV2DElementFloorObstacleLine::onUnfocus() {
selectedUserIdx = -1; // clear selection
}
std::vector<MoveableNode> MV2DElementFloorObstacleLine::getMoveableNodes() const {
return {
MoveableNode(0, fo->from),
MoveableNode(1, fo->to)
};
}
void MV2DElementFloorObstacleLine::onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) {
(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 MV2DElementFloorObstacleLine::onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}