Skip to content

Commit

Permalink
Rework the plugin list window (#52)
Browse files Browse the repository at this point in the history
* Rework the plugin list window

Also be able to load a plugin from the file dialog

* Save and load plugins in a file (like Qt)

* Fix for current SOFA
  • Loading branch information
alxbilger authored Jul 11, 2022
1 parent 0da0936 commit 8daa950
Showing 1 changed file with 46 additions and 16 deletions.
62 changes: 46 additions & 16 deletions SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include <SofaImGui/ObjectColor.h>
#include <sofa/core/visual/VisualParams.h>
#include <sofa/helper/io/File.h>
#include <sofa/gui/common/BaseGUI.h>

using namespace sofa;

Expand Down Expand Up @@ -103,6 +104,9 @@ void ImGuiGUIEngine::init()

// Setup Dear ImGui style
sofaimgui::setStyle(pv);

sofa::helper::system::PluginManager::getInstance().readFromIniFile(
sofa::gui::common::BaseGUI::getConfigDirectoryPath() + "/loadedPlugins.ini");
}

void ImGuiGUIEngine::initBackend(GLFWwindow* glfwWindow)
Expand Down Expand Up @@ -1043,7 +1047,25 @@ void ImGuiGUIEngine::showPlugins(const char* const& windowNamePlugins, bool& isP
{
if (ImGui::Begin(windowNamePlugins, &isPluginsWindowOpen))
{
ImGui::Columns(2);
if (ImGui::Button("Load"))
{
std::vector<nfdfilteritem_t> nfd_filters {
{"SOFA plugin", helper::system::DynamicLibrary::extension.c_str() } };

nfdchar_t *outPath;
nfdresult_t result = NFD_OpenDialog(&outPath, nfd_filters.data(), nfd_filters.size(), NULL);
if (result == NFD_OKAY)
{
if (helper::system::FileSystem::exists(outPath))
{
helper::system::PluginManager::getInstance().loadPluginByPath(outPath);
helper::system::PluginManager::getInstance().writeToIniFile(
sofa::gui::common::BaseGUI::getConfigDirectoryPath() + "/loadedPlugins.ini");
}
}
}

ImGui::BeginChild("Plugins", ImVec2(ImGui::GetContentRegionAvail().x * 0.5f, ImGui::GetContentRegionAvail().y), false, ImGuiWindowFlags_HorizontalScrollbar);

const auto& pluginMap = helper::system::PluginManager::getInstance().getPluginMap();

Expand All @@ -1057,24 +1079,32 @@ void ImGuiGUIEngine::showPlugins(const char* const& windowNamePlugins, bool& isP
}
}

ImGui::NextColumn();
ImGui::EndChild();
ImGui::SameLine();

const auto pluginIt = pluginMap.find(selectedPlugin);
if (pluginIt != pluginMap.end())
if (!selectedPlugin.empty())
{
ImGui::Text("Plugin: %s", pluginIt->second.getModuleName());
ImGui::Text("Version: %s", pluginIt->second.getModuleVersion());
ImGui::Text("License: %s", pluginIt->second.getModuleLicense());
ImGui::Spacing();
ImGui::TextDisabled("Description:");
ImGui::TextWrapped("%s", pluginIt->second.getModuleDescription());
ImGui::Spacing();
ImGui::TextDisabled("Components:");
ImGui::TextWrapped("%s", pluginIt->second.getModuleComponentList());
ImGui::Spacing();
ImGui::TextDisabled("Path:");
ImGui::TextWrapped(selectedPlugin.c_str());
ImGui::BeginChild("selectedPlugin", ImVec2(ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y), false, ImGuiWindowFlags_HorizontalScrollbar);

const auto pluginIt = pluginMap.find(selectedPlugin);
if (pluginIt != pluginMap.end())
{
ImGui::Text("Plugin: %s", pluginIt->second.getModuleName());
ImGui::Text("Version: %s", pluginIt->second.getModuleVersion());
ImGui::Text("License: %s", pluginIt->second.getModuleLicense());
ImGui::Spacing();
ImGui::TextDisabled("Description:");
ImGui::TextWrapped("%s", pluginIt->second.getModuleDescription());
ImGui::Spacing();
ImGui::TextDisabled("Components:");
ImGui::TextWrapped("%s", pluginIt->second.getModuleComponentList());
ImGui::Spacing();
ImGui::TextDisabled("Path:");
ImGui::TextWrapped(selectedPlugin.c_str());
}
}

ImGui::EndChild();
}
ImGui::End();
}
Expand Down

0 comments on commit 8daa950

Please sign in to comment.