Exemplo n.º 1
0
        public void saveYaml()
        {
            if (string.IsNullOrEmpty(Global.projectName))
            {
                MessageBox.Show("Please check the project", "Project Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            //네비 시작점 확인
            if (!checkStart())
            {
                MessageBox.Show("Please check the starting point.", "Start Point Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            //종점 확인
            if (!checkend())
            {
                MessageBox.Show("Please check the end point.", "End Point Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            saveNaviTemp.Clear();

            var startshape = NavinObsDiagram.Instance.Navidiagram.Items.OfType <NaviShape>().Where(x => x.PointType == "0").ToList();

            saveNaviTemp.Add(startshape[0]);
            SetNaviPoistion(startshape[0]);

            //리스트에 시작 끝점이 존재하는지 체크
            if (!checkStartEnd(saveNaviTemp))
            {
                MessageBox.Show("It is not connected from start point to end point.", "End Point Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            //저장을 시작한다.
            System.Windows.Forms.SaveFileDialog save = new System.Windows.Forms.SaveFileDialog();
            save.Title  = "";
            save.Filter = "Yaml file|*.yaml";

            if (save.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                using (new WaitCursor())
                {
                    string      filePath = save.FileName;
                    YamlMapping map      = new YamlMapping();

                    //point 갯수
                    map.Add("size_points", saveNaviTemp.Count);

                    //장애물 갯수
                    List <ObsShape> obsdata = NavinObsDiagram.Instance.Navidiagram.Items.OfType <ObsShape>().ToList();
                    map.Add("size_objects", obsdata.Count);

                    //네비포인트 갯수
                    for (int i = 0; i < saveNaviTemp.Count; i++)
                    {
                        //points0_x
                        string Xkey = "points" + i + "_x";
                        string Ykey = "points" + i + "_y";

                        map.Add(Xkey, saveNaviTemp[i].NaviPointX);
                        map.Add(Ykey, saveNaviTemp[i].NaviPointY);
                    }

                    //장애물 갯수
                    for (int i = 0; i < obsdata.Count; i++)
                    {
                        //x y name comment type
                        //objects0_pos_x

                        string Xkey    = "objects" + obsdata[i].Index.ToString() + "_pos_x";
                        string Ykey    = "objects" + obsdata[i].Index.ToString() + "_pos_y";
                        string NameKey = "objects" + obsdata[i].Index.ToString() + "_name";
                        string commKey = "objects" + obsdata[i].Index.ToString() + "_comment";
                        string typeKey = "objects" + obsdata[i].Index.ToString() + "_type";

                        map.Add(Xkey, obsdata[i].ObsPointX);
                        map.Add(Ykey, obsdata[i].ObsPointY);
                        map.Add(NameKey, Global.getObsCodeName(int.Parse(obsdata[i].PointType)));
                        map.Add(commKey, obsdata[i].Description);
                        map.Add(typeKey, int.Parse(obsdata[i].PointType));
                    }

                    map.Add("wayWidth", float.Parse("2.5000000000000000e+00"));
                    map.Add("nextDirDist", float.Parse("10.00000"));
                    map.Add("nextDirThres", float.Parse("20.00000"));

                    YamlNode node = map;
                    node.ToYamlFile(filePath);

                    MessageBox.Show("yaml file creation is complete.", "Yaml Create.", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }