示例#1
0
文件: Tools.cs 项目: zparr/ATF
        /// <summary>
        /// Finds DomNode with ID in tree containing give DomNode</summary>
        /// <param name="id">ID to find</param>
        /// <param name="domNode">DomNode in tree being searched</param>
        /// <returns>DomNode with ID in tree containing give DomNode</returns>
        public static DomNode FindNode(string id, DomNode domNode)
        {
            if (s_nodeDictionary == null || !s_lastRoot.Equals(domNode.GetRoot()))
            {
                s_nodeDictionary = new Dictionary <string, DomNode>();
                s_lastRoot       = domNode.GetRoot();

                foreach (DomNode node in domNode.GetRoot().Subtree)
                {
                    foreach (AttributeInfo attribute in node.Type.Attributes)
                    {
                        if (attribute.Name == "id")
                        {
                            string value = node.GetAttribute(attribute) as string;
                            if (!String.IsNullOrEmpty(value))
                            {
                                s_nodeDictionary[value] = node;
                            }
                            break;
                        }
                    }
                }
            }

            return(s_nodeDictionary[id]);
        }
示例#2
0
        private void DomNode_AttributeChanged(object sender, AttributeEventArgs e)
        {
            if (IsCircuitItem(e.DomNode, e.DomNode.Parent))
            {
                NotifyObjectChanged(e.DomNode); //required for Layers. http://tracker.ship.scea.com/jira/browse/WWSATF-1389

                // Editing the subgraph may cause changes in the parent graph, such as reordering group pins in a group needs
                // to change the pin indexes of the external edges in the parent graph.
                // Each circuit or group has its own local editing context, and the default TransactionContext implementation
                // only responds to these Dom changes from the adapted DomNode and below.
                // We need to catch changes up in the hierarchy too for proper undo/redo.
                var circuitValidator = DomNode.GetRoot().As <CircuitValidator>();
                if (circuitValidator != null)
                {
                    var transactionContext = circuitValidator.ActiveHistoryContext;
                    if (transactionContext != null && transactionContext != this)
                    {
                        if (transactionContext.DomNode.Ancestry.FirstOrDefault(x => x == e.DomNode.Parent) != null)
                        {
                            if (transactionContext.InTransaction)
                            {
                                transactionContext.AddOperation(new AttributeChangedOperation(e));
#if DEBUG_VERBOSE
                                var parent = transactionContext.DomNode.Ancestry.FirstOrDefault(x => x == e.DomNode.Parent);
                                Trace.TraceInformation("PARENT GRAPH {0} element  {1} -- Attribute {2} changed from  {3} to {4}",
                                                       CircuitUtil.GetDomNodeName(parent), CircuitUtil.GetDomNodeName(e.DomNode), e.AttributeInfo.Name, e.OldValue, e.NewValue);
#endif
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        public static GameObjectReference Create(DomNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (!node.Is <IGameObject>())
            {
                throw new ArgumentException(node.Type.Name + " is not derived from " +
                                            Schema.gameObjectType.Type.Name);
            }

            GameDocument gameDoc = node.GetRoot().As <GameDocument>();

            if (gameDoc == null)
            {
                throw new ArgumentException("node must belong to a document.");
            }

            // create game object reference.
            DomNode             refNode = new DomNode(Schema.gameObjectReferenceType.Type);
            GameObjectReference gobRef  = refNode.As <GameObjectReference>();

            gobRef.SetTarget(node);
            gobRef.UpdateUri();
            return(gobRef);
        }
示例#4
0
        public void TestRootGetRoot()
        {
            DomNodeType type  = new DomNodeType("type");
            DomNode     child = new DomNode(type);

            Assert.AreSame(child.GetRoot(), child);
        }
示例#5
0
        /// <summary>
        /// Inserts a reference to the specified child into the Owner
        /// in the List specified by the ChildInfo property</summary>
        /// <param name="child">Child to be inserted</param>
        public bool AddChild(object child)
        {
            DomNode childNode = child.As <DomNode>();
            bool    isGobRef  = child.Is <IGameObject>() && childNode.GetRoot().Is <IGame>() && m_childInfo.Type == Schema.gameObjectReferenceType.Type;
            bool    isResRef  = ResourceReference.CanReference(m_childInfo.Type, child.As <IResource>());

            DomNode refNode = null;

            if (isGobRef)
            {
                GameObjectReference gobRef = GameObjectReference.Create(childNode);
                refNode = gobRef.Cast <DomNode>();
            }
            else if (isResRef)
            {
                IReference <IResource> resReference =
                    ResourceReference.Create(m_childInfo.Type, child.As <IResource>());
                refNode = resReference.As <DomNode>();
            }

            if (m_childInfo.IsList)
            {
                m_owner.GetChildList(m_childInfo).Add(refNode);
            }
            else
            {
                m_owner.SetChild(m_childInfo, refNode);
            }
            return(true);
        }
        public static GameObjectReference Create(DomNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (!node.Is <IGameObject>())
            {
                throw new ArgumentException(node.Type.Name + " is not derived from " +
                                            Schema.gameObjectType.Type.Name);
            }
            DomNode      rootNode = node.GetRoot();
            GameDocument gameDoc  = rootNode.As <GameDocument>();

            if (gameDoc == null)
            {
                throw new ArgumentException("nod must belong to a document.");
            }


            // create game object reference.
            DomNode             refNode = new DomNode(Schema.gameObjectReferenceType.Type);
            GameObjectReference gobRef  = refNode.As <GameObjectReference>();

            // Create Uri
            Uri ur = new Uri(gameDoc.Uri + "#" + node.GetId());

            refNode.SetAttribute(Schema.gameObjectReferenceType.refAttribute, ur);
            gobRef.m_target = node;
            return(gobRef);
        }
示例#7
0
        /// <summary>
        /// Returns true iff a reference to specified child can be inserted into this slot</summary>
        /// <param name="child">Child to be inserted</param>
        /// <returns>True iff the specified child can be inserted into this slot</returns>
        public bool CanAddChild(object child)
        {
            DomNode childNode = child.As <DomNode>();
            bool    isGobRef  = child.Is <IGameObject>() && childNode.GetRoot().Is <IGame>() && m_childInfo.Type == Schema.gameObjectReferenceType.Type;
            bool    isResRef  = ResourceReference.CanReference(m_childInfo.Type, child.As <IResource>());

            return(isGobRef || isResRef);
        }
示例#8
0
        void ICommandClient.DoCommand(object commandTag)
        {
            if (!(commandTag is Command))
            {
                return;
            }

            switch ((Command)commandTag)
            {
            case Command.AddAmbientSettings:
                ApplicationUtil.Insert(
                    DomNode.GetRoot(), this,
                    new DomNode(Schema.ambientSettingsType.Type),
                    "Add Ambient Settings", null);
                break;

            case Command.AddToneMapSettings:
                ApplicationUtil.Insert(
                    DomNode.GetRoot(), this,
                    new DomNode(Schema.toneMapSettingsType.Type),
                    "Add Tone Map Settings", null);
                break;

            case Command.AddSun:
            {
                // the "Sun" is just a directional light with the name "Sun"
                var sun = new DomNode(Schema.directionalLightType.Type);
                sun.SetAttribute(Schema.envObjectType.nameAttribute, "Sun");
                ApplicationUtil.Insert(DomNode.GetRoot(), this, sun, "Add Sun", null);
                ApplicationUtil.Insert(
                    DomNode.GetRoot(), this,
                    new DomNode(Schema.envUtilityType.Type),
                    "Add Environment Utility", null);
                break;
            }

            case Command.AddAreaLight:
                ApplicationUtil.Insert(
                    DomNode.GetRoot(), this,
                    new DomNode(Schema.areaLightType.Type),
                    "Add Area Light", null);
                break;

            case Command.AddDirectionalLight:
                ApplicationUtil.Insert(
                    DomNode.GetRoot(), this,
                    new DomNode(Schema.directionalLightType.Type),
                    "Add Directional Light", null);
                break;

            case Command.AddShadowSettings:
                ApplicationUtil.Insert(
                    DomNode.GetRoot(), this,
                    new DomNode(Schema.envSettingsType.Type),
                    "Add Environment Settings", null);
                break;
            }
        }
示例#9
0
        /// <summary>
        /// Applies a replacement on the results of the last Query</summary>
        /// <returns>The list of objects on which we just performed a replacement</returns>
        public IEnumerable <object> Replace(object replaceInfo)
        {
            ITransactionContext currentTransaction = null;

            try
            {
                foreach (DomNodeQueryMatch match in m_results)
                {
                    DomNode             domNode        = match.DomNode;
                    ITransactionContext newTransaction = domNode != null?domNode.GetRoot().As <ITransactionContext>() : null;

                    if (newTransaction != currentTransaction)
                    {
                        {
                            if (currentTransaction != null)
                            {
                                currentTransaction.End();
                            }
                            currentTransaction = newTransaction;
                            if (currentTransaction != null)
                            {
                                currentTransaction.Begin(Localizer.Localize("Replace"));
                            }
                        }
                    }
                    // Apply replacement to all match items that predicates came up with on last search
                    foreach (IPredicateInfo predicateInfo in match.PredicateMatchResults.Keys)
                    {
                        predicateInfo.Replace(domNode, match.PredicateMatchResults[predicateInfo], replaceInfo);
                    }
                }
            }
            catch (InvalidTransactionException ex)
            {
                if (currentTransaction != null && currentTransaction.InTransaction)
                {
                    currentTransaction.Cancel();
                }

                if (ex.ReportError)
                {
                    Outputs.WriteLine(OutputMessageType.Error, ex.Message);
                }
            }
            finally
            {
                if (currentTransaction != null && currentTransaction.InTransaction)
                {
                    currentTransaction.End();
                }
            }

            Sce.Atf.Event.Raise(QueryResultsChanged, this, EventArgs.Empty);

            return((IEnumerable <Object>)m_results);
        }
示例#10
0
        public DynamicDomNode(DomNode node)
        {
            if (node == null)
                throw new ArgumentNullException("node");
            m_mgr = node.GetRoot().As<ExpressionManager>();
            if (m_mgr == null)
                throw new ArgumentException("node must be part of circuit");
            m_node = node;

        }
示例#11
0
        private DomNode GetRootNode(object context)
        {
            DomNode domNode = Adapters.As <DomNode>(context);

            if (domNode != null)
            {
                return(domNode.GetRoot());
            }
            return(null);
        }
示例#12
0
        internal Uri GetBaseUri()
        {
            var root = DomNode.GetRoot().As <IResource>();

            if (root != null)
            {
                return(root.Uri);
            }
            return(new Uri(Directory.GetCurrentDirectory().TrimEnd('\\') + "\\"));
        }
示例#13
0
文件: Tools.cs 项目: Joxx0r/ATF
        /// <summary>
        /// Finds DomNode with ID in tree containing give DomNode</summary>
        /// <param name="id">ID to find</param>
        /// <param name="domNode">DomNode in tree being searched</param>
        /// <returns>DomNode with ID in tree containing give DomNode</returns>
        public static DomNode FindNode(string id, DomNode domNode)
        {
            if (s_nodeDictionary == null || !s_lastRoot.Equals(domNode.GetRoot()))
            {
                s_nodeDictionary = new Dictionary<string, DomNode>();
                s_lastRoot = domNode.GetRoot();

                foreach (DomNode node in domNode.GetRoot().Subtree)
                    foreach (AttributeInfo attribute in node.Type.Attributes)
                        if (attribute.Name == "id")
                        {
                            string value = node.GetAttribute(attribute) as string;
                            if (!String.IsNullOrEmpty(value))
                                s_nodeDictionary[value] = node;
                            break;
                        }
            }

            return s_nodeDictionary[id];
        }
示例#14
0
        /// <summary>
        /// Moves the given nodes into a container</summary>
        /// <param name="newParent">New container</param>
        /// <param name="movingObjects">Nodes to move</param>
        void IEditableGraphContainer <Element, Wire, ICircuitPin> .Move(object newParent, IEnumerable <object> movingObjects)
        {
            if (newParent == null)
            {
                newParent = this;
            }

            var movingItems = movingObjects.ToArray();

            var moduleSet    = new HashSet <Element>();
            var movingNodes  = movingItems.AsIEnumerable <Element>().ToArray();
            var newContainer = newParent.Cast <ICircuitContainer>();
            var oldContainer = movingNodes.First().DomNode.Parent.Cast <ICircuitContainer>();

            Debug.Assert(oldContainer != newContainer);


            // all relevant (internal to the old container) edges before the moving
            var internalConnections = new List <Wire>();
            var incomingConnections = new List <Wire>();
            var outgoingConnections = new List <Wire>();

            CircuitUtil.GetSubGraph(oldContainer, movingItems, moduleSet, internalConnections, incomingConnections, outgoingConnections);
            var graphValidator = DomNode.GetRoot().Cast <CircuitValidator>();

            graphValidator.Suspended = true;

            // transfer modules
            foreach (var module in movingNodes)
            {
                oldContainer.Elements.Remove(module);
                newContainer.Elements.Add(module);
            }

            // transfer internal connections (those between grouped modules)
            foreach (Wire connection in internalConnections)
            {
                oldContainer.Wires.Remove(connection);
                newContainer.Wires.Add(connection);
            }

            // locaton transformation of moved modules
            var offset = GetRelativeOffset(oldContainer, newContainer);

            foreach (var module in movingNodes)
            {
                var relLoc = module.Bounds.Location;
                relLoc.Offset(offset);
                module.Bounds = new Rectangle(relLoc, module.Bounds.Size);
            }

            graphValidator.Suspended            = false;
            graphValidator.MovingCrossContainer = true;
        }
示例#15
0
文件: Layer.cs 项目: trizdreaming/XLE
        public bool CanAddChild(object child)
        {
            DomNode domNode = child.As <DomNode>();

            if (domNode.GetRoot() != DomNode.GetRoot())
            {
                return(false);
            }

            return(child.Is <ILayer>() || child.Is <IReference <IGameObject> >() || child.Is <IGameObject>());
        }
示例#16
0
 public DynamicDomNode(DomNode node)
 {
     if (node == null)
     {
         throw new ArgumentNullException("node");
     }
     m_mgr = node.GetRoot().As <ExpressionManager>();
     if (m_mgr == null)
     {
         throw new ArgumentException("node must be part of circuit");
     }
     m_node = node;
 }
示例#17
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);
        }
示例#18
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;
        }
示例#19
0
        /// <summary>
        /// Returns true if context can insert the child object</summary>
        /// <param name="parent">The proposed parent of the object to insert</param>
        /// <param name="insertingObject">Child to insert</param>
        /// <returns>True iff the context can insert the child</returns>
        public bool CanInsert(object parent, object insertingObject)
        {
            if (parent == null)
            {
                parent = m_activeItem ?? this;
            }
            else if (!(parent is LayeringContext) && !(parent is LayerFolder))
            {
                return(false);
            }

            IEnumerable <DomNode> nodes = GetCompatibleNodes((IDataObject)insertingObject);

            if (nodes == null)
            {
                return(false);
            }

            DomNode insertionPoint = parent.As <DomNode>();

            if (insertionPoint == null)
            {
                return(false);
            }

            foreach (DomNode node in nodes)
            {
                // Avoid inserting objects that are not part of the current document
                if (!IsLayerItem(node) || DomNode == null || node.GetRoot() != DomNode.GetRoot())
                {
                    return(false);
                }

                // Don't allow parenting cycles
                foreach (DomNode ancestor in insertionPoint.Lineage)
                {
                    if (node.Equals(ancestor))
                    {
                        return(false);
                    }
                }

                // Don't reparent to same parent
                if (insertionPoint != DomNode && node.Parent == insertionPoint)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#20
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);
        }
示例#21
0
        private static string GetNodeReferenceString(DomNode refNode, DomNode root)
        {
            var id = refNode.GetId();

            // if referenced node is in another resource, prepend URI
            if (!refNode.IsDescendantOf(root))
            {
                var nodeRoot = refNode.GetRoot();
                var resource = nodeRoot.As <IResource>();
                if (resource != null)
                {
                    id = resource.Uri.LocalPath + "#" + id;
                }
            }

            return(id);
        }
示例#22
0
        void ICommandClient.DoCommand(object commandTag)
        {
            if (!(commandTag is Command))
            {
                return;
            }

            switch ((Command)commandTag)
            {
            case Command.AddVegetationSpawnMaterial:
            {
                var mat = VegetationSpawnMaterialItem.Create(GetNextMaterialId());
                ApplicationUtil.Insert(DomNode.GetRoot(), this, mat, "Add Decoration Material", null);
            }
            break;
            }
        }
示例#23
0
        private void CollectInvalidGameObjectReference(IList <DomNode> removeList)
        {
            DomNode rootNode = DomNode;

            foreach (DomNode domNode in rootNode.Subtree)
            {
                GameObjectReference gameObjectReference = domNode.As <GameObjectReference>();
                if (gameObjectReference != null)
                {
                    DomNode targetNode = Adapters.As <DomNode>(gameObjectReference.Target);
                    if (targetNode == null || !targetNode.GetRoot().Is <IGame>())
                    {
                        removeList.Add(gameObjectReference.DomNode);
                    }
                }
            }
        }
示例#24
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;
        }
示例#25
0
        /// <summary>
        /// Converts a node to a string reference when writing DomNode</summary>
        /// <param name="refNode">Node that is referenced</param>
        /// <param name="root">Root node of data that is being written</param>
        /// <param name="uri">URI of data that is being written</param>
        /// <returns>String encoding the reference to the node</returns>
        protected virtual string GetNodeReferenceString(DomNode refNode, DomNode root, Uri uri)
        {
            string id = refNode.GetId();

            // if referenced node is in another resource, prepend URI
            DomNode nodeRoot = refNode.GetRoot();

            if (nodeRoot != root)
            {
                IResource resource = nodeRoot.As <IResource>();
                if (resource != null)
                {
                    id = resource.Uri.LocalPath + "#" + id;
                }
            }

            return(id);
        }
示例#26
0
        /// <summary>
        /// Converts a node to a string reference when writing</summary>
        /// <param name="refNode">Node that is referenced</param>
        /// <param name="root">Root node of data that is being written</param>
        /// <param name="uri">URI of data that is being written</param>
        /// <returns>String encoding the reference to the node</returns>
        protected virtual string GetNodeReferenceString(DomNode refNode, DomNode root, Uri uri)
        {
            string id = refNode.GetId();

            // if referenced node is in another resource, prepend URI
            if (!refNode.IsDescendantOf(root))
            {
                DomNode   nodeRoot = refNode.GetRoot();
                IResource resource = nodeRoot.As <IResource>();
                if (resource != null)
                {
                    Uri relativeUri = uri.MakeRelativeUri(resource.Uri);
                    id = relativeUri + "#" + id;
                }
            }

            return(id);
        }
示例#27
0
        private void DomNode_ChildInserted(object sender, ChildEventArgs e)
        {
            AddNode(e.Child);
            if (IsCircuitItem(e.Child, e.Parent))
            {
                if (e.Child.Is <Wire>())
                {
                    var connection = e.Child.Cast <Wire>();
                    if (connection.InputElement.Is <Group>())  // set dirty to force update group pin connectivity
                    {
                        connection.InputElement.Cast <Group>().Dirty = true;
                    }

                    if (connection.OutputElement.Is <Group>())
                    {
                        connection.OutputElement.Cast <Group>().Dirty = true;
                    }
                }

                OnObjectInserted(new ItemInsertedEventArgs <object>(e.Index, e.Child, e.Parent));

                var circuitValidator = DomNode.GetRoot().As <CircuitValidator>();
                if (circuitValidator != null)
                {
                    var transactionContext = circuitValidator.ActiveHistoryContext;
                    if (transactionContext != null && transactionContext != this)
                    {
                        if (transactionContext.DomNode.Ancestry.FirstOrDefault(x => x == e.Parent) != null)
                        {
                            if (transactionContext.InTransaction)
                            {
                                transactionContext.AddOperation(new ChildInsertedOperation(e));
#if DEBUG_VERBOSE
                                var parent = transactionContext.DomNode.Ancestry.FirstOrDefault(x => x == e.Parent);
                                Trace.TraceInformation("PARENT GRAPH {0} --  Added {1} to parent {2}",
                                                       CircuitUtil.GetDomNodeName(parent), CircuitUtil.GetDomNodeName(e.Child), CircuitUtil.GetDomNodeName(e.Parent));
#endif
                            }
                        }
                    }
                }
            }
        }
示例#28
0
        void ICommandClient.DoCommand(object commandTag)
        {
            if (!(commandTag is Command))
            {
                return;
            }

            switch ((Command)commandTag)
            {
            case Command.AddTerrainTextureMaterial:
            {
                var mat = TerrainBaseTextureMaterial.Create(GetNextMaterialId());
                ApplicationUtil.Insert(
                    DomNode.GetRoot(), this, mat,
                    "Add Terrain Material", null);
            }
            break;
            }
        }
示例#29
0
        private IGame TargetGame()
        {
            var     selection = DesignView.Context.As <ISelectionContext>();
            DomNode node      = selection.GetLastSelected <DomNode>();

            IReference <IGame> gameref = Adapters.As <IReference <IGame> >(node);

            if (gameref != null && gameref.Target != null)
            {
                return(gameref.Target);
            }

            if (node != null)
            {
                return(node.GetRoot().As <IGame>());
            }

            return(DesignView.Context.As <IGame>());
        }
示例#30
0
        public void SelectNameIfNecessary()
        {
            if (Uri == null)
            {
                System.Windows.Forms.MessageBox.Show(
                    "Select a name for the placements document", "Level Editor",
                    System.Windows.Forms.MessageBoxButtons.OK);

                var dlg = new System.Windows.Forms.SaveFileDialog();
                dlg.Filter = "Placement documents (*.plcdoc)|*.plcdoc";
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                var root = DomNode.GetRoot();
                var doc  = root.As <IDocument>();
                Uri          = new Uri(dlg.FileName);
                Target.Dirty = true;
            }
        }
        // adds refs to the tracker, and reports added external refs
        private void AddReference(DomNode owner, AttributeInfo attributeInfo, DomNode target)
        {
            List <Pair <DomNode, AttributeInfo> > referenceList;

            if (!m_nodeReferenceLists.TryGetValue(target, out referenceList))
            {
                referenceList = new List <Pair <DomNode, AttributeInfo> >();
                m_nodeReferenceLists.Add(target, referenceList);
            }
            referenceList.Add(new Pair <DomNode, AttributeInfo>(owner, attributeInfo));

            // if target's root isn't the context's root, then it's an external reference
            //  that is being added.
            DomNode targetRoot = target.GetRoot();

            if (DomNode != targetRoot)
            {
                ReferenceEventArgs e = new ReferenceEventArgs(owner, attributeInfo, target);
                OnExternalReferenceAdded(e);
                ExternalReferenceAdded.Raise(this, e);
            }
        }
示例#32
0
        public void SelectNameIfNecessary()
        {
            if (Uri == null)
            {
                System.Windows.Forms.MessageBox.Show(
                    "Select a name for the placements document", "Level Editor",
                    System.Windows.Forms.MessageBoxButtons.OK);

                var dlg = new System.Windows.Forms.SaveFileDialog();
                dlg.Filter = "Placement documents (*.plcdoc)|*.plcdoc";
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                var root = DomNode.GetRoot();
                var doc  = root.As <IDocument>();
                Uri baseUri;
                if (doc != null && Globals.MEFContainer.GetExportedValue <IDocumentService>().IsUntitled(doc))
                {
                    // This is an untitled document.
                    // We should use the resources root as a base, because the document uri
                    // is unreliable. It's a bit awkward, because it means this method of
                    // uri resolution can't work reliably until the root document has been saved.
                    // (and if the user changes the directory of the root document, does that mean
                    // they want the resource references to be updated, also?)
                    baseUri = Globals.ResourceRoot;
                }
                else
                {
                    baseUri = root.Cast <IResource>().Uri;
                }

                var relURI = baseUri.MakeRelativeUri(new Uri(dlg.FileName));
                RawReference = relURI.OriginalString;
                Target.Dirty = true;
            }
        }
        // removes refs from the tracker, and reports removed external refs
        private void RemoveReference(DomNode owner, AttributeInfo attributeInfo, DomNode target)
        {
            List <Pair <DomNode, AttributeInfo> > referenceList;

            if (m_nodeReferenceLists.TryGetValue(target, out referenceList))
            {
                referenceList.Remove(new Pair <DomNode, AttributeInfo>(owner, attributeInfo));
                if (referenceList.Count == 0)
                {
                    m_nodeReferenceLists.Remove(target);
                }
            }

            // if target's root isn't the context's root, then it's an external reference
            //  that is being removed.
            DomNode targetRoot = target.GetRoot();

            if (DomNode != targetRoot)
            {
                ReferenceEventArgs e = new ReferenceEventArgs(owner, attributeInfo, target);
                OnExternalReferenceRemoved(e);
                ExternalReferenceRemoved.Raise(this, e);
            }
        }
示例#34
0
        private static string GetNodeReferenceString(DomNode refNode, DomNode root)
        {
            var id = refNode.GetId();

            // if referenced node is in another resource, prepend URI
            if (!refNode.IsDescendantOf(root))
            {
                var nodeRoot = refNode.GetRoot();
                var resource = nodeRoot.As<IResource>();
                if (resource != null)
                    id = resource.Uri.LocalPath + "#" + id;
            }

            return id;
        }
示例#35
0
        /// <summary>
        /// Converts a node to a string reference when writing DomNode</summary>
        /// <param name="refNode">Node that is referenced</param>
        /// <param name="root">Root node of data that is being written</param>
        /// <param name="uri">URI of data that is being written</param>
        /// <returns>String encoding the reference to the node</returns>
        protected virtual string GetNodeReferenceString(DomNode refNode, DomNode root, Uri uri)
        {
            string id = refNode.GetId();

            // if referenced node is in another resource, prepend URI
            DomNode nodeRoot = refNode.GetRoot();
            if (nodeRoot != root)
            {
                IResource resource = nodeRoot.As<IResource>();
                if (resource != null)
                    id = resource.Uri.LocalPath + "#" + id;
            }

            return id;
        }
示例#36
0
        // adds refs to the tracker, and reports added external refs
        private void AddReference(DomNode owner, AttributeInfo attributeInfo, DomNode target)
        {
            List<Pair<DomNode, AttributeInfo>> referenceList;
            if (!m_nodeReferenceLists.TryGetValue(target, out referenceList))
            {
                referenceList = new List<Pair<DomNode, AttributeInfo>>();
                m_nodeReferenceLists.Add(target, referenceList);
            }
            referenceList.Add(new Pair<DomNode, AttributeInfo>(owner, attributeInfo));

            // if target's root isn't the context's root, then it's an external reference
            //  that is being added.
            DomNode targetRoot = target.GetRoot();
            if (DomNode != targetRoot)
            {
                ReferenceEventArgs e = new ReferenceEventArgs(owner, attributeInfo, target);
                OnExternalReferenceAdded(e);
                ExternalReferenceAdded.Raise(this, e);

            }
        }
示例#37
0
        /// <summary>
        /// Converts a node to a string reference when writing</summary>
        /// <param name="refNode">Node that is referenced</param>
        /// <param name="root">Root node of data that is being written</param>
        /// <param name="uri">URI of data that is being written</param>
        /// <returns>String encoding the reference to the node</returns>
        protected virtual string GetNodeReferenceString(DomNode refNode, DomNode root, Uri uri)
        {
            string id = refNode.GetId();

            // if referenced node is in another resource, prepend URI
            if (!refNode.IsDescendantOf(root))
            {
                DomNode nodeRoot = refNode.GetRoot();
                IResource resource = nodeRoot.As<IResource>();
                if (resource != null)
                {
                    Uri relativeUri = uri.MakeRelativeUri(resource.Uri);
                    id = relativeUri + "#" + id;
                }
            }

            return id;
        }
示例#38
0
        // removes refs from the tracker, and reports removed external refs
        private void RemoveReference(DomNode owner, AttributeInfo attributeInfo, DomNode target)
        {
            List<Pair<DomNode, AttributeInfo>> referenceList;
            if (m_nodeReferenceLists.TryGetValue(target, out referenceList))
            {
                referenceList.Remove(new Pair<DomNode, AttributeInfo>(owner, attributeInfo));
                if (referenceList.Count == 0)
                {
                    m_nodeReferenceLists.Remove(target);
                }
            }

            // if target's root isn't the context's root, then it's an external reference
            //  that is being removed.
            DomNode targetRoot = target.GetRoot();
            if (DomNode != targetRoot)
            {
                ReferenceEventArgs e = new ReferenceEventArgs(owner, attributeInfo, target);
                OnExternalReferenceRemoved(e);
                ExternalReferenceRemoved.Raise(this, e);
            }
        }
示例#39
0
 public void TestRootGetRoot()
 {
     DomNodeType type = new DomNodeType("type");
     DomNode child = new DomNode(type);
     Assert.AreSame(child.GetRoot(), child);
 }