private static void FillSerializedNodes(XmlNode node, SerializedNode resultNode) { foreach (XmlNode child in node.ChildNodes) { if (child.Name == "Item") { if (child.Attributes != null) { var childId = Convert.ToInt32(child.Attributes["id"].Value); resultNode.Children[childId] = new SerializedNode(childId); FillSerializedNodes(child, resultNode.Children[childId]); } } if (child.Name != "Interpterer") { continue; } if (child.Attributes == null) { continue; } var name = child.Attributes["Name"].Value; var data = new AttributeData(AttributeInterpreterFactory.GetTypeId(name)); foreach (XmlAttribute attribute in child.Attributes) { if (attribute.Name != "Name") { data.WriteAttribute(attribute.Name, attribute.Value); } } var typeId = AttributeInterpreterFactory.GetTypeId(name); resultNode.Interpreters[typeId] = data; } }
private static XmlElement CreateXmlNode(SerializedNode node, XmlDocument xmldoc) { var xmlelem = xmldoc.CreateElement("", "Item", ""); if (node.Index != -1) { var attr = xmldoc.CreateAttribute("id"); attr.Value = node.Index.ToString(); xmlelem.Attributes.Append(attr); } foreach (var child in node.Children) { var childElem = CreateXmlNode(child.Value, xmldoc); xmlelem.AppendChild(childElem); } foreach (var interpreter in node.Interpreters) { var childElem = xmldoc.CreateElement("", "Interpterer", ""); var attr = xmldoc.CreateAttribute("Name"); attr.Value = AttributeInterpreterFactory.GetName(interpreter.Key); childElem.Attributes.Append(attr); var data = interpreter.Value; xmlelem.AppendChild(data.CreateXmlNode(xmldoc)); } return(xmlelem); }
/// <summary> /// Get the string identifier of a specified interpreter type /// </summary> /// <returns>Gets the interpreter string name that is identified in the interpreters factory</returns> private static int GetInterpreterTypeNameId <T>() where T : AttributeInterpreterBase { var typeId = typeof(T).GetHashCode(); #if DEBUG //Should throw exception AttributeInterpreterFactory.GetName(typeId); #endif return(typeId); }
public void CreateInterpreterAndSerializeDeserialize() { AttributeInterpreterFactory.Register <DummyListIntInterpreter>(); var node = new Node(); var data = new List <int> { 2, 5, 6 }; SetupNodeInterpreter(node, data); var serializedData = SerializeAndCleanInterpreter(node); DeserializeAndTestValues(node, serializedData); }
private void InitDocument() { AttributeInterpreterFactory.Register <ActionGraphInterpreter>(); // Create a new document _document = new Document(); // Set the name of the label root _document.Root.Set <StringInterpreter>().Value = "New Part"; _document.Root.Set <LayerContainerInterpreter>(); _document.Root.Set <NaroVersionFileFormatInterpreter>(); _document.Root.Set <ActionGraphInterpreter>().ActionsGraph = _actionGraph; _document.Root.Set <DocumentContextInterpreter>().Context = _context; _document.Root.Set <DocumentContextInterpreter>().Document = _document; _document.Changed += OnCommit; }
private void OnReferencedModified(Node node, AttributeInterpreterBase atttributeName) { var attrId = atttributeName.GetType().GetHashCode(); if (_blackListAttributes.Contains(attrId)) { return; } _lockParent = true; var data = _node.Interpreters[attrId].Serialize(); if (!Parent.Interpreters.ContainsKey(attrId)) { Parent.Interpreters[attrId] = AttributeInterpreterFactory.GetInterpreter(attrId, Parent); } Parent.Interpreters[attrId].Deserialize(data); _lockParent = false; OnModified(); }
public static void Setup() { AttributeInterpreterFactory.Register <IntegerInterpreter>(); AttributeInterpreterFactory.Register <RealInterpreter>(); AttributeInterpreterFactory.Register <LayerContainerInterpreter>(); AttributeInterpreterFactory.Register <LayerVisibilityInterpreter>(); AttributeInterpreterFactory.Register <InheritedCloneInterpreter>(); AttributeInterpreterFactory.Register <MeshTopoShapeInterpreter>(); AttributeInterpreterFactory.Register <InteractiveShapeInterpreter>(); AttributeInterpreterFactory.Register <DrawingAttributesInterpreter>(); AttributeInterpreterFactory.Register <ObjectInterpreter>(); AttributeInterpreterFactory.Register <MetricsInterpreter>(); AttributeInterpreterFactory.Register <NotificationInterpreter>(); AttributeInterpreterFactory.Register <ConceptInterpreter>(); AttributeInterpreterFactory.Register <Point3DInterpreter>(); AttributeInterpreterFactory.Register <Axis3DInterpreter>(); AttributeInterpreterFactory.Register <StringInterpreter>(); AttributeInterpreterFactory.Register <ReferenceInterpreter>(); AttributeInterpreterFactory.Register <ReferenceListInterpreter>(); AttributeInterpreterFactory.Register <FunctionInterpreter>(); AttributeInterpreterFactory.Register <DocumentContextInterpreter>(); AttributeInterpreterFactory.Register <NamedShapeInterpreter>(); AttributeInterpreterFactory.Register <TopoDsShapeInterpreter>(); AttributeInterpreterFactory.Register <TransformationInterpreter>(); AttributeInterpreterFactory.Register <TreeViewVisibilityInterpreter>(); AttributeInterpreterFactory.Register <CustomShapeDataInterpreter>(); AttributeInterpreterFactory.Register <NaroVersionFileFormatInterpreter>(); AttributeInterpreterFactory.Register <DocumentUserConfigInterpreter>(); AttributeInterpreterFactory.Register <DontOptimize>(); AttributeInterpreterFactory.Register <ShapePointConstraint>(); AttributeInterpreterFactory.Register <MiddleEdgeConstraint>(); AttributeInterpreterFactory.Register <IndexPointConstraintInterpreter>(); AttributeInterpreterFactory.Register <HorizontalLineConstraint>(); AttributeInterpreterFactory.Register <VerticalLineConstraint>(); AttributeInterpreterFactory.Register <ActionGraphInterpreter>(); }
private static void CopyPaste(Node source, Node destination) { destination.RemoveAllChildren(); destination.RemoveAllInterpreters(); foreach (var childNode in source.Children) { CopyPaste(childNode.Value, destination.FindChild(childNode.Key, true)); } foreach (var childInterpreter in source.Interpreters) { destination.Interpreters[childInterpreter.Key] = AttributeInterpreterFactory.GetInterpreter( childInterpreter.Key, destination); } foreach (var childInterpreter in source.Interpreters) { var data = new AttributeData(childInterpreter.Key); childInterpreter.Value.Serialize(data); destination.Interpreters[childInterpreter.Key].Deserialize(data); } }
public static Document DefaultsSetup() { DefaultInterpreters.Setup(); AttributeInterpreterFactory.Register <ActionGraphInterpreter>(); var actionsGraph = new ActionsGraph(); actionsGraph.Register(new FunctionFactoryInput()); actionsGraph.Register(new OptionsSetupInput()); DefaultFunctions.Setup(actionsGraph); var constraintsFunctionsSetup = new DefaultConstraintFunctions(); constraintsFunctionsSetup.Setup(actionsGraph); QosCreate(); var document = new Document(); document.Transact(); document.Root.Set <ActionGraphInterpreter>().ActionsGraph = actionsGraph; document.Root.Set <DocumentContextInterpreter>().Document = document; document.Commit("document setup"); return(document); }
private static void ModifyNodeWithDiff(NodeDiff diff, Node result) { if (diff.Applied) { return; } diff.Applied = true; foreach (var removedNode in diff.RemovedNodes) { if (diff.Children.ContainsKey(removedNode)) { diff.Children.Remove(removedNode); } result.Remove(removedNode); } foreach (var modifiedNode in diff.Children.Keys) { var childDiff = diff.Children[modifiedNode]; if (!result.Children.ContainsKey(modifiedNode)) { result.AddChild(modifiedNode); } var childNode = result.Children[modifiedNode]; ModifyNodeWithDiff(childDiff, childNode); } AttributeInterpreterBase functionInterpreter = null; AttributeData attrData = null; foreach (var modifiedAttr in diff.ModifiedAttributeData) { AttributeInterpreterBase interpreter; var key = AttributeInterpreterFactory.GetTypeId(modifiedAttr.Value.Name); if (!result.Interpreters.ContainsKey(key)) { interpreter = AttributeInterpreterFactory.GetInterpreter(key, result); result.Interpreters[key] = interpreter; } else { interpreter = result.Interpreters[modifiedAttr.Key]; } try { if (modifiedAttr.Value.Name == "Function") { functionInterpreter = interpreter; attrData = modifiedAttr.Value; continue; } if (modifiedAttr.Key == typeof(ReferenceInterpreter).GetHashCode()) { interpreter.Disable(); interpreter.Deserialize(modifiedAttr.Value); var refNode = result.Get <ReferenceInterpreter>().Node; DeserializeTargetNode(diff, result, refNode); interpreter.Enable(); } if (modifiedAttr.Key == typeof(ReferenceListInterpreter).GetHashCode()) { interpreter.Disable(); interpreter.Deserialize(modifiedAttr.Value); var refNodes = new List <SceneSelectedEntity>(); foreach (var refnode in result.Get <ReferenceListInterpreter>().Nodes) { refNodes.Add(refnode); } foreach (var refNode in refNodes) { DeserializeTargetNode(diff, result, refNode.Node); } interpreter.Enable(); } interpreter.Deserialize(modifiedAttr.Value); } catch (Exception ex) { var path = AttributeData.RelativeReferencePath(result.Root, result); var interpreterName = AttributeInterpreterFactory.GetName(modifiedAttr.Key); Log.Info("Error on node: (" + path + ") interpreter: " + interpreterName + Environment.NewLine + " Message: " + ex.Message + Environment.NewLine + " Stack: " + ex.StackTrace); // throw; } } if (functionInterpreter != null) { functionInterpreter.Deserialize(attrData); } foreach (var removedAttr in diff.RemovedAttributes) { result.RemoveInterpreter(removedAttr); } }
public SetupUtils() { DefaultInterpreters.Setup(); AttributeInterpreterFactory.Register <ActionGraphInterpreter>(); }
private static string GetBaseInterpreterName(int nameId) { var name = GetInterpreterName(nameId); return(AttributeInterpreterFactory.ComputeShorthand(name)); }
private static string GetInterpreterName(int nameId) { return(AttributeInterpreterFactory.GetName(nameId)); }