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,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