fixed some issues

improvied editing
changed toolbox
This commit is contained in:
2017-03-20 19:25:23 +01:00
parent 92e279aefc
commit b7ee7d992a
18 changed files with 583 additions and 262 deletions

View File

@@ -1,4 +1,4 @@
#include "2D/MapView2D.h"
#include "MapView2D.h"
#include <QPainter>
#include <QOpenGLFunctions>
@@ -7,8 +7,8 @@
#include <iostream>
#include "model/MapModelElement.h"
#include "model/MapModel.h"
#include "../model/MapModelElement.h"
#include "../model/MapModel.h"
MapView2D::MapView2D(QWidget* parent) : QOpenGLWidget(parent) {

View File

@@ -25,7 +25,6 @@ protected:
/** register this tool into the given tools-queue */
Tools& tools;
Tool* oldMainTool;
std::vector<Point2> pts_m;
@@ -33,17 +32,12 @@ public:
/** ctor */
ToolMeasure(Tools& tools) : tools(tools) {
oldMainTool = tools.getMain(); // keep the current tool to reset it later
tools.setMain(this);
resetMe();
}
/** dtor */
virtual ~ToolMeasure() {
tools.setMain(oldMainTool); // reset to the previous tool
tools.setMainDefault();
}
const std::string getName() const {

View File

@@ -6,6 +6,7 @@
/**
* this tool allows moving the 2D map
* using the mouse
*/
class ToolMoveMap : public Tool {

View File

@@ -0,0 +1,61 @@
#ifndef TOOLNEWDOOR_H
#define TOOLNEWDOOR_H
#include "ToolNewElement.h"
class ToolNewDoor : public ToolNewElement<Floorplan::FloorObstacleDoor, MMFloorObstacleDoor> {
private:
/** currently edited line node (has 2) */
int idx = 0;
public:
ToolNewDoor(Tools& tools, MapLayer* layer) : ToolNewElement(tools, layer) {
create();
}
const std::string getName() const override {
return "new Door";
}
void createEmptyElement() override {
foEL = new Floorplan::FloorObstacleDoor(Floorplan::DoorType::SWING, Floorplan::Material::WOOD, Point2(0, 0), Point2(0, 0));
MMFloorObstacles* obs = (MMFloorObstacles*)layer;
mmEL = obs->createDoor(foEL);
}
/** 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 {
}
};
#endif // TOOLNEWDOOR_H

View File

@@ -0,0 +1,122 @@
#ifndef TOOLNEWELEMENT_H
#define TOOLNEWELEMENT_H
#include "Tool.h"
#include "Tools.h"
#include "../../model/MapLayer.h"
#include <Indoor/floorplan/v2/Floorplan.h>
/**
* this is a helper class
* for all tools within the toolbox,
* that create new elements: new door, new wall, ...
*/
template <typename FloorplanElement, typename MapModelElement> class ToolNewElement : public Tool {
protected:
/** add another line after this one? */
bool addAnother = true;
/** register this tool into the given tools-queue */
Tools& tools;
/** the layer to add the new element to */
MapLayer* layer = nullptr;
/** currently edited element */
FloorplanElement* foEL = nullptr;
MapModelElement* mmEL = nullptr;
public:
ToolNewElement(Tools& tools, MapLayer* layer) : tools(tools), layer(layer) {
}
virtual ~ToolNewElement() {
tools.setMainDefault();
}
virtual bool mousePressEvent(MapView2D* m, QMouseEvent* e) override {
if (e->button() == Qt::MouseButton::LeftButton) {
(void) m; (void) e;
return true;
} else {
return false;
}
}
virtual bool mouseMoveEvent(MapView2D* m, QMouseEvent* e) override {
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;
if (e->button() == Qt::MouseButton::LeftButton) {
leftMouse();
return true;
} else if (e->button() == Qt::MouseButton::RightButton) {
rightMouse();
return true;
} else {
return false;
}
}
virtual bool keyPressEvent(MapView2D* m, QKeyEvent* e) override {
(void) m;
if (e->key() == Qt::Key_Escape) {
deleteCurrent();
disableMe();
return true;
}
return false;
}
protected:
/** all subclasses must create a new, empty element here */
virtual void createEmptyElement() = 0;
/** mouse is currently moved */
virtual void moving(const Point2 mapPoint) = 0;
/** left mouse: usually: next part */
virtual void leftMouse() = 0;
/** right mouse: usually: done */
virtual void rightMouse() = 0;
protected:
void create() {
createEmptyElement();
mmEL->getMV2D()->focus();
}
/** delete the currently edited element */
void deleteCurrent() {
if (mmEL) {mmEL->deleteMe();}
}
/** finalize the current element (if any) */
void finalizeCurrent() {
if (!mmEL) {return;}
mmEL->getMV2D()->unfocus();
mmEL = nullptr;
}
/** finish creating new elements */
void disableMe() {
finalizeCurrent();
delete this; // see dtor!
}
};
#endif // TOOLNEWELEMENT_H

View File

@@ -0,0 +1,85 @@
#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) {
create();
}
const std::string getName() const override {
return "new Elevator";
}
void becomesActive() override {
showHelp();
}
void createEmptyElement() override {
foEL = new Floorplan::Elevator();
MMFloorElevators* elevators = (MMFloorElevators*)layer;
mmEL = elevators->create(foEL);
}
/** mouse is currently moved */
void moving(const Point2 mapPoint) override {
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);
}
/** 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;
}
}
};
#endif // TOOLNEWELEVATOR_H

View File

@@ -0,0 +1,66 @@
#ifndef TOOLNEWOUTLINE_H
#define TOOLNEWOUTLINE_H
#include "ToolNewElement.h"
#include "../../model/MMFloorOutline.h"
#include "../../model/MMFloorOutlinePolygon.h"
class ToolNewOutline : public ToolNewElement<Floorplan::FloorOutlinePolygon, MMFloorOutlinePolygon> {
private:
/** currently edited line node (has multiple) */
int idx = 0;
public:
ToolNewOutline(Tools& tools, MapLayer* layer) : ToolNewElement(tools, layer) {
create();
}
const std::string getName() const override {
return "new Outline";
}
void becomesActive() override {
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;
}
/** next point */
void leftMouse() override {
++idx;
foEL->poly.points.resize(idx+1);
foEL->poly.points.back() = foEL->poly.points[idx-1];
emit onHelpTextChange("left-click to add, right-click to end");
}
void rightMouse() override {
if (idx >= 3) {
finalizeCurrent();
} else {
deleteCurrent();
}
disableMe();
}
};
#endif // TOOLNEWOUTLINE_H

View File

@@ -0,0 +1,77 @@
#ifndef TOOLNEWSTAIR_H
#define TOOLNEWSTAIR_H
#include "ToolNewElement.h"
#include "../../model/MMFloorStairs.h"
class ToolNewStair : public ToolNewElement<Floorplan::StairFreeform, MMFloorStair> {
private:
/** currently edited line node (has multiple) */
int idx = 0;
public:
ToolNewStair(Tools& tools, MapLayer* layer) : ToolNewElement(tools, layer) {
create();
}
const std::string getName() const override {
return "new Stair";
}
void becomesActive() override {
emit onHelpTextChange("click for the stair's starting point");
}
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) {
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;
} else if (idx == 1) {
Floorplan::StairPart& part = foEL->parts[0];
part.end = Point3(mapPoint.x, mapPoint.y, 0);
} else {
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);
}
}
/** 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 rightMouse() override {
finalizeCurrent();
disableMe();
}
};
#endif // TOOLNEWSTAIR_H

View File

@@ -0,0 +1,63 @@
#ifndef TOOLNEWWALL_H
#define TOOLNEWWALL_H
#include "ToolNewElement.h"
#include "../../model/MMFloorObstacles.h"
#include "../../model/MMFloorObstacleLine.h"
class ToolNewWall : public ToolNewElement<Floorplan::FloorObstacleLine, MMFloorObstacleLine> {
private:
/** currently edited line node (has 2) */
int idx = 0;
public:
ToolNewWall(Tools& tools, MapLayer* layer) : ToolNewElement(tools, layer) {
create();
}
const std::string getName() const override {
return "new Wall";
}
void createEmptyElement() override {
foEL = new Floorplan::FloorObstacleLine(Floorplan::ObstacleType::WALL, Floorplan::Material::DRYWALL, Point2(0, 0), Point2(0, 0));
MMFloorObstacles* obs = (MMFloorObstacles*)layer;
mmEL = obs->createLine(foEL);
}
/** 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 {
}
};
#endif // TOOLNEWWALL_H

View File

@@ -15,8 +15,12 @@ private:
/** all added tools */
std::vector<Tool*> backgroundTools;
Tool* mainTool = nullptr;
/** the main tool to use whenever other tools are done: usually the select tool */
Tool* defaultMainTool = nullptr;
signals:
@@ -66,11 +70,20 @@ public:
}
}
/** set the currently active main tool back to the default */
void setMainDefault() {
setMain(defaultMainTool);
}
/** get the current main tool */
Tool* getMain() {
return this->mainTool;
}
/** set the default main tool to use whenever other tools are done */
void setDefaultMainTool(Tool* t) {
this->defaultMainTool = t;
}