public void createConnection(RTIO io, RTIO ioto) { if (io == ioto) { return; // Loop back not allowed } // Check for attached nets if ((ioto.connectedTo != null) && (io.connectedTo != null)) { // Both connected already if (ioto.connectedTo == io.connectedTo) { return; // Already connected! } // Merge Nets ProcessingNet voidNet = ioto.connectedTo; LockWorker(); io.connectedTo.MergeFrom(ioto.connectedTo); nets.Remove(voidNet); io.connectedTo.addConnection(io, ioto); UnLockWorker(); return; } if (io.connectedTo != null) { LockWorker(); io.connectedTo.addConnection(io, ioto); UnLockWorker(); return; } if (ioto.connectedTo != null) { LockWorker(); ioto.connectedTo.addConnection(io, ioto); UnLockWorker(); return; } // Still here --> create new net ProcessingNet net = new ProcessingNet(this); LockWorker(); net.addConnection(io, ioto); nets.Add(net); UnLockWorker(); }
public void FixGraph() { // Step 1: Remove unreferenced IOs and unconnected IOs in the connection List List <Boolean> referenced = new List <bool>(); foreach (RTIO io in connectedIOs) { referenced.Add(false); } foreach (ProcessingConnection cnct in connections) { referenced[cnct.i1] = true; referenced[cnct.i2] = true; } int i = 0; while (i < referenced.Count) { if (!referenced[i]) { connectedIOs[i].connectedTo = null; connectedIOs.RemoveAt(i); referenced.RemoveAt(i); foreach (ProcessingConnection cnct in connections) { cnct.IntelliRemove(i); } } else { i++; } } // Step 2: Remove already unconnected IOs i = 0; while (i < connectedIOs.Count) { if (connectedIOs[i].connectedTo == null) { // Found one foreach (ProcessingConnection cnct in connections) { cnct.IntelliRemove(i); } connectedIOs.RemoveAt(i); } else { i++; } } // Step 3: Check for Valid Net at all if (connectedIOs.Count < 2) { // less than two nodes --> invalid foreach (RTIO pio in connectedIOs) { pio.connectedTo = null; } owner.nets.Remove(this); return; } // Step 4: Check for disconnected Nets List <ProcessingConnectionRef> cr = new List <ProcessingConnectionRef>(); foreach (ProcessingConnection cnct in connections) { cr.Add(new ProcessingConnectionRef(connectedIOs[cnct.i1], connectedIOs[cnct.i2])); } for (i = 0; i < cr.Count; i++) { cr[i].group = i; } for (i = 0; i < cr.Count; i++) { for (int j = 0; j < cr.Count; j++) { if (j != i) { if (cr[j].ConnectedTo(cr[i])) { int grp = (cr[i].group < cr[j].group) ? cr[i].group : cr[j].group; cr[i].group = cr[j].group = grp; } } } } List <int> groups = new List <int>(); foreach (ProcessingConnectionRef c in cr) { if (groups.IndexOf(c.group) < 0) { groups.Add(c.group); } } // Now groups contains the independant list of nets if (groups.Count > 1) { // Must Split // Remove all Links first foreach (RTIO io in connectedIOs) { io.connectedTo = null; } List <ProcessingNet> newNets = new List <ProcessingNet>(); foreach (int grp in groups) { ProcessingNet pn = new ProcessingNet(owner); foreach (ProcessingConnectionRef c in cr) { if (c.group == grp) { pn.addConnection(c.i1, c.i2); } } newNets.Add(pn); } CopyFrom(newNets[0]); CheckValidity(); newNets.RemoveAt(0); foreach (ProcessingNet n in newNets) { owner.nets.Add(n); n.CheckValidity(); } } else { // Still one Set --> everything is ok CheckValidity(); } }