// Is the given control leg in the specific variation. private bool LegInSpecificVariation(Id <CourseControl> start, Id <CourseControl> end) { if (controlViewsSpecificVariation == controlViewsAllVariationsAndParts) { return(true); } for (int i = 0; i < courseControlIdsSpecificVariation.Length - 1; ++i) { if (courseControlIdsSpecificVariation[i] == start) { if (courseControlIdsSpecificVariation[i + 1] == end) { return(true); } CourseControl endCourseControl = eventDB.GetCourseControl(end); if (endCourseControl.splitCourseControls != null && endCourseControl.splitCourseControls.Contains(courseControlIdsSpecificVariation[i + 1])) { return(true); } } } return(false); }
public void RoundTripCourseControls() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); CourseControl ctl1, ctl2, ctl3, ctl4, ctl5, ctl6, ctl7, ctl8; undomgr.BeginCommand(61, "Command1"); ctl1 = new CourseControl(ControlId(1), CourseControlId(2)); eventDB.AddCourseControl(ctl1); ctl2 = new CourseControl(ControlId(2), Id <CourseControl> .None); ctl2.split = true; ctl2.splitEnd = CourseControlId(5); ctl2.splitCourseControls = new Id <CourseControl>[3] { CourseControlId(2), CourseControlId(3), CourseControlId(4) }; Id <CourseControl> ctl2id = eventDB.AddCourseControl(ctl2); ctl3 = new CourseControl(ControlId(5), CourseControlId(5)); ctl3.points = 10; eventDB.AddCourseControl(ctl3); ctl4 = new CourseControl(ControlId(6), CourseControlId(5)); ctl4.points = 20; ctl4.customNumberPlacement = true; ctl4.numberDeltaX = -6.3F; ctl4.numberDeltaY = 7.41F; eventDB.AddCourseControl(ctl4); ctl5 = new CourseControl(ControlId(7), CourseControlId(6)); Id <CourseControl> ctl5Id = eventDB.AddCourseControl(ctl5); ctl2.splitEnd = ctl5Id; eventDB.ReplaceCourseControl(ctl2id, ctl2); ctl6 = new CourseControl(ControlId(8), Id <CourseControl> .None); eventDB.AddCourseControl(ctl6); ctl7 = new CourseControl(ControlId(6), CourseControlId(5)); ctl7.descTextBefore = "hello"; ctl7.descTextAfter = "goodbye"; eventDB.AddCourseControl(ctl7); ctl8 = new CourseControl(ControlId(5), CourseControlId(7)); ctl8.exchange = true; eventDB.AddCourseControl(ctl8); undomgr.EndCommand(61); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); CollectionAssert.AreEquivalent(new List <KeyValuePair <Id <CourseControl>, CourseControl> >(eventDB.AllCourseControlPairs), new KeyValuePair <Id <CourseControl>, CourseControl>[] { new KeyValuePair <Id <CourseControl>, CourseControl>(CourseControlId(1), ctl1), new KeyValuePair <Id <CourseControl>, CourseControl>(CourseControlId(2), ctl2), new KeyValuePair <Id <CourseControl>, CourseControl>(CourseControlId(3), ctl3), new KeyValuePair <Id <CourseControl>, CourseControl>(CourseControlId(4), ctl4), new KeyValuePair <Id <CourseControl>, CourseControl>(CourseControlId(5), ctl5), new KeyValuePair <Id <CourseControl>, CourseControl>(CourseControlId(6), ctl6), new KeyValuePair <Id <CourseControl>, CourseControl>(CourseControlId(7), ctl7), new KeyValuePair <Id <CourseControl>, CourseControl>(CourseControlId(8), ctl8), } ); }
Fork FindForksToJoin(Id <CourseControl> begin, Id <CourseControl> join) { Id <CourseControl> nextCourseControlId = begin; Fork firstFork = null, lastFork = null; // Traverse the course control links. while (nextCourseControlId.IsNotNone && nextCourseControlId != join) { CourseControl courseCtl = eventDB.GetCourseControl(nextCourseControlId); if (courseCtl.split) { // Record information about the fork, and link it in. Fork currentFork = new Fork(); currentFork.loop = courseCtl.loop; currentFork.controlCode = Util.ControlPointName(eventDB, courseCtl.control, NameStyle.Medium); currentFork.numBranches = courseCtl.loop ? courseCtl.splitCourseControls.Length - 1 : courseCtl.splitCourseControls.Length; currentFork.codes = new char[currentFork.numBranches]; currentFork.subForks = new Fork[currentFork.numBranches]; if (firstFork == null) { firstFork = lastFork = currentFork; } else { lastFork.next = currentFork; lastFork = currentFork; } allForks.Add(currentFork); // Follow all of the alternate paths int j = 0; for (int i = 0; i < courseCtl.splitCourseControls.Length; ++i) { if (!(courseCtl.loop && (i == 0))) { Id <CourseControl> forkStart = courseCtl.splitCourseControls[i]; currentFork.codes[j] = variationMapping[courseCtl.splitCourseControls[i]]; currentFork.subForks[j] = FindForksToJoin(eventDB.GetCourseControl(forkStart).nextCourseControl, courseCtl.splitEnd); ++j; } } if (!courseCtl.loop) { nextCourseControlId = courseCtl.splitEnd; } else { nextCourseControlId = courseCtl.nextCourseControl; } } else { nextCourseControlId = courseCtl.nextCourseControl; } } return(firstFork); }
// Create a set of description lines for a course. If "createKey" is true, then lines for a key are created based on any symbols // that have custom text. This is typically done only if text description are not already being printed. public DescriptionLine[] CreateDescription(bool createKey) { EventDB eventDB = courseView.EventDB; CourseView.CourseViewKind kind = courseView.Kind; int scoreColumn = courseView.ScoreColumn; List <DescriptionLine> list = new List <DescriptionLine>(courseView.ControlViews.Count + 4); string text; DescriptionLine line; DescriptionLine[] lines; Dictionary <string, string> descriptionKey = new Dictionary <string, string>(); // dictionary for any symbols encountered with custom text. // Get the first title line. text = GetTitleLine1(); Debug.Assert(text != null); lines = GetTitleLineFromText(DescriptionLineKind.Title, text); list.AddRange(lines); // Get the second title line. text = GetTitleLine2(); if (text != null) { lines = GetTitleLineFromText(DescriptionLineKind.SecondaryTitle, text); list.AddRange(lines); } // Get the header line, depending on the kind of course. switch (kind) { case CourseView.CourseViewKind.Normal: line = GetNormalHeaderLine(); break; case CourseView.CourseViewKind.AllControls: line = GetAllControlsHeaderLine(); break; case CourseView.CourseViewKind.Score: line = GetScoreHeaderLine(); break; case CourseView.CourseViewKind.AllVariations: line = GetAllVariationsHeaderLine(); break; default: Debug.Fail("unknown CourseViewKind"); line = null; break; } if (line != null) { list.Add(line); } // Do all the normal lines for (int iLine = 0; iLine < courseView.ControlViews.Count; ++iLine) { CourseView.ControlView controlView = courseView.ControlViews[iLine]; ControlPoint control = eventDB.GetControl(controlView.controlId); CourseControl courseControl = controlView.courseControlIds[0].IsNone ? null : eventDB.GetCourseControl(controlView.courseControlIds[0]); // CONSIDER: this might need to be updated for relay or split controls. ControlPoint controlPrev = (iLine > 0) ? eventDB.GetControl(courseView.ControlViews[iLine - 1].controlId) : null; ControlPoint controlNext = (iLine < courseView.ControlViews.Count - 1) ? eventDB.GetControl(courseView.ControlViews[iLine + 1].controlId) : null; //Id<CourseControl> courseControlIdNext = (iLine < courseView.ControlViews.Count - 1) ? courseView.ControlViews[iLine + 1].courseControlId : Id<CourseControl>.None; //CourseControl courseControlNext = courseControlIdNext.IsNotNone ? eventDB.GetCourseControl(coruseControlIdNext) : null; // Do the control.control if (FilterControl(kind, control, controlPrev, controlNext)) { // Text associated with the course or course control (before) AddTextLine(list, control.descTextBefore, controlView.courseControlIds[0], controlView.controlId, DescriptionLine.TextLineKind.BeforeControl); if (courseControl != null) { AddTextLine(list, courseControl.descTextBefore, controlView.courseControlIds[0], controlView.controlId, DescriptionLine.TextLineKind.BeforeCourseControl); } // The control itself. if (control.kind == ControlPointKind.Finish || control.kind == ControlPointKind.CrossingPoint || control.kind == ControlPointKind.MapIssue) { line = GetDirectiveLine(kind, controlView, iLine > 0 ? courseView.ControlViews[iLine - 1] : null); } else { line = GetRegularLine(kind, scoreColumn, controlView, descriptionKey); } Debug.Assert(line != null); list.Add(line); // Text associated with the course or course control (after) if (courseControl != null) { AddTextLine(list, courseControl.descTextAfter, controlView.courseControlIds[0], controlView.controlId, DescriptionLine.TextLineKind.AfterCourseControl); } AddTextLine(list, control.descTextAfter, controlView.courseControlIds[0], controlView.controlId, DescriptionLine.TextLineKind.AfterControl); } // Add any map exchange lines. if (courseView.Kind == CourseView.CourseViewKind.Normal || courseView.Kind == CourseView.CourseViewKind.AllVariations) { if (controlNext != null && controlNext.kind == ControlPointKind.MapExchange) { line = GetMapExchangeLine(controlView, courseView.ControlViews[controlView.legTo[0]]); list.Add(line); } else if (courseControl != null && courseControl.exchange && control.kind != ControlPointKind.MapExchange && controlPrev != null) { line = GetMapExchangeAtControlLine(controlView); list.Add(line); } } // Do the leg (if any). if (controlView.legTo != null && controlView.legTo.Length > 0) { Id <Leg> legId = controlView.legId[0]; Leg leg = (legId.IsNotNone) ? eventDB.GetLeg(legId) : null; if (FilterLeg(kind, control, controlNext, leg)) { line = GetMarkedRouteLine(controlView, courseView.ControlViews[controlView.legTo[0]], legId); Debug.Assert(line != null); list.Add(line); } } } // Add the key if desired. if (createKey) { foreach (string symbolId in descriptionKey.Keys) { line = new DescriptionLine(); line.kind = DescriptionLineKind.Key; line.boxes = new object[2]; line.boxes[0] = symbolDB[symbolId]; line.boxes[1] = descriptionKey[symbolId]; list.Add(line); } } // And we're done! return(list.ToArray()); }
public void RoundTripCourseControls() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); CourseControl ctl1, ctl2, ctl3, ctl4, ctl5, ctl6, ctl7, ctl8; undomgr.BeginCommand(61, "Command1"); ctl1 = new CourseControl(ControlId(1), CourseControlId(2)); eventDB.AddCourseControl(ctl1); ctl2 = new CourseControl(ControlId(2), Id<CourseControl>.None); ctl2.split = true; ctl2.splitEnd = CourseControlId(5); ctl2.splitCourseControls = new Id<CourseControl>[3] { CourseControlId(2), CourseControlId(3), CourseControlId(4) }; Id<CourseControl> ctl2id = eventDB.AddCourseControl(ctl2); ctl3 = new CourseControl(ControlId(5), CourseControlId(5)); ctl3.points = 10; eventDB.AddCourseControl(ctl3); ctl4 = new CourseControl(ControlId(6), CourseControlId(5)); ctl4.points = 20; ctl4.customNumberPlacement = true; ctl4.numberDeltaX = -6.3F; ctl4.numberDeltaY = 7.41F; eventDB.AddCourseControl(ctl4); ctl5 = new CourseControl(ControlId(7), CourseControlId(6)); Id<CourseControl> ctl5Id = eventDB.AddCourseControl(ctl5); ctl2.splitEnd = ctl5Id; eventDB.ReplaceCourseControl(ctl2id, ctl2); ctl6 = new CourseControl(ControlId(8), Id<CourseControl>.None); eventDB.AddCourseControl(ctl6); ctl7 = new CourseControl(ControlId(6), CourseControlId(5)); ctl7.descTextBefore = "hello"; ctl7.descTextAfter = "goodbye"; eventDB.AddCourseControl(ctl7); ctl8 = new CourseControl(ControlId(5), CourseControlId(7)); ctl8.exchange = true; eventDB.AddCourseControl(ctl8); undomgr.EndCommand(61); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); CollectionAssert.AreEquivalent(new List<KeyValuePair<Id<CourseControl>, CourseControl>>(eventDB.AllCourseControlPairs), new KeyValuePair<Id<CourseControl>, CourseControl>[] { new KeyValuePair<Id<CourseControl>,CourseControl>(CourseControlId(1), ctl1), new KeyValuePair<Id<CourseControl>,CourseControl>(CourseControlId(2), ctl2), new KeyValuePair<Id<CourseControl>,CourseControl>(CourseControlId(3), ctl3), new KeyValuePair<Id<CourseControl>,CourseControl>(CourseControlId(4), ctl4), new KeyValuePair<Id<CourseControl>,CourseControl>(CourseControlId(5), ctl5), new KeyValuePair<Id<CourseControl>,CourseControl>(CourseControlId(6), ctl6), new KeyValuePair<Id<CourseControl>,CourseControl>(CourseControlId(7), ctl7), new KeyValuePair<Id<CourseControl>,CourseControl>(CourseControlId(8), ctl8), } ); }