예제 #1
0
        public override void DoSaveData(XElement parent, DataItem item)
        {
            GraphStructItem si = item as GraphStructItem;

            var name = Name;

            var el = new XElement(name);

            parent.Add(el);

            var relativeToNode = item.DataModel.RootItems.First(e => e.Definition is GraphNodeDefinition) as GraphNodeItem;

            el.Add(new XAttribute(MetaNS + "X", si.X - relativeToNode.X));
            el.Add(new XAttribute(MetaNS + "Y", si.Y - relativeToNode.Y));
            if (si.Comment != null)
            {
                el.Add(new XAttribute(MetaNS + "Comment", si.Comment));
            }

            if (string.IsNullOrWhiteSpace(ChildAsGUID) && (si.LinkParents.Count > 1 || si.DataModel.FlattenData))
            {
                if (item.DataModel.GraphNodeItems.Where(e => e != item).Any(e => e.GUID == si.GUID))
                {
                    throw new Exception("Duplicate GUID '" + si.GUID + "' in items!");
                }
                el.Add(new XAttribute("GUID", si.GUID));
            }
            else if (!string.IsNullOrWhiteSpace(ChildAsGUID))
            {
                if (item.DataModel.GraphNodeItems.Where(e => e != item).Any(e => e.GUID == si.GUID))
                {
                    throw new Exception("Duplicate GUID '" + si.GUID + "' in items!");
                }
            }

            foreach (var att in si.Attributes)
            {
                var primDef         = att.Definition as PrimitiveDataDefinition;
                var asString        = primDef.WriteToString(att);
                var defaultAsString = primDef.DefaultValueString();

                if (att.Name == "Name" || !primDef.SkipIfDefault || asString != defaultAsString)
                {
                    el.SetAttributeValue(att.Name, asString);
                }
            }

            foreach (var child in si.Children)
            {
                var childDef = child.Definition;
                if (!Children.Contains(childDef) && !(childDef is CommentDefinition))
                {
                    throw new Exception("A child has a definition that we dont have! Something broke!");
                }

                child.Definition.SaveData(el, child);
            }
        }
예제 #2
0
        public void CreateChildren(GraphStructItem item, UndoRedoManager undoRedo)
        {
            foreach (var def in Children)
            {
                var      name      = def.Name;
                DataItem childItem = def.CreateData(undoRedo);

                item.Children.Add(childItem);
            }
        }
예제 #3
0
        public override DataItem CreateData(UndoRedoManager undoRedo)
        {
            var item = new GraphStructItem(this, undoRedo);

            foreach (var att in Attributes)
            {
                var attItem = att.CreateData(undoRedo);
                item.Attributes.Add(attItem);
            }

            CreateChildren(item, undoRedo);

            foreach (var child in item.Attributes)
            {
                child.UpdateVisibleIfBinding();
            }
            foreach (var child in item.Children)
            {
                child.UpdateVisibleIfBinding();
            }

            return(item);
        }
예제 #4
0
        public override DataItem LoadData(XElement element, UndoRedoManager undoRedo)
        {
            var item = new GraphStructItem(this, undoRedo);

            item.X       = TryParseFloat(element, MetaNS + "X");
            item.Y       = TryParseFloat(element, MetaNS + "Y");
            item.GUID    = element.Attribute("GUID")?.Value?.ToString();
            item.Comment = element.Attribute(MetaNS + "Comment")?.Value?.ToString();

            var commentTexts = Children.Where(e => e is CommentDefinition).Select(e => (e as CommentDefinition).Text);

            var createdChildren = new List <DataItem>();

            foreach (var def in Children)
            {
                var name = def.Name;

                var els = element.Elements(name);

                if (els.Count() > 0)
                {
                    var prev = els.First().PreviousNode as XComment;
                    if (prev != null)
                    {
                        var comment = new CommentDefinition().LoadData(prev, undoRedo);
                        if (!commentTexts.Contains(comment.TextValue))
                        {
                            item.Children.Add(comment);
                        }
                    }

                    if (def is CollectionDefinition)
                    {
                        CollectionItem childItem = (CollectionItem)def.LoadData(els.First(), undoRedo);
                        if (childItem.Children.Count == 0)
                        {
                            var dummyEl = new XElement(els.First().Name);
                            foreach (var el in els)
                            {
                                dummyEl.Add(el);
                            }

                            childItem = (CollectionItem)def.LoadData(dummyEl, undoRedo);
                        }

                        item.Children.Add(childItem);
                    }
                    else
                    {
                        DataItem childItem = def.LoadData(els.First(), undoRedo);
                        item.Children.Add(childItem);
                    }
                }
                else
                {
                    DataItem childItem = def.CreateData(undoRedo);
                    item.Children.Add(childItem);
                }
            }

            if (element.LastNode is XComment)
            {
                var comment = new CommentDefinition().LoadData(element.LastNode as XComment, undoRedo);
                if (!commentTexts.Contains(comment.TextValue))
                {
                    item.Children.Add(comment);
                }
            }

            foreach (var att in Attributes)
            {
                var      el      = element.Attribute(att.Name);
                DataItem attItem = null;

                if (el != null)
                {
                    attItem = att.LoadData(new XElement(el.Name, el.Value.ToString()), undoRedo);
                }
                else
                {
                    attItem = att.CreateData(undoRedo);
                }
                item.Attributes.Add(attItem);
            }

            item.Children.OrderBy(e => Children.IndexOf(e.Definition));

            foreach (var child in item.Attributes)
            {
                child.UpdateVisibleIfBinding();
            }
            foreach (var child in item.Children)
            {
                child.UpdateVisibleIfBinding();
            }

            return(item);
        }