fixed some issues
added new tools for creating APs, Beacons, GTP, POI, Fingerprints fixed selection issue changed new-element creation added missing layer parameters
This commit is contained in:
@@ -2,18 +2,20 @@
|
||||
#define MV2DELEMENTSTAIR_H
|
||||
|
||||
#include "MV2DElement.h"
|
||||
#include "HasMoveableNodes.h"
|
||||
|
||||
#include "MapViewElementHelper.h"
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
|
||||
class MV2DElementStair : public MV2DElement {
|
||||
class MV2DElementStair : public MV2DElement, public HasMoveableNodes {
|
||||
|
||||
private:
|
||||
|
||||
bool sel = false;
|
||||
Floorplan::Floor* floor;
|
||||
Floorplan::Stair* stair;
|
||||
int selPart = -1;
|
||||
int selNode = -1;
|
||||
//int selPart = -1;
|
||||
//int selNode = -1;
|
||||
|
||||
public:
|
||||
|
||||
@@ -49,11 +51,8 @@ public:
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int getSelPart() const {return selPart;}
|
||||
int getSelNode() const {return selNode;}
|
||||
int getSelPart() const {return getSelectedNode() < 0 ? getSelectedNode() : getSelectedNode() / 2;}
|
||||
int getSelNode() const {return getSelectedNode() < 0 ? getSelectedNode() : getSelectedNode() % 2;}
|
||||
|
||||
static inline float clamp01(const float val) {
|
||||
if (val < 0) {return 0;}
|
||||
@@ -66,11 +65,6 @@ public:
|
||||
|
||||
Floorplan::StairFreeform* stair = dynamic_cast<Floorplan::StairFreeform*>(this->stair);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// if (sel) {
|
||||
// p.setPenBrush(Qt::black, CFG::SEL_COLOR);
|
||||
// p.drawCircle(stair->center);
|
||||
@@ -140,9 +134,9 @@ public:
|
||||
int cnt = 0;
|
||||
std::vector<Floorplan::StairPart> parts = stair->getParts();
|
||||
for (const Floorplan::StairPart& part : parts) {
|
||||
p.setPenBrush(Qt::black, (cnt == selPart && selNode == 0) ? CFG::SEL_COLOR : Qt::NoBrush); // part start
|
||||
p.setPenBrush(Qt::black, (cnt == getSelPart() && getSelNode() == 0) ? CFG::SEL_COLOR : Qt::NoBrush); // part start
|
||||
p.drawCircle(part.start.xy());
|
||||
p.setPenBrush(Qt::black, (cnt == selPart && selNode == 1) ? CFG::SEL_COLOR : Qt::NoBrush); // part end
|
||||
p.setPenBrush(Qt::black, (cnt == getSelPart() && getSelNode() == 1) ? CFG::SEL_COLOR : Qt::NoBrush); // part end
|
||||
p.drawRect(part.end.xy());
|
||||
p.setPenBrush(Qt::blue, Qt::NoBrush);
|
||||
Point2 ctr = (part.start+part.end).xy() / 2;
|
||||
@@ -160,54 +154,54 @@ public:
|
||||
|
||||
|
||||
|
||||
/** mouse pressed at the given point */
|
||||
virtual void mousePressed(MapView2D* v, const Point2 p) override {
|
||||
(void) v;
|
||||
(void) p;
|
||||
// /** mouse pressed at the given point */
|
||||
// virtual void mousePressed(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 (selPart == -1) {return;}
|
||||
Floorplan::StairFreeform* stair = dynamic_cast<Floorplan::StairFreeform*>(this->stair);
|
||||
const Point2 p = v->getScaler().snap(_p);
|
||||
stair->parts[selPart][selNode].x = p.x;
|
||||
stair->parts[selPart][selNode].y = p.y;
|
||||
}
|
||||
// /** mouse moved to the given point */
|
||||
// virtual void mouseMove(MapView2D* v, const Point2 _p) override {
|
||||
// (void) v;
|
||||
// if (selPart == -1) {return;}
|
||||
// Floorplan::StairFreeform* stair = dynamic_cast<Floorplan::StairFreeform*>(this->stair);
|
||||
// const Point2 p = v->getScaler().snap(_p);
|
||||
// stair->parts[selPart][selNode].x = p.x;
|
||||
// stair->parts[selPart][selNode].y = p.y;
|
||||
// }
|
||||
|
||||
/** mouse released */
|
||||
virtual void mouseReleased(MapView2D* v, const Point2 _p) override {
|
||||
(void) v;
|
||||
(void) _p;
|
||||
// select a new point on mouse-release (more robust than on mouse-press)
|
||||
Floorplan::StairFreeform* stair = dynamic_cast<Floorplan::StairFreeform*>(this->stair);
|
||||
const float t = v->getScaler().sm(CFG::SEL_THRESHOLD_SIZE_PX);
|
||||
// auto comp = [&] (const Point3 a, const Point3 b) {return a.xy().getDistance(_p) < b.xy().getDistance(_p);};
|
||||
// auto it = std::min_element(stair->nodes.begin(), stair->nodes.end(), comp);
|
||||
// if (it == stair->nodes.end()) {selIdx = -1;} // none found -> skip
|
||||
// else if ((*it).xy().getDistance(_p) > t) {selIdx = -1;} // nearest distance is above threshold -> skip
|
||||
// else {selIdx = it - stair->nodes.begin();}
|
||||
// /** mouse released */
|
||||
// virtual void mouseReleased(MapView2D* v, const Point2 _p) override {
|
||||
// (void) v;
|
||||
// (void) _p;
|
||||
// // select a new point on mouse-release (more robust than on mouse-press)
|
||||
// Floorplan::StairFreeform* stair = dynamic_cast<Floorplan::StairFreeform*>(this->stair);
|
||||
// const float t = v->getScaler().sm(CFG::SEL_THRESHOLD_SIZE_PX);
|
||||
//// auto comp = [&] (const Point3 a, const Point3 b) {return a.xy().getDistance(_p) < b.xy().getDistance(_p);};
|
||||
//// auto it = std::min_element(stair->nodes.begin(), stair->nodes.end(), comp);
|
||||
//// if (it == stair->nodes.end()) {selIdx = -1;} // none found -> skip
|
||||
//// else if ((*it).xy().getDistance(_p) > t) {selIdx = -1;} // nearest distance is above threshold -> skip
|
||||
//// else {selIdx = it - stair->nodes.begin();}
|
||||
|
||||
float best = 999999;
|
||||
int minPart; int minNode;
|
||||
for (int part = 0; part < (int) stair->parts.size(); ++part) {
|
||||
for (int node = 0; node < 2; ++node) {
|
||||
const float dist = stair->parts[part][node].xy().getDistance(_p);
|
||||
if (dist < best) {best = dist; minPart = part; minNode = node;}
|
||||
}
|
||||
}
|
||||
// float best = 999999;
|
||||
// int minPart; int minNode;
|
||||
// for (int part = 0; part < (int) stair->parts.size(); ++part) {
|
||||
// for (int node = 0; node < 2; ++node) {
|
||||
// const float dist = stair->parts[part][node].xy().getDistance(_p);
|
||||
// if (dist < best) {best = dist; minPart = part; minNode = node;}
|
||||
// }
|
||||
// }
|
||||
|
||||
if (best <= t) {
|
||||
selPart = minPart; selNode = minNode;
|
||||
} else {
|
||||
selPart = -1; selNode = -1;
|
||||
}
|
||||
// if (best <= t) {
|
||||
// selPart = minPart; selNode = minNode;
|
||||
// } else {
|
||||
// selPart = -1; selNode = -1;
|
||||
// }
|
||||
|
||||
emit v->onElementChange(this);
|
||||
// emit v->onElementChange(this);
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
virtual bool keyPressEvent(MapView2D* v, QKeyEvent *e) override {
|
||||
(void) v;
|
||||
@@ -218,13 +212,13 @@ public:
|
||||
if (e->key() == Qt::Key_Delete) {
|
||||
|
||||
// delete the currently selected vertex?
|
||||
if (selPart != -1) {
|
||||
if (getSelPart() != -1) {
|
||||
// stair->nodes.erase(stair->nodes.begin() + selIdx);
|
||||
// selIdx = -1;
|
||||
// return true;
|
||||
}
|
||||
|
||||
} else if (e->key() == Qt::Key_Plus && selPart != -1) {
|
||||
} else if (e->key() == Qt::Key_Plus && getSelPart() != -1) {
|
||||
// int idx1 = selIdx;
|
||||
// int idx2 = (selIdx + 1) % stair->nodes.size();
|
||||
// int idxNew = idx2;
|
||||
@@ -232,11 +226,11 @@ public:
|
||||
// stair->nodes.insert(stair->nodes.begin() + idxNew, pNew);
|
||||
// selIdx = idxNew;
|
||||
// return true;
|
||||
const int idxNew = selPart + 1;
|
||||
const Point3 p0 = stair->parts[selPart][1];
|
||||
const int idxNew = getSelPart() + 1;
|
||||
const Point3 p0 = stair->parts[getSelPart()][1];
|
||||
const Point3 p1 = p0 + Point3(1,1,0);
|
||||
const Point3 p2 = p1 + Point3(2,2,0);
|
||||
const float w = stair->parts[selPart].width;
|
||||
const float w = stair->parts[getSelPart()].width;
|
||||
stair->parts.insert(stair->parts.begin() + idxNew, Floorplan::StairPart(p1, p2, w));
|
||||
return true;
|
||||
}
|
||||
@@ -247,14 +241,46 @@ public:
|
||||
}
|
||||
|
||||
virtual void onFocus() override {
|
||||
selPart = -1;
|
||||
selNode = -1;
|
||||
// TODO?
|
||||
}
|
||||
|
||||
virtual void onUnfocus() override {
|
||||
sel = false;
|
||||
}
|
||||
|
||||
virtual std::vector<MoveableNode> getMoveableNodes() const override {
|
||||
|
||||
std::vector<MoveableNode> nodes;
|
||||
Floorplan::StairFreeform* stair = dynamic_cast<Floorplan::StairFreeform*>(this->stair);
|
||||
|
||||
// get a list of all moveable nodes (2 per stair-part)
|
||||
int idx = 0;
|
||||
for (size_t part = 0; part < stair->parts.size(); ++part) {
|
||||
for (int node = 0; node < 2; ++node) {
|
||||
MoveableNode mn(idx++, stair->parts[part][node].xy());
|
||||
nodes.push_back(mn);
|
||||
}
|
||||
}
|
||||
|
||||
return nodes;
|
||||
|
||||
}
|
||||
|
||||
void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override {
|
||||
|
||||
(void) v;
|
||||
|
||||
// convert node-index back to stair-part and node-nr within stair-part
|
||||
const int selPart = userIdx / 2;
|
||||
const int selNode = userIdx % 2;
|
||||
|
||||
// move the node
|
||||
Floorplan::StairFreeform* stair = dynamic_cast<Floorplan::StairFreeform*>(this->stair);
|
||||
stair->parts[selPart][selNode].x = newPos.x;
|
||||
stair->parts[selPart][selNode].y = newPos.y;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // MV2DELEMENTSTAIR_H
|
||||
|
||||
Reference in New Issue
Block a user