/// <summary> /// Update image /// </summary> public void UpdateImage() { int xNum = GridData.XNum; int yNum = GridData.YNum; byte[] imageBytes = new byte[xNum * yNum]; for (int i = 0; i < yNum; i++) { for (int j = 0; j < xNum; j++) { int value = -1; int b; for (b = 0; b < LegendScheme.LegendBreaks.Count - 1; b++) { ColorBreak aCB = LegendScheme.LegendBreaks[b]; if (aCB.StartValue.ToString() == aCB.EndValue.ToString()) { if (GridData.Data[i, j] == double.Parse(aCB.StartValue.ToString())) { value = b; break; } } else { if (GridData.Data[i, j] >= double.Parse(aCB.StartValue.ToString()) && GridData.Data[i, j] < double.Parse(aCB.EndValue.ToString())) { value = b; break; } } } if (value == -1) { value = b; if (LegendScheme.LegendBreaks[LegendScheme.BreakNum - 1].IsNoData) { if (!MIMath.DoubleEquals(GridData.Data[i, j], LegendScheme.MissingValue)) { value = b - 1; } } } imageBytes[i * xNum + j] = (byte)value; } } Image = DrawMeteoData.CreateBitmap(imageBytes, xNum, yNum); List <Color> colors = LegendScheme.GetColors(); DrawMeteoData.SetPalette(colors, Image); }
/// <summary> /// Import from XML node /// </summary> /// <param name="graphicNode">graphic xml node</param> public void ImportFromXML(XmlNode graphicNode) { XmlNode shape = graphicNode.ChildNodes[0]; _shape = LoadShape(shape); XmlNode legend = graphicNode.ChildNodes[1]; _legend = LoadLegend(legend, _shape.ShapeType); UpdateResizeAbility(); try { this._tag = graphicNode.Attributes["Tag"].InnerText; } catch { } }
/// <summary> /// Constructor /// </summary> /// <param name="aCB">color break</param> public ColorSet(ColorBreak aCB) { _LColor = aCB.Color; }
private ColorBreak LoadLegend(XmlNode legendNode, ShapeTypes shapeType) { ColorBreak legend = new ColorBreak(); try { Color color = ColorTranslator.FromHtml(legendNode.Attributes["Color"].InnerText); string legendType = legendNode.Attributes["LegendType"].InnerText; BreakTypes breakType = (BreakTypes)Enum.Parse(typeof(BreakTypes), legendType); switch (breakType) { case BreakTypes.PointBreak: PointBreak aPB = new PointBreak(); try { aPB.Color = color; aPB.DrawFill = bool.Parse(legendNode.Attributes["DrawFill"].InnerText); aPB.DrawOutline = bool.Parse(legendNode.Attributes["DrawOutline"].InnerText); aPB.OutlineColor = ColorTranslator.FromHtml(legendNode.Attributes["OutlineColor"].InnerText); aPB.Size = float.Parse(legendNode.Attributes["Size"].InnerText); aPB.Style = (PointStyle)Enum.Parse(typeof(PointStyle), legendNode.Attributes["Style"].InnerText); aPB.MarkerType = (MarkerType)Enum.Parse(typeof(MarkerType), legendNode.Attributes["MarkerType"].InnerText, true); aPB.FontName = legendNode.Attributes["FontName"].InnerText; aPB.CharIndex = int.Parse(legendNode.Attributes["CharIndex"].InnerText); aPB.ImagePath = legendNode.Attributes["ImagePath"].InnerText; aPB.Angle = float.Parse(legendNode.Attributes["Angle"].InnerText); } catch { } finally { legend = aPB; } break; case BreakTypes.LabelBreak: LabelBreak aLB = new LabelBreak(); try { aLB.Color = color; aLB.Angle = float.Parse(legendNode.Attributes["Angle"].InnerText); aLB.Text = legendNode.Attributes["Text"].InnerText; string fontName = legendNode.Attributes["FontName"].InnerText; float fontSize = float.Parse(legendNode.Attributes["FontSize"].InnerText); bool fontBold = bool.Parse(legendNode.Attributes["FontBold"].InnerText); if (fontBold) { aLB.Font = new Font(fontName, fontSize, FontStyle.Bold); } else { aLB.Font = new Font(fontName, fontSize); } aLB.YShift = float.Parse(legendNode.Attributes["YShift"].InnerText); } catch { } finally { legend = aLB; } break; case BreakTypes.ChartBreak: ChartBreak aChB = new ChartBreak(ChartTypes.BarChart); try { ChartTypes chartType = (ChartTypes)Enum.Parse(typeof(ChartTypes), legendNode.Attributes["ChartType"].InnerText); aChB = new ChartBreak(chartType); aChB.ShapeIndex = int.Parse(legendNode.Attributes["ShapeIndex"].InnerText); List <float> cData = new List <float>(); string[] cDataStr = legendNode.Attributes["ChartData"].InnerText.Split(','); for (int i = 0; i < cDataStr.Length; i++) { cData.Add(float.Parse(cDataStr[i])); } aChB.ChartData = cData; aChB.XShift = int.Parse(legendNode.Attributes["XShift"].InnerText); aChB.YShift = int.Parse(legendNode.Attributes["YShift"].InnerText); } catch { } finally { legend = aChB; } break; case BreakTypes.VectorBreak: VectorBreak aVB = new VectorBreak(); try { aVB.Color = color; } catch { } finally { legend = aVB; } break; case BreakTypes.PolylineBreak: PolyLineBreak aPLB = new PolyLineBreak(); try { aPLB.Color = color; aPLB.Size = Convert.ToSingle(legendNode.Attributes["Size"].InnerText); aPLB.Style = (LineStyles)Enum.Parse(typeof(LineStyles), legendNode.Attributes["Style"].InnerText, true); aPLB.DrawSymbol = bool.Parse(legendNode.Attributes["DrawSymbol"].InnerText); aPLB.SymbolSize = Single.Parse(legendNode.Attributes["SymbolSize"].InnerText); aPLB.SymbolStyle = (PointStyle)Enum.Parse(typeof(PointStyle), legendNode.Attributes["SymbolStyle"].InnerText, true); aPLB.SymbolColor = ColorTranslator.FromHtml(legendNode.Attributes["SymbolColor"].InnerText); aPLB.SymbolInterval = int.Parse(legendNode.Attributes["SymbolInterval"].InnerText); } catch { } finally { legend = aPLB; } break; case BreakTypes.PolygonBreak: PolygonBreak aPGB = new PolygonBreak(); try { aPGB.Color = color; aPGB.DrawFill = Convert.ToBoolean(legendNode.Attributes["DrawFill"].InnerText); aPGB.DrawOutline = Convert.ToBoolean(legendNode.Attributes["DrawOutline"].InnerText); aPGB.OutlineSize = Convert.ToSingle(legendNode.Attributes["OutlineSize"].InnerText); aPGB.OutlineColor = ColorTranslator.FromHtml(legendNode.Attributes["OutlineColor"].InnerText); aPGB.UsingHatchStyle = bool.Parse(legendNode.Attributes["UsingHatchStyle"].InnerText); aPGB.Style = (HatchStyle)Enum.Parse(typeof(HatchStyle), legendNode.Attributes["Style"].InnerText, true); aPGB.BackColor = ColorTranslator.FromHtml(legendNode.Attributes["BackColor"].InnerText); //aPGB.TransparencyPercent = int.Parse(legendNode.Attributes["TransparencyPercent"].InnerText); aPGB.IsMaskout = bool.Parse(legendNode.Attributes["IsMaskout"].InnerText); } catch { } { legend = aPGB; } break; } } catch { } return(legend); }
/// <summary> /// Constructor /// </summary> /// <param name="shape">shape</param> /// <param name="legend">legend</param> public Graphic(Shape shape, ColorBreak legend) { _shape = shape; _legend = legend; UpdateResizeAbility(); }
private void AddLegend(ref XmlDocument doc, XmlElement parent, ColorBreak aLegend, ShapeTypes shapeType) { XmlElement legend = doc.CreateElement("Legend"); XmlAttribute color = doc.CreateAttribute("Color"); color.InnerText = ColorTranslator.ToHtml(aLegend.Color); legend.Attributes.Append(color); XmlAttribute legendType = doc.CreateAttribute("LegendType"); XmlAttribute size; XmlAttribute style; XmlAttribute outlineColor; XmlAttribute drawOutline; XmlAttribute drawFill; legendType.InnerText = aLegend.BreakType.ToString(); switch (aLegend.BreakType) { case BreakTypes.PointBreak: PointBreak aPB = (PointBreak)aLegend; outlineColor = doc.CreateAttribute("OutlineColor"); size = doc.CreateAttribute("Size"); style = doc.CreateAttribute("Style"); drawOutline = doc.CreateAttribute("DrawOutline"); drawFill = doc.CreateAttribute("DrawFill"); XmlAttribute markerType = doc.CreateAttribute("MarkerType"); XmlAttribute fontName = doc.CreateAttribute("FontName"); XmlAttribute charIndex = doc.CreateAttribute("CharIndex"); XmlAttribute imagePath = doc.CreateAttribute("ImagePath"); XmlAttribute angle = doc.CreateAttribute("Angle"); //legendType.InnerText = "PointBreak"; outlineColor.InnerText = ColorTranslator.ToHtml(aPB.OutlineColor); size.InnerText = aPB.Size.ToString(); style.InnerText = Enum.GetName(typeof(PointStyle), aPB.Style); drawOutline.InnerText = aPB.DrawOutline.ToString(); drawFill.InnerText = aPB.DrawFill.ToString(); markerType.InnerText = aPB.MarkerType.ToString(); fontName.InnerText = aPB.FontName; charIndex.InnerText = aPB.CharIndex.ToString(); imagePath.InnerText = aPB.ImagePath; angle.InnerText = aPB.Angle.ToString(); legend.Attributes.Append(legendType); legend.Attributes.Append(outlineColor); legend.Attributes.Append(size); legend.Attributes.Append(style); legend.Attributes.Append(drawOutline); legend.Attributes.Append(drawFill); legend.Attributes.Append(markerType); legend.Attributes.Append(fontName); legend.Attributes.Append(charIndex); legend.Attributes.Append(imagePath); legend.Attributes.Append(angle); break; case BreakTypes.LabelBreak: LabelBreak aLB = (LabelBreak)aLegend; XmlAttribute text = doc.CreateAttribute("Text"); angle = doc.CreateAttribute("Angle"); fontName = doc.CreateAttribute("FontName"); XmlAttribute fontSize = doc.CreateAttribute("FontSize"); XmlAttribute fontBold = doc.CreateAttribute("FontBold"); XmlAttribute yShift = doc.CreateAttribute("YShift"); //legendType.InnerText = "LabelBreak"; text.InnerText = aLB.Text; angle.InnerText = aLB.Angle.ToString(); fontName.InnerText = aLB.Font.Name; fontSize.InnerText = aLB.Font.Size.ToString(); fontBold.InnerText = aLB.Font.Bold.ToString(); yShift.InnerText = aLB.YShift.ToString(); legend.Attributes.Append(legendType); legend.Attributes.Append(text); legend.Attributes.Append(angle); legend.Attributes.Append(fontName); legend.Attributes.Append(fontSize); legend.Attributes.Append(fontBold); legend.Attributes.Append(yShift); break; case BreakTypes.ChartBreak: ChartBreak aChB = (ChartBreak)aLegend; XmlAttribute shapeIndex = doc.CreateAttribute("ShapeIndex"); XmlAttribute chartType = doc.CreateAttribute("ChartType"); XmlAttribute chartData = doc.CreateAttribute("ChartData"); XmlAttribute xShift = doc.CreateAttribute("XShift"); yShift = doc.CreateAttribute("YShift"); shapeIndex.InnerText = aChB.ShapeIndex.ToString(); //legendType.InnerText = "ChartBreak"; chartType.InnerText = aChB.ChartType.ToString(); string cdata = ""; for (int i = 0; i < aChB.ItemNum; i++) { if (i == 0) { cdata = aChB.ChartData[i].ToString(); } else { cdata += "," + aChB.ChartData[i].ToString(); } } chartData.InnerText = cdata; xShift.InnerText = aChB.XShift.ToString(); yShift.InnerText = aChB.YShift.ToString(); legend.Attributes.Append(legendType); legend.Attributes.Append(shapeIndex); legend.Attributes.Append(chartType); legend.Attributes.Append(chartData); legend.Attributes.Append(xShift); legend.Attributes.Append(yShift); break; case BreakTypes.VectorBreak: //legendType.InnerText = "VectorBreak"; legend.Attributes.Append(legendType); break; case BreakTypes.PolylineBreak: PolyLineBreak aPLB = (PolyLineBreak)aLegend; size = doc.CreateAttribute("Size"); style = doc.CreateAttribute("Style"); XmlAttribute drawSymbol = doc.CreateAttribute("DrawSymbol"); XmlAttribute symbolSize = doc.CreateAttribute("SymbolSize"); XmlAttribute symbolStyle = doc.CreateAttribute("SymbolStyle"); XmlAttribute symbolColor = doc.CreateAttribute("SymbolColor"); XmlAttribute symbolInterval = doc.CreateAttribute("SymbolInterval"); //legendType.InnerText = "PolylineBreak"; size.InnerText = aPLB.Size.ToString(); style.InnerText = Enum.GetName(typeof(LineStyles), aPLB.Style); drawSymbol.InnerText = aPLB.DrawSymbol.ToString(); symbolSize.InnerText = aPLB.SymbolSize.ToString(); symbolStyle.InnerText = aPLB.SymbolStyle.ToString(); symbolColor.InnerText = ColorTranslator.ToHtml(aPLB.SymbolColor); symbolInterval.InnerText = aPLB.SymbolInterval.ToString(); legend.Attributes.Append(legendType); legend.Attributes.Append(size); legend.Attributes.Append(style); legend.Attributes.Append(drawSymbol); legend.Attributes.Append(symbolSize); legend.Attributes.Append(symbolStyle); legend.Attributes.Append(symbolColor); legend.Attributes.Append(symbolInterval); break; case BreakTypes.PolygonBreak: PolygonBreak aPGB = (PolygonBreak)aLegend; outlineColor = doc.CreateAttribute("OutlineColor"); drawOutline = doc.CreateAttribute("DrawOutline"); drawFill = doc.CreateAttribute("DrawFill"); XmlAttribute outlineSize = doc.CreateAttribute("OutlineSize"); XmlAttribute usingHatchStyle = doc.CreateAttribute("UsingHatchStyle"); style = doc.CreateAttribute("Style"); XmlAttribute backColor = doc.CreateAttribute("BackColor"); //XmlAttribute transparencyPer = doc.CreateAttribute("TransparencyPercent"); XmlAttribute isMaskout = doc.CreateAttribute("IsMaskout"); //legendType.InnerText = "PolygonBreak"; outlineColor.InnerText = ColorTranslator.ToHtml(aPGB.OutlineColor); drawOutline.InnerText = aPGB.DrawOutline.ToString(); drawFill.InnerText = aPGB.DrawFill.ToString(); outlineSize.InnerText = aPGB.OutlineSize.ToString(); usingHatchStyle.InnerText = aPGB.UsingHatchStyle.ToString(); style.InnerText = aPGB.Style.ToString(); backColor.InnerText = ColorTranslator.ToHtml(aPGB.BackColor); //transparencyPer.InnerText = aPGB.TransparencyPercent.ToString(); isMaskout.InnerText = aPGB.IsMaskout.ToString(); legend.Attributes.Append(legendType); legend.Attributes.Append(outlineColor); legend.Attributes.Append(drawOutline); legend.Attributes.Append(drawFill); legend.Attributes.Append(outlineSize); legend.Attributes.Append(usingHatchStyle); legend.Attributes.Append(style); legend.Attributes.Append(backColor); //legend.Attributes.Append(transparencyPer); legend.Attributes.Append(isMaskout); break; } parent.AppendChild(legend); }