Example #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(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;
            };
        }
Example #2
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()));
            };
        }
Example #3
0
        // Tests http://tracker.ship.scea.com/jira/browse/WWSATF-1370
        // Test adding two types of extensions that have the same Name but different FullName.
        public void TestDuplicateNames()
        {
            var domType = new DomNodeType("domType");
            var extension = new ExtensionInfo<TestExtensionInfo>();
            domType.Define(extension);

            var domDerivedType = new DomNodeType("domDerivedType", domType);
            var anotherExtension = new ExtensionInfo<AnotherName.TestExtensionInfo>();
            domDerivedType.Define(anotherExtension);

            var domNode = new DomNode(domDerivedType);
            domNode.InitializeExtensions();
            Assert.IsTrue(domNode.GetExtension(extension).GetType() == typeof(TestExtensionInfo));
            Assert.IsTrue(domNode.GetExtension(anotherExtension).GetType() == typeof(AnotherName.TestExtensionInfo));

            ExtensionInfo getInfo = domType.GetExtensionInfo("UnitTests.Atf.Dom.TestExtensionInfo");
            Assert.IsNotNull(getInfo);
            Assert.AreEqual(getInfo, extension);

            getInfo = domDerivedType.GetExtensionInfo("UnitTests.Atf.Dom.TestExtensionInfo");
            Assert.IsNotNull(getInfo);
            Assert.AreEqual(getInfo, extension);
            
            ExtensionInfo anotherGetInfo = domDerivedType.GetExtensionInfo("UnitTests.Atf.Dom.AnotherName.TestExtensionInfo");
            Assert.IsNotNull(anotherGetInfo);
            Assert.AreEqual(anotherGetInfo, anotherExtension);
        }
Example #4
0
File: Editor.cs Project: Joxx0r/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 orc = CreateOrc();
                    rootNode.GetChildList(Schema.gameType.gameObjectChild).Add(orc);

                    // add a child Orc.
                    var orcChildList = orc.GetChildList(Schema.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;
                    
                };
        }
Example #5
0
        // Tests http://tracker.ship.scea.com/jira/browse/WWSATF-1370
        // Test adding two types of extensions that have the same Name but different FullName.
        public void TestDuplicateNames()
        {
            var domType   = new DomNodeType("domType");
            var extension = new ExtensionInfo <TestExtensionInfo>();

            domType.Define(extension);

            var domDerivedType   = new DomNodeType("domDerivedType", domType);
            var anotherExtension = new ExtensionInfo <AnotherName.TestExtensionInfo>();

            domDerivedType.Define(anotherExtension);

            var domNode = new DomNode(domDerivedType);

            domNode.InitializeExtensions();
            Assert.IsTrue(domNode.GetExtension(extension).GetType() == typeof(TestExtensionInfo));
            Assert.IsTrue(domNode.GetExtension(anotherExtension).GetType() == typeof(AnotherName.TestExtensionInfo));

            ExtensionInfo getInfo = domType.GetExtensionInfo("UnitTests.Atf.Dom.TestExtensionInfo");

            Assert.IsNotNull(getInfo);
            Assert.AreEqual(getInfo, extension);

            getInfo = domDerivedType.GetExtensionInfo("UnitTests.Atf.Dom.TestExtensionInfo");
            Assert.IsNotNull(getInfo);
            Assert.AreEqual(getInfo, extension);

            ExtensionInfo anotherGetInfo = domDerivedType.GetExtensionInfo("UnitTests.Atf.Dom.AnotherName.TestExtensionInfo");

            Assert.IsNotNull(anotherGetInfo);
            Assert.AreEqual(anotherGetInfo, anotherExtension);
        }
Example #6
0
            public IGameObject CreateInstance()
            {
                DomNode[] org  = { m_node.GetChild(Schema.prototypeType.gameObjectChild) };
                DomNode   copy = DomNode.Copy(org)[0];

                copy.InitializeExtensions();
                return(copy.As <IGameObject>());
            }
Example #7
0
 public static PrefabInstance Create(IPrefab prefab)
 {
     DomNode instNode = new DomNode(Schema.prefabInstanceType.Type);
     PrefabInstance inst = instNode.As<PrefabInstance>();
     inst.m_prefab = prefab;
     instNode.InitializeExtensions();
     inst.Resolve(null);
     return inst;
 }
Example #8
0
        private DomNode CreatePrototype(IEnumerable <IGameObject> gobs)
        {
            DomNode[] originals = 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);
                originals[0] = gameObject.As <DomNode>();
                DomNode[]   copies = DomNode.Copy(originals);
                IGameObject copy   = copies[0].As <IGameObject>();
                TransformUtils.SetTransform(copy, world);
                copyList.Add(copy);
            }

            DomNode gobchild = null;

            if (copyList.Count > 1)
            {// create group
                IGame            game     = m_contextRegistry.GetActiveContext <IGame>();
                IGameObjectGroup gobgroup = game.CreateGameObjectGroup();
                gobgroup.Translation = bound.Center;
                gobgroup.UpdateTransform();
                Matrix4F worldInv = new Matrix4F();
                worldInv.Invert(gobgroup.Transform);
                foreach (IGameObject gob in copyList)
                {
                    Vec3F translate = gob.Translation;
                    worldInv.Transform(ref translate);
                    gob.Translation = translate;
                    gob.UpdateTransform();
                    gobgroup.GameObjects.Add(gob);
                }
                gobchild = gobgroup.As <DomNode>();
            }
            else
            {
                gobchild = copyList[0].As <DomNode>();
            }

            gobchild.InitializeExtensions();
            gobchild.As <IGameObject>().Translation = new Vec3F(0, 0, 0);

            DomNode prototype = null;

            if (gobchild != null)
            {
                prototype = new DomNode(Schema.prototypeType.Type, Schema.prototypeRootElement);
                prototype.SetChild(Schema.prototypeType.gameObjectChild, gobchild);
            }
            return(prototype);
        }
Example #9
0
        /// <summary>
        /// Creates a control point</summary>
        /// <returns>Control point</returns>
        public IControlPoint CreateControlPoint()
        {
            DomNode node = new DomNode(Schema.controlPointType.Type);

            node.InitializeExtensions();
            IControlPoint cpt = node.As <IControlPoint>();

            cpt.Name = "ControlPoint";
            return(cpt);
        }
Example #10
0
        public static PrefabInstance Create(IPrefab prefab)
        {
            DomNode        instNode = new DomNode(Schema.prefabInstanceType.Type);
            PrefabInstance inst     = instNode.As <PrefabInstance>();

            inst.m_prefab = prefab;
            instNode.InitializeExtensions();
            inst.Resolve(null);
            return(inst);
        }
Example #11
0
        public static DecorationMap Create(Uri maskuri)
        {
            DomNode node = new DomNode(Schema.decorationMapType.Type);

            node.SetAttribute(Schema.decorationMapType.maskAttribute, maskuri);
            node.InitializeExtensions();
            DecorationMap map = node.As <DecorationMap>();

            map.Name = "DecorationMap";
            return(map);
        }
Example #12
0
        /// <summary>
        /// Groups the specified GameObjects</summary>
        /// <param name="gobs">GameObjects to be grouped</param>
        /// <remarks>Creates a new GameObjectGroup and moves all
        /// the GameObjects into it.</remarks>
        public IGameObjectGroup Group(IEnumerable <IGameObject> gobs)
        {
            // extra check.
            if (!CanGroup(gobs))
            {
                return(null);
            }

            IGame game     = null;
            AABB  groupBox = new AABB();
            List <IGameObject> gameObjects = new List <IGameObject>();

            foreach (IGameObject gameObject in gobs)
            {
                if (game == null)
                {
                    game = gameObject.As <DomNode>().GetRoot().As <IGame>();
                }

                gameObjects.Add(gameObject);

                IBoundable boundable = gameObject.As <IBoundable>();
                groupBox.Extend(boundable.BoundingBox);
            }

            IGameObjectGroup group = game.CreateGameObjectGroup();
            DomNode          node  = group.As <DomNode>();

            node.InitializeExtensions();
            ITransformable transformable = node.As <ITransformable>();

            transformable.Translation = groupBox.Center;

            Matrix4F invWorld = new Matrix4F();

            invWorld.Invert(transformable.Transform);

            game.RootGameObjectFolder.GameObjects.Add(group);

            foreach (IGameObject gameObject in gameObjects)
            {
                ITransformable xformable = gameObject.As <ITransformable>();
                Matrix4F       world     = ComputeWorldTransform(xformable);
                SetTransform(xformable, world);
                group.GameObjects.Add(gameObject);
                Vec3F trans = world.Translation;
                invWorld.Transform(ref trans);
                xformable.Translation = trans;
            }

            return(group);
        }
Example #13
0
        /// <summary>
        /// Creates a control point</summary>
        /// <returns>Control point</returns>
        public IControlPoint CreateControlPoint()
        {
            DomNode node = new DomNode(UISchema.controlPointType.Type);

            node.InitializeExtensions();
            IControlPoint cpt = node.As <IControlPoint>();

            cpt.TangentInType  = CurveTangentTypes.Spline;
            cpt.TangentIn      = new Vec2F(0.5f, 0.5f);
            cpt.TangentOutType = CurveTangentTypes.Spline;
            cpt.TangentOut     = new Vec2F(0.5f, 0.5f);
            return(cpt);
        }
Example #14
0
        protected override void OnDragEnter(DragEventArgs drgevent)
        {
            base.OnDragEnter(drgevent);
            var dragDropTarget = TargetGame();

            foreach (DomNode ghost in m_ghosts)
            {
                ghost.RemoveFromParent();
            }
            m_ghosts.Clear();

            ResourceConverterService resourceConverter = Globals.MEFContainer.GetExportedValue <ResourceConverterService>();
            IEnumerable <object>     nodes             = Util.ConvertData(drgevent.Data, false);

            foreach (object iterNode in nodes)
            {
                DomNode node = iterNode as DomNode;
                if (node == null)
                {
                    if (resourceConverter != null)
                    {
                        var resGob = resourceConverter.Convert(iterNode as IResource);
                        node = resGob.As <DomNode>();
                    }
                }

                if (node == null || node.GetRoot().Is <IGame>())
                {
                    continue;
                }

                node.InitializeExtensions();

                var  hierarchical = dragDropTarget.AsAll <IHierarchical>();
                bool wasInserted  = false;
                foreach (var h in hierarchical)
                {
                    if (h.AddChild(node))
                    {
                        wasInserted = true; break;
                    }
                }

                if (wasInserted)
                {
                    m_ghosts.Add(node);
                }
            }

            drgevent.Effect = (m_ghosts.Count > 0) ? (DragDropEffects.Move | DragDropEffects.Link) : DragDropEffects.None;
        }
Example #15
0
        /// <summary>
        /// Opens or creates a document at the given URI</summary>
        /// <param name="uri">Document URI</param>
        /// <returns>Document, or null if the document couldn't be opened or created</returns>
        public IDocument Open(Uri uri)
        {
            DomNode node     = null;
            string  filePath = uri.LocalPath;
            string  fileName = Path.GetFileName(filePath);

            if (File.Exists(filePath))
            {
                // read existing document using standard XML reader
                using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    DomXmlReader reader = new DomXmlReader(m_schemaLoader);
                    node = reader.Read(stream, uri);
                }
            }
            else
            {
                // create new document by creating a Dom node of the root type defined by the schema
                node = SceneEditingContext._CreateSceneRoot("Scene");
            }



            SceneDocument document = null;

            if (node != null)
            {
                // Initialize Dom extensions now that the data is complete; after this, all Dom node
                //  adapters will have been bound to their underlying Dom node.
                node.InitializeExtensions();

                SceneEditingContext context = node.As <SceneEditingContext>();

                ControlInfo controlInfo = new ControlInfo(fileName, filePath, StandardControlGroup.Center);
                controlInfo.IsDocument = true;
                context.ControlInfo    = controlInfo;

                document     = node.As <SceneDocument>();
                document.Uri = uri;

                context.PropertyEditor  = m_propertyEditor;
                context.ContextRegistry = m_contextRegistry;
                context.Initialize(m_commandService);
                context.TreeEditor.TreeControl.Tag = document;

                context.Root = node;
                m_controlHostService.RegisterControl(context.TreeEditor.TreeControl, context.ControlInfo, this);
            }
            return(document);
        }
Example #16
0
        public static TerrainGob Create(string name, string hmPath, float cellSize)
        {            
            if (string.IsNullOrWhiteSpace(name))
                throw new ArgumentNullException(name);

            if (!File.Exists(hmPath))
                throw new ArgumentException(hmPath + " does not exist");
            
            Uri ur = new Uri(hmPath);
            DomNode terrainNode = new DomNode(Schema.terrainGobType.Type);            
            terrainNode.SetAttribute(Schema.terrainGobType.cellSizeAttribute, cellSize);
            terrainNode.SetAttribute(Schema.terrainGobType.heightMapAttribute, ur);
            terrainNode.InitializeExtensions();
            TerrainGob terrain = terrainNode.As<TerrainGob>();
            terrain.Name = name;
            return terrain;
        }
        /// <summary>
        /// Clones this control point</summary>
        /// <returns>Cloned control point</returns>
        public IControlPoint Clone()
        {
            DomNode node = new DomNode(UISchema.controlPointType.Type);

            // clone local attributes
            foreach (AttributeInfo attributeInfo in DomNode.Type.Attributes)
            {
                object value = DomNode.GetLocalAttribute(attributeInfo);
                if (value != null)
                {
                    node.SetAttribute(attributeInfo, attributeInfo.Type.Clone(value));
                }
            }

            node.InitializeExtensions();
            return(node.As <IControlPoint>());
        }
Example #18
0
        protected override void OnDragEnter(DragEventArgs drgevent)
        {
            base.OnDragEnter(drgevent);
            IGame dragDropTarget = TargetGame();

            if (dragDropTarget.RootGameObjectFolder.IsLocked)
            {
                drgevent.Effect = DragDropEffects.None;
                return;
            }

            IGameObjectFolder rootFolder = dragDropTarget.RootGameObjectFolder;

            m_ghosts.Clear();

            ResourceConverterService resourceConverter = Globals.MEFContainer.GetExportedValue <ResourceConverterService>();


            IEnumerable <object> nodes = Util.ConvertData(drgevent.Data, false);

            foreach (object iterNode in nodes)
            {
                DomNode node = iterNode as DomNode;
                if (node == null)
                {
                    if (resourceConverter != null)
                    {
                        IGameObject resGob = resourceConverter.Convert(iterNode as IResource);
                        node = resGob.As <DomNode>();
                    }
                }

                IGameObject gob = node.As <IGameObject>();
                if (gob == null || node.GetRoot().Is <IGame>())
                {
                    continue;
                }

                node.InitializeExtensions();
                m_ghosts.Add(node);
                rootFolder.GameObjects.Add(gob);
            }

            drgevent.Effect = m_ghosts.Count > 0 ? DragDropEffects.Move | DragDropEffects.Link
            : DragDropEffects.None;
        }
Example #19
0
        public static XLEPlacementDocument OpenUntitled()
        {
            var rootNode = new DomNode(Schema.placementsDocumentType.Type, Schema.placementsDocumentRootElement);

            var doc = rootNode.As <XLEPlacementDocument>();

            // Initialize Dom extensions now that the data is complete
            rootNode.InitializeExtensions();

            var docRegistry = GetDocRegistry();

            if (docRegistry != null)
            {
                docRegistry.Add(doc);
            }
            doc.Dirty = true;
            return(doc);
        }
Example #20
0
        IEnumerable <object> IResourceMetadataService.GetMetadata(IEnumerable <Uri> resourceUris)
        {
            List <DomNode> rootNodes = new List <DomNode>();

            foreach (Uri resourceUri in resourceUris)
            {
                string reExt = System.IO.Path.GetExtension(resourceUri.LocalPath).ToLower();

                ResourceMetadataInfo resInfo;
                m_extMap.TryGetValue(reExt, out resInfo);
                if (resInfo == null)
                {
                    m_extMap.TryGetValue(".*", out resInfo);
                }

                string  metadataFilePath = resourceUri.LocalPath + resInfo.MetadataFileExt;
                Uri     metadataUri      = new Uri(metadataFilePath);
                DomNode rootNode         = null;

                if (File.Exists(metadataFilePath))
                {
                    // read existing metadata
                    using (FileStream stream = File.OpenRead(metadataFilePath))
                    {
                        var reader = new DomXmlReader(m_schemaLoader);
                        rootNode = reader.Read(stream, metadataUri);
                    }
                }
                else
                {
                    rootNode = resInfo.CreateNode();
                    rootNode.SetAttribute(Schema.resourceMetadataType.uriAttribute, resourceUri);
                }

                rootNode.InitializeExtensions();
                ResourceMetadataDocument document = rootNode.Cast <ResourceMetadataDocument>();
                document.Uri = metadataUri;
                rootNodes.Add(rootNode);
            }
            return(rootNodes);
        }
        public TestDataValidator()
        {
            m_childType  = new DomNodeType("child");
            m_parentType = new DomNodeType("parent");
            m_parentType.Define(new ExtensionInfo <ValidationContext>());
            m_parentType.Define(new ExtensionInfo <DataValidator>());

            m_childCountRule = new ChildCountRule(2, 3);
            m_childInfo      = new ChildInfo("child", m_childType, true);
            m_parentType.Define(m_childInfo);
            m_childInfo.AddRule(m_childCountRule);

            m_parent = new DomNode(m_parentType);
            m_parent.InitializeExtensions();

            m_validationContext = m_parent.As <ValidationContext>();

            m_child1 = new DomNode(m_childType);
            m_child2 = new DomNode(m_childType);
            m_child3 = new DomNode(m_childType);
            m_child4 = new DomNode(m_childType);
        }
Example #22
0
        public TestDataValidator()
        {
            m_childType = new DomNodeType("child");
            m_parentType = new DomNodeType("parent");
            m_parentType.Define(new ExtensionInfo<ValidationContext>());
            m_parentType.Define(new ExtensionInfo<DataValidator>());

            m_childCountRule = new ChildCountRule(2, 3);
            m_childInfo = new ChildInfo("child", m_childType, true);
            m_parentType.Define(m_childInfo);
            m_childInfo.AddRule(m_childCountRule);

            m_parent = new DomNode(m_parentType);
            m_parent.InitializeExtensions();

            m_validationContext = m_parent.As<ValidationContext>();

            m_child1 = new DomNode(m_childType);
            m_child2 = new DomNode(m_childType);
            m_child3 = new DomNode(m_childType);
            m_child4 = new DomNode(m_childType);
        }
Example #23
0
        public ScriptDocument Open(Uri uri)
        {
            DomNode node     = null;
            string  filePath = uri.LocalPath;

            if (!File.Exists(filePath))
            {
                Outputs.WriteLine(OutputMessageType.Error, "Failed to open source file {0}", filePath);
                return(null);
            }

            // read existing document using standard XML reader
            using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                ScriptReader reader = new ScriptReader(m_nodeDefinitionManager.NodeTypeManager);
                node = reader.Read(stream, uri);
            }

            ScriptDocument scriptDocument = null;

            if (node != null)
            {
                // now that the data is complete, initialize all other extensions to the Dom data
                node.InitializeExtensions();

                scriptDocument = node.Cast <ScriptDocument>();
                string      fileName    = Path.GetFileName(filePath);
                ControlInfo controlInfo = new ControlInfo(fileName, filePath, StandardControlGroup.Center);

                //Set IsDocument to true to prevent exception in command service if two files with the
                //  same name, but in different directories, are opened.
                controlInfo.IsDocument = true;

                scriptDocument.ControlInfo = controlInfo;
                scriptDocument.Uri         = uri;
            }

            return(scriptDocument);
        }
Example #24
0
        public static TerrainGob Create(string name, string hmPath, float cellSize)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(name);
            }

            if (!File.Exists(hmPath))
            {
                throw new ArgumentException(hmPath + " does not exist");
            }

            Uri     ur          = new Uri(hmPath);
            DomNode terrainNode = new DomNode(Schema.terrainGobType.Type);

            terrainNode.SetAttribute(Schema.terrainGobType.cellSizeAttribute, cellSize);
            terrainNode.SetAttribute(Schema.terrainGobType.heightMapAttribute, ur);
            terrainNode.InitializeExtensions();
            TerrainGob terrain = terrainNode.As <TerrainGob>();

            terrain.Name = name;
            return(terrain);
        }
        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");
        }
        public override void OnBeginDrag()
        {
            if (m_hitRegion == HitRegion.None)
            {
                return;
            }

            m_cancelDrag = false;
            Clear(); // cached values.

            var selectionContext   = DesignView.Context.As <ISelectionContext>();
            var selection          = selectionContext.Selection;
            var transactionContext = DesignView.Context.As <ITransactionContext>();

            IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(selection.AsIEnumerable <DomNode>());

            m_duplicating = Control.ModifierKeys == m_duplicateKey;

            if (m_duplicating)
            {
                List <DomNode> originals = new List <DomNode>();
                foreach (DomNode node in rootDomNodes)
                {
                    ITransformable transformable = node.As <ITransformable>();
                    if (!CanManipulate(transformable))
                    {
                        continue;
                    }

                    originals.Add(node);
                }
                if (originals.Count > 0)
                {
                    DomNode[] copies = DomNode.Copy(originals);

                    transactionContext.Begin("Copy And Move".Localize());

                    List <object> newSelection = new List <object>();
                    // re-parent copy
                    for (int i = 0; i < copies.Length; i++)
                    {
                        DomNode copy     = copies[i];
                        DomNode original = originals[i];

                        ChildInfo chInfo = original.ChildInfo;
                        if (chInfo.IsList)
                        {
                            original.Parent.GetChildList(chInfo).Add(copy);
                        }
                        else
                        {
                            original.Parent.SetChild(chInfo, copy);
                        }

                        newSelection.Add(Util.AdaptDomPath(copy));
                        copy.InitializeExtensions();
                    }

                    selectionContext.SetRange(newSelection);
                    NodeList.AddRange(copies.AsIEnumerable <ITransformable>());
                }
            }
            else
            {
                foreach (DomNode node in rootDomNodes)
                {
                    ITransformable transformable = node.As <ITransformable>();
                    if (!CanManipulate(transformable))
                    {
                        continue;
                    }
                    NodeList.Add(transformable);
                }

                if (NodeList.Count > 0)
                {
                    transactionContext.Begin("Move".Localize());
                }
            }

            m_originalValues    = new Vec3F[NodeList.Count];
            m_originalRotations = new Vec3F[NodeList.Count];
            for (int k = 0; k < NodeList.Count; k++)
            {
                ITransformable     node     = NodeList[k];
                IManipulatorNotify notifier = node.As <IManipulatorNotify>();
                if (notifier != null)
                {
                    notifier.OnBeginDrag();
                }
                m_originalValues[k]    = node.Translation;
                m_originalRotations[k] = node.Rotation;
            }
        }
Example #27
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");
        }
Example #28
0
        /// <summary>
        /// Inserts the specified child into the specified parent</summary>
        /// <param name="parent">Parent to insert into</param>
        /// <param name="child">Child to be inserted</param>
        /// <remarks>This method is used by copy-paste and drag-drop from various sources.
        /// When making any changes to this method, please test the following:
        /// - Copy/Paste, Cut/Paste
        /// - Drag-drop from {Palette|ResourceLister} to {ProjectLister|DesignView}
        /// Pay special attention to:
        /// - (GameObjects with) GameObjectReferences
        /// - (GameObjects with) ResourceReferences incl. Locators
        /// - GameObjectGroups (and hierarchies thereof)
        /// - GameObjectFolders (and hierarchies thereof)
        /// - Pasting the same objects more than once</remarks>
        public void Insert(object parent, object child)
        {
            if (!CanInsert(parent, child))
            {
                return;
            }

            var hierarchical = parent.AsAll <IHierarchical>();

            // Extract node list from IDataObject
            IEnumerable <object> items = Util.ConvertData(child, true);

            DomNode parentRoot = null;
            DomNode parentNode = parent.As <DomNode>();

            if (parentNode != null)
            {
                parentRoot = parentNode.GetRoot();
            }

            List <DomNode> copyList   = new List <DomNode>();
            List <object>  objectlist = new List <object>();

            foreach (object item in items)
            {
                if (item.Is <IGameObject>() || item.Is <IGameObjectFolder>())
                {
                    DomNode childNode = item.As <DomNode>();
                    DomNode childRoot = childNode.GetRoot();

                    if ((parentRoot != null && childRoot.Is <IGame>() && parentRoot != childRoot))
                    {
                        childNode.RemoveFromParent();
                        copyList.Add(childNode);
                        continue;
                    }
                }
                objectlist.Add(item);
            }

            if (copyList.Count > 0)
            {
                IEnumerable <DomNode> copies = DomNode.Copy(copyList);
                // remvoe lock
                foreach (DomNode copy in copies)
                {
                    this.SetLocked(copy, false);
                }
                objectlist.AddRange(copies);
            }

            foreach (object obj in objectlist)
            {
                DomNode node = obj.As <DomNode>();
                if (node != null)
                {
                    node.InitializeExtensions();
                }
            }

            List <DomNode> insertedNodes = new List <DomNode>();

            foreach (object obj in objectlist)
            {
                object insertedObj = null;

                bool inserted = false;
                foreach (var h in hierarchical)
                {
                    if (h.AddChild(obj))
                    {
                        inserted = true;
                        break;
                    }
                }

                if (inserted)
                {
                    insertedObj = obj;
                }
                else
                {
                    IResource res = obj as IResource;
                    var       gob = m_resourceConverterService.Convert(res);
                    foreach (var h in hierarchical)
                    {
                        if (h.AddChild(gob))
                        {
                            inserted = true;
                            break;
                        }
                    }
                    if (inserted)
                    {
                        insertedObj = gob;
                    }
                }
                DomNode insertNode = Adapters.As <DomNode>(insertedObj);
                if (insertNode != null)
                {
                    insertedNodes.Add(insertNode);
                }
            }

            IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(insertedNodes);
            List <object>         newSelection = new List <object>();

            foreach (DomNode rootNode in rootDomNodes)
            {
                AdaptablePath <object> path = Util.AdaptDomPath(rootNode);

                if (path.First.Is <IGame>() && (rootNode.Is <IGameObject>() || rootNode.Is <IGameObjectFolder>()))
                {
                    newSelection.Add(path);
                }
            }
            if (newSelection.Count > 0)
            {
                if (InTransaction)
                {
                    m_savedSelection = new List <object>(MasterContext.Selection);
                }

                MasterContext.SetRange(newSelection);
            }
        }
Example #29
0
        public static XLEPlacementDocument OpenUntitled()
        {
            var rootNode = new DomNode(Schema.placementsDocumentType.Type, Schema.placementsDocumentRootElement);

            var doc = rootNode.As<XLEPlacementDocument>();

            // Initialize Dom extensions now that the data is complete
            rootNode.InitializeExtensions();

            var docRegistry = GetDocRegistry(); 
            if (docRegistry != null) docRegistry.Add(doc);
            doc.Dirty = true;
            return doc;
        }
Example #30
0
 public static DecorationMap Create(Uri maskuri)
 {
     DomNode node = new DomNode(Schema.decorationMapType.Type);
     node.SetAttribute(Schema.decorationMapType.maskAttribute, maskuri);
     node.InitializeExtensions();
     DecorationMap map = node.As<DecorationMap>();
     map.Name = "DecorationMap";
     return map;
 }
Example #31
0
        /// <summary>
        /// Clones this control point</summary>
        /// <returns>Cloned control point</returns>
        public IControlPoint Clone()
        {
            DomNode node = new DomNode(UISchema.controlPointType.Type);
            // clone local attributes
            foreach (AttributeInfo attributeInfo in DomNode.Type.Attributes)
            {
                object value = DomNode.GetLocalAttribute(attributeInfo);
                if (value != null)
                    node.SetAttribute(attributeInfo, attributeInfo.Type.Clone(value));
            }

            node.InitializeExtensions();
            return node.As<IControlPoint>();
        }
Example #32
0
        public ManipulatorActiveOperation(
            string name, ISelectionContext selectionContext,
            FilterDelegate filter,
            bool duplicate)
        {
            TransactionContextList = new List <ITransactionContext>();
            NodeList      = new List <ITransformable>();
            IsDuplicating = duplicate;

            var selection = selectionContext.Selection;
            IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(selection.AsIEnumerable <DomNode>());

            SetupTransactionContexts(rootDomNodes);

            if (duplicate)
            {
                List <DomNode> originals = new List <DomNode>();
                foreach (DomNode node in rootDomNodes)
                {
                    ITransformable transformable = node.As <ITransformable>();
                    if (!CanManipulate(transformable, filter))
                    {
                        continue;
                    }

                    originals.Add(node);
                }

                if (originals.Count > 0)
                {
                    DomNode[] copies = DomNode.Copy(originals);

                    foreach (var t in TransactionContextList)
                    {
                        t.Begin(("Copy And" + name).Localize());
                    }

                    List <object> newSelection = new List <object>();
                    // re-parent copy
                    for (int i = 0; i < copies.Length; i++)
                    {
                        DomNode copy     = copies[i];
                        DomNode original = originals[i];

                        ChildInfo chInfo = original.ChildInfo;
                        if (chInfo.IsList)
                        {
                            original.Parent.GetChildList(chInfo).Add(copy);
                        }
                        else
                        {
                            original.Parent.SetChild(chInfo, copy);
                        }

                        newSelection.Add(Util.AdaptDomPath(copy));
                        copy.InitializeExtensions();
                    }

                    selectionContext.SetRange(newSelection);
                    NodeList.AddRange(copies.AsIEnumerable <ITransformable>());
                }
            }
            else
            {
                foreach (DomNode node in rootDomNodes)
                {
                    ITransformable transformable = node.As <ITransformable>();
                    if (!CanManipulate(transformable, filter))
                    {
                        continue;
                    }
                    NodeList.Add(transformable);
                }

                if (NodeList.Count > 0)
                {
                    foreach (var t in TransactionContextList)
                    {
                        t.Begin(name.Localize());
                    }
                }
            }

            for (int k = 0; k < NodeList.Count; k++)
            {
                IManipulatorNotify notifier = NodeList[k].As <IManipulatorNotify>();
                if (notifier != null)
                {
                    notifier.OnBeginDrag();
                }
            }
        }
Example #33
0
File: Curve.cs Project: Joxx0r/ATF
 /// <summary>
 /// Creates a control point</summary>
 /// <returns>Control point</returns>
 public IControlPoint CreateControlPoint()
 {
     DomNode node = new DomNode(UISchema.controlPointType.Type);
     node.InitializeExtensions();
     IControlPoint cpt = node.As<IControlPoint>();
     cpt.TangentInType = CurveTangentTypes.Spline;
     cpt.TangentIn = new Vec2F(0.5f, 0.5f);
     cpt.TangentOutType = CurveTangentTypes.Spline;
     cpt.TangentOut = new Vec2F(0.5f, 0.5f);
     return cpt;
 }
Example #34
0
 /// <summary>
 /// Creates a control point</summary>
 /// <returns>Control point</returns>
 public IControlPoint CreateControlPoint()
 {
     DomNode node = new DomNode(Schema.controlPointType.Type);
     node.InitializeExtensions();
     IControlPoint cpt = node.As<IControlPoint>();
     cpt.Name = "ControlPoint";            
     return cpt;
 }