many changes :P

This commit is contained in:
k-a-z-u
2016-01-21 20:01:20 +01:00
parent a7dc0cabbb
commit 12084fe147
29 changed files with 2900 additions and 144 deletions

View File

@@ -2,7 +2,7 @@
#define FLOOR_H
#include <vector>
#include "../geo/Line2D.h"
#include "../geo/Line2.h"
/**
* represents one floor by describing all contained obstacles
@@ -13,7 +13,7 @@ private:
/** all obstacles within the floor */
std::vector<Line2D> lines;
std::vector<Line2> lines;
/** total width of the floor (in meter) */
double width_cm;
@@ -28,12 +28,12 @@ public:
Floor(const float width_cm, const float depth_cm) : width_cm(width_cm), depth_cm(depth_cm) {;}
/** get all obstacles */
const std::vector<Line2D>& getObstacles() const {
const std::vector<Line2>& getObstacles() const {
return lines;
}
/** add a new obstacle to this floor */
void addObstacle(const Line2D& l ) {
void addObstacle(const Line2& l ) {
lines.push_back(l);
}

View File

@@ -2,6 +2,8 @@
#define FLOORPLANFACTORYSVG_H
#include "Floor.h"
#include "Stairs.h"
#include <string>
#include "../Exception.h"
@@ -32,21 +34,21 @@ class FloorplanFactorySVG {
}
/** scale (x, y) into (_x, _y) */
void scale(const double x, const double y, double& _x, double& _y) const {
void scale(const double x, const double y, float& _x, float& _y) const {
_x = x * scalingFactor;
_y = y * scalingFactor;
}
/** scale the given point into a new output point */
K::Point scale(const K::Point p) const {
K::Point ret;
scale (p.x, p.y, ret.x, ret.y);
return ret;
}
// /** scale the given point into a new output point */
// K::Point scale(const K::Point p) const {
// K::Point ret;
// scale (p.x, p.y, ret.x, ret.y);
// return ret;
// }
/** scale the given line into a new output line */
Line2D scale(const K::Line l) const {
Line2D ret;
Line2 scale(const K::Line l) const {
Line2 ret;
scale (l.p1.x, l.p1.y, ret.p1.x, ret.p1.y);
scale (l.p2.x, l.p2.y, ret.p2.x, ret.p2.y);
return ret;
@@ -58,8 +60,8 @@ private:
K::SVGFile svg;
SVGScaler scaler;
double width;
double depth;
float width;
float depth;
public:
@@ -88,22 +90,38 @@ public:
// create and parse the new floor
Floor floor(width, depth);
load(layer, floor);
loadFloor(layer, floor);
return floor;
}
/** get all stairs within the given layer */
Stairs getStairs(const std::string& layerName) {
// get the requested SVG layer
K::SVGComposite* sc = svg.getLayers();
K::SVGLayer* layer = sc->getContainedLayerNamed(layerName);
if (!layer) {throw Exception("SVG has no layer named '" + layerName + "'");}
// create and parse the new floor
Stairs stairs;
loadStairs(layer, stairs);
return stairs;
}
private:
/** recursive loading/parsing of nested SVG elements */
void load(K::SVGElement* el, Floor& floor) {
void loadFloor(K::SVGElement* el, Floor& floor) {
switch (el->getType()) {
case SVGElementType::COMPOSITE: {
for (K::SVGElement* sub : ((K::SVGComposite*)el)->getChilds()) {
load(sub, floor);
loadFloor(sub, floor);
}
break;
}
@@ -111,7 +129,7 @@ private:
case SVGElementType::LAYER: {
K::SVGLayer* layer = (K::SVGLayer*) el;
for (K::SVGElement* sub : layer->getChilds()) {
load(sub, floor);
loadFloor(sub, floor);
}
break;
}
@@ -133,6 +151,60 @@ private:
}
}
/** recursive loading/parsing of nested SVG elements */
void loadStairs(K::SVGElement* el, Stairs& stairs) {
switch (el->getType()) {
case SVGElementType::COMPOSITE: {
for (K::SVGElement* sub : ((K::SVGComposite*)el)->getChilds()) {
loadStairs(sub, stairs);
}
break;
}
case SVGElementType::LAYER: {
K::SVGLayer* layer = (K::SVGLayer*) el;
for (K::SVGElement* sub : layer->getChilds()) {
loadStairs(sub, stairs);
}
break;
}
case SVGElementType::PATH: {
int i = 0;
Line2 start;
Line2 dir;
for (const K::Line& line : ((K::SVGPath*)el)->getLines()) {
if (++i == 1) {
start = scaler.scale(line);
} else {
Stair s;
Line2 dir = scaler.scale(line);
s.dir = (dir.p2 - dir.p1);
const float d = 9;
s.from.add(start.p1 + Point2(-d,-d));
s.from.add(start.p1 + Point2(+d,+d));
s.from.add(start.p2 + Point2(-d,-d));
s.from.add(start.p2 + Point2(+d,+d));
stairs.push_back(s);
}
}
break;
}
case SVGElementType::TEXT: {
break;
}
default:
throw "should not happen!";
}
}
};
#endif // FLOORPLANFACTORYSVG_H

17
floorplan/Stair.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef STAIR_H
#define STAIR_H
#include "../geo/BBox2.h"
#include "../geo/Point2.h"
struct Stair {
/** bbox with all starting points */
BBox2 from;
/** the direction to move all the starting points to */
Point2 dir;
};
#endif // STAIR_H

11
floorplan/Stairs.h Normal file
View File

@@ -0,0 +1,11 @@
#ifndef STAIRS_H
#define STAIRS_H
#include <vector>
#include "Stair.h"
class Stairs : public std::vector<Stair> {
};
#endif // STAIRS_H