Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+222
@@ -0,0 +1,222 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Construction of MapObjects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
// Own
|
||||
#include "object_factory.h"
|
||||
#include <MapImpl/abstract_map_object_impl.h>
|
||||
#include <MapImpl/map_impl.h>
|
||||
|
||||
|
||||
// ESRI
|
||||
|
||||
|
||||
// Qt
|
||||
#include <QCoreApplication>
|
||||
|
||||
|
||||
namespace SituationMap
|
||||
{
|
||||
|
||||
static FactoryMap &factoryMap()
|
||||
{
|
||||
static FactoryMap s_factoryMap;
|
||||
return s_factoryMap;
|
||||
}
|
||||
|
||||
static void cleanupFactoryMap()
|
||||
{
|
||||
// stored objects will be deleted by QSharedPointer:
|
||||
factoryMap().clear();
|
||||
}
|
||||
|
||||
FactoryMap &MapSingleton::getFactoryMap()
|
||||
{
|
||||
if (factoryMap().isEmpty())
|
||||
qAddPostRoutine(cleanupFactoryMap);
|
||||
|
||||
return factoryMap();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void ObjectFactory::setObjectContainer(const QSharedPointer<ObjectContainer> &objectContainer)
|
||||
{
|
||||
m_objectContainer = objectContainer;
|
||||
}
|
||||
|
||||
|
||||
bool ObjectFactory::initMapObject(AbstractMapObject *obj, Map *map, UniqueMapId uid, const QString &logicalLayerName)
|
||||
{
|
||||
bool success = false;
|
||||
if (obj && map)
|
||||
{
|
||||
AbstractMapObjectImpl *objImpl = dynamic_cast<AbstractMapObjectImpl *>(obj);
|
||||
MapImpl *mapImpl = dynamic_cast<MapImpl *>(map);
|
||||
if (objImpl)
|
||||
{
|
||||
success = objImpl->init(mapImpl, logicalLayerName);
|
||||
if (!success)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " obj->init() failed";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_objectContainer)
|
||||
{
|
||||
UniqueMapId uniqueId = m_objectContainer->insertObject(objImpl,uid);
|
||||
objImpl->setUniqueId(uniqueId);
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << " insertObject: "
|
||||
<< " uniqueId='" << uniqueId << "'"
|
||||
<< " countObjects=" << m_objectContainer->countObjects()
|
||||
<< " debugInfo='" << obj->debugInfo() << "'"
|
||||
<< " logicalLayerName='" << logicalLayerName << "'";
|
||||
}
|
||||
else
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " no objectContainer";
|
||||
|
||||
// apply symbolScale:
|
||||
objImpl->setScale(map->symbolScale());
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " initMapObject failed";
|
||||
return success;
|
||||
} // ObjectFactory::initMapObject
|
||||
|
||||
AbstractMapObject *ObjectFactory::idToMapObject(const UniqueMapId &uniqueId) const
|
||||
{
|
||||
if (m_objectContainer)
|
||||
{
|
||||
// if objectContainer stores type 'Referenced':
|
||||
// obj = dynamic_cast<AbstractMapObject*> ( m_objectContainer->getObject(uniqueId) );
|
||||
// or use static_cast to speed up.
|
||||
|
||||
return m_objectContainer->getObject(uniqueId);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
std::type_index ObjectFactory::interfaceToImplementation(const std::type_index &interface_IN, bool *bOk)
|
||||
{
|
||||
// 1. INTERFACE_TYPE -> GenericObjectFactory<IMPL_TYPE> -> type_index(IMPL_TYPE) via getFactoryMap
|
||||
const std::type_index &keyRequestedInterface = interface_IN;
|
||||
const QLatin1String name(interface_IN.name());
|
||||
|
||||
// DEBUG_LOG(m_logger) << LOGFUNCTION << " IFtype=" << name ;
|
||||
|
||||
if (MapSingleton::getFactoryMap().contains(keyRequestedInterface))
|
||||
{
|
||||
if (bOk)
|
||||
*bOk = true;
|
||||
return MapSingleton::getFactoryMap().value(keyRequestedInterface)->getTypeIndexOfImplementation();
|
||||
}
|
||||
return std::type_index(typeid(this)); // at least one parameter is expected :-(
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ObjectFactory::isUniqueIdValid(const UniqueMapId &uniqueMapId)
|
||||
{
|
||||
return isUniqueMapIdValid(uniqueMapId);
|
||||
} // ObjectFactory::isUniqueIdValid
|
||||
|
||||
qint32 ObjectFactory::count() const
|
||||
{
|
||||
if (m_objectContainer)
|
||||
return m_objectContainer->countObjects();
|
||||
FATAL_LOG(m_logger) << LOGFUNCTION
|
||||
<< " no objectContainer!!!";
|
||||
return -1;
|
||||
}
|
||||
|
||||
QList<RefPointer<AbstractMapObject> > ObjectFactory::getAllObjects() const
|
||||
{
|
||||
if (m_objectContainer)
|
||||
{
|
||||
const QList<ObjectContainer::Object *> objList = m_objectContainer->getAllObjects();
|
||||
|
||||
QList<RefPointer<AbstractMapObject> > refPtrList;
|
||||
refPtrList.reserve(objList.size());
|
||||
for (ObjectContainer::Object *obj : objList)
|
||||
refPtrList.append(RefPointer<AbstractMapObject>(obj));
|
||||
return refPtrList;
|
||||
}
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION
|
||||
<< " no objectContainer!!!";
|
||||
|
||||
return QList<RefPointer<AbstractMapObject> > ();
|
||||
}
|
||||
|
||||
QList<UniqueMapId> ObjectFactory::getAllKeys() const
|
||||
{
|
||||
if (m_objectContainer)
|
||||
return m_objectContainer->getAllKeys();
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION
|
||||
<< " no objectContainer!!!";
|
||||
|
||||
return QList<UniqueMapId> ();
|
||||
}
|
||||
|
||||
bool ObjectFactory::contains(const UniqueMapId &uniqueMapId) const
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START, requested for uniqueMapId=" << uniqueMapId;
|
||||
|
||||
if (m_objectContainer)
|
||||
return m_objectContainer->containsObject(uniqueMapId);
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " no objectContainer!!!";
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END, requested for uniqueMapId=" << uniqueMapId;
|
||||
return false;
|
||||
} // ObjectFactory::contains
|
||||
|
||||
|
||||
|
||||
RefPointer<AbstractMapObject> ObjectFactory::get(const UniqueMapId &uniqueMapId) const
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " get requested for uniqueMapId=" << uniqueMapId;
|
||||
|
||||
// lookup in internal container:
|
||||
if (m_objectContainer)
|
||||
{
|
||||
AbstractMapObject *mapObj = idToMapObject(uniqueMapId);
|
||||
if (!mapObj)
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " Requested object for uniqueMapId=" << uniqueMapId << " doesn't exist.";
|
||||
return RefPointer<AbstractMapObject>(mapObj);
|
||||
}
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " no objectContainer!!!";
|
||||
return RefPointer<AbstractMapObject>();
|
||||
}
|
||||
|
||||
void ObjectFactory::clearObjects()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
|
||||
if (m_objectContainer)
|
||||
m_objectContainer->clear();
|
||||
else
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " no objectContainer!!!";
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
}
|
||||
|
||||
void ObjectFactory::clearRegister()
|
||||
{
|
||||
// stored objects will be deleted by QSharedPointer:
|
||||
MapSingleton::getFactoryMap().clear();
|
||||
}
|
||||
|
||||
bool ObjectFactory::isMapReady() const
|
||||
{
|
||||
return m_map && m_map->isReady();
|
||||
}
|
||||
|
||||
|
||||
} // namespace SituationMap
|
||||
Reference in new issue
Block a user