refactoring

wireframe display
worked on 3d-model display
This commit is contained in:
2018-02-08 21:38:51 +01:00
parent bce771d6d6
commit 839401edb7
16 changed files with 395 additions and 236 deletions

View File

@@ -0,0 +1,138 @@
#include "MV2DElementFloorObstacleDoor.h"
#include "MV2DElement.h"
#include "MapViewElementHelper.h"
#include "HasMoveableNodes.h"
#include <Indoor/floorplan/v2/Floorplan.h>
#include <chrono>
MV2DElementFloorObstacleDoor::MV2DElementFloorObstacleDoor(Floorplan::FloorObstacleDoor* fo) : fo(fo) {
;
}
BBox2 MV2DElementFloorObstacleDoor::getBoundingBox() const {
BBox2 bbox;
bbox.add(fo->from);
bbox.add(fo->to);
return bbox;
}
ClickDist MV2DElementFloorObstacleDoor::getMinDistanceXY(const Point2 p) const {
return MapElementHelper::getLineDistanceXY(fo->from, fo->to, p) * 0.95;
}
void MV2DElementFloorObstacleDoor::paint(Painter& p) {
// 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);}
}
QPen pen;
pen.setColor(QColor(0.5,0.5,0.5));
pen.setStyle(Qt::PenStyle::DotLine);
p.setPenBrush(pen, Qt::NoBrush);
if (Floorplan::DoorType::SWING == fo->type) {
// opening indicator
const float open = (fo->swap) ? (-M_PI * 0.5) : (+M_PI * 0.5);
const float len = (fo->to - fo->from).length();
const float angle1 = std::atan2(fo->to.y-fo->from.y, fo->to.x-fo->from.x);
const float angle2 = angle1 + open;
const Point2 pOpen = Point2( std::cos(angle2) * len, std::sin(angle2) * len ) + fo->from;
pen.setWidth(2); p.setPen(pen);
p.drawLine(fo->from, fo->to);
pen.setWidth(1); p.setPen(pen);
p.drawLine(fo->from, pOpen);
p.drawArc(fo->from, len, angle1, open);
} else if (Floorplan::DoorType::REVOLVING == fo->type) {
const float angle_rad = std::atan2(fo->to.y-fo->from.y, fo->to.x-fo->from.x);
// arcs
const Point2 cen = (fo->from + fo->to) / 2;
const float rad = (fo->to - fo->from).length() / 2;
p.drawArc(cen, rad, (40-90)/180.0f*M_PI+angle_rad, 100/180.0f*M_PI);
p.drawArc(cen, rad, (180+40-90)/180.0f*M_PI+angle_rad, 100/180.0f*M_PI);
const int funAngle = (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() / 50) % 360;
// inner spinner
int numDoors = 3;
for (int i = 0; i < numDoors; ++i) {
const int deg = 360 * i / numDoors + angle_rad*180.0f/M_PI + funAngle;
const float sx = std::cos(deg / 180.0f * M_PI);
const float sy = std::sin(deg / 180.0f * M_PI);
const Point2 dst = cen + Point2(sx,sy) * rad;
p.drawLine(cen, dst);
}
}
// available endpoints
if (hasFocus()) {
p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawCircle(fo->from);
p.drawCircle(fo->to);
}
// obstacle length
if (hasFocus()) {
p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawLength(fo->from, fo->to, fo->from.getDistance(fo->to));
}
}
void MV2DElementFloorObstacleDoor::onFocus() {
;
}
void MV2DElementFloorObstacleDoor::onUnfocus() {
selectedUserIdx = -1; // clear selection
}
void MV2DElementFloorObstacleDoor::mousePressed(MapView2D* v, const Point2 p) {
(void) v;
(void) p;
}
void MV2DElementFloorObstacleDoor::mouseMove(MapView2D* v, const Point2 p) {
(void) v;
(void) p;
}
void MV2DElementFloorObstacleDoor::mouseReleased(MapView2D* v, const Point2 p) {
(void) v;
(void) p;
}
std::vector<MoveableNode> MV2DElementFloorObstacleDoor::getMoveableNodes() const {
std::vector<MoveableNode> nodes = {
MoveableNode(0, fo->from),
MoveableNode(1, fo->to)
};
return nodes;
}
void MV2DElementFloorObstacleDoor::onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) {
switch (userIdx) {
case 0: fo->from = newPos; break;
case 1: fo->to = newPos; break;
}
emit v->onElementChange(this);
}
bool MV2DElementFloorObstacleDoor::keyPressEvent(MapView2D* v, QKeyEvent *e) {
(void) v;
(void) e;
return false;
}

View File

@@ -2,7 +2,6 @@
#define MV2DELEMENTFLOOROBSTACLEDOOR_H
#include "MV2DElement.h"
#include "MapViewElementHelper.h"
#include "HasMoveableNodes.h"
#include <Indoor/floorplan/v2/Floorplan.h>
@@ -16,136 +15,36 @@ private:
public:
/** ctor */
MV2DElementFloorObstacleDoor(Floorplan::FloorObstacleDoor* fo) : fo(fo) {;}
MV2DElementFloorObstacleDoor(Floorplan::FloorObstacleDoor* fo);
/** get the element's 3D bounding box */
BBox2 getBoundingBox() const override {
BBox2 bbox;
bbox.add(fo->from);
bbox.add(fo->to);
return bbox;
}
BBox2 getBoundingBox() const override;
/** 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);
}
ClickDist getMinDistanceXY(const Point2 p) const override;
/** repaint me */
void paint(Painter& p) override {
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);}
}
virtual void onFocus() override;
QPen pen;
pen.setColor(QColor(0.5,0.5,0.5));
pen.setStyle(Qt::PenStyle::DotLine);
p.setPenBrush(pen, Qt::NoBrush);
virtual void onUnfocus() override;
// opening indicator
const float open = (fo->swap) ? (-M_PI * 0.5) : (+M_PI * 0.5);
const float len = (fo->to - fo->from).length();
const float angle1 = std::atan2(fo->to.y-fo->from.y, fo->to.x-fo->from.x);
const float angle2 = angle1 + open;
const Point2 pOpen = Point2( std::cos(angle2) * len, std::sin(angle2) * len ) + fo->from;
virtual void mousePressed(MapView2D* v, const Point2 p) override;
pen.setWidth(2); p.setPen(pen);
p.drawLine(fo->from, fo->to);
virtual void mouseMove(MapView2D* v, const Point2 p) override;
pen.setWidth(1); p.setPen(pen);
p.drawLine(fo->from, pOpen);
p.drawArc(fo->from, len, angle1, open);
// available endpoints
if (hasFocus()) {
p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawCircle(fo->from);
p.drawCircle(fo->to);
}
// obstacle length
if (hasFocus()) {
p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawLength(fo->from, fo->to, fo->from.getDistance(fo->to));
}
}
virtual void onFocus() override {
;
}
virtual void onUnfocus() override {
selectedUserIdx = -1; // clear selection
}
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;
}
/** mouse moved to the given point */
// virtual void mouseMove(MapView2D* v, const Point2 _p) override {
// (void) v;
// if (selPoint == -1) {return;}
// const Point2 p = v->getScaler().snap(_p);
// if (selPoint == 0) {fo->from.x = p.x; fo->from.y = p.y;}
// if (selPoint == 1) {fo->to.x = p.x; fo->to.y = p.y;}
// emit v->onElementChange(this);
// }
/** mouse released */
// virtual void mouseReleased(MapView2D* v, const Point2 _p) override {
// // select a new point on mouse-release (more robust than on mouse-press)
// const float t = v->getScaler().sm(CFG::SEL_THRESHOLD_SIZE_PX);
// const float l1 = _p.getDistance(fo->from);
// const float l2 = _p.getDistance(fo->to);
// if (l1 < l2 && l1 <= t) {selPoint = 0;}
// else if (l2 < l1 && l2 <= t) {selPoint = 1;}
// else {selPoint = -1;}
// }
virtual void mouseReleased(MapView2D* v, const Point2 p) override;
/** get a list of all nodes that are selectable / moveable */
virtual std::vector<MoveableNode> getMoveableNodes() const override {
std::vector<MoveableNode> nodes = {
MoveableNode(0, fo->from),
MoveableNode(1, fo->to)
};
return nodes;
}
virtual std::vector<MoveableNode> getMoveableNodes() const override;
/** the given node was moved */
virtual void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override {
switch (userIdx) {
case 0: fo->from = newPos; break;
case 1: fo->to = newPos; break;
}
emit v->onElementChange(this);
}
virtual void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override;
virtual bool keyPressEvent(MapView2D* v, QKeyEvent *e) override {
(void) v;
(void) e;
return false;
}
virtual bool keyPressEvent(MapView2D* v, QKeyEvent *e) override;
};

View File

@@ -34,7 +34,7 @@ public:
const ClickDist dst = MapElementHelper::getLineDistanceXY(p1, p2, p);
if (dst < min) {min = dst;}
}
return min;
return min * 1.1; // penalty.. outlines are everywhere.. reduce priority
}
virtual void onFocus() override {

View File

@@ -56,7 +56,7 @@ public:
}
// distance from endpoints
// (direct) distance from endpoints
const ClickDist d1(p1.getDistance(dst), ClickDistType::DIRECT);
const ClickDist d2(p2.getDistance(dst), ClickDistType::DIRECT);