コード例 #1
0
 private void UpdateLinkBundleRemove(Link link) {
   if (link == null) return;
   // see if there's an existing LinkBundle for this link
   LinkBundle bundle = link.Bundle;
   if (bundle != null) {
     int oldindex = link.BundleIndex;
     link.Bundle = null;
     link.BundleIndex = 0;
     link.InvalidateRelationships("curviness");
     bundle.Links.Remove(link);
     // if one or none left, remove the LinkBundle from both nodes
     if (bundle.Links.Count < 2) {
       // if there's only one link left in the LinkBundle, assume it shouldn't have one at all
       if (bundle.Links.Count == 1) {
         Link otherlink = bundle.Links[0];
         otherlink.Bundle = null;
         otherlink.BundleIndex = 0;
         otherlink.InvalidateRelationships("curviness");
       }
       bundle.Node1.RemoveBundle(bundle);
       bundle.Node2.RemoveBundle(bundle);
     } else {  // two or more links left in bundle
       // oldindex value no longer used: shift down BundleIndex values > oldindex, ignoring sign,
       // if they are on the same side as oldindex (i.e., if even, all even BundleIndexes that are larger than oldindex)
       oldindex = Math.Abs(oldindex);
       bool even = oldindex%2 == 0;
       foreach (Link l in bundle.Links) {
         int idx = Math.Abs(l.BundleIndex);
         bool e = idx%2 == 0;
         if (idx > oldindex && even == e) {
           if (l.BundleIndex > 0) {
             l.BundleIndex -= 2;
           } else {
             l.BundleIndex += 2;
           }
           l.InvalidateRelationships("curviness");
         }
       }
     }
   }
 }