-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOutSocket.m
98 lines (74 loc) · 3.39 KB
/
OutSocket.m
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
classdef OutSocket < ConnectionSocket
properties
nextNode %The node before this one that is connected to it
end
methods
function obj = OutSocket(Node, type,stringPos,button,fcn)
%Connects the node and the socket, to make it possible to
%reference eachother
obj.node = Node;
obj.node.outSocket = obj;
obj.setSocketOffset();
%Draw the socket
obj.anno = annotation(type,stringPos,[obj.node.anno.Position(1) obj.node.anno.Position(2) obj.socketSize(1) obj.socketSize(2)],button,fcn,'Color','red','FaceColor',[.9 .9 .9]);
obj.node.updateSocketPositions();
end
function select(obj)
if ~isempty(obj.connectionLine)
obj.disconnectLine();
end
end
function drop(obj)
obj.connectLine();
end
function drag(obj)
if isempty(obj.connectionLine)
obj.newConnectionLine('out',[obj.anno.Position(1) obj.anno.Position(2)]);
end
if ~isempty(obj.connectionLine)
mouse = get(gcf,'CurrentPoint');
%Update the endposition of the line
obj.connectionLine.Position(3) = mouse(1) - obj.connectionLine.Position(1);
obj.connectionLine.Position(4) = mouse(2) - obj.connectionLine.Position(2);
end
end
function connectLine(obj)
connectToSocket = obj.checkForSocketInRange('InSocket');
if ~isempty(connectToSocket) && ~isempty(obj.connectionLine)
%If a connection to it already exists, remove it
if ~isempty(connectToSocket.connectionLine)
disp(connectToSocket.node.inSocket)
disp('Connection Line Exists -- Delete it')
connectToSocket.prevNode.outSocket.disconnectLine();
end
%Update end of line position to be inside the in socket
obj.connectionLine.Position(3) = connectToSocket.anno.Position(1) + obj.socketOffset(1) - obj.connectionLine.Position(1);
obj.connectionLine.Position(4) = connectToSocket.anno.Position(2) + obj.socketOffset(2) - obj.connectionLine.Position(2);
connectToSocket.connectionLine = obj.connectionLine;
obj.nextNode = connectToSocket.node;
connectToSocket.prevNode = obj.node;
else
try
obj.disconnectLine();
catch
end
end
end
function disconnectLine(obj)
disp('DISCONNECT')
delete(obj.connectionLine);
try
obj.connectionLine = [];
catch
end
if isa(obj.nextNode, 'SpectrumNode')
obj.nextNode.hideSpectrum();
end
try
obj.nextNode.inSocket.connectionLine = [];
obj.nextNode = [];
catch
end
end
end
end