Example #1
0
 //Button click for populating the available SnapSpot names for the selected software node outputs
 private void button1_Click(object sender, EventArgs e)
 {
     ToSnaps.Items.Clear();
     if (outputBox.SelectedItem == null || inputBox.SelectedItem == null)
     {
         MessageBox.Show("Must make an input and output selection for connector");
     }
     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;
             }
         }
         foreach (var item in n1.OutSnaps)
         {
             if (item.Value.IsConnected == false)
             {
                 ToSnaps.Items.Add(item.Value.Name);
             }
         }
         n1.RecalculateSnaps();
     }
 }
Example #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();
        }
Example #3
0
        //Deletes the selected element
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var              vm         = DataContext as MainViewModel;
            Node             n          = vm.SelectedObject as Node;
            List <Connector> connectors = vm.Connectors.ToList();

            if (n == null)
            {
            }
            //Deletes a Software Node
            else
            {
                //Deletes its input SnapSpots
                foreach (SnapSpot s in n.InSnaps.Values)
                {
                    if (s.IsConnected)
                    {
                        foreach (Connector connector in connectors)
                        {
                            if (connector.End == s)
                            {
                                //deletes the connector
                                deleteConnector(connector);
                            }
                        }
                    }
                    //removes snaps
                    vm.Snaps.Remove(s);
                }
                connectors = vm.Connectors.ToList();
                //deletes it output SnapSpots
                foreach (SnapSpot s in n.OutSnaps.Values)
                {
                    if (s.IsConnected)
                    {
                        foreach (Connector connector in connectors)
                        {
                            if (connector.Start == s)
                            {
                                //deletes the connector
                                deleteConnector(connector);
                            }
                        }
                    }
                    //removes snaps
                    vm.Snaps.Remove(s);
                }
                //removes the software node
                vm.Nodes.Remove(n);
                updateNodes();
            }

            Node2 n2 = vm.SelectedObject as Node2;

            if (n2 == null)
            {
            }
            //Deleting a Data Node
            else
            {
                foreach (SnapSpot s in n2.Snaps)
                {
                    if (s.IsConnected)
                    {
                        foreach (Connector connector in connectors)
                        {
                            if (connector.Start == s || connector.End == s)
                            {
                                //deletes Connectors
                                deleteConnector(connector);
                            }
                        }
                    }
                    //Removes snaps
                    vm.Snaps.Remove(s);
                }
                //removes Data Node
                vm.Nodes2.Remove(n2);
            }

            Connector c = vm.SelectedObject as Connector;

            if (c == null)
            {
            }
            //deleting connector
            else
            {
                //deletes connector
                deleteConnector(c);
            }
            updateNodes();
        }
Example #4
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();
        }