-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathObjectCollection.pde
More file actions
104 lines (99 loc) · 2.93 KB
/
ObjectCollection.pde
File metadata and controls
104 lines (99 loc) · 2.93 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
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
public class ObjectCollection extends Collection {
private ArrayList<Path> fAxons, fDendrites;
private ArrayList<Soma> fSomas;
private ArrayList<Initiator> fInitiators;
private ArrayList<Synapse> fSynapses;
public ObjectCollection() {
fAxons = new ArrayList<Path>();
fDendrites = new ArrayList<Path>();
fSomas = new ArrayList<Soma>();
fSynapses = new ArrayList<Synapse>();
fInitiators = new ArrayList<Initiator>();
}
public void add(Interactive s) {
if (s != null) {
switch(s.getType()) {
case DENDRITE:
fDendrites.add((Dendrite)s);
break;
case AXON:
fAxons.add((Axon)s);
break;
case SYNAPSE:
fSynapses.add((Synapse)s);
break;
case SOMA:
fSomas.add((Soma)s);
break;
case INITIATOR:
fInitiators.add((Initiator)s);
break;
}
fObjs.add(s);
}
}
public void remove(Interactive s) {
if (s != null) {
switch(s.getType()) {
case AXON:
fAxons.remove((Axon)s);
case DENDRITE:
fDendrites.remove((Dendrite)s);
remove((Interactive)((Path)s).getDest());
Path path = (Path)s;
ArrayList<Path> paths = path.getConnectedPaths();
for (Path p : paths)
remove((Interactive)p);
break;
case SYNAPSE:
fSynapses.remove((Synapse)s);
Synapse ss = (Synapse)s;
remove((Interactive)(ss.getDendrite()));
break;
case SOMA:
fSomas.remove((Soma)s);
case INITIATOR:
fInitiators.remove((Initiator)s);
Cell cell = (Cell)s;
ArrayList<Path> axons = cell.getAxons();
for (Path p : axons)
remove((Interactive)p);
ArrayList<Path> dendrites = cell.getDendrites();
for (Path p : dendrites)
remove((Interactive)p);
break;
}
fObjs.remove(s);
}
}
public boolean onMouseDown(float x, float y, int key, int keyCode) {
for (int i = fObjs.size()-1; i>=0; i--) {
Interactive curr = fObjs.get(i);
if (curr.onMouseDown(x, y)) {
if (curr.getType() == INITIATOR || curr.getType() == SOMA) {
if (!fSelectedObjs.contains(curr) && curr.fVisible) {
fSelectedObjs.add(curr);
// @TODO: using selec to set selected state and trigger corresponding changes
curr.select(x, y);
}
else if (key == CODED && keyCode == ALT) {
fSelectedObjs.remove(curr);
}
}
return true;
}
}
// if (!(key == CODED && keyCode == SHIFT))
return false;
}
public boolean onMouseDragged(float x, float y) {
for (int i = fObjs.size()-1; i>=0; i--) {
Interactive curr = fObjs.get(i);
if (curr.fVisible && curr.onMouseDragged(x, y)) {
// syncAttributes(curr);
return true;
}
}
return false;
}
}