public static StyleCollection CreateByName(String styleName) { StyleCollection res = new StyleCollection(); String styleDir = Directories.GetConfigDirectory(); String styleFile = System.IO.Path.Combine(styleDir, styleName); if (styleName.ToLower() == DefaultName.ToLower()) { res.SetDefault(); return(res); } else if (System.IO.File.Exists(styleFile)) { try { LoadStyleCollection(res, styleFile); } catch (Exception) { UserErrors.ConfigFileCorrupted(styleName, "using default style"); res.SetDefault(); } return(res); } else { throw new ApplicationException("Internal error - cannot find style file"); } }
public Object Clone() { StyleCollection res = new StyleCollection(); List <StyleObject> allStyles = new List <StyleObject>(); res.AllStyles = allStyles; res.Poles = Poles.Clone() as PoleStyle; allStyles.Add(res.Poles); res.Tubes = Tubes.Clone() as TubeStyle; allStyles.Add(res.Tubes); res.Chromosomes = Chromosomes.Clone() as ChromosomeStyle; allStyles.Add(res.Chromosomes); res.Springs = Springs.Clone() as SpringStyle; allStyles.Add(res.Springs); res.Cell = Cell.Clone() as CellStyle; allStyles.Add(res.Cell); return(res); }
public DefaultStyleAspect() { // No selection by default. SelectedObject = null; // Loading required style for unselected objects. try { _unSelected = StyleManager.CreateByName(SettingsManager.GetRef().RenderSettings.StyleName); } catch (Exception) { UserErrors.SettingsFileCorrupted("using default style"); SettingsManager.GetRef().RenderSettings.StyleName = StyleManager.DefaultName; _unSelected = StyleManager.CreateByName(StyleManager.DefaultName); } // Creating style for selected objects. _selected = _unSelected.Clone() as StyleCollection; Material selectedMat = new Material(new SlimDX.Vector4(0.9f, 0.1f, 0.1f, 1.0f), new SlimDX.Vector4(0.0f, 0.0f, 0.0f, 1.0f), new SlimDX.Vector4(0.05f, 0.05f, 0.05f, 1.0f)); foreach (var style in _selected.AllStyles) { style.SetProperties(selectedMat); } }
public ObjectSelectingStyleAspect() { _styles = StyleManager.CreateByName(StyleManager.DefaultName); _bitsPerMajorID = 4; _bitsPerMinorID = 20; _typeToMajorId = new Dictionary <Type, int>(); _typeToMajorId.Add(typeof(Pole), 1); _typeToMajorId.Add(typeof(MT), 2); _typeToMajorId.Add(typeof(Chromosome), 4); _majorIdToRetriever = new Dictionary <int, ObjectRetriever>(); _majorIdToRetriever.Add(1, RetrievePole); _majorIdToRetriever.Add(2, RetrieveMT); _majorIdToRetriever.Add(4, RetrieveChromosome); }
private static void LoadStyleCollection(StyleCollection collection, String xmlFilename) { XmlDocument doc = new XmlDocument(); doc.Load(xmlFilename); XmlNode root = null; foreach (XmlNode node in doc.ChildNodes) { if (node.Name == "Style") { root = node; break; } } Dictionary <String, bool> loadedStyles = new Dictionary <string, bool>(); foreach (var obj in collection.AllStyles) { loadedStyles[obj.Name] = false; } var allStyles = new List <StyleObject>(collection.AllStyles); foreach (XmlNode node in root.ChildNodes) { StyleObject match = allStyles.Find(styleObject => styleObject.Name.ToLower() == node.Name.ToLower()); if (match != null) { LoadStyle(match, node); loadedStyles[match.Name] = true; } } foreach (StyleObject obj in collection.AllStyles) { if (!loadedStyles[obj.Name]) { throw new ApplicationException("Failed to load some sections from style file"); } } }