added support for meta-data editing improved element selection changed zooming fixed some issues with layer events fixed issue with 3D outline fixed loading issue for old maps some interface changes
180 lines
4.1 KiB
C++
180 lines
4.1 KiB
C++
#ifndef MAPLAYER_H
|
|
#define MAPLAYER_H
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <algorithm>
|
|
|
|
#include "MapLayerListener.h"
|
|
|
|
class MapModelElement;
|
|
|
|
|
|
enum class MapLayerType {
|
|
UNKNOWN,
|
|
ROOT,
|
|
FLOORS,
|
|
FLOOR,
|
|
FLOOR_GROUND,
|
|
FLOOR_OBSTACLES,
|
|
FLOOR_BEACONS,
|
|
FLOOR_ACCESS_POINTS,
|
|
FLOOR_ELEVATORS,
|
|
FLOOR_UNDERLAYS,
|
|
FLOOR_POIS,
|
|
FLOOR_STAIRS,
|
|
};
|
|
|
|
|
|
|
|
class MapLayer {
|
|
|
|
/** this layer's elements */
|
|
std::vector<MapModelElement*> elements;
|
|
|
|
/** attached listeners (if any) */
|
|
std::vector<MapLayerListener*> listeners;
|
|
|
|
protected:
|
|
|
|
/** this layer's parent */
|
|
MapLayer* parent;
|
|
|
|
/** this layer's sublayers */
|
|
std::vector<MapLayer*> sublayers;
|
|
|
|
/** this layer's type */
|
|
MapLayerType type;
|
|
|
|
/** whether this layer is visible */
|
|
bool visible;
|
|
|
|
public:
|
|
|
|
/** ctor */
|
|
MapLayer(MapLayer* parent) : parent(parent), type(MapLayerType::UNKNOWN), visible(true) {
|
|
if (parent) {parent->addSublayer(this);} // attach myself as child of my parent
|
|
}
|
|
|
|
/** ctor */
|
|
MapLayer(MapLayer* parent, MapLayerType type) : parent(parent), type(type), visible(true) {
|
|
if (parent) {parent->addSublayer(this);} // attach myself as child of my parent
|
|
}
|
|
|
|
/** dtor */
|
|
virtual ~MapLayer() {;}
|
|
|
|
/** attach a listener to this layer [usually only added to the root layer] */
|
|
void addListener(MapLayerListener* listener) {
|
|
listeners.push_back(listener);
|
|
}
|
|
|
|
/** get the layer's parent */
|
|
MapLayer* getParent() const {return parent;}
|
|
|
|
/** get the layer's name */
|
|
virtual std::string getLayerName() const = 0;
|
|
|
|
/** get the layer's type */
|
|
MapLayerType getLayerType() const {return type;}
|
|
|
|
|
|
/** get all elements within this layer */
|
|
const std::vector<MapModelElement*>& getElements() const {return elements;}
|
|
|
|
/** get all elements within this layer */
|
|
size_t getNumElements() const {return elements.size();}
|
|
|
|
/** remove the given element from the elements list */
|
|
void removeElement(const MapModelElement* elem) {
|
|
elements.erase(std::remove(elements.begin(), elements.end(), elem), elements.end());
|
|
onElemRemoved(elem);
|
|
}
|
|
|
|
/** add a new element to this layer */
|
|
void addElement(MapModelElement* el) {
|
|
elements.push_back(el);
|
|
onElemAdded(el);
|
|
}
|
|
|
|
/** remove the given sublayer from this layer */
|
|
void removeSublayer(const MapLayer* layer) { sublayers.erase(std::remove(sublayers.begin(), sublayers.end(), layer), sublayers.end()); }
|
|
|
|
/** is this layer currently visible? */
|
|
bool isVisible() const {return visible;}
|
|
|
|
/** make this layer visible */
|
|
void setVisible(const bool visible) {
|
|
this->visible = visible;
|
|
onVisibilityChanged(visible);
|
|
}
|
|
|
|
|
|
/** get all sub-layers within this layer */
|
|
const std::vector<MapLayer*>& getSubLayers() const {return sublayers;}
|
|
|
|
|
|
/** helper method to get all elements and those of all sub-layers */
|
|
void getVisibleElementsRecursive(std::vector<MapModelElement*>& el) {
|
|
if (isVisible()) {
|
|
const std::vector<MapModelElement*> local = getElements();
|
|
el.insert(el.end(), local.begin(), local.end());
|
|
for (MapLayer* sub : getSubLayers()) {
|
|
sub->getVisibleElementsRecursive(el);
|
|
}
|
|
}
|
|
}
|
|
|
|
public:
|
|
|
|
/** add a new sublayer to this layer */
|
|
void addSublayer(MapLayer* ml) {
|
|
|
|
// sanity check before adding
|
|
if (std::find(sublayers.begin(), sublayers.end(), ml) != sublayers.end()) {throw "layer already present!";}
|
|
sublayers.push_back(ml);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
void onElemAdded(MapModelElement* e) {
|
|
if (parent) {parent->onElemAdded(e);}
|
|
for (MapLayerListener* listener : listeners) {
|
|
listener->onLayerChanged(this);
|
|
listener->onLayerElementAdded(this, e);
|
|
}
|
|
}
|
|
|
|
void onElemRemoved(const MapModelElement* e) {
|
|
if (parent) {parent->onElemRemoved(e);}
|
|
for (MapLayerListener* listener : listeners) {
|
|
listener->onLayerChanged(this);
|
|
listener->onLayerElementRemoved(this, e);
|
|
}
|
|
}
|
|
|
|
void onVisibilityChanged(const bool visibile) {
|
|
if (parent) {parent->onVisibilityChanged(visibile);}
|
|
for (MapLayerListener* listener : listeners) {
|
|
listener->onLayerChanged(this);
|
|
listener->onLayerVisibilityChanged(this, visibile);
|
|
}
|
|
}
|
|
|
|
};
|
|
|
|
|
|
class MapLayerRoot : public MapLayer {
|
|
|
|
public:
|
|
|
|
MapLayerRoot(MapLayer* parent) : MapLayer(parent, MapLayerType::ROOT) {;}
|
|
|
|
std::string getLayerName() const override {return "root";}
|
|
|
|
};
|
|
|
|
|
|
#endif // MAPLAYER_H
|