/// <summary> /// Creates a new object that is a copy of the current instance. /// </summary> /// <returns>A new object that is a copy of this instance</returns> public object Clone() { PolygonStyle ps = (PolygonStyle)MemberwiseClone(); if (_brushPattern != null) { _brushPattern = (Bitmap)_brushPattern.Clone(); _originalBrushPattern = (Bitmap)_originalBrushPattern.Clone(); ps.brushPatternParamsChanged(); } return(ps); }
/// <summary> /// Draw a polygon. /// </summary> protected virtual void DrawPolygon(Feature feature, Graphics g, PolygonStyle style, TitleStyle titleStyle, BoundingRectangle viewBox, bool titleVisible, double scaleFactor) { if (feature.Polygon.Contours.Count == 0) return; //if (feature.Layer != null && feature.Layer.Title == "adp.TAB") //{ // drawPrismPolygon(feature, g, viewBox, scaleFactor); // // inscription // if (!string.IsNullOrEmpty(feature.Title) && titleVisible) // addTitleBufferElement(g, feature, titleStyle, viewBox, scaleFactor); // return; //} if (!_isSelectionRendering && feature.Selected) { PolygonBufferElement element = new PolygonBufferElement(feature, style, titleStyle, titleVisible); _selectedPolygons.Add(element); return; } double pixelsize = 1/scaleFactor; if (_reduceSubpixelDetails) { if (feature.BoundingRectangle.Width < pixelsize && feature.BoundingRectangle.Height < pixelsize) return; Polygon tempPolygon = (Polygon) feature.Polygon.Clone(); tempPolygon.Weed(pixelsize); Feature tempFeature = new Feature(FeatureType.Polygon); tempFeature.Title = feature.Title; tempFeature.Selected = feature.Selected; tempFeature.Polygon = tempPolygon; feature = tempFeature; if (feature.Polygon.Contours.Count == 0) return; } using (Pen pen = style.GetPen()) { using (GraphicsPath path = new GraphicsPath(FillMode.Alternate)) { path.StartFigure(); float x = (float) ((feature.Polygon.Contours[0].Vertices[0].X - viewBox.MinX)*scaleFactor); float y = (float) ((viewBox.MaxY - feature.Polygon.Contours[0].Vertices[0].Y)*scaleFactor); g.RenderingOrigin = new Point((int) Math.Round(x), (int) Math.Round(y)); foreach (Contour c in feature.Polygon.Contours) { // there is no point in trying to draw the contours of the degenerate if (c.Vertices.Count <= 2) continue; PointF[] points = new PointF[c.Vertices.Count]; for (int j = 0; j < c.Vertices.Count; j++) { points[j].X = (float) ((c.Vertices[j].X - viewBox.MinX)*scaleFactor); points[j].Y = (float) ((viewBox.MaxY - c.Vertices[j].Y)*scaleFactor); } if (points.Length > 2) path.AddPolygon(points); } path.CloseFigure(); // Fill polygon using (Brush b = style.GetBrush()) { if (style.FillPatternInternal != null) { int w = style.FillPatternInternal.Width; int h = style.FillPatternInternal.Height; ((TextureBrush) b).TranslateTransform(g.RenderingOrigin.X%w, g.RenderingOrigin.Y%h); } g.FillPath(b, path); } if (feature.Selected) { //Fills the selected polygon //Color color = Color.FromArgb(50, _selectionColor); //using (Brush b = new HatchBrush(HatchStyle.Percent70, color, Color.Transparent)) if (_selectionColorChanged || _selectionTexture == null) createSelectionTexture(); using (Brush b = new TextureBrush(_selectionTexture)) { ((TextureBrush) b).TranslateTransform(g.RenderingOrigin.X%8, g.RenderingOrigin.Y%8); g.FillPath(b, path); } // boundary of the selected polygons using (Pen p = new Pen(_selectionColor, style.BorderWidth + 3)) { p.LineJoin = LineJoin.Bevel; g.DrawPath(p, path); } } //boundary of the landfill if (style.BorderVisible) g.DrawPath(pen, path); } // inscription if (!string.IsNullOrEmpty(feature.Title) && titleVisible) addTitleBufferElement(g, feature, titleStyle, viewBox, scaleFactor); } }
void IFeatureRenderer.DrawPolygon(Feature feature, Graphics g, PolygonStyle style, TitleStyle titleStyle, BoundingRectangle viewBox, bool titleVisible, double scaleFactor) { DrawPolygon(feature, g, style, titleStyle, viewBox, titleVisible, scaleFactor); }
public PolygonBufferElement(Feature polygon, PolygonStyle style, TitleStyle titleStyle, bool titleVisible) { _style = style; _titleStyle = titleStyle; _polygon = polygon; _titleVisible = titleVisible; }
/// <summary/> protected void processPolygonStyle(XmlNode layerNode, PolygonStyle PolygonStyle) { XmlNode polygonStyle = tryGetNodeByName(layerNode.ChildNodes, "polygon_style"); if (polygonStyle != null) { PolygonStyle.BorderWidth = float.Parse(polygonStyle.Attributes["border_width"].Value, CultureInfo.InvariantCulture); PolygonStyle.BorderColor = ColorTranslator.FromHtml(polygonStyle.Attributes["border_color"].Value); PolygonStyle.BorderDashStyle = (DashStyle)int.Parse(polygonStyle.Attributes["border_dash_style"].Value, CultureInfo.InvariantCulture); PolygonStyle.HatchStyle = (HatchStyle)int.Parse(polygonStyle.Attributes["hatch_style"].Value, CultureInfo.InvariantCulture); if (polygonStyle.Attributes["border_dash_cap"] != null) PolygonStyle.BorderDashCap = (DashCap)int.Parse(polygonStyle.Attributes["border_dash_cap"].Value, CultureInfo.InvariantCulture); PolygonStyle.UseHatch = polygonStyle.Attributes["use_hatch"].Value == "1"; if (polygonStyle.Attributes["border_visible"] != null) PolygonStyle.BorderVisible = polygonStyle.Attributes["border_visible"].Value == "1"; PolygonStyle.FillForeColor = ColorTranslator.FromHtml(polygonStyle.Attributes["fill_fore_color"].Value); PolygonStyle.FillBackColor = ColorTranslator.FromHtml(polygonStyle.Attributes["fill_back_color"].Value); if (polygonStyle.Attributes["fill_transparent"] != null) PolygonStyle.FillBackColor = Color.FromArgb(int.Parse(polygonStyle.Attributes["fill_transparent"].Value, CultureInfo.InvariantCulture), PolygonStyle.FillBackColor); if (polygonStyle.Attributes["fill_pattern"] != null) PolygonStyle.FillPattern = (BuiltInFillPatterns)int.Parse(polygonStyle.Attributes["fill_pattern"].Value, CultureInfo.InvariantCulture); } }
/// <summary/> protected void addPolygonStyleElement(PolygonStyle PolygonStyle, XmlDocument doc, XmlElement layerElement) { XmlElement polygonStyleElement = doc.CreateElement("polygon_style"); layerElement.AppendChild(polygonStyleElement); addAttribute( polygonStyleElement, "border_width", PolygonStyle.BorderWidth.ToString(CultureInfo.InvariantCulture)); addAttribute( polygonStyleElement, "border_color", ColorTranslator.ToHtml(PolygonStyle.BorderColor)); addAttribute( polygonStyleElement, "border_visible", PolygonStyle.BorderVisible ? "1" : "0"); addAttribute( polygonStyleElement, "border_dash_style", ((int)PolygonStyle.BorderDashStyle).ToString(CultureInfo.InvariantCulture)); addAttribute( polygonStyleElement, "border_dash_cap", ((int)PolygonStyle.BorderDashCap).ToString(CultureInfo.InvariantCulture)); addAttribute( polygonStyleElement, "hatch_style", ((int)PolygonStyle.HatchStyle).ToString(CultureInfo.InvariantCulture)); addAttribute( polygonStyleElement, "use_hatch", PolygonStyle.UseHatch ? "1" : "0"); addAttribute( polygonStyleElement, "fill_fore_color", ColorTranslator.ToHtml(PolygonStyle.FillForeColor)); addAttribute( polygonStyleElement, "fill_back_color", ColorTranslator.ToHtml(PolygonStyle.FillBackColor)); addAttribute( polygonStyleElement, "fill_pattern", ((int)PolygonStyle.FillPattern).ToString(CultureInfo.InvariantCulture)); addAttribute( polygonStyleElement, "fill_transparent", PolygonStyle.FillBackColor.A.ToString(CultureInfo.InvariantCulture)); }