/// <summary> /// Creates a new link between the startNode and the endNode. /// The startPort and endPort are the ports for the start and end nodes. /// </summary> /// <param name="startNode">The starting node</param> /// <param name="endNode">The ending node</param> /// <param name="startPort">The starting port</param> /// <param name="endPort">the ending port</param> /// <param name="mapdata">The Mapdata to use for generating the unique id of the link.</param> /// <param name="origLink">The original link</param> /// <param name="toBeAddedLinks">The number of links yet to be added.</param> /// <returns>The new link created.</returns> private MapLink CreateNewLink( MapNode startNode, MapNode endNode, MapPort startPort, MapPort endPort, MapData mapdata, MapLink origLink, int toBeAddedLinks) { //Create new link long newLinkId = GetUniqueId(typeof(MapLink), mapdata, toBeAddedLinks); MapLink newLink = new MapLink(); newLink.Id = newLinkId; newLink.Name = MapLinkNamePrefix + newLinkId; //Add the nodes newLink.AddNode(startNode); newLink.AddNode(endNode); //Add the ports newLink.AddPort(startPort); newLink.AddPort(endPort); //Copy attributes of original link and set owner id of the new attributes. Also add to mapdata CopyAttributes(origLink, newLink, newLinkId, mapdata); //create a new attribute to store the original link id MapAttribute origLinkIdAttr = new MapAttribute(); origLinkIdAttr.Name = "origLinkId"; origLinkIdAttr.StringValue = origLink.Id.ToString(); long newAttrId = GetUniqueId(typeof(MapAttribute), mapdata, 0); origLinkIdAttr.Id = newAttrId; origLinkIdAttr.OwnerType = "link"; origLinkIdAttr.OwnerId = newLink.Id; origLinkIdAttr.Type = AttrTypeString; //Add the new attribute to the new link and the map data newLink.Attributes.Add(origLinkIdAttr); mapdata.AddAttribute(origLinkIdAttr); //Set new link's element type from original link newLink.ElementType = origLink.ElementType; return(newLink); }
/// <summary> /// Copies the attributes of an old link to a new one. /// </summary> /// <param name="origLink">The old link</param> /// <param name="newLink">The new link</param> /// <param name="newLinkId">The id of the new link</param> /// <param name="mapdata">The mapdata into which the new attributes will be added.</param> private void CopyAttributes(MapLink origLink, MapLink newLink, long newLinkId, MapData mapdata) { foreach (MapAttribute attr in origLink.Attributes) { //Create a new attribute and set its properties MapAttribute newattr = new MapAttribute(); newattr.Id = GetUniqueId(typeof(MapAttribute), mapdata, 0); newattr.OwnerId = newLinkId; newattr.Name = attr.Name; newattr.OwnerType = attr.OwnerType; newattr.Type = attr.Type; newattr.IntValue = attr.IntValue; newattr.StringValue = attr.StringValue; newattr.DoubleValue = attr.DoubleValue; newattr.DateTimeValue = attr.DateTimeValue; //Add new attribute to the new link newLink.AddAttribute(newattr); //Add new attribute to the new mapdata mapdata.AddAttribute(newattr); } }