private bool AddLocationLink(LocationLinkKey key) { //Check if we know about this key already if(LinkKeyToLinkView.ContainsKey(key)) { return false; } //Trace.WriteLine("Add Link " + key.A.ToString() + " -> " + key.B.ToString()); LocationObj AObj = Store.Locations.GetObjectByID(key.A, false); LocationObj BObj = Store.Locations.GetObjectByID(key.B, false); if (AObj == null) return false; if (BObj == null) return false; if (AObj.VolumePosition.X < 0 && AObj.VolumePosition.Y < 0) return false; if (BObj.VolumePosition.X < 0 && BObj.VolumePosition.Y < 0) return false; if (AObj.VolumePosition == BObj.VolumePosition) return false; //LocationLinkKey key = new LocationLinkKey(link); //LocationLink linkView = new LocationLink(AView, BView); LocationLink linkView; linkView = LinkKeyToLinkView.GetOrAdd(key, (newLink) => { return new LocationLink(AObj, BObj); }); bool success = AddLocationLinkToSectionSearchGrids(AObj, BObj, linkView); if (success) { AddRefLocation(AObj); AddRefLocation(BObj); } return true; }
private void OnLinkedLocationPropertyChanged(object sender, PropertyChangedEventArgs e) { LocationObj loc = sender as LocationObj; if (loc == null) return; //Update if a position or everything has changed if (e.PropertyName.Contains("VolumePosition") || e.PropertyName.Contains("Position") || String.IsNullOrEmpty(e.PropertyName)) { // Trace.WriteLine("Linked Location property changed: " + loc.ToString() + " property: " + e.PropertyName); foreach (long linkID in loc.Links) { LocationLinkKey key = new LocationLinkKey(loc.ID, linkID); RemoveLocationLinks(key); AddLocationLink(key); } } }
internal void RemoveLocationLinks(LocationLinkKey key) { //LocationLinkKey key = new LocationLinkKey(link); LocationLink linkView; bool success = LinkKeyToLinkView.TryRemove(key, out linkView); if(false == success) return; success = RemoveLocationLinkFromSectionSearchGrids(linkView); if (success) { LocationObj AObj = linkView.A; LocationObj BObj = linkView.B; ReleaseRefLocation(AObj); ReleaseRefLocation(BObj); } }