コード例 #1
0
        private void SaveWMPFile()
        {
            SaveFileDialog SFDlg = new SaveFileDialog();

            SFDlg.Filter = "wmp File (*.wmp)|*.wmp";
            if (SFDlg.ShowDialog() == DialogResult.OK)
            {
                //ProgressBar
                toolStripProgressBar1.Visible = true;
                this.Cursor = Cursors.WaitCursor;

                string       aFile       = SFDlg.FileName;
                StreamWriter sw          = new StreamWriter(aFile);
                List <int>   selIndexes  = _currentLayer.GetSelectedShapeIndexes();
                bool         hasSelShape = _currentLayer.HasSelectedShapes();
                int          shpNum      = _currentLayer.ShapeNum;
                if (hasSelShape)
                {
                    shpNum = selIndexes.Count;
                }
                int i;
                switch (_currentLayer.ShapeType)
                {
                case ShapeTypes.Point:
                    sw.WriteLine("Point");
                    sw.WriteLine(shpNum.ToString());
                    PointShape aPS = new PointShape();
                    if (hasSelShape)
                    {
                        for (i = 0; i < _currentLayer.ShapeNum; i++)
                        {
                            aPS = (PointShape)_currentLayer.ShapeList[i];
                            if (aPS.Selected)
                            {
                                sw.WriteLine(aPS.Point.X.ToString() + "," + aPS.Point.Y.ToString());
                            }
                            this.toolStripProgressBar1.Value = (i + 1) * 100 / _currentLayer.ShapeNum;
                        }
                    }
                    else
                    {
                        for (i = 0; i < _currentLayer.ShapeNum; i++)
                        {
                            aPS = (PointShape)_currentLayer.ShapeList[i];
                            sw.WriteLine(aPS.Point.X.ToString() + "," + aPS.Point.Y.ToString());
                            this.toolStripProgressBar1.Value = (i + 1) * 100 / _currentLayer.ShapeNum;
                        }
                    }
                    break;

                case ShapeTypes.Polyline:
                    sw.WriteLine("Polyline");
                    int           shapeNum = 0;
                    PolylineShape aPLS     = new PolylineShape();
                    if (hasSelShape)
                    {
                        for (i = 0; i < _currentLayer.ShapeNum; i++)
                        {
                            aPLS = (PolylineShape)_currentLayer.ShapeList[i];
                            if (aPLS.Selected)
                            {
                                shapeNum += aPLS.PartNum;
                            }
                        }
                    }
                    for (i = 0; i < _currentLayer.ShapeNum; i++)
                    {
                        aPLS      = (PolylineShape)_currentLayer.ShapeList[i];
                        shapeNum += aPLS.PartNum;
                    }
                    sw.WriteLine(shpNum.ToString());

                    for (i = 0; i < _currentLayer.ShapeNum; i++)
                    {
                        aPLS = (PolylineShape)_currentLayer.ShapeList[i];
                        if (hasSelShape)
                        {
                            if (!aPLS.Selected)
                            {
                                continue;
                            }
                        }
                        MeteoInfoC.PointD[] Pointps;
                        for (int p = 0; p < aPLS.PartNum; p++)
                        {
                            if (p == aPLS.PartNum - 1)
                            {
                                Pointps = new MeteoInfoC.PointD[aPLS.PointNum - aPLS.parts[p]];
                                for (int pp = aPLS.parts[p]; pp < aPLS.PointNum; pp++)
                                {
                                    Pointps[pp - aPLS.parts[p]] = (MeteoInfoC.PointD)aPLS.Points[pp];
                                }
                            }
                            else
                            {
                                Pointps = new MeteoInfoC.PointD[aPLS.parts[p + 1] - aPLS.parts[p]];
                                for (int pp = aPLS.parts[p]; pp < aPLS.parts[p + 1]; pp++)
                                {
                                    Pointps[pp - aPLS.parts[p]] = (MeteoInfoC.PointD)aPLS.Points[pp];
                                }
                            }
                            sw.WriteLine(Pointps.Length.ToString());
                            foreach (MeteoInfoC.PointD aPoint in Pointps)
                            {
                                sw.WriteLine(aPoint.X.ToString() + "," + aPoint.Y.ToString());
                            }
                            shapeNum += 1;
                        }
                        Application.DoEvents();
                        this.toolStripProgressBar1.Value = (i + 1) * 100 / _currentLayer.ShapeNum;
                    }
                    break;

                case ShapeTypes.Polygon:
                    sw.WriteLine("Polygon");
                    shapeNum = 0;
                    PolygonShape aPGS = new PolygonShape();
                    for (i = 0; i < _currentLayer.ShapeNum; i++)
                    {
                        aPGS = (PolygonShape)_currentLayer.ShapeList[i];
                        if (hasSelShape)
                        {
                            if (!aPGS.Selected)
                            {
                                continue;
                            }
                        }
                        shapeNum += aPGS.PartNum;
                    }
                    sw.WriteLine(shapeNum.ToString());

                    for (i = 0; i < _currentLayer.ShapeNum; i++)
                    {
                        aPGS = (PolygonShape)_currentLayer.ShapeList[i];
                        if (hasSelShape)
                        {
                            if (!aPGS.Selected)
                            {
                                continue;
                            }
                        }

                        MeteoInfoC.PointD[] Pointps;
                        for (int p = 0; p < aPGS.PartNum; p++)
                        {
                            if (p == aPGS.PartNum - 1)
                            {
                                Pointps = new MeteoInfoC.PointD[aPGS.PointNum - aPGS.parts[p]];
                                for (int pp = aPGS.parts[p]; pp < aPGS.PointNum; pp++)
                                {
                                    Pointps[pp - aPGS.parts[p]] = (MeteoInfoC.PointD)aPGS.Points[pp];
                                }
                            }
                            else
                            {
                                Pointps = new MeteoInfoC.PointD[aPGS.parts[p + 1] - aPGS.parts[p]];
                                for (int pp = aPGS.parts[p]; pp < aPGS.parts[p + 1]; pp++)
                                {
                                    Pointps[pp - aPGS.parts[p]] = (MeteoInfoC.PointD)aPGS.Points[pp];
                                }
                            }
                            sw.WriteLine(Pointps.Length.ToString());
                            foreach (MeteoInfoC.PointD aPoint in Pointps)
                            {
                                sw.WriteLine(aPoint.X.ToString() + "," + aPoint.Y.ToString());
                            }
                            shapeNum += 1;
                        }
                        Application.DoEvents();
                        this.toolStripProgressBar1.Value = (i + 1) * 100 / _currentLayer.ShapeNum;
                    }
                    break;
                }

                sw.Close();

                //Progressbar
                this.toolStripProgressBar1.Value   = 0;
                this.toolStripProgressBar1.Visible = false;
                this.Cursor = Cursors.Default;
            }
        }