Merge branch 'features/imgui' into develop

This commit is contained in:
Alexander Bock
2015-02-17 19:04:43 +01:00
18 changed files with 1933 additions and 465 deletions
+4 -2
View File
@@ -25,6 +25,8 @@
#ifndef __OPENSPACEENGINE_H__
#define __OPENSPACEENGINE_H__
#include <openspace/gui/gui.h>
#include <string>
#include <vector>
@@ -67,7 +69,7 @@ public:
scripting::ScriptEngine* scriptEngine();
LuaConsole* console();
GUI* gui();
gui::GUI* gui();
// SGCT callbacks
bool initializeGL();
@@ -105,7 +107,7 @@ private:
scripting::ScriptEngine* _scriptEngine;
ghoul::cmdparser::CommandlineParser* _commandlineParser;
LuaConsole* _console;
GUI* _gui;
gui::GUI* _gui;
double _dt;
SyncBuffer* _syncBuffer;
+26 -40
View File
@@ -25,40 +25,28 @@
#ifndef __GUI_H__
#define __GUI_H__
#include <openspace/gui/guihelpcomponent.h>
#include <openspace/gui/guiperformancecomponent.h>
#include <openspace/gui/guipropertycomponent.h>
#include <openspace/scripting/scriptengine.h>
#include <ghoul/glm.h>
#include <map>
#include <set>
#include <string>
#include <vector>
namespace ghoul {
class SharedMemory;
}
namespace openspace {
namespace properties {
class Property;
}
namespace gui {
class GUI {
public:
GUI();
~GUI();
~GUI();
bool isEnabled() const;
void setEnabled(bool enabled);
void initialize();
void deinitialize();
void initializeGL();
void deinitializeGL();
void registerProperty(properties::Property* prop);
bool mouseButtonCallback(int key, int action);
bool mouseWheelCallback(int position);
bool keyCallback(int key, int action);
@@ -67,39 +55,37 @@ public:
void startFrame(float deltaTime, const glm::vec2& windowSize, const glm::vec2& mousePos, bool mouseButtonsPressed[2]);
void endFrame();
static scripting::ScriptEngine::LuaLibrary luaLibrary();
private:
void renderMainWindow();
void renderPropertyWindow();
void renderPerformanceWindow();
static openspace::scripting::ScriptEngine::LuaLibrary luaLibrary();
//protected:
GuiPerformanceComponent _performance;
GuiPropertyComponent _property;
GuiHelpComponent _help;
bool _isEnabled;
bool _showPropertyWindow;
bool _showPerformanceWindow;
bool _showHelp;
//ghoul::SharedMemory* _performanceMemory;
//float _minMaxValues[2];
ghoul::SharedMemory* _performanceMemory;
float _minMaxValues[2];
//std::set<properties::Property*> _boolProperties;
//std::set<properties::Property*> _intProperties;
//std::set<properties::Property*> _floatProperties;
//std::set<properties::Property*> _vec2Properties;
//std::set<properties::Property*> _vec3Properties;
//std::set<properties::Property*> _vec4Properties;
//std::set<properties::Property*> _stringProperties;
//std::set<properties::Property*> _optionProperty;
//std::set<properties::Property*> _selectionProperty;
//std::set<properties::Property*> _triggerProperty;
std::set<properties::Property*> _boolProperties;
std::set<properties::Property*> _intProperties;
std::set<properties::Property*> _floatProperties;
std::set<properties::Property*> _vec2Properties;
std::set<properties::Property*> _vec3Properties;
std::set<properties::Property*> _vec4Properties;
std::set<properties::Property*> _stringProperties;
std::set<properties::Property*> _optionProperty;
std::set<properties::Property*> _selectionProperty;
std::set<properties::Property*> _triggerProperty;
std::map<std::string, std::vector<properties::Property*>> _propertiesByOwner;
//std::map<std::string, std::vector<properties::Property*>> _propertiesByOwner;
};
} // namespace gui
} // namespace openspace
#endif // __GUI_H__
+77
View File
@@ -0,0 +1,77 @@
/*****************************************************************************************
* *
* 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 __GUICOMPONENT_H__
#define __GUICOMPONENT_H__
namespace openspace {
namespace gui {
class GUI;
/**
* The base class for a GUI component that can be rendered to the screen.
*/
class GuiComponent {
public:
friend class GUI;
/**
* Returns if this component is enabled, that is, if it is currently active and
* visible on the screen.
* \return <code>true</code> if this component is enabled, <code>false</code>
* otherwise
*/
bool isEnabled() const;
/**
* Sets if this component is enabled, that is, if it is currently active and visible
* on the screen.
* \param enabled The new enabled status of this component
*/
void setEnabled(bool enabled);
/// Initializes the component with everything that does not require an OpenGL context
virtual void initialize();
/// Initializes the component with everything that requires an OpenGL context
virtual void initializeGL();
/// Deinitializes the component with things that do not require an OpenGL context
virtual void deinitialize();
/// Deinitializes the component with things that require an OpenGL context
virtual void deinitializeGL();
/// Renders the individual subcomponents to the screen
virtual void render() = 0;
protected:
/// <code>true</code> if this component is enabled and visible on the screen
bool _isEnabled = false;
};
} // namespace gui
} // namespace openspace
#endif // __GUICOMPONENT_H__
+41
View File
@@ -0,0 +1,41 @@
/*****************************************************************************************
* *
* 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 __GUIHELPCOMPONENT_H__
#define __GUIHELPCOMPONENT_H__
#include <openspace/gui/guicomponent.h>
namespace openspace {
namespace gui {
class GuiHelpComponent : public GuiComponent {
public:
void render();
};
} // namespace gui
} // namespace openspace
#endif // __GUIHELPCOMPONENT_H__
@@ -0,0 +1,52 @@
/*****************************************************************************************
* *
* 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 __GUIPERFORMANCECOMPONENT_H__
#define __GUIPERFORMANCECOMPONENT_H__
#include <openspace/gui/guicomponent.h>
namespace ghoul {
class SharedMemory;
}
namespace openspace {
namespace gui {
class GuiPerformanceComponent : public GuiComponent {
public:
void initialize();
void deinitialize();
void render();
protected:
ghoul::SharedMemory* _performanceMemory = nullptr;
float _minMaxValues[2];
};
} // namespace gui
} // namespace openspace
#endif // __GUIPERFORMANCECOMPONENT_H__
@@ -0,0 +1,100 @@
/*****************************************************************************************
* *
* 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 __GUIPROPERTYCOMPONENT_H__
#define __GUIPROPERTYCOMPONENT_H__
#include <openspace/gui/guicomponent.h>
#include <ghoul/misc/dictionary.h>
#include <string>
#include <vector>
#include <set>
namespace openspace {
namespace properties {
class Property;
}
namespace gui {
class GuiPropertyComponent : public GuiComponent {
public:
//void registerProperty(const std::string& propertyDescription);
void registerProperty(properties::Property* prop);
void render();
protected:
enum class PropertyType {
BoolProperty = 0,
IntProperty,
FloatProperty,
Vec2Property,
Vec3Property,
StringProperty,
OptionProperty,
SelectionProperty,
TriggerProperty,
InvalidPropertyType
};
struct PropertyInfo {
PropertyType type;
std::string identifier;
std::string name;
std::string group;
};
typedef std::string PropertyOwner;
struct Property {
PropertyOwner owner;
std::vector<PropertyInfo> properties;
};
void handleProperty(const ghoul::Dictionary& value);
PropertyType toPropertyType(const std::string& name) const;
void renderProperty(const PropertyInfo& info) const;
std::set<properties::Property*> _boolProperties;
std::set<properties::Property*> _intProperties;
std::set<properties::Property*> _floatProperties;
std::set<properties::Property*> _vec2Properties;
std::set<properties::Property*> _vec3Properties;
std::set<properties::Property*> _vec4Properties;
std::set<properties::Property*> _stringProperties;
std::set<properties::Property*> _optionProperty;
std::set<properties::Property*> _selectionProperty;
std::set<properties::Property*> _triggerProperty;
std::map<std::string, std::vector<properties::Property*>> _propertiesByOwner;
//std::vector<Property> _properties;
};
} // namespace gui
} // namespace openspace
#endif // __GUIPROPERTYCOMPONENT_H__
+30
View File
@@ -44,6 +44,18 @@ public:
_encodeOffset += size;
}
template<>
void encode(const std::string& s) {
const size_t size = sizeof(char) * s.size() + sizeof(int32_t);
assert(_encodeOffset + size < _n);
int32_t length = s.length();
memcpy(_dataStream.data() + _encodeOffset, reinterpret_cast<const char*>(&length), sizeof(int32_t));
_encodeOffset += sizeof(int32_t);
memcpy(_dataStream.data() + _encodeOffset, s.c_str(), length);
_encodeOffset += length;
}
template<typename T>
T decode() {
const size_t size = sizeof(T);
@@ -54,6 +66,19 @@ public:
return value;
}
template<>
std::string decode() {
int32_t length;
memcpy(reinterpret_cast<char*>(&length), _dataStream.data() + _decodeOffset, sizeof(int32_t));
char* tmp = new char[length + 1];
_decodeOffset += sizeof(int32_t);
memcpy(tmp, _dataStream.data() + _decodeOffset, length);
_decodeOffset += length;
tmp[length] = '\0';
std::string ret(tmp);
delete[] tmp;
return ret;
}
template<typename T>
void decode(T& value) {
@@ -63,6 +88,11 @@ public:
_decodeOffset += size;
}
template<>
void decode(std::string &s) {
s = decode<std::string>();
}
void write();
void read();
+4 -4
View File
@@ -90,7 +90,7 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName)
, _scriptEngine(new scripting::ScriptEngine)
, _commandlineParser(new ghoul::cmdparser::CommandlineParser(programName, true))
, _console(new LuaConsole)
, _gui(new GUI)
, _gui(new gui::GUI)
, _syncBuffer(nullptr)
{
SpiceManager::initialize();
@@ -100,7 +100,7 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName)
}
OpenSpaceEngine::~OpenSpaceEngine() {
_gui->deinitializeGL();
_gui->deinitializeGL();
delete _configurationManager;
delete _interactionHandler;
@@ -260,7 +260,7 @@ bool OpenSpaceEngine::initialize() {
_scriptEngine->addLibrary(Time::luaLibrary());
_scriptEngine->addLibrary(interaction::InteractionHandler::luaLibrary());
_scriptEngine->addLibrary(LuaConsole::luaLibrary());
_scriptEngine->addLibrary(GUI::luaLibrary());
_scriptEngine->addLibrary(gui::GUI::luaLibrary());
// TODO: Maybe move all scenegraph and renderengine stuff to initializeGL
scriptEngine()->initialize();
@@ -503,7 +503,7 @@ LuaConsole* OpenSpaceEngine::console() {
return _console;
}
GUI* OpenSpaceEngine::gui() {
gui::GUI* OpenSpaceEngine::gui() {
ghoul_assert(_gui != nullptr, "GUI is nullptr");
return _gui;
}
+801 -407
View File
File diff suppressed because it is too large Load Diff
+47
View File
@@ -0,0 +1,47 @@
/*****************************************************************************************
* *
* 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. *
****************************************************************************************/
#include <openspace/gui/guicomponent.h>
namespace openspace {
namespace gui {
bool GuiComponent::isEnabled() const {
return _isEnabled;
}
void GuiComponent::setEnabled(bool enabled) {
_isEnabled = enabled;
}
void GuiComponent::initialize() {}
void GuiComponent::initializeGL() {}
void GuiComponent::deinitialize() {}
void GuiComponent::deinitializeGL() {}
} // namespace gui
} // namespace openspace
+43
View File
@@ -0,0 +1,43 @@
/*****************************************************************************************
* *
* 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. *
****************************************************************************************/
#include <openspace/gui/guihelpcomponent.h>
#include "imgui.h"
namespace {
const ImVec2 size = ImVec2(350, 500);
}
namespace openspace {
namespace gui {
void GuiHelpComponent::render() {
ImGui::Begin("Help", &_isEnabled, size, 0.5f);
ImGui::ShowUserGuide();
ImGui::End();
}
} // gui
} // openspace
+117
View File
@@ -0,0 +1,117 @@
/*****************************************************************************************
* *
* 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. *
****************************************************************************************/
#include <openspace/gui/guiperformancecomponent.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <ghoul/misc/sharedmemory.h>
#include <imgui.h>
#include <algorithm>
namespace {
const std::string _loggerCat = "GuiPerformanceComponent";
}
namespace openspace {
namespace gui {
void GuiPerformanceComponent::initialize() {
_minMaxValues[0] = 100.f;
_minMaxValues[1] = 250.f;
}
void GuiPerformanceComponent::deinitialize() {
delete _performanceMemory;
_performanceMemory = nullptr;
}
void GuiPerformanceComponent::render() {
// Copy and paste from renderengine.cpp::storePerformanceMeasurements method
const int8_t Version = 0;
const int nValues = 250;
const int lengthName = 256;
const int maxValues = 50;
struct PerformanceLayout {
int8_t version;
int32_t nValuesPerEntry;
int32_t nEntries;
int32_t maxNameLength;
int32_t maxEntries;
struct PerformanceLayoutEntry {
char name[lengthName];
float renderTime[nValues];
float updateRenderable[nValues];
float updateEphemeris[nValues];
int32_t currentRenderTime;
int32_t currentUpdateRenderable;
int32_t currentUpdateEphemeris;
};
PerformanceLayoutEntry entries[maxValues];
};
ImGui::Begin("Performance", &_isEnabled);
if (OsEng.renderEngine()->doesPerformanceMeasurements() &&
ghoul::SharedMemory::exists(RenderEngine::PerformanceMeasurementSharedData))
{
ImGui::SliderFloat2("Min values, max Value", _minMaxValues, 0.f, 10000.f);
_minMaxValues[1] = fmaxf(_minMaxValues[0], _minMaxValues[1]);
if (!_performanceMemory)
_performanceMemory = new ghoul::SharedMemory(RenderEngine::PerformanceMeasurementSharedData);
PerformanceLayout* layout = reinterpret_cast<PerformanceLayout*>(_performanceMemory->pointer());
for (int i = 0; i < layout->nEntries; ++i) {
const PerformanceLayout::PerformanceLayoutEntry& entry = layout->entries[i];
if (ImGui::CollapsingHeader(entry.name)) {
std::string updateEphemerisTime = std::to_string(entry.updateEphemeris[entry.currentUpdateEphemeris - 1]) + "us";
ImGui::PlotLines("UpdateEphemeris", &entry.updateEphemeris[0], layout->nValuesPerEntry, 0, updateEphemerisTime.c_str(), _minMaxValues[0], _minMaxValues[1], ImVec2(0, 40));
std::string updateRenderableTime = std::to_string(entry.updateRenderable[entry.currentUpdateRenderable - 1]) + "us";
ImGui::PlotLines("UpdateRender", &entry.updateRenderable[0], layout->nValuesPerEntry, 0, updateRenderableTime.c_str(), _minMaxValues[0], _minMaxValues[1], ImVec2(0, 40));
std::string renderTime = std::to_string(entry.renderTime[entry.currentRenderTime - 1]) + "us";
ImGui::PlotLines("RenderTime", &entry.renderTime[0], layout->nValuesPerEntry, 0, renderTime.c_str(), _minMaxValues[0], _minMaxValues[1], ImVec2(0, 40));
}
}
}
else {
ImGui::TextWrapped("Performance monitoring is disabled. Enable with "
"'openspace.setPerformanceMeasurement(true)'");
}
ImGui::End();
}
} // namespace gui
} // namespace openspace
+577
View File
@@ -0,0 +1,577 @@
/*****************************************************************************************
* *
* 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. *
****************************************************************************************/
#include <openspace/gui/guipropertycomponent.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/scripting/scriptengine.h>
#include <openspace/properties/scalarproperty.h>
#include <openspace/properties/optionproperty.h>
#include <openspace/properties/selectionproperty.h>
#include <openspace/properties/vectorproperty.h>
#include <ghoul/lua/lua_helper.h>
#include <ghoul/misc/assert.h>
#include "imgui.h"
namespace {
const std::string _loggerCat = "GuiPropertyComponent";
const ImVec2 size = ImVec2(350, 500);
using namespace openspace::properties;
void executeScript(const std::string& id, const std::string& value) {
std::string script =
"openspace.setPropertyValue('" + id + "', " + value + ");";
OsEng.scriptEngine()->queueScript(script);
}
void renderBoolProperty(Property* prop, const std::string& ownerName) {
BoolProperty* p = static_cast<BoolProperty*>(prop);
std::string name = p->guiName();
BoolProperty::ValueType value = *p;
ImGui::Checkbox((ownerName + "." + name).c_str(), &value);
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(), value ? "true": "false");
}
void renderOptionProperty(Property* prop, const std::string& ownerName) {
OptionProperty* p = static_cast<OptionProperty*>(prop);
std::string name = p->guiName();
int value = *p;
std::vector<OptionProperty::Option> options = p->options();
for (const OptionProperty::Option& o : options) {
ImGui::RadioButton((ownerName + "." + name).c_str(), &value, o.value);
ImGui::SameLine();
ImGui::Text(o.description.c_str());
}
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(), std::to_string(value));
}
void renderSelectionProperty(Property* prop, const std::string& ownerName) {
SelectionProperty* p = static_cast<SelectionProperty*>(prop);
std::string name = p->guiName();
if (ImGui::CollapsingHeader((ownerName + "." + name).c_str())) {
const std::vector<SelectionProperty::Option>& options = p->options();
std::vector<int> newSelectedIndices;
std::vector<int> selectedIndices = p->value();
for (int i = 0; i < options.size(); ++i) {
std::string description = options[i].description;
bool selected = std::find(selectedIndices.begin(), selectedIndices.end(), i) != selectedIndices.end();
ImGui::Checkbox(description.c_str(), &selected);
if (selected)
newSelectedIndices.push_back(i);
}
if (newSelectedIndices != p->value()) {
std::string parameters = "{";
for (int i : newSelectedIndices)
parameters += std::to_string(i) + ",";
parameters += "}";
executeScript(p->fullyQualifiedIdentifier(), parameters);
}
}
}
void renderIntProperty(Property* prop, const std::string& ownerName) {
IntProperty* p = static_cast<IntProperty*>(prop);
std::string name = p->guiName();
IntProperty::ValueType value = *p;
ImGui::SliderInt((ownerName + "." + name).c_str(), &value, p->minValue(), p->maxValue());
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(), std::to_string(value));
}
void renderFloatProperty(Property* prop, const std::string& ownerName) {
FloatProperty* p = static_cast<FloatProperty*>(prop);
std::string name = p->guiName();
FloatProperty::ValueType value = *p;
ImGui::SliderFloat((ownerName + "." + name).c_str(), &value, p->minValue(), p->maxValue());
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(), std::to_string(value));
}
void renderVec2Property(Property* prop, const std::string& ownerName) {
Vec2Property* p = static_cast<Vec2Property*>(prop);
std::string name = p->guiName();
Vec2Property::ValueType value = *p;
ImGui::SliderFloat2((ownerName + "." + name).c_str(), &value.x, p->minValue().x, p->maxValue().x);
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," + std::to_string(value.y) + "}");
}
void renderVec3Property(Property* prop, const std::string& ownerName) {
Vec3Property* p = static_cast<Vec3Property*>(prop);
std::string name = p->guiName();
Vec3Property::ValueType value = *p;
ImGui::SliderFloat3((ownerName + "." + name).c_str(), &value.x, p->minValue().x, p->maxValue().x);
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," +
std::to_string(value.y) + "," +
std::to_string(value.z) + "}");
}
void renderVec4Property(Property* prop, const std::string& ownerName) {
Vec4Property* p = static_cast<Vec4Property*>(prop);
std::string name = p->guiName();
Vec4Property::ValueType value = *p;
ImGui::SliderFloat4((ownerName + "." + name).c_str(), &value.x, p->minValue().x, p->maxValue().x);
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," +
std::to_string(value.y) + "," +
std::to_string(value.z) + "," +
std::to_string(value.w) + "}");
}
void renderTriggerProperty(Property* prop, const std::string& ownerName) {
std::string name = prop->guiName();
bool pressed = ImGui::Button((ownerName + "." + name).c_str());
if (pressed)
executeScript(prop->fullyQualifiedIdentifier(), "0");
}
//void renderBoolProperty(Property* prop, const std::string& ownerName) {
// BoolProperty* p = static_cast<BoolProperty*>(prop);
// std::string name = p->guiName();
// BoolProperty::ValueType value = *p;
// ImGui::Checkbox((ownerName + "." + name).c_str(), &value);
// p->set(value);
//}
//void renderOptionProperty(Property* prop, const std::string& ownerName) {
// OptionProperty* p = static_cast<OptionProperty*>(prop);
// std::string name = p->guiName();
// int value = *p;
// std::vector<OptionProperty::Option> options = p->options();
// for (const OptionProperty::Option& o : options) {
// ImGui::RadioButton((ownerName + "." + name).c_str(), &value, o.value);
// ImGui::SameLine();
// ImGui::Text(o.description.c_str());
// }
// p->set(value);
//}
//void renderSelectionProperty(Property* prop, const std::string& ownerName) {
// SelectionProperty* p = static_cast<SelectionProperty*>(prop);
// std::string name = p->guiName();
// if (ImGui::CollapsingHeader((ownerName + "." + name).c_str())) {
// const std::vector<SelectionProperty::Option>& options = p->options();
// std::vector<int> newSelectedIndices;
// std::vector<int> selectedIndices = p->value();
// for (int i = 0; i < options.size(); ++i) {
// std::string description = options[i].description;
// bool selected = std::find(selectedIndices.begin(), selectedIndices.end(), i) != selectedIndices.end();
// ImGui::Checkbox(description.c_str(), &selected);
// if (selected)
// newSelectedIndices.push_back(i);
// }
// p->setValue(std::move(newSelectedIndices));
// }
//}
//void renderIntProperty(Property* prop, const std::string& ownerName) {
// IntProperty* p = static_cast<IntProperty*>(prop);
// std::string name = p->guiName();
// IntProperty::ValueType value = *p;
// ImGui::SliderInt((ownerName + "." + name).c_str(), &value, p->minValue(), p->maxValue());
// p->set(value);
//}
//void renderFloatProperty(Property* prop, const std::string& ownerName) {
// FloatProperty* p = static_cast<FloatProperty*>(prop);
// std::string name = p->guiName();
// FloatProperty::ValueType value = *p;
// ImGui::SliderFloat((ownerName + "." + name).c_str(), &value, p->minValue(), p->maxValue());
// p->set(value);
//}
//void renderVec2Property(Property* prop, const std::string& ownerName) {
// Vec2Property* p = static_cast<Vec2Property*>(prop);
// std::string name = p->guiName();
// Vec2Property::ValueType value = *p;
// ImGui::SliderFloat2((ownerName + "." + name).c_str(), &value.x, p->minValue().x, p->maxValue().x);
// p->set(value);
//}
//void renderVec3Property(Property* prop, const std::string& ownerName) {
// Vec3Property* p = static_cast<Vec3Property*>(prop);
// std::string name = p->guiName();
// Vec3Property::ValueType value = *p;
// ImGui::SliderFloat3((ownerName + "." + name).c_str(), &value.x, p->minValue().x, p->maxValue().x);
// p->set(value);
//}
//void renderTriggerProperty(Property* prop, const std::string& ownerName) {
// std::string name = prop->guiName();
// bool pressed = ImGui::Button((ownerName + "." + name).c_str());
// if (pressed)
// prop->set(0);
//}
}
namespace openspace {
namespace gui {
//void GuiPropertyComponent::registerProperty(properties::Property* prop) {
//registerProperty(prop->description());
//using namespace properties;
//std::string className = prop->className();
//if (className == "BoolProperty")
// _boolProperties.insert(prop);
//else if (className == "IntProperty")
// _intProperties.insert(prop);
//else if (className == "FloatProperty")
// _floatProperties.insert(prop);
//else if (className == "StringProperty")
// _stringProperties.insert(prop);
//else if (className == "Vec2Property")
// _vec2Properties.insert(prop);
//else if (className == "Vec3Property")
// _vec3Properties.insert(prop);
//else if (className == "OptionProperty")
// _optionProperty.insert(prop);
//else if (className == "TriggerProperty")
// _triggerProperty.insert(prop);
//else if (className == "SelectionProperty")
// _selectionProperty.insert(prop);
//else {
// LWARNING("Class name '" << className << "' not handled in GUI generation");
// return;
//}
//std::string fullyQualifiedId = prop->fullyQualifiedIdentifier();
//size_t pos = fullyQualifiedId.find('.');
//std::string owner = fullyQualifiedId.substr(0, pos);
//auto it = _propertiesByOwner.find(owner);
//if (it == _propertiesByOwner.end())
// _propertiesByOwner[owner] = { prop };
//else
// it->second.push_back(prop);
//}
void GuiPropertyComponent::registerProperty(properties::Property* prop) {
//void GuiPropertyComponent::registerProperty(const std::string& propertyDescription) {
using namespace properties;
std::string className = prop->className();
if (className == "BoolProperty")
_boolProperties.insert(prop);
else if (className == "IntProperty")
_intProperties.insert(prop);
else if (className == "FloatProperty")
_floatProperties.insert(prop);
else if (className == "StringProperty")
_stringProperties.insert(prop);
else if (className == "Vec2Property")
_vec2Properties.insert(prop);
else if (className == "Vec3Property")
_vec3Properties.insert(prop);
else if (className == "Vec4Property")
_vec4Properties.insert(prop);
else if (className == "OptionProperty")
_optionProperty.insert(prop);
else if (className == "TriggerProperty")
_triggerProperty.insert(prop);
else if (className == "SelectionProperty")
_selectionProperty.insert(prop);
else {
LWARNING("Class name '" << className << "' not handled in GUI generation");
return;
}
std::string fullyQualifiedId = prop->fullyQualifiedIdentifier();
size_t pos = fullyQualifiedId.find('.');
std::string owner = fullyQualifiedId.substr(0, pos);
auto it = _propertiesByOwner.find(owner);
if (it == _propertiesByOwner.end())
_propertiesByOwner[owner] = { prop };
else
it->second.push_back(prop);
//ghoul::Dictionary dictionary;
//ghoul::lua::loadDictionaryFromString(propertyDescription, dictionary);
//handleProperty(dictionary);
}
void GuiPropertyComponent::handleProperty(const ghoul::Dictionary& dictionary) {
//static const std::string TypeKey = "Type";
//static const std::string IdentifierKey = "Identifier";
//static const std::string NameKey = "Name";
//static const std::string GroupKey = "MetaData.Group";
//ghoul_assert(
// dictionary.hasKeyAndValue<std::string>(TypeKey), "Missing Type key"
//);
//ghoul_assert(
// dictionary.hasKeyAndValue<std::string>(IdentifierKey), "Missing Identifier key"
//);
//ghoul_assert(
// dictionary.hasKeyAndValue<std::string>(NameKey), "Missing Name key"
//);
//ghoul_assert(
// dictionary.hasKeyAndValue<std::string>(GroupKey), "Missing Group key"
//);
//std::string typeString = dictionary.value<std::string>(TypeKey);
//std::string identifier = dictionary.value<std::string>(IdentifierKey);
//std::string name = dictionary.value<std::string>(NameKey);
//std::string group = dictionary.value<std::string>(GroupKey);
//PropertyType type = toPropertyType(typeString);
//
//size_t pos = identifier.find('.');
//std::string owner = identifier.substr(0, pos);
//PropertyInfo info = { type, identifier, name, group };
//auto it = std::find_if(_properties.begin(), _properties.end(),
// [owner](const Property& prop) {
// return prop.owner == owner;
//});
//if (it == _properties.end()) {
// Property p;
// p.owner = owner;
// p.properties = {info};
// _properties.push_back(p);
//}
//else
// it->properties.push_back(std::move(info));
}
void GuiPropertyComponent::render() {
ImGui::Begin("Properties", &_isEnabled, size, 0.5f);
//ImGui::ShowUserGuide();
ImGui::Spacing();
for (const auto& p : _propertiesByOwner) {
if (ImGui::CollapsingHeader(p.first.c_str())) {
for (properties::Property* prop : p.second) {
if (_boolProperties.find(prop) != _boolProperties.end()) {
renderBoolProperty(prop, p.first);
continue;
}
if (_intProperties.find(prop) != _intProperties.end()) {
renderIntProperty(prop, p.first);
continue;
}
if (_floatProperties.find(prop) != _floatProperties.end()) {
renderFloatProperty(prop, p.first);
continue;
}
if (_vec2Properties.find(prop) != _vec2Properties.end()) {
renderVec2Property(prop, p.first);
continue;
}
if (_vec3Properties.find(prop) != _vec3Properties.end()) {
renderVec3Property(prop, p.first);
continue;
}
if (_vec4Properties.find(prop) != _vec4Properties.end()) {
renderVec4Property(prop, p.first);
continue;
}
if (_optionProperty.find(prop) != _optionProperty.end()) {
renderOptionProperty(prop, p.first);
continue;
}
if (_triggerProperty.find(prop) != _triggerProperty.end()) {
renderTriggerProperty(prop, p.first);
continue;
}
if (_selectionProperty.find(prop) != _selectionProperty.end()) {
renderSelectionProperty(prop, p.first);
continue;
}
}
}
}
//for (const Property& prop : _properties) {
// if (ImGui::CollapsingHeader(prop.owner.c_str())) {
// for (const PropertyInfo& info : prop.properties) {
// renderProperty(info);
// }
// }
// }
//for (const auto& p : _propertiesByOwner) {
// if (ImGui::CollapsingHeader(p.first.c_str())) {
// for (properties::Property* prop : p.second) {
// if (_boolProperties.find(prop) != _boolProperties.end()) {
// renderBoolProperty(prop, p.first);
// continue;
// }
// if (_intProperties.find(prop) != _intProperties.end()) {
// renderIntProperty(prop, p.first);
// continue;
// }
// if (_floatProperties.find(prop) != _floatProperties.end()) {
// renderFloatProperty(prop, p.first);
// continue;
// }
// if (_vec2Properties.find(prop) != _vec2Properties.end()) {
// renderVec2Property(prop, p.first);
// continue;
// }
// if (_vec3Properties.find(prop) != _vec3Properties.end()) {
// renderVec3Property(prop, p.first);
// continue;
// }
// if (_optionProperty.find(prop) != _optionProperty.end()) {
// renderOptionProperty(prop, p.first);
// continue;
// }
// if (_triggerProperty.find(prop) != _triggerProperty.end()) {
// renderTriggerProperty(prop, p.first);
// continue;
// }
// if (_selectionProperty.find(prop) != _selectionProperty.end()) {
// renderSelectionProperty(prop, p.first);
// continue;
// }
// }
// }
//}
ImGui::End();
}
GuiPropertyComponent::PropertyType GuiPropertyComponent::toPropertyType(
const std::string& name) const
{
if (name == "BoolProperty")
return PropertyType::BoolProperty;
if (name == "IntProperty")
return PropertyType::IntProperty;
if (name == "FloatProperty")
return PropertyType::FloatProperty;
if (name == "Vec2Property")
return PropertyType::Vec2Property;
if (name == "Vec3Property")
return PropertyType::Vec3Property;
if (name == "StringProperty")
return PropertyType::StringProperty;
if (name == "OptionProperty")
return PropertyType::OptionProperty;
if (name == "SelectionProperty")
return PropertyType::SelectionProperty;
if (name == "TriggerProperty")
return PropertyType::TriggerProperty;
LWARNING("Unsupported property type '" << name << "'");
return PropertyType::InvalidPropertyType;
}
void GuiPropertyComponent::renderProperty(const PropertyInfo& info) const {
switch (info.type) {
case PropertyType::BoolProperty:
{
// BoolProperty* p = static_cast<BoolProperty*>(prop);
// std::string name = p->guiName();
// BoolProperty::ValueType value = *p;
// ImGui::Checkbox((ownerName + "." + name).c_str(), &value);
// p->set(value);
break;
}
default:
LERROR("Missing case statement: {" << int(info.type) << "," << info.identifier << "}");
//ghoul_assert(false, "Missing case statement");
}
}
} // gui
} // openspace
+1 -1
View File
@@ -162,7 +162,7 @@ void Property::notifyListener() {
std::string Property::generateBaseDescription() const {
return
TypeKey + " = \"" + className() + "\", " +
IdentifierKey + " = \"" + identifier() + "\", " +
IdentifierKey + " = \"" + fullyQualifiedIdentifier() + "\", " +
NameKey + " = \"" + guiName() + "\", " +
generateMetaDataDescription() + ", " +
generateAdditionalDescription();
+6 -4
View File
@@ -25,7 +25,6 @@
#include "openspace/properties/vectorproperty.h"
#include <ghoul/lua/ghoul_lua.h>
#include <ghoul/glm.h>
#include <limits>
@@ -38,16 +37,19 @@ namespace properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
[](lua_State * state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
lua_pushnil(state); \
for (__TYPE__::size_type i = 0; i < result.length(); ++i) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
int success = lua_next(state, -2); \
if (success != 1) { \
success = false; \
return __TYPE__(0); \
} \
if (__TESTFUNC__(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
success = true; \
+2 -1
View File
@@ -441,7 +441,8 @@ bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath)
for (SceneGraphNode* node : _nodes) {
std::vector<properties::Property*> properties = node->propertiesRecursive();
for (properties::Property* p : properties) {
OsEng.gui()->registerProperty(p);
OsEng.gui()->_property.registerProperty(p);
//OsEng.gui()->_property.registerProperty(p->description());
}
}
+4 -5
View File
@@ -184,7 +184,7 @@ ScriptEngine::ScriptEngine()
}
ScriptEngine::~ScriptEngine() {
deinitialize();
//deinitialize();
}
bool ScriptEngine::initialize() {
@@ -615,15 +615,14 @@ void ScriptEngine::deserialize(SyncBuffer* syncBuffer){
}
void ScriptEngine::postSynchronizationPreDraw(){
}
void ScriptEngine::preSynchronization(){
if (!_currentSyncedScript.empty()){
runScript(_currentSyncedScript);
_currentSyncedScript.clear();
}
}
void ScriptEngine::preSynchronization(){
_mutex.lock();
if (!_queuedScripts.empty()){