public void SetFromTemplate(G3DPlotStyleCollection 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(); } } }
private static G3DPlotStyleCollection CreateScatterStyle(Altaxo.Main.Properties.IReadOnlyPropertyBag context) { var coll = new G3DPlotStyleCollection { new ScatterPlotStyle(context) }; return(coll); }
private static TypeArray GetTypeArray(G3DPlotStyleCollection coll) { var types = new Type[coll.Count]; for (int i = 0; i < types.Length; i++) { types[i] = coll[i].GetType(); } return(new TypeArray(types)); }
public static int GetIndexOfAvailableNamesPlusCustom(G3DPlotStyleCollection coll) { string name = GetName(coll); if (null == name) { return(0); } int result = _NamesInOrder.IndexOf(name); return(result < 0 ? 0 : result + 1); }
public void CopyFrom(G3DPlotStyleCollection from) { if (object.ReferenceEquals(this, from)) { return; } using (var suspendToken = SuspendGetToken()) { Clear(); _innerList = new List <IG3DPlotStyle>(); for (int i = 0; i < from._innerList.Count; ++i) { Add((IG3DPlotStyle)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(G3DPlotStyleCollection from) { if (object.ReferenceEquals(this, from)) { return(true); } using (var suspendToken = SuspendGetToken()) { var oldInnerList = _innerList; _innerList = new List <IG3DPlotStyle>(); 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); IG3DPlotStyle clonedStyle; if (foundIdx >= 0) // if old style list has such an item, we clone that item, and then CopyFrom (but without data) { clonedStyle = (IG3DPlotStyle)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 = (IG3DPlotStyle)from[i].Clone(false); // clone the style without data } Add(clonedStyle); } suspendToken.Resume(); } return(true); }
public static string GetName(G3DPlotStyleCollection coll) { return((string)_NamesByTypeArray[GetTypeArray(coll)]); }
public G3DPlotStyleCollection(G3DPlotStyleCollection from) { CopyFrom(from, true); }