예제 #1
0
        private void OnFunctionValuesChanged(object sender, FunctionValuesChangingEventArgs e)
        {
            if (function == null || function.IsEditing)
            {
                return;
            }

            //should not a delayedEventHandler be used?
            if (!DelayedEventHandlerController.FireEvents)
            {
                return;
            }

            if (changingFromGui)
            {
                return;
            }

            while (changing)
            {
                Wait();
            }

            changing = true;

            //find out the property descriptor for this function and raise event.
            switch (e.Action)
            {
            case NotifyCollectionChangeAction.Reset:
                Clear();
                changing = false;
                Fill();
                changing = true;
                break;

            case NotifyCollectionChangeAction.Replace:
                OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, e.Index));
                break;

            case NotifyCollectionChangeAction.Add:
                OnFunctionValuesAdd(e);
                break;

            case NotifyCollectionChangeAction.Remove:
                OnFunctionValuesRemoved(e);
                break;

            default:
                changing = false;
                throw new NotImplementedException(e.ToString());
            }

            if (FunctionValuesChanged != null)
            {
                FunctionValuesChanged(sender, e);
            }

            changing = false;
        }
예제 #2
0
        protected virtual void OnFunctionValuesChanged(object sender, FunctionValuesChangingEventArgs e)
        {
            if (changingFromGui)
            {
                return;
            }

            while (changing)
            {
                Thread.Sleep(0); // wait until other change has been processed
            }

            changing = true;

            //find out the property descriptor for this function and raise event.
            switch (e.Action)
            {
            case NotifyCollectionChangeAction.Reset:
                Clear();
                changing = false;
                Fill();
                changing = true;
                break;

            case NotifyCollectionChangeAction.Replace:
                OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, e.Index));
                break;

            case NotifyCollectionChangeAction.Add:
                OnFunctionValuesAdded(e);
                break;

            case NotifyCollectionChangeAction.Remove:
                OnFunctionValuesRemoved(e);
                break;

            default:
                changing = false;
                throw new NotImplementedException(e.ToString());
            }

            FireFunctionValuesChanged(sender, e);

            changing = false;
        }
예제 #3
0
        private void function_ValuesChanged(object sender, FunctionValuesChangingEventArgs e)
        {
            if (changingFromGui)
            {
                return;
            }

            while (changing)
            {
                Thread.Sleep(0); // wait until other change has been processed
            }

            changing = true;

            IFunction function = e.Function;

            //find out the property descriptor for this function and raise event.
            switch (e.Action)
            {
            case NotifyCollectionChangeAction.Reset:
                Clear();
                ResetBindings();
                changing = false;
                Fill();
                changing = true;
                break;

            case NotifyCollectionChangeAction.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 NotifyCollectionChangeAction.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
                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 MultipleFunctionBindingListRow(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 NotifyCollectionChangeAction.Remove:
                // 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;
                }

                var argumentIndex = function.Arguments.IndexOf((IVariable)e.Function);

                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;
        }