Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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.";
                    }
                   
                }

            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        private bool removeEdge(Node node)
        {
            double x = node.getX();
            double y = node.getY();

            for (int i = 0; i < x1Array.Count; i++)
            {
                Edge edge = edgeList[i];

                Node node1 = edge.node1;
                Node node2 = edge.node2;
                //Node node1 = nodeList[int.Parse(x1Index[i].ToString())];
                //Node node2 = nodeList[int.Parse(x2Index[i].ToString())];
                double x1 = double.Parse(x1Array[i].ToString());
                double y1 = double.Parse(y1Array[i].ToString());
                double x2 = double.Parse(x2Array[i].ToString());
                double y2 = double.Parse(y2Array[i].ToString());



                if (x1 == x || x2 == x)                                                                                      //check whether they have the same x value
                {
                    if (Math.Abs(x1 - x) <= EDGE_PRECISION && Math.Abs(x2 - x) <= EDGE_PRECISION && (y - y1) * (y - y2) < 0) //if 3 points are almost in line and y is in the middle
                    {
                        x1Array.RemoveAt(i);
                        y1Array.RemoveAt(i);
                        x2Array.RemoveAt(i);
                        y2Array.RemoveAt(i);
                        x1Index.RemoveAt(i);
                        x2Index.RemoveAt(i);

                        btnLoadConf.Text = "[1]," + node1.getId() + ", " + node2.getId();

                        node1.removeNeighbor(node2);
                        node2.removeNeighbor(node1);
                        edgeList.Remove(edge);

                        LinePlot(true);
                        PointPlot(false, pointListBox.SelectedIndex);
                        return(true);
                    }
                }
                else if (y1 == y || y2 == y)
                {
                    if (Math.Abs(y1 - y) <= EDGE_PRECISION && Math.Abs(y2 - y) < EDGE_PRECISION && (x - x1) * (x - x2) < 0)//if 3 points are in line and x is in the middle
                    {
                        x1Array.RemoveAt(i);
                        y1Array.RemoveAt(i);
                        x2Array.RemoveAt(i);
                        y2Array.RemoveAt(i);
                        x1Index.RemoveAt(i);
                        x2Index.RemoveAt(i);

                        btnLoadConf.Text = "[2]," + node1.getId() + ", " + node2.getId();

                        node1.removeNeighbor(node2);
                        node2.removeNeighbor(node1);
                        edgeList.Remove(edge);

                        LinePlot(true);
                        PointPlot(false, pointListBox.SelectedIndex);
                        return(true);
                    }
                }
                else
                {
                    double slope1 = (y1 - y) / (x1 - x);
                    double slope2 = (y2 - y) / (x2 - x);
                    if (Math.Abs((slope1 - slope2) / slope1) < EDGE_SLOP_PRECISION && (x - x1) * (x - x2) < 0 && (y - y1) * (y - y2) < 0)
                    {                                   //similar slope and clickedPoint in the middle
                        x1Array.RemoveAt(i);
                        y1Array.RemoveAt(i);
                        x2Array.RemoveAt(i);
                        y2Array.RemoveAt(i);
                        x1Index.RemoveAt(i);
                        x2Index.RemoveAt(i);

                        btnLoadConf.Text = "[3]," + node1.getId() + ", " + node2.getId();

                        node1.removeNeighbor(node2);
                        node2.removeNeighbor(node1);
                        edgeList.Remove(edge);

                        LinePlot(true);
                        PointPlot(false, pointListBox.SelectedIndex);
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 5
0
        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.";
                    }
                }
            }
        }