/// <summary> /// Generate a node at this vertex, if it does not already posess one. /// A new node will only be created if one does not exist and this vertex is part of /// an element's geometry definition. /// </summary> /// <param name="options"></param> public void GenerateNode(NodeGenerationParameters options) { if (Owner?.Element?.Model != null) { Model.Model model = Owner.Element.Model; if (Node == null) { if (model != null) { Node = model.Create.Node(Position, options.ConnectionTolerance, options.ExInfo); } } else { // Node already exists - check and update it double dist = Node.DistanceToSquared(this); if (dist > options.ConnectionTolerance.Squared()) { // Check for other connections that share this node: if (Node.Vertices.Count > 1) { if (model != null) { // Node is too far away - split and create new node Node = model.Create.Node(Position, options.ConnectionTolerance, options.ExInfo); } } else { // Check for other nodes at the end position to connect to: Node node = model.Nodes.ClosestNodeTo(Position, options.ConnectionTolerance); if (node != null && !node.IsDeleted) { if (options.DeleteUnusedNodes) { Node.Delete(); } Node = node; } else { Node.Position = Position; } } } } if (Node.IsDeleted) { Node.Undelete(); //Make sure the node isn't deleted } } }
/// <summary> /// Generate a node at this vertex, if it does not already posess one. /// This override can be used to generate nodes independent of a full model/element system. /// </summary> /// <param name="options"></param> public void GenerateNode(NodeGenerationParameters options, NodeCollection nodes, NodeDDTree nodeTree) { if (Node == null) { Node = nodeTree.NearestTo(Position, options.ConnectionTolerance); if (Node == null) { Node = new Node(Position); } } if (!nodes.Contains(Node.GUID)) { nodes.Add(Node); nodeTree.Add(Node); } }
/// <summary> /// Generate nodes at the ends of the paths in this collection. /// It is not necessary for the geometry to be part of a Model for this /// function, nor will any newly created nodes be added automatically /// to the current model - this should be done subsequently if necessary. /// </summary> /// <typeparam name="TPath"></typeparam> /// <param name="paths"></param> /// <param name="refreshNodes">Refresh nodes by removing any existing ones before beginning</param> /// <returns></returns> public static NodeCollection GenerateNetworkPathNodes <TPath>(this IList <TPath> paths, NodeGenerationParameters gParams, bool refreshNodes = false) where TPath : IWidePath { var nodes = new NodeCollection(); foreach (TPath path in paths) { if (refreshNodes) { if (path.Spine?.Start != null) { path.Spine.Start.Node = null; } if (path.Spine?.End != null) { path.Spine.End.Node = null; } } else { Node sNode = path.Spine?.Start?.Node; if (sNode != null && !nodes.Contains(sNode.GUID)) { nodes.Add(sNode); } Node eNode = path.Spine?.End?.Node; if (eNode != null && !nodes.Contains(eNode.GUID)) { nodes.Add(eNode); } } } var tree = new NodeDDTree(nodes); foreach (TPath path in paths) { path.Spine?.Start.GenerateNode(gParams, nodes, tree); path.Spine?.End.GenerateNode(gParams, nodes, tree); } return(nodes); }