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

Configurator: Fix additional "ghost" module when adding new module to group #1194

Merged
merged 2 commits into from
Jul 4, 2023
Merged
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
182 changes: 92 additions & 90 deletions frontend/services/gui/src/graph/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,8 @@ bool megamol::gui::Graph::DeleteModule(ImGuiID module_uid, bool use_queue) {
GroupPtr_t module_group_ptr = nullptr;
for (auto& group_ptr : this->groups) {
if (group_ptr->ContainsModule(module_uid)) {
group_ptr->RemoveModule(module_uid);
module_group_ptr = group_ptr;

queue_data.name_id = current_full_name;
queue_data.rename_id = (*iter)->FullName();
if (use_queue) {
this->PushSyncQueue(QueueAction::RENAME_MODULE, queue_data);
}
this->RemoveGroupModule(group_ptr->UID(), module_uid, use_queue, false);
}
}

Expand All @@ -297,6 +291,7 @@ bool megamol::gui::Graph::DeleteModule(ImGuiID module_uid, bool use_queue) {
module_group_ptr->RestoreInterfaceslots();
}


#ifdef GUI_VERBOSE
megamol::core::utility::log::Log::DefaultLog.WriteInfo(
"[GUI] Deleted module '%s' (uid %i) from project '%s'.\n", (*iter)->FullName().c_str(),
Expand Down Expand Up @@ -803,12 +798,13 @@ ImGuiID megamol::gui::Graph::AddGroup(const std::string& group_name) {
auto group_ptr = std::make_shared<Group>(group_id);
group_ptr->SetName((group_name.empty()) ? (this->generate_unique_group_name()) : (group_name));
this->groups.emplace_back(group_ptr);
this->ForceSetDirty();

#ifdef GUI_VERBOSE
megamol::core::utility::log::Log::DefaultLog.WriteInfo("[GUI] Added group '%s' (uid %i) to project '%s'.\n",
group_ptr->Name().c_str(), group_ptr->UID(), this->name.c_str());
#endif // GUI_VERBOSE

this->ForceSetDirty();
return group_id;

} catch (std::exception& e) {
Expand Down Expand Up @@ -840,7 +836,6 @@ megamol::gui::GroupPtr_t megamol::gui::Graph::GetGroup(ImGuiID group_uid) {

bool megamol::gui::Graph::DeleteGroup(ImGuiID group_uid) {

// ! No syncronisation of module renaming considered
try {
for (auto iter = this->groups.begin(); iter != this->groups.end(); iter++) {
if ((*iter)->UID() == group_uid) {
Expand All @@ -861,8 +856,6 @@ bool megamol::gui::Graph::DeleteGroup(ImGuiID group_uid) {
this->groups.erase(iter);

this->ForceSetDirty();

this->ForceUpdate();
return true;
}
}
Expand All @@ -885,32 +878,89 @@ bool megamol::gui::Graph::DeleteGroup(ImGuiID group_uid) {
ImGuiID megamol::gui::Graph::AddGroupModule(
const std::string& group_name, const ModulePtr_t& module_ptr, bool use_queue) {

// Only create new group if given name is not empty
if (!group_name.empty()) {
// Check if group with given name already exists
ImGuiID existing_group_uid = GUI_INVALID_ID;
for (auto& group_ptr : this->groups) {
if (group_ptr->Name() == group_name) {
if (existing_group_uid != GUI_INVALID_ID) {
megamol::core::utility::log::Log::DefaultLog.WriteWarn(
"[GUI] Warning: Found groups with same name. [%s, %s, line %d]\n", __FILE__, __FUNCTION__,
__LINE__);
}
existing_group_uid = group_ptr->UID();
}
}
// Create new group if there is no one with given name
if (existing_group_uid == GUI_INVALID_ID) {
existing_group_uid = this->AddGroup(group_name);
}
// Add module to group
for (auto& group_ptr : this->groups) {
if (group_ptr->UID() == existing_group_uid) {
if (this->AddGroupModule(existing_group_uid, module_ptr, use_queue) != GUI_INVALID_ID) {
return existing_group_uid;
}
}
}
}
return GUI_INVALID_ID;
}


ImGuiID megamol::gui::Graph::AddGroupModule(ImGuiID group_uid, const ModulePtr_t& module_ptr, bool use_queue) {

try {
// Only create new group if given name is not empty
if (!group_name.empty()) {
// Check if group with given name already exists
ImGuiID existing_group_uid = GUI_INVALID_ID;
for (auto& group_ptr : this->groups) {
if (group_ptr->Name() == group_name) {
existing_group_uid = group_ptr->UID();
}
}
// Create new group if there is no one with given name
if (existing_group_uid == GUI_INVALID_ID) {
existing_group_uid = this->AddGroup(group_name);
}
// Add module to group
for (auto& group_ptr : this->groups) {
if (group_ptr->UID() == existing_group_uid) {
Graph::QueueData queue_data;
queue_data.name_id = module_ptr->FullName();
if (group_ptr->AddModule(module_ptr)) {
queue_data.rename_id = module_ptr->FullName();
if (use_queue) {
this->PushSyncQueue(Graph::QueueAction::RENAME_MODULE, queue_data);
// Add module to group
for (auto& group_ptr : this->groups) {
if (group_ptr->UID() == group_uid) {
Graph::QueueData queue_data;
queue_data.name_id = module_ptr->FullName();
if (group_ptr->AddModule(module_ptr)) {
queue_data.rename_id = module_ptr->FullName();
if (use_queue) {
this->PushSyncQueue(Graph::QueueAction::RENAME_MODULE, queue_data);
}
this->ForceSetDirty();
return group_uid;
}
}
}

} catch (std::exception& e) {
megamol::core::utility::log::Log::DefaultLog.WriteError(
"[GUI] Error: %s [%s, %s, line %d]\n", e.what(), __FILE__, __FUNCTION__, __LINE__);
return GUI_INVALID_ID;
} catch (...) {
megamol::core::utility::log::Log::DefaultLog.WriteError(
"[GUI] Unknown Error. [%s, %s, line %d]\n", __FILE__, __FUNCTION__, __LINE__);
return GUI_INVALID_ID;
}

return GUI_INVALID_ID;
}


ImGuiID megamol::gui::Graph::RemoveGroupModule(
ImGuiID group_uid, ImGuiID module_uid, bool use_queue, bool reset_interface) {

try {
// Remove module to group
for (auto& group_ptr : this->groups) {
if (group_ptr->UID() == group_uid) {
for (auto module_ptr : this->modules) {
if (module_ptr->UID() == module_uid) {
Graph::QueueData queue_data;
queue_data.name_id = module_ptr->FullName();
if (group_ptr->RemoveModule(module_ptr->UID(), reset_interface)) {
queue_data.rename_id = module_ptr->FullName();
if (use_queue) {
this->PushSyncQueue(Graph::QueueAction::RENAME_MODULE, queue_data);
}
this->ForceSetDirty();
return group_uid;
}
this->ForceSetDirty();
return existing_group_uid;
}
}
}
Expand Down Expand Up @@ -973,8 +1023,6 @@ bool megamol::gui::Graph::UniqueModuleRename(const std::string& module_full_name
queue_data.rename_id = mod->FullName();
this->PushSyncQueue(QueueAction::RENAME_MODULE, queue_data);

this->ForceUpdate();

megamol::core::utility::log::Log::DefaultLog.WriteWarn(
"[GUI] Renamed existing module '%s' while adding module with same name. "
"This is required for successful unambiguous parameter addressing which uses the module "
Expand Down Expand Up @@ -1726,8 +1774,6 @@ void megamol::gui::Graph::Draw(GraphState_t& state) {
}
}
if (module_ptr != nullptr) {
std::string current_module_fullname = module_ptr->FullName();

// Add module to new or already existing group
// Create new group for multiple selected modules only once!
ImGuiID group_uid = GUI_INVALID_ID;
Expand All @@ -1740,47 +1786,22 @@ void megamol::gui::Graph::Draw(GraphState_t& state) {
group_uid = uid_pair.second;
}

if (auto add_group_ptr = this->GetGroup(group_uid)) {
Graph::QueueData queue_data;
queue_data.name_id = module_ptr->FullName();

// Remove module from previous associated group
ImGuiID module_group_uid = module_ptr->GroupUID();
if (auto remove_group_ptr = this->GetGroup(module_group_uid)) {
if (remove_group_ptr->UID() != add_group_ptr->UID()) {
remove_group_ptr->RemoveModule(module_ptr->UID());
remove_group_ptr->RestoreInterfaceslots();
}
}

// Add module to group
add_group_ptr->AddModule(module_ptr);
queue_data.rename_id = module_ptr->FullName();
this->PushSyncQueue(Graph::QueueAction::RENAME_MODULE, queue_data);
this->ForceSetDirty();
}
/// Without intermediate renaming via queue!
/// Would trigger megamol::gui::GraphCollection::NotifyRunningGraph_RenameModule for already renamed module!
std::string current_module_groupname = module_ptr->GroupName();
this->RemoveGroupModule(module_ptr->GroupUID(), module_ptr->UID(), false);
module_ptr->SetGroupName(current_module_groupname);
this->AddGroupModule(group_uid, module_ptr, true);
}
}
reset_state = true;
}
// Remove module from group -------------------------------------------
if (!this->gui_graph_state.interact.modules_remove_group_uids.empty()) {
for (auto& module_uid : this->gui_graph_state.interact.modules_remove_group_uids) {
ModulePtr_t module_ptr;
for (auto& mod : this->Modules()) {
if (mod->UID() == module_uid) {
module_ptr = mod;
}
}
for (auto& remove_group_ptr : this->GetGroups()) {
if (remove_group_ptr->ContainsModule(module_uid)) {
Graph::QueueData queue_data;
queue_data.name_id = module_ptr->FullName();
remove_group_ptr->RemoveModule(module_ptr->UID());
remove_group_ptr->RestoreInterfaceslots();
queue_data.rename_id = module_ptr->FullName();
this->PushSyncQueue(Graph::QueueAction::RENAME_MODULE, queue_data);
this->ForceSetDirty();
this->RemoveGroupModule(remove_group_ptr->UID(), module_uid, true);
}
}
}
Expand Down Expand Up @@ -1866,26 +1887,7 @@ void megamol::gui::Graph::Draw(GraphState_t& state) {
this->DeleteCall(this->gui_graph_state.interact.call_selected_uid);
}
if (this->gui_graph_state.interact.group_selected_uid != GUI_INVALID_ID) {
// Save old name of modules
std::vector<std::pair<ImGuiID, std::string>> module_uid_name_pair;
if (auto group_ptr = this->GetGroup(this->gui_graph_state.interact.group_selected_uid)) {
for (auto& module_ptr : group_ptr->Modules()) {
module_uid_name_pair.push_back({module_ptr->UID(), module_ptr->FullName()});
}
}
// Delete group
this->DeleteGroup(this->gui_graph_state.interact.group_selected_uid);
// Push module renaming to sync queue
for (auto& module_ptr : this->Modules()) {
for (auto& module_pair : module_uid_name_pair) {
if (module_ptr->UID() == module_pair.first) {
Graph::QueueData queue_data;
queue_data.name_id = module_pair.second;
queue_data.rename_id = module_ptr->FullName();
this->PushSyncQueue(Graph::QueueAction::RENAME_MODULE, queue_data);
}
}
}
}
if (this->gui_graph_state.interact.interfaceslot_selected_uid != GUI_INVALID_ID) {
for (auto& group_ptr : this->GetGroups()) {
Expand Down
7 changes: 3 additions & 4 deletions frontend/services/gui/src/graph/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class Graph {
}
GroupPtr_t GetGroup(ImGuiID group_uid);
ImGuiID AddGroupModule(const std::string& group_name, const ModulePtr_t& module_ptr, bool use_queue = true);
ImGuiID AddGroupModule(ImGuiID group_uid, const ModulePtr_t& module_ptr, bool use_queue = true);
ImGuiID RemoveGroupModule(
ImGuiID group_uid, ImGuiID module_uid, bool use_queue = true, bool reset_interface = true);

void Clear();

Expand Down Expand Up @@ -137,10 +140,6 @@ class Graph {
return this->name;
}

void ForceUpdate() {
this->gui_update = true;
}

void ResetStatePointers() {
this->gui_graph_state.interact.callslot_compat_ptr.reset();
this->gui_graph_state.interact.interfaceslot_compat_ptr.reset();
Expand Down
22 changes: 11 additions & 11 deletions frontend/services/gui/src/graph/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ megamol::gui::Group::~Group() {
module_uids.emplace_back(module_ptr->UID());
}
for (auto& module_uid : module_uids) {
this->RemoveModule(module_uid);
this->RemoveModule(module_uid, false);
}
this->modules.clear();

Expand Down Expand Up @@ -75,7 +75,7 @@ bool megamol::gui::Group::AddModule(const ModulePtr_t& module_ptr) {
module_ptr->SetHidden(this->gui_collapsed_view);
module_ptr->SetGroupName(this->name);

this->ForceUpdate();
this->gui_update = true;
this->RestoreInterfaceslots();

#ifdef GUI_VERBOSE
Expand All @@ -86,7 +86,7 @@ bool megamol::gui::Group::AddModule(const ModulePtr_t& module_ptr) {
}


bool megamol::gui::Group::RemoveModule(ImGuiID module_uid) {
bool megamol::gui::Group::RemoveModule(ImGuiID module_uid, bool restore_interface) {

try {
for (auto mod_iter = this->modules.begin(); mod_iter != this->modules.end(); mod_iter++) {
Expand All @@ -110,12 +110,12 @@ bool megamol::gui::Group::RemoveModule(ImGuiID module_uid) {
(*mod_iter).reset();
this->modules.erase(mod_iter);


/// Do not restore interface slots here.
/// E.g. RestoreInterfaceslots() should only be triggered,
/// after connected calls of deleted module are deleted.

this->ForceUpdate();
if (restore_interface) {
/// E.g. RestoreInterfaceslots() should only be triggered,
/// after connected calls of deleted module are deleted.
this->RestoreInterfaceslots();
}
this->gui_update = true;

return true;
}
Expand Down Expand Up @@ -191,7 +191,7 @@ InterfaceSlotPtr_t megamol::gui::Group::AddInterfaceSlot(const CallSlotPtr_t& ca
if (interfaceslot_ptr->AddCallSlot(callslot_ptr, interfaceslot_ptr)) {

interfaceslot_ptr->SetGroupViewCollapsed(this->gui_collapsed_view);
this->ForceUpdate();
this->gui_update = true;

return interfaceslot_ptr;
}
Expand Down Expand Up @@ -300,7 +300,7 @@ bool megamol::gui::Group::DeleteInterfaceSlot(ImGuiID interfaceslot_uid) {
(*iter).reset();
interfaceslot_map.second.erase(iter);

this->ForceUpdate();
this->gui_update = true;

return true;
}
Expand Down
6 changes: 1 addition & 5 deletions frontend/services/gui/src/graph/Group.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Group {
~Group();

bool AddModule(const ModulePtr_t& module_ptr);
bool RemoveModule(ImGuiID module_uid);
bool RemoveModule(ImGuiID module_uid, bool retore_interface = true);
bool ContainsModule(ImGuiID module_uid);
inline bool Empty() {
return (this->modules.empty());
Expand Down Expand Up @@ -69,10 +69,6 @@ class Group {
inline ImVec2 Size() const {
return this->gui_size;
}
inline void ForceUpdate() {
this->gui_update = true;
}

inline void SetName(const std::string& group_name) {
this->name = group_name;
}
Expand Down
Loading