示例#1
0
        /// <summary>
        /// Finish MEF intialization for the component by creating DomNode tree for application data.</summary>
        void IInitializable.Initialize()
        {
            m_mainform.Shown += (sender, e) =>
            {
                // create root node.
                var rootNode = new DomNode(Schema.gameType.Type, Schema.gameRootElement);
                rootNode.SetAttribute(Schema.gameType.nameAttribute, "Game");

                // create Orc game object and add it to rootNode.
                var orc1 = CreateOrc("Orc1");
                rootNode.GetChildList(Schema.gameType.gameObjectChild).Add(orc1);

                // add a child Orc.
                var orcChildList = orc1.GetChildList(Schema.orcType.orcChild);
                orcChildList.Add(CreateOrc("Child Orc1"));


                var orc2 = CreateOrc("Orc2");
                rootNode.GetChildList(Schema.gameType.gameObjectChild).Add(orc2);


                rootNode.InitializeExtensions();


                // set active context and select orc object.
                m_contextRegistry.ActiveContext = rootNode;

                var selectionContext = rootNode.Cast <ISelectionContext>();
                selectionContext.Set(new AdaptablePath <object>(orc1.GetPath()));
            };
        }
        /// <summary>
        /// Imports templates and template folders stored in an external file</summary>
        /// <param name="toFolder">Template folder in which to import templates and template folders</param>
        /// <param name="fromRoot">Root of templates to import</param>
        /// <param name="uri"></param>
        internal void ImportTemplates(DomNode toFolder, DomNode fromRoot, Uri uri)
        {
            TagTemplateTree(fromRoot, uri);
 
            // assume all templates and their containing folders are children of a root template folder 
            foreach (var domNode in fromRoot.LevelSubtree) // add top-level folders
            {
                if (domNode.Type == Schema.templateFolderType.Type) // this should be the root template folder of the imported DOM tree
                {
                    // import the children of the root template folder, but not the root itself
                    foreach (var child in domNode.Children.ToArray())
                    {
                        if (child.Type == Schema.templateFolderType.Type)
                        {
                            toFolder.GetChildList(Schema.templateFolderType.templateFolderChild).Add(child);
                        }
                        else if (child.Type == Schema.templateType.Type)
                        {
                            toFolder.GetChildList(Schema.templateFolderType.templateChild).Add(child);
                        }
                    }
                    break; // skip the rest of the document contents
                }
            }
        }
示例#3
0
        /// <summary>
        /// Imports templates and template folders stored in an external file</summary>
        /// <param name="toFolder">Template folder in which to import templates and template folders</param>
        /// <param name="fromRoot">Root of templates to import</param>
        /// <param name="uri"></param>
        internal void ImportTemplates(DomNode toFolder, DomNode fromRoot, Uri uri)
        {
            TagTemplateTree(fromRoot, uri);
 
            // assume all templates and their containing folders are children of a root template folder 
            foreach (var domNode in fromRoot.LevelSubtree) // add top-level folders
            {
                if (domNode.Type == Schema.templateFolderType.Type) // this should be the root template folder of the imported DOM tree
                {
                    // import the children of the root template folder, but not the root itself
                    foreach (var child in domNode.Children.ToArray())
                    {
                        if (child.Type == Schema.templateFolderType.Type)
                        {
                            toFolder.GetChildList(Schema.templateFolderType.templateFolderChild).Add(child);
                        }
                        else if (child.Type == Schema.templateType.Type)
                        {
                            toFolder.GetChildList(Schema.templateFolderType.templateChild).Add(child);
                        }
                    }
                    break; // skip the rest of the document contents
                }
            }
        }
示例#4
0
        public void TestGetLowestCommonAncestor()
        {
            DomNodeType type      = new DomNodeType("type");
            ChildInfo   childInfo = new ChildInfo("child", type, true);

            type.Define(childInfo);

            DomNode parent = new DomNode(type);
            DomNode child1 = new DomNode(type);
            DomNode child2 = new DomNode(type);

            parent.GetChildList(childInfo).Add(child1);
            parent.GetChildList(childInfo).Add(child2);
            DomNode grandchild1 = new DomNode(type);

            child1.GetChildList(childInfo).Add(grandchild1);
            DomNode grandchild2 = new DomNode(type);

            child2.GetChildList(childInfo).Add(grandchild2);

            Assert.AreSame(DomNode.GetLowestCommonAncestor(child1, child2), parent);
            Assert.AreSame(DomNode.GetLowestCommonAncestor(grandchild1, grandchild2), parent);
            Assert.AreSame(DomNode.GetLowestCommonAncestor(child1, grandchild1), child1);

            Assert.AreSame(DomNode.GetLowestCommonAncestor(new DomNode[] { child1, child2, grandchild1 }), parent);
        }
示例#5
0
文件: Editor.cs 项目: jethac/ATF
        /// <summary>
        /// Finish MEF intialization for the component by creating DomNode tree for application data.</summary>
        void IInitializable.Initialize()
        {
            m_mainform.Shown += (sender, e) =>
                {
                    // create root node.
                    var rootNode = new DomNode(Schema.gameType.Type, Schema.gameRootElement);
                    rootNode.SetAttribute(Schema.gameType.nameAttribute, "Game");

                    // create Orc game object and add it to rootNode.
                    var orc1 = CreateOrc("Orc1");
                    rootNode.GetChildList(Schema.gameType.gameObjectChild).Add(orc1);

                    // add a child Orc.
                    var orcChildList = orc1.GetChildList(Schema.orcType.orcChild);
                    orcChildList.Add(CreateOrc("Child Orc1"));


                    var orc2 = CreateOrc("Orc2");
                    rootNode.GetChildList(Schema.gameType.gameObjectChild).Add(orc2);


                    rootNode.InitializeExtensions();


                    // set active context and select orc object.
                    m_contextRegistry.ActiveContext = rootNode;
                    
                    var selectionContext = rootNode.Cast<ISelectionContext>();
                    selectionContext.Set(new AdaptablePath<object>(orc1.GetPath()));                                       
                };
        }
示例#6
0
        private bool Equals(DomNode n1, DomNode n2)
        {
            if (n1 == null || n2 == null)
            {
                return(n1 == n2);
            }
            if (n1.Type != n2.Type)
            {
                return(false);
            }
            if (n1.ChildInfo != n2.ChildInfo)
            {
                return(false);
            }

            foreach (AttributeInfo info in n1.Type.Attributes)
            {
                object val1 = n1.GetLocalAttribute(info);
                object val2 = n2.GetLocalAttribute(info);
                if (val1 == null || val2 == null)
                {
                    if (val1 != val2)
                    {
                        return(false);
                    }
                }
            }

            foreach (ChildInfo info in n1.Type.Children)
            {
                if (info.IsList)
                {
                    IList <DomNode> children1 = n1.GetChildList(info);
                    IList <DomNode> children2 = n1.GetChildList(info);
                    if (children1.Count != children2.Count)
                    {
                        return(false);
                    }
                    for (int i = 0; i < children1.Count; i++)
                    {
                        if (!Equals(children1[i], children2[i]))
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    DomNode child1 = n1.GetChild(info);
                    DomNode child2 = n2.GetChild(info);
                    if (!Equals(child1, child2))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#7
0
        public void TestValidate()
        {
            DomNodeType childType  = new DomNodeType("child");
            DomNodeType parentType = new DomNodeType("parent");
            ChildInfo   childInfo  = new ChildInfo("child", childType, true);

            parentType.Define(childInfo);
            DomNode         parent    = new DomNode(parentType);
            IList <DomNode> childList = parent.GetChildList(childInfo);
            DomNode         child1    = new DomNode(childType);
            DomNode         child2    = new DomNode(childType);
            DomNode         child3    = new DomNode(childType);

            ChildCountRule test = new ChildCountRule(1, 2);

            // 0 children. Not valid.
            Assert.False(test.Validate(parent, null, childInfo));

            // 1 child. Valid.
            childList.Add(child1);
            Assert.True(test.Validate(parent, null, childInfo));

            // 2 children. Valid.
            childList.Add(child2);
            Assert.True(test.Validate(parent, null, childInfo));

            // 3 children. Not valid.
            childList.Add(child3);
            Assert.False(test.Validate(parent, null, childInfo));

            // 0 children. Not valid.
            childList.Clear();
            Assert.False(test.Validate(parent, null, childInfo));
        }
示例#8
0
文件: Tools.cs 项目: zparr/ATF
        /// <summary>
        /// Creates effects dictionary</summary>
        /// <param name="bindMtrl">Bind material DomNode</param>
        /// <returns>Effects dictionary of string/Effect pairs</returns>
        public static Dictionary <string, Effect> CreateEffectDictionary(DomNode bindMtrl)
        {
            if (bindMtrl == null)
            {
                return(null);
            }

            var result = new Dictionary <string, Effect>();

            DomNode techCommon = bindMtrl.GetChild(Schema.bind_material.technique_commonChild);

            IList <DomNode> instMtrls = techCommon.GetChildList(Schema.bind_material_technique_common.instance_materialChild);

            foreach (DomNode instMtrl in instMtrls)
            {
                DomNode material   = instMtrl.GetAttribute(Schema.instance_material.targetAttribute).As <DomNode>();
                DomNode instEffect = material.GetChild(Schema.material.instance_effectChild);
                Effect  effect     = instEffect.GetAttribute(Schema.instance_effect.urlAttribute).As <Effect>();

                string symbol = instMtrl.GetAttribute(Schema.instance_material.symbolAttribute) as string;
                if (!String.IsNullOrEmpty(symbol))
                {
                    result.Add(symbol, effect);
                }
            }

            return((result.Count > 0) ? result : null);
        }
示例#9
0
 /// <summary>
 /// Constructor with parameters</summary>
 /// <param name="parent">Parent DomNode</param>
 /// <param name="child">Child DomNode</param>
 public ChildRemovedOperation(DomNode parent, DomNode child)
 {
     m_parent    = parent;
     m_child     = child;
     m_childInfo = child.ChildInfo;
     m_index     = m_childInfo.IsList ? parent.GetChildList(m_childInfo).IndexOf(child) : 0;
 }
示例#10
0
        /// <summary>
        /// Creates game by creating DomNodes and not using DOM adapters</summary>
        private static DomNode CreateGameUsingDomNode()
        {
            // Create DOM node of the root type defined by the schema
            DomNode game = new DomNode(GameSchema.gameType.Type, GameSchema.gameRootElement);

            game.SetAttribute(GameSchema.gameType.nameAttribute, "Ogre Adventure II");
            IList <DomNode> childList = game.GetChildList(GameSchema.gameType.gameObjectChild);

            // Add an ogre
            DomNode ogre = new DomNode(GameSchema.ogreType.Type);

            ogre.SetAttribute(GameSchema.ogreType.nameAttribute, "Bill");
            ogre.SetAttribute(GameSchema.ogreType.sizeAttribute, 12);
            ogre.SetAttribute(GameSchema.ogreType.strengthAttribute, 100);
            childList.Add(ogre);


            // Add a dwarf
            DomNode dwarf = new DomNode(GameSchema.dwarfType.Type);

            dwarf.SetAttribute(GameSchema.dwarfType.nameAttribute, "Sally");
            dwarf.SetAttribute(GameSchema.dwarfType.ageAttribute, 32);
            dwarf.SetAttribute(GameSchema.dwarfType.experienceAttribute, 55);
            childList.Add(dwarf);

            // Add a tree
            DomNode tree = new DomNode(GameSchema.treeType.Type);

            tree.SetAttribute(GameSchema.treeType.nameAttribute, "Mr. Oak");
            childList.Add(tree);

            return(game);
        }
示例#11
0
            /// <summary>
            /// Creates an array of property descriptors that are associated with
            /// the adapted DomNode's DomNodeType.</summary>
            /// <returns>Array of property descriptors</returns>
            protected override System.ComponentModel.PropertyDescriptor[] GetPropertyDescriptors()
            {
                // skin schema

                // styleType
                //    setterType 0 to N

                // setterType
                //     valueInfoType  0 to 1
                //     listInfoType 0 to 1

                // valueInfoType
                //  constructorParamsType 0 to 1
                //  setterType  0 to N
                //  attribs:
                //      type
                //      value

                // listInfoType
                //    valueInfoType 0 to N

                // constructorParamsType
                //    valueInfoType 0 to N


                var descriptors = new List <System.ComponentModel.PropertyDescriptor>();

                var setters = DomNode.GetChildList(SkinSchema.styleType.setterChild);

                foreach (var setter in setters)
                {
                    ProcessSetterType(setter, "", descriptors);
                }
                return(descriptors.ToArray());
            }
示例#12
0
        private DomNode CreatePrefab(IEnumerable <IGameObject> gobs)
        {
            UniqueNamer uniqueNamer = new UniqueNamer();

            DomNode[]          temp     = new DomNode[1];
            List <IGameObject> copyList = new List <IGameObject>();
            AABB bound = new AABB();

            foreach (IGameObject gameObject in SelectedGobs)
            {
                IBoundable boundable = gameObject.As <IBoundable>();
                bound.Extend(boundable.BoundingBox);
                Matrix4F world = TransformUtils.ComputeWorldTransform(gameObject);
                temp[0] = gameObject.As <DomNode>();
                DomNode[] copies = DomNode.Copy(temp);
                copies[0].InitializeExtensions();
                IGameObject copy = copies[0].As <IGameObject>();
                copy.Name = uniqueNamer.Name(copy.Name);
                TransformUtils.SetTransform(copy, world);
                copyList.Add(copy);
            }

            DomNode prefab = new DomNode(Schema.prefabType.Type, Schema.prefabRootElement);
            var     list   = prefab.GetChildList(Schema.prefabType.gameObjectChild);
            Vec3F   center = bound.Center;

            foreach (IGameObject gob in copyList)
            {
                gob.Translation = gob.Translation - center;
                gob.UpdateTransform();
                list.Add(gob.As <DomNode>());
            }
            return(prefab);
        }
示例#13
0
        public void TestValidate()
        {
            DomNodeType childType = new DomNodeType("child");
            DomNodeType parentType = new DomNodeType("parent");
            ChildInfo childInfo = new ChildInfo("child", childType, true);
            parentType.Define(childInfo);
            DomNode parent = new DomNode(parentType);
            IList<DomNode> childList = parent.GetChildList(childInfo);
            DomNode child1 = new DomNode(childType);
            DomNode child2 = new DomNode(childType);
            DomNode child3 = new DomNode(childType);

            ChildCountRule test = new ChildCountRule(1, 2);
            
            // 0 children. Not valid.
            Assert.False(test.Validate(parent, null, childInfo));

            // 1 child. Valid.
            childList.Add(child1);
            Assert.True(test.Validate(parent, null, childInfo));
            
            // 2 children. Valid.
            childList.Add(child2);
            Assert.True(test.Validate(parent, null, childInfo));

            // 3 children. Not valid.
            childList.Add(child3);
            Assert.False(test.Validate(parent, null, childInfo));

            // 0 children. Not valid.
            childList.Clear();
            Assert.False(test.Validate(parent, null, childInfo));
        }
示例#14
0
        /// <summary>
        /// Inserts new object of given type using a transaction. Called by automated scripts during testing.</summary>
        /// <typeparam name="T">Type of object to insert</typeparam>
        /// <param name="insertingObject">DomNode that contains inserted object</param>
        /// <param name="insertionParent">Parent where object is inserted</param>
        /// <returns>Inserted object</returns>
        public T Insert <T>(DomNode insertingObject, DomNode insertionParent) where T : class
        {
            SetInsertionParent(insertionParent);
            insertingObject.SetAttribute(UISchema.UIType.nameAttribute, typeof(T).Name);
            DataObject dataObject = new DataObject(new object[] { insertingObject });

            ITransactionContext transactionContext = this.As <ITransactionContext>();

            transactionContext.DoTransaction(
                delegate
            {
                Insert(dataObject);
            }, "Scripted Insert Object");

            T         newItem   = null;
            ChildInfo childInfo = GetChildInfo(insertionParent, insertingObject.Type);

            if (childInfo != null)
            {
                if (childInfo.IsList)
                {
                    IList <DomNode> list = insertionParent.GetChildList(childInfo);
                    //This assumes the new object is always appended at the end of the list
                    DomNode newNode = list[list.Count - 1];
                    newItem = newNode.As <T>();
                }
                else
                {
                    DomNode newNode = insertionParent.GetChild(childInfo);
                    newItem = newNode.As <T>();
                }
            }

            return(newItem);
        }
示例#15
0
        public void TestCopy_MultipleNodes()
        {
            DomNodeType type     = new DomNodeType("type");
            ChildInfo   info     = new ChildInfo("child", type);
            ChildInfo   infoList = new ChildInfo("childList", type, true);

            type.Define(info);
            type.Define(infoList);
            ChildInfo rootInfo = new ChildInfo("root", type, true);
            DomNode   test     = new DomNode(type, rootInfo);
            DomNode   child1   = new DomNode(type);

            test.SetChild(info, child1);
            DomNode         child2 = new DomNode(type);
            DomNode         child3 = new DomNode(type);
            IList <DomNode> list   = test.GetChildList(infoList);

            list.Add(child2);
            list.Add(child3);

            DomNode[] result = DomNode.Copy(new DomNode[] { test });
            Assert.AreEqual(result.Length, 1);
            Assert.True(Equals(result[0], test));

            DomNode singleResult = DomNode.Copy(test);

            Assert.True(Equals(singleResult, test));
        }
示例#16
0
        /// <summary>
        /// Creates game using raw DomNode</summary>        
        private static DomNode CreateGameUsingDomNode()
        {                                     
            // create Dom node of the root type defined by the schema
            DomNode game = new DomNode(GameSchema.gameType.Type, GameSchema.gameRootElement);
            game.SetAttribute(GameSchema.gameType.nameAttribute, "Ogre Adventure II");
            IList<DomNode> childList = game.GetChildList(GameSchema.gameType.gameObjectChild);

            // Add an ogre
            DomNode ogre = new DomNode(GameSchema.ogreType.Type);
            ogre.SetAttribute(GameSchema.ogreType.nameAttribute, "Bill");
            ogre.SetAttribute(GameSchema.ogreType.sizeAttribute, 12);
            ogre.SetAttribute(GameSchema.ogreType.strengthAttribute, 100);
            childList.Add(ogre);


            // Add a dwarf
            DomNode dwarf = new DomNode(GameSchema.dwarfType.Type);
            dwarf.SetAttribute(GameSchema.dwarfType.nameAttribute, "Sally");
            dwarf.SetAttribute(GameSchema.dwarfType.ageAttribute, 32);
            dwarf.SetAttribute(GameSchema.dwarfType.experienceAttribute, 55);
            childList.Add(dwarf);

            // Add a tree
            DomNode tree = new DomNode(GameSchema.treeType.Type);
            tree.SetAttribute(GameSchema.treeType.nameAttribute, "Mr. Oak");
            childList.Add(tree);

            return game;           
        }
示例#17
0
        /// <summary>
        /// Finish MEF intialization for the component by creating DomNode tree for application data.</summary>
        void IInitializable.Initialize()
        {
            m_mainform.Shown += (sender, e) =>
            {
                // create root node.
                var rootNode = new DomNode(GameSchema.gameType.Type, GameSchema.gameRootElement);
                rootNode.SetAttribute(GameSchema.gameType.nameAttribute, "Game");

                // create Orc game object and add it to rootNode.
                var orc = CreateOrc();
                rootNode.GetChildList(GameSchema.gameType.gameObjectChild).Add(orc);

                // add a child Orc.
                var orcChildList = orc.GetChildList(GameSchema.orcType.orcChild);
                orcChildList.Add(CreateOrc("Child Orc1"));

                rootNode.InitializeExtensions();

                var edContext = rootNode.Cast <GameEditingContext>();
                edContext.Set(orc);

                // set active context and select orc object.
                m_contextRegistry.ActiveContext = rootNode;
            };
        }
示例#18
0
            private void ProcessSetterType(DomNode setter, string parentPropName,
                                           List <System.ComponentModel.PropertyDescriptor> descriptors)
            {
                string curPropName = (string)setter.GetAttribute(SkinSchema.setterType.propertyNameAttribute);

                if (string.IsNullOrWhiteSpace(curPropName))
                {
                    return;
                }
                string propName = !string.IsNullOrEmpty(parentPropName)
                    ? parentPropName + "->" + curPropName : curPropName;

                DomNode valInfo = setter.GetChild(SkinSchema.setterType.valueInfoChild);

                if (valInfo != null)
                {
                    ProcessValueInfo(valInfo, propName, descriptors);
                }

                DomNode listInfo = setter.GetChild(SkinSchema.setterType.listInfoChild);

                if (listInfo != null)
                {
                    foreach (var vInfo in listInfo.GetChildList(SkinSchema.listInfoType.valueInfoChild))
                    {
                        ProcessValueInfo(vInfo, propName, descriptors);
                    }
                }
            }
示例#19
0
文件: Editor.cs 项目: vincenthamm/ATF
        /// <summary>
        /// Helper method to create instance of orcType.</summary>
        private static DomNode CreateOrc(string name = "Orc")
        {
            var orc = new DomNode(Schema.orcType.Type);
            orc.SetAttribute(Schema.orcType.nameAttribute, name);
            orc.SetAttribute(Schema.orcType.TextureRevDateAttribute, DateTime.Now);
            orc.SetAttribute(Schema.orcType.resourceFolderAttribute,System.Windows.Forms.Application.StartupPath);
            orc.SetAttribute(Schema.orcType.skinColorAttribute, System.Drawing.Color.DarkGray.ToArgb());
            orc.SetAttribute(Schema.orcType.healthAttribute, 80);
            var armorList = orc.GetChildList(Schema.orcType.armorChild);

            armorList.Add(CreateArmor("Iron breast plate",20,300));

            var clubList = orc.GetChildList(Schema.orcType.clubChild);
            clubList.Add(CreateClub(true, 20, 30));

            return orc;
        }
示例#20
0
        public void TestChildRemoveEvents()
        {
            DomNodeType type     = new DomNodeType("type");
            ChildInfo   info     = new ChildInfo("child", type);
            ChildInfo   infoList = new ChildInfo("childList", type, true);

            type.Define(info);
            type.Define(infoList);
            DomNode test = new DomNode(type);

            test.ChildRemoving += new EventHandler <ChildEventArgs>(test_ChildRemoving);
            test.ChildRemoved  += new EventHandler <ChildEventArgs>(test_ChildRemoved);

            // test child
            DomNode child = new DomNode(type);

            test.SetChild(info, child);
            ChildRemovingArgs = null;
            ChildRemovedArgs  = null;
            test.SetChild(info, null);
            ChildEventArgs expected = new ChildEventArgs(test, info, child, 0);

            Assert.True(Equals(ChildRemovingArgs, expected));
            Assert.True(Equals(ChildRemovedArgs, expected));

            // test inserting a child when there is one there already
            test.SetChild(info, child);
            DomNode newChild = new DomNode(type);

            ChildRemovingArgs = null;
            ChildRemovedArgs  = null;
            test.SetChild(info, newChild);
            expected = new ChildEventArgs(test, info, child, 0);
            Assert.True(Equals(ChildRemovingArgs, expected));
            Assert.True(Equals(ChildRemovedArgs, expected));

            // test child list
            IList <DomNode> list   = test.GetChildList(infoList);
            DomNode         child2 = new DomNode(type);

            list.Add(child2);
            DomNode child3 = new DomNode(type);

            list.Add(child3);
            ChildRemovingArgs = null;
            ChildRemovedArgs  = null;
            list.Remove(child3);
            expected = new ChildEventArgs(test, infoList, child3, 1);
            Assert.True(Equals(ChildRemovingArgs, expected));
            Assert.True(Equals(ChildRemovedArgs, expected));
            ChildRemovingArgs = null;
            ChildRemovedArgs  = null;
            list.Remove(child2);
            expected = new ChildEventArgs(test, infoList, child2, 0);
            Assert.True(Equals(ChildRemovingArgs, expected));
            Assert.True(Equals(ChildRemovedArgs, expected));
        }
示例#21
0
        private static DomNode Deserialize(BinaryReader reader, Func <string, DomNodeType> getNodeType, List <Reference> references)
        {
            string      typeName = reader.ReadString();
            DomNodeType type     = getNodeType(typeName);

            if (type == null)
            {
                throw new InvalidOperationException("unknown node type");
            }

            DomNode node = new DomNode(type);

            foreach (AttributeInfo info in type.Attributes)
            {
                bool hasAttribute = reader.ReadBoolean();
                if (hasAttribute)
                {
                    // references are reconstituted after all nodes are read
                    if (info.Type.Type == AttributeTypes.Reference)
                    {
                        int refId = reader.ReadInt32();
                        references.Add(new Reference(node, info, refId));
                    }
                    else
                    {
                        string valueString = reader.ReadString();
                        object value       = info.Type.Convert(valueString);
                        node.SetAttribute(info, value);
                    }
                }
            }

            foreach (ChildInfo info in type.Children)
            {
                if (info.IsList)
                {
                    int             count     = reader.ReadInt32();
                    IList <DomNode> childList = node.GetChildList(info);
                    for (int i = 0; i < count; i++)
                    {
                        DomNode child = Deserialize(reader, getNodeType, references);
                        childList.Add(child);
                    }
                }
                else
                {
                    bool hasChild = reader.ReadBoolean();
                    if (hasChild)
                    {
                        DomNode child = Deserialize(reader, getNodeType, references);
                        node.SetChild(info, child);
                    }
                }
            }

            return(node);
        }
示例#22
0
        /// <summary>
        /// Helper method to create instance of orcType.</summary>
        private static DomNode CreateOrc(string name = "Orc")
        {
            var orc = new DomNode(GameSchema.orcType.Type);

            orc.SetAttribute(GameSchema.orcType.nameAttribute, name);
            orc.SetAttribute(GameSchema.orcType.TextureRevDateAttribute, DateTime.Now);
            orc.SetAttribute(GameSchema.orcType.resourceFolderAttribute, System.Windows.Forms.Application.StartupPath);
            orc.SetAttribute(GameSchema.orcType.skinColorAttribute, System.Drawing.Color.DarkGray.ToArgb());
            orc.SetAttribute(GameSchema.orcType.healthAttribute, 80);
            var armorList = orc.GetChildList(GameSchema.orcType.armorChild);

            armorList.Add(CreateArmor("Iron breast plate", 20, 300));

            var clubList = orc.GetChildList(GameSchema.orcType.clubChild);

            clubList.Add(CreateClub(true, 20, 30));

            return(orc);
        }
示例#23
0
            private void ProcessValueInfo(DomNode valInfo, string propName,
                                          List <System.ComponentModel.PropertyDescriptor> descriptors)
            {
                string typeName = (string)valInfo.GetAttribute(SkinSchema.valueInfoType.typeAttribute);
                Type   type     = SkinUtil.GetType(typeName);


                if (type == typeof(Font))
                {
                    FontDescriptor descr
                        = new FontDescriptor(valInfo, propName, null, null, null, null);
                    descriptors.Add(descr);
                }
                else
                {
                    TypeConverter converter;
                    object        editor;
                    GetEditorAndConverter(type, out editor, out converter);
                    if (editor != null)
                    {
                        var descr = new SkinSetterAttributePropertyDescriptor(valInfo
                                                                              , propName, SkinSchema.valueInfoType.valueAttribute, null, null, false, editor, converter);
                        descriptors.Add(descr);
                    }
                    else
                    {
                        DomNode ctorParams = valInfo.GetChild(SkinSchema.valueInfoType.constructorParamsChild);
                        if (ctorParams != null)
                        {
                            var vInfoChildList = ctorParams.GetChildList(SkinSchema.constructorParamsType.valueInfoChild);
                            if (vInfoChildList.Count == 1)
                            {
                                ProcessValueInfo(vInfoChildList[0], propName, descriptors);
                            }
                            else
                            {
                                int    k         = 1;
                                string paramName = propName + " : Arg_";
                                foreach (DomNode vInfoChild in vInfoChildList)
                                {
                                    string name = paramName + k;
                                    ProcessValueInfo(vInfoChild, name, descriptors);
                                    k++;
                                }
                            }
                        }

                        foreach (DomNode setterChild in valInfo.GetChildList(SkinSchema.valueInfoType.setterChild))
                        {
                            ProcessSetterType(setterChild, propName, descriptors);
                        }
                    }
                }
            }
示例#24
0
        public void TestAncestorSubtree()
        {
            DomNodeType type      = new DomNodeType("type");
            ChildInfo   childInfo = new ChildInfo("child", type, true);

            type.Define(childInfo);

            DomNode grandparent = new DomNode(type);
            DomNode child1      = new DomNode(type);
            DomNode child2      = new DomNode(type);

            grandparent.GetChildList(childInfo).Add(child1);
            grandparent.GetChildList(childInfo).Add(child2);
            DomNode grandchild1 = new DomNode(type);
            DomNode grandchild2 = new DomNode(type);

            child1.GetChildList(childInfo).Add(grandchild1);
            child1.GetChildList(childInfo).Add(grandchild2);
            Utilities.TestSequenceEqual(grandparent.Subtree, grandparent, child1, grandchild1, grandchild2, child2);
        }
示例#25
0
        public void TestChildListReadonly()
        {
            DomNodeType type      = new DomNodeType("type");
            ChildInfo   childInfo = new ChildInfo("child", type, true);

            type.Define(childInfo);
            DomNode         parent = new DomNode(type);
            IList <DomNode> list   = parent.GetChildList(childInfo);

            Assert.False(list.IsReadOnly);
        }
示例#26
0
        public void TestChildParent()
        {
            DomNodeType type = new DomNodeType("type");
            ChildInfo childInfo = new ChildInfo("child", type, true);
            type.Define(childInfo);

            DomNode child = new DomNode(type);
            DomNode parent = new DomNode(type);
            parent.GetChildList(childInfo).Add(child);
            Assert.AreSame(child.Parent, parent);
        }
示例#27
0
        private DomNode CreatePrefab(IEnumerable <object> gobs)
        {
            UniqueNamer uniqueNamer = new UniqueNamer();

            DomNode[] temp     = new DomNode[1];
            var       copyList = new List <object>();
            AABB      bound    = new AABB();

            foreach (var gameObject in SelectedGobs)
            {
                IBoundable boundable = gameObject.As <IBoundable>();
                bound.Extend(boundable.BoundingBox);

                var trans = gameObject.As <ITransformable>();
                var world = (trans != null) ? TransformUtils.ComputeWorldTransform(trans) : Matrix4F.Identity;

                temp[0] = gameObject.As <DomNode>();
                DomNode[] copies = DomNode.Copy(temp);
                copies[0].InitializeExtensions();

                var nameable = copies[0].As <INameable>();
                if (nameable != null)
                {
                    nameable.Name = uniqueNamer.Name(nameable.Name);
                }

                var copyTrans = copies[0].As <ITransformable>();
                if (copyTrans != null)
                {
                    TransformUtils.SetTransform(copyTrans, world);
                }
                copyList.Add(copies[0]);
            }

            DomNode prefab = new DomNode(Schema.prefabType.Type, Schema.prefabRootElement);
            var     list   = prefab.GetChildList(Schema.prefabType.gameObjectChild);
            Vec3F   center = bound.Center;

            foreach (var gob in copyList)
            {
                var trans = gob.As <ITransformable>();
                if (trans != null)
                {
                    trans.Translation = trans.Translation - center;
                    trans.UpdateTransform();
                }
                var node = gob.As <DomNode>();
                if (node != null)
                {
                    list.Add(node);
                }
            }
            return(prefab);
        }
示例#28
0
        /// <summary>
        /// Reads in the data for an EventSequenceDocument from the given stream</summary>
        /// <remarks>This method proves the concept that a document can be persisted in a custom
        /// file format that is not XML.</remarks>
        /// <param name="stream">Stream with event sequence data</param>
        /// <returns>A valid EventSequenceDocument if successful or null if the stream's data is invalid</returns>
        public static EventSequenceDocument Read(Stream stream)
        {
            using (StreamReader reader = new StreamReader(stream))
            {
                string line = reader.ReadLine();
                if (line != "eventSequence")
                {
                    return(null);
                }

                DomNode root             = new DomNode(DomTypes.eventSequenceType.Type, DomTypes.eventSequenceRootElement);
                bool    readLineForEvent = true;
                while (true)
                {
                    // The root has a sequence of children that are eventType nodes.
                    if (readLineForEvent)
                    {
                        line = reader.ReadLine();
                    }
                    if (string.IsNullOrEmpty(line))
                    {
                        break;
                    }
                    readLineForEvent = true;
                    DomNode eventNode;
                    if (!ReadEvent(line, out eventNode))
                    {
                        break;
                    }
                    root.GetChildList(DomTypes.eventSequenceType.eventChild).Add(eventNode);

                    // Each eventType node may have zero or more resourceType nodes.
                    while (true)
                    {
                        line = reader.ReadLine();
                        if (string.IsNullOrEmpty(line))
                        {
                            break;
                        }
                        DomNode resourceNode;
                        if (!ReadResource(line, out resourceNode))
                        {
                            // might be a line for an event
                            readLineForEvent = false;
                            break;
                        }
                        eventNode.GetChildList(DomTypes.eventType.resourceChild).Add(resourceNode);
                    }
                }

                return(root.Cast <EventSequenceDocument>());
            }
        }
示例#29
0
        private void MoveBtnClick(object sender, EventArgs e)
        {
            TerrainGob gob     = (TerrainGob)m_cmboxTerrain.SelectedItem;
            ListBox    listbox = GetActiveList();

            if (listbox == null || listbox.SelectedItem == null || gob == null)
            {
                return;
            }


            int lastIndex      = listbox.Items.Count - 1;
            int selectedIndex  = listbox.SelectedIndex;
            int insertionIndex = -1;

            if (sender == m_moveUpBtn && selectedIndex > 0)
            {
                insertionIndex = selectedIndex - 1;
            }
            else if (sender == m_moveDownBtn && selectedIndex < lastIndex)
            {
                insertionIndex = selectedIndex + 1;
            }

            if (insertionIndex >= 0)
            {
                // todo: move class NativeGameWorldAdapter to LevelEditorCore
                //       and create an interface for accessing class GameEngine
                RenderingInterop.NativeGameWorldAdapter
                    gw = GameContext.As <RenderingInterop.NativeGameWorldAdapter>();
                try
                {
                    gw.ManageNativeObjectLifeTime = false;
                    object item = listbox.Items[selectedIndex];
                    GameContext.As <ITransactionContext>().DoTransaction(() =>
                    {
                        // the item must be terrain map.
                        DomNode node          = item.As <DomNode>();
                        DomNode parentNode    = node.Parent;
                        IList <DomNode> items = parentNode.GetChildList(node.ChildInfo);
                        int itemIndex         = items.IndexOf(node);
                        System.Diagnostics.Debug.Assert(itemIndex == selectedIndex);
                        items.RemoveAt(itemIndex);
                        items.Insert(insertionIndex, node);
                    }, "Move Map");
                    listbox.SelectedItem = item;
                }
                finally
                {
                    gw.ManageNativeObjectLifeTime = true;
                }
            }
        }
示例#30
0
 /// <summary>
 /// Checks that the parent DomNode has the correct # of children of the given type</summary>
 /// <param name="parent">Parent DOM node</param>
 /// <param name="child">Child DOM node; ignored</param>
 /// <param name="childInfo">Child relationship info</param>
 /// <returns>True, iff 'parent' has a valid number of children of the type associated
 /// with 'childInfo'</returns>
 public override bool Validate(DomNode parent, DomNode child, ChildInfo childInfo)
 {
     if (childInfo.IsList)
     {
         IList<DomNode> childList = parent.GetChildList(childInfo);
         int count = childList.Count;
         return
             count >= m_min &&
             count <= m_max;
     }
     // singleton child references can always be set
     return true;
 }
示例#31
0
        public void TestDescendantGetRoot()
        {
            DomNodeType type = new DomNodeType("type");
            ChildInfo childInfo = new ChildInfo("child", type, true);
            type.Define(childInfo);

            DomNode child = new DomNode(type);
            DomNode parent = new DomNode(type);
            DomNode grandparent = new DomNode(type);
            parent.GetChildList(childInfo).Add(child);
            grandparent.GetChildList(childInfo).Add(parent);
            Assert.AreSame(child.GetRoot(), grandparent);
        }
示例#32
0
        public void TestChildParent()
        {
            DomNodeType type      = new DomNodeType("type");
            ChildInfo   childInfo = new ChildInfo("child", type, true);

            type.Define(childInfo);

            DomNode child  = new DomNode(type);
            DomNode parent = new DomNode(type);

            parent.GetChildList(childInfo).Add(child);
            Assert.AreSame(child.Parent, parent);
        }
示例#33
0
 /// <summary>
 /// Checks that the parent DomNode has the correct # of children of the given type</summary>
 /// <param name="parent">Parent DOM node</param>
 /// <param name="child">Child DOM node; ignored</param>
 /// <param name="childInfo">Child relationship info</param>
 /// <returns>True, iff 'parent' has a valid number of children of the type associated
 /// with 'childInfo'</returns>
 public override bool Validate(DomNode parent, DomNode child, ChildInfo childInfo)
 {
     if (childInfo.IsList)
     {
         IList <DomNode> childList = parent.GetChildList(childInfo);
         int             count     = childList.Count;
         return
             (count >= m_min &&
              count <= m_max);
     }
     // singleton child references can always be set
     return(true);
 }
示例#34
0
文件: Mesh.cs 项目: zparr/ATF
        /// <summary>
        /// Performs initialization when the adapter's node is set.
        /// This method is called each time the adapter is connected to its underlying node.
        /// Typically overridden by creators of DOM adapters.</summary>
        protected override void OnNodeSet()
        {
            base.OnNodeSet();

            DomNode vertexChild = this.DomNode.GetChild(Schema.mesh.verticesChild);

            foreach (DomNode dome in vertexChild.GetChildList(Schema.vertices.inputChild))
            {
                PrimInput input = new PrimInput(dome, this);
                m_inputs.Add(input);
            }

            m_boundingBox = CalculateBoundingBox();
        }
示例#35
0
文件: PrimitiveSet.cs 项目: zparr/ATF
        /// <summary>
        /// Finds the index of the given binding name</summary>
        /// <param name="binding">Binding name</param>
        /// <returns>Index of the given binding name</returns>
        public int FindBinding(string binding)
        {
            IList <DomNode> bindings = DomNode.GetChildList(Schema.vertexArray_primitives.bindingChild);

            for (int i = 0; i < bindings.Count; i++)
            {
                string current = (string)bindings[i].GetAttribute(Schema.primitives_binding.sourceAttribute);
                if (current == binding)
                {
                    return(i);
                }
            }
            return(-1);
        }
示例#36
0
        public void TestRemoveFromParentList()
        {
            DomNodeType type      = new DomNodeType("type");
            ChildInfo   childInfo = new ChildInfo("child", type, true);

            type.Define(childInfo);
            DomNode parent = new DomNode(type);
            DomNode child  = new DomNode(type);

            parent.GetChildList(childInfo).Add(child);
            child.RemoveFromParent();
            CollectionAssert.IsEmpty(parent.Children);
            Assert.Null(child.Parent);
        }
示例#37
0
        public void TestGetChildList()
        {
            DomNodeType type      = new DomNodeType("type");
            ChildInfo   childInfo = new ChildInfo("child", type, true);

            type.Define(childInfo);

            DomNode         parent = new DomNode(type);
            IList <DomNode> list   = parent.GetChildList(childInfo);

            Assert.NotNull(list);
            Assert.Throws <InvalidOperationException>(delegate { parent.GetChild(childInfo); });
            CollectionAssert.IsEmpty(list);
        }
示例#38
0
        public void TestGetChild()
        {
            DomNodeType type      = new DomNodeType("type");
            ChildInfo   childInfo = new ChildInfo("child", type);

            type.Define(childInfo);

            DomNode parent = new DomNode(type);
            DomNode child  = new DomNode(type);

            parent.SetChild(childInfo, child);
            Assert.AreSame(parent.GetChild(childInfo), child);
            Assert.Throws <InvalidOperationException>(delegate { parent.GetChildList(childInfo); });
        }
示例#39
0
 /// <summary>
 /// Writes the element corresponding to the node</summary>
 /// <param name="node">DomNode to write</param>
 /// <param name="writer">The XML writer. See <see cref="T:System.Xml.XmlWriter"/></param>
 protected override void WriteElement(DomNode node, XmlWriter writer)
 {
     if (node.Type == Schema.prefabInstanceType.Type)
     {
         WriteStartElement(node, writer);
         WriteAttributes(node, writer);
         foreach (DomNode child in node.GetChildList(Schema.prefabInstanceType.objectOverrideChild))
             WriteElement(child, writer);
         writer.WriteEndElement();
     }
     else
     {
         base.WriteElement(node, writer);
     }
 }
示例#40
0
        public void TestGetPath()
        {
            DomNodeType type = new DomNodeType("type");
            ChildInfo childInfo = new ChildInfo("child", type, true);
            type.Define(childInfo);

            DomNode child = new DomNode(type);
            DomNode parent = new DomNode(type);
            DomNode grandparent = new DomNode(type);
            parent.GetChildList(childInfo).Add(child);
            grandparent.GetChildList(childInfo).Add(parent);

            Utilities.TestSequenceEqual(child.GetPath(), grandparent, parent, child);
            Utilities.TestSequenceEqual(parent.GetPath(), grandparent, parent);
            Utilities.TestSequenceEqual(grandparent.GetPath(), grandparent);
        }
示例#41
0
        /// <summary>
        /// Reads in the data for an EventSequenceDocument from the given stream</summary>
        /// <remarks>This method proves the concept that a document can be persisted in a custom
        /// file format that is not XML.</remarks>
        /// <param name="stream">Stream with event sequence data</param>
        /// <returns>A valid EventSequenceDocument if successful or null if the stream's data is invalid</returns>
        public static EventSequenceDocument Read(Stream stream)
        {
            using (StreamReader reader = new StreamReader(stream))
            {
                string line = reader.ReadLine();
                if (line != "eventSequence")
                    return null;

                DomNode root = new DomNode(DomTypes.eventSequenceType.Type, DomTypes.eventSequenceRootElement);
                bool readLineForEvent = true;
                while (true)
                {
                    // The root has a sequence of children that are eventType nodes.
                    if (readLineForEvent)
                        line = reader.ReadLine();
                    if (string.IsNullOrEmpty(line))
                        break;
                    readLineForEvent = true;
                    DomNode eventNode;
                    if (!ReadEvent(line, out eventNode))
                        break;
                    root.GetChildList(DomTypes.eventSequenceType.eventChild).Add(eventNode);

                    // Each eventType node may have zero or more resourceType nodes.
                    while (true)
                    {
                        line = reader.ReadLine();
                        if (string.IsNullOrEmpty(line))
                            break;
                        DomNode resourceNode;
                        if (!ReadResource(line, out resourceNode))
                        {
                            // might be a line for an event
                            readLineForEvent = false;
                            break;
                        }
                        eventNode.GetChildList(DomTypes.eventType.resourceChild).Add(resourceNode);
                    }
                }

                return root.Cast<EventSequenceDocument>();
            }
        }
        public void Insert(DomNode parent, DomNode child, ChildInfo chInfo, int index)
        {
            NativeObjectAdapter childObject = child.As<NativeObjectAdapter>();
            NativeObjectAdapter parentObject = parent.As<NativeObjectAdapter>();

            object listIdObj = chInfo.GetTag(NativeAnnotations.NativeElement);

            if (childObject == null || parentObject == null || listIdObj == null)
                return;

            if (chInfo.IsList && index >= (parent.GetChildList(chInfo).Count - 1))
                index = -1;

            if (ManageNativeObjectLifeTime)
            {
                GameEngine.CreateObject(childObject);
                childObject.UpdateNativeOjbect();
            }
            System.Diagnostics.Debug.Assert(childObject.InstanceId != 0);

            uint listId = (uint)listIdObj;
            uint typeId = (uint)chInfo.DefiningType.GetTag(NativeAnnotations.NativeType);
            ulong parentId = parentObject.InstanceId;
            ulong childId = childObject.InstanceId;

            if (index >= 0)
            {
                GameEngine.ObjectInsertChild(typeId, listId, parentId, childId, index);
            }
            else
            {
                GameEngine.ObjectAddChild(typeId, listId, parentId, childId);
            }

            foreach (var node in child.Children)
            {
                Insert(child, node, node.ChildInfo, -1); // use -1 for index to indicate an append operation.
            }
        }    
示例#43
0
        public void TestChildListInsert()
        {
            DomNodeType type = new DomNodeType("type");
            ChildInfo childInfo = new ChildInfo("child", type, true);
            type.Define(childInfo);
            DomNode parent = new DomNode(type);
            IList<DomNode> list = parent.GetChildList(childInfo);
            DomNode child1 = new DomNode(type);
            list.Insert(0, child1);
            Utilities.TestSequenceEqual(list, child1);
            // insertion again will cause removal, then insertion
            list.Insert(0, child1);
            Utilities.TestSequenceEqual(list, child1);

            DomNode child2 = new DomNode(type);
            list.Insert(0, child2);
            Utilities.TestSequenceEqual(list, child2, child1);
        }
示例#44
0
 public void TestChildListClear()
 {
     DomNodeType type = new DomNodeType("type");
     ChildInfo childInfo = new ChildInfo("child", type, true);
     type.Define(childInfo);
     DomNode parent = new DomNode(type);
     IList<DomNode> list = parent.GetChildList(childInfo);
     DomNode child1 = new DomNode(type);
     list.Add(child1);
     DomNode child2 = new DomNode(type);
     list.Add(child2);
     list.Clear();
     CollectionAssert.IsEmpty(list);
 }
示例#45
0
 public void TestChildListIndexOf()
 {
     DomNodeType type = new DomNodeType("type");
     ChildInfo childInfo = new ChildInfo("child", type, true);
     type.Define(childInfo);
     DomNode parent = new DomNode(type);
     IList<DomNode> list = parent.GetChildList(childInfo);
     DomNode child1 = new DomNode(type);
     Assert.AreEqual(list.IndexOf(child1), -1);
     list.Insert(0, child1);
     Assert.AreEqual(list.IndexOf(child1), 0);
     DomNode child2 = new DomNode(type);
     list.Insert(0, child2);
     Assert.AreEqual(list.IndexOf(child2), 0);
     Assert.AreEqual(list.IndexOf(child1), 1);
 }
示例#46
0
        public void TestMoveDomNode()
        {
            var root = new DomNode(RootType.Type, RootElement);

            root.InitializeExtensions();

            var folderChild1 = new DomNode(FolderType.Type);
            var folderChild2 = new DomNode(FolderType.Type);
            var itemChild1 = new DomNode(ItemType.Type);
            var itemChild2 = new DomNode(ItemType.Type);

            var validationContext = root.As<ValidationContext>();
            
            // Set up the tree:
            // root
            //     folder
            //         item
            //     folder1
            //         item

            validationContext.RaiseBeginning();

            root.SetAttribute(RootType.NameAttribute, "root");
            itemChild1.SetAttribute(ItemType.NameAttribute, "item");
            itemChild2.SetAttribute(ItemType.NameAttribute, "item");
            folderChild1.SetAttribute(FolderType.NameAttribute, "folder");
            folderChild2.SetAttribute(FolderType.NameAttribute, "folder");

            folderChild1.GetChildList(FolderType.ItemChild).Add(itemChild1);
            folderChild2.GetChildList(FolderType.ItemChild).Add(itemChild2);

            root.GetChildList(RootType.FolderChild).Add(folderChild1);
            root.GetChildList(RootType.FolderChild).Add(folderChild2);

            // renames all folders and items with unique paths
            validationContext.RaiseEnding();
            validationContext.RaiseEnded(); 

            // Move item from first folder to second folder
            // root
            //     folder
            //     folder1
            //         item
            //         item1

            validationContext.RaiseBeginning();

            itemChild1.RemoveFromParent();
            folderChild2.GetChildList(FolderType.ItemChild).Add(itemChild1);

            validationContext.RaiseEnding();
            validationContext.RaiseEnded();
            Assert.DoesNotThrow(() => ValidateSubtree(folderChild2));
            // Make sure that the existing child wasn't renamed. Only the moved child should be renamed.
            Assert.True((string)itemChild2.GetAttribute(ItemType.NameAttribute) == "item");

            // Rename 'item_1' to 'item'.
            validationContext.RaiseBeginning();

            itemChild1.SetAttribute(ItemType.NameAttribute, "item");

            validationContext.RaiseEnding();
            validationContext.RaiseEnded();
            Assert.DoesNotThrow(() => ValidateSubtree(folderChild2));

            // Make sure that the existing child wasn't renamed. Only the moved child should be renamed.
            Assert.True((string)itemChild2.GetAttribute(ItemType.NameAttribute) == "item");

            // Rename the root.
            validationContext.RaiseBeginning();

            root.SetAttribute(RootType.NameAttribute, "new_root");

            validationContext.RaiseEnding();
            validationContext.RaiseEnded();
            Assert.DoesNotThrow(() => ValidateSubtree(root));
            Assert.True((string)root.GetAttribute(RootType.NameAttribute) == "new_root");
        }
示例#47
0
        public void TestGetChildList()
        {
            DomNodeType type = new DomNodeType("type");
            ChildInfo childInfo = new ChildInfo("child", type, true);
            type.Define(childInfo);

            DomNode parent = new DomNode(type);
            IList<DomNode> list = parent.GetChildList(childInfo);
            Assert.NotNull(list);
            Assert.Throws<InvalidOperationException>(delegate { parent.GetChild(childInfo); });
            CollectionAssert.IsEmpty(list);
        }
示例#48
0
 /// <summary>
 /// Writes the child elements recursively</summary>
 /// <param name="node">DomNode to write</param>
 /// <param name="writer">The XML writer. See <see cref="T:System.Xml.XmlWriter"/>.</param>
 protected virtual void WriteChildElementsRecursive(DomNode node, XmlWriter writer)
 {
     // write child elements
     foreach (ChildInfo childInfo in node.Type.Children)
     {
         if (childInfo.IsList)
         {
             foreach (DomNode child in node.GetChildList(childInfo))
                 WriteElement(child, writer);
         }
         else
         {
             DomNode child = node.GetChild(childInfo);
             if (child != null)
                 WriteElement(child, writer);
         }
     }
 }
示例#49
0
        public void TestChildListRemove()
        {
            DomNodeType type = new DomNodeType("type");
            ChildInfo childInfo = new ChildInfo("child", type, true);
            type.Define(childInfo);
            DomNode parent = new DomNode(type);
            IList<DomNode> list = parent.GetChildList(childInfo);
            DomNode child1 = new DomNode(type);
            Assert.False(list.Remove(child1));
            list.Add(child1);
            DomNode child2 = new DomNode(type);
            list.Add(child2);

            Assert.True(list.Remove(child1));
            Utilities.TestSequenceEqual(list, child2);

            Assert.True(list.Remove(child2));
            CollectionAssert.IsEmpty(list);
        }
示例#50
0
        private bool Equals(DomNode n1, DomNode n2)
        {
            if (n1 == null || n2 == null)
                return n1 == n2;
            if (n1.Type != n2.Type)
                return false;
            if (n1.ChildInfo != n2.ChildInfo)
                return false;

            foreach (AttributeInfo info in n1.Type.Attributes)
            {
                object val1 = n1.GetLocalAttribute(info);
                object val2 = n2.GetLocalAttribute(info);
                if (val1 == null || val2 == null)
                    if (val1 != val2)
                        return false;
            }

            foreach (ChildInfo info in n1.Type.Children)
            {
                if (info.IsList)
                {
                    IList<DomNode> children1 = n1.GetChildList(info);
                    IList<DomNode> children2 = n1.GetChildList(info);
                    if (children1.Count != children2.Count)
                        return false;
                    for (int i = 0; i < children1.Count; i++)
                        if (!Equals(children1[i], children2[i]))
                            return false;
                }
                else
                {
                    DomNode child1 = n1.GetChild(info);
                    DomNode child2 = n2.GetChild(info);
                    if (!Equals(child1, child2))
                        return false;
                }
            }

            return true;
        }
示例#51
0
        public void TestCopy_MultipleNodes()
        {
            DomNodeType type = new DomNodeType("type");
            ChildInfo info = new ChildInfo("child", type);
            ChildInfo infoList = new ChildInfo("childList", type, true);
            type.Define(info);
            type.Define(infoList);
            ChildInfo rootInfo = new ChildInfo("root", type, true);
            DomNode test = new DomNode(type, rootInfo);
            DomNode child1 = new DomNode(type);
            test.SetChild(info, child1);
            DomNode child2 = new DomNode(type);
            DomNode child3 = new DomNode(type);
            IList<DomNode> list = test.GetChildList(infoList);
            list.Add(child2);
            list.Add(child3);

            DomNode[] result = DomNode.Copy(new DomNode[] { test });
            Assert.AreEqual(result.Length, 1);
            Assert.True(Equals(result[0], test));

            DomNode singleResult = DomNode.Copy(test);
            Assert.True(Equals(singleResult, test));
        }
示例#52
0
        public void TestChildRemoveEvents()
        {
            DomNodeType type = new DomNodeType("type");
            ChildInfo info = new ChildInfo("child", type);
            ChildInfo infoList = new ChildInfo("childList", type, true);
            type.Define(info);
            type.Define(infoList);
            DomNode test = new DomNode(type);
            test.ChildRemoving += new EventHandler<ChildEventArgs>(test_ChildRemoving);
            test.ChildRemoved += new EventHandler<ChildEventArgs>(test_ChildRemoved);

            // test child
            DomNode child = new DomNode(type);
            test.SetChild(info, child);
            ChildRemovingArgs = null;
            ChildRemovedArgs = null;
            test.SetChild(info, null);
            ChildEventArgs expected = new ChildEventArgs(test, info, child, 0);
            Assert.True(Equals(ChildRemovingArgs, expected));
            Assert.True(Equals(ChildRemovedArgs, expected));

            // test inserting a child when there is one there already
            test.SetChild(info, child);
            DomNode newChild = new DomNode(type);
            ChildRemovingArgs = null;
            ChildRemovedArgs = null;
            test.SetChild(info, newChild);
            expected = new ChildEventArgs(test, info, child, 0);
            Assert.True(Equals(ChildRemovingArgs, expected));
            Assert.True(Equals(ChildRemovedArgs, expected));

            // test child list
            IList<DomNode> list = test.GetChildList(infoList);
            DomNode child2 = new DomNode(type);
            list.Add(child2);
            DomNode child3 = new DomNode(type);
            list.Add(child3);
            ChildRemovingArgs = null;
            ChildRemovedArgs = null;
            list.Remove(child3);
            expected = new ChildEventArgs(test, infoList, child3, 1);
            Assert.True(Equals(ChildRemovingArgs, expected));
            Assert.True(Equals(ChildRemovedArgs, expected));
            ChildRemovingArgs = null;
            ChildRemovedArgs = null;
            list.Remove(child2);
            expected = new ChildEventArgs(test, infoList, child2, 0);
            Assert.True(Equals(ChildRemovingArgs, expected));
            Assert.True(Equals(ChildRemovedArgs, expected));
        }
示例#53
0
        public void TestGetChild()
        {
            DomNodeType type = new DomNodeType("type");
            ChildInfo childInfo = new ChildInfo("child", type);
            type.Define(childInfo);

            DomNode parent = new DomNode(type);
            DomNode child = new DomNode(type);
            parent.SetChild(childInfo, child);
            Assert.AreSame(parent.GetChild(childInfo), child);
            Assert.Throws<InvalidOperationException>(delegate { parent.GetChildList(childInfo); });
        }
示例#54
0
        private DomNode CreatePrefab(IEnumerable<IGameObject> gobs)
        {
            UniqueNamer uniqueNamer = new UniqueNamer();
            DomNode[] temp = new DomNode[1];
            List<IGameObject> copyList = new List<IGameObject>();
            AABB bound = new AABB();
            foreach (IGameObject gameObject in SelectedGobs)
            {
                IBoundable boundable = gameObject.As<IBoundable>();
                bound.Extend(boundable.BoundingBox);
                Matrix4F world = TransformUtils.ComputeWorldTransform(gameObject);
                temp[0] = gameObject.As<DomNode>();
                DomNode[] copies = DomNode.Copy(temp);
                copies[0].InitializeExtensions();
                IGameObject copy = copies[0].As<IGameObject>();
                copy.Name = uniqueNamer.Name(copy.Name);
                TransformUtils.SetTransform(copy, world);
                copyList.Add(copy);
            }

            DomNode prefab = new DomNode(Schema.prefabType.Type, Schema.prefabRootElement);
            var list = prefab.GetChildList(Schema.prefabType.gameObjectChild);
            Vec3F center = bound.Center;
            foreach (IGameObject gob in copyList)
            {                
                gob.Translation = gob.Translation - center;
                gob.UpdateTransform(); 
                list.Add(gob.As<DomNode>());
            }            
            return prefab;
        }
示例#55
0
 public void TestChildListContains()
 {
     DomNodeType type = new DomNodeType("type");
     ChildInfo childInfo = new ChildInfo("child", type, true);
     type.Define(childInfo);
     DomNode parent = new DomNode(type);
     IList<DomNode> list = parent.GetChildList(childInfo);
     DomNode child1 = new DomNode(type);
     Assert.False(list.Contains(child1));
     list.Add(child1);
     DomNode child2 = new DomNode(type);
     list.Add(child2);
     Assert.True(list.Contains(child2));
 }
示例#56
0
 public void TestChildListCopyTo()
 {
     DomNodeType type = new DomNodeType("type");
     ChildInfo childInfo = new ChildInfo("child", type, true);
     type.Define(childInfo);
     DomNode parent = new DomNode(type);
     IList<DomNode> list = parent.GetChildList(childInfo);
     DomNode child1 = new DomNode(type);
     list.Add(child1);
     DomNode child2 = new DomNode(type);
     list.Add(child2);
     DomNode[] array = new DomNode[list.Count + 1];
     list.CopyTo(array, 1);
     Utilities.TestSequenceEqual(array, null, child1, child2);
 }
示例#57
0
 public void TestChildListAdd()
 {
     DomNodeType type = new DomNodeType("type");
     ChildInfo childInfo = new ChildInfo("child", type, true);
     type.Define(childInfo);
     DomNode parent = new DomNode(type);
     IList<DomNode> list = parent.GetChildList(childInfo);
     DomNode child1 = new DomNode(type);
     list.Add(child1);
     Utilities.TestSequenceEqual(list, child1);
     DomNode child2 = new DomNode(type);
     list.Add(child2);
     Utilities.TestSequenceEqual(list, child1, child2);
     // add node that's already in the list; should remove it from old location
     list.Add(child1);
     Utilities.TestSequenceEqual(list, child2, child1);
 }
示例#58
0
        public void TestChildListIndexer()
        {
            DomNodeType type = new DomNodeType("type");
            ChildInfo childInfo = new ChildInfo("child", type, true);
            type.Define(childInfo);
            DomNode parent = new DomNode(type);
            IList<DomNode> list = parent.GetChildList(childInfo);
            DomNode child1 = new DomNode(type);
            Assert.Throws<IndexOutOfRangeException>(delegate { list[0] = child1; });
            list.Add(child1);
            Assert.AreSame(list[0], child1);
            DomNode child2 = new DomNode(type);
            list.Add(child2);
            Assert.AreSame(list[1], child2);

            DomNode child3 = new DomNode(type);
            list[0] = child3;
            Utilities.TestSequenceEqual(list, child3, child2); // child1 gets removed by set
        }
示例#59
0
 public void TestRemoveFromParentList()
 {
     DomNodeType type = new DomNodeType("type");
     ChildInfo childInfo = new ChildInfo("child", type, true);
     type.Define(childInfo);
     DomNode parent = new DomNode(type);
     DomNode child = new DomNode(type);
     parent.GetChildList(childInfo).Add(child);
     child.RemoveFromParent();
     CollectionAssert.IsEmpty(parent.Children);
     Assert.Null(child.Parent);
 }
示例#60
0
 public void TestChildListReadonly()
 {
     DomNodeType type = new DomNodeType("type");
     ChildInfo childInfo = new ChildInfo("child", type, true);
     type.Define(childInfo);
     DomNode parent = new DomNode(type);
     IList<DomNode> list = parent.GetChildList(childInfo);
     Assert.False(list.IsReadOnly);
 }