Skip to content

Commit

Permalink
connect, disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
zdenyhraz committed May 30, 2024
1 parent 47aa0f5 commit 05c9b5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
21 changes: 2 additions & 19 deletions src/Gui/Windows/NodeEditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,7 @@ struct NodeEditor
{
// ed::AcceptNewItem() return true when user release mouse button.
if (ed::AcceptNewItem())
{
// TODO:
// m_Workflow.Connect(outputPinId.Get(), inputPinId.Get());

// Draw new link.
// ed::Link(m_Links.back().Id, m_Links.back().InputId, m_Links.back().OutputId);
}
m_Workflow.Connect(outputPinId.Get(), inputPinId.Get());

// You may choose to reject connection between these nodes
// by calling ed::RejectNewItem(). This will allow editor to give
Expand All @@ -130,18 +124,7 @@ struct NodeEditor
{
// If you agree that link can be deleted, accept deletion.
if (ed::AcceptDeletedItem())
{
// TODO:
// // Then remove link from your data.
// for (auto& link : m_Links)
// {
// if (link.Id == deletedLinkId)
// {
// m_Links.erase(&link);
// break;
// }
// }
}
m_Workflow.Disconnect(deletedLinkId.Get());

// You may reject link deletion by calling:
// ed::RejectDeletedItem();
Expand Down
25 changes: 19 additions & 6 deletions src/Microservice/Workflow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class Workflow

struct MicroserviceConnection
{
Microservice* outputMicroservice;
Microservice* inputMicroservice;
MicroserviceOutputParameter* outputParameter;
MicroserviceInputParameter* inputParameter;
Microservice* outputMicroservice = nullptr;
Microservice* inputMicroservice = nullptr;
MicroserviceOutputParameter* outputParameter = nullptr;
MicroserviceInputParameter* inputParameter = nullptr;

auto operator<=>(const MicroserviceConnection&) const = default;

Expand Down Expand Up @@ -160,10 +160,10 @@ class Workflow
}

if (not connection.outputMicroservice)
throw std::runtime_error(fmt::format("Failed to find output parameter for id {}", outputId));
return LOG_WARNING("Failed to find output parameter for id {}", outputId);

if (not connection.inputMicroservice)
throw std::runtime_error(fmt::format("Failed to find input parameter for id {}", inputId));
return LOG_WARNING("Failed to find input parameter for id {}", inputId);

if (connections.contains(connection.outputMicroservice))
if (std::ranges::any_of(connections.at(connection.outputMicroservice), [&connection](auto& conn) { return conn == connection; }))
Expand All @@ -174,6 +174,19 @@ class Workflow
connections[connection.outputMicroservice].push_back(std::move(connection));
}

void Disconnect(uintptr_t connectionId)
{
for (auto& [ms, connectionvec] : connections)
{
const auto size = connectionvec.size();
auto conn = std::ranges::remove_if(connectionvec, [connectionId](const auto& conn) { return conn.GetId() == connectionId; });
connectionvec.erase(conn.begin(), connectionvec.end());
if (connectionvec.size() != size)
return LOG_DEBUG("Disconnected connection {}", connectionId);
}
LOG_WARNING("Ignoring disconnect of connection {}", connectionId);
}

void TestInitialize()
{
LOG_FUNCTION;
Expand Down

0 comments on commit 05c9b5e

Please sign in to comment.