Пример #1
0
 public void PopulateTree(MyTreeNode MyTreeRoot, TreeView treeView)
 {
     MyTreeRoot.Text = MyTreeRoot.nNode.sNode;
     treeView.Nodes.Clear();
     treeView.Nodes.Add(MyTreeRoot);
     MyTreeRoot.getTreeNodes();
 }
Пример #2
0
        //This makes sure everything has the correct coloring, makes for better overview for signals
        //Also used for text changes (Only connected signal for now)
        private void loadColors(MyTreeNode myRoot)
        {
            //Seek out all signals, and check if they are connected,
            int i = 0;

            foreach (MyTreeNode n in myRoot.Nodes)
            {
                loadColors(n);
                if (n.nNode.GetClass() == "Device")
                {
                    Device d = (Device)n.nNode;
                    foreach (MyTreeNode s in n.Nodes)
                    {
                        Signal sig = (Signal)s.nNode;
                        if (sig.ConnectedSignal != null)
                        {
                            s.ForeColor = System.Drawing.Color.Blue;
                            s.Text      = sig.sNode;
                            s.Text      = s.Text + " :: " + sig.ConnectedSignal.sNode /*+ "." + sig.ConnectedSignal.type*/;
                        }
                        else if (sig.ConnectedSignal == null)
                        {
                            s.ForeColor = System.Drawing.Color.Black;
                            s.Text      = sig.sNode;
                        }
                    }
                }
                i++;
            }
        }
Пример #3
0
        private void saveProjectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string         Path           = "Test.xml";
            SaveFileDialog saveFileDialog = new SaveFileDialog
            {
                InitialDirectory = @"C:\Users\Joris.Bosma.KG\source\repos\TestProject\TestProject\bin\Debug",
                Title            = "Browse XML Files",

                CheckFileExists = true,
                CheckPathExists = true,

                DefaultExt       = "xml",
                Filter           = "xml files (*.xml)|*.xml",
                FilterIndex      = 2,
                RestoreDirectory = true,
            };

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                Path = saveFileDialog.FileName;
            }

            MyTreeNode             treeRoot  = (MyTreeNode)treeView_proj.Nodes[0];
            Node                   root      = treeRoot.nNode;
            DataContractSerializer xs        = new DataContractSerializer(typeof(Node), "Node", "Building", new Type[] { typeof(Device), typeof(Signal) });
            FileStream             txtWriter = new FileStream(Path, FileMode.Create);

            xs.WriteObject(txtWriter, root);

            txtWriter.Close();
        }
Пример #4
0
 public Form3(MyTreeNode myTreeNode, MyTreeNode p)
 {
     TreeNode = myTreeNode;
     pNode    = p;
     InitializeComponent();
     d = (Device)TreeNode.nNode;
 }
Пример #5
0
        private void button3_Click(object sender, EventArgs e)
        {
            //This button adds the selected Node(, device or signal) to the project
            //In the future I want to make this a list instead of just 1 node

            if (addedNode == null)
            {
                return;
            }
            if (addedNode.nNode.GetClass() == "Device")
            {
                Device d = (Device)addedNode.nNode;

                foreach (Object o in clBox.CheckedItems)
                {
                    foreach (Signal s1 in l)
                    {
                        if (o.ToString() == s1.sNode)
                        {
                            d.Signals.Add(s1);
                            MyTreeNode s1t = new MyTreeNode(s1);
                            s1t.Text = s1t.nNode.sNode;
                            addedNode.Nodes.Add(s1t);
                        }
                    }
                }
                addedNode.nNode = d;
            }
            addNodes(addedNode);
            lbl_list.Text = "SELECTED: \n";
        }
Пример #6
0
        private void treeview_Shift(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.NumPad9 || e.KeyCode == Keys.NumPad3)
            {
                TreeView treeView = sender as TreeView;

                MyTreeNode selectedNode = (MyTreeNode)treeView.SelectedNode;
                MyTreeNode cNode        = selectedNode;
                MyTreeNode pNode        = (MyTreeNode)selectedNode.Parent;
                int        i            = selectedNode.Index;

                //change index based on which key is pressed
                if (e.KeyCode == Keys.NumPad9)
                {
                    i--;
                }
                if (e.KeyCode == Keys.NumPad3)
                {
                    i++;
                }

                //Remove old node from tree & data
                selectedNode.Remove();
                pNode.nNode.RemoveNode(selectedNode.nNode);

                //Add the copy to parent with new index
                pNode.Nodes.Insert(i, cNode);
                pNode.nNode.InsertNode(i, cNode.nNode);
                treeView.SelectedNode = cNode;
            }
        }
Пример #7
0
        private void treeView_lib_f2_DoubleClick(object sender, EventArgs e)
        {
            //Sets node as selected node, after this you can also select signals from a device
            //In the future, want to add it to a list instead of just 1 node at a time
            TreeView   treeView      = sender as TreeView;
            MyTreeNode selected_Node = (MyTreeNode)treeView.SelectedNode;

            lbl_list.Text = "SELECTED: \n" + selected_Node.nNode.sNode;
            MyTreeNode newNode = new MyTreeNode(selected_Node.nNode);

            newNode.Text = newNode.nNode.sNode;
            newNode      = (MyTreeNode)selected_Node.Clone();

            if ((pNode.nNode.GetClass() == "Device" && newNode.nNode.GetClass() != "Signal") || (pNode.nNode.GetClass() == "Node" && newNode.nNode.GetClass() == "Signal") || (pNode.nNode.GetClass() == "Signal"))
            {
                return;
            }
            if (newNode.nNode.GetClass() == "Device")
            {
                Device d = (Device)newNode.nNode;
                clBox.Items.Clear();
                foreach (Signal s in d.Signals)
                {
                    l.Add(s);
                    clBox.Items.Add(s.sNode);
                }

                d.Signals.Clear();
                newNode.nNode = d;
                newNode.Nodes.Clear();
            }
            addedNode = newNode;
            Ln.Add(newNode);
        }
Пример #8
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //This will create a completely new node and add it to the project
            string Name    = txtName.Text;
            Node   newNode = new Node(Name);

            if (Name == "")
            {
                return;
            }
            if (radioButton1.Checked == true)
            {
                newNode = new Device(Name);
            }
            else if (radioButton2.Checked == true)
            {
                string type = cboxType.SelectedItem.ToString();
                newNode = new Signal(Name, type);
            }
            MyTreeNode newTreeNode = new MyTreeNode(newNode);

            newTreeNode.Text = newNode.sNode;
            pNode.nNode.AddNode(newNode);
            if ((pNode.nNode.GetClass() == "Device" && newNode.GetClass() != "Signal") || (pNode.nNode.GetClass() == "Node" && newNode.GetClass() == "Signal") || (pNode.nNode.GetClass() == "Signal"))
            {
                return;
            }
            else
            {
                pNode.Nodes.Add(newTreeNode);
            }
            pNode.Expand();
        }
Пример #9
0
        private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string Path = "temp.xml";
            //WRITE DATA TO TEMP FILE
            MyTreeNode             treeRoot  = (MyTreeNode)treeView_proj.Nodes[0];
            Node                   root      = treeRoot.nNode;
            DataContractSerializer xs        = new DataContractSerializer(typeof(Node), "Node", "Building", new Type[] { typeof(Device), typeof(Signal) });
            FileStream             txtWriter = new FileStream(Path, FileMode.Create);

            xs.WriteObject(txtWriter, root);

            txtWriter.Close();

            //READ THAT DATA FROM TEMP
            DataContractSerializer xs2 = new DataContractSerializer(typeof(Node), "Node", "Building", new Type[] { typeof(Device), typeof(Signal) });

            using (Stream reader = new FileStream(Path, FileMode.Open))
                root = (Node)xs2.ReadObject(reader);

            //Console.WriteLine(root.sNode);
            MyTreeNode myTreeRoot = new MyTreeNode(root);

            PopulateTree(myTreeRoot, treeView_proj);
            loadColors(myTreeRoot);
            treeView_proj.Nodes[0].Expand();
        }
Пример #10
0
        public PropertyForm(MyTreeNode p)
        {
            this.pNode = p;
            InitializeComponent();

            this.StartPosition = FormStartPosition.Manual;
            this.Location      = new Point(0, 0);
        }
Пример #11
0
 public Form2(MyTreeNode p)
 {
     this.pNode = p;
     InitializeComponent();
     this.StartPosition        = FormStartPosition.Manual;
     this.Location             = new Point(0, 0);
     treeView_lib_f2.ItemDrag += new ItemDragEventHandler(treeView_lib_f2_ItemDrag);
 }
Пример #12
0
 private void button5_Click(object sender, EventArgs e)
 {
     //ADD THE LIST TO THE PROJECT // THIS MIGHT GET MOVED TO ANOTHER FUNCITON
     foreach (MyTreeNode n in Ln)
     {
         addedNode = n;
         button3_Click(sender, e);
     }
 }
Пример #13
0
        //----------------MAIN-----------------------------------------------------------------------------------------------------------------------------------------------
        private void Form1_Load(object sender, EventArgs e)
        {
            CreateFromXML("proj.xml", treeView_proj);
            // CreateFromXML("lib.xml", treeView_lib);
            // CreateFromXML("proj.xml", treeView_sig);
            // MyTreeNode libTreeRoot = (MyTreeNode)treeView_lib.Nodes[0];
            // Node libRoot = libTreeRoot.nNode;
            MyTreeNode treeRoot = (MyTreeNode)treeView_proj.Nodes[0];
            Node       root     = treeRoot.nNode;

            PopulateSigTree(root);
            loadColors(treeRoot);
        }
Пример #14
0
        private void propertiesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //set sender as toolstrip item to make properties accessable
            ToolStripItem button = sender as ToolStripItem;
            //then ask for the parent and put it in pbutton
            ContextMenuStrip pbutton = (ContextMenuStrip)button.GetCurrentParent();
            //then put the parent's tag into treeview
            TreeView   treeView     = (TreeView)pbutton.Tag;
            MyTreeNode selectedNode = (MyTreeNode)treeView.SelectedNode;
            //Open new form and give the (new) parent node
            Form propForm = new PropertyForm(selectedNode);

            propForm.Show();
        }
Пример #15
0
        private void btnVerwijderen_Click(object sender, EventArgs e)
        {
            //set sender as toolstrip item to make properties accessable
            ToolStripItem button = sender as ToolStripItem;
            //then ask for the parent and put it in pbutton
            ContextMenuStrip pbutton = (ContextMenuStrip)button.GetCurrentParent();
            //then put the parent's tag into treeview
            TreeView   treeView     = (TreeView)pbutton.Tag;
            MyTreeNode selectedNode = (MyTreeNode)treeView.SelectedNode;
            MyTreeNode pNode        = (MyTreeNode)selectedNode.Parent;

            pNode.nNode.RemoveNode(selectedNode.nNode);
            selectedNode.Remove();
        }
Пример #16
0
        public void CreateFromXML(string File, TreeView treeView)
        {
            //DESERIALIZER
            DataContractSerializer xs2 = new DataContractSerializer(typeof(Node), "Node", "Building", new Type[] { typeof(Device), typeof(Signal) });
            Node root;

            using (Stream reader = new FileStream(File, FileMode.Open))
                root = (Node)xs2.ReadObject(reader);

            //Console.WriteLine(root.sNode);
            MyTreeNode myTreeRoot = new MyTreeNode(root);

            PopulateTree(myTreeRoot, treeView);
            loadColors(myTreeRoot);
        }
Пример #17
0
        private MyTreeNode SearchNode(string SearchText, MyTreeNode StartNode)
        {
            MyTreeNode treeNode = new MyTreeNode(StartNode.nNode);

            treeNode.Text = treeNode.nNode.sNode;
            if (StartNode == null)
            {
                return(treeNode);
            }
            foreach (MyTreeNode n in StartNode.Nodes)
            {
                SearchNode(SearchText, n);
                if (n.Text.ToLower().Contains(SearchText.ToLower()))
                {
                    MyTreeNode cl = (MyTreeNode)n.Clone();
                    treeNode.Nodes.Add(cl);
                }
            }
            return(treeNode);
        }
Пример #18
0
 public void getTreeNodes()
 {
     if (this.nNode.GetClass() == "Device")
     {
         Device d = (Device)this.nNode;
         foreach (Signal s in d.Signals)
         {
             MyTreeNode a = new MyTreeNode(s);
             a.Text = a.nNode.sNode;
             this.Nodes.Add(a);
         }
     }
     foreach (Node n in this.nNode.Nodes)
     {
         MyTreeNode a = new MyTreeNode(n);
         a.getTreeNodes();
         a.Text = a.nNode.sNode;
         this.Nodes.Add(a);
     }
 }
Пример #19
0
        private void treeView_lib_f2_DragDrop(object sender, DragEventArgs e)
        {
            TreeView treeView = sender as TreeView;

            // Retrieve the client coordinates of the drop location.
            Point targetPoint = treeView.PointToClient(new Point(e.X, e.Y));

            // Retrieve the node at the drop location.
            MyTreeNode targetNode = (MyTreeNode)treeView.GetNodeAt(targetPoint);

            // Retrieve the node that was dragged.
            MyTreeNode draggedNode = (MyTreeNode)e.Data.GetData(typeof(MyTreeNode));

            // Confirm that the node at the drop location is not
            // the dragged node or a descendant of the dragged node.
            if (targetNode == null)
            {
                targetNode = (MyTreeNode)treeView.Nodes[0];                     //als jij niet op een node sleept, targetNode wordt rootnode
            }
            if (!draggedNode.Equals(targetNode) && !ContainsNode(draggedNode, targetNode))
            {
                // If it is a move operation, remove the node from its current
                // location and add it to the node at the drop location.
                if (e.Effect == DragDropEffects.Move)
                {
                    draggedNode.Remove();
                    targetNode.Nodes.Add(draggedNode);
                }

                // If it is a copy operation, clone the dragged node
                // and add it to the node at the drop location.
                else if (e.Effect == DragDropEffects.Copy)
                {
                    targetNode.Nodes.Add((MyTreeNode)draggedNode.Clone());
                }

                // Expand the node at the location
                // to show the dropped node.
                targetNode.Expand();
            }
        }
Пример #20
0
        public void treeView_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }
            TreeView         treeView    = sender as TreeView;
            ContextMenuStrip contextMenu = rightClickMenu;

            //set the tag of the contextmenu as the current treeview, this is for later use in the button
            contextMenu.Tag = treeView;
            MyTreeNode selected_Node = (MyTreeNode)treeView.GetNodeAt(e.X, e.Y);

            if (selected_Node == null)
            {
                return;
            }
            treeView.SelectedNode          = selected_Node;
            selected_Node.ContextMenuStrip = contextMenu;
            selected_Node.ContextMenuStrip.Show(treeView, new Point(e.X, e.Y));
        }
Пример #21
0
        private void button1_Click(object sender, EventArgs e)
        {
            //ZOEKEN
            Form1 f1 = new Form1();

            f1.CreateFromXML("lib.xml", treeView_lib_f2);
            string search = txtFilter_f2.Text;

            if (search.Count() < 3)
            {
                return;
            }
            MyTreeNode startNode    = (MyTreeNode)treeView_lib_f2.Nodes[0];
            MyTreeNode SelectedNode = SearchNode(search, startNode);

            if (SelectedNode != null)
            {
                treeView_lib_f2.Nodes.Clear();
                treeView_lib_f2.Nodes.Add(SelectedNode);
                treeView_lib_f2.Nodes[0].Expand();
            }
        }
Пример #22
0
 public void PopulateSigTree(Node myRoot)
 {
     foreach (Node n in myRoot.Nodes)
     {
         PopulateSigTree(n);
         if (n.GetClass() == "Device")
         {
             Device     d    = (Device)n;
             MyTreeNode tDev = new MyTreeNode(d);
             foreach (Signal s in d.Signals)
             {
                 if (s.ConnectedSignal == null)
                 {
                     MyTreeNode tSig = new MyTreeNode(s);
                     tSig.Text      = tSig.nNode.sNode;
                     tSig.ForeColor = System.Drawing.Color.Red;
                     tDev.Nodes.Add(tSig);
                 }
             }
             tDev.Text = tDev.nNode.sNode;
             treeView_sig.Nodes.Add(tDev);
         }
     }
 }
Пример #23
0
        private void button2_Click(object sender, EventArgs e)
        {
            //ADD TO LIBRARY
            //pNode becomes the selectedNode from the lib
            MyTreeNode SelectedNode = (MyTreeNode)treeView_lib_f2.SelectedNode;
            string     Name         = txtName.Text;
            Node       newNode      = new Node(Name);

            if (Name == null)
            {
                return;
            }
            if (radioButton1.Checked == true)
            {
                newNode = new Device(Name);
            }
            else if (radioButton2.Checked == true)
            {
                string type = cboxType.SelectedItem.ToString();
                newNode = new Signal(Name, type);
            }
            MyTreeNode newTreeNode = new MyTreeNode(newNode);

            newTreeNode.Text = newNode.sNode;
            SelectedNode.nNode.AddNode(newNode);
            //pNode.nNode.AddNode(newNode);
            if ((SelectedNode.nNode.GetClass() == "Device" && newNode.GetClass() != "Signal") || (SelectedNode.nNode.GetClass() == "Node" && newNode.GetClass() == "Signal") || (SelectedNode.nNode.GetClass() == "Signal"))
            {
                return;
            }
            else
            {
                SelectedNode.Nodes.Add(newTreeNode);
            }
            SelectedNode.Expand();
        }
Пример #24
0
        private void disconnectSignalsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //set sender as toolstrip item to make properties accessable
            ToolStripItem button = sender as ToolStripItem;
            //then ask for the parent and put it in pbutton
            ContextMenuStrip pbutton = (ContextMenuStrip)button.GetCurrentParent();
            //then put the parent's tag into treeview
            TreeView   treeView     = (TreeView)pbutton.Tag;
            MyTreeNode selectedNode = (MyTreeNode)treeView.SelectedNode;

            if (selectedNode.nNode.GetClass() != "Signal")
            {
                return;
            }
            Signal SelectedSig = (Signal)selectedNode.nNode;

            SelectedSig.Disconnnect();
            MyTreeNode treeRoot = (MyTreeNode)treeView_proj.Nodes[0];
            Node       root     = treeRoot.nNode;

            treeView_sig.Nodes.Clear();
            loadColors(treeRoot);
            PopulateSigTree(root);
        }
Пример #25
0
 public void addNodes(MyTreeNode newNode)
 {
     //As is says, it just adds new nodes
     pNode.Nodes.Add(newNode);
     pNode.nNode.AddNode(newNode.nNode);
 }
Пример #26
0
        public void treeView_DragDrop(object sender, DragEventArgs e)
        {
            TreeView treeView = sender as TreeView;

            // Retrieve the client coordinates of the drop location.
            Point targetPoint = treeView.PointToClient(new Point(e.X, e.Y));

            // Retrieve the node at the drop location.
            MyTreeNode targetNode = (MyTreeNode)treeView.GetNodeAt(targetPoint);

            // Retrieve the node that was dragged.
            MyTreeNode draggedNode = (MyTreeNode)e.Data.GetData(typeof(MyTreeNode));

            // Confirm that the node at the drop location is not
            // the dragged node or a descendant of the dragged node.
            if (targetNode == null)
            {
                targetNode = (MyTreeNode)treeView.Nodes[0];                     //als jij niet op een node sleept, targetNode wordt rootnode
            }
            if (!draggedNode.Equals(targetNode) && !ContainsNode(draggedNode, targetNode))
            {
                // If it is a move operation, remove the node from its current
                // location and add it to the node at the drop location.
                if (e.Effect == DragDropEffects.Move)
                {
                    if (targetNode.nNode.GetClass() == "Signal" && draggedNode.nNode.GetClass() == "Signal")
                    {
                        Signal sTarget  = (Signal)targetNode.nNode;
                        Signal sDragged = (Signal)draggedNode.nNode;
                        sTarget.Connect(sDragged);

                        MyTreeNode t       = (MyTreeNode)targetNode.Parent;
                        Device     parentD = (Device)t.nNode;
                        //System.Console.WriteLine("Connected: "+sTarget.ConnectedSignal.sNode + sDragged.ConnectedSignal.sNode);
                        targetNode.ForeColor  = System.Drawing.Color.Green;
                        draggedNode.ForeColor = System.Drawing.Color.Green;
                        //refresh tree
                        MyTreeNode treeRoot = (MyTreeNode)treeView_proj.Nodes[0];
                        Node       root     = treeRoot.nNode;
                        loadColors(treeRoot);
                        treeView_sig.Nodes.Clear();
                        PopulateSigTree(root);
                        //sTarget.Disconnnect(sDragged);
                        //System.Console.WriteLine("Connected: " + sTarget.ConnectedSignal.sNode + sDragged.ConnectedSignal.sNode);
                    }
                    if ((targetNode.nNode.GetClass() == "Device" && draggedNode.nNode.GetClass() != "Signal") || (targetNode.nNode.GetClass() == "Node" && draggedNode.nNode.GetClass() == "Signal") || (targetNode.nNode.GetClass() == "Signal"))
                    {
                        return;
                    }
                    else
                    {
                        //Remove and Add node in Data
                        MyTreeNode parentNode = (MyTreeNode)draggedNode.Parent;
                        // MyTreeNode cloneNode = (MyTreeNode)draggedNode.Clone();
                        if (parentNode == null)
                        {
                            return;
                        }
                        parentNode.nNode.RemoveNode(draggedNode.nNode);
                        targetNode.nNode.AddNode(draggedNode.nNode);
                        //Remove and Add node in the tree
                        //Always do this after manipulating the data, otherwise the parentNode is not accurate
                        draggedNode.Remove();
                        targetNode.Nodes.Add(draggedNode); //Put dragged node on top (bottom is default)
                    }
                }
                // Expand the node at the location
                // to show the dropped node.
                targetNode.Expand();
            }
        }