public override void OnBusRemoved(Bus bus, int index) { if (!_bridge.Buses.ContainsKey(bus.InstanceId)) { return; } BusShape shape = _bridge.Buses[bus.InstanceId]; _bridge.Buses.Remove(bus.InstanceId); _bridge.Model.RemoveShape(shape); _presentation.Invalidate(); }
public override void OnBusAdded(Bus bus, int index) { if (_bridge.Buses.ContainsKey(bus.InstanceId)) { return; } BusShape shape = new BusShape(new CommandReference(bus.InstanceId, index)); shape.Bus = bus; shape.Location = CreateRandomLocation(); _bridge.Buses.Add(bus.InstanceId, shape); _bridge.Model.AddShape(shape); _presentation.Invalidate(); }
void NetronEntityRemovedHandler(object sender, EntityEventArgs e) { IDiagramEntity entity = e.Entity; SignalShape ss = entity as SignalShape; if (ss != null) { if (!_bridge.Signals.ContainsValue(ss)) { return; } _bridge.Signals.Remove(ss.SignalReference.InstanceId); PostCommandRemoveSignal(ss.SignalReference, true); return; } BusShape bs = entity as BusShape; if (bs != null) { if (!_bridge.Buses.ContainsValue(bs)) { return; } _bridge.Buses.Remove(bs.BusReference.InstanceId); PostCommandRemoveBus(bs.BusReference); return; } PortShape ps = entity as PortShape; if (ps != null) { if (!_bridge.Ports.ContainsValue(ps)) { return; } _bridge.Ports.Remove(ps.PortReference.InstanceId); PostCommandRemovePort(ps.PortReference, true); return; } IConnection cn = entity as IConnection; if (cn != null) { } }
public override void OnBusValueChanged(Bus bus) { BusShape bs = _bridge.Buses[bus.InstanceId]; bs.AssignFly(GetFlyweightForBus(bus.Value)); }
void Model_OnConnectorAttached(object sender, ConnectorsEventArgs e) { if (maskNDrives) { return; } bool wasMasked = maskMDrives; try { maskMDrives = true; IConnection con = _bridge.Model.ConnectorHolders[e.SubjectConnector] as IConnection; // get rid of uninteresting situations if (con != null) { if (con.From.AttachedTo == null || con.To.AttachedTo == null) { return; } } else { con = _bridge.Model.ConnectorHolders[e.ObjectConnector] as IConnection; if (con != null) { if (con.From.AttachedTo == null || con.To.AttachedTo == null) { return; } } else { return; } } // find out who connects to whom IConnector portConnector = con.From.AttachedTo; IShape portShape = (IShape)_bridge.Model.ConnectorHolders[portConnector]; IShape valueShape = (IShape)_bridge.Model.ConnectorHolders[con.To.AttachedTo]; PortShape port = portShape as PortShape; if (port == null) { port = valueShape as PortShape; if (port == null) { return; } valueShape = portShape; //ensure valueShape should now be either signal or bus portConnector = con.To.AttachedTo; } SignalShape signal = valueShape as SignalShape; if (signal != null) { // PORT <-> SIGNAL int index = -1; List <YttriumConnector> sl = port.InputConnectors; for (int i = 0; i < sl.Count; i++) { if (sl[i] == portConnector) { index = i; break; } } if (index > -1) { PostCommandSignalDrivesPort(signal.SignalReference, port.PortReference, index); return; } index = -1; sl = port.OutputConnectors; for (int i = 0; i < sl.Count; i++) { if (sl[i] == portConnector) { index = i; break; } } if (index > -1) { PostCommandPortDrivesSignal(signal.SignalReference, port.PortReference, index); } return; } BusShape bus = valueShape as BusShape; if (bus != null) { // PORT <-> BUS int index = -1; List <YttriumConnector> bl = port.BusConnectors; for (int i = 0; i < bl.Count; i++) { if (bl[i] == portConnector) { index = i; break; } } if (index > -1) { PostCommandBusAttachedToPort(bus.BusReference, port.PortReference, index); } return; } } finally { maskMDrives = wasMasked; } }