Starting to clean out constants.h file by moving constants into the relevant classes

This commit is contained in:
Alexander Bock
2015-05-20 16:32:28 +02:00
parent 2bb2b906ff
commit 4de4c015d7
17 changed files with 140 additions and 162 deletions

View File

@@ -31,6 +31,26 @@ namespace openspace {
class ConfigurationManager : public ghoul::Dictionary {
public:
static const std::string KeyPaths;
static const std::string KeyCache;
static const std::string KeyCachePath;
static const std::string KeyFonts;
static const std::string KeyConfigSgct;
static const std::string KeyLuaDocumentationType;
static const std::string KeyLuaDocumentationFile;
static const std::string KeyPropertyDocumentationType;
static const std::string KeyPropertyDocumentationFile;
static const std::string KeyConfigScene;
static const std::string KeyEnableGui;
static const std::string KeyStartupScript;
static const std::string KeySettingsScript;
static const std::string KeySpiceTimeKernel;
static const std::string KeySpiceLeapsecondKernel;
static const std::string KeyLogLevel;
static const std::string KeyLogImmediateFlush;
static const std::string KeyLogs;
static const std::string KeyDisableMasterRendering;
bool loadFromFile(const std::string& filename);
private:

View File

@@ -78,14 +78,12 @@ public:
void setBody(std::string& body);
protected:
std::string findPath(const std::string& path);
void setPscUniforms(ghoul::opengl::ProgramObject* program, const Camera* camera, const PowerScaledCoordinate& position);
private:
properties::BoolProperty _enabled;
PowerScaledScalar boundingSphere_;
std::string _relativePath;
std::string _startTime;
std::string _endTime;
std::string _targetBody;

View File

@@ -51,6 +51,10 @@ public:
};
static std::string RootNodeName;
static const std::string KeyName;
static const std::string KeyParentName;
static const std::string KeyDependencies;
SceneGraphNode();
~SceneGraphNode();

View File

@@ -36,37 +36,15 @@ namespace fonts {
const std::string keyLight = "Light";
} // namespace fonts
namespace configurationmanager {
const std::string keyPaths = "Paths";
const std::string keyCache = "CACHE";
const std::string keyCachePath = keyPaths + "." + keyCache;
const std::string keyFonts = "Fonts";
const std::string keyConfigSgct = "SGCTConfig";
const std::string keyLuaDocumentationType = "LuaDocumentationFile.Type";
const std::string keyLuaDocumentationFile = "LuaDocumentationFile.File";
const std::string keyPropertyDocumentationType = "PropertyDocumentationFile.Type";
const std::string keyPropertyDocumentationFile = "PropertyDocumentationFile.File";
const std::string keyConfigScene = "Scene";
const std::string keyEnableGui = "EnableGUI";
const std::string keyStartupScript = "StartupScripts";
const std::string keySettingsScript = "SettingsScripts";
const std::string keySpiceTimeKernel = "SpiceKernel.Time";
const std::string keySpiceLeapsecondKernel = "SpiceKernel.LeapSecond";
const std::string keyLogLevel = "Logging.LogLevel";
const std::string keyLogImmediateFlush = "Logging.ImmediateFlush";
const std::string keyLogs = "Logging.Logs";
const std::string keyDisableMasterRendering = "DisableRenderingOnMaster";
} // namespace configurationmanager
namespace scenegraph {
const std::string keyPathScene = "ScenePath";
const std::string keyCommonFolder = "CommonFolder";
const std::string keyModules = "Modules";
const std::string keyCamera = "Camera";
const std::string keyFocusObject = "Focus";
const std::string keyPositionObject = "Position";
const std::string keyViewOffset = "Offset";
const std::string keyPathModule = "ModulePath";
// const std::string keyPathScene = "ScenePath";
//const std::string keyCommonFolder = "CommonFolder";
// const std::string keyModules = "Modules";
// const std::string keyCamera = "Camera";
// const std::string keyFocusObject = "Focus";
// const std::string keyPositionObject = "Position";
// const std::string keyViewOffset = "Offset";
// const std::string keyPathModule = "ModulePath";
} // namespace scenegraph
namespace scenegraphnode {

View File

@@ -39,9 +39,28 @@ namespace {
namespace openspace {
const std::string ConfigurationManager::KeyPaths = "Paths";
const std::string ConfigurationManager::KeyCache = "CACHE";
const std::string ConfigurationManager::KeyCachePath = KeyPaths + "." + KeyCache;
const std::string ConfigurationManager::KeyFonts = "Fonts";
const std::string ConfigurationManager::KeyConfigSgct = "SGCTConfig";
const std::string ConfigurationManager::KeyLuaDocumentationType = "LuaDocumentationFile.Type";
const std::string ConfigurationManager::KeyLuaDocumentationFile = "LuaDocumentationFile.File";
const std::string ConfigurationManager::KeyPropertyDocumentationType = "PropertyDocumentationFile.Type";
const std::string ConfigurationManager::KeyPropertyDocumentationFile = "PropertyDocumentationFile.File";
const std::string ConfigurationManager::KeyConfigScene = "Scene";
const std::string ConfigurationManager::KeyEnableGui = "EnableGUI";
const std::string ConfigurationManager::KeyStartupScript = "StartupScripts";
const std::string ConfigurationManager::KeySettingsScript = "SettingsScripts";
const std::string ConfigurationManager::KeySpiceTimeKernel = "SpiceKernel.Time";
const std::string ConfigurationManager::KeySpiceLeapsecondKernel = "SpiceKernel.LeapSecond";
const std::string ConfigurationManager::KeyLogLevel = "Logging.LogLevel";
const std::string ConfigurationManager::KeyLogImmediateFlush = "Logging.ImmediateFlush";
const std::string ConfigurationManager::KeyLogs = "Logging.Logs";
const std::string ConfigurationManager::KeyDisableMasterRendering = "DisableRenderingOnMaster";
bool ConfigurationManager::loadFromFile(const std::string& filename) {
using ghoul::filesystem::FileSystem;
using constants::configurationmanager::keyPaths;
if (!FileSys.fileExists(filename)) {
LERROR("Could not find file '" << filename << "'");
return false;
@@ -65,9 +84,9 @@ bool ConfigurationManager::loadFromFile(const std::string& filename) {
// Register all the paths
ghoul::Dictionary dictionary;
const bool success = getValue(keyPaths, dictionary);
const bool success = getValue(KeyPaths, dictionary);
if (!success) {
LERROR("Configuration does not contain the key '" << keyPaths << "'");
LERROR("Configuration does not contain the key '" << KeyPaths << "'");
return false;
}
@@ -94,17 +113,17 @@ bool ConfigurationManager::loadFromFile(const std::string& filename) {
// Remove the Paths dictionary from the configuration manager as those paths might
// change later and we don't want to be forced to keep our local copy up to date
removeKey(keyPaths);
removeKey(KeyPaths);
return true;
}
bool ConfigurationManager::checkCompleteness() const {
std::vector<std::string> requiredTokens = {
constants::configurationmanager::keyPaths,
constants::configurationmanager::keyCachePath,
constants::configurationmanager::keyFonts,
constants::configurationmanager::keyConfigSgct
KeyPaths,
KeyCachePath,
KeyFonts,
KeyConfigSgct
};
bool totalSuccess = true;

View File

@@ -223,7 +223,7 @@ bool OpenSpaceEngine::create(
}
// Create the cachemanager
FileSys.createCacheManager(absPath("${" + constants::configurationmanager::keyCache + "}"), CacheVersion);
FileSys.createCacheManager(absPath("${" + ConfigurationManager::KeyCache + "}"), CacheVersion);
_engine->_console->initialize();
ImageSequencer2::initialize();
@@ -237,7 +237,7 @@ bool OpenSpaceEngine::create(
LDEBUG("Determining SGCT configuration file");
std::string sgctConfigurationPath = _sgctDefaultConfigFile;
_engine->configurationManager()->getValue(
constants::configurationmanager::keyConfigSgct, sgctConfigurationPath);
ConfigurationManager::KeyConfigSgct, sgctConfigurationPath);
if (!commandlineArgumentPlaceholders.sgctConfigurationName.empty()) {
LDEBUG("Overwriting SGCT configuration file with commandline argument: " <<
@@ -299,15 +299,13 @@ bool OpenSpaceEngine::initialize() {
scriptEngine()->initialize();
// If a LuaDocumentationFile was specified, generate it now
using constants::configurationmanager::keyLuaDocumentationType;
using constants::configurationmanager::keyLuaDocumentationFile;
const bool hasType = configurationManager()->hasKey(keyLuaDocumentationType);
const bool hasFile = configurationManager()->hasKey(keyLuaDocumentationFile);
const bool hasType = configurationManager()->hasKey(ConfigurationManager::KeyLuaDocumentationType);
const bool hasFile = configurationManager()->hasKey(ConfigurationManager::KeyLuaDocumentationFile);
if (hasType && hasFile) {
std::string luaDocumentationType;
configurationManager()->getValue(keyLuaDocumentationType, luaDocumentationType);
configurationManager()->getValue(ConfigurationManager::KeyLuaDocumentationType, luaDocumentationType);
std::string luaDocumentationFile;
configurationManager()->getValue(keyLuaDocumentationFile, luaDocumentationFile);
configurationManager()->getValue(ConfigurationManager::KeyLuaDocumentationFile, luaDocumentationFile);
luaDocumentationFile = absPath(luaDocumentationFile);
_scriptEngine->writeDocumentation(luaDocumentationFile, luaDocumentationType);
@@ -315,7 +313,7 @@ bool OpenSpaceEngine::initialize() {
bool disableMasterRendering = false;
configurationManager()->getValue(
constants::configurationmanager::keyDisableMasterRendering, disableMasterRendering);
ConfigurationManager::KeyDisableMasterRendering, disableMasterRendering);
_renderEngine->setDisableRenderingOnMaster(disableMasterRendering);
@@ -333,7 +331,7 @@ bool OpenSpaceEngine::initialize() {
std::string sceneDescriptionPath;
success = configurationManager()->getValue(
constants::configurationmanager::keyConfigScene, sceneDescriptionPath);
ConfigurationManager::KeyConfigScene, sceneDescriptionPath);
if (success)
sceneGraph->scheduleLoadSceneFile(sceneDescriptionPath);
@@ -419,11 +417,11 @@ bool OpenSpaceEngine::findConfiguration(std::string& filename) {
bool OpenSpaceEngine::loadSpiceKernels() {
// Load time kernel
using constants::configurationmanager::keySpiceTimeKernel;
std::string timeKernel;
bool success = configurationManager()->getValue(keySpiceTimeKernel, timeKernel);
bool success = configurationManager()->getValue(ConfigurationManager::KeySpiceTimeKernel, timeKernel);
// Move this to configurationmanager::completenesscheck ---abock
if (!success) {
LERROR("Configuration file does not contain a '" << keySpiceTimeKernel << "'");
LERROR("Configuration file does not contain a '" << ConfigurationManager::KeySpiceTimeKernel << "'");
return false;
}
SpiceManager::KernelIdentifier id =
@@ -434,11 +432,11 @@ bool OpenSpaceEngine::loadSpiceKernels() {
}
// Load SPICE leap second kernel
using constants::configurationmanager::keySpiceLeapsecondKernel;
std::string leapSecondKernel;
success = configurationManager()->getValue(keySpiceLeapsecondKernel, leapSecondKernel);
success = configurationManager()->getValue(ConfigurationManager::KeySpiceLeapsecondKernel, leapSecondKernel);
if (!success) {
LERROR("Configuration file does not have a '" << keySpiceLeapsecondKernel << "'");
// Move this to configurationmanager::completenesscheck ---abock
LERROR("Configuration file does not have a '" << ConfigurationManager::KeySpiceLeapsecondKernel << "'");
return false;
}
id = SpiceManager::ref().loadKernel(std::move(leapSecondKernel));
@@ -472,14 +470,14 @@ void OpenSpaceEngine::runScripts(const ghoul::Dictionary& scripts) {
void OpenSpaceEngine::runStartupScripts() {
ghoul::Dictionary scripts;
configurationManager()->getValue(
constants::configurationmanager::keyStartupScript, scripts);
ConfigurationManager::KeyStartupScript, scripts);
runScripts(scripts);
}
void OpenSpaceEngine::runSettingsScripts() {
ghoul::Dictionary scripts;
configurationManager()->getValue(
constants::configurationmanager::keySettingsScript, scripts);
ConfigurationManager::KeySettingsScript, scripts);
runScripts(scripts);
}
@@ -488,7 +486,7 @@ void OpenSpaceEngine::loadFonts() {
sgct_text::FontManager::FontPath local = sgct_text::FontManager::FontPath::FontPath_Local;
ghoul::Dictionary fonts;
configurationManager()->getValue(constants::configurationmanager::keyFonts, fonts);
configurationManager()->getValue(ConfigurationManager::KeyFonts, fonts);
for (const std::string& key : fonts.keys()) {
std::string font;
@@ -505,18 +503,12 @@ void OpenSpaceEngine::loadFonts() {
}
void OpenSpaceEngine::configureLogging() {
using constants::configurationmanager::keyLogLevel;
using constants::configurationmanager::keyLogs;
if (configurationManager()->hasKeyAndValue<std::string>(keyLogLevel)) {
using constants::configurationmanager::keyLogLevel;
using constants::configurationmanager::keyLogImmediateFlush;
if (configurationManager()->hasKeyAndValue<std::string>(ConfigurationManager::KeyLogLevel)) {
std::string logLevel;
configurationManager()->getValue(keyLogLevel, logLevel);
configurationManager()->getValue(ConfigurationManager::KeyLogLevel, logLevel);
bool immediateFlush = false;
configurationManager()->getValue(keyLogImmediateFlush, immediateFlush);
configurationManager()->getValue(ConfigurationManager::KeyLogImmediateFlush, immediateFlush);
LogManager::LogLevel level = LogManager::levelFromString(logLevel);
LogManager::deinitialize();
@@ -524,9 +516,9 @@ void OpenSpaceEngine::configureLogging() {
LogMgr.addLog(new ConsoleLog);
}
if (configurationManager()->hasKeyAndValue<ghoul::Dictionary>(keyLogs)) {
if (configurationManager()->hasKeyAndValue<ghoul::Dictionary>(ConfigurationManager::KeyLogs)) {
ghoul::Dictionary logs;
configurationManager()->getValue(keyLogs, logs);
configurationManager()->getValue(ConfigurationManager::KeyLogs, logs);
for (size_t i = 1; i <= logs.size(); ++i) {
ghoul::Dictionary logInfo;

View File

@@ -76,23 +76,24 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
std::string name;
bool success = dictionary.getValue(constants::scenegraphnode::keyName, name);
ghoul_assert(success, "Name was not passed to RenderableModel");
std::string path;
success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
ghoul_assert(success, "Module path was not passed to RenderableModel");
//std::string path;
//success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
// ghoul_assert(success, "Module path was not passed to RenderableModel");
ghoul::Dictionary geometryDictionary;
success = dictionary.getValue(
constants::renderablemodel::keyGeometry, geometryDictionary);
if (success) {
geometryDictionary.setValue(constants::scenegraphnode::keyName, name);
geometryDictionary.setValue(constants::scenegraph::keyPathModule, path);
//geometryDictionary.setValue(constants::scenegraph::keyPathModule, path);
_geometry = modelgeometry::ModelGeometry::createFromDictionary(geometryDictionary);
}
std::string texturePath = "";
success = dictionary.getValue("Textures.Color", texturePath);
if (success)
_colorTexturePath = path + "/" + texturePath;
//_colorTexturePath = /*path + "/"*/ + texturePath;
_colorTexturePath = absPath(texturePath);
addPropertySubOwner(_geometry);

View File

@@ -71,8 +71,8 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
ghoul_assert(success,
"RenderablePlanet need the '" <<constants::scenegraphnode::keyName<<"' be specified");
std::string path;
success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
//std::string path;
//success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
//ghoul_assert(success,
// "RenderablePlanet need the '"<<constants::scenegraph::keyPathModule<<"' be specified");
@@ -93,9 +93,8 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
// as the requirements are fixed (ab)
std::string texturePath = "";
success = dictionary.getValue("Textures.Color", texturePath);
_colorTexturePath = absPath(texturePath);
if (success)
_colorTexturePath = path + "/" + texturePath;
_colorTexturePath = absPath(texturePath);
std::string nightTexturePath = "";
dictionary.getValue("Textures.Night", nightTexturePath);
@@ -103,7 +102,6 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
if (nightTexturePath != ""){
_hasNightTexture = true;
_nightTexturePath = absPath(nightTexturePath);
_nightTexturePath = path + "/" + nightTexturePath;
}
addPropertySubOwner(_geometry);

View File

@@ -103,18 +103,13 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
bool success = dictionary.getValue(constants::scenegraphnode::keyName, name);
ghoul_assert(success, "");
std::string path;
success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
ghoul_assert(success, "");
_defaultProjImage = path + "/textures/defaultProj.png";
_defaultProjImage = absPath("textures/defaultProj.png");
ghoul::Dictionary geometryDictionary;
success = dictionary.getValue(
keyGeometry, geometryDictionary);
if (success) {
geometryDictionary.setValue(constants::scenegraphnode::keyName, name);
geometryDictionary.setValue(constants::scenegraph::keyPathModule, path);
_geometry = planetgeometryprojection::PlanetGeometryProjection::createFromDictionary(geometryDictionary);
}
@@ -158,11 +153,11 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
std::string texturePath = "";
success = dictionary.getValue("Textures.Color", texturePath);
if (success){
_colorTexturePath = path + "/" + texturePath;
_colorTexturePath = absPath(texturePath);
}
success = dictionary.getValue("Textures.Project", texturePath);
if (success){
_projectionTexturePath = path + "/" + texturePath;
_projectionTexturePath = absPath(texturePath);
}
addPropertySubOwner(_geometry);
addProperty(_rotation);
@@ -520,7 +515,7 @@ void RenderablePlanetProjection::loadTexture(){
delete _texture;
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
_texture = ghoul::io::TextureReader::ref().loadTexture(_colorTexturePath);
if (_texture) {
_texture->uploadTexture();
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
@@ -529,7 +524,7 @@ void RenderablePlanetProjection::loadTexture(){
delete _textureOriginal;
_textureOriginal = nullptr;
if (_colorTexturePath.value() != "") {
_textureOriginal = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
_textureOriginal = ghoul::io::TextureReader::ref().loadTexture(_colorTexturePath);
if (_textureOriginal) {
_textureOriginal->uploadTexture();
_textureOriginal->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
@@ -538,7 +533,7 @@ void RenderablePlanetProjection::loadTexture(){
delete _textureWhiteSquare;
_textureWhiteSquare = nullptr;
if (_colorTexturePath.value() != "") {
_textureWhiteSquare = ghoul::io::TextureReader::ref().loadTexture(absPath(_defaultProjImage));
_textureWhiteSquare = ghoul::io::TextureReader::ref().loadTexture(_defaultProjImage);
if (_textureWhiteSquare) {
_textureWhiteSquare->uploadTexture();
_textureWhiteSquare->setFilter(ghoul::opengl::Texture::FilterMode::Linear);

View File

@@ -85,15 +85,6 @@ Renderable::Renderable(const ghoul::Dictionary& dictionary)
"Scenegraphnode need to specify '" << constants::scenegraphnode::keyName
<< "' because renderables is going to use this for debugging!");
#endif
// get path if available
bool success = dictionary.getValue(constants::scenegraph::keyPathModule, _relativePath);
#ifndef NDEBUG
ghoul_assert(success,
"Scenegraphnode need to specify '" << constants::scenegraph::keyPathModule
<< "' because renderables is going to use this for debugging!");
#endif
if (success)
_relativePath += ghoul::filesystem::FileSystem::PathSeparator;
dictionary.getValue(keyStart, _startTime);
dictionary.getValue(keyEnd, _endTime);
@@ -121,20 +112,6 @@ void Renderable::update(const UpdateData&)
{
}
std::string Renderable::findPath(const std::string& path) {
std::string tmp = absPath(path);
if(FileSys.fileExists(tmp))
return tmp;
tmp = absPath(_relativePath + path);
if(FileSys.fileExists(tmp))
return tmp;
LERROR("Could not find file '" << path << "'");
return "";
}
void Renderable::setPscUniforms(
ghoul::opengl::ProgramObject* program,
const Camera* camera,

View File

@@ -91,7 +91,7 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
std::string texturePath = "";
bool success = dictionary.getValue("Texture", texturePath);
if (success) {
_texturePath = findPath(texturePath);
_texturePath = absPath(texturePath);
_textureFile = new ghoul::filesystem::File(_texturePath);
}

View File

@@ -67,7 +67,7 @@ RenderablePlaneProjection::RenderablePlaneProjection(const ghoul::Dictionary& di
std::string texturePath = "";
bool success = dictionary.getValue(keyTexture, _texturePath);
if (success) {
_texturePath = findPath(_texturePath);
_texturePath = absPath(_texturePath);
_textureFile = new ghoul::filesystem::File(_texturePath);
}

View File

@@ -61,11 +61,6 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary)
, _sphere(nullptr)
, _sphereIsDirty(false)
{
std::string path;
bool success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
ghoul_assert(success,
"RenderablePlanet need the '" << constants::scenegraph::keyPathModule << "' be specified");
if (dictionary.hasKeyAndValue<glm::vec2>(keySize)) {
glm::vec2 size;
dictionary.getValue(keySize, size);
@@ -81,7 +76,7 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary)
if (dictionary.hasKeyAndValue<std::string>(keyTexture)) {
std::string texture;
dictionary.getValue(keyTexture, texture);
_texturePath = path + '/' + texture;
_texturePath = absPath(texture);
}
_orientation.addOption(Outside, "Outside");
@@ -183,7 +178,7 @@ void RenderableSphere::update(const UpdateData& data) {
void RenderableSphere::loadTexture() {
if (_texturePath.value() != "") {
ghoul::opengl::Texture* texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath));
ghoul::opengl::Texture* texture = ghoul::io::TextureReader::ref().loadTexture(_texturePath);
if (texture) {
LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'");
texture->uploadTexture();

View File

@@ -74,7 +74,7 @@ RenderableVolumeGL::RenderableVolumeGL(const ghoul::Dictionary& dictionary)
constants::renderablevolumegl::keyVolume << "'");
return;
}
_filename = findPath(_filename);
_filename = absPath(_filename);
if (_filename == "") {
return;
}
@@ -93,7 +93,7 @@ RenderableVolumeGL::RenderableVolumeGL(const ghoul::Dictionary& dictionary)
constants::renderablevolumegl::keyTransferFunction << "'");
return;
}
_transferFunctionPath = findPath(_transferFunctionPath);
_transferFunctionPath = absPath(_transferFunctionPath);
_transferFunctionFile = new ghoul::filesystem::File(_transferFunctionPath, true);
_samplerFilename = "";
@@ -104,7 +104,7 @@ RenderableVolumeGL::RenderableVolumeGL(const ghoul::Dictionary& dictionary)
constants::renderablevolumegl::keySampler << "'");
return;
}
_samplerFilename = findPath(_samplerFilename);
_samplerFilename = absPath(_samplerFilename);
KameleonWrapper kw(_filename);
auto t = kw.getGridUnits();

View File

@@ -60,6 +60,11 @@ namespace {
const std::string _moduleExtension = ".mod";
const std::string _defaultCommonDirectory = "common";
const std::string _commonModuleToken = "${COMMON_MODULE}";
const std::string KeyCamera = "Camera";
const std::string KeyFocusObject = "Focus";
const std::string KeyPositionObject = "Position";
const std::string KeyViewOffset = "Offset";
}
namespace openspace {
@@ -257,12 +262,12 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) {
// TODO: Make it less hard-coded and more flexible when nodes are not found
ghoul::Dictionary cameraDictionary;
if (dictionary.getValue(constants::scenegraph::keyCamera, cameraDictionary)) {
if (dictionary.getValue(KeyCamera, cameraDictionary)) {
LDEBUG("Camera dictionary found");
std::string focus;
if (cameraDictionary.hasKey(constants::scenegraph::keyFocusObject)
&& cameraDictionary.getValue(constants::scenegraph::keyFocusObject, focus))
if (cameraDictionary.hasKey(KeyFocusObject)
&& cameraDictionary.getValue(KeyFocusObject, focus))
{
auto focusIterator = std::find_if(
_graph.nodes().begin(),
@@ -357,8 +362,8 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) {
OsEng.interactionHandler()->setFocusNode(_graph.rootNode());
glm::vec4 position;
if (cameraDictionary.hasKey(constants::scenegraph::keyPositionObject)
&& cameraDictionary.getValue(constants::scenegraph::keyPositionObject, position)) {
if (cameraDictionary.hasKey(KeyPositionObject)
&& cameraDictionary.getValue(KeyPositionObject, position)) {
LDEBUG("Camera position is ("
<< position[0] << ", "
@@ -381,8 +386,8 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) {
c->setScaling(cameraScaling);
glm::vec3 viewOffset;
if (cameraDictionary.hasKey(constants::scenegraph::keyViewOffset)
&& cameraDictionary.getValue(constants::scenegraph::keyViewOffset, viewOffset)) {
if (cameraDictionary.hasKey(KeyViewOffset)
&& cameraDictionary.getValue(KeyViewOffset, viewOffset)) {
glm::quat rot = glm::quat(viewOffset);
c->rotate(rot);
}
@@ -396,15 +401,13 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) {
}
// If a LuaDocumentationFile was specified, generate it now
using constants::configurationmanager::keyPropertyDocumentationType;
using constants::configurationmanager::keyPropertyDocumentationFile;
const bool hasType = OsEng.configurationManager()->hasKey(keyPropertyDocumentationType);
const bool hasFile = OsEng.configurationManager()->hasKey(keyPropertyDocumentationFile);
const bool hasType = OsEng.configurationManager()->hasKey(ConfigurationManager::KeyPropertyDocumentationType);
const bool hasFile = OsEng.configurationManager()->hasKey(ConfigurationManager::KeyPropertyDocumentationFile);
if (hasType && hasFile) {
std::string propertyDocumentationType;
OsEng.configurationManager()->getValue(keyPropertyDocumentationType, propertyDocumentationType);
OsEng.configurationManager()->getValue(ConfigurationManager::KeyPropertyDocumentationType, propertyDocumentationType);
std::string propertyDocumentationFile;
OsEng.configurationManager()->getValue(keyPropertyDocumentationFile, propertyDocumentationFile);
OsEng.configurationManager()->getValue(ConfigurationManager::KeyPropertyDocumentationFile, propertyDocumentationFile);
propertyDocumentationFile = absPath(propertyDocumentationFile);
writePropertyDocumentation(propertyDocumentationFile, propertyDocumentationType);

View File

@@ -26,7 +26,6 @@
#include <openspace/engine/openspaceengine.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/constants.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
@@ -39,6 +38,11 @@ namespace {
const std::string _moduleExtension = ".mod";
const std::string _defaultCommonDirectory = "common";
const std::string _commonModuleToken = "${COMMON_MODULE}";
const std::string KeyPathScene = "ScenePath";
const std::string KeyModules = "Modules";
const std::string KeyCommonFolder = "CommonFolder";
const std::string KeyPathModule = "ModulePath";
}
namespace openspace {
@@ -78,7 +82,7 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
std::string sceneDescriptionDirectory =
ghoul::filesystem::File(absSceneFile, true).directoryName();
std::string sceneDirectory(".");
sceneDictionary.getValue(constants::scenegraph::keyPathScene, sceneDirectory);
sceneDictionary.getValue(KeyPathScene, sceneDirectory);
// The scene path could either be an absolute or relative path to the description
// paths directory
@@ -91,14 +95,13 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
else if (FileSys.directoryExists(absoluteCandidate))
sceneDirectory = absoluteCandidate;
else {
LERROR("The '" << constants::scenegraph::keyPathScene << "' pointed to a "
LERROR("The '" << KeyPathScene << "' pointed to a "
"path '" << sceneDirectory << "' that did not exist");
return false;
}
using constants::scenegraph::keyModules;
ghoul::Dictionary moduleDictionary;
success = sceneDictionary.getValue(keyModules, moduleDictionary);
success = sceneDictionary.getValue(KeyModules, moduleDictionary);
if (!success)
// There are no modules that are loaded
return true;
@@ -107,13 +110,12 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
OsEng.scriptEngine()->initializeLuaState(state);
// Get the common directory
using constants::scenegraph::keyCommonFolder;
bool commonFolderSpecified = sceneDictionary.hasKey(keyCommonFolder);
bool commonFolderCorrectType = sceneDictionary.hasKeyAndValue<std::string>(keyCommonFolder);
bool commonFolderSpecified = sceneDictionary.hasKey(KeyCommonFolder);
bool commonFolderCorrectType = sceneDictionary.hasKeyAndValue<std::string>(KeyCommonFolder);
if (commonFolderSpecified) {
if (commonFolderCorrectType) {
std::string commonFolder = sceneDictionary.value<std::string>(keyCommonFolder);
std::string commonFolder = sceneDictionary.value<std::string>(KeyCommonFolder);
std::string fullCommonFolder = FileSys.pathByAppendingComponent(
sceneDirectory,
commonFolder
@@ -182,10 +184,10 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
std::string parentName;
moduleDictionary.getValue(key, element);
element.setValue(constants::scenegraph::keyPathModule, modulePath);
element.setValue(KeyPathModule, modulePath);
element.getValue(constants::scenegraphnode::keyName, nodeName);
element.getValue(constants::scenegraphnode::keyParentName, parentName);
element.getValue(SceneGraphNode::KeyName, nodeName);
element.getValue(SceneGraphNode::KeyParentName, parentName);
FileSys.setCurrentDirectory(modulePath);
SceneGraphNode* node = SceneGraphNode::createFromDictionary(element);
@@ -199,11 +201,10 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
parents[nodeName] = parentName;
// Also include loaded dependencies
using constants::scenegraphnode::keyDependencies;
if (element.hasKey(keyDependencies)) {
if (element.hasValue<ghoul::Dictionary>(keyDependencies)) {
if (element.hasKey(SceneGraphNode::KeyDependencies)) {
if (element.hasValue<ghoul::Dictionary>(SceneGraphNode::KeyDependencies)) {
ghoul::Dictionary nodeDependencies;
element.getValue(constants::scenegraphnode::keyDependencies, nodeDependencies);
element.getValue(SceneGraphNode::KeyDependencies, nodeDependencies);
std::vector<std::string> keys = nodeDependencies.keys();
for (const std::string& key : keys) {

View File

@@ -51,6 +51,9 @@ const std::string _loggerCat = "SceneGraphNode";
namespace openspace {
std::string SceneGraphNode::RootNodeName = "Root";
const std::string SceneGraphNode::KeyName = "Name";
const std::string SceneGraphNode::KeyParentName = "Parent";
const std::string SceneGraphNode::KeyDependencies = "Dependencies";
SceneGraphNode* SceneGraphNode::createFromDictionary(const ghoul::Dictionary& dictionary)
{
@@ -59,12 +62,8 @@ SceneGraphNode* SceneGraphNode::createFromDictionary(const ghoul::Dictionary& di
SceneGraphNode* result = new SceneGraphNode;
std::string path;
dictionary.getValue(keyPathModule, path);
if (!dictionary.hasValue<std::string>(keyName)) {
LERROR("SceneGraphNode in '" << path << "' did not contain a '"
<< keyName << "' key");
LERROR("SceneGraphNode did not contain a '" << keyName << "' key");
return nullptr;
}
std::string name;
@@ -76,7 +75,6 @@ SceneGraphNode* SceneGraphNode::createFromDictionary(const ghoul::Dictionary& di
dictionary.getValue(keyRenderable, renderableDictionary);
renderableDictionary.setValue(keyName, name);
renderableDictionary.setValue(keyPathModule, path);
result->_renderable = Renderable::createFromDictionary(renderableDictionary);
if (result->_renderable == nullptr) {
@@ -91,7 +89,6 @@ SceneGraphNode* SceneGraphNode::createFromDictionary(const ghoul::Dictionary& di
if (dictionary.hasKey(keyEphemeris)) {
ghoul::Dictionary ephemerisDictionary;
dictionary.getValue(keyEphemeris, ephemerisDictionary);
ephemerisDictionary.setValue(keyPathModule, path);
result->_ephemeris = Ephemeris::createFromDictionary(ephemerisDictionary);
if (result->_ephemeris == nullptr) {
LERROR("Failed to create ephemeris for SceneGraphNode '"