# HG changeset patch # User spq@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1216721056 0 # Node ID 64e7fe3d4288f4591ce108eaef5625c06e3e84d3 # Parent 214e3eb81eb21b1dbd3d34ca5553eb8569107f32 - added possibility to change instance ids - speedup instances by removing uniqueness check for ids, that means the client has to provide unique ids or live with on unique ids - added possibility to list all instances with a given id diff -r 214e3eb81eb2 -r 64e7fe3d4288 engine/core/model/structures/instance.cpp --- a/engine/core/model/structures/instance.cpp Mon Jul 21 13:46:15 2008 +0000 +++ b/engine/core/model/structures/instance.cpp Tue Jul 22 10:04:16 2008 +0000 @@ -193,6 +193,10 @@ m_changeinfo |= ICHANGE_ROTATION; } + void Instance::setId(const std::string& identifier) { + m_id = identifier; + } + void Instance::addActionListener(InstanceActionListener* listener) { initializeChanges(); m_activity->m_actionlisteners.push_back(listener); diff -r 214e3eb81eb2 -r 64e7fe3d4288 engine/core/model/structures/instance.h --- a/engine/core/model/structures/instance.h Mon Jul 21 13:46:15 2008 +0000 +++ b/engine/core/model/structures/instance.h Tue Jul 22 10:04:16 2008 +0000 @@ -90,6 +90,10 @@ */ const std::string& getId() { return m_id; } + /** Set the identifier for this instance. + */ + void setId(const std::string& identifier=""); + /** Gets object where this instance is instantiated from */ Object* getObject() { return m_object; } diff -r 214e3eb81eb2 -r 64e7fe3d4288 engine/core/model/structures/instance.i --- a/engine/core/model/structures/instance.i Mon Jul 21 13:46:15 2008 +0000 +++ b/engine/core/model/structures/instance.i Tue Jul 22 10:04:16 2008 +0000 @@ -67,6 +67,7 @@ Instance(Object* object, const Location& location, const std::string& identifier=""); virtual ~Instance(); const std::string& getId(); + void setId(const std::string& identifier=""); Object* getObject(); void setLocation(const Location& loc); Location getLocation() const; diff -r 214e3eb81eb2 -r 64e7fe3d4288 engine/core/model/structures/layer.cpp --- a/engine/core/model/structures/layer.cpp Mon Jul 21 13:46:15 2008 +0000 +++ b/engine/core/model/structures/layer.cpp Tue Jul 22 10:04:16 2008 +0000 @@ -71,14 +71,6 @@ l.setLayer(this); l.setExactLayerCoordinates(p); - if(id != "") { - std::vector::iterator it = m_instances.begin(); - for(; it != m_instances.end(); ++it) { - if((*it)->getId() == id) - throw NameClash(id); - } - } - Instance* instance = new Instance(object, l, id); m_instances.push_back(instance); m_instanceTree->addInstance(instance); @@ -101,15 +93,6 @@ Location l; l.setLayer(this); l.setExactLayerCoordinates(p); - std::string id = instance->getId(); - - if(id != "") { - std::vector::iterator it = m_instances.begin(); - for(; it != m_instances.end(); ++it) { - if((*it)->getId() == id) - throw NameClash(id); - } - } m_instances.push_back(instance); m_instanceTree->addInstance(instance); @@ -152,6 +135,16 @@ throw NotFound(id); } + std::vector Layer::getInstances(const std::string& id) { + std::vector matching_instances; + std::vector::iterator it = m_instances.begin(); + for(; it != m_instances.end(); ++it) { + if((*it)->getId() == id) + matching_instances.push_back(*it); + } + return matching_instances; + } + void Layer::getMinMaxCoordinates(ModelCoordinate& min, ModelCoordinate& max, const Layer* layer) const { if (!layer) { layer = this; diff -r 214e3eb81eb2 -r 64e7fe3d4288 engine/core/model/structures/layer.h --- a/engine/core/model/structures/layer.h Mon Jul 21 13:46:15 2008 +0000 +++ b/engine/core/model/structures/layer.h Tue Jul 22 10:04:16 2008 +0000 @@ -145,9 +145,13 @@ */ const std::vector& getInstances() const { return m_instances; } - /** Get the instance on this layer with the given identifier. + /** Get the list of instances on this layer with the given identifier. */ - Instance* getInstance(const std::string& id); + std::vector getInstances(const std::string& id); + + /** Get the first instance on this layer with the given identifier. + */ + Instance* getInstance(const std::string& identifier); /** Set object visibility */ diff -r 214e3eb81eb2 -r 64e7fe3d4288 engine/core/model/structures/layer.i --- a/engine/core/model/structures/layer.i Mon Jul 21 13:46:15 2008 +0000 +++ b/engine/core/model/structures/layer.i Tue Jul 22 10:04:16 2008 +0000 @@ -72,6 +72,7 @@ void deleteInstance(Instance* object); const std::vector& getInstances() const; + std::vector getInstances(const std::string& identifier); Instance* getInstance(const std::string& id); void setInstancesVisible(bool vis);