diff --git a/include/openspace/util/constants.h b/include/openspace/util/constants.h new file mode 100644 index 0000000000..d2079a2493 --- /dev/null +++ b/include/openspace/util/constants.h @@ -0,0 +1,58 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __CONSTANTS_H__ +#define __CONSTANTS_H__ + +#include + +namespace openspace { +namespace constants { +namespace openspaceengine { + const std::string pathKey = "Paths"; + const std::string scenePathKey = "Paths.SCENEPATH"; + const std::string sgctConfigKey = "SGCTConfig"; + const std::string sceneConfigurationKey = "Scene"; +} // namespace openspaceengine + +namespace scenegraph { + const std::string modulesKey = "Modules"; + const std::string cameraKey = "Camera"; + const std::string focusKey = "Focus"; + const std::string positionKey = "Position"; + const std::string modulePathKey = "ModulePath"; +} // namespace scenegraph + +namespace scenegraphnode { + const std::string nameKey = "Name"; + const std::string parentKey = "Parent"; + const std::string renderableKey = "Renderable"; + const std::string ephemerisKey = "Position"; +} // namespace scenegraphnode + +} // namespace constants +} // namespace openspace + + +#endif // __CONSTANTS_H__ \ No newline at end of file diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 2a23200c2f..093a6862ed 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -52,14 +53,6 @@ namespace { const std::string _configurationFile = "openspace.cfg"; const std::string _basePathToken = "${BASE_PATH}"; const std::string _sgctDefaultConfigFile = "${SGCT}/single.xml"; - - namespace configuration { - const std::string pathKey = "Paths"; - const std::string scenePathKey = "Paths.SCENEPATH"; - const std::string sgctConfigKey = "SGCTConfig"; - const std::string sceneConfigurationKey = "Scene"; - - } } namespace openspace { @@ -80,7 +73,7 @@ OpenSpaceEngine::~OpenSpaceEngine() delete _interactionHandler; delete _renderEngine; - // TODO deallocate scriptengine when starting to use it + // TODO deallocate script engine when starting to use it // delete _scriptEngine; Spice::deinit(); @@ -195,15 +188,15 @@ void OpenSpaceEngine::create(int argc, char** argv, ghoul::Dictionary& configuration = *(_engine->_configurationManager); ghoul::lua::loadDictionaryFromFile(configurationFilePath, configuration); - if (configuration.hasKey(configuration::pathKey)) { + if (configuration.hasKey(constants::openspaceengine::pathKey)) { ghoul::Dictionary pathsDictionary; - if (configuration.getValue(configuration::pathKey, pathsDictionary)) + if (configuration.getValue(constants::openspaceengine::pathKey, pathsDictionary)) OpenSpaceEngine::registerPathsFromDictionary(pathsDictionary); } std::string sgctConfigurationPath = _sgctDefaultConfigFile; - if (configuration.hasKey(configuration::sgctConfigKey)) - configuration.getValue(configuration::sgctConfigKey, sgctConfigurationPath); + if (configuration.hasKey(constants::openspaceengine::sgctConfigKey)) + configuration.getValue(constants::openspaceengine::sgctConfigKey, sgctConfigurationPath); sgctArguments.push_back(argv[0]); sgctArguments.push_back("-config"); @@ -254,14 +247,14 @@ bool OpenSpaceEngine::initialize() std::shared_ptr sceneGraph(new SceneGraph); _renderEngine->setSceneGraph(sceneGraph); if (!OsEng.configurationManager().hasValue( - configuration::sceneConfigurationKey)) { + constants::openspaceengine::sceneConfigurationKey)) { LFATAL("Configuration needs to point to the scene file"); return false; } std::string sceneDescriptionPath; bool success = _configurationManager->getValue( - configuration::sceneConfigurationKey, sceneDescriptionPath); + constants::openspaceengine::sceneConfigurationKey, sceneDescriptionPath); if (!FileSys.fileExists(sceneDescriptionPath)) { LFATAL("Could not find '" << sceneDescriptionPath << "'"); @@ -269,7 +262,7 @@ bool OpenSpaceEngine::initialize() } std::string scenePath; - success = _configurationManager->getValue(configuration::scenePathKey, scenePath); + success = _configurationManager->getValue(constants::openspaceengine::scenePathKey, scenePath); if (!success) { LFATAL("Could not find SCENEPATH key in configuration file"); return false; diff --git a/src/scenegraph/scenegraph.cpp b/src/scenegraph/scenegraph.cpp index c4ef331a24..b3cc97bd57 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scenegraph/scenegraph.cpp @@ -28,6 +28,7 @@ #include #include #include +#include // ghoul includes #include "ghoul/opengl/programobject.h" @@ -50,13 +51,6 @@ const std::string _loggerCat = "SceneGraph"; const std::string _rootNodeName = "Root"; const std::string _moduleExtension = ".mod"; -namespace configuration { -const std::string modulesKey = "Modules"; -const std::string cameraKey = "Camera"; -const std::string focusKey = "Focus"; -const std::string positionKey = "Position"; -const std::string modulePathKey = "ModulePath"; -} } namespace openspace { @@ -248,7 +242,7 @@ bool SceneGraph::loadScene(const std::string& sceneDescriptionFilePath, Dictionary dictionary; loadDictionaryFromFile(sceneDescriptionFilePath, dictionary); Dictionary moduleDictionary; - if (dictionary.getValue(configuration::modulesKey, moduleDictionary)) { + if (dictionary.getValue(constants::scenegraph::modulesKey, moduleDictionary)) { std::vector keys = moduleDictionary.keys(); std::sort(keys.begin(), keys.end()); for (const std::string& key : keys) { @@ -260,13 +254,13 @@ bool SceneGraph::loadScene(const std::string& sceneDescriptionFilePath, // TODO: Make it less hard-coded and more flexible when nodes are not found Dictionary cameraDictionary; - if (dictionary.getValue(configuration::cameraKey, cameraDictionary)) { + if (dictionary.getValue(constants::scenegraph::cameraKey, cameraDictionary)) { LDEBUG("Camera dictionary found"); std::string focus; std::string position; - if (cameraDictionary.hasKey(configuration::focusKey) - && cameraDictionary.getValue(configuration::focusKey, focus)) { + if (cameraDictionary.hasKey(constants::scenegraph::focusKey) + && cameraDictionary.getValue(constants::scenegraph::focusKey, focus)) { auto focusIterator = _allNodes.find(focus); if (focusIterator != _allNodes.end()) { _focus = focus; @@ -275,8 +269,8 @@ bool SceneGraph::loadScene(const std::string& sceneDescriptionFilePath, else LERROR("Could not find focus object '" << focus << "'"); } - if (cameraDictionary.hasKey(configuration::positionKey) - && cameraDictionary.getValue(configuration::positionKey, position)) { + if (cameraDictionary.hasKey(constants::scenegraph::positionKey) + && cameraDictionary.getValue(constants::scenegraph::positionKey, position)) { auto positionIterator = _allNodes.find(position); if (positionIterator != _allNodes.end()) { _position = position; @@ -314,7 +308,7 @@ void SceneGraph::loadModule(const std::string& modulePath) ghoul::Dictionary element; moduleDictionary.getValue(key, element); - element.setValue(configuration::modulePathKey, modulePath); + element.setValue(constants::scenegraph::modulePathKey, modulePath); SceneGraphNode* node = SceneGraphNode::createFromDictionary(element); diff --git a/src/scenegraph/scenegraphnode.cpp b/src/scenegraph/scenegraphnode.cpp index 57bfb6f29c..9eea97f719 100644 --- a/src/scenegraph/scenegraphnode.cpp +++ b/src/scenegraph/scenegraphnode.cpp @@ -21,11 +21,12 @@ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ - + // open space includes #include #include #include +#include // ghoul includes #include @@ -41,14 +42,6 @@ namespace { const std::string _loggerCat = "SceneGraphNode"; - -namespace configuration { -const std::string nameKey = "Name"; -const std::string parentKey = "Parent"; -const std::string modulePathKey = "ModulePath"; -const std::string renderableKey = "Renderable"; -const std::string positionKey = "Position"; -} } namespace openspace { @@ -84,38 +77,37 @@ SceneGraphNode* SceneGraphNode::createFromDictionary(const ghoul::Dictionary& di SceneGraphNode* result = new SceneGraphNode; std::string path; - dictionary.getValue(configuration::modulePathKey, path); + dictionary.getValue(constants::scenegraph::modulePathKey, path); - if (!dictionary.hasValue(configuration::nameKey)) { + if (!dictionary.hasValue(constants::scenegraphnode::nameKey)) { LERROR("SceneGraphNode in '" << path << "' did not contain a '" - << configuration::nameKey << "' key"); + << constants::scenegraphnode::nameKey << "' key"); return nullptr; } - dictionary.getValue(configuration::nameKey, result->_nodeName); + dictionary.getValue(constants::scenegraphnode::nameKey, result->_nodeName); - - if (dictionary.hasKey(configuration::renderableKey)) { + if (dictionary.hasKey(constants::scenegraphnode::renderableKey)) { if (safeCreationWithDictionary( - &result->_renderable, configuration::renderableKey, dictionary, path)) { + &result->_renderable, constants::scenegraphnode::renderableKey, + dictionary, path)) { LDEBUG(result->_nodeName << ": Successful creation of renderable"); result->_renderable->setName(result->_nodeName); - } - else { + } else { LDEBUG(result->_nodeName << ": Failed to create renderable"); } } - if (dictionary.hasKey(configuration::positionKey)) { + if (dictionary.hasKey(constants::scenegraphnode::ephemerisKey)) { if (safeCreationWithDictionary( - &result->_position, configuration::positionKey, dictionary, path)) { + &result->_position, constants::scenegraphnode::ephemerisKey, dictionary, + path)) { LDEBUG(result->_nodeName << ": Successful creation of position"); - } - else { + } else { LDEBUG(result->_nodeName << ": Failed to create position"); } } std::string parentName; - if (!dictionary.getValue(configuration::parentKey, parentName)) { + if (!dictionary.getValue(constants::scenegraphnode::parentKey, parentName)) { LWARNING("Could not find 'Parent' key, using 'Root'."); parentName = "Root"; } @@ -123,16 +115,15 @@ SceneGraphNode* SceneGraphNode::createFromDictionary(const ghoul::Dictionary& di SceneGraphNode* parentNode = getSceneGraphNode(parentName); if (parentNode == nullptr) { LFATAL("Could not find parent named '" - << parentName << "' for '" << result->_nodeName << "'." - << " Check module definition order. Skipping module."); + << parentName << "' for '" << result->_nodeName << "'." + << " Check module definition order. Skipping module."); } parentNode->addNode(result); - + return result; } - SceneGraphNode::SceneGraphNode() : _parent(nullptr) , _nodeName("")