public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent) { int count = info.OpenArray(); IG2DPlotStyle[] array = new IG2DPlotStyle[count]; for (int i = 0; i < count; i++) { array[i] = (IG2DPlotStyle)info.GetValue("e", this); } info.CloseArray(count); if (o == null) { return(new G2DPlotStyleCollection(array)); } else { G2DPlotStyleCollection s = (G2DPlotStyleCollection)o; for (int i = count - 1; i >= 0; i--) { s.Add(array[i]); } return(s); } }
public void SetFromTemplate(G2DPlotStyleCollection from, PlotGroupStrictness strictness) { if (strictness == PlotGroupStrictness.Strict) { CopyFromTemplateCollection(from); // take the whole style collection as is from the template, but try to reuse the additionally needed data columns from the old style } else if (strictness == PlotGroupStrictness.Exact) { // note one sub style in the 'from' collection can update only one item in the 'this' collection using (var suspendToken = SuspendGetToken()) { var indicesFrom = new SortedSet <int>(System.Linq.Enumerable.Range(0, from.Count)); for (int i = 0; i < Count; ++i) { var thisStyleType = this[i].GetType(); // search in from for a style with the same name foreach (var fromIndex in indicesFrom) { if (thisStyleType == from[fromIndex].GetType()) { this[i].CopyFrom(from[fromIndex], false); indicesFrom.Remove(fromIndex); // this from style was used, thus remove it break; } } } suspendToken.Resume(); } } }
public void SetFromTemplate(G2DPlotStyleCollection from, PlotGroupStrictness strictness) { if (strictness == PlotGroupStrictness.Strict) { CopyFrom(from); } else if (strictness == PlotGroupStrictness.Exact) { // note one sub style in the 'from' collection can update only one item in the 'this' collection Suspend(); int myidx = 0; foreach (IG2DPlotStyle style in from) { for (int i = myidx; i < this.Count; i++) { if (this[i].GetType() == style.GetType()) { Replace((IG2DPlotStyle)from[i].Clone(), i, false); myidx = i + 1; break; } } } Resume(); } }
static G2DPlotStyleCollection CreateLabelStyle() { G2DPlotStyleCollection coll = new G2DPlotStyleCollection(LineScatterPlotStyleKind.Empty); coll.Add(new LabelPlotStyle()); return(coll); }
private static G2DPlotStyleCollection CreateLabelStyle(Altaxo.Main.Properties.IReadOnlyPropertyBag context) { var coll = new G2DPlotStyleCollection(LineScatterPlotStyleKind.Empty, context) { new LabelPlotStyle(context) }; return(coll); }
static TypeArray GetTypeArray(G2DPlotStyleCollection coll) { System.Type[] types = new Type[coll.Count]; for (int i = 0; i < types.Length; i++) { types[i] = coll[i].GetType(); } return(new TypeArray(types)); }
public void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info) { G2DPlotStyleCollection s = (G2DPlotStyleCollection)obj; info.CreateArray("Styles", s._innerList.Count); for (int i = 0; i < s._innerList.Count; i++) { info.AddValue("e", s._innerList[i]); } info.CommitArray(); }
public static int GetIndexOfAvailableNamesPlusCustom(G2DPlotStyleCollection coll) { string name = GetName(coll); if (null == name) { return(0); } int result = _NamesInOrder.IndexOf(name); return(result < 0 ? 0 : result + 1); }
public void CopyFrom(G2DPlotStyleCollection from) { Suspend(); Clear(); this._innerList = new List <IG2DPlotStyle>(); for (int i = 0; i < from._innerList.Count; ++i) { Add((IG2DPlotStyle)from[i].Clone()); } this._parent = from._parent; Resume(); }
public static void Add(string name, CreateCollectionProcedure procedure) { if (_CreationProcByName.ContainsKey(name)) { throw new Exception(string.Format("Template {0} is already present in the template collection", name)); } G2DPlotStyleCollection coll = procedure(); if (coll == null || coll.Count == 0) { throw new Exception(string.Format("Procedure for template {0} creates no or an empty collection.", name)); } _NamesInOrder.Add(name); _CreationProcByName.Add(name, procedure); _NamesByTypeArray.Add(GetTypeArray(coll), name); }
public void CopyFrom(G2DPlotStyleCollection from) { if (object.ReferenceEquals(this, from)) { return; } using (var suspendToken = SuspendGetToken()) { Clear(); _innerList = new List <IG2DPlotStyle>(); for (int i = 0; i < from._innerList.Count; ++i) { Add((IG2DPlotStyle)from[i].Clone()); } suspendToken.Resume(); } }
/// <summary> /// Copies all styles 1:1 from a template collection, but try to reuse the data columns from /// the old styles collection. This function is used if the user has selected the <see cref="PlotGroupStrictness.Strict"/>. /// </summary> /// <param name="from">The template style collection to copy from.</param> /// <returns>On return, this collection has exactly the same styles as the template collection, in /// exactly the same order and with the same properties, except for the data of the styles. The style data /// are tried to reuse from the old styles. If this is not possible, the data references will be left empty.</returns> public bool CopyFromTemplateCollection(G2DPlotStyleCollection from) { if (object.ReferenceEquals(this, from)) { return(true); } using (var suspendToken = SuspendGetToken()) { var oldInnerList = _innerList; _innerList = new List <IG2DPlotStyle>(); for (int i = 0; i < from._innerList.Count; ++i) { var fromStyleType = from[i].GetType(); // try to find the same style in the old list, and use the data from this style int foundIdx = oldInnerList.IndexOfFirst(item => item.GetType() == fromStyleType); IG2DPlotStyle clonedStyle; if (foundIdx >= 0) // if old style list has such an item, we clone that item, and then CopyFrom (but without data) { clonedStyle = (IG2DPlotStyle)oldInnerList[foundIdx].Clone(true); // First, clone _with_ the old data because we want to reuse them clonedStyle.CopyFrom(from[i], false); // now copy the properties from the template style, but _without_ the data oldInnerList.RemoveAt(foundIdx); // remove the used style now } else // an old style of the same type was not found { clonedStyle = (IG2DPlotStyle)from[i].Clone(false); // clone the style without data } Add(clonedStyle); } suspendToken.Resume(); } return(true); }
public G2DPlotStyleCollection(G2DPlotStyleCollection from) { CopyFrom(from); }
public static string GetName(G2DPlotStyleCollection coll) { return((string)_NamesByTypeArray[GetTypeArray(coll)]); }