1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
#include "AasFileManager.h"
#include "itextstream.h"
#include "iarchive.h"
#include "ieclass.h"
#include "ifilesystem.h"
#include "eclass.h"
#include "module/StaticModule.h"
namespace map
{
namespace
{
const char* const AAS_TYPES_ENTITYDEF = "aas_types";
}
AasFileManager::AasFileManager() :
_typesLoaded(false)
{}
void AasFileManager::registerLoader(const IAasFileLoaderPtr& loader)
{
_loaders.insert(loader);
}
void AasFileManager::unregisterLoader(const IAasFileLoaderPtr& loader)
{
_loaders.erase(loader);
}
IAasFileLoaderPtr AasFileManager::getLoaderForStream(std::istream& stream)
{
IAasFileLoaderPtr loader;
for (const IAasFileLoaderPtr& candidate : _loaders)
{
// Rewind the stream before passing it to the format for testing
stream.seekg(0, std::ios_base::beg);
if (candidate->canLoad(stream))
{
loader = candidate;
break;
}
}
// Rewind the stream when we're done
stream.seekg(0, std::ios_base::beg);
return loader;
}
void AasFileManager::ensureAasTypesLoaded()
{
if (_typesLoaded) return;
_typesLoaded = true;
_typeList.clear();
IEntityClassPtr aasTypesClass = GlobalEntityClassManager().findClass(AAS_TYPES_ENTITYDEF);
if (aasTypesClass)
{
eclass::AttributeList list = eclass::getSpawnargsWithPrefix(aasTypesClass, "type");
for (const EntityClassAttribute& attr : list)
{
AasType type;
type.entityDefName = attr.getValue();
IEntityClassPtr aasType = GlobalEntityClassManager().findClass(type.entityDefName);
if (!aasType)
{
rWarning() << "Could not find entityDef for AAS type " << type.entityDefName <<
" mentioned in " << AAS_TYPES_ENTITYDEF << " entityDef." << std::endl;
continue;
}
type.fileExtension = aasType->getAttributeValue("fileExtension");
_typeList.push_back(type);
}
}
}
AasTypeList AasFileManager::getAasTypes()
{
ensureAasTypesLoaded();
return _typeList;
}
AasType AasFileManager::getAasTypeByName(const std::string& typeName)
{
ensureAasTypesLoaded();
for (AasType& type : _typeList)
{
if (type.entityDefName == typeName)
{
return type;
}
}
throw std::runtime_error("Could not find AAS type " + typeName);
}
std::list<AasFileInfo> AasFileManager::getAasFilesForMap(const std::string& mapPath)
{
std::list<AasFileInfo> list;
AasTypeList types = getAasTypes();
for (const AasType& type : types)
{
std::string path = mapPath;
// Cut off the extension
path = path.substr(0, path.rfind('.'));
path += "." + type.fileExtension;
ArchiveTextFilePtr file = GlobalFileSystem().openTextFileInAbsolutePath(path);
if (file)
{
// Add this file to the list
list.push_back(AasFileInfo());
list.back().absolutePath = path;
list.back().type = type;
}
}
return list;
}
const std::string& AasFileManager::getName() const
{
static std::string _name(MODULE_AASFILEMANAGER);
return _name;
}
const StringSet& AasFileManager::getDependencies() const
{
static StringSet _dependencies;
if (_dependencies.empty())
{
_dependencies.insert(MODULE_VIRTUALFILESYSTEM);
_dependencies.insert(MODULE_ECLASSMANAGER);
}
return _dependencies;
}
void AasFileManager::initialiseModule(const IApplicationContext& ctx)
{
}
// Define the static AasFileManager module
module::StaticModuleRegistration<AasFileManager> aasFileManagerModule;
}
|