From 00ee8242b6909fdd1268bef3f75b2fe63098ca86 Mon Sep 17 00:00:00 2001 From: gralkapk Date: Fri, 30 Jun 2023 16:53:07 +0200 Subject: [PATCH 1/8] wip parameter mark --- core/include/mmcore/MegaMolGraph.h | 2 ++ core/include/mmcore/param/AbstractParam.h | 11 +++++++++++ core/include/mmcore/param/AbstractParamPresentation.h | 11 +++++++++++ core/src/MegaMolGraph.cpp | 11 +++++++++++ core/src/param/AbstractParamPresentation.cpp | 8 ++++++++ frontend/services/gui/src/graph/Parameter.cpp | 8 ++++++++ .../lua_service_wrapper/Lua_Service_Wrapper.cpp | 10 ++++++++++ 7 files changed, 61 insertions(+) diff --git a/core/include/mmcore/MegaMolGraph.h b/core/include/mmcore/MegaMolGraph.h index ad6fbcb632..72464561a6 100644 --- a/core/include/mmcore/MegaMolGraph.h +++ b/core/include/mmcore/MegaMolGraph.h @@ -67,6 +67,8 @@ class MegaMolGraph { bool SetParameter(std::string const& paramName, std::string const& value); + bool SetParameterHighlight(std::string const& paramName, bool is_highlight); + megamol::core::param::ParamSlot* FindParameterSlot(std::string const& paramName) const; std::vector EnumerateModuleParameters(std::string const& moduleName) const; diff --git a/core/include/mmcore/param/AbstractParam.h b/core/include/mmcore/param/AbstractParam.h index d1dc4db321..1e99970a1a 100644 --- a/core/include/mmcore/param/AbstractParam.h +++ b/core/include/mmcore/param/AbstractParam.h @@ -110,6 +110,17 @@ class AbstractParam { } } + bool IsGUIHighlight() const { + return gui_presentation.IsHighlight(); + } + + void SetGUIHighlight(bool highlight) { + if (gui_presentation.IsHighlight() != highlight) { + gui_presentation.SetHighlight(highlight); + indicatePresentationChange(); + } + } + inline AbstractParamPresentation::Presentation GetGUIPresentation() const { return gui_presentation.GetGUIPresentation(); } diff --git a/core/include/mmcore/param/AbstractParamPresentation.h b/core/include/mmcore/param/AbstractParamPresentation.h index c79fa93528..4f7179ed61 100644 --- a/core/include/mmcore/param/AbstractParamPresentation.h +++ b/core/include/mmcore/param/AbstractParamPresentation.h @@ -103,6 +103,14 @@ class AbstractParamPresentation { this->read_only = read_only; } + bool IsHighlight() const { + return highlight; + } + + void SetHighlight(bool highlight) { + this->highlight = highlight; + } + /** * Set presentation of parameter in GUI. * @@ -179,6 +187,9 @@ class AbstractParamPresentation { /* Make parameter read-only in the GUI. */ bool read_only; + /* Highlight the parameter in the GUI */ + bool highlight; + /* Presentation (= widget representation) of parameter in the GUI. */ AbstractParamPresentation::Presentation presentation; diff --git a/core/src/MegaMolGraph.cpp b/core/src/MegaMolGraph.cpp index 94c5966e03..d3df6c00a0 100644 --- a/core/src/MegaMolGraph.cpp +++ b/core/src/MegaMolGraph.cpp @@ -222,6 +222,17 @@ bool megamol::core::MegaMolGraph::SetParameter(std::string const& paramName, std return true; } +bool megamol::core::MegaMolGraph::SetParameterHighlight(std::string const& paramName, bool is_highlight) { + auto param_slot_ptr = FindParameterSlot(paramName); + auto param_ptr = getParameterFromParamSlot(param_slot_ptr); + + if (!param_ptr) + return false; + param_ptr->SetGUIHighlight(is_highlight); + + return true; +} + bool megamol::core::MegaMolGraph::Broadcast_graph_subscribers_parameter_changes() { for (auto& subscriber : graph_subscribers.subscribers) { diff --git a/core/src/param/AbstractParamPresentation.cpp b/core/src/param/AbstractParamPresentation.cpp index 9453e63abf..3bd7447ece 100644 --- a/core/src/param/AbstractParamPresentation.cpp +++ b/core/src/param/AbstractParamPresentation.cpp @@ -54,6 +54,7 @@ std::string AbstractParamPresentation::GetTypeName(ParamType type) { AbstractParamPresentation::AbstractParamPresentation() : visible(true) , read_only(false) + , highlight(false) , presentation(AbstractParamPresentation::Presentation::Basic) , compatible(Presentation::Basic) , initialised(false) @@ -89,6 +90,7 @@ void AbstractParamPresentation::InitPresentation(AbstractParamPresentation::Para this->SetGUIVisible(visible); this->SetGUIReadOnly(read_only); + this->SetHighlight(highlight); // Initialize presentations depending on parameter type switch (param_type) { @@ -203,6 +205,10 @@ bool AbstractParamPresentation::StateFromJSON(const nlohmann::json& in_json, con valid &= megamol::core::utility::get_json_value(gui_state, {"gui_read-only"}, &gui_read_only); + bool gui_highlight = false; + valid &= + megamol::core::utility::get_json_value(gui_state, {"gui_highlicht"}, &gui_highlight); + int presentation_mode = 0; valid &= megamol::core::utility::get_json_value( gui_state, {"gui_presentation_mode"}, &presentation_mode); @@ -211,6 +217,7 @@ bool AbstractParamPresentation::StateFromJSON(const nlohmann::json& in_json, con if (valid) { this->SetGUIVisible(gui_visibility); this->SetGUIReadOnly(gui_read_only); + this->SetHighlight(gui_highlight); this->SetGUIPresentation(gui_presentation_mode); return true; } @@ -234,6 +241,7 @@ bool AbstractParamPresentation::StateToJSON(nlohmann::json& inout_json, const st // Append to given json inout_json[GUI_JSON_TAG_GUISTATE_PARAMETERS][param_fullname]["gui_visibility"] = this->IsGUIVisible(); inout_json[GUI_JSON_TAG_GUISTATE_PARAMETERS][param_fullname]["gui_read-only"] = this->IsGUIReadOnly(); + inout_json[GUI_JSON_TAG_GUISTATE_PARAMETERS][param_fullname]["gui_highlight"] = this->IsHighlight(); inout_json[GUI_JSON_TAG_GUISTATE_PARAMETERS][param_fullname]["gui_presentation_mode"] = static_cast(this->GetGUIPresentation()); } catch (...) { diff --git a/frontend/services/gui/src/graph/Parameter.cpp b/frontend/services/gui/src/graph/Parameter.cpp index b712cd7411..cadb8de952 100644 --- a/frontend/services/gui/src/graph/Parameter.cpp +++ b/frontend/services/gui/src/graph/Parameter.cpp @@ -501,6 +501,7 @@ bool megamol::gui::Parameter::ReadNewCoreParameterToNewParameter(megamol::core:: out_param->SetGUIVisible(parameter_ptr->IsGUIVisible()); out_param->SetGUIReadOnly(parameter_ptr->IsGUIReadOnly()); out_param->SetGUIPresentation(parameter_ptr->GetGUIPresentation()); + out_param->SetHighlight(parameter_ptr->IsGUIHighlight()); if (save_core_param_pointer) { out_param->core_param_ptr = parameter_ptr; } @@ -516,6 +517,7 @@ bool megamol::gui::Parameter::ReadCoreParameterToParameter( out_param.SetGUIVisible(in_param_ptr->IsGUIVisible()); out_param.SetGUIReadOnly(in_param_ptr->IsGUIReadOnly()); out_param.SetGUIPresentation(in_param_ptr->GetGUIPresentation()); + out_param.SetHighlight(in_param_ptr->IsGUIHighlight()); /// XXX Prioritizing currently changed value from GUI /// Do not read param value from core param if gui param has already updated value @@ -829,6 +831,9 @@ bool megamol::gui::Parameter::draw_parameter(megamol::gui::Parameter::WidgetScop gui_utils::PushReadOnly(this->IsGUIReadOnly()); } + if (this->IsHighlight()) + ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(255, 0, 0, 255)); + switch (this->GetGUIPresentation()) { // BASIC /////////////////////////////////////////////////// case (Present_t::Basic): { @@ -1229,6 +1234,9 @@ bool megamol::gui::Parameter::draw_parameter(megamol::gui::Parameter::WidgetScop break; } + if (this->IsHighlight()) + ImGui::PopStyleColor(); + // LOCAL ----------------------------------------------------------- if (scope == megamol::gui::Parameter::WidgetScope::LOCAL) { // Reset read only diff --git a/frontend/services/lua_service_wrapper/Lua_Service_Wrapper.cpp b/frontend/services/lua_service_wrapper/Lua_Service_Wrapper.cpp index b6c8887c38..d5bfae7986 100644 --- a/frontend/services/lua_service_wrapper/Lua_Service_Wrapper.cpp +++ b/frontend/services/lua_service_wrapper/Lua_Service_Wrapper.cpp @@ -597,6 +597,16 @@ void Lua_Service_Wrapper::fill_graph_manipulation_callbacks(void* callbacks_coll return VoidResult{}; }}); + callbacks.add("mmSetParamHighlight", + "(string name, bool is_highlight)\n\tHighlight parameter slot.", + {[&](std::string paramName, bool is_highlight) -> VoidResult { + if (!graph.SetParameterHighlight(paramName, is_highlight)) { + return Error{ + "parameter highlight could not be set: " + paramName + " : " + std::to_string(is_highlight)}; + } + return VoidResult{}; + }}); + callbacks.add("mmCreateParamGroup", "(string name, string size)\n\tGenerate a param group that can only be set at once. Sets are queued until size " "is reached.", From 84406282683139070b2602ff9799a58f9c3bedf5 Mon Sep 17 00:00:00 2001 From: gralkapk Date: Fri, 30 Jun 2023 17:54:57 +0200 Subject: [PATCH 2/8] wip --- frontend/services/gui/src/graph/Parameter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/services/gui/src/graph/Parameter.cpp b/frontend/services/gui/src/graph/Parameter.cpp index cadb8de952..ae7c537131 100644 --- a/frontend/services/gui/src/graph/Parameter.cpp +++ b/frontend/services/gui/src/graph/Parameter.cpp @@ -686,6 +686,7 @@ bool megamol::gui::Parameter::WriteCoreParameterGUIState( out_param_ptr->SetGUIVisible(in_param.IsGUIVisible()); out_param_ptr->SetGUIReadOnly(in_param.IsGUIReadOnly()); out_param_ptr->SetGUIPresentation(in_param.GetGUIPresentation()); + out_param_ptr->SetGUIHighlight(in_param.IsHighlight()); return true; } From 11fb6f4c74e1d8ef2d96a9c185d6dea1347c9808 Mon Sep 17 00:00:00 2001 From: gralkapk Date: Fri, 30 Jun 2023 17:55:28 +0200 Subject: [PATCH 3/8] open group header, if one parameter is marked --- frontend/services/gui/src/windows/ParameterList.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frontend/services/gui/src/windows/ParameterList.cpp b/frontend/services/gui/src/windows/ParameterList.cpp index 2eb0e8c494..9741d33714 100644 --- a/frontend/services/gui/src/windows/ParameterList.cpp +++ b/frontend/services/gui/src/windows/ParameterList.cpp @@ -152,6 +152,15 @@ bool ParameterList::Draw() { std::string module_label = module_ptr->FullName(); ImGui::PushID(module_ptr->UID()); + auto const& param_vec = module_ptr->Parameters(); + bool highlight = false; + for (auto const& param : param_vec) { + if (param.IsHighlight()) + highlight = true; + } + if (highlight) + ImGui::SetNextItemOpen(true); + // Draw module header bool module_header_open = gui_utils::GroupHeader( megamol::gui::HeaderType::MODULE, module_label, module_search_string, override_header_state); From 721cca8d6fc025b5ad49523e483c93443fabf212 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Tue, 4 Jul 2023 17:54:37 +0200 Subject: [PATCH 4/8] cleaned param presentation interface --- core/include/mmcore/param/AbstractParam.h | 15 +++- .../mmcore/param/AbstractParamPresentation.h | 6 +- core/src/param/AbstractParamPresentation.cpp | 12 +-- frontend/services/gui/src/graph/Graph.cpp | 4 +- frontend/services/gui/src/graph/Parameter.cpp | 81 ++++++++----------- frontend/services/gui/src/graph/Parameter.h | 61 ++++++++++---- .../gui/src/graph/ParameterGroups.cpp | 12 +-- .../gui/src/windows/ParameterList.cpp | 2 +- 8 files changed, 103 insertions(+), 90 deletions(-) diff --git a/core/include/mmcore/param/AbstractParam.h b/core/include/mmcore/param/AbstractParam.h index 1e99970a1a..d3333a14d3 100644 --- a/core/include/mmcore/param/AbstractParam.h +++ b/core/include/mmcore/param/AbstractParam.h @@ -111,12 +111,12 @@ class AbstractParam { } bool IsGUIHighlight() const { - return gui_presentation.IsHighlight(); + return gui_presentation.IsGUIHighlight(); } void SetGUIHighlight(bool highlight) { - if (gui_presentation.IsHighlight() != highlight) { - gui_presentation.SetHighlight(highlight); + if (gui_presentation.IsGUIHighlight() != highlight) { + gui_presentation.SetGUIHighlight(highlight); indicatePresentationChange(); } } @@ -132,6 +132,15 @@ class AbstractParam { } } + void SetParamPresentation(const AbstractParamPresentation& other) { + this->gui_presentation = other; + indicatePresentationChange(); + } + + const AbstractParamPresentation& GetParamPresentation() const { + return this->gui_presentation; + } + protected: /** * Ctor. diff --git a/core/include/mmcore/param/AbstractParamPresentation.h b/core/include/mmcore/param/AbstractParamPresentation.h index 4f7179ed61..b8b8648b9d 100644 --- a/core/include/mmcore/param/AbstractParamPresentation.h +++ b/core/include/mmcore/param/AbstractParamPresentation.h @@ -103,11 +103,11 @@ class AbstractParamPresentation { this->read_only = read_only; } - bool IsHighlight() const { + bool IsGUIHighlight() const { return highlight; } - void SetHighlight(bool highlight) { + void SetGUIHighlight(bool highlight) { this->highlight = highlight; } @@ -171,7 +171,7 @@ class AbstractParamPresentation { * De-/Serialization of parameters GUI state. */ bool StateFromJSON(const nlohmann::json& in_json, const std::string& param_fullname); - bool StateToJSON(nlohmann::json& inout_json, const std::string& param_fullname); + bool StateToJSON(nlohmann::json& inout_json, const std::string& param_fullname) const; AbstractParamPresentation(); diff --git a/core/src/param/AbstractParamPresentation.cpp b/core/src/param/AbstractParamPresentation.cpp index 3bd7447ece..e24d99eb0f 100644 --- a/core/src/param/AbstractParamPresentation.cpp +++ b/core/src/param/AbstractParamPresentation.cpp @@ -88,10 +88,6 @@ void AbstractParamPresentation::InitPresentation(AbstractParamPresentation::Para this->initialised = true; - this->SetGUIVisible(visible); - this->SetGUIReadOnly(read_only); - this->SetHighlight(highlight); - // Initialize presentations depending on parameter type switch (param_type) { case (ParamType::BOOL): { @@ -207,7 +203,7 @@ bool AbstractParamPresentation::StateFromJSON(const nlohmann::json& in_json, con bool gui_highlight = false; valid &= - megamol::core::utility::get_json_value(gui_state, {"gui_highlicht"}, &gui_highlight); + megamol::core::utility::get_json_value(gui_state, {"gui_highlight"}, &gui_highlight); int presentation_mode = 0; valid &= megamol::core::utility::get_json_value( @@ -217,7 +213,7 @@ bool AbstractParamPresentation::StateFromJSON(const nlohmann::json& in_json, con if (valid) { this->SetGUIVisible(gui_visibility); this->SetGUIReadOnly(gui_read_only); - this->SetHighlight(gui_highlight); + this->SetGUIHighlight(gui_highlight); this->SetGUIPresentation(gui_presentation_mode); return true; } @@ -235,13 +231,13 @@ bool AbstractParamPresentation::StateFromJSON(const nlohmann::json& in_json, con } -bool AbstractParamPresentation::StateToJSON(nlohmann::json& inout_json, const std::string& param_fullname) { +bool AbstractParamPresentation::StateToJSON(nlohmann::json& inout_json, const std::string& param_fullname) const { try { // Append to given json inout_json[GUI_JSON_TAG_GUISTATE_PARAMETERS][param_fullname]["gui_visibility"] = this->IsGUIVisible(); inout_json[GUI_JSON_TAG_GUISTATE_PARAMETERS][param_fullname]["gui_read-only"] = this->IsGUIReadOnly(); - inout_json[GUI_JSON_TAG_GUISTATE_PARAMETERS][param_fullname]["gui_highlight"] = this->IsHighlight(); + inout_json[GUI_JSON_TAG_GUISTATE_PARAMETERS][param_fullname]["gui_highlight"] = this->IsGUIHighlight(); inout_json[GUI_JSON_TAG_GUISTATE_PARAMETERS][param_fullname]["gui_presentation_mode"] = static_cast(this->GetGUIPresentation()); } catch (...) { diff --git a/frontend/services/gui/src/graph/Graph.cpp b/frontend/services/gui/src/graph/Graph.cpp index 8439fc4c0e..0924be1e43 100644 --- a/frontend/services/gui/src/graph/Graph.cpp +++ b/frontend/services/gui/src/graph/Graph.cpp @@ -184,9 +184,7 @@ ModulePtr_t megamol::gui::Graph::AddModule(const ModuleStockVector_t& stock_modu p.stepsize, p.param_name, p.description); parameter.SetParentModuleName(mod_ptr->FullName()); parameter.SetValueString(p.default_value, true, true); - parameter.SetGUIVisible(p.gui_visibility); - parameter.SetGUIReadOnly(p.gui_read_only); - parameter.SetGUIPresentation(p.gui_presentation); + parameter.SetParamPresentation(p.GetParamPresentation()); mod_ptr->Parameters().emplace_back(parameter); } diff --git a/frontend/services/gui/src/graph/Parameter.cpp b/frontend/services/gui/src/graph/Parameter.cpp index ae7c537131..35d521491f 100644 --- a/frontend/services/gui/src/graph/Parameter.cpp +++ b/frontend/services/gui/src/graph/Parameter.cpp @@ -35,8 +35,7 @@ using namespace megamol::gui; megamol::gui::Parameter::Parameter(ImGuiID uid, ParamType_t type, Storage_t store, Min_t minv, Max_t maxv, Step_t step, const std::string& param_name, const std::string& description) - : megamol::core::param::AbstractParamPresentation() - , uid(uid) + : uid(uid) , type(type) , param_name(param_name) , parent_module_name() @@ -50,6 +49,7 @@ megamol::gui::Parameter::Parameter(ImGuiID uid, ParamType_t type, Storage_t stor , default_value() , default_value_mismatch(false) , value_dirty(false) + , gui_present() , gui_extended(false) , gui_float_format("%.7f") , gui_help() @@ -73,7 +73,7 @@ megamol::gui::Parameter::Parameter(ImGuiID uid, ParamType_t type, Storage_t stor , tf_editor_hash(0) , filepath_scroll_xmax(false) { - this->InitPresentation(type); + this->gui_present.InitPresentation(type); // Initialize variant types which should/can not be changed afterwards. // Default ctor of variants initializes std::monostate. @@ -316,10 +316,7 @@ bool megamol::gui::Parameter::ReadNewCoreParameterToStockParameter( out_param.param_name = std::string(in_param_slot.Name().PeekBuffer()); out_param.description = std::string(in_param_slot.Description().PeekBuffer()); - - out_param.gui_visibility = parameter_ptr->IsGUIVisible(); - out_param.gui_read_only = parameter_ptr->IsGUIReadOnly(); - out_param.gui_presentation = static_cast(parameter_ptr->GetGUIPresentation()); + out_param.SetParamPresentation(parameter_ptr->GetParamPresentation()); if (auto* p_ptr = in_param_slot.Param()) { out_param.type = ParamType_t::BUTTON; @@ -497,11 +494,8 @@ bool megamol::gui::Parameter::ReadNewCoreParameterToNewParameter(megamol::core:: } out_param->SetParentModuleName(parent_module_name); + out_param->SetParamPresentation(parameter_ptr->GetParamPresentation()); - out_param->SetGUIVisible(parameter_ptr->IsGUIVisible()); - out_param->SetGUIReadOnly(parameter_ptr->IsGUIReadOnly()); - out_param->SetGUIPresentation(parameter_ptr->GetGUIPresentation()); - out_param->SetHighlight(parameter_ptr->IsGUIHighlight()); if (save_core_param_pointer) { out_param->core_param_ptr = parameter_ptr; } @@ -514,10 +508,7 @@ bool megamol::gui::Parameter::ReadCoreParameterToParameter( std::shared_ptr in_param_ptr, megamol::gui::Parameter& out_param, bool set_default_val, bool set_dirty) { - out_param.SetGUIVisible(in_param_ptr->IsGUIVisible()); - out_param.SetGUIReadOnly(in_param_ptr->IsGUIReadOnly()); - out_param.SetGUIPresentation(in_param_ptr->GetGUIPresentation()); - out_param.SetHighlight(in_param_ptr->IsGUIHighlight()); + out_param.SetParamPresentation(in_param_ptr->GetParamPresentation()); /// XXX Prioritizing currently changed value from GUI /// Do not read param value from core param if gui param has already updated value @@ -683,10 +674,7 @@ bool megamol::gui::Parameter::ReadNewCoreParameterToExistingParameter(megamol::c bool megamol::gui::Parameter::WriteCoreParameterGUIState( megamol::gui::Parameter& in_param, std::shared_ptr out_param_ptr) { - out_param_ptr->SetGUIVisible(in_param.IsGUIVisible()); - out_param_ptr->SetGUIReadOnly(in_param.IsGUIReadOnly()); - out_param_ptr->SetGUIPresentation(in_param.GetGUIPresentation()); - out_param_ptr->SetGUIHighlight(in_param.IsHighlight()); + out_param_ptr->SetParamPresentation(in_param.GetParamPresentation()); return true; } @@ -710,15 +698,15 @@ bool megamol::gui::Parameter::Draw(megamol::gui::Parameter::WidgetScope scope) { switch (scope) { case (WidgetScope::LOCAL): { - if (this->IsGUIVisible() || this->gui_extended) { + if (this->gui_present.IsGUIVisible() || this->gui_extended) { ImGui::BeginGroup(); if (this->gui_extended) { /// PREFIX --------------------------------------------- // Visibility - if (ImGui::RadioButton("###visible", this->IsGUIVisible())) { - this->SetGUIVisible(!this->IsGUIVisible()); + if (ImGui::RadioButton("###visible", this->gui_present.IsGUIVisible())) { + this->gui_present.SetGUIVisible(!this->gui_present.IsGUIVisible()); this->ForceSetGUIStateDirty(); } this->gui_tooltip.ToolTip("Visibility (Basic Mode)"); @@ -726,9 +714,9 @@ bool megamol::gui::Parameter::Draw(megamol::gui::Parameter::WidgetScope scope) { ImGui::SameLine(); // Read-only option - bool read_only = this->IsGUIReadOnly(); + bool read_only = this->gui_present.IsGUIReadOnly(); if (ImGui::Checkbox("###readonly", &read_only)) { - this->SetGUIReadOnly(read_only); + this->gui_present.SetGUIReadOnly(read_only); this->ForceSetGUIStateDirty(); } this->gui_tooltip.ToolTip("Read-Only"); @@ -737,13 +725,13 @@ bool megamol::gui::Parameter::Draw(megamol::gui::Parameter::WidgetScope scope) { // Presentation ButtonWidgets::OptionButton(ButtonWidgets::ButtonStyle::POINT_CIRCLE, "param_present_button", "", - (this->GetGUIPresentation() != Present_t::Basic), false); + (this->gui_present.GetGUIPresentation() != Present_t::Basic), false); if (ImGui::BeginPopupContextItem("param_present_button_context", ImGuiPopupFlags_MouseButtonLeft)) { - for (auto& present_name_pair : this->GetPresentationNameMap()) { - if (this->IsPresentationCompatible(present_name_pair.first)) { + for (auto& present_name_pair : this->gui_present.GetPresentationNameMap()) { + if (this->gui_present.IsPresentationCompatible(present_name_pair.first)) { if (ImGui::MenuItem(present_name_pair.second.c_str(), nullptr, - (present_name_pair.first == this->GetGUIPresentation()))) { - this->SetGUIPresentation(present_name_pair.first); + (present_name_pair.first == this->gui_present.GetGUIPresentation()))) { + this->gui_present.SetGUIPresentation(present_name_pair.first); this->ForceSetGUIStateDirty(); } } @@ -824,18 +812,16 @@ bool megamol::gui::Parameter::draw_parameter(megamol::gui::Parameter::WidgetScop using T = std::decay_t; // LOCAL ----------------------------------------------------------- + // Set style of local parameters if (scope == megamol::gui::Parameter::WidgetScope::LOCAL) { - // Set general proportional item width float widget_width = ImGui::GetContentRegionAvail().x * 0.65f; ImGui::PushItemWidth(widget_width); - // Set read only - gui_utils::PushReadOnly(this->IsGUIReadOnly()); + gui_utils::PushReadOnly(this->gui_present.IsGUIReadOnly()); + if (this->gui_present.IsGUIHighlight()) + ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(255, 0, 0, 255)); } - if (this->IsHighlight()) - ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(255, 0, 0, 255)); - - switch (this->GetGUIPresentation()) { + switch (this->gui_present.GetGUIPresentation()) { // BASIC /////////////////////////////////////////////////// case (Present_t::Basic): { // BOOL ------------------------------------------------ @@ -1235,15 +1221,12 @@ bool megamol::gui::Parameter::draw_parameter(megamol::gui::Parameter::WidgetScop break; } - if (this->IsHighlight()) - ImGui::PopStyleColor(); - // LOCAL ----------------------------------------------------------- if (scope == megamol::gui::Parameter::WidgetScope::LOCAL) { - // Reset read only - gui_utils::PopReadOnly(this->IsGUIReadOnly()); - // Reset item width + gui_utils::PopReadOnly(this->gui_present.IsGUIReadOnly()); ImGui::PopItemWidth(); + if (this->gui_present.IsGUIHighlight()) + ImGui::PopStyleColor(); } }; @@ -1252,7 +1235,7 @@ bool megamol::gui::Parameter::draw_parameter(megamol::gui::Parameter::WidgetScop if (error) { megamol::core::utility::log::Log::DefaultLog.WriteError( "[GUI] No widget presentation '%s' available for '%s' . [%s, %s, line %d]\n", - this->GetPresentationName(this->GetGUIPresentation()).c_str(), + this->gui_present.GetPresentationName(this->gui_present.GetGUIPresentation()).c_str(), megamol::core::param::AbstractParamPresentation::GetTypeName(this->type).c_str(), __FILE__, __FUNCTION__, __LINE__); } @@ -1299,7 +1282,7 @@ bool megamol::gui::Parameter::widget_bool( // LOCAL ----------------------------------------------------------- if (scope == megamol::gui::Parameter::WidgetScope::LOCAL) { - auto p = this->GetGUIPresentation(); + auto p = this->gui_present.GetGUIPresentation(); if (p == Present_t::Checkbox) { retval = ImGui::Checkbox(label.c_str(), &val); @@ -1617,7 +1600,7 @@ bool megamol::gui::Parameter::widget_int( ImGui::SameLine(); // Value - auto p = this->GetGUIPresentation(); + auto p = this->gui_present.GetGUIPresentation(); if (p == Present_t::Slider) { const int offset = 2; auto slider_min = (minv > INT_MIN) ? (minv) : ((val == 0) ? (-offset) : (val - (offset * val))); @@ -1686,7 +1669,7 @@ bool megamol::gui::Parameter::widget_float(megamol::gui::Parameter::WidgetScope } ImGui::BeginGroup(); - auto p = this->GetGUIPresentation(); + auto p = this->gui_present.GetGUIPresentation(); // Min Max Step Option if ((p == Present_t::Basic) || (p == Present_t::Slider) || (p == Present_t::Drag)) { @@ -1766,7 +1749,7 @@ bool megamol::gui::Parameter::widget_vector2f(megamol::gui::Parameter::WidgetSco this->gui_widget_value = val; } - auto p = this->GetGUIPresentation(); + auto p = this->gui_present.GetGUIPresentation(); ImGui::BeginGroup(); // Min Max Option @@ -1844,7 +1827,7 @@ bool megamol::gui::Parameter::widget_vector3f(megamol::gui::Parameter::WidgetSco this->gui_widget_value = val; } - auto p = this->GetGUIPresentation(); + auto p = this->gui_present.GetGUIPresentation(); ImGui::BeginGroup(); // Min Max Option @@ -1924,7 +1907,7 @@ bool megamol::gui::Parameter::widget_vector4f(megamol::gui::Parameter::WidgetSco this->gui_widget_value = val; } - auto p = this->GetGUIPresentation(); + auto p = this->gui_present.GetGUIPresentation(); ImGui::BeginGroup(); // Min Max Option diff --git a/frontend/services/gui/src/graph/Parameter.h b/frontend/services/gui/src/graph/Parameter.h index 9a72f932c8..b66b2393eb 100644 --- a/frontend/services/gui/src/graph/Parameter.h +++ b/frontend/services/gui/src/graph/Parameter.h @@ -18,6 +18,9 @@ #include +using namespace megamol::core::param; + + namespace megamol::gui { @@ -33,14 +36,14 @@ typedef std::shared_ptr ModulePtr_t; // Types typedef std::vector ParamVector_t; typedef std::map EnumStorage_t; -typedef std::pair +typedef std::pair FilePathStorage_t; /** ************************************************************************ * Defines parameter data structure for graph */ -class Parameter : public megamol::core::param::AbstractParamPresentation { +class Parameter { public: /* * Globally scoped widgets (widget parts) are always called each frame. @@ -89,7 +92,7 @@ class Parameter : public megamol::core::param::AbstractParamPresentation { megamol::core::view::KeyCode, // BUTTON EnumStorage_t, // ENUM FilePathStorage_t, // FILEPATH - megamol::core::param::FlexEnumParam::Storage_t // FLEXENUM + FlexEnumParam::Storage_t // FLEXENUM > Storage_t; @@ -102,35 +105,40 @@ class Parameter : public megamol::core::param::AbstractParamPresentation { Max_t maxval; Step_t stepsize; Storage_t storage; - bool gui_visibility; - bool gui_read_only; - Present_t gui_presentation; + AbstractParamPresentation gui_present; + + void SetParamPresentation(const AbstractParamPresentation& other) { + this->gui_present = other; + } + const AbstractParamPresentation& GetParamPresentation() const { + return this->gui_present; + } }; // STATIC --------------------- static bool ReadNewCoreParameterToStockParameter( - megamol::core::param::ParamSlot& in_param_slot, megamol::gui::Parameter::StockParameter& out_param); + ParamSlot& in_param_slot, megamol::gui::Parameter::StockParameter& out_param); - static bool ReadNewCoreParameterToNewParameter(megamol::core::param::ParamSlot& in_param_slot, + static bool ReadNewCoreParameterToNewParameter(ParamSlot& in_param_slot, std::shared_ptr& out_param, bool set_default_val, bool set_dirty, bool save_core_param_pointer, const std::string& parent_module_name); - static bool ReadCoreParameterToParameter(std::shared_ptr in_param_ptr, + static bool ReadCoreParameterToParameter(std::shared_ptr in_param_ptr, megamol::gui::Parameter& out_param, bool set_default_val, bool set_dirty); - static bool ReadNewCoreParameterToExistingParameter(megamol::core::param::ParamSlot& in_param_slot, + static bool ReadNewCoreParameterToExistingParameter(ParamSlot& in_param_slot, megamol::gui::Parameter& out_param, bool set_default_val, bool set_dirty, bool save_core_param_pointer); static bool WriteCoreParameterGUIState( - megamol::gui::Parameter& in_param, std::shared_ptr out_param_ptr); + megamol::gui::Parameter& in_param, std::shared_ptr out_param_ptr); // ---------------------------- Parameter(ImGuiID uid, ParamType_t type, Storage_t store, Min_t minval, Max_t maxval, Step_t step, const std::string& param_name, const std::string& description); - ~Parameter() override; + ~Parameter(); bool Draw(WidgetScope scope); @@ -236,13 +244,18 @@ class Parameter : public megamol::core::param::AbstractParamPresentation { inline const bool IsExtended() const { return this->gui_extended; } - inline std::shared_ptr CoreParamPtr() const { + inline std::shared_ptr CoreParamPtr() const { return this->core_param_ptr; } inline void ResetCoreParamPtr() { this->core_param_ptr = nullptr; } + // Returning cont& is not working since none const access to member functions of AbstractParamPresentation is required + const AbstractParamPresentation& GetParamPresentation() const { + return this->gui_present; + } + // SET ---------------------------------------------------------------- inline void SetParentModuleName(const std::string& name) { @@ -273,6 +286,19 @@ class Parameter : public megamol::core::param::AbstractParamPresentation { this->gui_extended = extended; } + inline void SetParamPresentation(const AbstractParamPresentation& other) { + this->gui_present = other; + } + + // State ---------------------------------------------------------------- + + bool StateFromJSON(const nlohmann::json& in_json, const std::string& param_fullname) { + return this->gui_present.StateFromJSON(in_json, param_fullname); + } + bool StateToJSON(nlohmann::json& inout_json, const std::string& param_fullname) const { + return this->gui_present.StateToJSON(inout_json, param_fullname); + } + private: // VARIABLES -------------------------------------------------------------- @@ -282,7 +308,7 @@ class Parameter : public megamol::core::param::AbstractParamPresentation { std::string parent_module_name; /// :::: std::string description; - std::shared_ptr core_param_ptr; + std::shared_ptr core_param_ptr; Min_t minval; Max_t maxval; @@ -294,6 +320,7 @@ class Parameter : public megamol::core::param::AbstractParamPresentation { bool default_value_mismatch; bool value_dirty; + AbstractParamPresentation gui_present; bool gui_extended; const std::string gui_float_format; std::string gui_help; @@ -329,7 +356,7 @@ class Parameter : public megamol::core::param::AbstractParamPresentation { bool widget_color(WidgetScope scope, const std::string& label, glm::vec4& val); bool widget_enum(WidgetScope scope, const std::string& label, int& val, EnumStorage_t store); bool widget_flexenum(WidgetScope scope, const std::string& label, std::string& val, - const megamol::core::param::FlexEnumParam::Storage_t& store); + const FlexEnumParam::Storage_t& store); bool widget_filepath( WidgetScope scope, const std::string& label, std::filesystem::path& val, const FilePathStorage_t& store); bool widget_ternary(WidgetScope scope, const std::string& label, vislib::math::Ternary& val); @@ -362,7 +389,7 @@ void Parameter::SetValue(T val, bool set_default_val, bool set_dirty) { } if (this->type == ParamType_t::FLEXENUM) { // Update storage - auto flex_storage = this->GetStorage(); + auto flex_storage = this->GetStorage(); flex_storage.insert(std::get(this->value)); this->SetStorage(flex_storage); } else if (this->type == ParamType_t::TRANSFERFUNCTION) { @@ -370,7 +397,7 @@ void Parameter::SetValue(T val, bool set_default_val, bool set_dirty) { if constexpr (std::is_same_v) { int texture_width, texture_height; std::vector texture_data; - if (megamol::core::param::TransferFunctionParam::GetTextureData( + if (TransferFunctionParam::GetTextureData( val, texture_data, texture_width, texture_height)) { this->TransferFunction_LoadTexture(texture_data, texture_width, texture_height); } diff --git a/frontend/services/gui/src/graph/ParameterGroups.cpp b/frontend/services/gui/src/graph/ParameterGroups.cpp index a4c850fff9..838c7a1097 100644 --- a/frontend/services/gui/src/graph/ParameterGroups.cpp +++ b/frontend/services/gui/src/graph/ParameterGroups.cpp @@ -34,7 +34,7 @@ void megamol::gui::ParameterGroups::DrawParameter(megamol::gui::Parameter& inout if (in_scope == Parameter::WidgetScope::LOCAL) { param_searched = gui_utils::FindCaseInsensitiveSubstring(param_fullname, in_search); } - bool visible = (inout_param.IsGUIVisible() || inout_param.IsExtended()) && param_searched; + bool visible = (inout_param.GetParamPresentation().IsGUIVisible() || inout_param.IsExtended()) && param_searched; if (visible) { inout_param.Draw(in_scope); @@ -58,7 +58,7 @@ void megamol::gui::ParameterGroups::DrawGroupedParameters(const std::string& in_ bool visible = false; bool extended = false; for (auto& param : params) { - visible = visible || param->IsGUIVisible(); + visible = visible || param->GetParamPresentation().IsGUIVisible(); extended = extended || param->IsExtended(); } if (!visible && !extended) @@ -246,7 +246,7 @@ bool megamol::gui::ParameterGroups::StateToJSON(nlohmann::json& inout_json, cons } } - return false; + return true; } @@ -260,7 +260,7 @@ bool megamol::gui::ParameterGroups::StateFromJSON(const nlohmann::json& in_json, } } - return false; + return true; } @@ -274,7 +274,7 @@ bool megamol::gui::ParameterGroups::ParametersVisible(megamol::gui::ParamVector_ if (!param_namespace.empty()) { group_map[param_namespace].emplace_back(¶m); } else { - if (param.IsGUIVisible()) { + if (param.GetParamPresentation().IsGUIVisible()) { params_visisble = true; } } @@ -292,7 +292,7 @@ bool megamol::gui::ParameterGroups::ParametersVisible(megamol::gui::ParamVector_ } if (!found_group_widget) { for (auto& param_ptr : group.second) { - if (param_ptr->IsGUIVisible()) { + if (param_ptr->GetParamPresentation().IsGUIVisible()) { params_visisble = true; } } diff --git a/frontend/services/gui/src/windows/ParameterList.cpp b/frontend/services/gui/src/windows/ParameterList.cpp index 9741d33714..d678ca93ae 100644 --- a/frontend/services/gui/src/windows/ParameterList.cpp +++ b/frontend/services/gui/src/windows/ParameterList.cpp @@ -155,7 +155,7 @@ bool ParameterList::Draw() { auto const& param_vec = module_ptr->Parameters(); bool highlight = false; for (auto const& param : param_vec) { - if (param.IsHighlight()) + if (param.GetParamPresentation().IsGUIHighlight()) highlight = true; } if (highlight) From 5d96a7fd29398a105db47cf5fcb8c26b9301b6fa Mon Sep 17 00:00:00 2001 From: gralkapk Date: Wed, 5 Jul 2023 15:30:30 +0200 Subject: [PATCH 5/8] fixed typo --- core/src/param/AbstractParamPresentation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/param/AbstractParamPresentation.cpp b/core/src/param/AbstractParamPresentation.cpp index 3bd7447ece..6886cfa893 100644 --- a/core/src/param/AbstractParamPresentation.cpp +++ b/core/src/param/AbstractParamPresentation.cpp @@ -207,7 +207,7 @@ bool AbstractParamPresentation::StateFromJSON(const nlohmann::json& in_json, con bool gui_highlight = false; valid &= - megamol::core::utility::get_json_value(gui_state, {"gui_highlicht"}, &gui_highlight); + megamol::core::utility::get_json_value(gui_state, {"gui_highlight"}, &gui_highlight); int presentation_mode = 0; valid &= megamol::core::utility::get_json_value( From b6ca8e7fbdd5bb6d4b8ced49454f69c419c3e357 Mon Sep 17 00:00:00 2001 From: gralkapk Date: Wed, 5 Jul 2023 18:12:57 +0200 Subject: [PATCH 6/8] removed SetParamHighlight from graph interface --- core/include/mmcore/MegaMolGraph.h | 2 -- core/src/MegaMolGraph.cpp | 11 ----------- .../lua_service_wrapper/Lua_Service_Wrapper.cpp | 7 ++++++- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/core/include/mmcore/MegaMolGraph.h b/core/include/mmcore/MegaMolGraph.h index 72464561a6..ad6fbcb632 100644 --- a/core/include/mmcore/MegaMolGraph.h +++ b/core/include/mmcore/MegaMolGraph.h @@ -67,8 +67,6 @@ class MegaMolGraph { bool SetParameter(std::string const& paramName, std::string const& value); - bool SetParameterHighlight(std::string const& paramName, bool is_highlight); - megamol::core::param::ParamSlot* FindParameterSlot(std::string const& paramName) const; std::vector EnumerateModuleParameters(std::string const& moduleName) const; diff --git a/core/src/MegaMolGraph.cpp b/core/src/MegaMolGraph.cpp index d3df6c00a0..94c5966e03 100644 --- a/core/src/MegaMolGraph.cpp +++ b/core/src/MegaMolGraph.cpp @@ -222,17 +222,6 @@ bool megamol::core::MegaMolGraph::SetParameter(std::string const& paramName, std return true; } -bool megamol::core::MegaMolGraph::SetParameterHighlight(std::string const& paramName, bool is_highlight) { - auto param_slot_ptr = FindParameterSlot(paramName); - auto param_ptr = getParameterFromParamSlot(param_slot_ptr); - - if (!param_ptr) - return false; - param_ptr->SetGUIHighlight(is_highlight); - - return true; -} - bool megamol::core::MegaMolGraph::Broadcast_graph_subscribers_parameter_changes() { for (auto& subscriber : graph_subscribers.subscribers) { diff --git a/frontend/services/lua_service_wrapper/Lua_Service_Wrapper.cpp b/frontend/services/lua_service_wrapper/Lua_Service_Wrapper.cpp index d5bfae7986..12d6501c67 100644 --- a/frontend/services/lua_service_wrapper/Lua_Service_Wrapper.cpp +++ b/frontend/services/lua_service_wrapper/Lua_Service_Wrapper.cpp @@ -600,10 +600,15 @@ void Lua_Service_Wrapper::fill_graph_manipulation_callbacks(void* callbacks_coll callbacks.add("mmSetParamHighlight", "(string name, bool is_highlight)\n\tHighlight parameter slot.", {[&](std::string paramName, bool is_highlight) -> VoidResult { - if (!graph.SetParameterHighlight(paramName, is_highlight)) { + auto param_ptr = graph.FindParameter(paramName); + + if (param_ptr == nullptr) { return Error{ "parameter highlight could not be set: " + paramName + " : " + std::to_string(is_highlight)}; } + + param_ptr->SetGUIHighlight(is_highlight); + return VoidResult{}; }}); From 1453924ac6aca3fbb413b32a15b29a535b0b2d25 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 6 Jul 2023 12:16:50 +0200 Subject: [PATCH 7/8] replaced stock graph items with regular ones WIP (compiles, needs testing) --- frontend/services/gui/src/graph/Call.cpp | 6 +- frontend/services/gui/src/graph/Call.h | 15 +- frontend/services/gui/src/graph/CallSlot.cpp | 11 +- frontend/services/gui/src/graph/CallSlot.h | 13 +- frontend/services/gui/src/graph/Graph.cpp | 29 ++- frontend/services/gui/src/graph/Graph.h | 10 +- .../gui/src/graph/GraphCollection.cpp | 136 ++++++------- .../services/gui/src/graph/GraphCollection.h | 14 +- frontend/services/gui/src/graph/Module.cpp | 7 + frontend/services/gui/src/graph/Module.h | 27 +-- frontend/services/gui/src/graph/Parameter.cpp | 121 ++++++------ frontend/services/gui/src/graph/Parameter.h | 30 +-- .../services/gui/src/windows/Configurator.cpp | 181 ++++++++++-------- .../gui/src/windows/ParameterList.cpp | 2 +- 14 files changed, 307 insertions(+), 295 deletions(-) diff --git a/frontend/services/gui/src/graph/Call.cpp b/frontend/services/gui/src/graph/Call.cpp index d9680ca555..a9470015b8 100644 --- a/frontend/services/gui/src/graph/Call.cpp +++ b/frontend/services/gui/src/graph/Call.cpp @@ -22,8 +22,12 @@ using namespace megamol; using namespace megamol::gui; +megamol::gui::Call::Call(ImGuiID uid, const Call& in_stock_call) + : Call(uid, in_stock_call.class_name, in_stock_call.description, in_stock_call.plugin_name, + in_stock_call.functions) {} + megamol::gui::Call::Call(ImGuiID uid, const std::string& class_name, const std::string& description, - const std::string& plugin_name, const std::vector& functions) + const std::string& plugin_name, const std::vector& functions) : uid(uid) , class_name(class_name) , description(description) diff --git a/frontend/services/gui/src/graph/Call.h b/frontend/services/gui/src/graph/Call.h index 7dfd05dfba..64013f444b 100644 --- a/frontend/services/gui/src/graph/Call.h +++ b/frontend/services/gui/src/graph/Call.h @@ -37,6 +37,7 @@ typedef std::shared_ptr ModulePtr_t; // Types typedef std::shared_ptr CallPtr_t; typedef std::vector CallPtrVector_t; +typedef std::vector CallVector_t; /** ************************************************************************ @@ -44,15 +45,13 @@ typedef std::vector CallPtrVector_t; */ class Call { public: - struct StockCall { - std::string class_name; - std::string description; - std::string plugin_name; - std::vector functions; - }; + Call(ImGuiID uid, const Call& in_stock_call); + + // CTOR only for stock calls Call(ImGuiID uid, const std::string& class_name, const std::string& description, const std::string& plugin_name, const std::vector& functions); + ~Call(); bool IsConnected(); @@ -96,6 +95,10 @@ class Call { return this->gui_hidden; } + inline const std::vector& Functions() const { + return this->functions; + } + #ifdef MEGAMOL_USE_PROFILING ImVec2 GetProfilingButtonPosition() { diff --git a/frontend/services/gui/src/graph/CallSlot.cpp b/frontend/services/gui/src/graph/CallSlot.cpp index cd53995fb3..fd79b4341f 100644 --- a/frontend/services/gui/src/graph/CallSlot.cpp +++ b/frontend/services/gui/src/graph/CallSlot.cpp @@ -16,7 +16,14 @@ using namespace megamol; using namespace megamol::gui; -megamol::gui::CallSlot::CallSlot(ImGuiID uid, const std::string& name, const std::string& description, +megamol::gui::CallSlot::CallSlot(ImGuiID uid, const CallSlotPtr_t in_stock_callslot) + : CallSlot(uid, in_stock_callslot->name, in_stock_callslot->description, + in_stock_callslot->compatible_call_idxs, + in_stock_callslot->type, in_stock_callslot->necessity) {} + + +megamol::gui::CallSlot::CallSlot( + ImGuiID uid, const std::string& name, const std::string& description, const std::vector& compatible_call_idxs, CallSlotType type, megamol::core::AbstractCallSlotPresentation::Necessity necessity) : uid(uid) @@ -212,7 +219,7 @@ ImGuiID megamol::gui::CallSlot::GetCompatibleCallIndex( ImGuiID megamol::gui::CallSlot::GetCompatibleCallIndex( - const CallSlotPtr_t& callslot, const CallSlot::StockCallSlot& stock_callslot) { + const CallSlotPtr_t& callslot, const CallSlot& stock_callslot) { if (callslot != nullptr) { if (callslot->type != stock_callslot.type) { diff --git a/frontend/services/gui/src/graph/CallSlot.h b/frontend/services/gui/src/graph/CallSlot.h index 91d9a7c2e9..ce2c905328 100644 --- a/frontend/services/gui/src/graph/CallSlot.h +++ b/frontend/services/gui/src/graph/CallSlot.h @@ -41,17 +41,14 @@ typedef std::map CallSlotPtrMap_t; */ class CallSlot { public: - struct StockCallSlot { - std::string name; - std::string description; - std::vector compatible_call_idxs; - CallSlotType type; - megamol::core::AbstractCallSlotPresentation::Necessity necessity; - }; + CallSlot(ImGuiID uid, const CallSlotPtr_t in_stock_callslot); + + // CTOR only for stock callslots CallSlot(ImGuiID uid, const std::string& name, const std::string& description, const std::vector& compatible_call_idxs, CallSlotType type, megamol::core::AbstractCallSlotPresentation::Necessity necessity); + ~CallSlot(); bool CallsConnected() const; @@ -66,7 +63,7 @@ class CallSlot { const ModulePtr_t& GetParentModule(); static ImGuiID GetCompatibleCallIndex(const CallSlotPtr_t& callslot_1, const CallSlotPtr_t& callslot_2); - static ImGuiID GetCompatibleCallIndex(const CallSlotPtr_t& callslot, const CallSlot::StockCallSlot& stock_callslot); + static ImGuiID GetCompatibleCallIndex(const CallSlotPtr_t& callslot, const CallSlot& stock_callslot); bool IsConnectionValid(CallSlot& callslot); diff --git a/frontend/services/gui/src/graph/Graph.cpp b/frontend/services/gui/src/graph/Graph.cpp index 0924be1e43..196b241195 100644 --- a/frontend/services/gui/src/graph/Graph.cpp +++ b/frontend/services/gui/src/graph/Graph.cpp @@ -162,36 +162,34 @@ ModulePtr_t megamol::gui::Graph::AddModule(const std::string& class_name, const } -ModulePtr_t megamol::gui::Graph::AddModule(const ModuleStockVector_t& stock_modules, const std::string& class_name, +ModulePtr_t megamol::gui::Graph::AddModule(const ModuleVector_t& stock_modules, const std::string& class_name, const std::string& module_name, const std::string& group_name) { try { for (auto& mod : stock_modules) { - if (class_name == mod.class_name) { + if (class_name == mod.ClassName()) { ImGuiID mod_uid = megamol::gui::GenerateUniqueID(); auto mod_ptr = - std::make_shared(mod_uid, mod.class_name, mod.description, mod.plugin_name, mod.is_view); + std::make_shared(mod_uid, mod); if (module_name.empty()) { - mod_ptr->SetName(this->generate_unique_module_name(mod.class_name)); + mod_ptr->SetName(this->generate_unique_module_name(mod.ClassName())); } else { mod_ptr->SetName(module_name); } mod_ptr->SetGraphEntryName(""); this->AddGroupModule(group_name, mod_ptr, false); - for (auto& p : mod.parameters) { - Parameter parameter(megamol::gui::GenerateUniqueID(), p.type, p.storage, p.minval, p.maxval, - p.stepsize, p.param_name, p.description); + for (auto& p : mod.ConstParameters()) { + Parameter parameter(megamol::gui::GenerateUniqueID(), p); parameter.SetParentModuleName(mod_ptr->FullName()); - parameter.SetValueString(p.default_value, true, true); + parameter.SetValueString(p.GetValueString(), true, true); parameter.SetParamPresentation(p.GetParamPresentation()); mod_ptr->Parameters().emplace_back(parameter); } - for (auto& callslots_type : mod.callslots) { + for (auto& callslots_type : mod.CallSlots()) { for (auto& c : callslots_type.second) { - auto callslot_ptr = std::make_shared(megamol::gui::GenerateUniqueID(), c.name, - c.description, c.compatible_call_idxs, c.type, c.necessity); + auto callslot_ptr = std::make_shared(megamol::gui::GenerateUniqueID(), c); callslot_ptr->ConnectParentModule(mod_ptr); mod_ptr->AddCallSlot(callslot_ptr); } @@ -368,7 +366,7 @@ bool megamol::gui::Graph::ModuleExists(const std::string& module_fullname) { } -bool megamol::gui::Graph::AddCall(const CallStockVector_t& stock_calls, ImGuiID slot_1_uid, ImGuiID slot_2_uid) { +bool megamol::gui::Graph::AddCall(const CallVector_t& stock_calls, ImGuiID slot_1_uid, ImGuiID slot_2_uid) { try { if ((slot_1_uid == GUI_INVALID_ID) || (slot_2_uid == GUI_INVALID_ID)) { @@ -474,7 +472,7 @@ bool megamol::gui::Graph::AddCall(const CallStockVector_t& stock_calls, ImGuiID CallPtr_t megamol::gui::Graph::AddCall( - const CallStockVector_t& stock_calls, CallSlotPtr_t callslot_1, CallSlotPtr_t callslot_2, bool use_queue) { + const CallVector_t& stock_calls, CallSlotPtr_t callslot_1, CallSlotPtr_t callslot_2, bool use_queue) { try { if ((callslot_1 == nullptr) || (callslot_2 == nullptr)) { @@ -491,10 +489,9 @@ CallPtr_t megamol::gui::Graph::AddCall( "[GUI] Unable to find index of compatible call. [%s, %s, line %d]\n", __FILE__, __FUNCTION__, __LINE__); return nullptr; } - Call::StockCall call_stock_data = stock_calls[compat_idx]; + Call call_stock_data = stock_calls[compat_idx]; - auto call_ptr = std::make_shared(megamol::gui::GenerateUniqueID(), call_stock_data.class_name, - call_stock_data.description, call_stock_data.plugin_name, call_stock_data.functions); + auto call_ptr = std::make_shared(megamol::gui::GenerateUniqueID(), call_stock_data); return this->ConnectCall(call_ptr, callslot_1, callslot_2, use_queue) ? call_ptr : nullptr; diff --git a/frontend/services/gui/src/graph/Graph.h b/frontend/services/gui/src/graph/Graph.h index ac93bb6fea..04a1f018bb 100644 --- a/frontend/services/gui/src/graph/Graph.h +++ b/frontend/services/gui/src/graph/Graph.h @@ -24,10 +24,6 @@ namespace megamol::gui { // Forward declarations class Graph; -// Types -typedef std::vector ModuleStockVector_t; -typedef std::vector CallStockVector_t; - /** ************************************************************************ * Defines the graph @@ -55,7 +51,7 @@ class Graph { explicit Graph(const std::string& graph_name); ~Graph(); - ModulePtr_t AddModule(const ModuleStockVector_t& stock_ms, const std::string& class_name, + ModulePtr_t AddModule(const ModuleVector_t& stock_ms, const std::string& class_name, const std::string& module_name, const std::string& group_name); ModulePtr_t AddModule(const std::string& class_name, const std::string& module_name, const std::string& group_name, const std::string& description, const std::string& plugin_name, bool is_view); @@ -68,8 +64,8 @@ class Graph { bool ModuleExists(const std::string& module_fullname); bool UniqueModuleRename(const std::string& module_full_name); - bool AddCall(const CallStockVector_t& stock_calls, ImGuiID slot_1_uid, ImGuiID slot_2_uid); - CallPtr_t AddCall(const CallStockVector_t& stock_calls, CallSlotPtr_t callslot_1, CallSlotPtr_t callslot_2, + bool AddCall(const CallVector_t& stock_calls, ImGuiID slot_1_uid, ImGuiID slot_2_uid); + CallPtr_t AddCall(const CallVector_t& stock_calls, CallSlotPtr_t callslot_1, CallSlotPtr_t callslot_2, bool use_queue = true); bool ConnectCall(CallPtr_t& call_ptr, CallSlotPtr_t callslot_1, CallSlotPtr_t callslot_2, bool use_queue = true); CallPtr_t GetCall( diff --git a/frontend/services/gui/src/graph/GraphCollection.cpp b/frontend/services/gui/src/graph/GraphCollection.cpp index 456ac46dc1..9164ee3bd1 100644 --- a/frontend/services/gui/src/graph/GraphCollection.cpp +++ b/frontend/services/gui/src/graph/GraphCollection.cpp @@ -148,10 +148,7 @@ bool megamol::gui::GraphCollection::load_call_stock(const megamol::frontend_reso for (auto& plugin : pluginsRes.plugins) { plugin_name = plugin->GetObjectFactoryName(); for (auto& c_desc : plugin->GetCallDescriptionManager()) { - Call::StockCall call; - if (this->get_call_stock_data(call, c_desc, plugin_name)) { - this->calls_stock.emplace_back(call); - } + this->get_call_stock_data(c_desc, plugin_name); } } } @@ -212,10 +209,8 @@ bool megamol::gui::GraphCollection::load_module_stock(const megamol::frontend_re for (auto& plugin : pluginsRes.plugins) { plugin_name = plugin->GetObjectFactoryName(); for (auto& m_desc : plugin->GetModuleDescriptionManager()) { - Module::StockModule mod; - if (this->get_module_stock_data(mod, m_desc, plugin_name)) { - this->modules_stock.emplace_back(mod); - } + this->get_module_stock_data(m_desc, plugin_name); + #ifdef GUI_VERBOSE auto module_load_time_count = static_cast>(std::chrono::system_clock::now() - module_load_time) @@ -227,16 +222,6 @@ bool megamol::gui::GraphCollection::load_module_stock(const megamol::frontend_re #endif // GUI_VERBOSE } } - - // Sorting module by alphabetically ascending class names. - std::sort(this->modules_stock.begin(), this->modules_stock.end(), - [](Module::StockModule& mod1, Module::StockModule& mod2) { - std::string a_str(mod1.class_name); - core::utility::string::ToUpperAscii(a_str); - std::string b_str(mod2.class_name); - core::utility::string::ToUpperAscii(b_str); - return (a_str < b_str); - }); } auto delta_time = @@ -559,7 +544,7 @@ bool megamol::gui::GraphCollection::LoadOrAddProjectFromFile( // First, rename existing modules with same name graph_ptr->UniqueModuleRename(view_full_name); // Add module and set as view instance - auto graph_module = + auto graph_module = graph_ptr->AddModule(this->modules_stock, view_class_name, view_name, view_namespace); if (graph_module == nullptr) { megamol::core::utility::log::Log::DefaultLog.WriteError( @@ -894,7 +879,7 @@ bool megamol::gui::GraphCollection::SaveProjectToFile(ImGuiID in_graph_uid, cons << module_ptr->FullName() << "\")\n"; } - for (auto& parameter : module_ptr->Parameters()) { + for (auto& parameter : module_ptr->ConstParameters()) { // Either write_all_param_values or only write parameters with values deviating from the default // Button parameters are always ignored if ((write_all_param_values || parameter.DefaultValueMismatch()) && @@ -952,17 +937,7 @@ bool megamol::gui::GraphCollection::SaveProjectToFile(ImGuiID in_graph_uid, cons } -bool megamol::gui::GraphCollection::get_module_stock_data(Module::StockModule& out_mod, - std::shared_ptr mod_desc, const std::string& plugin_name) { - - out_mod.class_name = std::string(mod_desc->ClassName()); - out_mod.description = std::string(mod_desc->Description()); - out_mod.is_view = false; - out_mod.parameters.clear(); - out_mod.callslots.clear(); - out_mod.callslots.emplace(CallSlotType::CALLER, std::vector()); - out_mod.callslots.emplace(CallSlotType::CALLEE, std::vector()); - out_mod.plugin_name = plugin_name; +bool megamol::gui::GraphCollection::get_module_stock_data(std::shared_ptr mod_desc, const std::string& plugin_name) { if (this->calls_stock.empty()) { megamol::core::utility::log::Log::DefaultLog.WriteError( @@ -997,7 +972,7 @@ bool megamol::gui::GraphCollection::get_module_stock_data(Module::StockModule& o std::shared_ptr viewptr = std::dynamic_pointer_cast(new_mod); - out_mod.is_view = (viewptr != nullptr); + Module stock_module(GUI_INVALID_ID, std::string(mod_desc->ClassName()), std::string(mod_desc->Description()), plugin_name, bool(viewptr != nullptr)); std::vector> paramSlots; std::vector> callerSlots; @@ -1020,34 +995,37 @@ bool megamol::gui::GraphCollection::get_module_stock_data(Module::StockModule& o for (auto& param_slot : paramSlots) { if (param_slot == nullptr) continue; - Parameter::StockParameter psd; - if (megamol::gui::Parameter::ReadNewCoreParameterToStockParameter((*param_slot), psd)) { - out_mod.parameters.emplace_back(psd); + if (param_slot->Parameter() != nullptr) { + stock_module.Parameters().emplace_back( + megamol::gui::Parameter::ReadNewCoreParameterToStockParameter((*param_slot))); + } else { + megamol::core::utility::log::Log::DefaultLog.WriteError( + "[GUI] Pointer to core parameter is nullptr. [%s, %s, line %d]\n", __FILE__, __FUNCTION__, __LINE__); } } // CallerSlots for (auto& caller_slot : callerSlots) { - CallSlot::StockCallSlot csd; - csd.name = std::string(caller_slot->Name().PeekBuffer()); - csd.description = std::string(caller_slot->Description().PeekBuffer()); - csd.compatible_call_idxs = this->get_compatible_caller_idxs(caller_slot.get()); - csd.type = CallSlotType::CALLER; - csd.necessity = caller_slot->GetNecessity(); - - out_mod.callslots[csd.type].emplace_back(csd); + auto name = std::string(caller_slot->Name().PeekBuffer()); + auto description = std::string(caller_slot->Description().PeekBuffer()); + auto compatible_call_idxs = this->get_compatible_caller_idxs(caller_slot.get()); + auto type = CallSlotType::CALLER; + auto necessity = caller_slot->GetNecessity(); + + stock_module.CallSlots(type).emplace_back(std::make_shared< + CallSlot>(GUI_INVALID_ID, name, description, compatible_call_idxs, type, necessity)); } // CalleeSlots for (auto& callee_slot : calleeSlots) { - CallSlot::StockCallSlot csd; - csd.name = std::string(callee_slot->Name().PeekBuffer()); - csd.description = std::string(callee_slot->Description().PeekBuffer()); - csd.compatible_call_idxs = this->get_compatible_callee_idxs(callee_slot.get()); - csd.type = CallSlotType::CALLEE; - csd.necessity = callee_slot->GetNecessity(); - - out_mod.callslots[csd.type].emplace_back(csd); + auto name = std::string(callee_slot->Name().PeekBuffer()); + auto description = std::string(callee_slot->Description().PeekBuffer()); + auto compatible_call_idxs = this->get_compatible_callee_idxs(callee_slot.get()); + auto type = CallSlotType::CALLEE; + auto necessity = callee_slot->GetNecessity(); + + stock_module.CallSlots(type).emplace_back( + std::make_shared(GUI_INVALID_ID, name, description, compatible_call_idxs, type, necessity)); } paramSlots.clear(); @@ -1062,6 +1040,8 @@ bool megamol::gui::GraphCollection::get_module_stock_data(Module::StockModule& o // megamol::core::utility::log::Log::DefaultLog.WriteInfo( // "[GUI] [DEBUG] Removed temporary module '%s'.", mod_desc->ClassName()); + this->modules_stock.emplace_back(stock_module); + } catch (std::exception& e) { megamol::core::utility::log::Log::DefaultLog.WriteError( "[GUI] Error: %s [%s, %s, line %d]\n", e.what(), __FILE__, __FUNCTION__, __LINE__); @@ -1075,17 +1055,17 @@ bool megamol::gui::GraphCollection::get_module_stock_data(Module::StockModule& o } -bool megamol::gui::GraphCollection::get_call_stock_data(Call::StockCall& out_call, - std::shared_ptr call_desc, const std::string& plugin_name) { +bool megamol::gui::GraphCollection::get_call_stock_data(std::shared_ptr call_desc, const std::string& plugin_name) { try { - out_call.class_name = std::string(call_desc->ClassName()); - out_call.description = std::string(call_desc->Description()); - out_call.functions.clear(); + + std::vector functions; for (unsigned int i = 0; i < call_desc->FunctionCount(); ++i) { - out_call.functions.emplace_back(call_desc->FunctionName(i)); + functions.emplace_back(call_desc->FunctionName(i)); } - out_call.plugin_name = plugin_name; + + this->calls_stock.emplace_back(Call(GUI_INVALID_ID, std::string(call_desc->ClassName()), + std::string(call_desc->Description()), plugin_name, functions)); } catch (std::exception& e) { megamol::core::utility::log::Log::DefaultLog.WriteError( @@ -1209,30 +1189,28 @@ std::vector megamol::gui::GraphCollection::get_compatible_callee_idxs( assert(ll == funcNames.size()); for (auto& callName : uniqueCallNames) { bool found_call = false; - Call::StockCall call; - for (auto& c : this->calls_stock) { - if (callName == c.class_name) { - call = c; - found_call = true; - break; - } - } bool allFound = true; - if (found_call) { - for (auto& func_name : call.functions) { - bool found = false; - for (size_t j = 0; j < ll; ++j) { - if ((callNames[j] == callName) && (funcNames[j] == func_name)) { - found = true; + for (auto& c : this->calls_stock) { + if (callName == c.ClassName()) { + for (auto& func_name : c.Functions()) { + bool found = false; + for (size_t j = 0; j < ll; ++j) { + if ((callNames[j] == callName) && (funcNames[j] == func_name)) { + found = true; + break; + } + } + if (!found) { + allFound = false; break; } } - if (!found) { - allFound = false; - break; - } + found_call = true; + break; } - } else { + } + + if (!found_call) { allFound = false; } if (allFound) { @@ -1243,7 +1221,7 @@ std::vector megamol::gui::GraphCollection::get_compatible_callee_idxs( size_t calls_cnt = this->calls_stock.size(); for (size_t idx = 0; idx < calls_cnt; ++idx) { // Case-Insensitive call slot comparison - if (gui_utils::CaseInsensitiveStringEqual(this->calls_stock[idx].class_name, callName)) { + if (gui_utils::CaseInsensitiveStringEqual(this->calls_stock[idx].ClassName(), callName)) { retval.emplace_back(idx); } } @@ -1267,7 +1245,7 @@ std::vector megamol::gui::GraphCollection::get_compatible_caller_idxs( size_t calls_cnt = this->calls_stock.size(); for (size_t idx = 0; idx < calls_cnt; ++idx) { // Case-Insensitive call slot comparison - if (gui_utils::CaseInsensitiveStringEqual(this->calls_stock[idx].class_name, comp_call_class_name)) { + if (gui_utils::CaseInsensitiveStringEqual(this->calls_stock[idx].ClassName(), comp_call_class_name)) { retval.emplace_back(idx); } } diff --git a/frontend/services/gui/src/graph/GraphCollection.h b/frontend/services/gui/src/graph/GraphCollection.h index 9ba2a22c45..d493e083c3 100644 --- a/frontend/services/gui/src/graph/GraphCollection.h +++ b/frontend/services/gui/src/graph/GraphCollection.h @@ -48,10 +48,10 @@ class GraphCollection { } GraphPtr_t GetRunningGraph(); - inline const ModuleStockVector_t& GetModulesStock() { + inline const ModuleVector_t& GetModulesStock() { return this->modules_stock; } - inline const CallStockVector_t& GetCallsStock() { + inline const CallVector_t& GetCallsStock() { return this->calls_stock; } bool IsCallStockLoaded() const { @@ -106,8 +106,8 @@ class GraphCollection { // VARIABLES -------------------------------------------------------------- GraphPtrVector_t graphs; - ModuleStockVector_t modules_stock; - CallStockVector_t calls_stock; + ModuleVector_t modules_stock; + CallVector_t calls_stock; unsigned int graph_name_uid; FileBrowserWidget gui_file_browser; @@ -125,10 +125,8 @@ class GraphCollection { std::string get_state(ImGuiID graph_id, const std::string& filename); - bool get_call_stock_data(Call::StockCall& out_call, - std::shared_ptr call_desc, const std::string& plugin_name); - bool get_module_stock_data(Module::StockModule& out_mod, - std::shared_ptr mod_desc, const std::string& plugin_name); + bool get_call_stock_data(std::shared_ptr call_desc, const std::string& plugin_name); + bool get_module_stock_data(std::shared_ptr mod_desc, const std::string& plugin_name); bool read_project_command_arguments( const std::string& line, size_t arg_count, std::vector& out_args) const; diff --git a/frontend/services/gui/src/graph/Module.cpp b/frontend/services/gui/src/graph/Module.cpp index 841c9f3db6..6a003d1b7f 100644 --- a/frontend/services/gui/src/graph/Module.cpp +++ b/frontend/services/gui/src/graph/Module.cpp @@ -22,6 +22,13 @@ using namespace megamol; using namespace megamol::gui; + + +megamol::gui::Module::Module(ImGuiID uid, const Module& in_stock_module) : + Module(uid, in_stock_module.class_name, in_stock_module.description, in_stock_module.plugin_name, in_stock_module.is_view) { +} + + megamol::gui::Module::Module(ImGuiID uid, const std::string& class_name, const std::string& description, const std::string& plugin_name, bool is_view) : uid(uid) diff --git a/frontend/services/gui/src/graph/Module.h b/frontend/services/gui/src/graph/Module.h index 7598a9f474..111976f64e 100644 --- a/frontend/services/gui/src/graph/Module.h +++ b/frontend/services/gui/src/graph/Module.h @@ -28,6 +28,7 @@ typedef std::shared_ptr CallSlotPtr_t; // Types typedef std::shared_ptr ModulePtr_t; typedef std::vector ModulePtrVector_t; +typedef std::vector ModuleVector_t; /** ************************************************************************ @@ -35,28 +36,27 @@ typedef std::vector ModulePtrVector_t; */ class Module { public: - struct StockModule { - std::string class_name; - std::string description; - std::string plugin_name; - bool is_view; - std::vector parameters; - std::map> callslots; - }; static ImVec2 GetDefaultModulePosition(const GraphCanvas_t& canvas); + + Module(ImGuiID uid, const Module& in_stock_module); + + // CTOR only for stock modules Module(ImGuiID uid, const std::string& class_name, const std::string& description, const std::string& plugin_name, bool is_view); + ~Module(); bool AddCallSlot(CallSlotPtr_t callslot); bool DeleteCallSlots(); void Draw(megamol::gui::PresentPhase phase, GraphItemsState_t& state); + void Update() { this->gui_update = true; } + void InstantUpdate(const GraphItemsState_t& state) { this->update(state); } @@ -78,10 +78,10 @@ class Module { // GET ---------------------------------------------------------------- CallSlotPtr_t CallSlotPtr(ImGuiID callslot_uid); - const CallSlotPtrVector_t& CallSlots(CallSlotType type) { + CallSlotPtrVector_t& CallSlots(CallSlotType type) { return this->callslots[type]; } - const CallSlotPtrMap_t& CallSlots() { + const CallSlotPtrMap_t& CallSlots() const { return this->callslots; } @@ -97,6 +97,9 @@ class Module { inline std::string Name() const { return this->name; } + inline std::string PluginName() const { + return this->plugin_name; + } inline std::string FullName() const { std::string fullname = "::" + this->name; if (!this->group_name.empty()) { @@ -113,6 +116,9 @@ class Module { inline ImGuiID GroupUID() const { return this->group_uid; } + inline const ParamVector_t& ConstParameters() const { + return this->parameters; + } inline ParamVector_t& Parameters() { return this->parameters; } @@ -217,7 +223,6 @@ class Module { // VARIABLES -------------------------------------------------------------- const ImGuiID uid; - // TODO place StockModule (Properties?) here instead const std::string class_name; const std::string description; const std::string plugin_name; diff --git a/frontend/services/gui/src/graph/Parameter.cpp b/frontend/services/gui/src/graph/Parameter.cpp index 35d521491f..672cfde46e 100644 --- a/frontend/services/gui/src/graph/Parameter.cpp +++ b/frontend/services/gui/src/graph/Parameter.cpp @@ -33,6 +33,11 @@ using namespace megamol; using namespace megamol::gui; +megamol::gui::Parameter::Parameter(ImGuiID uid, const Parameter& in_stock_param) + : Parameter(uid, in_stock_param.type, in_stock_param.storage, in_stock_param.minval, in_stock_param.maxval, + in_stock_param.stepsize, in_stock_param.param_name, in_stock_param.description) {} + + megamol::gui::Parameter::Parameter(ImGuiID uid, ParamType_t type, Storage_t store, Min_t minv, Max_t maxv, Step_t step, const std::string& param_name, const std::string& description) : uid(uid) @@ -306,95 +311,98 @@ bool megamol::gui::Parameter::SetValueString(const std::string& val_str, bool se } -bool megamol::gui::Parameter::ReadNewCoreParameterToStockParameter( - megamol::core::param::ParamSlot& in_param_slot, megamol::gui::Parameter::StockParameter& out_param) { - - auto const parameter_ptr = in_param_slot.Parameter(); - if (parameter_ptr == nullptr) { - return false; - } +megamol::gui::Parameter& megamol::gui::Parameter::ReadNewCoreParameterToStockParameter(megamol::core::param::ParamSlot& in_param_slot) { - out_param.param_name = std::string(in_param_slot.Name().PeekBuffer()); - out_param.description = std::string(in_param_slot.Description().PeekBuffer()); - out_param.SetParamPresentation(parameter_ptr->GetParamPresentation()); + std::string name = std::string(in_param_slot.Name().PeekBuffer()); + std::string description = std::string(in_param_slot.Description().PeekBuffer()); + ParamType_t type; + std::string value; + Min_t minval; + Max_t maxval; + Step_t stepsize; + Storage_t storage; if (auto* p_ptr = in_param_slot.Param()) { - out_param.type = ParamType_t::BUTTON; - out_param.storage = p_ptr->GetKeyCode(); + type = ParamType_t::BUTTON; + storage = p_ptr->GetKeyCode(); } else if (auto* p_ptr = in_param_slot.Param()) { - out_param.type = ParamType_t::BOOL; - out_param.default_value = p_ptr->ValueString(); + type = ParamType_t::BOOL; + value = p_ptr->ValueString(); } else if (auto* p_ptr = in_param_slot.Param()) { - out_param.type = ParamType_t::COLOR; - out_param.default_value = p_ptr->ValueString(); + type = ParamType_t::COLOR; + value = p_ptr->ValueString(); } else if (auto* p_ptr = in_param_slot.Param()) { - out_param.type = ParamType_t::ENUM; - out_param.default_value = p_ptr->ValueString(); + type = ParamType_t::ENUM; + value = p_ptr->ValueString(); EnumStorage_t map; for (auto const& el : p_ptr->getMap()) { map.emplace(el); } - out_param.storage = map; + storage = map; } else if (auto* p_ptr = in_param_slot.Param()) { - out_param.type = ParamType_t::FILEPATH; - out_param.default_value = p_ptr->ValueString(); - out_param.storage = FilePathStorage_t({p_ptr->GetFlags(), p_ptr->GetExtensions()}); + type = ParamType_t::FILEPATH; + value = p_ptr->ValueString(); + storage = FilePathStorage_t({p_ptr->GetFlags(), p_ptr->GetExtensions()}); } else if (auto* p_ptr = in_param_slot.Param()) { - out_param.type = ParamType_t::FLEXENUM; - out_param.default_value = p_ptr->ValueString(); - out_param.storage = p_ptr->getStorage(); + type = ParamType_t::FLEXENUM; + value = p_ptr->ValueString(); + storage = p_ptr->getStorage(); } else if (auto* p_ptr = in_param_slot.Param()) { - out_param.type = ParamType_t::FLOAT; - out_param.default_value = p_ptr->ValueString(); - out_param.minval = p_ptr->MinValue(); - out_param.maxval = p_ptr->MaxValue(); - out_param.stepsize = p_ptr->StepSize(); + type = ParamType_t::FLOAT; + value = p_ptr->ValueString(); + minval = p_ptr->MinValue(); + maxval = p_ptr->MaxValue(); + stepsize = p_ptr->StepSize(); } else if (auto* p_ptr = in_param_slot.Param()) { - out_param.type = ParamType_t::INT; - out_param.default_value = p_ptr->ValueString(); - out_param.minval = p_ptr->MinValue(); - out_param.maxval = p_ptr->MaxValue(); - out_param.stepsize = p_ptr->StepSize(); + type = ParamType_t::INT; + value = p_ptr->ValueString(); + minval = p_ptr->MinValue(); + maxval = p_ptr->MaxValue(); + stepsize = p_ptr->StepSize(); } else if (auto* p_ptr = in_param_slot.Param()) { - out_param.type = ParamType_t::STRING; - out_param.default_value = p_ptr->ValueString(); + type = ParamType_t::STRING; + value = p_ptr->ValueString(); } else if (auto* p_ptr = in_param_slot.Param()) { - out_param.type = ParamType_t::TERNARY; - out_param.default_value = p_ptr->ValueString(); + type = ParamType_t::TERNARY; + value = p_ptr->ValueString(); } else if (auto* p_ptr = in_param_slot.Param()) { - out_param.type = ParamType_t::TRANSFERFUNCTION; - out_param.default_value = p_ptr->ValueString(); + type = ParamType_t::TRANSFERFUNCTION; + value = p_ptr->ValueString(); } else if (auto* p_ptr = in_param_slot.Param()) { - out_param.type = ParamType_t::VECTOR2F; - out_param.default_value = p_ptr->ValueString(); + type = ParamType_t::VECTOR2F; + value = p_ptr->ValueString(); auto minv = p_ptr->MinValue(); - out_param.minval = glm::vec2(minv.X(), minv.Y()); + minval = glm::vec2(minv.X(), minv.Y()); auto maxv = p_ptr->MaxValue(); - out_param.maxval = glm::vec2(maxv.X(), maxv.Y()); + maxval = glm::vec2(maxv.X(), maxv.Y()); } else if (auto* p_ptr = in_param_slot.Param()) { - out_param.type = ParamType_t::VECTOR3F; - out_param.default_value = p_ptr->ValueString(); + type = ParamType_t::VECTOR3F; + value = p_ptr->ValueString(); auto minv = p_ptr->MinValue(); - out_param.minval = glm::vec3(minv.X(), minv.Y(), minv.Z()); + minval = glm::vec3(minv.X(), minv.Y(), minv.Z()); auto maxv = p_ptr->MaxValue(); - out_param.maxval = glm::vec3(maxv.X(), maxv.Y(), maxv.Z()); + maxval = glm::vec3(maxv.X(), maxv.Y(), maxv.Z()); } else if (auto* p_ptr = in_param_slot.Param()) { - out_param.type = ParamType_t::VECTOR4F; - out_param.default_value = p_ptr->ValueString(); + type = ParamType_t::VECTOR4F; + value = p_ptr->ValueString(); auto minv = p_ptr->MinValue(); - out_param.minval = glm::vec4(minv.X(), minv.Y(), minv.Z(), minv.W()); + minval = glm::vec4(minv.X(), minv.Y(), minv.Z(), minv.W()); auto maxv = p_ptr->MaxValue(); - out_param.maxval = glm::vec4(maxv.X(), maxv.Y(), maxv.Z(), maxv.W()); + maxval = glm::vec4(maxv.X(), maxv.Y(), maxv.Z(), maxv.W()); } else { megamol::core::utility::log::Log::DefaultLog.WriteError( "[GUI] Found unknown parameter type. Please extend parameter types " "for the configurator. [%s, %s, line %d]\n", __FILE__, __FUNCTION__, __LINE__); - out_param.type = ParamType_t::UNKNOWN; - return false; + type = ParamType_t::UNKNOWN; } - return true; + Parameter new_stock_param = Parameter(GUI_INVALID_ID, type, storage, minval, maxval, stepsize, name, description); + + auto const parameter_ptr = in_param_slot.Parameter(); + new_stock_param.SetParamPresentation(parameter_ptr->GetParamPresentation()); + + return new_stock_param; } @@ -818,6 +826,7 @@ bool megamol::gui::Parameter::draw_parameter(megamol::gui::Parameter::WidgetScop ImGui::PushItemWidth(widget_width); gui_utils::PushReadOnly(this->gui_present.IsGUIReadOnly()); if (this->gui_present.IsGUIHighlight()) + /// TODO Other highlighting style: Yellow Frame? ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(255, 0, 0, 255)); } diff --git a/frontend/services/gui/src/graph/Parameter.h b/frontend/services/gui/src/graph/Parameter.h index b66b2393eb..4ae849be5d 100644 --- a/frontend/services/gui/src/graph/Parameter.h +++ b/frontend/services/gui/src/graph/Parameter.h @@ -96,29 +96,9 @@ class Parameter { > Storage_t; - struct StockParameter { - std::string param_name; - std::string description; - ParamType_t type; - std::string default_value; - Min_t minval; - Max_t maxval; - Step_t stepsize; - Storage_t storage; - AbstractParamPresentation gui_present; - - void SetParamPresentation(const AbstractParamPresentation& other) { - this->gui_present = other; - } - const AbstractParamPresentation& GetParamPresentation() const { - return this->gui_present; - } - }; - // STATIC --------------------- - static bool ReadNewCoreParameterToStockParameter( - ParamSlot& in_param_slot, megamol::gui::Parameter::StockParameter& out_param); + static megamol::gui::Parameter& ReadNewCoreParameterToStockParameter(ParamSlot& in_param_slot); static bool ReadNewCoreParameterToNewParameter(ParamSlot& in_param_slot, std::shared_ptr& out_param, bool set_default_val, bool set_dirty, @@ -135,6 +115,9 @@ class Parameter { // ---------------------------- + Parameter(ImGuiID uid, const Parameter& in_stock_param); + + // CTOR only for stock parameters Parameter(ImGuiID uid, ParamType_t type, Storage_t store, Min_t minval, Max_t maxval, Step_t step, const std::string& param_name, const std::string& description); @@ -229,9 +212,10 @@ class Parameter { return std::get(this->storage); } - inline bool DefaultValueMismatch() { + inline bool DefaultValueMismatch() const { return this->default_value_mismatch; } + inline size_t GetTransferFunctionHash() const { return this->tf_string_hash; } @@ -303,7 +287,7 @@ class Parameter { // VARIABLES -------------------------------------------------------------- const ImGuiID uid; - const ParamType_t type; + ParamType_t type; std::string param_name; /// :: std::string parent_module_name; /// :::: std::string description; diff --git a/frontend/services/gui/src/windows/Configurator.cpp b/frontend/services/gui/src/windows/Configurator.cpp index 2940a3fa83..cf69f3211e 100644 --- a/frontend/services/gui/src/windows/Configurator.cpp +++ b/frontend/services/gui/src/windows/Configurator.cpp @@ -427,22 +427,30 @@ void megamol::gui::Configurator::draw_window_module_list(float width, float heig } } - ImGuiID id = 1; + struct FilteredModule { + std::string class_name; + std::string plugin_name; + std::string description; + bool is_view; + bool compat_filter; + }; + std::vector filtered_modules; + for (auto& mod : this->graph_collection.GetModulesStock()) { // Filter module by given search string bool search_filter = true; if (!search_string.empty()) { - search_filter = gui_utils::FindCaseInsensitiveSubstring(mod.class_name, search_string); + search_filter = gui_utils::FindCaseInsensitiveSubstring(mod.ClassName(), search_string); } // Filter module by compatible call slots bool compat_filter = true; if (selected_callslot_ptr != nullptr) { compat_filter = false; - for (auto& stock_callslot_map : mod.callslots) { + for (auto& stock_callslot_map : mod.CallSlots()) { for (auto& stock_callslot : stock_callslot_map.second) { if (CallSlot::GetCompatibleCallIndex(selected_callslot_ptr, stock_callslot) != GUI_INVALID_ID) { - compat_callslot_name = stock_callslot.name; + compat_callslot_name = stock_callslot->Name(); compat_filter = true; } } @@ -450,99 +458,118 @@ void megamol::gui::Configurator::draw_window_module_list(float width, float heig } if (search_filter && compat_filter) { - ImGui::PushID(static_cast(id)); + FilteredModule fm; + fm.class_name = mod.ClassName(); + fm.plugin_name = mod.PluginName(); + fm.description = mod.Description(); + fm.is_view = mod.IsView(); + fm.compat_filter = compat_filter; + filtered_modules.emplace_back(fm); + } + } + // Sort filtered modules by alphabetically ascending class names. + std::sort(filtered_modules.begin(), filtered_modules.end(), [](FilteredModule& mod1, FilteredModule& mod2) { + std::string a_str(mod1.class_name); + core::utility::string::ToUpperAscii(a_str); + std::string b_str(mod2.class_name); + core::utility::string::ToUpperAscii(b_str); + return (a_str < b_str); + }); - std::string label = mod.class_name + " (" + mod.plugin_name + ")"; - if (mod.is_view) { - label += " [View]"; - } + ImGuiID id = 1; + for (auto& mod : filtered_modules) { + ImGui::PushID(static_cast(id)); - bool add_module = false; - if (ImGui::Selectable(label.c_str(), (id == this->selected_list_module_id))) { - this->selected_list_module_id = id; - } - // Left mouse button double click action - if ((ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && ImGui::IsItemHovered()) || // Mouse Double Click - (!ImGui::IsMouseClicked(ImGuiMouseButton_Left) && ImGui::IsItemFocused() && - ImGui::IsItemActivated())) { // Selection via key ('Space') + std::string label = mod.class_name + " (" + mod.plugin_name + ")"; + if (mod.is_view) { + label += " [View]"; + } + + bool add_module = false; + if (ImGui::Selectable(label.c_str(), (id == this->selected_list_module_id))) { + this->selected_list_module_id = id; + } + // Left mouse button double click action + if ((ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && ImGui::IsItemHovered()) || // Mouse Double Click + (!ImGui::IsMouseClicked(ImGuiMouseButton_Left) && ImGui::IsItemFocused() && + ImGui::IsItemActivated())) { // Selection via key ('Space') + add_module = true; + } + // Context menu + if (ImGui::BeginPopupContextItem()) { + if (ImGui::MenuItem("Add", "'Double-Click'")) { add_module = true; } - // Context menu - if (ImGui::BeginPopupContextItem()) { - if (ImGui::MenuItem("Add", "'Double-Click'")) { - add_module = true; - } - ImGui::EndPopup(); - } + ImGui::EndPopup(); + } - if (add_module) { - if (auto selected_graph_ptr = this->graph_collection.GetGraph(this->graph_state.graph_selected_uid)) { - if (auto module_ptr = selected_graph_ptr->AddModule( - this->graph_collection.GetModulesStock(), mod.class_name, "", "")) { + if (add_module) { + if (auto selected_graph_ptr = this->graph_collection.GetGraph(this->graph_state.graph_selected_uid)) { + if (auto module_ptr = selected_graph_ptr->AddModule( + this->graph_collection.GetModulesStock(), mod.class_name, "", "")) { - // If there is a call slot selected, create call to compatible call slot of new module - bool add_call = compat_filter && (selected_callslot_ptr != nullptr); + // If there is a call slot selected, create call to compatible call slot of new module + bool add_call = mod.compat_filter && (selected_callslot_ptr != nullptr); - // If there is a group selected or hovered or the new call is connected to module which is part - // of group, add module to this group - if (!interfaceslot_selected) { - ImGuiID connected_group = GUI_INVALID_ID; - if (add_call && selected_callslot_ptr->IsParentModuleConnected()) { - connected_group = selected_callslot_ptr->GetParentModule()->GroupUID(); - } - ImGuiID selected_group_uid = selected_graph_ptr->GetSelectedGroup(); - ImGuiID group_uid = (connected_group != GUI_INVALID_ID) - ? (connected_group) - : ((selected_group_uid != GUI_INVALID_ID) - ? (selected_group_uid) - : (this->module_list_popup_hovered_group_uid)); - - if (auto group_ptr = selected_graph_ptr->GetGroup(group_uid)) { - Graph::QueueData queue_data; - queue_data.name_id = module_ptr->FullName(); - selected_graph_ptr->ResetStatePointers(); - group_ptr->AddModule(module_ptr); - queue_data.rename_id = module_ptr->FullName(); - selected_graph_ptr->PushSyncQueue(Graph::QueueAction::RENAME_MODULE, queue_data); - } + // If there is a group selected or hovered or the new call is connected to module which is part + // of group, add module to this group + if (!interfaceslot_selected) { + ImGuiID connected_group = GUI_INVALID_ID; + if (add_call && selected_callslot_ptr->IsParentModuleConnected()) { + connected_group = selected_callslot_ptr->GetParentModule()->GroupUID(); } + ImGuiID selected_group_uid = selected_graph_ptr->GetSelectedGroup(); + ImGuiID group_uid = (connected_group != GUI_INVALID_ID) + ? (connected_group) + : ((selected_group_uid != GUI_INVALID_ID) + ? (selected_group_uid) + : (this->module_list_popup_hovered_group_uid)); + + if (auto group_ptr = selected_graph_ptr->GetGroup(group_uid)) { + Graph::QueueData queue_data; + queue_data.name_id = module_ptr->FullName(); + selected_graph_ptr->ResetStatePointers(); + group_ptr->AddModule(module_ptr); + queue_data.rename_id = module_ptr->FullName(); + selected_graph_ptr->PushSyncQueue(Graph::QueueAction::RENAME_MODULE, queue_data); + } + } - // Add new call after module is created and after possible renaming due to group joining of module! - if (add_call) { - // Get call slots of last added module - for (auto& callslot_map : module_ptr->CallSlots()) { - for (auto& callslot_ptr : callslot_map.second) { - if (callslot_ptr->Name() == compat_callslot_name) { - if (selected_graph_ptr->AddCall(this->graph_collection.GetCallsStock(), - selected_callslot_ptr, callslot_ptr)) { - module_ptr->SetSelectedSlotPosition(); - } + // Add new call after module is created and after possible renaming due to group joining of module! + if (add_call) { + // Get call slots of last added module + for (auto& callslot_map : module_ptr->CallSlots()) { + for (auto& callslot_ptr : callslot_map.second) { + if (callslot_ptr->Name() == compat_callslot_name) { + if (selected_graph_ptr->AddCall(this->graph_collection.GetCallsStock(), + selected_callslot_ptr, callslot_ptr)) { + module_ptr->SetSelectedSlotPosition(); } } } } - // Place new module at mouse pos if added via separate module list child window. - else if (this->show_module_list_popup) { - module_ptr->SetScreenPosition(ImGui::GetMousePos()); - } } - if (this->show_module_list_popup) { - this->show_module_list_popup = false; - // ImGui::CloseCurrentPopup(); + // Place new module at mouse pos if added via separate module list child window. + else if (this->show_module_list_popup) { + module_ptr->SetScreenPosition(ImGui::GetMousePos()); } - } else { - megamol::core::utility::log::Log::DefaultLog.WriteError( - "[GUI] No project loaded. [%s, %s, line %d]\n", __FILE__, __FUNCTION__, __LINE__); } + if (this->show_module_list_popup) { + this->show_module_list_popup = false; + // ImGui::CloseCurrentPopup(); + } + } else { + megamol::core::utility::log::Log::DefaultLog.WriteError( + "[GUI] No project loaded. [%s, %s, line %d]\n", __FILE__, __FUNCTION__, __LINE__); } - // Hover tool tip - this->tooltip.ToolTip(mod.description, id, 0.5f, 5.0f); - - ImGui::PopID(); } + // Hover tool tip + this->tooltip.ToolTip(mod.description, id, 0.5f, 5.0f); + + ImGui::PopID(); id++; } - + ImGui::EndChild(); ImGui::EndGroup(); diff --git a/frontend/services/gui/src/windows/ParameterList.cpp b/frontend/services/gui/src/windows/ParameterList.cpp index d678ca93ae..e138bd8d16 100644 --- a/frontend/services/gui/src/windows/ParameterList.cpp +++ b/frontend/services/gui/src/windows/ParameterList.cpp @@ -152,7 +152,7 @@ bool ParameterList::Draw() { std::string module_label = module_ptr->FullName(); ImGui::PushID(module_ptr->UID()); - auto const& param_vec = module_ptr->Parameters(); + auto const& param_vec = module_ptr->ConstParameters(); bool highlight = false; for (auto const& param : param_vec) { if (param.GetParamPresentation().IsGUIHighlight()) From 7e2e6d26b7967992623543f588ded315faac61ee Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 6 Jul 2023 13:41:27 +0200 Subject: [PATCH 8/8] WIP ... --- frontend/services/gui/src/graph/CallSlot.cpp | 33 +++++-------------- frontend/services/gui/src/graph/CallSlot.h | 1 - .../gui/src/graph/GraphCollection.cpp | 30 +++++++++-------- frontend/services/gui/src/graph/Parameter.cpp | 2 +- frontend/services/gui/src/graph/Parameter.h | 2 +- 5 files changed, 28 insertions(+), 40 deletions(-) diff --git a/frontend/services/gui/src/graph/CallSlot.cpp b/frontend/services/gui/src/graph/CallSlot.cpp index fd79b4341f..b5729938d4 100644 --- a/frontend/services/gui/src/graph/CallSlot.cpp +++ b/frontend/services/gui/src/graph/CallSlot.cpp @@ -18,12 +18,10 @@ using namespace megamol::gui; megamol::gui::CallSlot::CallSlot(ImGuiID uid, const CallSlotPtr_t in_stock_callslot) : CallSlot(uid, in_stock_callslot->name, in_stock_callslot->description, - in_stock_callslot->compatible_call_idxs, - in_stock_callslot->type, in_stock_callslot->necessity) {} + in_stock_callslot->compatible_call_idxs, in_stock_callslot->type, in_stock_callslot->necessity) {} -megamol::gui::CallSlot::CallSlot( - ImGuiID uid, const std::string& name, const std::string& description, +megamol::gui::CallSlot::CallSlot(ImGuiID uid, const std::string& name, const std::string& description, const std::vector& compatible_call_idxs, CallSlotType type, megamol::core::AbstractCallSlotPresentation::Necessity necessity) : uid(uid) @@ -203,7 +201,13 @@ ImGuiID megamol::gui::CallSlot::GetCompatibleCallIndex( const CallSlotPtr_t& callslot_1, const CallSlotPtr_t& callslot_2) { if ((callslot_1 != nullptr) && (callslot_2 != nullptr)) { - if (callslot_1->GetParentModule() != callslot_2->GetParentModule() && (callslot_1->type != callslot_2->type)) { + bool different_parents = true; + auto pmc1 = callslot_1->IsParentModuleConnected(); + auto pmc2 = callslot_2->IsParentModuleConnected(); + if (pmc1 && pmc2) { + different_parents = (callslot_1->GetParentModule() != callslot_2->GetParentModule()); + } + if (different_parents && (callslot_1->type != callslot_2->type)) { // Return first found compatible call index for (auto& comp_call_idx_1 : callslot_1->compatible_call_idxs) { for (auto& comp_call_idx_2 : callslot_2->compatible_call_idxs) { @@ -218,25 +222,6 @@ ImGuiID megamol::gui::CallSlot::GetCompatibleCallIndex( } -ImGuiID megamol::gui::CallSlot::GetCompatibleCallIndex( - const CallSlotPtr_t& callslot, const CallSlot& stock_callslot) { - - if (callslot != nullptr) { - if (callslot->type != stock_callslot.type) { - // Return first found compatible call index - for (auto& comp_call_idx_1 : callslot->compatible_call_idxs) { - for (auto& comp_call_idx_2 : stock_callslot.compatible_call_idxs) { - if (comp_call_idx_1 == comp_call_idx_2) { - return static_cast(comp_call_idx_1); - } - } - } - } - } - return GUI_INVALID_ID; -} - - bool megamol::gui::CallSlot::IsConnectionValid(CallSlot& callslot) { // Check for different type diff --git a/frontend/services/gui/src/graph/CallSlot.h b/frontend/services/gui/src/graph/CallSlot.h index ce2c905328..9c59f43090 100644 --- a/frontend/services/gui/src/graph/CallSlot.h +++ b/frontend/services/gui/src/graph/CallSlot.h @@ -63,7 +63,6 @@ class CallSlot { const ModulePtr_t& GetParentModule(); static ImGuiID GetCompatibleCallIndex(const CallSlotPtr_t& callslot_1, const CallSlotPtr_t& callslot_2); - static ImGuiID GetCompatibleCallIndex(const CallSlotPtr_t& callslot, const CallSlot& stock_callslot); bool IsConnectionValid(CallSlot& callslot); diff --git a/frontend/services/gui/src/graph/GraphCollection.cpp b/frontend/services/gui/src/graph/GraphCollection.cpp index 9164ee3bd1..3c6cafddcc 100644 --- a/frontend/services/gui/src/graph/GraphCollection.cpp +++ b/frontend/services/gui/src/graph/GraphCollection.cpp @@ -544,7 +544,7 @@ bool megamol::gui::GraphCollection::LoadOrAddProjectFromFile( // First, rename existing modules with same name graph_ptr->UniqueModuleRename(view_full_name); // Add module and set as view instance - auto graph_module = + auto graph_module = graph_ptr->AddModule(this->modules_stock, view_class_name, view_name, view_namespace); if (graph_module == nullptr) { megamol::core::utility::log::Log::DefaultLog.WriteError( @@ -937,7 +937,8 @@ bool megamol::gui::GraphCollection::SaveProjectToFile(ImGuiID in_graph_uid, cons } -bool megamol::gui::GraphCollection::get_module_stock_data(std::shared_ptr mod_desc, const std::string& plugin_name) { +bool megamol::gui::GraphCollection::get_module_stock_data( + std::shared_ptr mod_desc, const std::string& plugin_name) { if (this->calls_stock.empty()) { megamol::core::utility::log::Log::DefaultLog.WriteError( @@ -972,7 +973,9 @@ bool megamol::gui::GraphCollection::get_module_stock_data(std::shared_ptr viewptr = std::dynamic_pointer_cast(new_mod); - Module stock_module(GUI_INVALID_ID, std::string(mod_desc->ClassName()), std::string(mod_desc->Description()), plugin_name, bool(viewptr != nullptr)); + auto stock_module = Module(GUI_INVALID_ID, std::string(mod_desc->ClassName()), + std::string(mod_desc->Description()), plugin_name, bool(viewptr != nullptr)); + this->modules_stock.emplace_back(stock_module); std::vector> paramSlots; std::vector> callerSlots; @@ -996,11 +999,12 @@ bool megamol::gui::GraphCollection::get_module_stock_data(std::shared_ptrParameter() != nullptr) { - stock_module.Parameters().emplace_back( - megamol::gui::Parameter::ReadNewCoreParameterToStockParameter((*param_slot))); + auto stock_param = megamol::gui::Parameter::ReadNewCoreParameterToStockParameter((*param_slot)); + this->modules_stock.back().Parameters().emplace_back(stock_param); } else { megamol::core::utility::log::Log::DefaultLog.WriteError( - "[GUI] Pointer to core parameter is nullptr. [%s, %s, line %d]\n", __FILE__, __FUNCTION__, __LINE__); + "[GUI] Pointer to core parameter is nullptr. [%s, %s, line %d]\n", __FILE__, __FUNCTION__, + __LINE__); } } @@ -1011,9 +1015,10 @@ bool megamol::gui::GraphCollection::get_module_stock_data(std::shared_ptrget_compatible_caller_idxs(caller_slot.get()); auto type = CallSlotType::CALLER; auto necessity = caller_slot->GetNecessity(); - - stock_module.CallSlots(type).emplace_back(std::make_shared< - CallSlot>(GUI_INVALID_ID, name, description, compatible_call_idxs, type, necessity)); + + this->modules_stock.back().AddCallSlot( + std::make_shared( + GUI_INVALID_ID, name, description, compatible_call_idxs, type, necessity)); } // CalleeSlots @@ -1024,7 +1029,7 @@ bool megamol::gui::GraphCollection::get_module_stock_data(std::shared_ptrGetNecessity(); - stock_module.CallSlots(type).emplace_back( + this->modules_stock.back().AddCallSlot( std::make_shared(GUI_INVALID_ID, name, description, compatible_call_idxs, type, necessity)); } @@ -1040,8 +1045,6 @@ bool megamol::gui::GraphCollection::get_module_stock_data(std::shared_ptrClassName()); - this->modules_stock.emplace_back(stock_module); - } catch (std::exception& e) { megamol::core::utility::log::Log::DefaultLog.WriteError( "[GUI] Error: %s [%s, %s, line %d]\n", e.what(), __FILE__, __FUNCTION__, __LINE__); @@ -1055,7 +1058,8 @@ bool megamol::gui::GraphCollection::get_module_stock_data(std::shared_ptr call_desc, const std::string& plugin_name) { +bool megamol::gui::GraphCollection::get_call_stock_data( + std::shared_ptr call_desc, const std::string& plugin_name) { try { diff --git a/frontend/services/gui/src/graph/Parameter.cpp b/frontend/services/gui/src/graph/Parameter.cpp index 672cfde46e..651d066367 100644 --- a/frontend/services/gui/src/graph/Parameter.cpp +++ b/frontend/services/gui/src/graph/Parameter.cpp @@ -311,7 +311,7 @@ bool megamol::gui::Parameter::SetValueString(const std::string& val_str, bool se } -megamol::gui::Parameter& megamol::gui::Parameter::ReadNewCoreParameterToStockParameter(megamol::core::param::ParamSlot& in_param_slot) { +megamol::gui::Parameter megamol::gui::Parameter::ReadNewCoreParameterToStockParameter(megamol::core::param::ParamSlot& in_param_slot) { std::string name = std::string(in_param_slot.Name().PeekBuffer()); std::string description = std::string(in_param_slot.Description().PeekBuffer()); diff --git a/frontend/services/gui/src/graph/Parameter.h b/frontend/services/gui/src/graph/Parameter.h index 4ae849be5d..cd46c3f5f6 100644 --- a/frontend/services/gui/src/graph/Parameter.h +++ b/frontend/services/gui/src/graph/Parameter.h @@ -98,7 +98,7 @@ class Parameter { // STATIC --------------------- - static megamol::gui::Parameter& ReadNewCoreParameterToStockParameter(ParamSlot& in_param_slot); + static megamol::gui::Parameter ReadNewCoreParameterToStockParameter(ParamSlot& in_param_slot); static bool ReadNewCoreParameterToNewParameter(ParamSlot& in_param_slot, std::shared_ptr& out_param, bool set_default_val, bool set_dirty,