/// <summary> /// Insert a graphic /// </summary> /// <param name="index">index</param> /// <param name="aGraphic">graphic</param> public void Insert(int index, Graphic aGraphic) { _graphicList.Insert(index, aGraphic); //Update extent if (_graphicList.Count == 1) { _extent = aGraphic.Shape.Extent; } else { _extent = MIMath.GetLagerExtent(_extent, aGraphic.Shape.Extent); } }
/// <summary> /// Add a graphic /// </summary> /// <param name="aGraphic">graphic</param> public void Add(Graphic aGraphic) { _graphicList.Add(aGraphic); //Update extent if (_graphicList.Count == 1) { _extent = aGraphic.Shape.Extent; } else { _extent = MIMath.GetLagerExtent(_extent, aGraphic.Shape.Extent); } }
/// <summary> /// Override paint method /// </summary> /// <param name="g">graphics</param> public override void Paint(Graphics g) { if (_mapFrame != null) { g.FillRectangle(new SolidBrush(_mapFrame.MapView.BackColor), _mapFrame.LayoutBounds); //Region oldRegion = g.Clip; //GraphicsPath path = new GraphicsPath(); //Rectangle rect = this.Bounds; //path.AddRectangle(rect); //g.SetClip(path); //Matrix oldMatrix = g.Transform; //g.TranslateTransform(this.Left, this.Top); _mapFrame.MapView.PaintGraphics(g, _mapFrame.LayoutBounds); //Draw lon/lat grid labels if (_mapFrame.DrawGridLabel) { List <Extent> extentList = new List <Extent>(); Extent maxExtent = new Extent(); Extent aExtent = new Extent(); SizeF aSF = new SizeF(); SolidBrush aBrush = new SolidBrush(this.ForeColor); Pen aPen = new Pen(_mapFrame.GridLineColor); aPen.Width = _mapFrame.GridLineSize; string drawStr; PointF sP = new PointF(0, 0); PointF eP = new PointF(0, 0); Font font = new Font(_mapFrame.GridFont.Name, _mapFrame.GridFont.Size, _mapFrame.GridFont.Style); float labX, labY; int len = 5; int space = len + 2; for (int i = 0; i < _mapFrame.MapView.GridLabels.Count; i++) { GridLabel aGL = _mapFrame.MapView.GridLabels[i]; switch (_mapFrame.GridLabelPosition) { case GridLabelPosition.LeftBottom: switch (aGL.LabDirection) { case Direction.East: case Direction.North: continue; } break; case GridLabelPosition.LeftUp: switch (aGL.LabDirection) { case Direction.East: case Direction.South: continue; } break; case GridLabelPosition.RightBottom: switch (aGL.LabDirection) { case Direction.Weast: case Direction.North: continue; } break; case GridLabelPosition.RightUp: switch (aGL.LabDirection) { case Direction.Weast: case Direction.South: continue; } break; } labX = (float)aGL.LabPoint.X; labY = (float)aGL.LabPoint.Y; labX = labX + this.Left; labY = labY + this.Top; sP.X = labX; sP.Y = labY; drawStr = aGL.LabString; aSF = g.MeasureString(drawStr, font); switch (aGL.LabDirection) { case Direction.South: labX = labX - aSF.Width / 2; labY = labY + space; eP.X = sP.X; eP.Y = sP.Y + len; break; case Direction.Weast: labX = labX - aSF.Width - space; labY = labY - aSF.Height / 2; eP.X = sP.X - len; eP.Y = sP.Y; break; case Direction.North: labX = labX - aSF.Width / 2; labY = labY - aSF.Height - space; eP.X = sP.X; eP.Y = sP.Y - len; break; case Direction.East: labX = labX + space; labY = labY - aSF.Height / 2; eP.X = sP.X + len; eP.Y = sP.Y; break; } bool ifDraw = true; float aSize = aSF.Width / 2; float bSize = aSF.Height / 2; aExtent.minX = labX; aExtent.maxX = labX + aSF.Width; aExtent.minY = labY - aSF.Height; aExtent.maxY = labY; //Judge extent if (extentList.Count == 0) { maxExtent = aExtent; extentList.Add(aExtent); } else { if (!MIMath.IsExtentCross(aExtent, maxExtent)) { extentList.Add(aExtent); maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent); } else { for (int j = 0; j < extentList.Count; j++) { if (MIMath.IsExtentCross(aExtent, extentList[j])) { ifDraw = false; break; } } if (ifDraw) { extentList.Add(aExtent); maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent); } } } if (ifDraw) { g.DrawLine(aPen, sP, eP); g.DrawString(drawStr, font, aBrush, labX, labY); } } aPen.Dispose(); aBrush.Dispose(); } //g.Transform = oldMatrix; //g.Clip = oldRegion; if (_mapFrame.DrawNeatLine) { Pen aPen = new Pen(_mapFrame.NeatLineColor, _mapFrame.NeatLineSize); g.DrawRectangle(aPen, _mapFrame.LayoutBounds); aPen.Dispose(); } } }
/// <summary> /// Override PaintOnLayout method /// </summary> /// <param name="g">graphics</param> /// <param name="pageLocation">page location</param> /// <param name="zoom">zoom</param> public override void PaintOnLayout(Graphics g, PointF pageLocation, float zoom) { if (_mapFrame != null) { PointF aP = PageToScreen(this.Left, this.Top, pageLocation, zoom); Rectangle rect = new Rectangle((int)aP.X, (int)aP.Y, (int)(Width * zoom), (int)(Height * zoom)); g.FillRectangle(new SolidBrush(_mapFrame.MapView.BackColor), rect); _mapFrame.MapView.PaintGraphics(g, rect); //Draw lon/lat grid labels if (_mapFrame.DrawGridLabel || _mapFrame.DrawGridTickLine) { List <Extent> extentList = new List <Extent>(); Extent maxExtent = new Extent(); Extent aExtent = new Extent(); SizeF aSF = new SizeF(); SolidBrush aBrush = new SolidBrush(this.ForeColor); Pen aPen = new Pen(_mapFrame.GridLineColor); aPen.Width = _mapFrame.GridLineSize; string drawStr; PointF sP = new PointF(0, 0); PointF eP = new PointF(0, 0); Font font = new Font(_mapFrame.GridFont.Name, _mapFrame.GridFont.Size * zoom, _mapFrame.GridFont.Style); float labX, labY; int len = _mapFrame.TickLineLength; int space = len + _mapFrame.GridLabelShift; if (_mapFrame.InsideTickLine) { space = _mapFrame.GridLabelShift; } for (int i = 0; i < _mapFrame.MapView.GridLabels.Count; i++) { GridLabel aGL = _mapFrame.MapView.GridLabels[i]; switch (_mapFrame.GridLabelPosition) { case GridLabelPosition.LeftBottom: switch (aGL.LabDirection) { case Direction.East: case Direction.North: continue; } break; case GridLabelPosition.LeftUp: switch (aGL.LabDirection) { case Direction.East: case Direction.South: continue; } break; case GridLabelPosition.RightBottom: switch (aGL.LabDirection) { case Direction.Weast: case Direction.North: continue; } break; case GridLabelPosition.RightUp: switch (aGL.LabDirection) { case Direction.Weast: case Direction.South: continue; } break; } labX = (float)aGL.LabPoint.X; labY = (float)aGL.LabPoint.Y; labX = labX + this.Left * zoom + pageLocation.X; labY = labY + this.Top * zoom + pageLocation.Y; sP.X = labX; sP.Y = labY; drawStr = aGL.LabString; if (_mapFrame.DrawDegreeSymbol) { if (drawStr.EndsWith("E") || drawStr.EndsWith("W") || drawStr.EndsWith("N") || drawStr.EndsWith("S")) { drawStr = drawStr.Substring(0, drawStr.Length - 1) + ((char)186).ToString() + drawStr.Substring(drawStr.Length - 1); } else { drawStr = drawStr + ((char)186).ToString(); } } aSF = g.MeasureString(drawStr, font); switch (aGL.LabDirection) { case Direction.South: labX = labX - aSF.Width / 2; labY = labY + space; eP.X = sP.X; if (_mapFrame.InsideTickLine) { eP.Y = sP.Y - len; } else { eP.Y = sP.Y + len; } break; case Direction.Weast: labX = labX - aSF.Width - space; labY = labY - aSF.Height / 2; eP.Y = sP.Y; if (_mapFrame.InsideTickLine) { eP.X = sP.X + len; } else { eP.X = sP.X - len; } break; case Direction.North: labX = labX - aSF.Width / 2; labY = labY - aSF.Height - space; eP.X = sP.X; if (_mapFrame.InsideTickLine) { eP.Y = sP.Y + len; } else { eP.Y = sP.Y - len; } break; case Direction.East: labX = labX + space; labY = labY - aSF.Height / 2; eP.Y = sP.Y; if (_mapFrame.InsideTickLine) { eP.X = sP.X - len; } else { eP.X = sP.X + len; } break; } bool ifDraw = true; float aSize = aSF.Width / 2; float bSize = aSF.Height / 2; aExtent.minX = labX; aExtent.maxX = labX + aSF.Width; aExtent.minY = labY - aSF.Height; aExtent.maxY = labY; //Judge extent if (extentList.Count == 0) { maxExtent = aExtent; extentList.Add(aExtent); } else { if (!MIMath.IsExtentCross(aExtent, maxExtent)) { extentList.Add(aExtent); maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent); } else { for (int j = 0; j < extentList.Count; j++) { if (MIMath.IsExtentCross(aExtent, extentList[j])) { ifDraw = false; break; } } if (ifDraw) { extentList.Add(aExtent); maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent); } } } if (ifDraw) { if (_mapFrame.DrawGridTickLine) { g.DrawLine(aPen, sP, eP); } if (_mapFrame.DrawGridLabel) { g.DrawString(drawStr, font, aBrush, labX, labY); } } } aPen.Dispose(); aBrush.Dispose(); } //Draw neat line if (_mapFrame.DrawNeatLine) { Pen aPen = new Pen(_mapFrame.NeatLineColor, _mapFrame.NeatLineSize); g.DrawRectangle(aPen, rect); aPen.Dispose(); } } }
private void SavGrADSMaskoutFile() { SaveFileDialog SFDlg = new SaveFileDialog(); SFDlg.Filter = "GrADS File (*.ctl)|*.ctl"; if (SFDlg.ShowDialog() == DialogResult.OK) { string aFile = SFDlg.FileName; int i; bool hasSelShape = _currentLayer.HasSelectedShapes(); //Get grid set PolygonShape aPGS = new PolygonShape(); Extent aExtent = new Extent(); int n = 0; for (i = 0; i < _currentLayer.ShapeNum; i++) { aPGS = (PolygonShape)_currentLayer.ShapeList[i]; if (hasSelShape) { if (!aPGS.Selected) { continue; } } if (n == 0) { aExtent = aPGS.Extent; } else { aExtent = MIMath.GetLagerExtent(aExtent, aPGS.Extent); } n += 1; } GridDataSetting aGDP = new GridDataSetting(); aGDP.DataExtent.minX = Math.Floor(aExtent.minX); aGDP.DataExtent.maxX = Math.Ceiling(aExtent.maxX); aGDP.DataExtent.minY = Math.Floor(aExtent.minY); aGDP.DataExtent.maxY = Math.Ceiling(aExtent.maxY); aGDP.XNum = 20; aGDP.YNum = 20; frmGridSet aFrmGS = new frmGridSet(); aFrmGS.SetParameters(aGDP); if (aFrmGS.ShowDialog() == DialogResult.OK) { aFrmGS.GetParameters(ref aGDP); //Show progressbar this.toolStripProgressBar1.Visible = true; this.toolStripProgressBar1.Value = 0; this.Cursor = Cursors.WaitCursor; Application.DoEvents(); //Get grid data double[,] gridData = new double[aGDP.YNum, aGDP.XNum]; int j, p; MeteoInfoC.PointD aPoint = new MeteoInfoC.PointD(); double xSize, ySize; xSize = (aGDP.DataExtent.maxX - aGDP.DataExtent.minX) / (aGDP.XNum - 1); ySize = (aGDP.DataExtent.maxY - aGDP.DataExtent.minY) / (aGDP.YNum - 1); bool isIn = false; for (i = 0; i < aGDP.YNum; i++) { aPoint.Y = aGDP.DataExtent.minY + i * ySize; for (j = 0; j < aGDP.XNum; j++) { aPoint.X = aGDP.DataExtent.minX + j * xSize; isIn = false; for (p = 0; p < _currentLayer.ShapeNum; p++) { aPGS = (PolygonShape)_currentLayer.ShapeList[p]; if (hasSelShape) { if (!aPGS.Selected) { continue; } } if (MIMath.PointInPolygon(aPGS, aPoint)) { isIn = true; break; } } if (isIn) { gridData[i, j] = 1; } else { gridData[i, j] = -1; } } this.toolStripProgressBar1.Value = (i + 1) * 100 / aGDP.YNum; Application.DoEvents(); } //Get GrADS data info string dFile = Path.ChangeExtension(aFile, ".dat"); GrADSDataInfo aDataInfo = new GrADSDataInfo(); aDataInfo.TITLE = "Mask data"; aDataInfo.DSET = dFile; aDataInfo.DTYPE = "GRIDDED"; aDataInfo.XDEF.Type = "LINEAR"; aDataInfo.XDEF.XNum = aGDP.XNum; aDataInfo.XDEF.XMin = (Single)aGDP.DataExtent.minX; aDataInfo.XDEF.XDelt = (Single)(xSize); aDataInfo.YDEF.Type = "LINEAR"; aDataInfo.YDEF.YNum = aGDP.YNum; aDataInfo.YDEF.YMin = (Single)aGDP.DataExtent.minY; aDataInfo.YDEF.YDelt = (Single)(ySize); aDataInfo.ZDEF.Type = "LINEAR"; aDataInfo.ZDEF.ZNum = 1; aDataInfo.ZDEF.SLevel = 1; aDataInfo.ZDEF.ZDelt = 1; aDataInfo.TDEF.Type = "LINEAR"; aDataInfo.TDEF.TNum = 1; aDataInfo.TDEF.STime = DateTime.Now; aDataInfo.TDEF.TDelt = "1mo"; Variable aVar = new Variable(); aVar.Name = "mask"; //aVar.LevelNum = 0; aVar.Units = "99"; aVar.Description = "background mask data"; aDataInfo.VARDEF.AddVar(aVar); //Save files aDataInfo.WriteGrADSCTLFile(); aDataInfo.WriteGrADSData_Grid(dFile, gridData); //Hide progressbar this.toolStripProgressBar1.Visible = false; this.Cursor = Cursors.Default; } } }