private void SetStitch(string stitch) { CurrentPath = CurrentKnot.IsNullOrEmpty() ? stitch : $"{CurrentKnot}.{stitch}"; CurrentNode = AddNode(NodeType.Stitch, CurrentPath); CurrentNode.KnotId = CurrentKnotId; CurrentNode.StitchId = CurrentStitchId = CurrentNode.Id; }
private void SetLabel(string label, string lineInfo) { string path = CurrentKnot.IsNullOrEmpty() ? label : $"{CurrentKnot}.{label}"; CurrentNode = AddNode(NodeType.Label, path); CurrentNode.KnotId = CurrentKnotId; CurrentNode.StitchId = CurrentStitchId > 0 ? CurrentStitchId : CurrentKnotId; AddEdge(CurrentPath, path, lineInfo); CurrentPath = path; }
private void AddEdge(string sourcePath, string targetPath, string label) { if (sourcePath.IsNullOrEmpty()) { Debug.LogWarning($"Null source path for {label}."); return; } if (targetPath.IsNullOrEmpty()) { Debug.LogWarning($"Null target path for {label}."); return; } if (!NodeLookup.TryGetValue(sourcePath, out GraphNode source)) { Debug.LogWarning($"Couldn't find node for '{sourcePath}'."); return; } if (!targetPath.Contains('.') && !CurrentKnot.IsNullOrEmpty()) { string testPath = $"{CurrentKnot}.{targetPath}"; if (NodeLookup.ContainsKey(testPath)) { targetPath = testPath; } } if (!NodeLookup.TryGetValue(targetPath, out GraphNode target)) { Debug.LogWarning($"Couldn't find node for '{targetPath}'."); return; } source = GetNodeAtDepth(source); target = GetNodeAtDepth(target); if (source.IsExcluded || target.IsExcluded) { return; } if (m_Settings.TunnelNodesHandling == TunnelNodesHandling.Remove && (target.IsTunnel || source.IsTunnel)) { return; } bool duplicateTunnel = false; // Duplicate tunnels if needed. if (m_Settings.TunnelNodesHandling == TunnelNodesHandling.Duplicate && target.IsTunnel && source != target) { string tunnelId = source.Label + "->" + target.Label; if (DuplicateTunnelLookup.ContainsKey(tunnelId)) { // Already created this one. return; } if (target.IsUsed) { target = DuplicateNode(target); } else { target.IsUsed = true; } DuplicateTunnelLookup[tunnelId] = target; duplicateTunnel = true; } else if (m_Settings.ForceDuplicatePaths.Contains(target.Label)) { string forcedDuplicateId = source.Label + "->" + target.Label; if (ForceDuplicateLookup.ContainsKey(forcedDuplicateId)) { // Already created this one. return; } if (target.IsUsed) { target = DuplicateNode(target); } else { target.IsUsed = true; } ForceDuplicateLookup[forcedDuplicateId] = target; } AddEdge(source, target, label); if (duplicateTunnel) { AddEdge(target, source); } }