77 lines
2.4 KiB
C++
77 lines
2.4 KiB
C++
/*
|
||
* © Copyright 2014 – Urheberrechtshinweis
|
||
* Alle Rechte vorbehalten / All Rights Reserved
|
||
*
|
||
* Programmcode ist urheberrechtlich geschuetzt.
|
||
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
|
||
* Keine Verwendung ohne explizite Genehmigung.
|
||
* (vgl. § 106 ff UrhG / § 97 UrhG)
|
||
*/
|
||
|
||
#include "MapViewElementHelper.h"
|
||
|
||
#include <Indoor/geo/Point2.h>
|
||
#include <Indoor/geo/Point3.h>
|
||
#include <Indoor/geo/Line2.h>
|
||
|
||
#include <QColor>
|
||
#include <QPen>
|
||
#include <QBrush>
|
||
|
||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||
|
||
ClickDist MapElementHelper::getLineDistanceXY(Point2 p1, Point2 p2, Point2 dst) {
|
||
|
||
// the line (p1, p2)
|
||
const Line2 line(p1, p2);
|
||
|
||
// 90 degree rotation L of the line (p1, p2)
|
||
const Point2 vec = (p1 - p2).perpendicular();
|
||
|
||
// the line L
|
||
const Line2 perb(dst-vec*100, dst+vec*100);
|
||
|
||
// calculate the cut betwen L and (p1,p2) (if any)
|
||
Point2 cut(0,0);
|
||
ClickDist cutDist(99999999, ClickDistType::CUT);
|
||
if (line.getSegmentIntersection(perb, cut)) {
|
||
|
||
// distance between cut-point and mouse
|
||
cutDist.dst_px = cut.getDistance(dst);
|
||
|
||
}
|
||
|
||
// (direct) distance from endpoints
|
||
const ClickDist d1(p1.getDistance(dst), ClickDistType::DIRECT);
|
||
const ClickDist d2(p2.getDistance(dst), ClickDistType::DIRECT);
|
||
|
||
// return the nearest possibility:
|
||
return std::min(d1, std::min(d2, cutDist));
|
||
|
||
}
|
||
|
||
QPen MapElementHelper::getPen(Floorplan::Material mat, Floorplan::ObstacleType type, bool focus, float thickness_px) {
|
||
|
||
using namespace Floorplan;
|
||
QPen pen;
|
||
pen.setColor(Qt::darkGray); // default color
|
||
pen.setWidth(thickness_px); // element thickness
|
||
|
||
// this one is very important!
|
||
// as we change the line's width, the line also becomes longer
|
||
// but, we do not want this! -> FlatCap
|
||
pen.setCapStyle(Qt::FlatCap);
|
||
|
||
if (focus) {pen.setColor(QColor(64,64,200));}
|
||
else if (mat == Material::CONCRETE) {pen.setColor(QColor(32,32,32));}
|
||
else if (mat == Material::DRYWALL) {;}
|
||
else if (mat == Material::GLASS) {pen.setStyle(Qt::PenStyle::DotLine);}
|
||
else if (mat == Material::METALLIZED_GLAS) {pen.setStyle(Qt::PenStyle::DotLine);}
|
||
else if (mat == Material::METAL) {pen.setColor(QColor(64, 64, 64));}
|
||
else if (type == ObstacleType::HANDRAIL) {pen.setStyle(Qt::PenStyle::DashLine);}
|
||
else if (type == ObstacleType::UNKNOWN) {pen.setColor(Qt::red);}
|
||
else if (type == ObstacleType::PILLAR) {pen.setColor(Qt::red);}
|
||
|
||
return pen;
|
||
}
|