protected override void OnFunctionValuesChanged(FunctionValuesChangedEventArgs e) { if (!IsIndependent) { return; } if (ChecksIfValuesAreUnique) { switch (e.Action) { // TODO incompatible with new events. case NotifyCollectionChangedAction.Add: uniqueValues.Add((T)e.Item); break; case NotifyCollectionChangedAction.Remove: uniqueValues.Remove((T)e.Item); break; case NotifyCollectionChangedAction.Replace: // remove previous value uniqueValues.Remove((T)e.Item); // add a new value var values = (IList)Values; uniqueValues.Add((T)values[e.Index]); break; } } }
private void locations_ValuesChanging(object sender, FunctionValuesChangedEventArgs e) { if (!(sender is IVariable <INetworkLocation>)) { return; } //don;t use 'locations'here it calls initialze and therefore very slow. switch (e.Action) { case NotifyCollectionChangedAction.Add: var location = (INetworkLocation)e.Item; if (location == null) { location = new NetworkLocation(network.Branches[0], 0); e.Item = location; } break; case NotifyCollectionChangedAction.Remove: break; default: throw new NotSupportedException(); } }
private void UpdateItemValue(FunctionValuesChangedEventArgs e, IList <T> values) { if (!GenerateUniqueValueForDefaultValue) { return; } if ((e.Item == null && DefaultValue == null) || (e.Item.Equals(DefaultValue) && e.Index > 0)) // add a new value using current DefaultStep (generate series) { object previousValue = default(T); if (values.Count != 0) { previousValue = values[e.Index - 1]; } e.Item = GetNextValue(previousValue); } }
private void UpdateInsertionIndex(FunctionValuesChangedEventArgs e, IList <T> values) { if ((typeof(T) == typeof(string))) { return; // doesn't matter, it is always unique + we don't care about objects } var oldIndex = e.Index; e.Index = MultiDimensionalArrayHelper.GetInsertionIndex((T)e.Item, values); if (e.Action == NotifyCollectionChangedAction.Replace) { if (e.Index > oldIndex) // !@#@#?????? { e.Index--; } } }
private void locations_ValuesChanged(object sender, FunctionValuesChangedEventArgs e) { if (!(e.Item is INetworkLocation)) { return; } var location = e.Item as INetworkLocation; if (location != null && location.Branch.Geometry != null && location.Geometry == null) // generate geometry for new location { var coordinate = GeometryHelper.LineStringCoordinate((ILineString)location.Branch.Geometry, location.Offset); location.Geometry = new Point(coordinate); } if (SegmentGenerationMethod != SegmentGenerationMethod.None) { segmentsInitialized = false; } initialized = false; }
private void function_ValuesChanged(object sender, FunctionValuesChangedEventArgs e) { if (changing) // this is dangerous, what if values change during list changes, rare but possible? { return; } changing = true; var argumentIndex = function.Arguments.IndexOf((IVariable)e.Function);; //find out the property descriptor for this function and raise event. switch (e.Action) { case NotifyCollectionChangedAction.Replace: OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, e.Index)); // log.DebugFormat("Function[{0}] value replaced {1}, number of rows: {2}", args.Function, e.Index, Count); break; case NotifyCollectionChangedAction.Add: // react only on chainges in arguments if (!function.Arguments.Contains((IVariable)e.Function)) { break; } // do nothing if at least 1 of arguments is empty if (function.Arguments.Any(a => a.Values.Count == 0)) { break; } // get number of rows to insert lock (function.Store) { var shape = function.Components[0].Values.Shape; //TODO : this would be wrong if not the dimensions is added. var countValuesToInsert = MultiDimensionalArrayHelper.GetTotalLength(shape.Skip(1).ToArray()); var index = new int[shape.Length]; for (var i = 0; i < countValuesToInsert; i++) { Insert(e.Index, new FunctionBindingListRow(this)); //rowIndices.Insert(e.Index, index); MultiDimensionalArrayHelper.IncrementIndex(index, shape, 0); } } // log.DebugFormat("Function[{0}] value added {1}, number of rows: {2}", args.Function, e.Index, Count); break; case NotifyCollectionChangedAction.Remove: lock (function.Store) { // react only on chainges in arguments if (!function.Arguments.Contains((IVariable)e.Function)) { break; } // 1d case, faster implementation if (function.Arguments.Count == 1) { RemoveAt(e.Index); break; } for (var i = Count - 1; i >= 0; i--) { if (this[i].Index[argumentIndex] == e.Index) { AllowRemove = true; RemoveAt(i); AllowRemove = false; } } } // log.DebugFormat("Function[{0}] value removed {1}, number of rows: {2}", args.Function, e.Index, Count); break; default: changing = false; throw new NotImplementedException(e.ToString()); } changing = false; }
private void RegularGridCoverage_ValuesChanged(object sender, FunctionValuesChangedEventArgs e) { isDirty = true; }
private void ValuesChanged(object sender, FunctionValuesChangedEventArgs e) { base.RenderRequired = true; }
//TODO : split out some logic here. We do a unique values administration AND determine insertion index. Split. protected override void OnFunctionValuesChanging(FunctionValuesChangedEventArgs e) { if (!IsIndependent) { return; } if (ChecksIfValuesAreUnique) { var values = (IList)Values; // check if we're replacing the same value if (e.Action == NotifyCollectionChangedAction.Replace && (e.Item.Equals(values[e.Index]))) { return; } } switch (e.Action) { case NotifyCollectionChangedAction.Replace: case NotifyCollectionChangedAction.Add: //objects need to be sorted as wel. Look at networklocations in a coverage. IList <T> values = null; if (ChecksIfValuesAreUnique || AutoSort) // performance optimization, get Values only when it is required { values = Values; } if (ChecksIfValuesAreUnique) { UpdateItemValue(e, values); } //find out where to insert. if (AutoSort) { UpdateInsertionIndex(e, values); } if (ChecksIfValuesAreUnique) { if (uniqueValues.Contains((T)e.Item)) { var message = string.Format( "Values added to independent variable must be unique, adding {0} at index {1}", e.Item, e.Index); throw new InvalidOperationException(message); } } //TODO : keep a good sort order!!. Nu 5 uur en tijd om te gaan. break; case NotifyCollectionChangedAction.Remove: break; default: break; } }