Ejemplo n.º 1
0
        private async Task LoadPointfile(MapDocument document, string file)
        {
            if (file != null && File.Exists(file))
            {
                var       text = File.ReadAllLines(file);
                Pointfile point;
                try
                {
                    point = Pointfile.Parse(text);
                }
                catch
                {
                    MessageBox.Show(String.Format(InvalidPointfile, Path.GetFileName(file)));
                    return;
                }

                await MapDocumentOperation.Perform(document, new TrivialOperation(
                                                       d => d.Map.Data.Replace(point),
                                                       c => c.Add(c.Document.Map.Root)
                                                       ));

                if (point.Lines.Any())
                {
                    var start = point.Lines[0].Start;
                    await Oy.Publish("MapDocument:Viewport:Focus2D", start);

                    await Oy.Publish("MapDocument:Viewport:Focus3D", start);
                }
            }
        }
Ejemplo n.º 2
0
        public static Pointfile Parse(IEnumerable <string> lines)
        {
            var pf   = new Pointfile();
            var list = lines.ToList();

            if (!list.Any())
            {
                return(pf);
            }

            // Format detection: look at one line
            // .lin format: coordinate - coordinate
            // .pts format: coordinate
            var detect = list[0].Split(' ');
            var lin    = detect.Length == 7;
            var pts    = detect.Length == 3;

            if (!lin && !pts)
            {
                throw new Exception("Invalid pointfile format.");
            }

            Vector3?previous = null;

            foreach (var line in list)
            {
                var split = line.Split(' ');
                var point = NumericsExtensions.Parse(split[0], split[1], split[2], NumberStyles.Float, CultureInfo.InvariantCulture);
                if (lin)
                {
                    var point2 = NumericsExtensions.Parse(split[4], split[5], split[6], NumberStyles.Float, CultureInfo.InvariantCulture);
                    pf.Lines.Add(new Line(point2, point));
                }
                else // pts
                {
                    if (previous.HasValue)
                    {
                        pf.Lines.Add(new Line(previous.Value, point));
                    }
                    previous = point;
                }
            }

            return(pf);
        }
Ejemplo n.º 3
0
        protected override async Task Invoke(MapDocument document, CommandParameters parameters)
        {
            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter           = "Pointfiles (*.lin, *.pts)|*.lin;*.pts";
                ofd.InitialDirectory = Path.GetDirectoryName(document.FileName);
                ofd.Multiselect      = false;
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var       file = ofd.FileName;
                var       text = File.ReadAllLines(file);
                Pointfile point;
                try
                {
                    point = Pointfile.Parse(text);
                }
                catch
                {
                    MessageBox.Show(String.Format(InvalidPointfile, Path.GetFileName(file)));
                    return;
                }

                await MapDocumentOperation.Perform(document, new TrivialOperation(
                                                       d => d.Map.Data.Replace(point),
                                                       c => c.Add(c.Document.Map.Root)
                                                       ));

                if (point.Lines.Any())
                {
                    var start = point.Lines[0].Start;
                    await Oy.Publish("MapDocument:Viewport:Focus2D", start);

                    await Oy.Publish("MapDocument:Viewport:Focus3D", start);
                }
            }
        }