Ejemplo n.º 1
0
        //Method to delete a connector
        public void deleteConnector(Connector c)
        {
            var      vm    = DataContext as MainViewModel;
            SnapSpot end   = c.End;
            SnapSpot start = c.Start;

            //Sets the SnapSpots to be not connected
            c.End.IsConnected   = false;
            c.Start.IsConnected = false;
            //Removes the Connector
            vm.Connectors.Remove(c);
            //If that snap is being used elsewhwere it is set back to being connected
            foreach (Connector x in vm.Connectors)
            {
                if (x.Start == start)
                {
                    x.Start.IsConnected = true;
                }
                if (x.End == end)
                {
                    x.End.IsConnected = true;
                }
            }
            updateNodes();
        }
Ejemplo n.º 2
0
        //Button click to create a connector from the selected software node snap to the selected data node
        private void createToConnector_Click(object sender, EventArgs e)
        {
            if (ToSnaps.SelectedItem == null)
            {
                MessageBox.Show("Must Select a Snap");
            }
            else
            {
                string n1name = outputBox.SelectedItem.ToString();
                Node   n1     = v.Nodes[0];
                for (int i = 0; i < v.Nodes.Count; i++)
                {
                    if (v.Nodes[i].Name == n1name)
                    {
                        n1 = v.Nodes[i];
                        break;
                    }
                }
                string n2name = inputBox.SelectedItem.ToString();
                Node2  n2     = v.Nodes2[0];
                for (int i = 0; i < v.Nodes2.Count; i++)
                {
                    if (v.Nodes2[i].Name == n2name)
                    {
                        n2 = v.Nodes2[i];
                        break;
                    }
                }
                var      vm    = v.DataContext as MainViewModel;
                SnapSpot snapA = n1.OutSnaps[ToSnaps.SelectedItem.ToString()];
                SnapSpot snapB = n2.Snaps[0];

                //Constructor to make the connector
                vm.customConnectorToData(snapA, snapB);
            }
            v.updateNodes();
            Close();
        }
Ejemplo n.º 3
0
        /*Button Click method to open a saved file
         * It first uses an Open File Dialog to get the file. It then reads all the lines and creates string[] for connectors, software nodes, and data nodes.
         * Next it uses a switch case based on the number of file lines to  determine which elements exist in the save file
         * Lastly, based on the case, it reads in the relevant information for each data structure and adds them to the screen.
         */
        private void button2_Click(object sender, EventArgs e)
        {
            //clear screen before loading
            x.clearScreen();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //create variables based on the file read in.
                string   filename  = openFileDialog1.FileName;
                string[] filelines = File.ReadAllLines(filename);
                string[] connectors;
                string[] nodes;
                string[] nodes2;
                //Switch case that is used to determine which elements need to be created and added
                switch (filelines.Count())
                {
                //Just Software Nodes
                case 1:
                    nodes = filelines[0].Split('+');
                    for (int i = 0; i < nodes.Length; i++)
                    {
                        string[] nodeString = nodes[i].Split(',');
                        string[] strings    = new string[(nodeString.Length - 3)];
                        for (int j = 0; j < strings.Length; j++)
                        {
                            strings[j] = nodeString[(j + 3)];
                        }

                        var  vm = x.DataContext as MainViewModel;
                        Node n  = vm.CreateNewNode(Convert.ToInt32(nodeString[2]), 10, strings);
                        n.Location.Value = new System.Windows.Point(Convert.ToInt32(nodeString[0]), Convert.ToInt32(nodeString[1]));
                        vm.viewNodes(n);
                        x.updateNodes();
                    }

                    break;

                //Software and Data Nodes
                case 2:
                    nodes = filelines[0].Split('+');
                    for (int i = 0; i < nodes.Length; i++)
                    {
                        string[] nodeString = nodes[i].Split(',');
                        string[] strings    = new string[(nodeString.Length - 3)];
                        for (int j = 0; j < strings.Length; j++)
                        {
                            strings[j] = nodeString[(j + 3)];
                        }

                        var  vm = x.DataContext as MainViewModel;
                        Node n  = vm.CreateNewNode(Convert.ToInt32(nodeString[2]), 10, strings);
                        n.Location.Value = new System.Windows.Point(Convert.ToInt32(nodeString[0]), Convert.ToInt32(nodeString[1]));
                        vm.viewNodes(n);
                        x.updateNodes();
                    }
                    nodes2 = filelines[1].Split('+');
                    for (int i = 0; i < nodes2.Length; i++)
                    {
                        string[] node2String = nodes2[i].Split(',');
                        string[] strings2    = new string[(node2String.Length - 3)];
                        for (int j = 0; j < strings2.Length; j++)
                        {
                            strings2[j] = node2String[(j + 3)];
                        }

                        var   vm = x.DataContext as MainViewModel;
                        Node2 n2 = vm.CreateNewNode2(Convert.ToInt32(node2String[2]), strings2);
                        n2.Location.Value = new System.Windows.Point(Convert.ToInt32(node2String[0]), Convert.ToInt32(node2String[1]));
                        x.updateNodes();
                    }
                    break;

                //Software Nodes, Data Nodes, and Connectors
                case 3:
                    connectors = filelines[2].Split('+');
                    nodes      = filelines[0].Split('+');
                    nodes2     = filelines[1].Split('+');


                    for (int i = 0; i < nodes.Length; i++)
                    {
                        string[] nodeString = nodes[i].Split(',');
                        string[] strings    = new string[(nodeString.Length - 3)];
                        for (int j = 0; j < strings.Length; j++)
                        {
                            strings[j] = nodeString[(j + 3)];
                        }

                        var  vm = x.DataContext as MainViewModel;
                        Node n  = vm.CreateNewNode(Convert.ToInt32(nodeString[2]), 10, strings);
                        n.Location.Value = new System.Windows.Point(Convert.ToInt32(nodeString[0]), Convert.ToInt32(nodeString[1]));
                        vm.viewNodes(n);
                        x.updateNodes();
                    }
                    for (int i = 0; i < nodes2.Length; i++)
                    {
                        string[] node2String = nodes2[i].Split(',');
                        string[] strings2    = new string[(node2String.Length - 3)];
                        for (int j = 0; j < strings2.Length; j++)
                        {
                            strings2[j] = node2String[(j + 3)];
                        }

                        var   vm = x.DataContext as MainViewModel;
                        Node2 n2 = vm.CreateNewNode2(Convert.ToInt32(node2String[2]), strings2);
                        n2.Location.Value = new System.Windows.Point(Convert.ToInt32(node2String[0]), Convert.ToInt32(node2String[1]));
                        x.updateNodes();
                    }


                    for (int i = 0; i < connectors.Length; i++)
                    {
                        var      vm       = x.DataContext as MainViewModel;
                        string[] conSplit = connectors[i].Split(',');
                        if (conSplit[0] == "N2")
                        {
                            Node2 n2 = vm.Nodes2[0];
                            for (int n = 0; n < vm.Nodes2.Count; n++)
                            {
                                if (vm.Nodes2[n].Name == conSplit[1])
                                {
                                    n2 = vm.Nodes2[n];
                                    break;
                                }
                            }
                            SnapSpot snapA = n2.Snaps[1];
                            Node     n1    = vm.Nodes[0];
                            for (int n = 0; n < vm.Nodes.Count; n++)
                            {
                                if (vm.Nodes[n].Name == conSplit[3])
                                {
                                    n1 = vm.Nodes[n];
                                    break;
                                }
                            }
                            SnapSpot snapB = n1.InSnaps[conSplit[4]];
                            vm.customConnectorFromData(snapA, snapB);
                        }
                        else
                        {
                            Node n1 = vm.Nodes[0];
                            for (int n = 0; n < vm.Nodes.Count; n++)
                            {
                                if (vm.Nodes[n].Name == conSplit[1])
                                {
                                    n1 = vm.Nodes[n];
                                    break;
                                }
                            }
                            SnapSpot snapA = n1.OutSnaps[conSplit[2]];
                            Node2    n2    = vm.Nodes2[0];
                            for (int n = 0; n < vm.Nodes2.Count; n++)
                            {
                                if (vm.Nodes2[n].Name == conSplit[3])
                                {
                                    n2 = vm.Nodes2[n];
                                    break;
                                }
                            }
                            SnapSpot snapB = n2.Snaps[0];

                            vm.customConnectorToData(snapA, snapB);
                        }
                        x.updateNodes();
                    }
                    break;
                }
            }
            Close();
        }