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/model/MMFloorStair.h
2017-07-27 18:41:48 +02:00

133 lines
3.7 KiB
C++

#ifndef MMFLOORSTAIR_H
#define MMFLOORSTAIR_H
#include "MapLayer.h"
#include "IHasParams.h"
#include "MMFloorOutlinePolygon.h"
#include "../2D/MV2DElementStair.h"
#include "../3D/MV3DElementStair.h"
#include <Indoor/floorplan/v2/Floorplan.h>
/**
* layer containing all elements describing a floor's outline
*/
class MMFloorStair : public MapModelElement, public IHasParams {
private:
/** the underlying model */
Floorplan::Floor* floor;
Floorplan::StairFreeform* stair;
MV2DElementStair mv2d;
MV3DElementStair mv3d;
public:
/** ctor with the underlying model */
MMFloorStair(MapLayer* parent, Floorplan::IndoorMap* map, Floorplan::Floor* floor, Floorplan::StairFreeform* stair) :
MapModelElement(parent), floor(floor), stair(stair), mv2d(map, floor, stair), mv3d(floor, stair) {
;
}
MV2DElement* getMV2D() const override {return (MV2DElement*) &mv2d;}
MV3DElement* getMV3D() const override {return (MV3DElement*) &mv3d;}
virtual int getNumParams() const override {
const int selPart = mv2d.getSelPart();
return (selPart >= 0) ? (3) : (0);
}
virtual Param getParamDesc(const int idx) const override {
const int selPart = mv2d.getSelPart();
const int selNode = mv2d.getSelNode();
switch(idx) {
case 0: return Param("node height", ParamType::FLOAT);
case 1: return (selPart >= 0 && selNode == 0) ? Param("part width", ParamType::FLOAT) : Param::getNA();
case 2: return (selPart >= 0 && selNode == 0) ? Param("connect", ParamType::BOOL) : Param::getNA();
}
throw 1;
}
virtual ParamValue getParamValue(const int idx) const override {
const int selPart = mv2d.getSelPart();
const int selNode = mv2d.getSelNode();
switch(idx) {
case 0: if (selPart >= 0) {return stair->parts[selPart][selNode].z;} else {return NAN;}
case 1: if (selPart >= 0) {return stair->parts[selPart].width;} else {return NAN;}
case 2: if (selPart >= 0) {return stair->parts[selPart].connectWithPrev;} else {return false;}
}
throw 1;
}
virtual void setParamValue(const int idx, const ParamValue& val) override {
const int selPart = mv2d.getSelPart();
const int selNode = mv2d.getSelNode();
switch(idx) {
case 0: if (selPart >= 0) {stair->parts[selPart][selNode].z = val.toFloat();} break;
case 1: if (selPart >= 0) {stair->parts[selPart].width = val.toFloat();} break;
case 2: if (selPart >= 0) {stair->parts[selPart].connectWithPrev = val.toBool();} break;
}
}
void deleteMe() const override {
parent->removeElement(this);
floor->stairs.erase(std::remove(floor->stairs.begin(), floor->stairs.end(), stair), floor->stairs.end());
}
// virtual int getNumParams() const override {
// return 4;
// }
// virtual Param getParamDesc(const int idx) const override {
// switch(idx) {
// case 0: return Param("center", ParamType::POINT2);
// case 1: return Param("at height", ParamType::FLOAT);
// case 2: return Param("height", ParamType::FLOAT);
// case 3: return Param("angle", ParamType::FLOAT);
// }
// throw 1;
// }
// virtual ParamValue getParamValue(const int idx) const override {
// switch(idx) {
// case 0: return stair->center;
// case 1: return stair->atHeight;
// case 2: return stair->height;
// case 3: return stair->angleDeg;
// }
// throw 1;
// }
// virtual void setParamValue(const int idx, const ParamValue& val) const override {
// switch(idx) {
// case 0: stair->center = val.toPoint2(); break;
// case 1: stair->atHeight = val.toFloat(); break;
// case 2: stair->height = val.toFloat(); break;
// case 3: stair->angleDeg = val.toFloat(); break;
// }
// }
// //TODO: check
// void create(Floorplan::FloorOutlinePolygon* poly) {
// // add to underlying model
// floor->outline.push_back(poly);
// // add to myself as element
// elements.push_back(new MMFloorOutlinePolygon(this, floor, poly));
// }
};
#endif // MMFLOORSTAIR_H