Exemplo n.º 1
0
            /// <summary>
            /// Creates a new PeriodMatrix for the specified day's periods.
            /// </summary>
            public PeriodMatrix(StudyDay day)
            {
                _positions        = new Dictionary <Period, int>();
                _widthMultipliers = new Dictionary <Period, double>();

                int[] periodsPerInterval = new int[HoursInDay * MinutesInHour / CollisionCheckingInterval];

                foreach (var period in day.Periods)
                {
                    IterateOverIntervals(period, periodsPerInterval, n => periodsPerInterval[n]++);
                }

                ColumnCount = periodsPerInterval.Max();
                int[] remainingPeriods = (int[])periodsPerInterval.Clone();

                foreach (var period in day.Periods)
                {
                    int collisions = 1;
                    int column     = 0;

                    IterateOverIntervals(period, periodsPerInterval, n => collisions = Math.Max(collisions, periodsPerInterval[n]));
                    IterateOverIntervals(period, remainingPeriods, n => { remainingPeriods[n]--; column = Math.Max(column, remainingPeriods[n]); });

                    _positions.Add(period, column);
                    _widthMultipliers.Add(period, 1.0 / collisions);
                }
            }
Exemplo n.º 2
0
        /// <summary>
        /// Adds the periods of the specified day to the specified canvas with the specified size.
        /// </summary>
        private void AddPeriodsToCanvas(Canvas canvas, Size size, StudyDay day)
        {
            var matrix = new PeriodMatrix(day);

            double heightPerMinute = size.Height / ((_maxHour - _minHour) * MinutesInHour);
            double widthPerColumn  = size.Width / matrix.ColumnCount;
            var    startDate       = day.Day.AddHours(_minHour);

            foreach (var period in day.Periods)
            {
                var control = new ContentControl
                {
                    ContentTemplate = PeriodTemplate,
                    Content         = period,
                    Style           = ContainerStyle,
                    Height          = (period.End - period.Start).TotalMinutes * heightPerMinute,
                    Width           = matrix.GetWidthMultiplier(period) * size.Width
                };

                Canvas.SetTop(control, (period.Start - startDate).TotalMinutes * heightPerMinute);
                Canvas.SetLeft(control, widthPerColumn * matrix.GetColumn(period));

                canvas.Children.Add(control);
            }
        }
        public object Clone()
        {
            Pair            newPair            = Pair.Clone() as Pair;
            StudyDay        newStudyDay        = StudyDay.Clone() as StudyDay;
            PossibleFilling newPossibleFilling = new PossibleFilling(newPair, newStudyDay);

            return(newPossibleFilling);
        }
 public PossibleFilling(Pair pair, StudyDay studyDay)
 {
     if (pair.NameThePair.Length > padNameThePair)
     {
         padNameThePair = pair.NameThePair.Length;
     }
     if (pair.NumberThePair.ToString().Length > padNumberThePair)
     {
         padNumberThePair = pair.NumberThePair.ToString().Length;
     }
     if (studyDay.AbbreviationDayOfWeek.Length > padNameDayOfWeek)
     {
         padNameDayOfWeek = studyDay.AbbreviationDayOfWeek.Length;
     }
     if (studyDay.NumberOfWeek.ToString().Length > padNumberOfWeek)
     {
         padNumberOfWeek = studyDay.NumberOfWeek.ToString().Length;
     }
     Pair     = pair;
     StudyDay = studyDay;
 }