added elevator support
This commit is contained in:
111
mapview/2D/MV2DElementElevator.h
Normal file
111
mapview/2D/MV2DElementElevator.h
Normal file
@@ -0,0 +1,111 @@
|
||||
#ifndef MV2DELEMENTELEVATOR_H
|
||||
#define MV2DELEMENTELEVATOR_H
|
||||
|
||||
#include "MV2DElement.h"
|
||||
#include "HasMoveableNodes.h"
|
||||
|
||||
#include "MapViewElementHelper.h"
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
|
||||
#include "../../UIHelper.h"
|
||||
|
||||
class MV2DElementElevator : public MV2DElement, public HasMoveableNodes {
|
||||
|
||||
private:
|
||||
|
||||
Floorplan::Elevator* elevator;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor with the AP to render/edit */
|
||||
MV2DElementElevator(Floorplan::Elevator* elevator) : elevator(elevator) {;}
|
||||
|
||||
|
||||
BBox2 getBoundingBox() const override {
|
||||
BBox2 bbox;
|
||||
const float max = std::max(elevator->width, elevator->depth);
|
||||
bbox.add(Point2(elevator->center.x, elevator->center.y));
|
||||
bbox.grow(Point2(max/2, max/2));
|
||||
return bbox;
|
||||
}
|
||||
|
||||
/** get the element's minimal distance (nearest whatsoever) to the given point */
|
||||
float getMinDistanceXY(const Point2 p) const override {
|
||||
// std::vector<Point2> points = elevator->getPoints().points;
|
||||
// points.push_back(elevator->center);
|
||||
// auto it minEl = std::min_element(points.begin(), points.end(),
|
||||
return p.getDistance(elevator->center);
|
||||
}
|
||||
|
||||
/** repaint me */
|
||||
void paint(Painter& p) override {
|
||||
|
||||
// area
|
||||
const Floorplan::Polygon2 poly = elevator->getPoints();
|
||||
p.setPenBrush(Qt::gray, Qt::lightGray);
|
||||
p.drawPolygon(poly.points);
|
||||
|
||||
// outline
|
||||
QPen pen; pen.setWidth(2); pen.setColor(QColor(0,0,0));
|
||||
p.setPenBrush(pen, Qt::NoBrush);
|
||||
//p.drawLine(poly.points[0], poly.points[1]);
|
||||
p.drawLine(poly.points[1], poly.points[2]);
|
||||
p.drawLine(poly.points[2], poly.points[3]);
|
||||
p.drawLine(poly.points[3], poly.points[0]);
|
||||
|
||||
if (selectedUserIdx == 0) {
|
||||
p.setPenBrush(Qt::black, CFG::SEL_COLOR);
|
||||
p.drawCircle(elevator->center);
|
||||
} else if (hasFocus()) {
|
||||
p.setPenBrush(Qt::black, Qt::NoBrush);
|
||||
p.drawCircle(elevator->center);
|
||||
} else {
|
||||
//p.setPenBrush(Qt::gray, Qt::NoBrush);
|
||||
//p.drawCircle(elevator->center);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
virtual std::vector<MoveableNode> getMoveableNodes() const override {
|
||||
return { MoveableNode(0, elevator->center) };
|
||||
}
|
||||
|
||||
virtual void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override {
|
||||
(void) v;
|
||||
if (userIdx == 0) {elevator->center.x = newPos.x; elevator->center.y = newPos.y;}
|
||||
}
|
||||
|
||||
|
||||
virtual void mousePressed(MapView2D* v, const Point2 p) override {
|
||||
(void) v;
|
||||
(void) p;
|
||||
}
|
||||
|
||||
virtual void mouseMove(MapView2D* v, const Point2 p) override {
|
||||
(void) v;
|
||||
(void) p;
|
||||
}
|
||||
|
||||
virtual void mouseReleased(MapView2D* v, const Point2 p) override {
|
||||
(void) v;
|
||||
(void) p;
|
||||
}
|
||||
|
||||
virtual bool keyPressEvent(MapView2D* v, QKeyEvent *e) override {
|
||||
(void) v;
|
||||
(void) e;
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void onFocus() override {
|
||||
;
|
||||
}
|
||||
|
||||
virtual void onUnfocus() override {
|
||||
;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // MV2DELEMENTELEVATOR_H
|
||||
@@ -15,6 +15,8 @@ class MV2DElementFloorUnderlay : public MV2DElement {
|
||||
private:
|
||||
|
||||
QImage img;
|
||||
QImage imgScaled;
|
||||
|
||||
std::string tmpFile;
|
||||
Floorplan::UnderlayImage* underlay;
|
||||
BBox2 bbox;
|
||||
@@ -58,9 +60,8 @@ public:
|
||||
|
||||
if (tmpFile != underlay->filename) {
|
||||
img = QImage(underlay->filename.c_str());
|
||||
if (img.size().width() == 0) {
|
||||
missing();
|
||||
}
|
||||
if (img.size().width() == 0) { missing(); }
|
||||
img = img.convertToFormat(QImage::Format_Grayscale8); // saves a huge amount of memory and should suffice
|
||||
tmpFile = underlay->filename;
|
||||
}
|
||||
|
||||
@@ -79,17 +80,39 @@ public:
|
||||
float sy1 = p.s.yms(my1);
|
||||
float sx2 = p.s.xms(mx2);
|
||||
float sy2 = p.s.yms(my2);
|
||||
float sw = std::abs(sx1-sx2);
|
||||
float sh = std::abs(sy1-sy2);
|
||||
float sw = std::round(std::abs(sx1-sx2));
|
||||
float sh = std::round(std::abs(sy1-sy2));
|
||||
|
||||
const float origArea = img.width() * img.height();
|
||||
const float scaledArea = sw*sh;
|
||||
|
||||
bbox = BBox2();
|
||||
bbox.add(Point2(mx1, my1));
|
||||
bbox.add(Point2(mx2, my2));
|
||||
|
||||
|
||||
// if the to-be-displayed image is smaller than the input-one, use a pre-computed downscaled version
|
||||
if (scaledArea < origArea) {
|
||||
// does the cached downscaled image needs rebuild? (size changed)
|
||||
if (imgScaled.width() != sw || imgScaled.height() != sh) {
|
||||
imgScaled = img.scaled(sw, sh, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
} else {
|
||||
imgScaled = QImage();
|
||||
}
|
||||
|
||||
|
||||
float opacity = p.p->opacity();
|
||||
p.p->setOpacity(0.50f);
|
||||
p.p->drawImage(QRectF(sx1, sy1-sh, sw, sh), img, QRectF(0,0,img.width(),img.height()));
|
||||
|
||||
// render downscaled image from cache? or use live-upscaling (faster, eats up less memory, ...)
|
||||
if (imgScaled.width() > 0) {
|
||||
p.p->drawImage(sx1, sy1-sh, imgScaled);
|
||||
} else {
|
||||
p.p->setRenderHint(QPainter::SmoothPixmapTransform, true);
|
||||
p.p->drawImage(QRectF(sx1, sy1-sh, sw, sh), img, QRectF(0,0,img.width(),img.height()));
|
||||
}
|
||||
|
||||
p.p->setOpacity(opacity);
|
||||
|
||||
// selected endpoint(s)?
|
||||
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
GridFactory<MyNode> fac(grid);
|
||||
fac.build(im, &l);
|
||||
|
||||
Importance::addImportance(grid);
|
||||
Importance::addImportance(grid, &l);
|
||||
//Importance::addImportance(grid, 400);
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "MMFloorUnderlays.h"
|
||||
#include "MMFloorPOIs.h"
|
||||
#include "MMFloorStairs.h"
|
||||
#include "MMFloorElevators.h"
|
||||
|
||||
#include "IHasParams.h"
|
||||
|
||||
@@ -39,7 +40,7 @@ public:
|
||||
new MMFloorBeacons(this, floor);
|
||||
new MMFloorPOIs(this, floor);
|
||||
new MMFloorStairs(this, floor);
|
||||
|
||||
new MMFloorElevators(this, floor);
|
||||
|
||||
}
|
||||
|
||||
|
||||
68
mapview/model/MMFloorElevator.h
Normal file
68
mapview/model/MMFloorElevator.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#ifndef MMFLOORELEVATOR_H
|
||||
#define MMFLOORELEVATOR_H
|
||||
|
||||
#include "MapModelElement.h"
|
||||
#include "IHasParams.h"
|
||||
|
||||
#include "../2D/MV2DElementElevator.h"
|
||||
//#include "../3D/MV3DElementElevator.h" TODO
|
||||
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
|
||||
class MMFloorElevator : public MapModelElement, public IHasParams {
|
||||
|
||||
private:
|
||||
|
||||
Floorplan::Floor* floor;
|
||||
Floorplan::Elevator* elevator;
|
||||
MV2DElementElevator mv2d;
|
||||
//MV3DElementElevator mv3d; TODO
|
||||
|
||||
public:
|
||||
|
||||
MMFloorElevator(MapLayer* parent, Floorplan::Floor* floor, Floorplan::Elevator* elevator) :
|
||||
MapModelElement(parent), floor(floor), elevator(elevator), mv2d(elevator) {
|
||||
|
||||
}
|
||||
|
||||
virtual int getNumParams() const override {
|
||||
return 3;
|
||||
}
|
||||
|
||||
virtual Param getParamDesc(const int idx) const override {
|
||||
switch(idx) {
|
||||
case 0: return Param("width", ParamType::FLOAT);
|
||||
case 1: return Param("depth", ParamType::FLOAT);
|
||||
case 2: return Param("rotation", ParamType::FLOAT);
|
||||
}
|
||||
throw 1;
|
||||
}
|
||||
|
||||
virtual ParamValue getParamValue(const int idx) const override {
|
||||
switch(idx) {
|
||||
case 0: return elevator->width;
|
||||
case 1: return elevator->depth;
|
||||
case 2: return (elevator->rotation * 180.0f / (float)M_PI);
|
||||
}
|
||||
throw 1;
|
||||
}
|
||||
|
||||
virtual void setParamValue(const int idx, const ParamValue& val) const override {
|
||||
switch(idx) {
|
||||
case 0: elevator->width = val.toFloat(); break;
|
||||
case 1: elevator->depth = val.toFloat(); break;
|
||||
case 2: elevator->rotation = val.toFloat() / 180.0f * (float)M_PI; break;
|
||||
}
|
||||
}
|
||||
|
||||
MV2DElement* getMV2D() const override {return (MV2DElement*) &mv2d;}
|
||||
MV3DElement* getMV3D() const override {return nullptr;} // TODO
|
||||
|
||||
void deleteMe() const override {
|
||||
parent->removeElement(this);
|
||||
floor->elevators.erase(std::remove(floor->elevators.begin(), floor->elevators.end(), elevator), floor->elevators.end());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // MMFLOORELEVATOR_H
|
||||
47
mapview/model/MMFloorElevators.h
Normal file
47
mapview/model/MMFloorElevators.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef MMFLOORELEVATORS_H
|
||||
#define MMFLOORELEVATORS_H
|
||||
|
||||
|
||||
#include "MapLayer.h"
|
||||
#include "MMFloorElevator.h"
|
||||
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
|
||||
/**
|
||||
* layer containing one floor's elevators
|
||||
*/
|
||||
class MMFloorElevators : public MapLayer {
|
||||
|
||||
private:
|
||||
|
||||
Floorplan::Floor* floor;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor with the underlying model */
|
||||
MMFloorElevators(MapLayer* parent, Floorplan::Floor* floor) : MapLayer(parent, MapLayerType::FLOOR_ELEVATORS), floor(floor) {
|
||||
|
||||
// add all elevators
|
||||
for (Floorplan::Elevator* elevator : floor->elevators) {
|
||||
elements.push_back(new MMFloorElevator(this, floor, elevator));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::string getLayerName() const override {return "Elevators";}
|
||||
|
||||
//TODO: check
|
||||
void create(Floorplan::Elevator* elevator) {
|
||||
|
||||
// add to underlying model
|
||||
floor->elevators.push_back(elevator);
|
||||
|
||||
// add to myself as element
|
||||
elements.push_back(new MMFloorElevator(this, floor, elevator));
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // MMFLOORELEVATORS_H
|
||||
@@ -17,6 +17,7 @@ enum class MapLayerType {
|
||||
FLOOR_OBSTACLES,
|
||||
FLOOR_BEACONS,
|
||||
FLOOR_ACCESS_POINTS,
|
||||
FLOOR_ELEVATORS,
|
||||
FLOOR_UNDERLAYS,
|
||||
FLOOR_POIS,
|
||||
FLOOR_STAIRS,
|
||||
|
||||
Reference in New Issue
Block a user