Esempio n. 1
0
        public void MoveNode(MidgetTreeNode node, MidgetTreeNode newParentNode)
        {
            // retrieve old parent
            MidgetTreeNode oldParentNode = (MidgetTreeNode)node.Parent;

            // make sure not just copying to the parent or reorganizing within the parent
            if(!newParentNode.Equals(node) && !newParentNode.Equals(node.Parent) && oldParentNode != null)
            {

                // if child is becoming the parent of it's parent
                foreach (TreeNode childNode in node.Nodes)
                {
                    if(childNode.Equals(newParentNode))
                    {
                        // clone old child and adjust it's parent
                        newParentNode = (MidgetTreeNode)childNode.Clone();
                        oldParentNode.Nodes.Add(newParentNode);

                        oldParentNode.ExpandAll();

                        // removce old child
                        childNode.Remove();
                        break;
                    }
                }

                // remove node from it's old location
                oldParentNode.Nodes.Remove(node);

                // add the node to it's new parent
                newParentNode.Nodes.Add(node);
                newParentNode.ExpandAll();
            }
        }
Esempio n. 2
0
        public void MoveNode(MidgetTreeNode node, MidgetTreeNode newParentNode)
        {
            // retrieve old parent
            MidgetTreeNode oldParentNode = (MidgetTreeNode)node.Parent;

            // make sure not just copying to the parent or reorganizing within the parent
            if (!newParentNode.Equals(node) && !newParentNode.Equals(node.Parent) && oldParentNode != null)
            {
                // if child is becoming the parent of it's parent
                foreach (TreeNode childNode in node.Nodes)
                {
                    if (childNode.Equals(newParentNode))
                    {
                        // clone old child and adjust it's parent
                        newParentNode = (MidgetTreeNode)childNode.Clone();
                        oldParentNode.Nodes.Add(newParentNode);

                        oldParentNode.ExpandAll();

                        // removce old child
                        childNode.Remove();
                        break;
                    }
                }

                // remove node from it's old location
                oldParentNode.Nodes.Remove(node);

                // add the node to it's new parent
                newParentNode.Nodes.Add(node);
                newParentNode.ExpandAll();
            }
        }
Esempio n. 3
0
        private void EventFactory_ParentChange(object sender, Midget.Events.Object.Relation.ParentChangeEventArgs e)
        {
            // find the parent node
            MidgetTreeNode newParent = FindNode(e.NewParent);

            // add all objects to the scene
            foreach (IObject3D obj in e.Objects)
            {
                treeView.MoveNode(FindNode(obj), newParent);
            }
        }
Esempio n. 4
0
        private void EventFactory_SelectAdditionalObject(object sender, Midget.Events.Object.SingleObjectEventArgs e)
        {
            selectedObjects.Add(e.Object);

            MidgetTreeNode node = FindNode(e.Object);

            if (node != null)
            {
                treeView.SelectedNode = node;
            }
        }
Esempio n. 5
0
        private void EventFactory_Ungroup(object sender, Midget.Events.Object.SingleObjectEventArgs e)
        {
            // move each node to new parent
            MidgetTreeNode groupNode = FindNode(e.Object);

            while (groupNode.Nodes.Count != 0)
            {
                MidgetTreeNode obj = (MidgetTreeNode)groupNode.Nodes[0];
                treeView.MoveNode(FindNode(obj.Object3d), (MidgetTreeNode)groupNode.Parent);
            }
        }
Esempio n. 6
0
        private void EventFactory_DeleteObject(object sender, Midget.Events.Object.MultiObjectEventArgs e)
        {
            foreach (IObject3D obj in e.Objects)
            {
                MidgetTreeNode node = FindNode(obj);

                // if the node hasn't already been deleted
                if (node != null)
                {
                    node.Remove();
                }
            }
        }
Esempio n. 7
0
        private void EventFactory_Group(object sender, Midget.Events.Object.Relation.GroupEventArgs e)
        {
            // add the group
            MidgetTreeNode groupNode = new MidgetTreeNode(e.Group);

            treeView.AddNode(groupNode, FindParentNode(groupNode));

            // add all objects to the scene
            foreach (IObject3D obj in e.Objects)
            {
                treeView.MoveNode(FindNode(obj), groupNode);
            }
        }
Esempio n. 8
0
 private void AddChildren(MidgetTreeNode node)
 {
     // add each element in the scene that belongs to this
     foreach (IObject3D obj in sm.ObjectList)
     {
         // if the node is the object's parent add it to the list
         if(obj.Parent == node.Object3d)
         {
             MidgetTreeNode newNode = new MidgetTreeNode(obj);
             node.Nodes.Add(newNode);
             AddChildren(newNode);
         }
     }
 }
Esempio n. 9
0
        private MidgetTreeNode FindNode(IObject3D obj)
        {
            MidgetTreeNode node = (MidgetTreeNode)treeView.Nodes[0];

            try
            {
                while (node != null)
                {
                    if (node.Object3d.Equals(obj))
                    {
                        return(node);
                    }

                    // try to move first child node
                    if (node.Nodes.Count != 0)
                    {
                        node = (MidgetTreeNode)node.Nodes[0];
                    }
                    // try to go to next sibling
                    else if (node.NextNode != null)
                    {
                        node = (MidgetTreeNode)node.NextNode;
                    }
                    else
                    {
                        node = (MidgetTreeNode)node.Parent;

                        while (node.NextNode == null)
                        {
                            // go to parent node
                            node = (MidgetTreeNode)node.Parent;

                            // if back at top stop
                            if (node == (MidgetTreeNode)treeView.Nodes[0])
                            {
                                return(null);
                            }
                        }

                        node = (MidgetTreeNode)node.NextNode;
                    }
                }
            }
            catch
            {
                return(null);
            }

            return(null);
        }
Esempio n. 10
0
 private void AddChildren(MidgetTreeNode node)
 {
     // add each element in the scene that belongs to this
     foreach (IObject3D obj in sm.ObjectList)
     {
         // if the node is the object's parent add it to the list
         if (obj.Parent == node.Object3d)
         {
             MidgetTreeNode newNode = new MidgetTreeNode(obj);
             node.Nodes.Add(newNode);
             AddChildren(newNode);
         }
     }
 }
Esempio n. 11
0
        private void EventFactory_DeselectObjects(object sender, Midget.Events.Object.SingleObjectEventArgs e)
        {
            selectedObjects.Remove(e.Object);

            if (selectedObjects.Count != 0)
            {
                MidgetTreeNode node = FindNode((IObject3D)selectedObjects[selectedObjects.Count - 1]);

                if (node != null)
                {
                    treeView.SelectedNode = node;
                }
            }
        }
Esempio n. 12
0
        private void InitObjectTree()
        {
            treeView.Nodes.Clear();

            treeView.Nodes.Add(new MidgetTreeNode(sm.Scene));

            // n2 algorithm, not very good but there are never going to be a large number
            // of objects in a scene, if this slows program change algorithm

            for (int i = 0; i < treeView.Nodes.Count; ++i)
            {
                MidgetTreeNode tempNode = (MidgetTreeNode)treeView.Nodes[i];
                AddChildren(tempNode);
            }
        }
Esempio n. 13
0
        private MidgetTreeNode FindParentNode(MidgetTreeNode node)
        {
            MidgetTreeNode parent = (MidgetTreeNode)treeView.Nodes[0];

            while (parent != null)
            {
                if (node.Object3d.Parent.Equals(parent.Object3d))
                {
                    return(parent);
                }

                parent = (MidgetTreeNode)parent.NextVisibleNode;
            }

            return(null);
        }
Esempio n. 14
0
        protected override void OnDragDrop(DragEventArgs drgevent)
        {
            string [] text = drgevent.Data.GetFormats();

            // if the object being dragged can become a treenode
            if (drgevent.Data.GetDataPresent("MidgetUI.MidgetTreeNode", false))
            {
                Point pt = PointToClient(new Point(drgevent.X, drgevent.Y));

                // retrieve the new parent node
                MidgetTreeNode newParentNode = (MidgetTreeNode)GetNodeAt(pt);

                // if you have missed the list drop it under the root node
                if (newParentNode == null)
                {
                    newParentNode = ((MidgetTreeNode)this.Nodes[0]);
                }

                // get newNode location
                MidgetTreeNode node = (MidgetUI.MidgetTreeNode)drgevent.Data.GetData("MidgetUI.MidgetTreeNode");

                // retrieve old parent
                MidgetTreeNode oldParentNode = (MidgetTreeNode)node.Parent;

                // make sure not just copying to the parent or reorganizing within the parent
                if (!newParentNode.Equals(node) && !newParentNode.Equals(node.Parent) && oldParentNode != null)
                {
                    // Issue update request
                    if (NodeMoveRequest != null)
                    {
                        NodeMoveRequest(this, new NodeMoveRequestEventArgs(node, newParentNode));
                    }
                    // no one is listening just do it
                    else
                    {
                        MoveNode(node, newParentNode);
                    }
                }
            }
        }
Esempio n. 15
0
 public void RemoveNode(MidgetTreeNode node)
 {
     node.Remove();
 }
Esempio n. 16
0
 public void AddNode(MidgetTreeNode node, MidgetTreeNode parent)
 {
     parent.Nodes.Add(node);
 }
Esempio n. 17
0
 public void AddNode(MidgetTreeNode node,MidgetTreeNode parent)
 {
     parent.Nodes.Add(node);
 }
Esempio n. 18
0
 public void RemoveNode(MidgetTreeNode node)
 {
     node.Remove();
 }
Esempio n. 19
0
        private MidgetTreeNode FindParentNode(MidgetTreeNode node)
        {
            MidgetTreeNode parent = (MidgetTreeNode)treeView.Nodes[0];

            while(parent != null)
            {
                if(node.Object3d.Parent.Equals(parent.Object3d))
                    return parent;

                parent = (MidgetTreeNode)parent.NextVisibleNode;
            }

            return null;
        }
Esempio n. 20
0
        private void EventFactory_Group(object sender, Midget.Events.Object.Relation.GroupEventArgs e)
        {
            // add the group
            MidgetTreeNode groupNode = new MidgetTreeNode(e.Group);

            treeView.AddNode(groupNode,FindParentNode(groupNode));

            // add all objects to the scene
            foreach(IObject3D obj in e.Objects)
            {
                treeView.MoveNode(FindNode(obj),groupNode);
            }
        }