This commit is contained in:
2016-11-29 21:29:40 +01:00
77 changed files with 1818 additions and 248 deletions

View File

@@ -14,6 +14,27 @@ class FloorplanHelper {
public:
/** align all floorplan values to the given grid size. needed for the grid factory */
static void align(Floorplan::IndoorMap* map, const int gridSize_cm) {
for (Floorplan::Floor* floor : map->floors) {
floor->atHeight = align_m(floor->atHeight, gridSize_cm);
floor->height = align_m(floor->height, gridSize_cm);
for (Floorplan::Stair* stair : floor->stairs) {
for (Floorplan::StairPart& part : ((Floorplan::StairFreeform*)stair)->parts) {
part.start.z = align_m(part.start.z, gridSize_cm);
part.end.z = align_m(part.end.z, gridSize_cm);
}
}
}
}
static inline float align_m(const float val_m, const int gridSize_cm) {
const float val_cm = val_m * 100;
const int snapped = std::round(val_cm / gridSize_cm);
const float res_cm = snapped * gridSize_cm;
return res_cm / 100.0f;
}
/** get a BBox for the whole map */
static BBox3 getBBox(const Floorplan::IndoorMap* map) {

View File

@@ -5,6 +5,7 @@
#include "Floorplan.h"
#include "../../misc/Debug.h"
#include "../../Assertions.h"
#include "../../lib/tinyxml/tinyxml2.h"
@@ -18,10 +19,15 @@ namespace Floorplan {
*/
class Reader {
private:
static constexpr const char* name = "FPReader";
public:
/** read an IndoorMap from the given XML-file */
static IndoorMap* readFromFile(const std::string& file) {
Log::add(name, "reading floorplan from file: " + file);
setlocale(LC_NUMERIC, "C");
tinyxml2::XMLDocument doc;
const tinyxml2::XMLError res = doc.LoadFile(file.c_str());
@@ -31,6 +37,7 @@ namespace Floorplan {
/** read an IndoorMap from the given XMl-string */
static IndoorMap* readFromString(const std::string& str) {
Log::add(name, "reading floorplan from string");
setlocale(LC_NUMERIC, "C");
tinyxml2::XMLDocument doc;
const tinyxml2::XMLError res = doc.Parse(str.c_str(), str.length());
@@ -54,7 +61,7 @@ namespace Floorplan {
/** parse the <map> node */
static IndoorMap* parseMap(const XMLElem* el) {
std::cout << el->Name() << std::endl;
Log::add(name, "parsing the map");
IndoorMap* map = new IndoorMap();
map->width = el->FloatAttribute("width");
map->depth = el->FloatAttribute("depth");
@@ -76,6 +83,7 @@ namespace Floorplan {
/** parse one <floor> node */
static Floor* parseFloor(const XMLElem* el) {
Floor* floor = new Floor();
Log::add(name, std::string("parsing floor ") + el->Attribute("name"));
floor->atHeight = el->FloatAttribute("atHeight");
floor->height = el->FloatAttribute("height");
floor->name = el->Attribute("name");