Skip to content

Commit

Permalink
Added ability to delete nodes and links with delete key. Disabled dra…
Browse files Browse the repository at this point in the history
…g detach for nodes
  • Loading branch information
jasonbeverage committed Feb 5, 2025
1 parent c7b2855 commit 44e5e14
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/osgEarthImGui/ImGuiEventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ImGuiEventHandler::newFrame(osg::RenderInfo& renderInfo)
{
ImGui::CreateContext();
ImNodes::CreateContext();
ImNodes::PushAttributeFlag(ImNodesAttributeFlags_EnableLinkDetachWithDragClick);
//ImNodes::PushAttributeFlag(ImNodesAttributeFlags_EnableLinkDetachWithDragClick);
ImNodesIO& imNodesio = ImNodes::GetIO();
imNodesio.LinkDetachWithModifierClick.Modifier = &ImGui::GetIO().KeyCtrl;
imNodesio.MultipleSelectModifier.Modifier = &ImGui::GetIO().KeyCtrl;
Expand Down
56 changes: 50 additions & 6 deletions src/osgEarthImGui/NodeGraphGUI
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ namespace osgEarth

if (ImGui::Begin(name(), visible(), ImGuiWindowFlags_MenuBar))
{
// Capture the keyboard so we can use the delete key
ImGui::SetNextFrameWantCaptureKeyboard(true);

DrawMenuBar();

DrawToolbar();
Expand Down Expand Up @@ -761,15 +764,15 @@ namespace osgEarth
ImNodes::EndNode();
}

// Draw all the links
for (auto& o : _proceduralModelLayer->getNodeGraph()->operations)
{
for (auto& link : o->getLinks())
// Draw all the links
for (auto& o : _proceduralModelLayer->getNodeGraph()->operations)
{
ImNodes::Link(link.getId(), link._sourceAttribute->getId(), link._destinationAttribute->getId());
for (auto& link : o->getLinks())
{
ImNodes::Link(link.getId(), link._sourceAttribute->getId(), link._destinationAttribute->getId());
}
}
}
}

ImNodes::EndNodeEditor();

Expand Down Expand Up @@ -831,6 +834,47 @@ namespace osgEarth
}
}
}

if (ImGui::IsKeyPressed(ImGuiKey_Delete))
{
static int selected_items[256];
if (ImNodes::NumSelectedNodes() > 0)
{
ImNodes::GetSelectedNodes(selected_items);
for (int i = 0; i < ImNodes::NumSelectedNodes(); i++)
{
for (auto itr = _proceduralModelLayer->getNodeGraph()->operations.begin(); itr != _proceduralModelLayer->getNodeGraph()->operations.end(); ++itr)
{
if ((*itr)->getId() == selected_items[i])
{
_proceduralModelLayer->getNodeGraph()->operations.erase(itr);
break;
}
}
}
updateNodeGraph();
}

if (ImNodes::NumSelectedLinks() > 0)
{
ImNodes::GetSelectedLinks(selected_items);
for (int i = 0; i < ImNodes::NumSelectedLinks(); i++)
{
for (auto& o : _proceduralModelLayer->getNodeGraph()->operations)
{
for (auto itr = o->getLinks().begin(); itr != o->getLinks().end(); ++itr)
{
if (itr->getId() == selected_items[i])
{
o->getLinks().erase(itr);
break;
}
}
}
}
updateNodeGraph();
}
}
}
ImGui::End();
}
Expand Down

0 comments on commit 44e5e14

Please sign in to comment.