From dc32dfe075e922a2fcaed76518bd83f8190670c7 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 14 Jul 2016 00:28:09 -0400 Subject: [PATCH] Added functionality to print all keybindings to file when a scene is loaded --- .gitignore | 1 + ext/ghoul | 2 +- .../openspace/engine/configurationmanager.h | 4 ++++ .../interaction/interactionhandler.h | 3 +++ src/engine/configurationmanager.cpp | 2 ++ src/interaction/interactionhandler.cpp | 20 +++++++++++++++++++ src/scene/scene.cpp | 18 +++++++++++++++-- 7 files changed, 47 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 512c197509..b6b3900ce1 100644 --- a/.gitignore +++ b/.gitignore @@ -154,3 +154,4 @@ data/scene/juno/juno/textures data/scene/juno/juno/spice data/scene/juno/juno/Juno.mtl data/scene/juno/juno/Juno.obj +KeyboardMapping.txt diff --git a/ext/ghoul b/ext/ghoul index cafbe9c243..3c60705400 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit cafbe9c2432041341fad43f3a72fcd1bdb5bdeef +Subproject commit 3c6070540080700b84f4e7e3986e2497a2b85b56 diff --git a/include/openspace/engine/configurationmanager.h b/include/openspace/engine/configurationmanager.h index da899ce3bb..4af3c63afa 100644 --- a/include/openspace/engine/configurationmanager.h +++ b/include/openspace/engine/configurationmanager.h @@ -61,6 +61,10 @@ public: static const std::string KeyPropertyDocumentationType; /// The key that stores the save location of the Property documentation static const std::string KeyPropertyDocumentationFile; + /// The key that stores the type of keyboard bindings that should be stored + static const std::string KeyKeyboardShortcutsType; + /// The key that stores the save location of the keyboard bindings file + static const std::string KeyKeyboardShortcutsFile; /// The key that stores the location of the scene file that is initially loaded static const std::string KeyConfigScene; /// The key that stores the subdirectory containing a list of all startup scripts to diff --git a/include/openspace/interaction/interactionhandler.h b/include/openspace/interaction/interactionhandler.h index 05b06838bc..a90df2ba87 100644 --- a/include/openspace/interaction/interactionhandler.h +++ b/include/openspace/interaction/interactionhandler.h @@ -109,6 +109,7 @@ public: void distanceDelta(const PowerScaledScalar& distance, size_t iterations = 0); void lookAt(const glm::quat& rotation); void setRotation(const glm::quat& rotation); + private: // Remove copy and move constructors @@ -349,6 +350,8 @@ public: void mousePositionCallback(double x, double y); void mouseScrollWheelCallback(double pos); + void writeKeyboardDocumentation(const std::string& type, const std::string& file); + private: void setInteractionMode(std::shared_ptr interactionMode); diff --git a/src/engine/configurationmanager.cpp b/src/engine/configurationmanager.cpp index 55211d1074..2e6cabe62c 100644 --- a/src/engine/configurationmanager.cpp +++ b/src/engine/configurationmanager.cpp @@ -51,6 +51,8 @@ const string ConfigurationManager::KeyPropertyDocumentationType = "PropertyDocumentationFile.Type"; const string ConfigurationManager::KeyPropertyDocumentationFile = "PropertyDocumentationFile.File"; +const string ConfigurationManager::KeyKeyboardShortcutsType = "KeyboardShortcuts.Type"; +const string ConfigurationManager::KeyKeyboardShortcutsFile = "KeyboardShortcuts.File"; const string ConfigurationManager::KeyConfigScene = "Scene"; const string ConfigurationManager::KeySpiceTimeKernel = "SpiceKernel.Time"; const string ConfigurationManager::KeySpiceLeapsecondKernel = "SpiceKernel.LeapSecond"; diff --git a/src/interaction/interactionhandler.cpp b/src/interaction/interactionhandler.cpp index 4a79be111a..35c8f20127 100644 --- a/src/interaction/interactionhandler.cpp +++ b/src/interaction/interactionhandler.cpp @@ -36,6 +36,8 @@ #include +#include + namespace { const std::string _loggerCat = "InteractionHandler"; } @@ -1151,6 +1153,24 @@ void InteractionHandler::bindKey(Key key, KeyModifier modifier, std::string lua) lua }); } + +void InteractionHandler::writeKeyboardDocumentation(const std::string& type, const std::string& file) +{ + if (type == "text") { + std::ofstream f(absPath(file)); + + for (const auto& p : _keyLua) { + f << std::to_string(p.first) << ": " << + p.second << std::endl; + } + } + else { + throw ghoul::RuntimeError( + "Unsupported keyboard documentation type '" + type + "'", + "InteractionHandler" + ); + } +} scripting::ScriptEngine::LuaLibrary InteractionHandler::luaLibrary() { return{ diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index f26ff0cd0f..d66c4fc2b4 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -87,14 +87,28 @@ bool Scene::deinitialize() { return true; } -//bool ONCE = false; - void Scene::update(const UpdateData& data) { if (!_sceneGraphToLoad.empty()) { OsEng.renderEngine().scene()->clearSceneGraph(); try { loadSceneInternal(_sceneGraphToLoad); _sceneGraphToLoad = ""; + + // After loading the scene, the keyboard bindings have been set + + std::string type; + std::string file; + bool hasType = OsEng.configurationManager().getValue( + ConfigurationManager::KeyKeyboardShortcutsType, type + ); + + bool hasFile = OsEng.configurationManager().getValue( + ConfigurationManager::KeyKeyboardShortcutsFile, file + ); + + if (hasType && hasFile) { + OsEng.interactionHandler().writeKeyboardDocumentation(type, file); + } } catch (const ghoul::RuntimeError& e) { LERROR(e.what());