/// <summary> /// Find symbol by name (without adding) /// </summary> /// <param name="symbolset">The symbolset object</param> /// <param name="key_to_find">the symbol name to search for</param> /// <returns>Symbol found or null</returns> public static symbolObj FindSymbol(symbolSetObj symbolset, string name_to_find) { if (name_to_find != null) { for (int i = 0; i < symbolset.numsymbols; i++) { symbolObj sym = symbolset.getSymbol(i); if (sym.name != null && sym.name.ToLower() == name_to_find.ToLower()) { return(sym); } } } return(null); }
/// <summary> /// Find symbol by name (without adding) /// </summary> /// <param name="symbolset">The symbolset object</param> /// <param name="key_to_find">the symbol name to search for</param> /// <returns>Symbol found or null</returns> public static symbolObj FindSymbol(symbolSetObj symbolset, string name_to_find) { if (name_to_find != null) { for (int i = 0; i < symbolset.numsymbols; i++) { symbolObj sym = symbolset.getSymbol(i); if (sym.name != null && sym.name.ToLower() == name_to_find.ToLower()) return sym; } } return null; }
/// <summary> /// Validating event handler of the scintillaControlSymbolset control. /// </summary> /// <param name="sender">The source object of this event.</param> /// <param name="layer">The selected layer.</param> private void scintillaControlSymbolset_Validating(object sender, CancelEventArgs e) { if (symbolsetChanged) { // validating string fileName = Path.GetTempFileName(); try { File.WriteAllText(fileName, scintillaControlSymbolset.Text); // test whether we can parse the symbolset symbolSetObj s = new symbolSetObj(fileName); // make sure we have all symbol references Hashtable symbolNames = new Hashtable(); for (int i = 0; i < s.numsymbols; i++) { string symbolName = s.getSymbol(i).name; if (symbolName != null && !symbolNames.ContainsKey(symbolName)) { symbolNames.Add(symbolName, symbolName); } } mapObj map = StyleLibrary.Styles; s = map.symbolset; for (int i = 0; i < s.numsymbols; i++) { symbolObj sym = s.getSymbol(i); string symbolName = sym.name; if (symbolName != null && sym.inmapfile == mapscript.MS_TRUE && !symbolNames.ContainsKey(symbolName)) { symbolNames.Add(symbolName, symbolName); } } for (int i = 0; i < map.numlayers; i++) { layerObj layer = map.getLayer(i); for (int j = 0; j < layer.numclasses; j++) { classObj classobj = layer.getClass(j); for (int k = 0; k < classobj.numstyles; k++) { string symbolName = classobj.getStyle(k).symbolname; if (symbolName != null && !symbolNames.ContainsKey(symbolName)) { throw new Exception("Symbol name '" + symbolName + "' is missing from the symbolset file!"); } } } } } catch (Exception ex) { if (MessageBox.Show(ex.Message + "\n\rPress OK to correct the errors or Cancel to ignore the changes!", "MapManager", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK) { e.Cancel = true; } else { LoadSymbolset(); } return; } finally { if (File.Exists(fileName)) { File.Delete(fileName); } } // validation ok, ask whether to save or not DialogResult res = MessageBox.Show("Do you wish to save the modifications of the symbolset?", "MapManager", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (res == DialogResult.Yes) { SaveSymbolset(); // the symbolset has changed, need to reload view timerRefresh.Enabled = true; } else if (res == DialogResult.No) { LoadSymbolset(); } else if (res == DialogResult.Cancel) { e.Cancel = true; } } }
/// <summary> /// Validating event handler of the scintillaControlSymbolset control. /// </summary> /// <param name="sender">The source object of this event.</param> /// <param name="layer">The selected layer.</param> private void scintillaControlSymbolset_Validating(object sender, CancelEventArgs e) { if (symbolsetChanged) { // validating string fileName = Path.GetTempFileName(); try { File.WriteAllText(fileName, scintillaControlSymbolset.Text); // test whether we can parse the symbolset symbolSetObj s = new symbolSetObj(fileName); // make sure we have all symbol references Hashtable symbolNames = new Hashtable(); for (int i = 0; i < s.numsymbols; i++) { string symbolName = s.getSymbol(i).name; if (symbolName != null && !symbolNames.ContainsKey(symbolName)) symbolNames.Add(symbolName, symbolName); } mapObj map = StyleLibrary.Styles; s = map.symbolset; for (int i = 0; i < s.numsymbols; i++) { symbolObj sym = s.getSymbol(i); string symbolName = sym.name; if (symbolName != null && sym.inmapfile == mapscript.MS_TRUE && !symbolNames.ContainsKey(symbolName)) symbolNames.Add(symbolName, symbolName); } for (int i = 0; i < map.numlayers; i++) { layerObj layer = map.getLayer(i); for (int j = 0; j < layer.numclasses; j++) { classObj classobj = layer.getClass(j); for (int k = 0; k < classobj.numstyles; k++) { string symbolName = classobj.getStyle(k).symbolname; if (symbolName != null && !symbolNames.ContainsKey(symbolName)) throw new Exception("Symbol name '" + symbolName + "' is missing from the symbolset file!"); } } } } catch (Exception ex) { if (MessageBox.Show(ex.Message + "\n\rPress OK to correct the errors or Cancel to ignore the changes!", "MapManager", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK) e.Cancel = true; else { LoadSymbolset(); } return; } finally { if (File.Exists(fileName)) File.Delete(fileName); } // validation ok, ask whether to save or not DialogResult res = MessageBox.Show("Do you wish to save the modifications of the symbolset?", "MapManager", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (res == DialogResult.Yes) { SaveSymbolset(); // the symbolset has changed, need to reload view timerRefresh.Enabled = true; } else if (res == DialogResult.No) { LoadSymbolset(); } else if (res == DialogResult.Cancel) e.Cancel = true; } }