Render asset tree in gui

This commit is contained in:
Emil Axelsson
2017-12-07 18:44:08 +01:00
parent f33b24d551
commit 4a43ca44f2
3 changed files with 62 additions and 32 deletions

View File

@@ -82,7 +82,6 @@ public:
void setState(State state);
void addSynchronization(std::shared_ptr<ResourceSynchronization> synchronization);
std::vector<std::shared_ptr<ResourceSynchronization>> ownSynchronizations() const;
std::vector<std::shared_ptr<ResourceSynchronization>> requiredSynchronizations() const;
void syncStateChanged(std::shared_ptr<ResourceSynchronization> sync,
ResourceSynchronization::State s);

View File

@@ -27,13 +27,18 @@
#include <modules/imgui/include/guicomponent.h>
namespace openspace {
class Asset;
}
namespace openspace::gui {
class GuiAssetComponent : public GuiComponent {
public:
GuiAssetComponent();
void render() override;
private:
void renderTree(const std::shared_ptr<openspace::Asset> a, const std::string& rootPath);
};
} // namespace openspace::gui

View File

@@ -30,52 +30,78 @@
#include <openspace/scene/assetmanager.h>
#include <openspace/scene/asset.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/file.h>
namespace {
std::string assetStateToString(openspace::Asset::State state) {
switch (state) {
case openspace::Asset::State::Loaded: return "Loaded"; break;
case openspace::Asset::State::LoadingFailed: return "LoadingFailed"; break;
case openspace::Asset::State::Synchronizing: return "Synchronizing"; break;
case openspace::Asset::State::SyncRejected: return "SyncRejected"; break;
case openspace::Asset::State::SyncResolved: return "SyncResolved"; break;
case openspace::Asset::State::Initialized: return "Initialized"; break;
case openspace::Asset::State::InitializationFailed: return "InitializationFailed"; break;
default: return "Unknown"; break;
}
}
}
namespace openspace::gui {
GuiAssetComponent::GuiAssetComponent()
: GuiComponent("Assets")
{}
void GuiAssetComponent::render() {
bool e = _isEnabled;
ImGui::Begin("Assets", &e);
_isEnabled = e;
ImGui::Columns(2);
ImGui::Separator();
AssetManager& assetManager = OsEng.assetManager();
std::vector<std::shared_ptr<Asset>> allAssets =
assetManager.rootAsset()->subTreeAssets();
std::string rootPath = "";
for (const auto& a : allAssets) {
ImGui::Text("%s", a->assetFilePath().c_str());
ImGui::NextColumn();
std::string stateText;
switch(a->state()) {
case Asset::State::Loaded: stateText = "Loaded"; break;
case Asset::State::LoadingFailed: stateText = "LoadingFailed"; break;
case Asset::State::Synchronizing: stateText = "Synchronizing"; break;
case Asset::State::SyncRejected: stateText = "SyncRejected"; break;
case Asset::State::SyncResolved: stateText = "SyncResolved"; break;
case Asset::State::Initialized: stateText = "Initialized"; break;
case Asset::State::InitializationFailed: stateText = "InitializationFailed"; break;
default: stateText = "Unknown"; break;
}
ImGui::Text("%s", stateText.c_str());
ImGui::NextColumn();
ImGui::Separator();
/*
ImGui::Text("%s", t.c_str());
ImGui::NextColumn();
ImGui::Text("%s", absPath(t).c_str());
ImGui::NextColumn();
ImGui::Separator();*/
for (const std::shared_ptr<Asset>& a : assetManager.rootAsset()->childAssets()) {
renderTree(a, rootPath);
}
ImGui::End();
}
void GuiAssetComponent::renderTree(const std::shared_ptr<openspace::Asset> asset,
const std::string& relativeToPath)
{
std::string assetPath = asset->assetFilePath();
const std::string assetDirectory = ghoul::filesystem::File(assetPath).directoryName();
if (relativeToPath != "") {
assetPath = FileSys.relativePath(assetPath, relativeToPath);
}
std::string assetText = assetPath + " " + assetStateToString(asset->state());
std::vector<std::shared_ptr<Asset>> requested = asset->requestedAssets();
std::vector<std::shared_ptr<Asset>> required = asset->requiredAssets();
if (requested.empty() && required.empty()) {
ImGui::Text(assetText.c_str());
} else if (ImGui::TreeNode(assetText.c_str())) {
ImGui::Text("Required assets:");
for (const auto& child : required) {
renderTree(child, assetDirectory);
}
ImGui::Text("Requested assets:");
for (const auto& child : requested) {
renderTree(child, assetDirectory);
}
ImGui::TreePop();
}
}
} // namespace openspace::gui