Skip to content

Commit

Permalink
MegaMolGraph: use relative file path for FilePathParam serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
geringsj committed Jun 2, 2022
1 parent 5c854af commit 136e135
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions core/src/MegaMolGraph_Convenience.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,35 @@ std::string megamol::core::MegaMolGraph_Convenience::SerializeCalls() const {
}

#include "mmcore/param/ButtonParam.h"
#include "mmcore/param/FilePathParam.h"
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(':'));

// file path params hold a file path which might be relative to some project directory
// asking for file_param->ValueString() gives us back an absolute path accomodated for the project directory
// instead we need to explicitly ask to the relative path
if (auto* p_ptr = paramSlot->template Param<core::param::FilePathParam>()) {
auto value = p_ptr->GetRelativePathValueString();
serParams.append(parameter_serialization(name, value));
continue;
}

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 136e135

Please sign in to comment.