Beispiel #1
0
        protected ITransformable GetManipulatorNode(TransformationTypes xformType)
        {
            ITransformable manipNode         = null;
            var            selectionCntx     = DesignView.Context.As <ISelectionContext>();
            var            visibilityContext = DesignView.Context.As <IVisibilityContext>();

            if (selectionCntx.LastSelected != null)
            {
                Path <object> path = selectionCntx.LastSelected.As <Path <object> >();
                foreach (object obj in path)
                {
                    DomNode pathnode = obj.As <DomNode>();
                    if (pathnode == null)
                    {
                        break;
                    }
                    object item = Util.AdaptDomPath(pathnode);
                    if (selectionCntx.SelectionContains(item))
                    {
                        var xformable = pathnode.As <ITransformable>();
                        if (xformable != null &&
                            (xformable.TransformationType & xformType) != 0 &&
                            visibilityContext.IsVisible(pathnode))
                        {
                            manipNode = xformable;
                        }
                        break;
                    }
                }
            }
            return(manipNode);
        }
Beispiel #2
0
        /// <summary>
        /// Does the specified command</summary>
        /// <param name="commandTag">Command</param>
        void ICommandClient.DoCommand(object commandTag)
        {
            ITransactionContext transactionContext = m_selectionContext.As <ITransactionContext>();

            if (transactionContext == null)
            {
                return;
            }

            switch ((StandardCommand)commandTag)
            {
            case StandardCommand.EditGroup:
                transactionContext.DoTransaction(delegate
                {
                    IGameObjectGroup group = Group(SelectedGobs);
                    m_selectionContext.Set(Util.AdaptDomPath(group.As <DomNode>()));
                }, "Group".Localize());
                break;

            case StandardCommand.EditUngroup:
                transactionContext.DoTransaction(delegate
                {
                    IEnumerable <IGameObject> gobs = Ungroup(SelectedGobs);
                    List <object> newselection     = new List <object>();
                    foreach (var gob in gobs)
                    {
                        newselection.Add(Util.AdaptDomPath(gob.As <DomNode>()));
                    }
                    m_selectionContext.SetRange(newselection);
                }, "Ungroup".Localize());
                break;
            }
        }
Beispiel #3
0
        private void SelectAllInstances(DomNodeType nodeType)
        {
            ISelectionContext sc = GetSelectionContext();

            if (sc != null)
            {
                List <object> nodes = new List <object>();
                foreach (DomNode node in Util.FindAll(nodeType, true))
                {
                    nodes.Add(Util.AdaptDomPath(node));
                }
                if (nodes.Count > 0)
                {
                    sc.SetRange(nodes);
                }
                else
                {
                    sc.Clear();
                }
            }
        }
        private void SelectAllInstances()
        {
            DomNodeType domNodeType = SelectedNodeType;

            if (domNodeType == null)
            {
                return;
            }

            ISelectionContext selectionContext = SelectionContext;

            if (selectionContext == null)
            {
                return;
            }

            DomNode rootNode = GetRootNode(selectionContext);

            if (rootNode == null)
            {
                return;
            }


            selectionContext.Clear();
            List <Path <object> > newSelection = new List <Path <object> >();

            foreach (DomNode domNode in GetNodesOfType(rootNode, domNodeType))
            {
                newSelection.Add(Util.AdaptDomPath(domNode));
            }
            if (newSelection.Count > 0)
            {
                selectionContext.SetRange(newSelection);
            }
        }
Beispiel #5
0
        protected override IList <object> Pick(MouseEventArgs e)
        {
            bool          multiSelect = DragOverThreshold;
            List <object> paths       = new List <object>();

            Picking.HitRecord[] hits;

            if (multiSelect)
            {// frustum pick
                RectangleF rect    = MakeRect(FirstMousePoint, CurrentMousePoint);
                var        frustum = XLEBridgeUtils.Utils.MakeFrustumMatrix(Utils.AsCameraDesc(Camera), rect, ClientSize);
                hits = Picking.FrustumPick(
                    GameEngine.GetEngineDevice(),
                    Adapter.SceneManager, Adapter.TechniqueContext,
                    frustum, Utils.AsCameraDesc(Camera), ClientSize,
                    Picking.Flags.Objects | Picking.Flags.Helpers);
            }
            else
            {// ray pick
                Ray3F rayW = GetWorldRay(CurrentMousePoint);
                hits = Picking.RayPick(
                    GameEngine.GetEngineDevice(),
                    Adapter.SceneManager, Adapter.TechniqueContext,
                    rayW, Utils.AsCameraDesc(Camera), ClientSize,
                    Picking.Flags.Terrain | Picking.Flags.Objects | Picking.Flags.Helpers);
            }

            if (hits == null)
            {
                return(new List <object>());
            }

            // create unique list of hits
            HashSet <ulong> instanceSet = new HashSet <ulong>();
            var             uniqueHits  = new List <Picking.HitRecord>();

            // build 'path' objects for each hit record.
            foreach (var hit in hits)
            {
                bool added = instanceSet.Add(hit.instanceId);
                if (added)
                {
                    uniqueHits.Add(hit);
                }
            }

            var firstHit = new Picking.HitRecord();


            // build 'path' objects for each hit record.
            foreach (var hit in uniqueHits)
            {
                var nativeIdMapping = Globals.MEFContainer.GetExportedValue <INativeIdMapping>();
                var nobj            = nativeIdMapping.GetAdapter(hit.documentId, hit.instanceId).As <DomNodeAdapter>();
                if (nobj == null)
                {
                    continue;
                }

                DomNode dom     = nobj.DomNode;
                object  hitPath = Util.AdaptDomPath(dom);
                object  obj     = DesignView.PickFilter.Filter(hitPath, e);
                if (obj != null)
                {
                    if (paths.Count == 0)
                    {
                        firstHit = hit;
                    }
                    var newPath = obj as AdaptablePath <object> ?? Util.AdaptDomPath((DomNode)obj);
                    paths.Add(newPath);
                }
            }


            if (multiSelect == false && paths.Count > 0)
            {
                var path = paths[0];
                ISelectionContext selection = DesignView.Context.As <ISelectionContext>();
                ILinear           linear    = path.As <ILinear>();
                if (linear != null &&
                    Control.ModifierKeys == System.Windows.Forms.Keys.Shift &&
                    selection.SelectionContains(path))
                {
                    ITransactionContext trans = DesignView.Context.As <ITransactionContext>();
                    trans.DoTransaction(
                        delegate
                    {
                        linear.InsertPoint(firstHit.index, firstHit.hitPt.X, firstHit.hitPt.Y, firstHit.hitPt.Z);
                    }, "insert control point".Localize()
                        );
                }
            }
            return(paths);
        }
        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;
            }
        }
        protected override IList <object> Pick(MouseEventArgs e)
        {
            bool          multiSelect = DragOverThreshold;
            List <object> paths       = new List <object>();

            HitRecord[] hits;


            if (multiSelect)
            {// frustum pick
                RectangleF rect = MakeRect(FirstMousePoint, CurrentMousePoint);
                hits = GameEngine.FrustumPick(SurfaceId, Camera.ViewMatrix, Camera.ProjectionMatrix, rect);
            }
            else
            {// ray pick
                Ray3F rayW = GetWorldRay(CurrentMousePoint);
                hits = GameEngine.RayPick(Camera.ViewMatrix, Camera.ProjectionMatrix, rayW, false);
            }

            // create unique list of hits
            HashSet <ulong>  instanceSet = new HashSet <ulong>();
            List <HitRecord> uniqueHits  = new List <HitRecord>();

            // build 'path' objects for each hit record.
            foreach (HitRecord hit in hits)
            {
                bool added = instanceSet.Add(hit.instanceId);
                if (added)
                {
                    uniqueHits.Add(hit);
                }
            }

            HitRecord firstHit = new HitRecord();


            // build 'path' objects for each hit record.
            foreach (HitRecord hit in uniqueHits)
            {
                NativeObjectAdapter nobj = GameEngine.GetAdapterFromId(hit.instanceId);
                DomNode             dom  = nobj.DomNode;
                object hitPath           = Util.AdaptDomPath(dom);
                object obj = DesignView.PickFilter.Filter(hitPath, e);
                if (obj != null)
                {
                    if (paths.Count == 0)
                    {
                        firstHit = hit;
                    }
                    var newPath = obj as AdaptablePath <object> ?? Util.AdaptDomPath((DomNode)obj);
                    paths.Add(newPath);
                }
            }


            if (multiSelect == false && paths.Count > 0)
            {
                var path = paths[0];
                ISelectionContext selection = DesignView.Context.As <ISelectionContext>();
                ILinear           linear    = path.As <ILinear>();
                if (linear != null &&
                    Control.ModifierKeys == System.Windows.Forms.Keys.Shift &&
                    selection.SelectionContains(path))
                {
                    ITransactionContext trans = DesignView.Context.As <ITransactionContext>();
                    trans.DoTransaction(
                        delegate
                    {
                        linear.InsertPoint(firstHit.index, firstHit.hitPt.X, firstHit.hitPt.Y, firstHit.hitPt.Z);
                    }, "insert control point".Localize()
                        );
                }
            }
            return(paths);
        }
Beispiel #8
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();
                }
            }
        }
Beispiel #9
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);
            }
        }
Beispiel #10
0
        protected override IEnumerable <object> Pick(MouseEventArgs e)
        {
            bool multiSelect = DragOverThreshold;

            Picking.HitRecord[] hits;
            if (multiSelect)
            {
                RectangleF rect    = MakeRect(FirstMousePoint, CurrentMousePoint);
                var        frustum = XLEBridgeUtils.Utils.MakeFrustumMatrix(Utils.AsCameraDesc(Camera), rect, ClientSize);
                hits = Picking.FrustumPick(
                    GameEngine.GetEngineDevice(),
                    Adapter.SceneManager, Adapter.TechniqueContext,
                    frustum, Utils.AsCameraDesc(Camera), ClientSize,
                    Picking.Flags.Objects | Picking.Flags.Helpers);
            }
            else
            {
                Ray3F rayW = GetWorldRay(CurrentMousePoint);
                hits = Picking.RayPick(
                    GameEngine.GetEngineDevice(),
                    Adapter.SceneManager, Adapter.TechniqueContext,
                    rayW, Utils.AsCameraDesc(Camera), ClientSize,
                    Picking.Flags.Terrain | Picking.Flags.Objects | Picking.Flags.Helpers);
            }

            if (hits == null)
            {
                return(new List <object>());
            }

            // create unique list of hits
            var uniqueHits = new List <DomNode>();

            var             nativeIdMapping = Globals.MEFContainer.GetExportedValue <INativeIdMapping>();
            HashSet <ulong> instanceSet     = new HashSet <ulong>();

            foreach (var hit in hits)
            {
                if (instanceSet.Add(hit.instanceId))
                {
                    var nobj = nativeIdMapping.GetAdapter(hit.documentId, hit.instanceId).As <DomNodeAdapter>();
                    if (nobj != null && nobj.DomNode != null)
                    {
                        uniqueHits.Add(nobj.DomNode);
                    }
                }
            }

            // build 'path' objects for each hit record.
            var paths = new List <AdaptablePath <object> >();

            foreach (var node in uniqueHits)
            {
                var hitPath = Util.AdaptDomPath(node);
                var obj     = DesignView.PickFilter.Filter(hitPath, e);
                if (obj != null)
                {
                    var path = obj as AdaptablePath <object> ?? Util.AdaptDomPath((DomNode)obj);
                    // Prevent the same object from being added multiple times...
                    if (paths.Where(x => x.Last == path.Last).FirstOrDefault() == null)
                    {
                        paths.Add(path);
                    }
                }
            }

            #if false
            if (multiSelect == false && paths.Count > 0 && firstHit != null)
            {
                var path = paths[0];
                ISelectionContext selection = DesignView.Context.As <ISelectionContext>();
                ILinear           linear    = path.As <ILinear>();
                if (linear != null &&
                    Control.ModifierKeys == System.Windows.Forms.Keys.Shift &&
                    selection.SelectionContains(path))
                {
                    ITransactionContext trans = DesignView.Context.As <ITransactionContext>();
                    trans.DoTransaction(
                        delegate
                    {
                        linear.InsertPoint(firstHit.index, firstHit.hitPt.X, firstHit.hitPt.Y, firstHit.hitPt.Z);
                    }, "insert control point".Localize()
                        );
                }
            }
            #endif

            return(paths);
        }