/// <summary> /// Creates and returns a node /// </summary> /// <remarks> /// If a node with same ID already exist, modifies existing node with the given values and returns it /// </remarks> /// <param name="id">ID of the node</param> /// <param name="style">Style name</param> /// <param name="type">type of the node</param> /// <param name="title">title of the node</param> /// <param name="actions">list of actions and respective parameters we can use on the node (XML)</param> /// <param name="drawingInformation">drawing information (XML)</param> /// <param name="refreshRate">refresh rate in millisecond</param> /// <param name="relativeSize">size coeficient to applied the node</param> /// <param name="url">url use to download this node</param> /// <param name="isDownloaded">true if the node has been downloaded</param> /// <returns>the model representation of our node</returns> public Node CreateNode( string id, string style, string type, string title, List<string> actions, string drawingInformation, int refreshRate, double relativeSize, string url, bool isDownloaded) { bool nodeExist = false; Node node = null; // unicity constrain foreach (Node n in new List<Node>(this.nodeList)) { if (id == n.ID) { nodeExist = true; node = n; } } if (! nodeExist) { // creating node node = new Node(id); } if (actions != null) { node.Actions = actions; } if (drawingInformation != null) { node.DrawingInformation = drawingInformation; } node.RefreshRate = refreshRate; if (style != null) { node.StyleName = style; } node.TypeName = type; this.GetNodeType(node.TypeName); if (title != null) { node.Title = title; } node.Url = url; if (relativeSize >= 0) { node.RelativeSize = relativeSize; } node.IsDeployed |= isDownloaded; if (! nodeExist) { // we add the node to the model node.SelectionChanged += new EventHandler(this.Node_SelectionChanged); this.nodeList.Add(node); } return node; }
/// <summary> /// Sets the given repulsion force between current node and given node /// </summary> /// <param name="node">Node with which the repulsion with apply</param> /// <param name="repulsion">Repulsion force to apply</param> /// TODO : move away ? public void SetRepulsion(Node node, Attraction repulsion) { // if there already was a repulsion force between the two nodes, // we need to turn it off. if (this.repulsionsList.ContainsKey(node)) { this.repulsionsList[node].Dispose(); } // sets the repulsion force // (as repulsionList is a dictionnary, the entry will be added if it doesn't already exist) this.repulsionsList[node] = repulsion; }
/// <summary> /// Gets the repulsion force between current node and given node /// </summary> /// <param name="node">Second node for repulsion force</param> /// <returns>Repulsion force between current node and given node</returns> /// TODO : move away ? public Attraction GetRepulsion(Node node) { // the method is not protected because // we assume here that there will always be an entry for the node // (as all nodes repulse each other) return this.repulsionsList[node]; }
/// <summary> /// Gets the second node at end of the link /// </summary> /// <param name="node">Node at one end of the link</param> /// <returns> /// Node at the other end of the link /// If given node is not related to the link, returns null /// </returns> public Node GetTheOppositeNode(Node node) { if (node == this.relatedNode1) { return this.relatedNode2; } if (node == this.relatedNode2) { return this.relatedNode1; } return null; }
/// <summary> /// Dispose of the link /// </summary> public void Dispose() { // Remove current link from link list of both nodes this.isDisposed = true; this.relatedNode1.LinkList.Remove(this); this.relatedNode2.LinkList.Remove(this); this.relatedNode1.IsDeployed = false; this.relatedNode2.IsDeployed = false; this.relatedNode1.SetRelativeMass(); this.relatedNode2.SetRelativeMass(); this.relatedNode1 = null; this.relatedNode2 = null; this.physicRepresentation.Dispose(); }
/// <summary> /// Initializes a new instance of the Link class. /// </summary> /// <param name="id">ID of the new link</param> /// <param name="node1">First node relative to the link</param> /// <param name="node2">Second node relative to the link</param> public Link( string id, Node node1, Node node2) { this.id = id; this.relatedNode1 = node1; this.relatedNode1.LinkList.Add(this); this.relatedNode1.SetRelativeMass(); this.relatedNode2 = node2; this.relatedNode2.LinkList.Add(this); this.relatedNode2.SetRelativeMass(); }