/// <summary> /// Creates a new <c>ScaleSpecificPen</c> /// </summary> /// <param name="style">The style that makes reference to this pen</param> /// <param name="draw">The drawing tool that holds the current scale</param> internal ScaleSpecificPen(Style style, ISpatialDisplay draw) { m_Pen = new Pen(Color.Black); m_Scale = (int)draw.MapScale; style.DefinePen(this, draw); }
/// <summary> /// Reset data members to their initial values. /// </summary> void ResetContents() { m_Spec = String.Empty; m_StyleLookup = null; m_LastLookup = String.Empty; m_LastStyle = null; m_Styles = null; m_DashPatterns = null; }
/// <summary> /// Initialize this style file object with the content of a file. /// </summary> /// <param name="file">The file to read the definition from.</param> /// <returns>The number of styles that were loaded.</returns> int Create(StreamReader file) { // If we previously created stuff, get rid of it. ResetContents(); // Load an index for standard colour names Dictionary<string, Color> colors = LoadColors(); // Create the index of entity and/or layer name vs it's style m_StyleLookup = new Dictionary<string, Style>(100); string line; StyleEntry entry = new StyleEntry(); StringBuilder errors = new StringBuilder(1000); List<DashPattern> dashPatterns = new List<DashPattern>(100); List<Style> styles = new List<Style>(100); while ((line=file.ReadLine())!=null) { int nToken = entry.Parse(line); if (nToken == 0) continue; if (nToken < 0) { errors.AppendLine(String.Format("Invalid style entry: {0}", line)); continue; } // If we've got the definition of a dash style, // parse it and add to the list of styles if (entry.IsDashStyle) { DashPattern dp = new DashPattern(); if (dp.Create(entry)) dashPatterns.Add(dp); else errors.AppendLine(String.Format("Cannot parse style definition: {0}", line)); } else { // Only entity & layer entries are currently supported string itemName; if (entry.IsEntityEntry) itemName = entry.EntityToken; else if (entry.IsLayerEntry) itemName = entry.LayerToken; else continue; // Both entity & layer entries should have some sort of colour (either a // named colour, or an RGB value) Color col = Color.Black; bool colDefined = false; string colName = entry.ColToken; if (colName.Length==0) { string rgb = entry.RGBToken; colDefined = TryParseRGB(rgb, out col); } else { string fmtcol = FormatColorName(colName); colDefined = colors.ContainsKey(fmtcol); if (colDefined) col = colors[fmtcol]; } if (!colDefined) { errors.AppendLine(String.Format("Invalid colour in: {0}", line)); continue; } // Get any line pattern DashPattern dp = null; string pat = entry.DashToken; if (pat.Length > 0) { dp = dashPatterns.Find(d => d.Name==pat); if (dp==null) { errors.AppendLine(String.Format("Cannot find dash pattern for: {0}", line)); continue; } } // Get any line weight (sanity check forces it // to be in the range (0.01,10.0)) float fwt = -1.0F; string wt = entry.WtToken; if (wt.Length>0) { if (!Single.TryParse(wt, out fwt) || fwt<0.01F || fwt>10.0F) { errors.AppendLine(String.Format("Invalid line weight: {0}", line)); continue; } } // Create a suitable style Style style; if (fwt < 0.01F && dp==null) style = new Style(col); else style = new LineStyle(col, fwt, dp); // If we already have an identical style, use that instead Style prevStyle = styles.Find(s => style.IsMatch(s)); if (prevStyle!=null) m_StyleLookup[itemName] = prevStyle; else { styles.Add(style); m_StyleLookup[itemName] = style; } } } m_DashPatterns = dashPatterns.ToArray(); m_Styles = styles.ToArray(); if (errors.Length>0) throw new Exception(errors.ToString()); // Return the number of styles that we loaded. return m_Styles.Length; }
/// <summary> /// Returns the style associated with the specified name (which is expected to /// refer either to the name of an entity type, or the name of a layer) /// </summary> /// <param name="itemName">The name of the entity type or layer</param> /// <returns>The corresponding style (null if the supplied name could not be found /// in the style mapping, or a style file has not been loaded).</returns> internal Style GetStyle(string itemName) { if (m_StyleLookup == null) return null; if (m_LastLookup == itemName) return m_LastStyle; m_LastStyle = (m_StyleLookup.ContainsKey(itemName) ? m_StyleLookup[itemName] : null); m_LastLookup = itemName; return m_LastStyle; }
/// <summary> /// Does this style match the supplied style? The scale at which any pen /// has been defined gets ignored. /// </summary> /// <param name="style">The style to compare with</param> /// <returns>True if the supplied style is identical to this one.</returns> internal virtual bool IsMatch(Style style) { if (style==null) return false; if (Object.ReferenceEquals(style, this)) return true; // The display color must match return m_Color.Equals(style.Color); }
/// <summary> /// Does this style match the supplied style? /// </summary> /// <param name="style">The style to compare with</param> /// <returns>True if the supplied style is identical to this one.</returns> internal override bool IsMatch(Style style) { if (!(style is LineStyle)) return false; if (!base.IsMatch(style)) return false; // No match if the other style isn't also a line style LineStyle that = (style as LineStyle); if (that == null) return false; // Any dash pattern must have the same address in memory return (this.m_Style == that.m_Style && Object.ReferenceEquals(this.m_Pattern, that.m_Pattern) && Math.Abs(this.m_Weight-that.m_Weight) < 0.0001); }