-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionSocket.m
More file actions
60 lines (50 loc) · 2.23 KB
/
ConnectionSocket.m
File metadata and controls
60 lines (50 loc) · 2.23 KB
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
classdef (Abstract) ConnectionSocket < Interactable
properties
connectionLine;
node;
socketOffset;
socketSize = [.03 .05]; %The size of the sockets
maxConnectionRange = 0.05;
end
methods
function setSocketOffset(obj)
obj.socketOffset = [(obj.socketSize(1)/2) (obj.socketSize(2)/2)];
end
function newConnectionLine(obj, from, socketPos)
%Create new connection line from input / output socket to the
%other one.
mouse = get(gcf,'CurrentPoint');
%Position(n)
%startOfLine x = 1, in y = 3
%endOfLine x = 2, y = 4
if strcmp(from, 'out')
obj.connectionLine = annotation('line',[socketPos(1)+obj.socketOffset(1) mouse(1)], [socketPos(2)+obj.socketOffset(2) mouse(2)]);
elseif strcmp(from, 'in') %Not used anymore
obj.connectionLine = annotation('line',[mouse(1) socketPos(1)+obj.socketOffset(1)], [mouse(2) socketPos(2)+obj.socketOffset(2)]);
end
end
%return the socket that is in range of the mouse position
function socketInRange = checkForSocketInRange(obj,socketType)
global Interactables;
socketInRange = [];
for i = 1:length(Interactables)
if isa(Interactables{i}, socketType)
mouse = get(gcf,'CurrentPoint');
if ~isempty(Interactables{i})
socketPos = [Interactables{i}.anno.Position(1) + Interactables{i}.socketOffset(1) Interactables{i}.anno.Position(2) + Interactables{i}.socketOffset(2)];
distance = pdist([mouse; socketPos],'euclidean');
if distance < obj.maxConnectionRange
socketInRange = Interactables{i};
return
end
end
end
end
return
end
end
methods (Abstract)
connectLine(obj);
disconnectLine(obj);
end
end