예제 #1
0
        public int CompareTo(object obj)
        {
            int result = -1;

            try
            {
                GpsMapScenicSpot ss = obj as GpsMapScenicSpot;
                if (ss != null)
                {
                    result = this.Id.CompareTo(ss.Id);
                }
                else
                {
                    result = this.Id.CompareTo(obj);
                }
            }
            catch (Exception ex)
            {
                XxdwDebugger.Log(ex.Message);
            }
            return(result);
        }
예제 #2
0
파일: GpsMap.cs 프로젝트: cyuuu4u/facetrip
        private void DataThreadFunc()
        {
            XxdwDebugger.Log("GpsMap: DataThreadFunc() entering...");
            try
            {
                this.LoadingStatus = SafeStatus.LS_NULL;

                int    pos        = this.mapXmlText.IndexOf("<cells>");
                string strMapData = this.mapXmlText.Substring(0, pos);
                strMapData += "</grid>";
                string strCellAndPathData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<grid>\n";
                strCellAndPathData += this.mapXmlText.Substring(pos);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(new StringReader(strMapData));

                XmlNode node = xmlDoc.SelectSingleNode("/grid/mapName");
                this.name            = (node == null ? "" : node.InnerText.Trim());
                node                 = xmlDoc.SelectSingleNode("/grid/sliceWidth");
                this.sliceWidth      = (node == null ? 0 : int.Parse(node.InnerText.Trim()));
                node                 = xmlDoc.SelectSingleNode("/grid/sliceHeight");
                this.sliceHeight     = (node == null ? 0 : int.Parse(node.InnerText.Trim()));
                node                 = xmlDoc.SelectSingleNode("/grid/triggerDistance");
                this.triggerDistance = (node == null ? 0 : int.Parse(node.InnerText.Trim()));

                node                  = xmlDoc.SelectSingleNode("/grid/pixelWidth");
                this.pixelWidth       = int.Parse(node.InnerText.Trim());
                node                  = xmlDoc.SelectSingleNode("/grid/pixelHeight");
                this.pixelHeight      = int.Parse(node.InnerText.Trim());
                node                  = xmlDoc.SelectSingleNode("/grid/gridCellPixelNum");
                this.gridCellPixelNum = int.Parse(node.InnerText.Trim());
                this.rowNum           = this.pixelHeight / this.gridCellPixelNum;
                this.colNum           = this.pixelWidth / this.gridCellPixelNum;

                this.mapRange = new Rect(-(float)this.PixelWidth / 2 / UNIT_PIXEL_NUM,
                                         -(float)this.pixelHeight / 2 / UNIT_PIXEL_NUM,
                                         (float)this.PixelWidth / UNIT_PIXEL_NUM,
                                         (float)this.PixelHeight / UNIT_PIXEL_NUM);
                XxdwDebugger.Log("rowNum=" + this.rowNum + "colNum=" + this.colNum
                                 + " mapRange:(" + this.mapRange.xMin + "," + this.mapRange.yMin + "),(" + this.mapRange.xMax + "," + this.mapRange.yMax + ")");

                node = xmlDoc.SelectSingleNode("/grid/rolePositionIndex");
                if (node != null)
                {
                    this.rolePositionIndex = int.Parse(node.InnerText.Trim());
                }

                node = xmlDoc.SelectSingleNode("/grid/gridCellLongitudeDiff");
                this.gridCellLongitudeDiff = float.Parse(node.InnerText.Trim());
                node = xmlDoc.SelectSingleNode("/grid/gridCellLatitudeDiff");
                this.gridCellLatitudeDiff = float.Parse(node.InnerText.Trim());
                node = xmlDoc.SelectSingleNode("/grid/gridCellDistance");
                this.gridCellDistance = float.Parse(node.InnerText.Trim());
                node = xmlDoc.SelectSingleNode("/grid/gridCellDiagonalDistance");
                this.gridCellDiagonalDistance = float.Parse(node.InnerText.Trim());
                node = xmlDoc.SelectSingleNode("/grid/zeroLongitude");
                this.zeroLongitude = float.Parse(node.InnerText.Trim());
                node = xmlDoc.SelectSingleNode("/grid/zeroLatitude");
                this.zeroLatitude = float.Parse(node.InnerText.Trim());

                node                     = xmlDoc.SelectSingleNode("/grid/baseIndex1");
                this.baseIndex1          = int.Parse(node.InnerText.Trim());
                node                     = xmlDoc.SelectSingleNode("/grid/baseIndex2");
                this.baseIndex2          = int.Parse(node.InnerText.Trim());
                node                     = xmlDoc.SelectSingleNode("/grid/basePoint1Longitude");
                this.basePoint1Longitude = float.Parse(node.InnerText.Trim());
                node                     = xmlDoc.SelectSingleNode("/grid/basePoint1Latitude");
                this.basePoint1Latitude  = float.Parse(node.InnerText.Trim());
                node                     = xmlDoc.SelectSingleNode("/grid/basePoint2Longitude");
                this.basePoint2Longitude = float.Parse(node.InnerText.Trim());
                node                     = xmlDoc.SelectSingleNode("/grid/basePoint2Latitude");
                this.basePoint2Latitude  = float.Parse(node.InnerText.Trim());

                this.LoadingStatus |= SafeStatus.LS_INFO_DATA;
                XxdwDebugger.Log("GpsMap: DataThreadFunc(), post NOTI_MAP_INFO_READY");
                AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MAP_INFO_READY, this.LoadingStatus, this.name);

                //--------------------------------------------------------------------------------------
                xmlDoc.Load(new StringReader(strCellAndPathData));

                // read cells of the grid
                this.grid = new GpsMapCell[this.rowNum, this.colNum];

                string      xmlPathPattern = "/grid/cells/r";
                XmlNodeList rows           = xmlDoc.SelectNodes(xmlPathPattern);
                if (rows != null && rows.Count > 0)
                {
                    foreach (XmlNode xn in rows)
                    {
                        int         i    = int.Parse(xn.Attributes["v"].InnerText);
                        XmlNodeList cols = xn.SelectNodes("./c");
                        foreach (XmlNode cell in cols)
                        {
                            int j = int.Parse(cell.Attributes["v"].InnerText);
                            if (!(i >= 0 && i < this.rowNum && j >= 0 && j < this.colNum))
                            {
                                continue;
                            }

                            node = cell.SelectSingleNode("./t");
                            int type = int.Parse(node.InnerText.Trim());

                            node = cell.SelectSingleNode("./d");
                            string data = (node == null ? "" : node.InnerText.Trim());

                            int entryNumber = 0;
                            if ((type & (int)GpsMapCell.EType.EN_CROSS) != 0)
                            {
                                node = cell.SelectSingleNode("./n");
                                if (node != null)
                                {
                                    entryNumber = int.Parse(node.InnerText.Trim());
                                }
                            }

                            this.grid[i, j] = new GpsMapCell(i * this.colNum + j, i, j, (GpsMapCell.EType)type, data, entryNumber);

                            //---------------------------------------------------------------------------------
                            // 触发点,以触发点编号排序插入
                            if ((type & (int)GpsMapCell.EType.EN_MONITOR_POINT) != 0)
                            {
                                node = cell.SelectSingleNode("./d2");
                                if (node != null)
                                {
                                    string   data2       = node.InnerText.Trim();
                                    string[] ssid_number = data2.Split(new char[] { '_' });
                                    if (ssid_number.Length == 2)
                                    {
                                        GpsMapMonitorSpot ms = new GpsMapMonitorSpot(data2, ssid_number[0], i * this.colNum + j);
                                        int index            = this.listMonitorSpots.BinarySearch(ms);
                                        if (index < 0)
                                        {
                                            this.listMonitorSpots.Insert(~index, ms);
                                        }
                                    }
                                    else
                                    {
                                        XxdwDebugger.LogWarning("Invalid monitor spot data at: " + (i * this.colNum + j));
                                    }
                                }
                                else
                                {
                                    XxdwDebugger.LogWarning("Monitor spot without data at: " + (i * this.colNum + j));
                                }
                            }
                        }
                    }
                }

                this.LoadingStatus |= SafeStatus.LS_CELL_DATA;
                XxdwDebugger.Log("GpsMap: DataThreadFunc(), post NOTI_MAP_DATA_READY cell_data ok");
                AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MAP_DATA_READY, this.LoadingStatus, this.name);

                //--------------------------------------------------------------------------------------
                // read the road data of the grid, which will shape a Data Structure of Graph.
                xmlPathPattern = "/grid/edges/e";
                XmlNodeList edges = xmlDoc.SelectNodes(xmlPathPattern);

                if (edges != null && edges.Count > 0)
                {
                    for (int i = 0; i < edges.Count; i++)
                    {
                        node = edges[i].SelectSingleNode("./cl1");
                        int cell1 = int.Parse(node.InnerText.Trim());
                        node = edges[i].SelectSingleNode("./cl2");
                        int cell2 = int.Parse(node.InnerText.Trim());
                        node = edges[i].SelectSingleNode("./w");
                        float weight = float.Parse(node.InnerText.Trim());
                        node = edges[i].SelectSingleNode("./ir");
                        string identifier = node.InnerText.Trim();
                        node = edges[i].SelectSingleNode("./s");
                        string   strSpots = node.InnerText.Trim();
                        string[] sSpots   = strSpots.Split(new char[] { ',' });
                        if (sSpots.Length == 0)
                        {
                            continue;
                        }
                        int[] spots = new int[sSpots.Length];
                        for (int j = 0; j < sSpots.Length; j++)
                        {
                            spots[j] = int.Parse(sSpots[j]);
                        }

                        this.pathGraph.AddEdge(cell1, cell2, weight, spots, identifier, CompareEdgeByRadian);
                    }
                }

                //--------------------------------------------------------------------------------------
                // read the scenic spot data of the grid
                xmlPathPattern = "/grid/scenic_spot/ss";
                XmlNodeList scenicSpots = xmlDoc.SelectNodes(xmlPathPattern);
                this.listScenicSpots.Clear();
                if (scenicSpots != null)
                {
                    foreach (XmlNode xn in scenicSpots)
                    {
                        node = xn.SelectSingleNode("./ir");
                        string identifier = node.InnerText.Trim();
                        node = xn.SelectSingleNode("./en");
                        string cells = node.InnerText.Trim();

                        GpsMapScenicSpot ss = new GpsMapScenicSpot(identifier, cells);
                        int index           = listScenicSpots.BinarySearch(ss);
                        if (index < 0)
                        {
                            this.listScenicSpots.Insert(~index, ss);
                        }
                    }
                }

                //------------------------------------------------------
                this.LoadingStatus |= SafeStatus.LS_PATH_DATA;
                XxdwDebugger.Log("GpsMap: DataThreadFunc(), post NOTI_MAP_DATA_READY path_data ok");
                AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MAP_DATA_READY, this.LoadingStatus, this.name);
            }
            catch (System.Exception ex)
            {
                XxdwDebugger.LogError(ex.Message);
                this.LoadingStatus = SafeStatus.LS_NULL;
            }

            //this.pathGraph.TraverseAllAdjacents();
            XxdwDebugger.Log("GpsMap: DataThreadFunc() leaving...");
        }