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:
2017-06-01 16:26:09 +02:00
parent 489a64fd69
commit 7a23001b82
29 changed files with 763 additions and 265 deletions

View File

@@ -0,0 +1,47 @@
#ifndef TOOLNEWACCESSPOINT_H
#define TOOLNEWACCESSPOINT_H
#include "ToolNewElement.h"
#include "../../model/MMFloorAccessPoint.h"
#include "../../model/MMFloorAccessPoints.h"
class ToolNewAccessPoint : public ToolNewElement<Floorplan::AccessPoint, MMFloorAccessPoint> {
public:
ToolNewAccessPoint(Tools& tools, MapLayer* layer) : ToolNewElement(tools, layer) {
;
}
void becomesActive() override {
emit onHelpTextChange("left-click where to place a new access-point. right-click to end.");
}
void becomesInactive() override {
;
}
const std::string getName() const override {
return "new Access-Point";
}
void moving(const Point2 mapPoint) override {
(void) mapPoint;
}
/** next point */
void leftMouse(const Point2 mapPoint) override {
foEL = new Floorplan::AccessPoint("AP xx", "xx:xx:xx:xx:xx:xx", Point3(mapPoint.x, mapPoint.y, 2.0));
MMFloorAccessPoints* obs = (MMFloorAccessPoints*)layer;
mmEL = obs->createAP(foEL);
}
void rightMouse(const Point2 mapPoint) override {
(void) mapPoint;
finalizeCurrent();
disableMe();
}
};
#endif // TOOLNEWACCESSPOINT_H

View File

@@ -0,0 +1,47 @@
#ifndef TOOLNEWBEACON_H
#define TOOLNEWBEACON_H
#include "ToolNewElement.h"
#include "../../model/MMFloorBeacon.h"
#include "../../model/MMFloorBeacons.h"
class ToolNewBeacon : public ToolNewElement<Floorplan::Beacon, MMFloorBeacon> {
public:
ToolNewBeacon(Tools& tools, MapLayer* layer) : ToolNewElement(tools, layer) {
;
}
void becomesActive() override {
emit onHelpTextChange("left-click where to place a new beacon. right-click to end.");
}
void becomesInactive() override {
;
}
const std::string getName() const override {
return "new Beacon";
}
void moving(const Point2 mapPoint) override {
(void) mapPoint;
}
/** next point */
void leftMouse(const Point2 mapPoint) override {
foEL = new Floorplan::Beacon("Beacon xx", "xx:xx:xx:xx:xx:xx", Point3(mapPoint.x, mapPoint.y, 2));
MMFloorBeacons* obs = (MMFloorBeacons*)layer;
mmEL = obs->createBeacon(foEL);
}
void rightMouse(const Point2 mapPoint) override {
(void) mapPoint;
finalizeCurrent();
disableMe();
}
};
#endif // TOOLNEWBEACON_H

View File

@@ -13,14 +13,49 @@ private:
public:
ToolNewDoor(Tools& tools, MapLayer* layer) : ToolNewElement(tools, layer) {
create();
//create();
}
const std::string getName() const override {
return "new Door";
}
void createEmptyElement() override {
/** mouse is currently moved */
void moving(const Point2 mapPoint) override {
if (idx > 0) {
setPoint(idx, mapPoint);
}
}
/** next point */
void leftMouse(const Point2 mapPoint) override {
(void) mapPoint;
if (idx == 0) {
createEmptyElement();
setPoint(idx, mapPoint);
++idx;
} else if (idx == 1) {
setPoint(idx, mapPoint);
finalizeCurrent();
idx = 0;
if (!addAnother) {disableMe();}
}
}
void rightMouse(const Point2 mapPoint) override {
(void) mapPoint;
finalizeCurrent();
disableMe();
}
private:
void createEmptyElement() {
foEL = new Floorplan::FloorObstacleDoor(Floorplan::DoorType::SWING, Floorplan::Material::WOOD, Point2(0, 0), Point2(0, 0));
MMFloorObstacles* obs = (MMFloorObstacles*)layer;
@@ -28,33 +63,13 @@ public:
}
/** mouse is currently moved */
void moving(const Point2 mapPoint) override {
void setPoint(const int idx, const Point2 mapPoint) {
if (idx == 0) { foEL->from = mapPoint; foEL->to = mapPoint; }
if (idx == 1) { foEL->to = mapPoint; }
}
/** next point */
void leftMouse() override {
if (++idx == 2) {
finalizeCurrent();
if (addAnother) {
idx = 0;
create();
} else {
disableMe();
}
}
}
void rightMouse() override {
}
};

View File

@@ -48,24 +48,34 @@ public:
}
virtual bool mouseMoveEvent(MapView2D* m, QMouseEvent* e) override {
// get location on screen and within map
const Point2 onScreen(e->x(), e->y());
Point2 onMap = m->getScaler().sm(onScreen);
onMap = m->getScaler().snap(onMap);
moving(onMap);
return true;
}
virtual bool mouseReleaseEvent(MapView2D* m, QMouseEvent* e) override {
(void) m;
// get location on screen and within map
const Point2 onScreen(e->x(), e->y());
Point2 onMap = m->getScaler().sm(onScreen);
onMap = m->getScaler().snap(onMap);
if (e->button() == Qt::MouseButton::LeftButton) {
leftMouse();
leftMouse(onMap);
return true;
} else if (e->button() == Qt::MouseButton::RightButton) {
rightMouse();
rightMouse(onMap);
return true;
} else {
return false;
}
}
virtual bool keyPressEvent(MapView2D* m, QKeyEvent* e) override {
@@ -81,22 +91,22 @@ public:
protected:
/** all subclasses must create a new, empty element here */
virtual void createEmptyElement() = 0;
//virtual void createEmptyElement() = 0;
/** mouse is currently moved */
virtual void moving(const Point2 mapPoint) = 0;
/** left mouse: usually: next part */
virtual void leftMouse() = 0;
virtual void leftMouse(const Point2 mapPoint) = 0;
/** right mouse: usually: done */
virtual void rightMouse() = 0;
virtual void rightMouse(const Point2 mapPoint) = 0;
protected:
void create() {
createEmptyElement();
mmEL->getMV2D()->focus();
//createEmptyElement();
//mmEL->getMV2D()->focus();
}
/** delete the currently edited element */
@@ -107,8 +117,10 @@ protected:
/** finalize the current element (if any) */
void finalizeCurrent() {
if (!mmEL) {return;}
layer->changed(); // update the UI
mmEL->getMV2D()->unfocus();
mmEL = nullptr;
layer->changed(); // update the UI
}
/** finish creating new elements */

View File

@@ -21,7 +21,7 @@ public:
}
void becomesActive() override {
create(); // start adding an new element
//create(); // start adding an new element
showHelp();
}
@@ -33,7 +33,53 @@ public:
return "new Elevator";
}
void createEmptyElement() override {
/** mouse is currently moved */
void moving(const Point2 mapPoint) override {
if (idx > 0) {
setPoint(idx, mapPoint);
}
}
/** next point */
void leftMouse(const Point2 mapPoint) override {
(void) mapPoint;
if (idx == 0) {
createEmptyElement();
setPoint(idx, mapPoint);
++idx;
} else if (idx == 1) {
setPoint(idx, mapPoint);
++idx;
} else if (idx == 2) {
setPoint(idx, mapPoint);
finalizeCurrent();
disableMe();
idx = 0;
}
showHelp();
}
void rightMouse(const Point2 mapPoint) override {
(void) mapPoint;
}
void showHelp() {
switch (idx) {
case 0: emit onHelpTextChange("click at the right side of the elevator's door"); break;
case 1: emit onHelpTextChange("click at the left side of the elevator's door"); break;
case 2: emit onHelpTextChange("click at the left backside of the elevator"); break;
}
}
private:
void createEmptyElement() {
foEL = new Floorplan::Elevator();
MMFloorElevators* elevators = (MMFloorElevators*)layer;
@@ -41,8 +87,7 @@ public:
}
/** mouse is currently moved */
void moving(const Point2 mapPoint) override {
void setPoint(const int idx, const Point2 mapPoint) {
if (idx == 0) {
p1 = mapPoint;
@@ -62,28 +107,6 @@ public:
}
/** next point */
void leftMouse() override {
++idx;
if (idx == 3) {
finalizeCurrent();
disableMe();
}
showHelp();
}
void rightMouse() override {
;
}
void showHelp() {
switch (idx) {
case 0: emit onHelpTextChange("click at the right side of the elevator's door"); break;
case 1: emit onHelpTextChange("click at the left side of the elevator's door"); break;
case 2: emit onHelpTextChange("click at the left backside of the elevator"); break;
}
}
};

View File

@@ -0,0 +1,47 @@
#ifndef TOOLNEWFINGERPRINT_H
#define TOOLNEWFINGERPRINT_H
#include "ToolNewElement.h"
#include "../../model/MMFloorFingerprintLocation.h"
#include "../../model/MMFloorFingerprints.h"
class ToolNewFingerprint : public ToolNewElement<Floorplan::FingerprintLocation, MMFloorFingerprintLocation> {
public:
ToolNewFingerprint(Tools& tools, MapLayer* layer) : ToolNewElement(tools, layer) {
;
}
void becomesActive() override {
emit onHelpTextChange("left-click where to place a new fingerprint. right-click to end.");
}
void becomesInactive() override {
;
}
const std::string getName() const override {
return "new Fingerprint";
}
void moving(const Point2 mapPoint) override {
(void) mapPoint;
}
/** next point */
void leftMouse(const Point2 mapPoint) override {
foEL = new Floorplan::FingerprintLocation("FP xx", mapPoint, 1.3);
MMFloorFingerprints* obs = (MMFloorFingerprints*)layer;
mmEL = obs->create(foEL);
}
void rightMouse(const Point2 mapPoint) override {
(void) mapPoint;
finalizeCurrent();
disableMe();
}
};
#endif // TOOLNEWFINGERPRINT_H

View File

@@ -0,0 +1,49 @@
#ifndef TOOLNEWGROUNDTRUTH_H
#define TOOLNEWGROUNDTRUTH_H
#include "ToolNewElement.h"
#include "../../model/MMFloorGroundTruthPoint.h"
#include "../../model/MMFloorGroundTruthPoints.h"
class ToolNewGroundTruth : public ToolNewElement<Floorplan::GroundTruthPoint, MMFloorGroundTruthPoint> {
public:
ToolNewGroundTruth(Tools& tools, MapLayer* layer) : ToolNewElement(tools, layer) {
;
}
void becomesActive() override {
emit onHelpTextChange("left-click where to place a new ground-truth-point. right-click to end.");
}
void becomesInactive() override {
;
}
const std::string getName() const override {
return "new GroundTruth";
}
void moving(const Point2 mapPoint) override {
(void) mapPoint;
}
/** next point */
void leftMouse(const Point2 mapPoint) override {
foEL = new Floorplan::GroundTruthPoint(0, Point3(mapPoint.x, mapPoint.y, 0));
MMFloorGroundTruthPoints* obs = (MMFloorGroundTruthPoints*)layer;
mmEL = obs->createGroundTruthPoint(foEL);
}
void rightMouse(const Point2 mapPoint) override {
(void) mapPoint;
finalizeCurrent();
disableMe();
}
};
#endif // TOOLNEWGROUNDTRUTH_H

View File

@@ -15,7 +15,7 @@ private:
public:
ToolNewOutline(Tools& tools, MapLayer* layer) : ToolNewElement(tools, layer) {
create();
//create();
}
const std::string getName() const override {
@@ -26,32 +26,41 @@ public:
emit onHelpTextChange("left-click for each edge of the outline. right-click to end");
}
void createEmptyElement() override {
foEL = new Floorplan::FloorOutlinePolygon();
foEL->poly.points.resize(1);
foEL->outdoor = false;
foEL->method = Floorplan::OutlineMethod::ADD;
MMFloorOutline* outlines = (MMFloorOutline*)layer;
mmEL = outlines->create(foEL);
}
/** mouse is currently moved */
void moving(const Point2 mapPoint) override {
foEL->poly.points[idx] = mapPoint;
if (idx > 0) {
setPoint(idx, mapPoint);
}
}
/** next point */
void leftMouse() override {
void leftMouse(const Point2 mapPoint) override {
(void) mapPoint;
// 1st click
if (idx == 0) {
createEmptyElement();
foEL->poly.points.resize(foEL->poly.points.size() + 1);
} else {
;
}
foEL->poly.points.resize(foEL->poly.points.size() + 1);
setPoint(idx, mapPoint); // current element (finished)
++idx;
foEL->poly.points.resize(idx+1);
foEL->poly.points.back() = foEL->poly.points[idx-1];
setPoint(idx, mapPoint); // new element (start at the current)
emit onHelpTextChange("left-click to add, right-click to end");
}
void rightMouse() override {
void rightMouse(const Point2 mapPoint) override {
(void) mapPoint;
if (idx >= 3) {
finalizeCurrent();
} else {
@@ -60,6 +69,22 @@ public:
disableMe();
}
private:
void setPoint(const int idx, const Point2 mapPoint) {
foEL->poly.points[idx] = mapPoint;
}
void createEmptyElement() {
foEL = new Floorplan::FloorOutlinePolygon();
foEL->outdoor = false;
foEL->method = Floorplan::OutlineMethod::ADD;
MMFloorOutline* outlines = (MMFloorOutline*)layer;
mmEL = outlines->create(foEL);
}
};

View File

@@ -0,0 +1,49 @@
#ifndef TOOLNEWPOI_H
#define TOOLNEWPOI_H
#include "ToolNewElement.h"
#include "../../model/MMFloorPOI.h"
#include "../../model/MMFloorPOIs.h"
class ToolNewPOI : public ToolNewElement<Floorplan::POI, MMFloorPOI> {
public:
ToolNewPOI(Tools& tools, MapLayer* layer) : ToolNewElement(tools, layer) {
;
}
void becomesActive() override {
emit onHelpTextChange("left-click where to place a new POI. right-click to end.");
}
void becomesInactive() override {
;
}
const std::string getName() const override {
return "new Beacon";
}
void moving(const Point2 mapPoint) override {
(void) mapPoint;
}
/** next point */
void leftMouse(const Point2 mapPoint) override {
foEL = new Floorplan::POI(Floorplan::POIType::ROOM, "POI", mapPoint);
MMFloorPOIs* obs = (MMFloorPOIs*)layer;
mmEL = obs->createPOI(foEL);
}
void rightMouse(const Point2 mapPoint) override {
(void) mapPoint;
finalizeCurrent();
disableMe();
}
};
#endif // TOOLNEWPOI_H

View File

@@ -18,7 +18,7 @@ public:
}
void becomesActive() override {
create(); // start adding an new element
//create(); // start adding an new element
emit onHelpTextChange("click for the stair's starting point");
}
@@ -30,23 +30,59 @@ public:
return "new Stair";
}
void createEmptyElement() override {
foEL = new Floorplan::StairFreeform();
foEL->parts.resize(1);
MMFloorStairs* stairs = (MMFloorStairs*)layer;
mmEL = stairs->create(foEL);
}
/** mouse is currently moved */
void moving(const Point2 mapPoint) override {
if (idx == 0) {
if (idx > 0) {
setPoint(idx, mapPoint);
}
}
/** next point */
void leftMouse(const Point2 mapPoint) override {
(void) mapPoint;
// start a new stair here
if (idx == 0) {
createEmptyElement();
} else {
;
}
// add a new part to the stair
Floorplan::StairPart sp;
sp.connectWithPrev = false;
sp.width = 1.5;
foEL->parts.push_back(sp);
setPoint(idx, mapPoint); // current element (finished)
++idx;
setPoint(idx, mapPoint); // new element (start at the current)
emit onHelpTextChange("right-click: set end + start new part, left-click set end + finish");
}
void rightMouse(const Point2 mapPoint) override {
(void) mapPoint;
finalizeCurrent();
disableMe();
idx = 0;
}
private:
void setPoint(const int idx, const Point2 mapPoint) {
if (idx == 0) {
Floorplan::StairPart& part = foEL->parts[0];
part.connectWithPrev = false;
part.width = 1.5;
part.start = Point3(mapPoint.x, mapPoint.y, 0);
part.end = part.start;
@@ -54,10 +90,9 @@ public:
Floorplan::StairPart& part = foEL->parts[0];
part.end = Point3(mapPoint.x, mapPoint.y, 0);
} else {
} else if (idx > 1) {
Floorplan::StairPart& p1 = foEL->parts[idx-2];
Floorplan::StairPart& p2 = foEL->parts[idx-1];
p2.width = 1.5;
p2.start = p1.end;
p2.end = Point3(mapPoint.x, mapPoint.y, 0);
@@ -65,16 +100,12 @@ public:
}
/** next point */
void leftMouse() override {
++idx;
foEL->parts.resize(idx);
emit onHelpTextChange("right-click: set end + start new part, left-click set end + finish");
}
void createEmptyElement() {
foEL = new Floorplan::StairFreeform();
MMFloorStairs* stairs = (MMFloorStairs*)layer;
mmEL = stairs->create(foEL);
void rightMouse() override {
finalizeCurrent();
disableMe();
}
};

View File

@@ -19,7 +19,7 @@ public:
}
void becomesActive() override {
create(); // start adding an new element
//create(); // start adding an new element
}
void becomesInactive() override {
@@ -30,7 +30,46 @@ public:
return "new Wall";
}
void createEmptyElement() override {
/** mouse is currently moved */
void moving(const Point2 mapPoint) override {
// live-moving of the ending point
if (idx == 1) { foEL->to = mapPoint; }
}
/** next point */
void leftMouse(const Point2 mapPoint) override {
// 1st click (where to start the line)
if (idx == 0) {
createEmptyElement();
foEL->from = mapPoint; foEL->to = mapPoint;
++idx;
// 2nd click (wehere the line ends)
} else if (idx == 1) {
finalizeCurrent();
idx = 0;
if (!addAnother) {disableMe();}
}
}
void rightMouse(const Point2 mapPoint) override {
(void) mapPoint;
finalizeCurrent();
disableMe();
}
private:
void createEmptyElement() {
foEL = new Floorplan::FloorObstacleLine(Floorplan::ObstacleType::WALL, Floorplan::Material::DRYWALL, Point2(0, 0), Point2(0, 0));
MMFloorObstacles* obs = (MMFloorObstacles*)layer;
@@ -38,33 +77,6 @@ public:
}
/** mouse is currently moved */
void moving(const Point2 mapPoint) override {
if (idx == 0) { foEL->from = mapPoint; foEL->to = mapPoint; }
if (idx == 1) { foEL->to = mapPoint; }
}
/** next point */
void leftMouse() override {
if (++idx == 2) {
finalizeCurrent();
if (addAnother) {
idx = 0;
create();
} else {
disableMe();
}
}
}
void rightMouse() override {
}
};

View File

@@ -52,7 +52,7 @@ public:
* @return true if the focused element has changed. false otherwise
*/
bool focus(MapView2D* v, MapModelElement* el) {
setFocused(v, el);
return setFocused(v, el);
}
private:
@@ -72,40 +72,58 @@ private:
}
void processPress(MapView2D* m, const Point2 p, MapModelElement* elem) {
void processPress(QMouseEvent* e, MapView2D* m, const Point2 p, MapModelElement* elem) {
MV2DElement* me = elem->getMV2D();
if (!me) {return;}
// left mouse button?
if (e->button() == Qt::MouseButton::LeftButton) {
// element has selectedable nodes? try to select one
if (dynamic_cast<HasMoveableNodes*>(me)) {
if (selectNode(m, p, dynamic_cast<HasMoveableNodes*>(me))) {return;}
}
}
// let the element itself process all events
me->mousePressed(m, p);
}
void processMove(MapView2D* m, const Point2 p, MapModelElement* elem) {
void processMove(QMouseEvent* e, MapView2D* m, const Point2 p, MapModelElement* elem) {
(void) e;
MV2DElement* me = elem->getMV2D();
if (!me) {return;}
// elements has selectedable nodes? try to process them
if (dynamic_cast<HasMoveableNodes*>(me)) {
if (moveNode(m, p, dynamic_cast<HasMoveableNodes*>(me))) {return;}
}
// left mouse button? [does not work for move-events?!]
//if (e->button() == Qt::MouseButton::LeftButton) {
// elements has selectedable nodes? try to move the selected one (if any)
if (dynamic_cast<HasMoveableNodes*>(me)) {
if (moveNode(m, p, dynamic_cast<HasMoveableNodes*>(me))) {return;}
}
//}
// otherwise: let the element itself process all events
me->mouseMove(m, p);
}
void processRelease(MapView2D* m, const Point2 p, MapModelElement* elem) {
void processRelease(QMouseEvent* e, MapView2D* m, const Point2 p, MapModelElement* elem) {
(void) e;
MV2DElement* me = elem->getMV2D();
if (!me) {return;}
// element has selectedable nodes? try to process them
if (dynamic_cast<HasMoveableNodes*>(me)) {
if (selectNode(m, p, dynamic_cast<HasMoveableNodes*>(me))) {return;}
}
// // left mouse button?
// if (e->button() == Qt::MouseButton::LeftButton) {
// // element has selectedable nodes? try to select one
// if (dynamic_cast<HasMoveableNodes*>(me)) {
// if (selectNode(m, p, dynamic_cast<HasMoveableNodes*>(me))) {return;}
// }
// }
// otherwise: let the element itself process all events
me->mouseReleased(m, p);
@@ -124,6 +142,7 @@ private:
// find the node nearest to p
auto comp = [&] (const MoveableNode& n1, const MoveableNode& n2) {return n1.pos.getDistance(p) < n2.pos.getDistance(p);};
auto lst = elem->getMoveableNodes();
if (lst.empty()) {return false;} // nothing available!
auto it = std::min_element(lst.begin(), lst.end(), comp);
// is the nearest point below the threshold?
@@ -240,7 +259,7 @@ private:
// focus kept. provide the currently focused element with events
if (focused) {
processPress(m, p2, focused);
processPress(e, m, p2, focused);
}
}
@@ -258,7 +277,7 @@ private:
if (mouseIsDown) {
// provide the focused element with the mouse event?
if (focused) {processMove(m, p2, focused);}
if (focused) {processMove(e, m, p2, focused);}
}
@@ -269,13 +288,14 @@ private:
virtual bool mouseReleaseEvent(MapView2D* m, QMouseEvent* e) override {
const Scaler& s = m->getScaler();
Point2 p2(s.xsm(e->x()), s.ysm(e->y()));
const Point2 p2(s.xsm(e->x()), s.ysm(e->y()));
// provide the focused element with the mouse event?
if (focused) {processRelease(m, p2, focused);}
if (focused) {processRelease(e, m, p2, focused);}
mouseIsDown = false;
// not consumed
return false;
}