/// <summary> /// Returns deep copy of this instance /// </summary> /// <returns></returns> public IClonable Clone() { ColorTheme thisClone = new ColorTheme(); foreach (ColorInfo colorInfo in m_AppInterfaceColorsDictionary.Values) { if (colorInfo == null || string.IsNullOrEmpty(colorInfo.SystemName)) { continue; } ColorInfo colorInfoClone = colorInfo.Clone() as ColorInfo; if (colorInfoClone == null || string.IsNullOrEmpty(colorInfoClone.SystemName)) { continue; } thisClone.AddInterfaceColor(colorInfoClone); } if (m_GeometryColorsTheme != null) { thisClone.GeometryColorsTheme = m_GeometryColorsTheme.Clone() as IGeometryColorsTheme; } return(thisClone); }
/// <summary> /// Read colors from stream /// </summary> public bool ReadFromStream(StreamReader sr) { if (sr == null) { return(false); } bool bInterfaceColor = false; bool bGeometryColor = false; string line; while ((line = sr.ReadLine()) != null) { if (HEADER_INTERFACE_COLORS == line) { bInterfaceColor = true; bGeometryColor = false; } else if (HEADER_GEOMETRY_COLORS == line) { bInterfaceColor = false; bGeometryColor = true; } else { string[] arr = line.Split(COLORINFO_VALUES_DELIMITER); if (arr.Count() >= 2) { string sysname = arr[0]; string value = arr[1]; string localname = string.Empty; if (arr.Count() >= 3) { localname = arr[2]; } string description = string.Empty; if (arr.Count() >= 4) { description = arr[3]; } if (string.IsNullOrEmpty(sysname)) { continue; } Color colorValue = Colors.Black; try { colorValue = (Color)ColorConverter.ConvertFromString(value); } catch { continue; } if (bInterfaceColor) { ColorInfo colorInfo = new ColorInfo(sysname, colorValue, localname, description); AddInterfaceColor(colorInfo); } else if (bGeometryColor) { eColorType colorType = ColorTheme.SystemNameToColorType(sysname); AddGeometryColor(colorType, colorValue); //// replace local name and descriptions //if (m_ColorTypeToDescriptionDict != null && m_ColorTypeToDescriptionDict.ContainsKey(colorType)) // m_ColorTypeToDescriptionDict[colorType] = description; //if (m_ColorTypeToLocalNameDict != null && m_ColorTypeToLocalNameDict.ContainsKey(colorType)) // m_ColorTypeToLocalNameDict[colorType] = localname; } } } } return(true); }
/// <summary> /// Write color theme to file /// </summary> public bool WriteToFile(string filePath) { if (string.IsNullOrEmpty(filePath)) { return(false); } using (StreamWriter fs = new StreamWriter(filePath, false)) { // STEP 1. Write interface colors fs.WriteLine(HEADER_INTERFACE_COLORS); foreach (ColorInfo interfaceColorInfo in m_AppInterfaceColorsDictionary.Values) { if (interfaceColorInfo == null || string.IsNullOrEmpty(interfaceColorInfo.SystemName)) { continue; } string localName = interfaceColorInfo.LocalName; if (string.IsNullOrEmpty(localName)) { localName = interfaceColorInfo.SystemName; } StringBuilder sb = new StringBuilder(); sb.Append(interfaceColorInfo.SystemName); sb.Append(COLORINFO_VALUES_DELIMITER); sb.Append(interfaceColorInfo.Value.ToString()); sb.Append(COLORINFO_VALUES_DELIMITER); sb.Append(localName); sb.Append(COLORINFO_VALUES_DELIMITER); sb.Append(interfaceColorInfo.Description); sb.Append(COLORINFO_VALUES_DELIMITER); fs.WriteLine(sb.ToString()); } fs.WriteLine(); // STEP 2. Write geometry colors fs.WriteLine(HEADER_GEOMETRY_COLORS); if (m_GeometryColorsTheme != null) { foreach (eColorType colorType in (eColorType[])Enum.GetValues(typeof(eColorType))) { if (eColorType.eUndefined == colorType) { continue; } Color colorValue; if (!m_GeometryColorsTheme.GetGeometryColor(colorType, out colorValue)) { continue; } string sysName = ColorTheme.ColorTypeToSystemName(colorType); string locName = ColorTheme.ColorTypeToLocalName(colorType); string description = ColorTheme.ColorTypeToDescription(colorType); if (string.IsNullOrEmpty(sysName)) { continue; } StringBuilder sb = new StringBuilder(); sb.Append(sysName); sb.Append(COLORINFO_VALUES_DELIMITER); sb.Append(colorValue.ToString()); sb.Append(COLORINFO_VALUES_DELIMITER); sb.Append(locName); sb.Append(COLORINFO_VALUES_DELIMITER); sb.Append(description); sb.Append(COLORINFO_VALUES_DELIMITER); fs.WriteLine(sb.ToString()); } } fs.WriteLine(); fs.Close(); } return(true); }