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 + "]"); }
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 GetPath(MutableTree node, MutableTree root) { StringBuilder sb = new StringBuilder(); GetPathHelper(node, root, sb); return(sb.ToString()); }
public static MutableTree from_bounding_box(IBoundingBox box, PythonDictionary dict) { var csharpDict = new Dictionary <string, object>(); foreach (string key in dict.Keys) { csharpDict[key] = dict[key]; } return(MutableTree.FromBoundingBox(box, csharpDict)); }
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 Tree Interpret(Tree frame) { if (_interpreter != null) { Tree tree = LayerChain.InterpretChain(_layers, frame); MutableTree mutable = MutableTree.FromTree(tree); PrefabSingleInterpretArgs args = new PrefabSingleInterpretArgs(mutable, Storage); try { _interpreter.Interpret(args); } catch (Exception e) { mutable["interpretation_exception"] = e; } return(Tree.FromMutable(mutable)); } return(frame); }
public PrefabSingleInterpretArgs(MutableTree tree, IRuntimeStorage runtimeStorage) { Tree = tree; RuntimeStorage = new PythonRuntimeStorageWrapper(runtimeStorage); }