106 lines
2.7 KiB
C++
106 lines
2.7 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::Floor* f, Floorplan::FloorObstacleLine* fo) : f(f), 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);
|
|
}
|
|
|
|
bool isConnected(const Point2 p, const Floorplan::Floor* f, const Floorplan::FloorObstacleLine* fo) {
|
|
const float delta = 0.001;
|
|
for (const Floorplan::FloorObstacle* fo1 : f->obstacles) {
|
|
if (fo1 == fo) {continue;}
|
|
const Floorplan::FloorObstacleLine* line = dynamic_cast<const Floorplan::FloorObstacleLine*>(fo1);
|
|
if (line) {
|
|
if (line->from.eq(p, delta)) {return true;}
|
|
if (line->to.eq(p, delta)) {return true;}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void MV2DElementFloorObstacleLine::paint(Painter& p) {
|
|
|
|
// convert wall's thickness from meter to pixels
|
|
const float thickness_px = p.s.ms(fo->thickness_m);
|
|
|
|
// see notes within MapElementHelper!
|
|
// lines only get thicker, but not longer!
|
|
p.setPenBrush(MapElementHelper::getPen(fo->material, fo->type, hasFocus(), thickness_px), Qt::NoBrush);
|
|
|
|
// draw the wall itself
|
|
p.drawLine(fo->from, fo->to);
|
|
|
|
const bool c1 = isConnected(fo->from, f, fo);
|
|
const bool c2 = isConnected(fo->to, f, fo);
|
|
|
|
// wall conencted to other walls?
|
|
if (c1 || c2) {
|
|
|
|
// QPen change is costly!
|
|
QPen pp = p.getPen();
|
|
pp.setCapStyle(Qt::RoundCap);
|
|
p.setPen(pp);
|
|
|
|
// indicate connection with other wall
|
|
if (c1) {p.drawDot(fo->from);}
|
|
if (c2) {p.drawDot(fo->to);}
|
|
|
|
}
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
|