//places New Waypoint private void PlaceDot(string name) { WayPointButton waypointDot = new WayPointButton(name, m_data.DrawEllipsAt, WaypointACombo, WaypointBCombo); m_data.AddWaypoint(waypointDot); }
//return waypoint that has been clicked private WayPointButton Select(PointF location) { WayPointButton nothing = null; foreach (WayPointButton wp in m_data.GetWayPointButtons()) { PointF vector = VectorMath.Minus(location, wp.Location); float length = VectorMath.Magnitued(vector); if (length < WayPointButton.Radius + m_data.selectBuffer) { return(wp); } } return(nothing); }
//add clicked waypoint to comboBox private void UpdateComboBox(WayPointButton b) { if (b != null) { if (b.Selected == true) { if (m_data.box == 0) { WaypointACombo.Text = b.Name; m_data.box++; } else if (m_data.box == 1) { WaypointBCombo.Text = b.Name; m_data.box--; } } } }
//adds new waypoint when panel is clicked private void pictureBoxMap_Click(object sender, EventArgs e) { if (e is MouseEventArgs) { WayPointButton temp = Select(m_data.DrawEllipsAt); if (temp == null) { if (m_data.waypoint >= 'Z') { m_data.waypoint = 'a'; } //adds waypoint coordinates to text box WaypointListBox.Items.Add(m_mousePos + ", " + "Waypoint " + m_data.waypoint.ToString() + Environment.NewLine); //adds waypoint letters to combo boxes WaypointACombo.Items.Add("Waypoint " + m_data.waypoint.ToString()); WaypointBCombo.Items.Add("Waypoint " + m_data.waypoint.ToString()); //add Dot PlaceDot("Waypoint " + m_data.waypoint.ToString()); } else { temp.Selected = !temp.Selected; } UpdateComboBox(temp); //refresh picture box panel1.Invalidate(); //increment waypoint letter m_data.waypoint++; } }
//remove specified waypoint public void RemoveWaypoint(WayPointButton b) { m_waypointStorage.Remove(b); }
//adds a waypoint button to waypoint list public void AddWaypoint(WayPointButton b) { m_waypointStorage.Add(b); }
//import text/csv file private void buttonImport_Click(object sender, EventArgs e) { Stream myStream; OpenFileDialog openFileDialog = new OpenFileDialog() { Filter = "txt files (*.txt)| *.txt|All Files(*,*)|*.*", FilterIndex = 2, RestoreDirectory = true }; if (openFileDialog.ShowDialog() == DialogResult.OK) { if ((myStream = openFileDialog.OpenFile()) != null) { ClearAll(); using (StreamReader reader = new StreamReader(myStream)) { //holds x position saved in a line int posX = 0; //holds y position save in a line int posY = 0; // holds the number found in the line this pass int num = 0; //keeps track of the number of passes int pass = 0; while (!reader.EndOfStream) { //check read line to string string text = reader.ReadLine(); //check if the line starts with { if (text.StartsWith("{")) { //copy Whole line to textbox WaypointListBox.Items.Add(text); //add each word between spaces in line to array string[] numbers = text.Split(); //check for numbers foreach (string value in numbers) { //if theres a number in value store it in num if (int.TryParse(value, out num)) { //check if first pass, then save num to pos x if (pass == 0) { posX = num; pass++; } //save num to pos y else { posY = num; pass--; } } } //create buttons in positions given by file WayPointButton button = new WayPointButton("Waypoint " + m_data.waypoint, new Point(posX, posY), WaypointACombo, WaypointBCombo); //reset variables posX = 0; posY = 0; //add waypoints to Waypoint list. m_data.AddWaypoint(button); //add waypoint to combo box's WaypointACombo.Items.Add("Waypoint " + m_data.waypoint); WaypointBCombo.Items.Add("Waypoint " + m_data.waypoint); panel1.Invalidate(); m_data.waypoint++; }//end text starts with { else if (!text.StartsWith("{")) { //add weighted waypoint information to text box if (text.Contains("Waypoint")) { WeightedListBox.Items.Add(text); } } } //variables to store edge PointF start = new PointF(0, 0); PointF end = new PointF(0, 0); string name = null; //loop through items in weighted list box for (int i = 0; i < WeightedListBox.Items.Count; ++i) { //check if item matches a waypoint name store location in start if true foreach (WayPointButton b in m_data.GetWayPointButtons()) { if (WeightedListBox.Items[i].ToString().Contains(b.Name)) { name = b.Name + ", "; start = b.Location; } } //check if item matches waypoint name, store location in end if true foreach (WayPointButton b in m_data.GetWayPointButtons()) { if (WeightedListBox.Items[i].ToString().Contains(b.Name)) { if (name.Contains(b.Name) == false) { name += b.Name; end = b.Location; } } } //if end is not 0,0 create new edge if (end != new PointF(0, 0)) { Edge ed = new Edge(name, start, end); m_data.AddEdge(ed); panel1.Invalidate(); } } }//end stream } myStream.Close(); } }