Exemple #1
0
        /// <summary>
        /// Tree->Screen Selection. If the viewport entities are selected, they get marked as selected straight away.
        /// To check we are considering the correct entities we use the Entity stored in the Tag property of the TreeView
        /// </summary>
        /// <returns>The selected item.</returns>
        /// <param name="tv">The TreeView control</param>
        /// <param name="vl">The ViewportLayout control</param>
        public static ViewportLayout.SelectedItem SynchTreeSelection(TreeView tv, ViewportLayout vl)
        {
            // Fill a stack of entities and blockreferences starting from the node tags.
            Stack <BlockReference> parents = new Stack <BlockReference>();

            TreeNode node   = tv.SelectedNode;
            Entity   entity = node.Tag as Entity;

            node = node.Parent;

            while (node != null)
            {
                var ent = node.Tag as Entity;
                if (ent != null)
                {
                    parents.Push((BlockReference)ent);
                }

                node = node.Parent;
            }

            tv.HideSelection = false;

            // The top most parent is the root Blockreference: must reverse the order, creating a new Stack
            var selItem = new ViewportLayout.SelectedItem(new Stack <BlockReference>(parents), entity);

            // Selects the item
            selItem.Select(vl, true);

            return(selItem);
        }
Exemple #2
0
        private void Selection(MouseClickType mouseClickType)
        {
            if (_treeModify)
            {
                return;
            }

            _treeModify = true;

            if (mouseClickType == MouseClickType.RightClick)
            {
                // Sets the parent of the current BlockReference as current.
                viewportLayout1.Entities.SetParentAsCurrent();
            }
            else
            {
                // Deselects the previously selected item
                if (lastSelectedItem != null)
                {
                    lastSelectedItem.Select(viewportLayout1, false);
                    lastSelectedItem = null;
                }

                var item = viewportLayout1.GetItemUnderMouseCursor(_mousePosition);

                if (item != null)
                {
                    lastSelectedItem = item;

                    TreeViewManager.CleanCurrent(viewportLayout1, false);

                    // Marks as selected the entity under the mouse cursor.
                    item.Select(viewportLayout1, true);
                }
                else
                {
                    // Back to the root level
                    if (mouseClickType == MouseClickType.LeftDoubleClick)
                    {
                        TreeViewManager.CleanCurrent(viewportLayout1);
                    }
                }
            }

            // An entity in the viewport was selected, so we highlight the corresponding element in the treeview as well
            TreeViewManager.SynchScreenSelection(modelTree, new Stack <BlockReference>(viewportLayout1.Entities.CurrentBlockReferences), lastSelectedItem);

            viewportLayout1.Invalidate();

            _treeModify = false;
        }
Exemple #3
0
        private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (_treeModify)
            {
                return;
            }

            _treeModify = true;

            //An element of the treeview was selected, so we select the corresponding viewport element as well

            if (lastSelectedItem != null)
            {
                lastSelectedItem.Select(viewportLayout1, false);
            }

            TreeViewManager.CleanCurrent(viewportLayout1);
            lastSelectedItem = TreeViewManager.SynchTreeSelection(modelTree, viewportLayout1);

            viewportLayout1.Invalidate();

            _treeModify = false;
        }
Exemple #4
0
        /// <summary>
        /// Screen->Tree Selection. To check we are considering the correct entities, we use the Entity stored in the Tag property of the TreeView.
        /// </summary>
        /// <param name="tv">The TreeView control</param>
        /// <param name="blockReferences">The block reference stack</param>
        /// <param name="selectedEntity">The selected entity inside a block reference. Can be null when we click on a BlockReference.</param>
        /// <param name="parentTn">The parent TreeNode for searching inside its nodes. Can be null.</param>
        public static void SearchNodeInTree(TreeView tv, Stack <BlockReference> blockReferences, ViewportLayout.SelectedItem selectedEntity, TreeNode parentTn = null)
        {
            if (blockReferences.Count == 0 && selectedEntity == null)
            {
                return;
            }

            TreeNodeCollection tnc = tv.Nodes;

            if (parentTn != null)
            {
                tnc = parentTn.Nodes;
            }

            if (blockReferences.Count > 0)
            {
                // Nested BlockReferences

                BlockReference br = blockReferences.Pop();

                foreach (TreeNode tn in tnc)
                {
                    if (ReferenceEquals(br, tn.Tag))
                    {
                        if (blockReferences.Count > 0)
                        {
                            SearchNodeInTree(tv, blockReferences, selectedEntity, tn);
                        }
                        else
                        {
                            if (selectedEntity != null)
                            {
                                foreach (TreeNode childNode in tn.Nodes)
                                {
                                    if (ReferenceEquals(selectedEntity.Item, childNode.Tag))
                                    {
                                        tv.SelectedNode = childNode;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                tv.SelectedNode = tn;
                            }
                        }

                        return;
                    }
                }
            }
            else
            {
                // Root level

                if (selectedEntity != null)
                {
                    foreach (TreeNode childNode in tnc)
                    {
                        if (ReferenceEquals(selectedEntity.Item, childNode.Tag))
                        {
                            tv.SelectedNode = childNode;
                            break;
                        }
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Screen->Tree Selection.
        /// </summary>
        /// <param name="tv">The TreeView control</param>
        /// <param name="blockReferences">The BlockReference stack</param>
        /// <param name="selectedEntity">The selected entity inside a block reference. Can be null when we click on a BlockReference.</param>
        public static void SynchScreenSelection(TreeView tv, Stack <BlockReference> blockReferences, ViewportLayout.SelectedItem selectedEntity)
        {
            tv.SelectedNode  = null;
            tv.HideSelection = false;

            tv.CollapseAll();

            if (selectedEntity != null && selectedEntity.Parents.Count > 0)
            {
                //// Add the parents of the selectedEntity to the BlockReferences stack

                // Reverse the stack so the one on top is the one at the root of the hierarchy
                var parentsReversed = selectedEntity.Parents.Reverse();

                var cumulativeStack = new Stack <BlockReference>(blockReferences);

                foreach (var br in parentsReversed)
                {
                    cumulativeStack.Push(br);
                }

                // Create a new stack with the reversed order so the one on top is the root.
                blockReferences = new Stack <BlockReference>(cumulativeStack);
            }

            SearchNodeInTree(tv, blockReferences, selectedEntity);
        }