public static MutableTree GetParent(MutableTree node, MutableTree root) { if (root == null || node == null) { return(null); } if (root == node) { return(null); } if (root.GetChildren().Contains(node)) { return(root); } foreach (MutableTree child in root.GetChildren()) { MutableTree found = GetParent(node, child); if (found != null) { return(found); } } return(null); }
public static string ToJson(MutableTree tree) { JObject jobject = new JObject(); ToJsonHelper(tree, jobject); return(jobject.ToString()); }
public static Tree FromMutable(MutableTree mutable) { Tree node = Tree.FromBoundingBox(mutable, mutable.Tags); foreach (MutableTree child in mutable.GetChildren()) { node._children.Add(FromMutable(child)); } return(node); }
public static MutableTree FromBoundingBox(IBoundingBox bb, Dictionary<string, object> tags) { MutableTree tree = new MutableTree(); tree.Top = bb.Top; tree.Left = bb.Left; tree.Width = bb.Width; tree.Height = bb.Height; if (tags != null) tree._tags = new Dictionary<string, object>(tags); else tree._tags = new Dictionary<string, object>(); tree._children = new List<MutableTree>(); return tree; }
public static IEnumerable <MutableTree> GetSiblings(MutableTree node, MutableTree root) { MutableTree parent = GetParent(node, root); List <MutableTree> siblings = new List <MutableTree>(); if (parent != null) { foreach (MutableTree child in parent.GetChildren()) { if (child != node) { siblings.Add(node); } } } return(siblings); }
public static MutableTree FromTree(Tree tree) { var tags = new Dictionary <string, object>(); foreach (var pair in tree.GetTags()) { tags[pair.Key] = pair.Value; } MutableTree node = MutableTree.FromBoundingBox(tree, tags); foreach (Tree child in tree.GetChildren()) { node._children.Add(FromTree(child)); } return(node); }
public static MutableTree GetParent(MutableTree node, MutableTree root) { if (root == null || node == null) return null; if (root == node) return null; if (root.GetChildren().Contains(node)) return root; foreach (MutableTree child in root.GetChildren()) { MutableTree found = GetParent(node, child); if (found != null) return found; } return null; }
public static MutableTree FromBoundingBox(IBoundingBox bb, Dictionary <string, object> tags) { MutableTree tree = new MutableTree(); tree.Top = bb.Top; tree.Left = bb.Left; tree.Width = bb.Width; tree.Height = bb.Height; if (tags != null) { tree._tags = new Dictionary <string, object>(tags); } else { tree._tags = new Dictionary <string, object>(); } tree._children = new List <MutableTree>(); return(tree); }
private static void ToJsonHelper(MutableTree currnode, JObject jo) { foreach (string tagname in currnode._tags.Keys) { jo.Add(tagname, currnode._tags[tagname].ToString()); } jo.Add("top", currnode.Top); jo.Add("left", currnode.Left); jo.Add("width", currnode.Width); jo.Add("height", currnode.Height); JArray array = new JArray(); foreach (MutableTree child in currnode._children) { JObject childjo = new JObject(); ToJsonHelper(child, childjo); array.Add(childjo); } jo.Add("children", array); }
public static IEnumerable<MutableTree> GetSiblings(MutableTree node, MutableTree root) { MutableTree parent = GetParent(node, root); List<MutableTree> siblings = new List<MutableTree>(); if (parent != null) { foreach (MutableTree child in parent.GetChildren()) { if (child != node) siblings.Add(node); } } return siblings; }
private static int GetNodeIndex(MutableTree node, MutableTree parent) { int index = 0; string pixelhash = null; string type = "none"; if (node.ContainsAttribute("type")) type = node["type"].ToString(); if (node.ContainsAttribute("type") && node["type"].Equals("content")) pixelhash = node["pixel_hash"].ToString(); if (parent != null) { var children = parent.GetChildren(); children.Sort(BoundingBox.CompareByTopThenLeft); foreach (MutableTree sibling in children) { if (sibling == node) return index; else { string sibtype = "none"; if (sibling.ContainsAttribute("type")) sibtype = sibling["type"].ToString(); if (sibtype.Equals("ptype") && type.Equals("ptype")) { if (sibling["ptype_id"].Equals(node["ptype_id"])) index++; } else if (sibtype.Equals(type)) { index++; } } } } return index; }
private static void GetPathHelper(MutableTree node, MutableTree root, StringBuilder sb) { if (node == null) return; MutableTree parent = GetParent(node, root); GetLocalPath(node, parent, sb); if (parent != null) { sb.Append("/"); GetPathHelper(parent, root, sb); } }
public static string GetPath(MutableTree node, MutableTree root) { StringBuilder sb = new StringBuilder(); GetPathHelper(node, root, sb); return sb.ToString(); }
public static Tree FromMutable(MutableTree mutable) { Tree node = Tree.FromBoundingBox(mutable, mutable.Tags); foreach (MutableTree child in mutable.GetChildren()) { node._children.Add(FromMutable(child)); } return node; }
public PrefabSingleInterpretArgs(MutableTree tree, IRuntimeStorage runtimeStorage) { Tree = tree; RuntimeStorage = new PythonRuntimeStorageWrapper(runtimeStorage); }
public static string ToJson(MutableTree tree) { JObject jobject = new JObject(); ToJsonHelper(tree, jobject); return jobject.ToString(); }
private static void GetLocalPath(MutableTree node, MutableTree parent, StringBuilder sb) { if (node.ContainsAttribute("type")) { switch (node["type"].ToString()) { case "ptype": sb.Append(node["ptype_id"].ToString()); break; case "frame": sb.Append("frame"); break; case "content": sb.Append("content[@pixel_hash=" + node["pixel_hash"] + "]"); break; default: sb.Append(node["type"]); break; } } int index = GetNodeIndex(node, parent); sb.Append("[" + index + "]"); }