Skip to content

Commit

Permalink
MegaMolGraph: feed projet directory to FilePathParams of newly create…
Browse files Browse the repository at this point in the history
…d modules
  • Loading branch information
geringsj committed May 19, 2023
1 parent 58c547e commit 83cfc84
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 11 additions & 0 deletions core/src/MegaMolGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<param::ParamSlot*>((*child).get());
if (ps != nullptr) {
auto p = ps->Param<param::FilePathParam>();
if (p != nullptr) {
p->SetProjectDirectory(project_directory_path);
}
}
}
}

const auto create_module = [module_description, module_ptr](auto& module_lifetime_dependencies) {
Expand Down
10 changes: 8 additions & 2 deletions core/src/MegaMolGraph_Convenience.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<core::param::ButtonParam>()) {
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';
Expand Down

0 comments on commit 83cfc84

Please sign in to comment.