private List<string> ExportSymbol(IStyleGallery sg,string symbolType, int col, int row, int size,int width, int labelsize, int label_h, int size_w, int size_h, double height, string cat, IPageLayout3 layout) { List<string> pdfpages = new List<string>(); IGraphicsContainer con = layout as IGraphicsContainer; IPage page = layout.Page; int r = 0; int c = 0; int p = 0; IEnumStyleGalleryItem items = sg.get_Items(symbolType, "", cat); IStyleGalleryItem item = items.Next(); while (item != null) { #region Symbol if (symbolType == "Marker Symbols") { IMarkerElement mele = new MarkerElementClass(); IPoint ptn = new PointClass(); ptn.PutCoords(c * size_w + size / 2, height - (r * size_h + size / 2)); IElement ele_i = mele as IElement; ele_i.Geometry = ptn; IMarkerSymbol sym_m = item.Item as IMarkerSymbol; sym_m.Size = size; mele.Symbol = sym_m; con.AddElement(ele_i, 0); } else if (symbolType == "Line Symbols") { ILineElement lele = new LineElementClass(); IPolyline line = new PolylineClass(); IPoint ptn_f = new PointClass(); ptn_f.PutCoords(c * size_w + size / 4, height - (r * size_h + size * 3 / 4)); IPoint ptn_t = new PointClass(); ptn_t.PutCoords(c * size_w + size * 3 / 4, height - (r * size_h + size / 4)); line.FromPoint = ptn_f; line.ToPoint = ptn_t; IElement ele_i = lele as IElement; ele_i.Geometry = line; ILineSymbol sym_l = item.Item as ILineSymbol; sym_l.Width = width; lele.Symbol = sym_l; con.AddElement(ele_i, 0); } else if (symbolType == "Fill Symbols") { IRectangleElement fele = new RectangleElementClass(); IFillShapeElement fsele = fele as IFillShapeElement; IEnvelope env_f = new EnvelopeClass(); env_f.PutCoords(c * size_w + size / 4, height - (r * size_h + size * 3 / 4), c * size_w + size * 3 / 4, height - (r * size_h + size / 4)); IElement ele_i = fele as IElement; ele_i.Geometry = env_f; IFillSymbol sym_f = item.Item as IFillSymbol; fsele.Symbol = sym_f; con.AddElement(ele_i, 0); } #endregion if (cbGrid.Checked) { #region Grid IEnvelope env_g = new EnvelopeClass(); env_g.PutCoords(c * size_w, height - r * size_h, c * size_w + size_w, height - r * size_h - size_h); IRectangleElement gele = new RectangleElementClass(); IElement ele_g = gele as IElement; ele_g.Geometry = env_g; IFillSymbol sym_g = new SimpleFillSymbolClass(); IRgbColor color_g = new RgbColorClass(); color_g.NullColor = true; sym_g.Color = color_g; IFillShapeElement fshp_g = ele_g as IFillShapeElement; fshp_g.Symbol = sym_g; con.AddElement(ele_g, 0); #endregion } #region Label ITextElement tele = new ParagraphTextElementClass(); IElement ele_t = tele as IElement; tele.Text = item.Name; IEnvelope env_l = new EnvelopeClass(); env_l.PutCoords(c * size_w, height - r * size_h - size_h + label_h, c * size_w + size_w, height - r * size_h - size_h); env_l.PutCoords(c * size_w, height - r * size_h - size_h + label_h, c * size_w + size_w, height - r * size_h - size_h); env_l.PutCoords(c * size_w, height - r * size_h - size_h + label_h, c * size_w + size_w, height - r * size_h - size_h); env_l.PutCoords(c * size_w, height - r * size_h - size_h + label_h, c * size_w + size_w, height - r * size_h - size_h); env_l.PutCoords(c * size_w, height - r * size_h - size_h + label_h, c * size_w + size_w, height - r * size_h - size_h); ele_t.Geometry = env_l; ITextSymbol sym_label = new TextSymbolClass(); sym_label.Size = labelsize/2; IRgbColor color = new RgbColorClass(); color.NullColor = true; ISimpleLineSymbol sym_border = new SimpleLineSymbolClass(); sym_border.Color = color; ISymbolBorder border = new SymbolBorderClass(); border.LineSymbol = sym_border; IFrameProperties fp = ele_t as IFrameProperties; fp.Border = border; con.AddElement(ele_t, 0); #endregion if (c < col - 1) { c++; } else { c = 0; if (r < row - 1) { r++; } else { IActiveView av = layout as IActiveView; string temp_pdf = System.IO.Path.GetTempFileName() + ".pdf"; ExportPDF(av, temp_pdf); pdfpages.Add(temp_pdf); con.DeleteAllElements(); r = 0; c = 0; p++; } } item = items.Next(); } if (con.Next() != null) { IActiveView av = layout as IActiveView; string temp_pdf = System.IO.Path.GetTempFileName() + ".pdf"; ExportPDF(av, temp_pdf); pdfpages.Add(temp_pdf); con.DeleteAllElements(); } return pdfpages; }
public clsGxStyleGallery() : base() { m_pChildren = new GxObjectArray(); m_childrenLoaded = false; m_pGallery = new ESRI.ArcGIS.Framework.StyleGallery(); }
private void ProcessStyleGalleryItems(IStyleGallery styleGallery, string styleClass) { if ((styleGallery == null) || string.IsNullOrEmpty(styleClass)) { Console.WriteLine("ERROR: Style Gallery NULL"); return; } System.Diagnostics.Trace.WriteLine("ProcessStyleGalleryItems for class: " + styleClass); IEnumStyleGalleryItem ge = styleGallery.get_Items(styleClass, "", ""); if (ge == null) { Console.WriteLine("ERROR: No Items for Style Class:" + styleClass); return; } int count = 0; IStyleGalleryItem item = null; while ((item = ge.Next()) != null) { try { if (!ID2StyleGalleryItemDictionary.ContainsKey(item.Name)) { IStyleGalleryItem2 item2 = item as IStyleGalleryItem2; if (item2 != null) { // split the tags into list var tagList = item2.Tags.Split(new char[] { ';' }); // reverse the list so we can easily locate the symbol ID code tag var tagListReversed = tagList.Reverse(); // IMPORTANT: assumes SIC is always first in reversed list (last in original list) string lastTag = tagListReversed.ElementAt(0); string sidcTag = lastTag.ToUpper().Trim(); // WORKAROUND: for for some erroneous cases: string sidcNoStars = sidcTag.Replace('*', '-'); if ((!IsValidSic(sidcNoStars)) && (sidcNoStars.Length > 10)) LogDebug(String.Format("***Style Item SIDC: {0} does not appear to be a valid, length = {1}", sidcNoStars, sidcNoStars.Length)); string sidcNoSpaces = sidcNoStars.Replace(" ", ""); if (sidcNoSpaces.Length > 15) sidcNoSpaces = sidcNoSpaces.Remove(15); // END WORKAROUND string sidc = sidcNoSpaces; if (string.IsNullOrEmpty(sidc)) { // It has an empty SIC (Some of the entries have blank SICs) LogDebug(String.Format("No SIDC found for Item Name: {0}", item.Name)); } else { if (!SIC2SymbolNameDictionary.ContainsKey(sidc)) { string itemName = item.Name; if ((styleClass.StartsWith("Rep")) && ((sidc[0] == 'G') || (sidc[0] == 'W'))) { int len = itemName.Length; if ((len > 2) && (itemName.EndsWith("F") || itemName.EndsWith("H") || itemName.EndsWith("N") || itemName.EndsWith("U"))) itemName = itemName.Remove(len - 2); } count++; // If debug output needed during StyleFile read: // LogDebug("#" + count + ", Item Name: " + itemName + ", SIDC: " + sidc); if (!ID2StyleGalleryItemDictionary.ContainsKey(itemName)) ID2StyleGalleryItemDictionary.Add(itemName, item); else if (!styleClass.StartsWith("Rep")) // multiple items are expected for rep rules LogDebug(String.Format("*** Failed to add a SIC to ID2StyleGalleryItemDictionary: {0}, {1}, {2}, {3}", item.Name, sidc, sidc.Length, IsValidSic(sidc) ? "Valid" : "INVALID")); if (!SIC2SymbolNameDictionary.ContainsKey(sidc)) { SIC2SymbolNameDictionary.Add(sidc, itemName); } else LogDebug(String.Format("*** Failed to add a SIC to SIC2SymbolNameDictionary: {0}, {1}, {2}, {3}", item.Name, sidc, sidc.Length, IsValidSic(sidc) ? "Valid" : "INVALID")); } } } } } catch (Exception ex) { LogError(String.Format("Error loading marker symbol from style item, {0}", item.Name)); LogError(ex.ToString()); Console.WriteLine(ex); } } System.Runtime.InteropServices.Marshal.ReleaseComObject(ge); ge = null; }