ReplaceSpecial() public method

public ReplaceSpecial ( Id id, Special special ) : void
id Id
special Special
return void
Example #1
0
        // Change the set of courses that a special is on. If all the courses are in the new array, changes the special to display in
        // all courses.
        public static void ChangeDisplayedCourses(EventDB eventDB, Id<Special> specialId, CourseDesignator[] displayedCourses)
        {
            // Check if the array contains all of the courses.
            bool allCourses = true;
            Special special = (Special) eventDB.GetSpecial(specialId).Clone();

            foreach (Id<Course> courseId in eventDB.AllCourseIds) {
                if (Array.IndexOf(displayedCourses, new CourseDesignator(courseId)) < 0) {
                    allCourses = false;
                    break;
                }
            }

            if (special.kind == SpecialKind.Descriptions) {
                if (Array.IndexOf(displayedCourses, CourseDesignator.AllControls) < 0)
                    allCourses = false;   // all courses includes all controls only for descriptions.
            }

            special.allCourses = allCourses;
            if (allCourses)
                special.courses = null;
            else
                special.courses = displayedCourses;
            eventDB.ReplaceSpecial(specialId, special);

            // Descriptions special are unique per course -- enforce this.
            if (special.kind == SpecialKind.Descriptions)
                UpdateDescriptionCourses(eventDB, specialId);
        }
Example #2
0
        // Change the line properties associated with a special
        internal static void ChangeSpecialLineAppearance(EventDB eventDB, Id<Special> specialId, SpecialColor color, LineKind lineKind, float lineWidth, float gapSize, float dashSize, float cornerRadius)
        {
            Special special = eventDB.GetSpecial(specialId);

            Debug.Assert(special.kind == SpecialKind.Rectangle || special.kind == SpecialKind.Line);

            special = (Special)special.Clone();
            special.color = color;
            special.lineKind = lineKind;
            special.lineWidth = lineWidth;
            special.gapSize = gapSize;
            special.dashSize = dashSize;
            if (special.kind == SpecialKind.Rectangle)
                special.cornerRadius = cornerRadius;

            eventDB.ReplaceSpecial(specialId, special);
        }
Example #3
0
        // Change the number of columns of a descriptions
        public static void ChangeDescriptionColumns(EventDB eventDB, Id<Special> specialId, int numColumns)
        {
            Special special = eventDB.GetSpecial(specialId);

            Debug.Assert(special.kind == SpecialKind.Descriptions);

            special = (Special)special.Clone();
            special.numColumns = numColumns;

            eventDB.ReplaceSpecial(specialId, special);
        }
Example #4
0
        // Check all descriptions other than the passed one, and remove any duplicate courses.
        public static void UpdateDescriptionCourses(EventDB eventDB, Id<Special> descriptionId)
        {
            // Which courses to remove?
            CourseDesignator[] coursesToRemove = QueryEvent.GetSpecialDisplayedCourses(eventDB, descriptionId);

            // Find all descriptions to change.
            List<Id<Special>> allDescriptionIds = new List<Id<Special>>();
            foreach (Id<Special> specialId in eventDB.AllSpecialIds) {
                if (eventDB.GetSpecial(specialId).kind == SpecialKind.Descriptions && specialId != descriptionId)
                    allDescriptionIds.Add(specialId);
            }

            foreach (Id<Special> descriptionToChange in allDescriptionIds) {
                // Remove any courses that overlap with the courses the given description has..
                bool changes = false;          // track if any changes made.
                List<CourseDesignator> courses = new List<CourseDesignator>(QueryEvent.GetSpecialDisplayedCourses(eventDB, descriptionToChange));
                for (int courseIndex = 0; courseIndex < courses.Count; ++courseIndex) {
                    foreach (CourseDesignator courseToRemove in coursesToRemove) {
                        if (courseIndex >= 0 && courseIndex < courses.Count) {
                            if (courseToRemove == courses[courseIndex]) {
                                changes = true;
                                courses.RemoveAt(courseIndex--);
                            }
                            else if (courseToRemove.CourseId == courses[courseIndex].CourseId) {
                                changes = true;
                                if (!courseToRemove.AllParts && courses[courseIndex].AllParts) {
                                    int removedPart = courseToRemove.Part;
                                    courses.RemoveAt(courseIndex--);
                                    for (int part = 0; part < QueryEvent.CountCourseParts(eventDB, courseToRemove.CourseId); ++part) {
                                        if (part != removedPart)
                                            courses.Add(new CourseDesignator(courseToRemove.CourseId, part));
                                    }
                                }
                                else if (courseToRemove.AllParts) {
                                    courses.RemoveAt(courseIndex--);
                                }
                            }
                        }
                    }
                }

                // Commit the removal to the event database.
                if (changes) {
                    if (courses.Count == 0) {
                        // Remove the given description entire, since it has no displayed courses.
                        eventDB.RemoveSpecial(descriptionToChange);
                    }
                    else {
                        Special newDescription = (Special) eventDB.GetSpecial(descriptionToChange).Clone();
                        newDescription.allCourses = false;
                        newDescription.courses = courses.ToArray();
                        eventDB.ReplaceSpecial(descriptionToChange, newDescription);
                    }
                }
            }
        }
Example #5
0
        // Delete a course and all of its course controls.
        public static void DeleteCourse(EventDB eventDB, Id<Course> courseId)
        {
            // Remember the set of course controls.
            List<Id<CourseControl>> courseControls = new List<Id<CourseControl>>(QueryEvent.EnumCourseControlIds(eventDB, new CourseDesignator(courseId)));

            // Remove the course.
            eventDB.RemoveCourse(courseId);

            // Remove each of the course controls in that course
            foreach (Id<CourseControl> courseControlId in courseControls) {
                eventDB.RemoveCourseControl(courseControlId);
            }

            // Now check specials, and see which need to be modified
            List<Id<Special>> specialsToChange = new List<Id<Special>>();
            foreach (Id<Special> specialId in eventDB.AllSpecialIds) {
                Special special = eventDB.GetSpecial(specialId);
                if (!special.allCourses && special.courses.Any(cd => cd.CourseId == courseId)) {
                    // This special is not an all controls special, and is present on the course being deleted. Update it.
                    specialsToChange.Add(specialId);
                }
            }

            // Update each of the specials.
            foreach (Id<Special> specialId in specialsToChange) {
                Special special = eventDB.GetSpecial(specialId);
                CourseDesignator[] newCourses = special.courses.Where(cd => cd.CourseId != courseId).ToArray();
                if (newCourses.Length == 0)
                    ChangeEvent.DeleteSpecial(eventDB, specialId);
                else {
                    special = (Special) special.Clone();
                    special.courses = newCourses;
                    eventDB.ReplaceSpecial(specialId, special);
                }
            }
        }
Example #6
0
        // Change the text associated with a special. Must be an text special
        public static void ChangeSpecialText(EventDB eventDB, Id<Special> specialId, string newText, string fontName, bool fontBold, bool fontItalic, SpecialColor specialColor)
        {
            Special special = eventDB.GetSpecial(specialId);

            Debug.Assert(special.kind == SpecialKind.Text);

            special = (Special) special.Clone();
            special.text = newText;
            special.fontName = fontName;
            special.fontBold = fontBold;
            special.fontItalic = fontItalic;
            special.color = specialColor;

            eventDB.ReplaceSpecial(specialId, special);
        }
Example #7
0
        // Change the orientation associated with a special. Must be an optional crossing point.
        public static void ChangeSpecialOrientation(EventDB eventDB, Id<Special> specialId, float newOrientation)
        {
            Special special = eventDB.GetSpecial(specialId);

            Debug.Assert(special.kind == SpecialKind.OptCrossing);

            special = (Special) special.Clone();
            special.orientation = newOrientation;

            eventDB.ReplaceSpecial(specialId, special);
        }
Example #8
0
        // Change the locations associated with a special.
        public static void ChangeSpecialLocations(EventDB eventDB, Id<Special> specialId, PointF[] newLocations)
        {
            Special special = eventDB.GetSpecial(specialId);

            special = (Special) special.Clone();
            special.locations = (PointF[]) newLocations.Clone();

            eventDB.ReplaceSpecial(specialId, special);
        }