private void WriteNode(StringBuilder xml, HashSet <CsgNode> added, CsgGroup node, string indent) { string tagName = node.GetType().Name; xml.Append(indent); xml.Append("<"); xml.Append(tagName); if (node.IsObjectRoot || node.ReferencedByCount != 1) { xml.Append(" Id=\""); xml.Append(node.Id); xml.Append("\""); } if (!string.IsNullOrEmpty(node.Name)) { xml.Append(" Name=\""); xml.Append(node.Name); xml.Append("\""); } xml.AppendLine(">"); foreach (CsgNode child in node.Children) { WriteNode(xml, added, child, indent + " "); } xml.Append(indent); xml.Append("</"); xml.Append(tagName); xml.AppendLine(">"); }
private void ReadElement(XElement root, CsgGroup owner) { foreach (XElement e in root.Elements()) { CsgNode node = null; string id = e.Attribute("Id").GetValue(); switch (e.Name.LocalName) { case "Link": if (!nodeIds.TryGetValue(id, out node)) { deferredLinks.Add(new Tuple <string, CsgGroup>(id, owner)); } break; case "CsgCube": node = ReadCube(e); break; case "CsgScale": node = ReadScale(e); break; case "CsgTranslate": node = ReadTranslate(e); break; case "CsgRotate": node = ReadRotate(e); break; default: Type type = Type.GetType("ConstructorEngine." + e.Name.LocalName); if (type != null) { node = Activator.CreateInstance(type) as CsgNode; } break; } if (node != null) { node.Name = e.Attribute("Name").GetValue(node.Name); if (!string.IsNullOrEmpty(id)) { nodeIds[id] = node; } if (owner != null) { owner.AddChild(node); } else { node.IsObjectRoot = true; } Repository.RegisterNode(node); if (node is CsgGroup) { ReadElement(e, (CsgGroup)node); } } } }