/// <summary> /// This function returns the link type state from the name in argument /// </summary> /// <param name="link">name of the type you need</param> /// <returns>the type of link you asked for</returns> private model.LinkType GetLinkType(Link link) { if (!this.linkTypeList.ContainsKey(link.TypeName)) { this.linkTypeList.Add(link.TypeName, new LinkType(link.Verb, link.RelatedNode1.TypeName, link.RelatedNode2.TypeName)); if (this.LinkTypesChanged != null) { this.LinkTypesChanged(this, new EventArgs()); } } return this.linkTypeList[link.TypeName]; }
/// <summary> /// Creates and returns a link but doesn't add it to the current model /// </summary> /// <remarks> /// If a link with same ID already exist, modifies existing link with the given values and returns it /// You must add the link to the model after creation. /// </remarks> /// <param name="id">ID of the link</param> /// <param name="nodeFrom">ID of the first node relative to the link</param> /// <param name="nodeTo">ID of the second node relative to the link</param> /// <param name="actions">List of all action that could be performed on the link (XML)</param> /// <param name="drawingInformation">An Xml representation of all information needed to draw a link on the graph</param> /// <param name="strength">Strength between the two nodes</param> /// <param name="style">Style of the link</param> /// <param name="verb">Verb used in the link description</param> /// <param name="complement">Complement used in the link description</param> /// <returns>Created link</returns> public Link CreateLink( string id, string nodeFrom, string nodeTo, List<string> actions, string drawingInformation, float strength, string style, string verb, string complement) { bool linkExist = false; Link link = null; // make sure this link is unique foreach (Link otherLink in new List<Link>(this.linkList)) { if (otherLink.ID.Equals(id)) { // if the link already exist linkExist = true; link = otherLink; } } if (!linkExist) { // get related nodes Node node1 = null; Node node2 = null; foreach (Node node in new List<Node>(this.nodeList)) { if (node.ID.Equals(nodeFrom)) { node1 = node; } if (node.ID.Equals(nodeTo)) { node2 = node; } } if (node1 == null) { throw new ArgumentException("the link \"" + id + "\" cannot be create. (the value of property \"From\" isn't a valid node ID)"); } if (node2 == null) { throw new ArgumentException("the link \"" + id + "\" cannot be create. (the value of property \"To\" isn't a valid node ID)"); } // creating the link link = new Link(id, node1, node2); // we add it to the model this.linkList.Add(link); } link.Actions = actions; link.DrawingInformation = drawingInformation; link.Strength = strength; link.StyleName = style; link.Verb = verb; this.GetLinkType(link); link.Complement = complement; return link; }