Beispiel #1
0
        //--------------------------------------------------------------------------------------------------

        void _InitializeCustomRatioItems()
        {
            if (BoxJoint.CustomBoxRatios == null)
            {
                return;
            }

            if (BoxJoint.BoxCount != CustomRatioItems.Count)
            {
                CustomRatioItems.Clear();
            }

            // Update
            for (int i = 0; i < BoxJoint.CustomBoxRatios.Length; i++)
            {
                var item = new CustomRatioItem()
                {
                    Index    = i,
                    Value    = BoxJoint.CustomBoxRatios[i],
                    ReadOnly = i == BoxJoint.CustomBoxRatios.Length - 1
                };
                if (CustomRatioItems.Count > i)
                {
                    CustomRatioItems[i] = item;
                }
                else
                {
                    CustomRatioItems.Add(item);
                }
            }
        }
Beispiel #2
0
        //--------------------------------------------------------------------------------------------------

        void _BoxJoint_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(BoxJoint.BoxCount))
            {
                if (BoxJoint.CustomBoxRatios == null)
                {
                    return;
                }

                if (BoxJoint.BoxCount <= 1)
                {
                    return;
                }

                int countDiff = BoxJoint.BoxCount - CustomRatioItems.Count;
                if (countDiff == 0)
                {
                    return;
                }

                if (countDiff > 0)
                {
                    // New Items
                    double newRatio = CustomRatioItems.Last().Value / (countDiff + 1);
                    for (int i = CustomRatioItems.Count - 1; i < BoxJoint.BoxCount; i++)
                    {
                        var item = new CustomRatioItem()
                        {
                            Index    = i,
                            Value    = newRatio,
                            ReadOnly = i == CustomRatioItems.Count
                        };
                        if (i >= CustomRatioItems.Count)
                        {
                            CustomRatioItems.Add(item);
                        }
                        else
                        {
                            CustomRatioItems[i] = item;
                        }
                    }
                }
                else
                {
                    // Lost Items
                    while (CustomRatioItems.Count > BoxJoint.BoxCount)
                    {
                        CustomRatioItems.RemoveAt(CustomRatioItems.Count - 1);
                    }

                    _ClampLastItem();
                }

                _BuildCustomRatios();
            }
        }