This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
IndoorMap/mapview/2D/tools/ToolNewElevator.h
2018-10-25 12:23:40 +02:00

124 lines
2.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © 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)
*/
#ifndef TOOLNEWELEVATOR_H
#define TOOLNEWELEVATOR_H
#include "ToolNewElement.h"
#include "../../model/MMFloorElevators.h"
class ToolNewElevator : public ToolNewElement<Floorplan::Elevator, MMFloorElevator> {
private:
/** currently edited line node (has multiple) */
int idx = 0;
Point2 p1;
Point2 p2;
Point2 p3;
public:
ToolNewElevator(Tools& tools, MapLayer* layer) : ToolNewElement(tools, layer) {
;
}
void becomesActive() override {
//create(); // start adding an new element
showHelp();
}
void becomesInactive() override {
deleteCurrent(); // delete the currently pending and not yet finished elevator
}
const std::string getName() const override {
return "new Elevator";
}
/** 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;
mmEL = elevators->create(foEL);
}
void setPoint(const int idx, const Point2 mapPoint) {
if (idx == 0) {
p1 = mapPoint;
p2 = mapPoint;
p3 = mapPoint;
} else if (idx == 1) {
p2 = mapPoint;
p3 = mapPoint;
} else if (idx == 2) {
p3 = mapPoint;
}
foEL->center = (p1+p3)/2;
foEL->width = p1.getDistance(p2);
foEL->depth = p2.getDistance(p3);
foEL->rotation = std::atan2(p2.y-p1.y, p2.x-p1.x);
}
};
#endif // TOOLNEWELEVATOR_H