示例#1
0
        protected override void OnDragOver(DragEventArgs drgevent)
        {
            base.OnDragOver(drgevent);
            if (DesignView.Context == null ||
                m_ghosts.Count == 0)
            {
                return;
            }


            Point clientPoint = PointToClient(new Point(drgevent.X, drgevent.Y));
            Ray3F rayw        = GetWorldRay(clientPoint);

            bool shiftPressed = Control.ModifierKeys == Keys.Shift;

            DomNode   hitnode = null;
            HitRecord?hit     = null;

            if (shiftPressed)
            {
                Matrix4F    v    = Camera.ViewMatrix;
                Matrix4F    p    = Camera.ProjectionMatrix;
                HitRecord[] hits = GameEngine.RayPick(v, p, rayw, false);
                foreach (HitRecord ht in hits)
                {
                    hitnode = GameEngine.GetAdapterFromId(ht.instanceId).Cast <DomNode>();

                    bool skip = false;
                    // ignore ghosts
                    foreach (DomNode node in m_ghosts)
                    {
                        if (hitnode == node || hitnode.IsDescendantOf(node))
                        {
                            skip = true;
                            break;
                        }
                    }
                    if (skip)
                    {
                        continue;
                    }
                    hit = ht;
                    break;
                }
            }

            ISnapFilter snapFilter = Globals.MEFContainer.GetExportedValue <ISnapFilter>();
            bool        snap       = (shiftPressed && hit.HasValue);

            foreach (DomNode ghost in m_ghosts)
            {
                HitRecord?hr = (snap && (snapFilter == null || snapFilter.CanSnapTo(ghost, hitnode))) ? hit : null;
                ProjectGhost(ghost, rayw, hr);
            }

            GameLoop.Update();
            GameLoop.Render();
        }
示例#2
0
 /// <summary>
 /// Returns true iff the specified child can be inserted</summary>
 /// <param name="child">Child to be inserted</param>
 /// <returns>True iff the specified child can be inserted</returns>
 public bool CanAddChild(object child)
 {
     if (Adapters.Is <IGameObjectFolder>(child))
     {
         DomNode childNode = Adapters.As <DomNode>(child);
         if (childNode == null || childNode == DomNode || DomNode.IsDescendantOf(childNode))
         {
             return(false);
         }
         return(true);
     }
     return(Adapters.Is <IGameObject>(child));
 }
示例#3
0
        public bool CanInsert(object parent, object child)
        {
            var hierarchical = parent.AsAll <IHierarchical>();

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

            ILockable lockable = parent.As <ILockable>();

            if (lockable != null && lockable.IsLocked)
            {
                return(false);
            }

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

            IEnumerable <object> items = Util.ConvertData(child, false);
            bool canInsert             = false;

            foreach (object item in items)
            {
                DomNode childNode = item as DomNode;
                if (parentNode != null && childNode != null)
                {
                    if ((parentNode.IsDescendantOf(childNode) ||
                         parentNode == childNode ||
                         parentNode == childNode.Parent))
                    {
                        return(false);
                    }
                }
                IResource res = item as IResource;
                var       gob = m_resourceConverterService.Convert(res);

                foreach (var h in hierarchical)
                {
                    if (h.CanAddChild(item) || h.CanAddChild(gob))
                    {
                        canInsert = true;
                        break;
                    }
                }
            }

            return(canInsert);
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
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;
        }
示例#7
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;
        }