some refactoring

hopefully improved rendering speed
added support to add .obj obstacles
This commit is contained in:
2018-02-17 17:39:18 +01:00
parent 839401edb7
commit 52ab71fac5
25 changed files with 538 additions and 12 deletions

View File

@@ -0,0 +1,79 @@
#ifndef MMFLOOROBSTACLEOBJECT_H
#define MMFLOOROBSTACLEOBJECT_H
#include "MapModelElement.h"
#include "../2D/MapViewElementHelper.h"
#include "IHasMaterial.h"
#include "IHasDoorType.h"
#include "IHasParams.h"
#include "../2D/MV2DElementFloorObstacleObject.h"
#include "../3D/MV3DElementFloorObstacleObject.h"
#include <Indoor/floorplan/v2/Floorplan.h>
class MMFloorObstacleObject : public MapModelElement, public IHasParams {
public:
Floorplan::Floor* mf;
Floorplan::FloorObstacleObject* fo;
MV2DElementFloorObstacleObject mv2d;
MV3DElementFloorObstacleObject mv3d;
public:
MMFloorObstacleObject(MapLayer* parent, Floorplan::Floor* mf, Floorplan::FloorObstacleObject* fo) :
MapModelElement(parent), mf(mf), fo(fo), mv2d(fo), mv3d(mf,fo) {
}
MV2DElement* getMV2D() const override {return (MV2DElement*) &mv2d;}
MV3DElement* getMV3D() const override {return (MV3DElement*) &mv3d;}
void deleteMe() const override {
parent->removeElement(this);
mf->obstacles.erase(std::remove(mf->obstacles.begin(), mf->obstacles.end(), fo), mf->obstacles.end());
}
/** get the number of parameters */
int getNumParams() const override {
return 3;
}
/** get the description of the idx-th parameter */
virtual Param getParamDesc(const int idx) const override {
switch (idx) {
case 0: return Param("file", ParamType::STRING);
case 1: return Param("pos", ParamType::POINT3);
case 2: return Param("rot", ParamType::POINT3);
default: throw Exception("out of bounds");
}
}
/** get the idx-th param's value */
virtual ParamValue getParamValue(const int idx) const override {
switch(idx) {
case 0: return fo->file;
case 1: return fo->pos;
case 2: return fo->rot;
default: throw Exception("out of bounds");
}
}
/** set the idx-th param's value */
virtual void setParamValue(const int idx, const ParamValue& val) override {
switch (idx) {
case 0: fo->file = val.toString(); break;
case 1: fo->pos = val.toPoint3(); break;
case 2: fo->rot = val.toPoint3(); break;
default: throw Exception("out of bounds");
}
}
};
#endif // MMFLOOROBSTACLEOBJECT_H

View File

@@ -5,6 +5,7 @@
#include "MMFloorObstacleCircle.h"
#include "MMFloorObstacleLine.h"
#include "MMFloorObstacleDoor.h"
#include "MMFloorObstacleObject.h"
#include <Indoor/floorplan/v2/Floorplan.h>
@@ -28,6 +29,8 @@ public:
addElement(new MMFloorObstacleCircle(this, floor, (Floorplan::FloorObstacleCircle*)o));
} else if (dynamic_cast<Floorplan::FloorObstacleDoor*>(o)) {
addElement(new MMFloorObstacleDoor(this, floor, (Floorplan::FloorObstacleDoor*)o));
} else if (dynamic_cast<Floorplan::FloorObstacleObject*>(o)) {
addElement(new MMFloorObstacleObject(this, floor, (Floorplan::FloorObstacleObject*)o));
} else {
throw new Exception("todo: not yet implemented obstacle type");
}
@@ -84,6 +87,19 @@ public:
}
//TODO: check
MMFloorObstacleObject* createObject(Floorplan::FloorObstacleObject* obs) {
// add to underlying model
floor->obstacles.push_back(obs);
// add to myself as element
MMFloorObstacleObject* mm = new MMFloorObstacleObject(this, floor, obs);
addElement(mm);
return mm;
}
std::string getLayerName() const override {return "obstacles";}