private void btnLoadConf_Click(object sender, EventArgs e) { OpenFileDialog openConfFile = new OpenFileDialog(); openConfFile.Title = "Open Conf file"; openConfFile.FileName = ".conf"; openConfFile.Filter = "Conf files (*.conf)|*.conf|All files (*.*)|*.*"; if (openConfFile.ShowDialog() == DialogResult.OK) { initializeMap();//reset the map List<List<int>> nodeNeighborsList = new List<List<int>>(); string confFileName = openConfFile.FileName; XmlDocument confFile = new XmlDocument(); confFile.Load(confFileName); //node info XmlNode NTUTag = confFile.DocumentElement.SelectSingleNode("/NTU"); //get building and floor info XmlNode buildingTag = confFile.SelectSingleNode("/NTU/building"); XmlNode floorTag = confFile.SelectSingleNode("/NTU/floor"); buildingName = buildingTag.InnerText; floorName = floorTag.InnerText; //get the map size info XmlNode widthTag = confFile.SelectSingleNode("/NTU/width"); XmlNode heightTag = confFile.SelectSingleNode("/NTU/height"); string width = widthTag.InnerText; string height = heightTag.InnerText; mainLabel.Text = "width: " + width + ", height: " + height; //initialize sizeOkButton click event buildingTextBox.Text = buildingName; floorTextBox.Text = floorName; sizeWidthTextBox.Text = width; sizeHeightTextBox.Text = height; sizeOKButton.PerformClick(); foreach (XmlNode pointNode in NTUTag.SelectNodes("/NTU/p"))//loop through each point { List<int> neighborIDList = new List<int>();//a list of nodeID of neighbors int id = Convert.ToInt32(pointNode.Attributes["id"].InnerText); string type = pointNode.Attributes["type"].InnerText; string typeValue = pointNode.Attributes["typeValue"].InnerText; int x = Convert.ToInt32(pointNode.Attributes["x"].InnerText); int y = Convert.ToInt32(pointNode.Attributes["y"].InnerText); Node node = new Node(id, x, y); if (type == POINT_TYPE.Normal.ToString()) { node.pointType = Node.POINT_TYPE.Normal; } else if (type == POINT_TYPE.Elevator.ToString()) { node.pointType = Node.POINT_TYPE.Elevator; node.setElevatorGroupNum(int.Parse(typeValue)); } else if (type == POINT_TYPE.Connector.ToString()) { node.pointType = Node.POINT_TYPE.Connector; node.setConnectorName(typeValue); } xArray.Add(x); yArray.Add(y); pointListBox.Items.Add(node.getId() + " (" + x.ToString() + ", " + y.ToString() + ")"); nodeList.Add(node); //get neighbors info string connect = pointNode.Attributes["connect"].InnerText; if (connect != "") { if (connect.Contains(',')) { string[] neighbors = connect.Split(','); for (int i = 0; i < neighbors.Length; i++) { int neighborID = Convert.ToInt32(neighbors[i]); neighborIDList.Add(neighborID); } nodeNeighborsList.Add(neighborIDList); } else { neighborIDList.Add(Convert.ToInt32(connect)); nodeNeighborsList.Add(neighborIDList); } } else { neighborIDList.Add(0); nodeNeighborsList.Add(neighborIDList); } } for (int i = 0; i < nodeNeighborsList.Count; i++) { for (int j = 0; j < nodeNeighborsList[i].Count; j++) { int neighborID = nodeNeighborsList[i][j]; if (neighborID != 0) { setNeighbors(nodeList[i], nodeList[neighborID]); } } } refreshEdgeList(); PointPlot(false, nodeNeighborsList.Count); LinePlot(false); } }
private void btnLoadConf_Click(object sender, EventArgs e) { OpenFileDialog openConfFile = new OpenFileDialog(); openConfFile.Title = "Open Conf file"; openConfFile.FileName = ".conf"; openConfFile.Filter = "Conf files (*.conf)|*.conf|All files (*.*)|*.*"; if (openConfFile.ShowDialog() == DialogResult.OK) { initializeMap();//reset the map List <List <int> > nodeNeighborsList = new List <List <int> >(); string confFileName = openConfFile.FileName; XmlDocument confFile = new XmlDocument(); confFile.Load(confFileName); //node info XmlNode NTUTag = confFile.DocumentElement.SelectSingleNode("/NTU"); //get building and floor info XmlNode buildingTag = confFile.SelectSingleNode("/NTU/building"); XmlNode floorTag = confFile.SelectSingleNode("/NTU/floor"); buildingName = buildingTag.InnerText; floorName = floorTag.InnerText; //get the map size info XmlNode widthTag = confFile.SelectSingleNode("/NTU/width"); XmlNode heightTag = confFile.SelectSingleNode("/NTU/height"); string width = widthTag.InnerText; string height = heightTag.InnerText; mainLabel.Text = "width: " + width + ", height: " + height; //initialize sizeOkButton click event buildingTextBox.Text = buildingName; floorTextBox.Text = floorName; sizeWidthTextBox.Text = width; sizeHeightTextBox.Text = height; sizeOKButton.PerformClick(); foreach (XmlNode pointNode in NTUTag.SelectNodes("/NTU/p")) //loop through each point { List <int> neighborIDList = new List <int>(); //a list of nodeID of neighbors int id = Convert.ToInt32(pointNode.Attributes["id"].InnerText); string type = pointNode.Attributes["type"].InnerText; string typeValue = pointNode.Attributes["typeValue"].InnerText; int x = Convert.ToInt32(pointNode.Attributes["x"].InnerText); int y = Convert.ToInt32(pointNode.Attributes["y"].InnerText); Node node = new Node(id, x, y); if (type == POINT_TYPE.Normal.ToString()) { node.pointType = Node.POINT_TYPE.Normal; } else if (type == POINT_TYPE.Elevator.ToString()) { node.pointType = Node.POINT_TYPE.Elevator; node.setElevatorGroupNum(int.Parse(typeValue)); } else if (type == POINT_TYPE.Connector.ToString()) { node.pointType = Node.POINT_TYPE.Connector; node.setConnectorName(typeValue); } xArray.Add(x); yArray.Add(y); pointListBox.Items.Add(node.getId() + " (" + x.ToString() + ", " + y.ToString() + ")"); nodeList.Add(node); //get neighbors info string connect = pointNode.Attributes["connect"].InnerText; if (connect != "") { if (connect.Contains(',')) { string[] neighbors = connect.Split(','); for (int i = 0; i < neighbors.Length; i++) { int neighborID = Convert.ToInt32(neighbors[i]); neighborIDList.Add(neighborID); } nodeNeighborsList.Add(neighborIDList); } else { neighborIDList.Add(Convert.ToInt32(connect)); nodeNeighborsList.Add(neighborIDList); } } else { neighborIDList.Add(0); nodeNeighborsList.Add(neighborIDList); } } for (int i = 0; i < nodeNeighborsList.Count; i++) { for (int j = 0; j < nodeNeighborsList[i].Count; j++) { int neighborID = nodeNeighborsList[i][j]; if (neighborID != 0) { setNeighbors(nodeList[i], nodeList[neighborID]); } } } refreshEdgeList(); PointPlot(false, nodeNeighborsList.Count); LinePlot(false); } }
private void pictureBox1_Click(object sender, EventArgs e) { if (mapWidth > 0 && mapHeight > 0) { Point clickPoint = pictureBox1.PointToClient(Control.MousePosition); //String myText = String.Format("x: {0}, y: {1}", clickPoint.X, clickPoint.Y); //PointLabel.Text = myText; double pictureBoxWidth = (double)pictureBox1.Size.Width; double pictureBoxHeight = (double)pictureBox1.Size.Height; double clickedX = 0, clickedY = 0; //Get the X and Y of the clicked point --zpx if ((imageWidth / imageHeight) > (pictureBoxWidth / pictureBoxHeight)) { clickedX = (clickPoint.X) / pictureBoxWidth * mapWidth; double offset = (pictureBoxHeight - pictureBoxWidth / imageWidth * imageHeight) / 2; clickedY = (clickPoint.Y - offset) / (pictureBoxHeight - offset * 2) * mapHeight; } else { clickedY = (clickPoint.Y) / pictureBoxHeight * mapHeight; double offset = (pictureBoxWidth - pictureBoxHeight / imageHeight * imageWidth) / 2; clickedX = (clickPoint.X - offset) / (pictureBoxWidth - offset * 2) * mapWidth; } //Get the rounded coordinates of the clicked point --zpx bool flag = false; int x = Convert.ToInt32(clickedX); int y = Convert.ToInt32(clickedY); Node clickedNode = new Node(x, y);//create an object of the clicked node --zpx //add more properties if there pointType is not normal --zpx if (pointType == POINT_TYPE.Elevator) { clickedNode.pointType = Node.POINT_TYPE.Elevator; if (pointTypeValueTextBox.Text != "") { int elevatorGroupNum = int.Parse(pointTypeValueTextBox.Text); clickedNode.setElevatorGroupNum(elevatorGroupNum); } } else if (pointType == POINT_TYPE.Connector) { clickedNode.pointType = Node.POINT_TYPE.Connector; clickedNode.setConnectorName(pointTypeValueTextBox.Text); } /*-----------------------------------------------*/ //Input the points if (pointConfirmed == false) { if (nodeList.Count > 0) { for (int i = 0; i < nodeList.Count; i++) { if ((x == nodeList[i].getX()) && (y == nodeList[i].getY())) { flag = true;//same point, no need to add it to the nodeList --zpx //mainLabel.Text = "You have already added this point!"; pointListBox.SelectedIndex = i; mainLabel.Text = "Id= " + i + " " + "x=" + x + " " + "y=" + y + " nodeListID: " + i; } } } if (flag == false)//different points --zpx { xArray.Add(x); yArray.Add(y); //set the property of the clickedNode --zpx nodeList.Add(clickedNode); clickedNode.setId(nodeList.IndexOf(clickedNode)); //add the item to the pointListBox pointListBox.Items.Add(clickedNode.getId() + " (" + x.ToString() + ", " + y.ToString() + ")"); pointListBox.SelectedIndex = pointListBox.Items.Count - 1; //display the node info --zpx mainLabel.Text = "Id= " + clickedNode.getId() + " " + "x=" + clickedNode.getX() + " " + "y=" + clickedNode.getY(); } } //Input the edges else { if (isIncluded(nodeList, clickedNode) && firstNode == null)//add first node { firstNode = clickedNode; mainLabel.Text = "Please click the second point of the edge."; } else if (isIncluded(nodeList, clickedNode) && firstNode != null)//add second node { secondNode = clickedNode; if (!node1.Equals(node2)) { setNeighbors(node1, node2);//node 1 and 2 are the actual nodes in nodeList refreshEdgeList();//refresh th edge list to ensure that it is synchronized with the x1Index and x2Index firstNode = null; secondNode = null; node1 = null; node2 = null; mainLabel.Text = "Edge added. Please click two points for a new edge."; } else { mainLabel.Text = "Must be connected to different nodes."; node2 = null; secondNode = null; } } else if (removeEdge(clickedNode))//check whether it is in line with any edges, if yes, delete the edge { mainLabel.Text = "Edge removed."; refreshEdgeList(); } else { mainLabel.Text = "Please click the exact position."; } } } }
private void pictureBox1_Click(object sender, EventArgs e) { if (mapWidth > 0 && mapHeight > 0) { Point clickPoint = pictureBox1.PointToClient(Control.MousePosition); //String myText = String.Format("x: {0}, y: {1}", clickPoint.X, clickPoint.Y); //PointLabel.Text = myText; double pictureBoxWidth = (double)pictureBox1.Size.Width; double pictureBoxHeight = (double)pictureBox1.Size.Height; double clickedX = 0, clickedY = 0; //Get the X and Y of the clicked point --zpx if ((imageWidth / imageHeight) > (pictureBoxWidth / pictureBoxHeight)) { clickedX = (clickPoint.X) / pictureBoxWidth * mapWidth; double offset = (pictureBoxHeight - pictureBoxWidth / imageWidth * imageHeight) / 2; clickedY = (clickPoint.Y - offset) / (pictureBoxHeight - offset * 2) * mapHeight; } else { clickedY = (clickPoint.Y) / pictureBoxHeight * mapHeight; double offset = (pictureBoxWidth - pictureBoxHeight / imageHeight * imageWidth) / 2; clickedX = (clickPoint.X - offset) / (pictureBoxWidth - offset * 2) * mapWidth; } //Get the rounded coordinates of the clicked point --zpx bool flag = false; int x = Convert.ToInt32(clickedX); int y = Convert.ToInt32(clickedY); Node clickedNode = new Node(x, y);//create an object of the clicked node --zpx //add more properties if there pointType is not normal --zpx if (pointType == POINT_TYPE.Elevator) { clickedNode.pointType = Node.POINT_TYPE.Elevator; if (pointTypeValueTextBox.Text != "") { int elevatorGroupNum = int.Parse(pointTypeValueTextBox.Text); clickedNode.setElevatorGroupNum(elevatorGroupNum); } } else if (pointType == POINT_TYPE.Connector) { clickedNode.pointType = Node.POINT_TYPE.Connector; clickedNode.setConnectorName(pointTypeValueTextBox.Text); } /*-----------------------------------------------*/ //Input the points if (pointConfirmed == false) { if (nodeList.Count > 0) { for (int i = 0; i < nodeList.Count; i++) { if ((x == nodeList[i].getX()) && (y == nodeList[i].getY())) { flag = true;//same point, no need to add it to the nodeList --zpx //mainLabel.Text = "You have already added this point!"; pointListBox.SelectedIndex = i; mainLabel.Text = "Id= " + i + " " + "x=" + x + " " + "y=" + y + " nodeListID: " + i; } } } if (flag == false)//different points --zpx { xArray.Add(x); yArray.Add(y); //set the property of the clickedNode --zpx nodeList.Add(clickedNode); clickedNode.setId(nodeList.IndexOf(clickedNode)); //add the item to the pointListBox pointListBox.Items.Add(clickedNode.getId() + " (" + x.ToString() + ", " + y.ToString() + ")"); pointListBox.SelectedIndex = pointListBox.Items.Count - 1; //display the node info --zpx mainLabel.Text = "Id= " + clickedNode.getId() + " " + "x=" + clickedNode.getX() + " " + "y=" + clickedNode.getY(); } } //Input the edges else { if (isIncluded(nodeList, clickedNode) && firstNode == null)//add first node { firstNode = clickedNode; mainLabel.Text = "Please click the second point of the edge."; } else if (isIncluded(nodeList, clickedNode) && firstNode != null)//add second node { secondNode = clickedNode; if (!node1.Equals(node2)) { setNeighbors(node1, node2); //node 1 and 2 are the actual nodes in nodeList refreshEdgeList(); //refresh th edge list to ensure that it is synchronized with the x1Index and x2Index firstNode = null; secondNode = null; node1 = null; node2 = null; mainLabel.Text = "Edge added. Please click two points for a new edge."; } else { mainLabel.Text = "Must be connected to different nodes."; node2 = null; secondNode = null; } } else if (removeEdge(clickedNode))//check whether it is in line with any edges, if yes, delete the edge { mainLabel.Text = "Edge removed."; refreshEdgeList(); } else { mainLabel.Text = "Please click the exact position."; } } } }