Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some GUI Refactoring ... #1208

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions core/include/mmcore/param/AbstractParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ class AbstractParam {
}
}

bool IsGUIHighlight() const {
return gui_presentation.IsGUIHighlight();
}

void SetGUIHighlight(bool highlight) {
if (gui_presentation.IsGUIHighlight() != highlight) {
gui_presentation.SetGUIHighlight(highlight);
indicatePresentationChange();
}
}

inline AbstractParamPresentation::Presentation GetGUIPresentation() const {
return gui_presentation.GetGUIPresentation();
}
Expand All @@ -121,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.
Expand Down
13 changes: 12 additions & 1 deletion core/include/mmcore/param/AbstractParamPresentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ class AbstractParamPresentation {
this->read_only = read_only;
}

bool IsGUIHighlight() const {
return highlight;
}

void SetGUIHighlight(bool highlight) {
this->highlight = highlight;
}

/**
* Set presentation of parameter in GUI.
*
Expand Down Expand Up @@ -163,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();

Expand All @@ -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;

Expand Down
12 changes: 8 additions & 4 deletions core/src/param/AbstractParamPresentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -87,9 +88,6 @@ void AbstractParamPresentation::InitPresentation(AbstractParamPresentation::Para

this->initialised = true;

this->SetGUIVisible(visible);
this->SetGUIReadOnly(read_only);

// Initialize presentations depending on parameter type
switch (param_type) {
case (ParamType::BOOL): {
Expand Down Expand Up @@ -203,6 +201,10 @@ bool AbstractParamPresentation::StateFromJSON(const nlohmann::json& in_json, con
valid &=
megamol::core::utility::get_json_value<bool>(gui_state, {"gui_read-only"}, &gui_read_only);

bool gui_highlight = false;
valid &=
megamol::core::utility::get_json_value<bool>(gui_state, {"gui_highlight"}, &gui_highlight);

int presentation_mode = 0;
valid &= megamol::core::utility::get_json_value<int>(
gui_state, {"gui_presentation_mode"}, &presentation_mode);
Expand All @@ -211,6 +213,7 @@ bool AbstractParamPresentation::StateFromJSON(const nlohmann::json& in_json, con
if (valid) {
this->SetGUIVisible(gui_visibility);
this->SetGUIReadOnly(gui_read_only);
this->SetGUIHighlight(gui_highlight);
this->SetGUIPresentation(gui_presentation_mode);
return true;
}
Expand All @@ -228,12 +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->IsGUIHighlight();
inout_json[GUI_JSON_TAG_GUISTATE_PARAMETERS][param_fullname]["gui_presentation_mode"] =
static_cast<int>(this->GetGUIPresentation());
} catch (...) {
Expand Down
6 changes: 5 additions & 1 deletion frontend/services/gui/src/graph/Call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>& functions)
const std::string& plugin_name, const std::vector<std::string>& functions)
: uid(uid)
, class_name(class_name)
, description(description)
Expand Down
15 changes: 9 additions & 6 deletions frontend/services/gui/src/graph/Call.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,21 @@ typedef std::shared_ptr<Module> ModulePtr_t;
// Types
typedef std::shared_ptr<Call> CallPtr_t;
typedef std::vector<CallPtr_t> CallPtrVector_t;
typedef std::vector<Call> CallVector_t;


/** ************************************************************************
* Defines call data structure for graph
*/
class Call {
public:
struct StockCall {
std::string class_name;
std::string description;
std::string plugin_name;
std::vector<std::string> 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<std::string>& functions);

~Call();

bool IsConnected();
Expand Down Expand Up @@ -96,6 +95,10 @@ class Call {
return this->gui_hidden;
}

inline const std::vector<std::string>& Functions() const {
return this->functions;
}

#ifdef MEGAMOL_USE_PROFILING

ImVec2 GetProfilingButtonPosition() {
Expand Down
32 changes: 12 additions & 20 deletions frontend/services/gui/src/graph/CallSlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ using namespace megamol;
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) {}


megamol::gui::CallSlot::CallSlot(ImGuiID uid, const std::string& name, const std::string& description,
const std::vector<size_t>& compatible_call_idxs, CallSlotType type,
megamol::core::AbstractCallSlotPresentation::Necessity necessity)
Expand Down Expand Up @@ -196,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) {
Expand All @@ -211,25 +222,6 @@ ImGuiID megamol::gui::CallSlot::GetCompatibleCallIndex(
}


ImGuiID megamol::gui::CallSlot::GetCompatibleCallIndex(
const CallSlotPtr_t& callslot, const CallSlot::StockCallSlot& 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<ImGuiID>(comp_call_idx_1);
}
}
}
}
}
return GUI_INVALID_ID;
}


bool megamol::gui::CallSlot::IsConnectionValid(CallSlot& callslot) {

// Check for different type
Expand Down
12 changes: 4 additions & 8 deletions frontend/services/gui/src/graph/CallSlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ typedef std::map<CallSlotType, CallSlotPtrVector_t> CallSlotPtrMap_t;
*/
class CallSlot {
public:
struct StockCallSlot {
std::string name;
std::string description;
std::vector<size_t> 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<size_t>& compatible_call_idxs, CallSlotType type,
megamol::core::AbstractCallSlotPresentation::Necessity necessity);

~CallSlot();

bool CallsConnected() const;
Expand All @@ -66,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::StockCallSlot& stock_callslot);

bool IsConnectionValid(CallSlot& callslot);

Expand Down
33 changes: 14 additions & 19 deletions frontend/services/gui/src/graph/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,38 +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<Module>(mod_uid, mod.class_name, mod.description, mod.plugin_name, mod.is_view);
std::make_shared<Module>(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.SetGUIVisible(p.gui_visibility);
parameter.SetGUIReadOnly(p.gui_read_only);
parameter.SetGUIPresentation(p.gui_presentation);
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<CallSlot>(megamol::gui::GenerateUniqueID(), c.name,
c.description, c.compatible_call_idxs, c.type, c.necessity);
auto callslot_ptr = std::make_shared<CallSlot>(megamol::gui::GenerateUniqueID(), c);
callslot_ptr->ConnectParentModule(mod_ptr);
mod_ptr->AddCallSlot(callslot_ptr);
}
Expand Down Expand Up @@ -370,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)) {
Expand Down Expand Up @@ -476,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)) {
Expand All @@ -493,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<Call>(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<Call>(megamol::gui::GenerateUniqueID(), call_stock_data);

return this->ConnectCall(call_ptr, callslot_1, callslot_2, use_queue) ? call_ptr : nullptr;

Expand Down
10 changes: 3 additions & 7 deletions frontend/services/gui/src/graph/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ namespace megamol::gui {
// Forward declarations
class Graph;

// Types
typedef std::vector<Module::StockModule> ModuleStockVector_t;
typedef std::vector<Call::StockCall> CallStockVector_t;


/** ************************************************************************
* Defines the graph
Expand Down Expand Up @@ -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);
Expand All @@ -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(
Expand Down
Loading