From 83cfc84ac59493834bfec7c2a3e5ee9bc343ba07 Mon Sep 17 00:00:00 2001 From: Sergej Geringer Date: Thu, 19 May 2022 14:18:55 +0200 Subject: [PATCH] MegaMolGraph: feed projet directory to FilePathParams of newly created modules --- core/src/MegaMolGraph.cpp | 11 +++++++++++ core/src/MegaMolGraph_Convenience.cpp | 10 ++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/src/MegaMolGraph.cpp b/core/src/MegaMolGraph.cpp index 95e73db3ed..5c9e661e75 100644 --- a/core/src/MegaMolGraph.cpp +++ b/core/src/MegaMolGraph.cpp @@ -10,6 +10,7 @@ #include "ResourceRequest.h" #include "mmcore/AbstractSlot.h" #include "mmcore/param/ButtonParam.h" +#include "mmcore/param/FilePathParam.h" #include "mmcore/utility/String.h" #include "mmcore/utility/log/Log.h" #include "mmcore/view/AbstractView_EventConsumption.h" @@ -607,6 +608,16 @@ bool megamol::core::MegaMolGraph::add_module(ModuleInstantiationRequest_t const& // the current project directory path if (m_current_project_path->attributes.has_value()) { auto project_directory_path = m_current_project_path->attributes.value().project_directory; + + for (auto child = module_ptr->ChildList_Begin(); child != module_ptr->ChildList_End(); ++child) { + auto ps = dynamic_cast((*child).get()); + if (ps != nullptr) { + auto p = ps->Param(); + if (p != nullptr) { + p->SetProjectDirectory(project_directory_path); + } + } + } } const auto create_module = [module_description, module_ptr](auto& module_lifetime_dependencies) { diff --git a/core/src/MegaMolGraph_Convenience.cpp b/core/src/MegaMolGraph_Convenience.cpp index 54ddf122cc..4edf43382a 100644 --- a/core/src/MegaMolGraph_Convenience.cpp +++ b/core/src/MegaMolGraph_Convenience.cpp @@ -74,16 +74,22 @@ std::string megamol::core::MegaMolGraph_Convenience::SerializeCalls() const { std::string megamol::core::MegaMolGraph_Convenience::SerializeModuleParameters(std::string const& module_name) const { std::string serParams; + auto parameter_serialization = [](std::string const& name, std::string const& value) { + return "mmSetParamValue(\"" + name + "\",[=[" + value + "]=])\n"; + }; + for (auto& paramSlot : get(m_graph_ptr).EnumerateModuleParameterSlots(module_name)) { - // it seems serialiing button params is illegal + // it seems serializing button params is illegal if (auto* p_ptr = paramSlot->template Param()) { continue; } + auto name = std::string{paramSlot->FullName()}; // as FullName() prepends :: to module names, normalize multiple leading :: in parameter name path name = "::" + name.substr(name.find_first_not_of(':')); + auto value = paramSlot->Parameter()->ValueString(); - serParams.append("mmSetParamValue(\"" + name + "\",[=[" + value + "]=])\n"); + serParams.append(parameter_serialization(name, value)); } return serParams + '\n';