From dca1286661f61e51943863de8ce68849a9578363 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Sat, 17 Apr 2021 17:31:47 -0700 Subject: Initial work on one-to-many/many-to-one connections --- core/src/Model/Workflow.hpp | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'core/src/Model/Workflow.hpp') diff --git a/core/src/Model/Workflow.hpp b/core/src/Model/Workflow.hpp index 2c83816..62dd9ca 100644 --- a/core/src/Model/Workflow.hpp +++ b/core/src/Model/Workflow.hpp @@ -7,21 +7,37 @@ #include #include #include +#include #include class WorkflowConnection { public: static constexpr auto kInvalidId = std::numeric_limits::max(); - size_t Source; - size_t Destination; - int SourcePin; - int DestinationPin; + enum Direction { + ManyToOne, + OneToMany, + }; + + struct ConnectionPoint { + size_t Node; + int Pin; + + bool operator==(const ConnectionPoint&) const = default; + }; + + std::vector MultiConnections; + ConnectionPoint SingleConnection; + Direction ConnectionDirection; public: WorkflowConnection(); bool IsValid() const; + std::span GetSourcePoints(); + std::span GetSourcePoints() const; + std::span GetDestinationPoints(); + std::span GetDestinationPoints() const; }; class WorkflowNode { @@ -54,17 +70,23 @@ protected: size_t Connection = WorkflowConnection::kInvalidId; BaseValue::Kind MatchingType = BaseValue::KindInvalid; bool ConnectionToConst = false; + bool AllowsMultipleConnections = false; /// A constant connection connects from a user-specified constant value, feeding to a valid \c Destination and \c DestinationPin (i.e. input pins). bool IsConstantConnection() const; bool IsConnected() const; + BaseValue::Kind GetMatchingType() const; + WorkflowConnection::Direction GetSupportedDirection() const; }; struct OutputPin { size_t Connection = WorkflowConnection::kInvalidId; BaseValue::Kind MatchingType = BaseValue::KindInvalid; + bool AllowsMultipleConnections = false; bool IsConnected() const; + BaseValue::Kind GetMatchingType() const; + WorkflowConnection::Direction GetSupportedDirection() const; }; friend class Workflow; @@ -131,9 +153,9 @@ public: void AddStep(std::unique_ptr step); void RemoveStep(size_t id); - void Connect(WorkflowNode& source, int sourceNode, WorkflowNode& destination, int destinationNode); - void DisconnectBySource(WorkflowNode& source, int sourceNode); - void DisconnectByDestination(WorkflowNode& destination, int destinationNode); + bool Connect(WorkflowNode& sourceNode, int sourcePin, WorkflowNode& destinationNode, int destinationPin); + bool DisconnectBySource(WorkflowNode& sourceNode, int sourcePin); + bool DisconnectByDestination(WorkflowNode& destinationNode, int destinationPin); private: std::pair AllocWorkflowConnection(); -- cgit v1.2.3-70-g09d2