-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnection.cs
127 lines (112 loc) · 4.59 KB
/
Connection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Windows.Input;
namespace Nurielite
{
/// <summary>
/// Represents a pathway of data, flowing out of one python algorithm and into another.
/// </summary>
public class Connection
{
// member variables
private Nodule m_pInNodule, m_pOutNodule; // same as below, but referenced for different reasons
private Nodule m_pOrigin;
private Nodule m_pEnd;
private bool m_bCompleted = false; // if connection has been created/assigned to two nodes
private ConnectionGraphic m_pGraphic;
// construction
/// <summary>
/// Initializes a new connection originating from specified nodule.
/// </summary>
/// <param name="pStart">The nodule to start the connection from.</param>
public Connection(Nodule pStart)
{
if (Master.VerboseMode) Master.log("Connection initialized");
m_pOrigin = pStart;
if (pStart.IsInput)
{
m_pInNodule = pStart;
if(pStart.Connections.Count > 0)
{
Connection x = pStart.Connections[0];
x.removeConnection();
}
}
else { m_pOutNodule = pStart; }
m_pGraphic = new ConnectionGraphic(this);
}
// properties
/// <summary>
/// The first nodule referred to during the creation of this connection. This property should only be used during the creation of the connection.(<see cref="Nodule"/>.)
/// </summary>
public Nodule Origin { get { return m_pOrigin; } set { m_pOrigin = value; } }
/// <summary>
/// The second nodule referred to during the creation of this connection. This property should only be used during the creation of the connection.
/// </summary>
public Nodule End { get { return m_pEnd; } set { m_pEnd = value; } }
/// <summary>
/// The terminal nodule for the data connection. (Data flows through connection TO this nodule.)
/// </summary>
public Nodule InputNodule { get { return m_pInNodule; } set { m_pInNodule = value; } }
/// <summary>
/// The introductory nodule for the data connection. (Data flows through connection FROM this nodule.)
/// </summary>
public Nodule OutputNodule { get { return m_pOutNodule; } set { m_pOutNodule = value; } }
/// <summary>
/// Represents whether the connection has been created and finalized between the nodules or not.
/// </summary>
public bool IsComplete { get { return m_bCompleted; } set { m_bCompleted = value; } }
/// <summary>
/// GUI/Visual controller associated with this connection. (<see cref="ConnectionGraphic"/>)
/// </summary>
public ConnectionGraphic Graphic { get { return m_pGraphic; } set { m_pGraphic = value; } }
// -- FUNCTIONS --
/// <summary>
/// Finalizes the creation process of a connection between nodules, and adds a connection reference inside the involved nodules. Returns true on success, false on failure.
/// </summary>
/// <param name="pOther">The end nodule (<see cref="Connection.End"/>) to connect to the origin nodule.</param>
public bool completeConnection(Nodule pOther)
{
m_pEnd = pOther;
if (m_pOutNodule == null) { m_pOutNodule = pOther; }
else { m_pInNodule = pOther; }
// make sure the nodes aren't the same and are not both inputs or outputs
if (m_pOrigin.Equals(m_pEnd) ||
m_pOrigin.IsInput == m_pEnd.IsInput ||
m_pOrigin.Parent == m_pEnd.Parent)
{
m_pGraphic.removeGraphic();
return false;
}
// set end point to end node center
m_pGraphic.finishVisualConnection(m_pEnd);
m_bCompleted = true;
int iInputBlockID = m_pInNodule.Parent.ID;
int iInputNodeID = m_pInNodule.GroupNum;
int iOutputBlockID = m_pOutNodule.Parent.ID;
int iOutputNodeID = m_pOutNodule.GroupNum;
if(Master.VerboseMode) Master.log("Connection created - OutputID: " + iOutputBlockID + " (out-node " + iOutputNodeID + ") InputID: " + iInputBlockID + " (in-node " + iInputNodeID + ")");
return true;
}
/// <summary>
/// Safely remove the connection from all involved nodules and deletes the visual representation.
/// </summary>
/// <remarks>
/// Connection must have already been created and finalized.
/// </remarks>
public void removeConnection()
{
// remove all the things! (effectively delete connection)
m_pOrigin.removeConnection(this);
m_pEnd.removeConnection(this);
m_pGraphic.removeGraphic();
if (Master.VerboseMode) Master.log("Connection destroyed");
}
}
}