public void ActiveTab() { bool success = controller.LoadInitialFile(TestUtil.GetTestFile("selectionmgr\\sampleevent1.coursescribe"), true); Assert.IsTrue(success); Assert.AreEqual(7, selectionMgr.TabCount); Assert.AreEqual(0, selectionMgr.ActiveTab); selectionMgr.ActiveTab = 5; Assert.AreEqual(5, selectionMgr.ActiveTab); UndoMgr undoMgr = controller.GetUndoMgr(); EventDB eventDB = controller.GetEventDB(); undoMgr.BeginCommand(197, "Add course"); eventDB.AddCourse(new Course(CourseKind.Normal, "AAA", 15000, 1)); undoMgr.EndCommand(197); Assert.AreEqual(6, selectionMgr.ActiveTab); undoMgr.BeginCommand(198, "Remove courses"); eventDB.RemoveCourse(CourseId(1)); undoMgr.EndCommand(198); Assert.AreEqual(0, selectionMgr.ActiveTab); }
public void LoadModifySave() { Id <TestObject> id; UndoMgr undomgr = new UndoMgr(5); ObjectStore <TestObject> objstore = new ObjectStore <TestObject>(undomgr); string xmlText = @"<?xml version=""1.0"" encoding=""utf-16""?> <testobjects> <testobject id=""2"" x=""8"" f=""9.4"">goodbye</testobject> <testobject id=""4"" x=""11"" f=""1.4"">foo</testobject> </testobjects>"; XmlInput xmlinput = new XmlInput(new StringReader(xmlText), "testfile"); xmlinput.CheckElement("testobjects"); xmlinput.Read(); objstore.Load(xmlinput); xmlinput.Dispose(); undomgr.BeginCommand(57, "Command1"); id = objstore.Add(new TestObject(5, "hello", 5.4F)); Assert.AreEqual(5, id.id); id = objstore.Add(new TestObject(9, "bat", 9.9F)); Assert.AreEqual(6, id.id); undomgr.EndCommand(57); undomgr.BeginCommand(58, "Command2"); objstore.Replace(new Id <TestObject>(2), new TestObject(-9, "elvis", 9.1F)); objstore.Remove(new Id <TestObject>(4)); undomgr.EndCommand(58); TextWriter writer = new StringWriter(); XmlTextWriter xmloutput = new XmlTextWriter(writer); xmloutput.Formatting = Formatting.Indented; xmloutput.Namespaces = false; xmloutput.WriteStartDocument(); xmloutput.WriteStartElement("testobjects"); objstore.Save(xmloutput); xmloutput.WriteEndElement(); xmloutput.WriteEndDocument(); xmloutput.Close(); Assert.AreEqual( @"<?xml version=""1.0"" encoding=""utf-16""?> <testobjects> <testobject id=""2"" x=""-9"" f=""9.1"">elvis</testobject> <testobject id=""5"" x=""5"" f=""5.4"">hello</testobject> <testobject id=""6"" x=""9"" f=""9.9"">bat</testobject> </testobjects>", writer.ToString()); }
public override void LeftButtonEndDrag(Pane pane, PointF location, PointF locationStart, float pixelSize, ref bool displayUpdateNeeded) { Debug.Assert(pane == Pane.Map); DragTo(location); PointF upperLeft = new PointF(currentObj.rect.Left, currentObj.rect.Bottom); float cellSize = currentObj.CellSize; int numColumns = currentObj.NumberOfColumns; // Create the new description, unless it's ridiculously small. if (cellSize > 0.5F) { CourseDesignator[] courses = null; courses = new CourseDesignator[] { courseDesignator.WithAllVariations() }; undoMgr.BeginCommand(1522, CommandNameText.AddObject); Id <Special> specialId = ChangeEvent.AddDescription(eventDB, false, courses, upperLeft, cellSize, numColumns); undoMgr.EndCommand(1522); selectionMgr.SelectSpecial(specialId); } controller.DefaultCommandMode(); displayUpdateNeeded = true; }
public void Event() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); Event e = eventDB.GetEvent(); Assert.AreEqual(e.title, ""); Assert.AreEqual(e.notes, null); Assert.AreEqual(e.mapType, MapType.None); Event e2 = new Event(); e2.title = "Hello"; e2.notes = "These are my notes"; e2.mapType = MapType.OCAD; e2.mapFileName = "C:\\hello.ocad"; undomgr.BeginCommand(198, "change event"); eventDB.ChangeEvent(e2); undomgr.EndCommand(198); e = eventDB.GetEvent(); Assert.AreEqual(e2, e); }
public void HasChanged() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); long changeNum = 0; Assert.IsTrue(changeNum < eventDB.ChangeNum); changeNum = eventDB.ChangeNum; undomgr.BeginCommand(61, "Command1"); ControlPoint ctl1 = new ControlPoint(ControlPointKind.Start, null, new PointF(5, 0)); ctl1.symbolIds[1] = "2.8"; ctl1.symbolIds[2] = "8.5"; eventDB.AddControlPoint(ctl1); undomgr.EndCommand(61); Assert.IsTrue(changeNum < eventDB.ChangeNum); changeNum = eventDB.ChangeNum; eventDB = new EventDB(undomgr); Assert.IsTrue(changeNum != eventDB.ChangeNum); changeNum = eventDB.ChangeNum; eventDB = new EventDB(undomgr); Assert.IsTrue(changeNum != eventDB.ChangeNum); changeNum = eventDB.ChangeNum; }
// Render the given course id (0 = all controls) and kind to a map, and compare it to the saved version. internal void CheckRenderMapStandardChange(string filename, Id <Course> id, DescriptionKind kind, string newDescStandard) { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); CourseView courseView; eventDB.Load(filename); symbolDB.Standard = eventDB.GetEvent().descriptionStandard; eventDB.Validate(); courseView = CourseView.CreateViewingCourseView(eventDB, DesignatorFromCourseId(eventDB, id)); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting); DescriptionLine[] description = descFormatter.CreateDescription(kind == DescriptionKind.Symbols); Bitmap bmNew = RenderToMapThenToBitmap(symbolDB, description, kind, 1); TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "_std_default", kind)); undomgr.BeginCommand(71231, "change standard"); symbolDB.Standard = newDescStandard; ChangeEvent.UpdateDescriptionToMatchStandard(eventDB, symbolDB); undomgr.EndCommand(71231); description = descFormatter.CreateDescription(kind == DescriptionKind.Symbols); bmNew = RenderToMapThenToBitmap(symbolDB, description, kind, 1); TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "_std_" + newDescStandard, kind)); }
void CreateImageSpecial(RectangleF boundingRect) { undoMgr.BeginCommand(1851, CommandNameText.AddObject); Id <Special> specialId = createSpecial(boundingRect); undoMgr.EndCommand(1851); selectionMgr.SelectSpecial(specialId); controller.DefaultCommandMode(); }
public void Save() { UndoMgr undomgr = new UndoMgr(5); ObjectStore <TestObject> objstore = new ObjectStore <TestObject>(undomgr); undomgr.BeginCommand(57, "Command1"); objstore.Add(new TestObject(5, "hello", 5.4F)); objstore.Add(new TestObject(7, "hi", 3.4F)); objstore.Add(new TestObject(9, "bat", 9.9F)); undomgr.EndCommand(57); undomgr.BeginCommand(58, "Command2"); objstore.Add(new TestObject(11, "foo", 1.4F)); objstore.Replace(new Id <TestObject>(2), new TestObject(8, "goodbye", 9.4F)); objstore.Remove(new Id <TestObject>(1)); undomgr.EndCommand(58); TextWriter writer = new StringWriter(); XmlTextWriter xmloutput = new XmlTextWriter(writer); xmloutput.Formatting = Formatting.Indented; xmloutput.Namespaces = false; xmloutput.WriteStartDocument(); xmloutput.WriteStartElement("testobjects"); objstore.Save(xmloutput); xmloutput.WriteEndElement(); xmloutput.WriteEndDocument(); xmloutput.Close(); Assert.AreEqual( @"<?xml version=""1.0"" encoding=""utf-16""?> <testobjects> <testobject id=""2"" x=""8"" f=""9.4"">goodbye</testobject> <testobject id=""3"" x=""9"" f=""9.9"">bat</testobject> <testobject id=""4"" x=""11"" f=""1.4"">foo</testobject> </testobjects>", writer.ToString()); }
void CreateTextSpecial(RectangleF boundingRect) { undoMgr.BeginCommand(1551, CommandNameText.AddObject); Id <Special> specialId = ChangeEvent.AddTextSpecial(eventDB, boundingRect, text, currentObj.fontName, (currentObj.fontStyle & FontStyle.Bold) != 0, (currentObj.fontStyle & FontStyle.Italic) != 0, currentObj.fontColor, currentObj.fontDigitHeight); undoMgr.EndCommand(1551); selectionMgr.SelectSpecial(specialId); controller.DefaultCommandMode(); }
public void AllPairs() { UndoMgr undomgr = new UndoMgr(5); ObjectStore <TestObject> objstore = new ObjectStore <TestObject>(undomgr); undomgr.BeginCommand(57, "Command1"); objstore.Add(new TestObject(5, "hello", 5.4F)); objstore.Add(new TestObject(7, "hi", 3.4F)); objstore.Add(new TestObject(9, "bat", 9.9F)); undomgr.EndCommand(57); undomgr.BeginCommand(58, "Command2"); objstore.Add(new TestObject(11, "foo", 1.4F)); objstore.Replace(new Id <TestObject>(2), new TestObject(8, "goodbye", 9.4F)); objstore.Remove(new Id <TestObject>(1)); undomgr.EndCommand(58); TestUtil.TestEnumerableAnyOrder(objstore.AllPairs, new KeyValuePair <Id <TestObject>, TestObject>[] { new KeyValuePair <Id <TestObject>, TestObject>(new Id <TestObject>(3), new TestObject(9, "bat", 9.9F)), new KeyValuePair <Id <TestObject>, TestObject>(new Id <TestObject>(4), new TestObject(11, "foo", 1.4F)), new KeyValuePair <Id <TestObject>, TestObject>(new Id <TestObject>(2), new TestObject(8, "goodbye", 9.4F)) }); }
public void AddRemoveTabs() { bool success = controller.LoadInitialFile(TestUtil.GetTestFile("selectionmgr\\sampleevent1.coursescribe"), true); Assert.IsTrue(success); Assert.AreEqual(7, selectionMgr.TabCount); Assert.AreEqual(0, selectionMgr.ActiveTab); string[] expected = { "All controls", "Green Y", "Rambo", "SampleCourse4", "Score 4", "White", "Yellow" }; for (int i = 0; i < expected.Length; ++i) { Assert.AreEqual(expected[i], selectionMgr.TabName(i)); } UndoMgr undoMgr = controller.GetUndoMgr(); EventDB eventDB = controller.GetEventDB(); undoMgr.BeginCommand(197, "Add course"); eventDB.AddCourse(new Course(CourseKind.Normal, "AAA", 15000, 10)); undoMgr.EndCommand(197); undoMgr.BeginCommand(198, "Remove courses"); eventDB.RemoveCourse(CourseId(1)); eventDB.RemoveCourse(CourseId(4)); undoMgr.EndCommand(198); expected = new string[] { "All controls", "Green Y", "Rambo", "Score 4", "Yellow", "AAA" }; Assert.AreEqual(6, selectionMgr.TabCount); Assert.AreEqual(0, selectionMgr.ActiveTab); for (int i = 0; i < expected.Length; ++i) { Assert.AreEqual(expected[i], selectionMgr.TabName(i)); } }
public void MapExchangeSelectionChanges() { bool success = controller.LoadInitialFile(TestUtil.GetTestFile("selectionmgr\\mapexchange2.ppen"), true); Assert.IsTrue(success); UndoMgr undoMgr = controller.GetUndoMgr(); EventDB eventDB = controller.GetEventDB(); selectionMgr.ActiveTab = selectionMgr.TabCount - 1; // last tab selectionMgr.SelectCourseControl(CourseControlId(602)); Assert.IsTrue(selectionMgr.Selection.SelectedCourseControl.id == 602); selectionMgr.SelectCourseView(new CourseDesignator(selectionMgr.Selection.ActiveCourseDesignator.CourseId, 0)); Assert.IsTrue(selectionMgr.Selection.SelectedCourseControl.id == 602); selectionMgr.SelectCourseView(new CourseDesignator(selectionMgr.Selection.ActiveCourseDesignator.CourseId, 1)); Assert.IsTrue(selectionMgr.Selection.SelectedCourseControl.IsNone); selectionMgr.SelectLeg(CourseControlId(611), CourseControlId(612), LegInsertionLoc.Normal); Assert.IsTrue(selectionMgr.Selection.SelectedCourseControl.id == 611); Assert.IsTrue(selectionMgr.Selection.SelectedCourseControl2.id == 612); selectionMgr.SelectCourseView(new CourseDesignator(selectionMgr.Selection.ActiveCourseDesignator.CourseId, 0)); Assert.IsTrue(selectionMgr.Selection.SelectedCourseControl.IsNone); Assert.IsTrue(selectionMgr.Selection.SelectedCourseControl2.IsNone); selectionMgr.SelectCourseView(new CourseDesignator(selectionMgr.Selection.ActiveCourseDesignator.CourseId, 3)); Assert.IsTrue(selectionMgr.Selection.ActiveCourseDesignator.Part == 3); undoMgr.BeginCommand(912, "Remove Course Control"); ChangeEvent.RemoveCourseControl(eventDB, selectionMgr.Selection.ActiveCourseDesignator.CourseId, CourseControlId(615)); undoMgr.EndCommand(912); Assert.AreEqual(2, selectionMgr.Selection.ActiveCourseDesignator.Part); undoMgr.BeginCommand(915, "Remove Course Controls"); ChangeEvent.RemoveCourseControl(eventDB, selectionMgr.Selection.ActiveCourseDesignator.CourseId, CourseControlId(611)); ChangeEvent.RemoveCourseControl(eventDB, selectionMgr.Selection.ActiveCourseDesignator.CourseId, CourseControlId(616)); undoMgr.EndCommand(915); Assert.IsTrue(selectionMgr.Selection.ActiveCourseDesignator.AllParts); }
public void AddRemove() { Id <TestObject> id; TestObject o, p; UndoMgr undomgr = new UndoMgr(5); ObjectStore <TestObject> objstore = new ObjectStore <TestObject>(undomgr); undomgr.BeginCommand(57, "Command1"); o = new TestObject(5, "hello", 5.4F); id = objstore.Add(o); Assert.AreEqual(1, id.id); Assert.IsTrue(objstore.IsPresent(new Id <TestObject>(1))); p = objstore[new Id <TestObject>(1)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); o = new TestObject(6, "hi", 5.4F); id = objstore.Add(o); Assert.AreEqual(2, id.id); Assert.IsTrue(objstore.IsPresent(new Id <TestObject>(2))); p = objstore[new Id <TestObject>(2)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); objstore.Remove(new Id <TestObject>(1)); Assert.IsFalse(objstore.IsPresent(new Id <TestObject>(1))); o = new TestObject(7, "xx", 1.1F); id = objstore.Add(o); Assert.AreEqual(3, id.id); Assert.IsTrue(objstore.IsPresent(new Id <TestObject>(3))); p = objstore[new Id <TestObject>(3)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); objstore.Remove(new Id <TestObject>(3)); int count = 0; foreach (TestObject x in objstore.All) { Assert.AreEqual(x, new TestObject(6, "hi", 5.4F)); ++count; } Assert.AreEqual(1, count); undomgr.EndCommand(57); }
public void AddRemove() { Id<TestObject> id; TestObject o, p; UndoMgr undomgr = new UndoMgr(5); ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr); undomgr.BeginCommand(57, "Command1"); o = new TestObject(5, "hello", 5.4F); id = objstore.Add(o); Assert.AreEqual(1, id.id); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(1))); p = objstore[new Id<TestObject>(1)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); o = new TestObject(6, "hi", 5.4F); id = objstore.Add(o); Assert.AreEqual(2, id.id); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(2))); p = objstore[new Id<TestObject>(2)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); objstore.Remove(new Id<TestObject>(1)); Assert.IsFalse(objstore.IsPresent(new Id<TestObject>(1))); o = new TestObject(7, "xx", 1.1F); id = objstore.Add(o); Assert.AreEqual(3, id.id); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(3))); p = objstore[new Id<TestObject>(3)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); objstore.Remove(new Id<TestObject>(3)); int count = 0; foreach (TestObject x in objstore.All) { Assert.AreEqual(x, new TestObject(6, "hi", 5.4F)); ++count; } Assert.AreEqual(1, count); undomgr.EndCommand(57); }
// Create the object with the number of fixed points there are, if there are enough. Returns true if object was created, false // if no enough points. bool CreateObject() { // Line objects need at least 2 points, area objects need at least 3. if (numberFixedPoints < 2 || (isArea && numberFixedPoints < 3)) { return(false); } undoMgr.BeginCommand(1327, CommandNameText.AddObject); // Create the special Id <Special> specialId = createObject(points.GetRange(0, numberFixedPoints).ToArray()); // select the new special. selectionMgr.SelectSpecial(specialId); undoMgr.EndCommand(1327); return(true); }
public void Replace() { Id <TestObject> id; TestObject o, p; UndoMgr undomgr = new UndoMgr(5); ObjectStore <TestObject> objstore = new ObjectStore <TestObject>(undomgr); undomgr.BeginCommand(57, "Command1"); o = new TestObject(5, "hello", 5.4F); id = objstore.Add(o); Assert.AreEqual(1, id.id); Assert.IsTrue(objstore.IsPresent(new Id <TestObject>(1))); p = objstore[new Id <TestObject>(1)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); o = new TestObject(6, "hi", 5.4F); id = objstore.Add(o); Assert.AreEqual(2, id.id); Assert.IsTrue(objstore.IsPresent(new Id <TestObject>(2))); p = objstore[new Id <TestObject>(2)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); o = new TestObject(11, "mr ed", 9.7F); objstore.Replace(new Id <TestObject>(1), o); Assert.IsTrue(objstore.IsPresent(new Id <TestObject>(1))); p = objstore[new Id <TestObject>(1)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); o = new TestObject(13, "baz", 2.4F); objstore.Replace(new Id <TestObject>(2), o); Assert.IsTrue(objstore.IsPresent(new Id <TestObject>(2))); p = objstore[new Id <TestObject>(2)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); TestUtil.TestEnumerableAnyOrder(objstore.All, new TestObject[] { new TestObject(11, "mr ed", 9.7F), new TestObject(13, "baz", 2.4F) }); }
public override void LeftButtonClick(Pane pane, PointF location, float pixelSize, ref bool displayUpdateNeeded) { if (pane != Pane.Map) { return; } // Create the new special! PointF highlightLocation = new PointF(location.X + PIXELOFFSETX * pixelSize, location.Y + PIXELOFFSETY * pixelSize); undoMgr.BeginCommand(1322, CommandNameText.AddObject); // Creat the special Id <Special> specialId = ChangeEvent.AddPointSpecial(eventDB, specialKind, highlightLocation, 0); // select the new special. selectionMgr.SelectSpecial(specialId); undoMgr.EndCommand(1322); controller.DefaultCommandMode(); }
public void ChangeNum() { int changeNum; Id <TestObject> id; TestObject o; UndoMgr undomgr = new UndoMgr(5); ObjectStore <TestObject> objstore = new ObjectStore <TestObject>(undomgr); changeNum = objstore.ChangeNum; undomgr.BeginCommand(57, "Command1"); o = new TestObject(5, "hello", 5.4F); id = objstore.Add(o); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; objstore.Remove(new Id <TestObject>(1)); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; id = objstore.Add(o); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; objstore.Replace(new Id <TestObject>(2), o); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; undomgr.EndCommand(57); undomgr.Undo(); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; undomgr.Redo(); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; }
public void Present() { Id <TestObject> id; TestObject o; UndoMgr undomgr = new UndoMgr(5); ObjectStore <TestObject> objstore = new ObjectStore <TestObject>(undomgr); undomgr.BeginCommand(57, "Command1"); o = new TestObject(5, "hello", 5.4F); id = objstore.Add(o); Assert.AreEqual(1, id.id); Assert.IsTrue(objstore.IsPresent(new Id <TestObject>(1))); Assert.IsFalse(objstore.IsPresent(new Id <TestObject>(2))); objstore.CheckPresent(new Id <TestObject>(1)); try { objstore.IsPresent(new Id <TestObject>(2)); Assert.Fail("should throw"); } catch { } }
public void ComputeStraightLineControlDistance() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); ControlPoint control1, control2, control3; Leg leg1; Event ev = new Event(); control1 = new ControlPoint(ControlPointKind.Normal, "31", new PointF(4.5F, -10.1F)); control2 = new ControlPoint(ControlPointKind.Normal, "32", new PointF(-6.8F, 14.1F)); control3 = new ControlPoint(ControlPointKind.Normal, "33", new PointF(-12.8F, 32.9F)); undomgr.BeginCommand(123, "Add controls"); Id<ControlPoint> id1 = eventDB.AddControlPoint(control1); Id<ControlPoint> id2 = eventDB.AddControlPoint(control2); Id<ControlPoint> id3 = eventDB.AddControlPoint(control3); leg1 = new Leg(id1, id2); leg1.bends = new PointF[] { new PointF(7, 8), new PointF(10, 14) }; Id<Leg> legId = eventDB.AddLeg(leg1); ev.mapScale = 15000; eventDB.ChangeEvent(ev); undomgr.EndCommand(123); float length = QueryEvent.ComputeStraightLineControlDistance(eventDB, id1, id2); Assert.AreEqual(400.62F, length, 0.01F); // Doesn't take bend in leg into account! length = QueryEvent.ComputeStraightLineControlDistance(eventDB, id3, id2); Assert.AreEqual(296.01F, length, 0.01F); }
public void AutoRenumber() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); Event ev = new Event(); Id<ControlPoint>[] ids = new Id<ControlPoint>[10]; undomgr.BeginCommand(123, "Add controls"); ids[0] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "36", new PointF())); //36 ids[1] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "33", new PointF())); //33 ids[2] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "AB", new PointF())); //40 ids[3] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "34", new PointF())); //34 ids[4] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "31", new PointF())); //35 ids[5] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "51", new PointF())); //39 ids[6] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "37", new PointF())); //37 ids[7] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "38", new PointF())); //38 ids[8] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "FA", new PointF())); //41 ev.mapScale = 15000; ev.firstControlCode = 33; ev.disallowInvertibleCodes = false; eventDB.ChangeEvent(ev); ChangeEvent.AutoRenumberControls(eventDB); undomgr.EndCommand(123); Assert.AreEqual("36", eventDB.GetControl(ids[0]).code); Assert.AreEqual("33", eventDB.GetControl(ids[1]).code); Assert.AreEqual("40", eventDB.GetControl(ids[2]).code); Assert.AreEqual("34", eventDB.GetControl(ids[3]).code); Assert.AreEqual("35", eventDB.GetControl(ids[4]).code); Assert.AreEqual("39", eventDB.GetControl(ids[5]).code); Assert.AreEqual("37", eventDB.GetControl(ids[6]).code); Assert.AreEqual("38", eventDB.GetControl(ids[7]).code); Assert.AreEqual("41", eventDB.GetControl(ids[8]).code); }
public void RoundTripSpecials() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); Special sp1, sp2, sp3, sp4, sp5, sp6, sp7, sp8, sp9, sp10, sp11, sp12, sp13, sp14; undomgr.BeginCommand(88, "Command1"); sp1 = new Special(SpecialKind.FirstAid, new PointF[1] { new PointF(4.5F, 1.2F) }); sp2 = new Special(SpecialKind.OptCrossing, new PointF[1] { new PointF(-4.2F, 1.7F) }); sp2.allCourses = false; sp2.courses = new CourseDesignator[] { Designator(1), Designator(2), Designator(3), CourseDesignator.AllControls }; sp2.orientation = 45F; sp3 = new Special(SpecialKind.Boundary, new PointF[2] { new PointF(8, 7), new PointF(1, 2) }); sp4 = new Special(SpecialKind.OOB, new PointF[4] { new PointF(3, 7), new PointF(11, 2), new PointF(0, -1), new PointF(-12, -3) }); sp5 = new Special(SpecialKind.Text, new PointF[2] { new PointF(3, 7), new PointF(11, 4) }); sp5.text = "Hello"; sp5.fontName = "Tahoma"; sp5.fontBold = true; sp5.fontItalic = false; sp5.fontHeight = 6.5F; sp5.allCourses = false; sp5.color = new SpecialColor(0.2F, 0.5F, 0.3F, 0F); sp5.courses = new CourseDesignator[2] { Designator(2), new CourseDesignator(CourseId(3), 1) }; sp6 = new Special(SpecialKind.Descriptions, new PointF[2] { new PointF(5, 6), new PointF(11, 6) }); sp6.numColumns = 2; sp7 = new Special(SpecialKind.Text, new PointF[2] { new PointF(8, 7), new PointF(18, 5) }); sp7.fontName = "Courier New"; sp7.fontBold = false; sp7.fontItalic = true; sp7.text = "$(CourseName)"; sp7.color = SpecialColor.Purple; sp8 = new Special(SpecialKind.WhiteOut, new PointF[4] { new PointF(13, 17), new PointF(21, 12), new PointF(10, -1), new PointF(-2, 7) }); sp9 = new Special(SpecialKind.Image, new PointF[2] { new PointF(18, 17), new PointF(28, 15) }); sp9.imageBitmap = (Bitmap)Image.FromFile(TestUtil.GetTestFile("eventDB\\testimage.jpg")); sp9.text = "testimage.jpg"; sp10 = new Special(SpecialKind.Line, new PointF[3] { new PointF(8, 7), new PointF(1, 2), new PointF(5, 12) }); sp10.color = SpecialColor.Black; sp10.lineKind = LineKind.Single; sp10.lineWidth = 0.1F; sp11 = new Special(SpecialKind.Line, new PointF[3] { new PointF(8, 7), new PointF(1, 2), new PointF(5, 12) }); sp11.color = new SpecialColor(1F, 0.66F, 0.45F, 0.83F); sp11.lineKind = LineKind.Double; sp11.lineWidth = 0.1F; sp11.gapSize = 0.15F; sp12 = new Special(SpecialKind.Line, new PointF[2] { new PointF(8, 7), new PointF(1, 2) }); sp12.color = SpecialColor.Purple; sp12.lineKind = LineKind.Dashed; sp12.lineWidth = 0.1F; sp12.gapSize = 0.15F; sp12.dashSize = 0.44F; sp13 = new Special(SpecialKind.Rectangle, new PointF[2] { new PointF(8, 7), new PointF(1, 2) }); sp13.color = SpecialColor.Purple; sp13.lineKind = LineKind.Single; sp13.lineWidth = 0.1F; sp13.cornerRadius = 0.23F; sp14 = new Special(SpecialKind.Ellipse, new PointF[2] { new PointF(5, 6), new PointF(1, 3) }); sp14.color = new SpecialColor(CmykColor.FromCmyk(0.8F, 0.3F, 0.2F, 0.1F)); sp14.lineKind = LineKind.Double; sp14.lineWidth = 0.25F; eventDB.AddSpecial(sp1); eventDB.AddSpecial(sp2); eventDB.AddSpecial(sp3); eventDB.AddSpecial(sp4); eventDB.AddSpecial(sp5); eventDB.AddSpecial(sp6); eventDB.AddSpecial(sp7); eventDB.AddSpecial(sp8); eventDB.AddSpecial(sp9); eventDB.AddSpecial(sp10); eventDB.AddSpecial(sp11); eventDB.AddSpecial(sp12); eventDB.AddSpecial(sp13); eventDB.AddSpecial(sp14); undomgr.EndCommand(88); eventDB.Save(TestUtil.GetTestFile("eventDB\\testoutput_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); // The loaded image won't compare equal. Check the image is the same, then force equal. Special loadedSp9 = eventDB.GetSpecial(SpecialId(9)); Assert.IsNotNull(loadedSp9.imageBitmap); Assert.AreEqual(loadedSp9.imageBitmap.Width, sp9.imageBitmap.Width); Assert.AreEqual(loadedSp9.imageBitmap.Height, sp9.imageBitmap.Height); Assert.AreEqual(loadedSp9.imageBitmap.RawFormat, sp9.imageBitmap.RawFormat); loadedSp9.imageBitmap = sp9.imageBitmap; TestUtil.TestEnumerableAnyOrder(eventDB.AllSpecialPairs, new KeyValuePair <Id <Special>, Special>[] { new KeyValuePair <Id <Special>, Special>(SpecialId(1), sp1), new KeyValuePair <Id <Special>, Special>(SpecialId(2), sp2), new KeyValuePair <Id <Special>, Special>(SpecialId(3), sp3), new KeyValuePair <Id <Special>, Special>(SpecialId(4), sp4), new KeyValuePair <Id <Special>, Special>(SpecialId(5), sp5), new KeyValuePair <Id <Special>, Special>(SpecialId(6), sp6), new KeyValuePair <Id <Special>, Special>(SpecialId(7), sp7), new KeyValuePair <Id <Special>, Special>(SpecialId(8), sp8), new KeyValuePair <Id <Special>, Special>(SpecialId(9), sp9), new KeyValuePair <Id <Special>, Special>(SpecialId(10), sp10), new KeyValuePair <Id <Special>, Special>(SpecialId(11), sp11), new KeyValuePair <Id <Special>, Special>(SpecialId(12), sp12), new KeyValuePair <Id <Special>, Special>(SpecialId(13), sp13), new KeyValuePair <Id <Special>, Special>(SpecialId(14), sp14), } ); }
public void RoundTripEvent() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); Event e = new Event(); e.title = "Hello"; e.notes = "These are my notes"; e.mapType = MapType.OCAD; e.mapFileName = "C:\\hello.ocad"; e.mapScale = 14000; e.allControlsPrintScale = 10000; e.allControlsDescKind = DescriptionKind.SymbolsAndText; e.printArea = new PrintArea(false, false, new RectangleF(50, 70, 200, 300)); e.punchcardFormat.boxesAcross = 7; e.punchcardFormat.boxesDown = 5; e.punchcardFormat.leftToRight = false; e.punchcardFormat.topToBottom = true; undomgr.BeginCommand(198, "change event"); eventDB.ChangeEvent(e); undomgr.EndCommand(198); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput1_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput1_temp.xml")); Assert.AreEqual(e, eventDB.GetEvent()); Assert.AreEqual(7, e.punchcardFormat.boxesAcross); /* --- */ undomgr.Clear(); eventDB = new EventDB(undomgr); e.title = "Hi"; e.notes = null; e.mapType = MapType.None; e.mapFileName = null; e.courseAppearance.purpleColorBlend = true; undomgr.BeginCommand(198, "change event"); eventDB.ChangeEvent(e); undomgr.EndCommand(198); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput2_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput2_temp.xml")); Assert.AreEqual(e, eventDB.GetEvent()); /* --- */ undomgr.Clear(); eventDB = new EventDB(undomgr); e.title = "Hi"; e.notes = null; e.mapType = MapType.Bitmap; e.mapFileName = TestUtil.GetTestFile("eventdb\\maps\\testoutput3.jpg"); e.mapScale = 12000; e.mapDpi = 330; e.allControlsPrintScale = 7500; e.allControlsDescKind = DescriptionKind.Text; e.descriptionLangId = "bg"; e.courseAppearance.useOcadOverprint = true; e.courseAppearance.itemScaling = ItemScaling.RelativeTo15000; undomgr.BeginCommand(198, "change event"); eventDB.ChangeEvent(e); undomgr.EndCommand(198); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput3_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput3_temp.xml")); Assert.AreEqual(e, eventDB.GetEvent()); /* --- */ undomgr.Clear(); eventDB = new EventDB(undomgr); e.title = "Hi"; e.notes = null; e.mapType = MapType.None; e.mapFileName = null; e.mapScale = 12000; e.mapDpi = 330; e.allControlsPrintScale = 7500; e.allControlsDescKind = DescriptionKind.Text; e.courseAppearance.lineWidth = 1.3F; e.courseAppearance.controlCircleSize = 0.9F; e.courseAppearance.centerDotDiameter = 0.53F; e.courseAppearance.numberHeight = 1.1F; e.courseAppearance.numberBold = true; e.courseAppearance.numberOutlineWidth = 0.5F; e.courseAppearance.autoLegGapSize = 2.75F; e.courseAppearance.useDefaultPurple = false; e.courseAppearance.purpleC = 0.4F; e.courseAppearance.purpleM = 0.5F; e.courseAppearance.purpleY = 0.6F; e.courseAppearance.purpleK = 0.74F; e.courseAppearance.itemScaling = ItemScaling.RelativeToMap; e.courseAppearance.descriptionsPurple = true; e.courseAppearance.mapStandard = "2017"; e.descriptionStandard = "2018"; undomgr.BeginCommand(198, "change event"); eventDB.ChangeEvent(e); undomgr.EndCommand(198); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput5_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput5_temp.xml")); Assert.AreEqual(e, eventDB.GetEvent()); /* --- */ undomgr.Clear(); eventDB = new EventDB(undomgr); e.title = "Mr. Event"; e.notes = null; e.mapType = MapType.OCAD; e.mapFileName = TestUtil.GetTestFile("eventdb\\My Map-File.ocad"); e.ignoreMissingFonts = true; List <SymbolText> texts = new List <SymbolText>(); SymbolText text1 = new SymbolText(), text2 = new SymbolText(), text3 = new SymbolText(); text1.Lang = "en"; text1.Gender = ""; text1.Plural = false; text1.Text = "man-made & cool object"; text2.Lang = "en"; text2.Gender = ""; text2.Plural = true; text2.Text = "man-made & cool objects"; text3.Lang = "bg"; text3.Gender = "masculine"; text3.Plural = false; text3.Text = "bulgarish mm"; texts.Add(text1); texts.Add(text2); texts.Add(text3); e.customSymbolText["6.1"] = texts; texts = new List <SymbolText>(); text1.Lang = "en"; text1.Gender = ""; text1.Plural = false; text1.Text = "boopsie"; text1.Case = ""; texts.Add(text1); e.customSymbolText["6.2"] = texts; e.customSymbolKey["6.2"] = true; e.customSymbolKey["6.1"] = false; e.courseAppearance.mapStandard = "2000"; e.descriptionStandard = "2004"; undomgr.BeginCommand(198, "change event"); eventDB.ChangeEvent(e); undomgr.EndCommand(198); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput4_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput4_temp.xml")); Assert.AreEqual(e, eventDB.GetEvent()); }
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), } ); }
public void RoundTripLeg() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); Leg leg1, leg2, leg3, leg4, leg5; ControlPoint ctl1, ctl2; Id<ControlPoint> ctlId1, ctlId2; undomgr.BeginCommand(81, "Command1"); ctl1 = new ControlPoint(ControlPointKind.Normal, "31", new PointF(10, 10)); ctl1.symbolIds[0] = "0.3"; ctl1.symbolIds[1] = "2.4"; ctl1.columnFText = "2m"; ctlId1 = eventDB.AddControlPoint(ctl1); ctl2 = new ControlPoint(ControlPointKind.Normal, "32", new PointF(20, -10.5F)); ctl2.symbolIds[1] = "3.7"; ctl2.symbolIds[5] = "12.1"; ctl2.gaps = new Dictionary<int, CircleGap[]>(); ctl2.gaps.Add(15000, CircleGap.ComputeCircleGaps(0xFFFFFFDF)); ctl2.gaps.Add(10000, CircleGap.ComputeCircleGaps(0xFF00FFFF)); ctl2.descriptionText = "very marshy spot"; ctlId2 = eventDB.AddControlPoint(ctl2); leg1 = new Leg(ctlId1, ctlId2); eventDB.AddLeg(leg1); leg2 = new Leg(ctlId1, ctlId2); leg2.flagging = FlaggingKind.All; eventDB.AddLeg(leg2); leg3 = new Leg(ctlId1, ctlId2); leg3.flagging = FlaggingKind.Begin; leg3.flagStartStop = new PointF(5, -7.5F); leg3.bends = new PointF[2] { leg3.flagStartStop, new PointF(17, 6) }; eventDB.AddLeg(leg3); leg4 = new Leg(ctlId1, ctlId2); leg4.flagging = FlaggingKind.End; leg4.flagStartStop = new PointF(5, -7.5F); leg4.bends = new PointF[1] { leg4.flagStartStop }; leg4.gaps = new LegGap[2] { new LegGap(2, 0.3F), new LegGap(3.4F, 0.4F)}; eventDB.AddLeg(leg4); leg5 = new Leg(ctlId1, ctlId2); leg5.gaps = new LegGap[3] { new LegGap(0.9F, 0.3F), new LegGap(3.4F, 0.4F), new LegGap(4.5F, 1.1F) }; eventDB.AddLeg(leg5); undomgr.EndCommand(81); eventDB.Validate(); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); eventDB.Validate(); TestUtil.TestEnumerableAnyOrder(eventDB.AllLegPairs, new KeyValuePair<Id<Leg>, Leg>[] { new KeyValuePair<Id<Leg>,Leg>(LegId(1), leg1), new KeyValuePair<Id<Leg>,Leg>(LegId(2), leg2), new KeyValuePair<Id<Leg>,Leg>(LegId(3), leg3), new KeyValuePair<Id<Leg>,Leg>(LegId(4), leg4), new KeyValuePair<Id<Leg>,Leg>(LegId(5), leg5) } ); }
public void UndoRedo() { UndoMgr undomgr = new UndoMgr(5); ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr); undomgr.BeginCommand(57, "Command1"); objstore.Add(new TestObject(5, "hello", 5.4F)); objstore.Add(new TestObject(7, "hi", 3.4F)); objstore.Add(new TestObject(9, "bat", 9.9F)); undomgr.EndCommand(57); undomgr.BeginCommand(58, "Command2"); objstore.Add(new TestObject(11, "foo", 1.4F)); objstore.Replace(new Id<TestObject>(2), new TestObject(8, "goodbye", 9.4F)); objstore.Remove(new Id<TestObject>(1)); undomgr.EndCommand(58); TestUtil.TestEnumerableAnyOrder(objstore.All, new TestObject[] { new TestObject(9, "bat", 9.9F), new TestObject(11, "foo", 1.4F), new TestObject(8, "goodbye", 9.4F) }); undomgr.Undo(); TestUtil.TestEnumerableAnyOrder(objstore.All, new TestObject[] { new TestObject(5, "hello", 5.4F), new TestObject(7, "hi", 3.4F), new TestObject(9, "bat", 9.9F) }); undomgr.Undo(); TestUtil.TestEnumerableAnyOrder(objstore.All, new TestObject[] { }); undomgr.Redo(); TestUtil.TestEnumerableAnyOrder(objstore.All, new TestObject[] { new TestObject(5, "hello", 5.4F), new TestObject(7, "hi", 3.4F), new TestObject(9, "bat", 9.9F) }); undomgr.Redo(); TestUtil.TestEnumerableAnyOrder(objstore.All, new TestObject[] { new TestObject(9, "bat", 9.9F), new TestObject(11, "foo", 1.4F), new TestObject(8, "goodbye", 9.4F) }); }
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), } ); }
public void DescriptionEquals() { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("coursesymbols\\sampleevent1.coursescribe")); eventDB.Validate(); CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(3))); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB); DescriptionLine[] description = descFormatter.CreateDescription(false); CourseObj courseobj1 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1); description = descFormatter.CreateDescription(false); CourseObj courseobj2 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1); CourseObj courseobj3 = (CourseObj) courseobj1.Clone(); CourseObj courseobj4 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 3), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1); CourseObj courseobj5 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 1.0F, symbolDB, description, DescriptionKind.Symbols, 1); CourseObj courseobj6 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Text, 1); undomgr.BeginCommand(12, "move control"); ChangeEvent.ChangeControlLocation(eventDB, ControlId(11), new PointF(4, 8)); undomgr.EndCommand(12); description = descFormatter.CreateDescription(false); CourseObj courseobj7 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1); undomgr.BeginCommand(13, "change description"); ChangeEvent.ChangeDescriptionSymbol(eventDB, ControlId(11), 1, "5.4"); undomgr.EndCommand(13); description = descFormatter.CreateDescription(false); CourseObj courseobj8 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1); undomgr.BeginCommand(13, "change description"); // change description back ChangeEvent.ChangeDescriptionSymbol(eventDB, ControlId(11), 1, "5.2"); undomgr.EndCommand(13); description = descFormatter.CreateDescription(false); CourseObj courseobj9 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1); CourseObj courseobj10 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 2); Assert.AreEqual(courseobj1, courseobj2); Assert.AreEqual(courseobj1, courseobj3); Assert.AreNotEqual(courseobj1, courseobj4); Assert.AreNotEqual(courseobj1, courseobj5); Assert.AreNotEqual(courseobj1, courseobj6); Assert.AreEqual(courseobj1, courseobj7); Assert.AreNotEqual(courseobj1, courseobj8); Assert.AreEqual(courseobj1, courseobj9); Assert.AreNotEqual(courseobj9, courseobj10); }
public void RoundTripCourses() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); RectangleF mapBounds = new RectangleF(0, 0, 200, 300); Course course1, course2, course3, course4, course5; undomgr.BeginCommand(61, "Command1"); course1 = new Course(CourseKind.Normal, "White", 15000, 1); course1.descKind = DescriptionKind.Symbols; course1.secondaryTitle = "White is right"; course1.load = 0; course1.firstCourseControl = CourseControlId(1); course1.UpdateUnknownPageSizes(mapBounds, 15000); eventDB.AddCourse(course1); course2 = new Course(CourseKind.Normal, "Yellow", 15000, 2); course2.descKind = DescriptionKind.SymbolsAndText; course2.climb = 95; course2.labelKind = ControlLabelKind.Code; course2.firstCourseControl = CourseControlId(0); course2.printArea = new PrintArea(false, true, new RectangleF(50, 70, 200, 100)); course2.partPrintAreas[1] = new PrintArea(false, false, new RectangleF(10, 20, 30, 40), 1.1F); course2.partPrintAreas[0] = new PrintArea(true, false, new RectangleF(70, 10, 130, 140)); course2.partOptions[1] = new PartOptions() { ShowFinish = true }; course2.partOptions[0] = new PartOptions() { ShowFinish = false }; course2.relayTeams = 43; course2.relayLegs = 3; course2.UpdateUnknownPageSizes(mapBounds, 15000); eventDB.AddCourse(course2); course3 = new Course(CourseKind.Score, "Rambo", 10000, 3); course3.secondaryTitle = ""; course3.firstCourseControl = CourseControlId(2); course3.load = 125; course3.climb = 0; course3.firstControlOrdinal = 7; course3.labelKind = ControlLabelKind.SequenceAndCode; course3.descKind = DescriptionKind.Text; course3.partPrintAreas[1] = new PrintArea(true, true, new RectangleF(-10, -20, 90, 80), 0.9F); course3.UpdateUnknownPageSizes(mapBounds, 15000); eventDB.AddCourse(course3); course4 = new Course(CourseKind.Score, "Silly1", 10000, 3); course4.secondaryTitle = ""; course4.firstCourseControl = CourseControlId(2); course4.load = 0; course4.climb = 25; course4.overrideCourseLength = 4243; course4.firstControlOrdinal = 3; course4.labelKind = ControlLabelKind.SequenceAndScore; course4.descKind = DescriptionKind.SymbolsAndText; course4.partPrintAreas[1] = new PrintArea(false, false, new RectangleF(-10, -20, 90, 80)); course4.partOptions[1] = new PartOptions() { ShowFinish = false }; course4.relayTeams = 0; course4.UpdateUnknownPageSizes(mapBounds, 15000); eventDB.AddCourse(course4); course5 = new Course(CourseKind.Score, "Silly2", 10000, 3); course5.secondaryTitle = ""; course5.firstCourseControl = CourseControlId(2); course5.load = 125; course5.climb = 0; course5.firstControlOrdinal = 1; course5.labelKind = ControlLabelKind.CodeAndScore; course5.descKind = DescriptionKind.Symbols; course5.partPrintAreas[1] = new PrintArea(false, false, new RectangleF(-10, -20, 90, 80), 1.25F); course5.relayTeams = 5; course5.relayLegs = 6; course5.UpdateUnknownPageSizes(mapBounds, 15000); eventDB.AddCourse(course5); 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")); Assert.AreEqual(eventDB.GetCourse(CourseId(1)), course1); Assert.AreEqual(eventDB.GetCourse(CourseId(2)), course2); Assert.AreEqual(eventDB.GetCourse(CourseId(3)), course3); Assert.AreEqual(eventDB.GetCourse(CourseId(4)), course4); Assert.AreEqual(eventDB.GetCourse(CourseId(5)), course5); TestUtil.TestEnumerableAnyOrder(eventDB.AllCoursePairs, new KeyValuePair<Id<Course>, Course>[] { new KeyValuePair<Id<Course>,Course>(CourseId(1), course1), new KeyValuePair<Id<Course>,Course>(CourseId(2), course2), new KeyValuePair<Id<Course>,Course>(CourseId(3), course3), new KeyValuePair<Id<Course>,Course>(CourseId(4), course4), new KeyValuePair<Id<Course>,Course>(CourseId(5), course5), } ); }
public void FindLeg() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); ControlPoint control1, control2, control3, control4; Leg leg1, leg2; Id<Leg> legId1, legId2; Event ev = new Event(); control1 = new ControlPoint(ControlPointKind.Normal, "31", new PointF(4.5F, -10.1F)); control2 = new ControlPoint(ControlPointKind.Normal, "32", new PointF(-6.8F, 14.1F)); control3 = new ControlPoint(ControlPointKind.Normal, "33", new PointF(5F, 19F)); control4 = new ControlPoint(ControlPointKind.Normal, "34", new PointF(18F, 1F)); undomgr.BeginCommand(124, "Add controls"); Id<ControlPoint> id1 = eventDB.AddControlPoint(control1); Id<ControlPoint> id2 = eventDB.AddControlPoint(control2); Id<ControlPoint> id3 = eventDB.AddControlPoint(control3); Id<ControlPoint> id4 = eventDB.AddControlPoint(control4); leg1 = new Leg(id1, id2); legId1 = eventDB.AddLeg(leg1); leg2 = new Leg(id4, id2); legId2 = eventDB.AddLeg(leg2); undomgr.EndCommand(124); Id<Leg> result = QueryEvent.FindLeg(eventDB, id1, id3); Assert.IsTrue(result.IsNone); result = QueryEvent.FindLeg(eventDB, id2, id1); Assert.IsTrue(result.IsNone); result = QueryEvent.FindLeg(eventDB, id3, id2); Assert.IsTrue(result.IsNone); result = QueryEvent.FindLeg(eventDB, id1, id2); Assert.IsTrue(result == legId1); result = QueryEvent.FindLeg(eventDB, id4, id2); Assert.IsTrue(result == legId2); }
public void ComputeFlaggedLegLength() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); ControlPoint control1, control2; Leg leg1; Event ev = new Event(); control1 = new ControlPoint(ControlPointKind.Normal, "31", new PointF(4F, -10F)); control2 = new ControlPoint(ControlPointKind.Normal, "32", new PointF(-3F, 14F)); undomgr.BeginCommand(123, "Add controls"); Id<ControlPoint> id1 = eventDB.AddControlPoint(control1); Id<ControlPoint> id2 = eventDB.AddControlPoint(control2); leg1 = new Leg(id1, id2); leg1.bends = new PointF[] { new PointF(6, 3), new PointF(7, 8), new PointF(10, 14) }; Id<Leg> legId = eventDB.AddLeg(leg1); // distances. 13.153, 5.099, 6.708, 13.00 * 15000 ev.mapScale = 15000; eventDB.ChangeEvent(ev); undomgr.EndCommand(123); float length = QueryEvent.ComputeFlaggedLegLength(eventDB, id1, id2, legId); Assert.AreEqual(569.4, length, 0.01); undomgr.BeginCommand(123, "Change leg"); leg1.flagging = FlaggingKind.All; eventDB.ReplaceLeg(legId, leg1); undomgr.EndCommand(123); length = QueryEvent.ComputeFlaggedLegLength(eventDB, id1, id2, legId); Assert.AreEqual(569.4, length, 0.01); undomgr.BeginCommand(123, "Change leg"); leg1.flagging = FlaggingKind.Begin; leg1.flagStartStop = new PointF(7, 8); eventDB.ReplaceLeg(legId, leg1); undomgr.EndCommand(123); length = QueryEvent.ComputeFlaggedLegLength(eventDB, id1, id2, legId); Assert.AreEqual(273.78, length, 0.01); undomgr.BeginCommand(123, "Change leg"); leg1.flagging = FlaggingKind.End; eventDB.ReplaceLeg(legId, leg1); undomgr.EndCommand(123); length = QueryEvent.ComputeFlaggedLegLength(eventDB, id1, id2, legId); Assert.AreEqual(295.62, length, 0.01); }
public void Replace() { Id<TestObject> id; TestObject o, p; UndoMgr undomgr = new UndoMgr(5); ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr); undomgr.BeginCommand(57, "Command1"); o = new TestObject(5, "hello", 5.4F); id = objstore.Add(o); Assert.AreEqual(1, id.id); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(1))); p = objstore[new Id<TestObject>(1)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); o = new TestObject(6, "hi", 5.4F); id = objstore.Add(o); Assert.AreEqual(2, id.id); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(2))); p = objstore[new Id<TestObject>(2)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); o = new TestObject(11, "mr ed", 9.7F); objstore.Replace(new Id<TestObject>(1), o); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(1))); p = objstore[new Id<TestObject>(1)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); o = new TestObject(13, "baz", 2.4F); objstore.Replace(new Id<TestObject>(2), o); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(2))); p = objstore[new Id<TestObject>(2)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); TestUtil.TestEnumerableAnyOrder(objstore.All, new TestObject[] { new TestObject(11, "mr ed", 9.7F), new TestObject(13, "baz", 2.4F) }); }
public void Save() { UndoMgr undomgr = new UndoMgr(5); ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr); undomgr.BeginCommand(57, "Command1"); objstore.Add(new TestObject(5, "hello", 5.4F)); objstore.Add(new TestObject(7, "hi", 3.4F)); objstore.Add(new TestObject(9, "bat", 9.9F)); undomgr.EndCommand(57); undomgr.BeginCommand(58, "Command2"); objstore.Add(new TestObject(11, "foo", 1.4F)); objstore.Replace(new Id<TestObject>(2), new TestObject(8, "goodbye", 9.4F)); objstore.Remove(new Id<TestObject>(1)); undomgr.EndCommand(58); TextWriter writer = new StringWriter(); XmlTextWriter xmloutput = new XmlTextWriter(writer); xmloutput.Formatting = Formatting.Indented; xmloutput.Namespaces = false; xmloutput.WriteStartDocument(); xmloutput.WriteStartElement("testobjects"); objstore.Save(xmloutput); xmloutput.WriteEndElement(); xmloutput.WriteEndDocument(); xmloutput.Close(); Assert.AreEqual( @"<?xml version=""1.0"" encoding=""utf-16""?> <testobjects> <testobject id=""2"" x=""8"" f=""9.4"">goodbye</testobject> <testobject id=""3"" x=""9"" f=""9.9"">bat</testobject> <testobject id=""4"" x=""11"" f=""1.4"">foo</testobject> </testobjects>", writer.ToString()); }
public override void LeftButtonClick(Pane pane, PointF location, float pixelSize, ref bool displayUpdateNeeded) { if (pane != Pane.Map) { return; } // Create the new control! // Are we creating a new control point, or using existing one? PointF highlightLocation; Id <ControlPoint> controlId = HitTestPoint(location, pixelSize, out highlightLocation); bool createNewControl = controlId.IsNone; string commandString; switch (controlKind) { case ControlPointKind.MapIssue: commandString = CommandNameText.AddMapIssue; break; case ControlPointKind.Start: commandString = CommandNameText.AddStart; break; case ControlPointKind.Finish: commandString = CommandNameText.AddFinish; break; case ControlPointKind.CrossingPoint: commandString = CommandNameText.AddCrossingPoint; break; case ControlPointKind.MapExchange: commandString = CommandNameText.AddMapExchange; break; default: if (exchangeAtControl) { commandString = CommandNameText.AddMapExchange; } else { commandString = CommandNameText.AddControl; } break; } undoMgr.BeginCommand(1321, commandString); if (createNewControl) { // Creating a new control point. string newCode = null; if (controlKind == ControlPointKind.Normal) { newCode = QueryEvent.NextUnusedControlCode(eventDB); } controlId = ChangeEvent.AddControlPoint(eventDB, controlKind, newCode, highlightLocation, 0, mapIssueKind); if (controlKind == ControlPointKind.Finish) { ChangeEvent.ChangeDescriptionSymbol(eventDB, controlId, 0, "14.3"); // set finish to "navigate to finish". } else if (controlKind == ControlPointKind.CrossingPoint) { ChangeEvent.ChangeDescriptionSymbol(eventDB, controlId, 0, "13.3"); // set to mandatory crossing point. } else if (controlKind == ControlPointKind.MapIssue) { ChangeEvent.ChangeDescriptionSymbol(eventDB, controlId, 0, "13.6"); // Map issue point. } } if (allControls) { // select the new control. selectionMgr.SelectControl(controlId); } else { // Add the control to the current course. // Get where to add the control. CourseDesignator courseDesignator; Id <CourseControl> courseControl1, courseControl2; LegInsertionLoc legInsertionLoc; GetControlInsertionPoint(highlightLocation, out courseDesignator, out courseControl1, out courseControl2, out legInsertionLoc); // And add it. Id <CourseControl> courseControlId; if (controlKind == ControlPointKind.Start) { courseControlId = ChangeEvent.AddStartOrMapIssueToCourse(eventDB, controlId, courseDesignator.CourseId, true); } else if (controlKind == ControlPointKind.MapIssue) { courseControlId = ChangeEvent.AddStartOrMapIssueToCourse(eventDB, controlId, courseDesignator.CourseId, true); } else if (controlKind == ControlPointKind.Finish) { courseControlId = ChangeEvent.AddFinishToCourse(eventDB, controlId, courseDesignator.CourseId, true); } else if (controlKind == ControlPointKind.MapExchange) { courseControlId = ChangeEvent.AddCourseControl(eventDB, controlId, courseDesignator.CourseId, courseControl1, courseControl2, legInsertionLoc); ChangeEvent.ChangeControlExchange(eventDB, courseControlId, true); } else if (exchangeAtControl && QueryEvent.CourseUsesControl(eventDB, courseDesignator, controlId)) { // Selected control already on course, just add map exchange at that courseControl(s)). courseControlId = Id <CourseControl> .None; foreach (Id <CourseControl> courseControlBecomesExchange in QueryEvent.GetCourseControlsInCourse(eventDB, courseDesignator, controlId)) { ChangeEvent.ChangeControlExchange(eventDB, courseControlBecomesExchange, true); courseControlId = courseControlBecomesExchange; } } else { courseControlId = ChangeEvent.AddCourseControl(eventDB, controlId, courseDesignator.CourseId, courseControl1, courseControl2, legInsertionLoc); if (exchangeAtControl) { ChangeEvent.ChangeControlExchange(eventDB, courseControlId, true); } } // select the new control. selectionMgr.SelectCourseControl(courseControlId); } undoMgr.EndCommand(1321); controller.DefaultCommandMode(); }
public void RoundTripSpecials() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); Special sp1, sp2, sp3, sp4, sp5, sp6, sp7, sp8, sp9, sp10, sp11, sp12, sp13; undomgr.BeginCommand(88, "Command1"); sp1 = new Special(SpecialKind.FirstAid, new PointF[1] { new PointF(4.5F, 1.2F) }); sp2 = new Special(SpecialKind.OptCrossing, new PointF[1] { new PointF(-4.2F, 1.7F) }); sp2.allCourses = false; sp2.courses = new CourseDesignator[] { Designator(1), Designator(2), Designator(3), CourseDesignator.AllControls }; sp2.orientation = 45F; sp3 = new Special(SpecialKind.Boundary, new PointF[2] { new PointF(8, 7), new PointF(1, 2) }); sp4 = new Special(SpecialKind.OOB, new PointF[4] { new PointF(3, 7), new PointF(11, 2), new PointF(0, -1), new PointF(-12, -3) }); sp5 = new Special(SpecialKind.Text, new PointF[2] { new PointF(3, 7), new PointF(11, 4) }); sp5.text = "Hello"; sp5.fontName = "Tahoma"; sp5.fontBold = true; sp5.fontItalic = false; sp5.allCourses = false; sp5.color = new SpecialColor(0.2F, 0.5F, 0.3F, 0F); sp5.courses = new CourseDesignator[2] { Designator(2), new CourseDesignator(CourseId(3), 1) }; sp6 = new Special(SpecialKind.Descriptions, new PointF[2] { new PointF(5, 6), new PointF(11, 6) }); sp6.numColumns = 2; sp7 = new Special(SpecialKind.Text, new PointF[2] { new PointF(8, 7), new PointF(18, 5) }); sp7.fontName = "Courier New"; sp7.fontBold = false; sp7.fontItalic = true; sp7.text = "$(CourseName)"; sp7.color = SpecialColor.Purple; sp8 = new Special(SpecialKind.WhiteOut, new PointF[4] { new PointF(13, 17), new PointF(21, 12), new PointF(10, -1), new PointF(-2, 7) }); sp9 = new Special(SpecialKind.Image, new PointF[2] { new PointF(18, 17), new PointF(28, 15) }); sp9.imageBitmap = (Bitmap)Image.FromFile(TestUtil.GetTestFile("eventDB\\testimage.jpg")); sp9.text = "testimage.jpg"; sp10 = new Special(SpecialKind.Line, new PointF[3] { new PointF(8, 7), new PointF(1, 2), new PointF(5, 12) }); sp10.color = SpecialColor.Black; sp10.lineKind = LineKind.Single; sp10.lineWidth = 0.1F; sp11 = new Special(SpecialKind.Line, new PointF[3] { new PointF(8, 7), new PointF(1, 2), new PointF(5, 12) }); sp11.color = new SpecialColor(1F, 0.66F, 0.45F, 0.83F); sp11.lineKind = LineKind.Double; sp11.lineWidth = 0.1F; sp11.gapSize = 0.15F; sp12 = new Special(SpecialKind.Line, new PointF[2] { new PointF(8, 7), new PointF(1, 2) }); sp12.color = SpecialColor.Purple; sp12.lineKind = LineKind.Dashed; sp12.lineWidth = 0.1F; sp12.gapSize = 0.15F; sp12.dashSize = 0.44F; sp13 = new Special(SpecialKind.Rectangle, new PointF[2] { new PointF(8, 7), new PointF(1, 2) }); sp13.color = SpecialColor.Purple; sp13.lineKind = LineKind.Single; sp13.lineWidth = 0.1F; sp13.cornerRadius = 0.23F; eventDB.AddSpecial(sp1); eventDB.AddSpecial(sp2); eventDB.AddSpecial(sp3); eventDB.AddSpecial(sp4); eventDB.AddSpecial(sp5); eventDB.AddSpecial(sp6); eventDB.AddSpecial(sp7); eventDB.AddSpecial(sp8); eventDB.AddSpecial(sp9); eventDB.AddSpecial(sp10); eventDB.AddSpecial(sp11); eventDB.AddSpecial(sp12); eventDB.AddSpecial(sp13); undomgr.EndCommand(88); eventDB.Save(TestUtil.GetTestFile("eventDB\\testoutput_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); // The loaded image won't compare equal. Check the image is the same, then force equal. Special loadedSp9 = eventDB.GetSpecial(SpecialId(9)); Assert.IsNotNull(loadedSp9.imageBitmap); Assert.AreEqual(loadedSp9.imageBitmap.Width, sp9.imageBitmap.Width); Assert.AreEqual(loadedSp9.imageBitmap.Height, sp9.imageBitmap.Height); Assert.AreEqual(loadedSp9.imageBitmap.RawFormat, sp9.imageBitmap.RawFormat); loadedSp9.imageBitmap = sp9.imageBitmap; TestUtil.TestEnumerableAnyOrder(eventDB.AllSpecialPairs, new KeyValuePair<Id<Special>, Special>[] { new KeyValuePair<Id<Special>,Special>(SpecialId(1), sp1), new KeyValuePair<Id<Special>,Special>(SpecialId(2), sp2), new KeyValuePair<Id<Special>,Special>(SpecialId(3), sp3), new KeyValuePair<Id<Special>,Special>(SpecialId(4), sp4), new KeyValuePair<Id<Special>,Special>(SpecialId(5), sp5), new KeyValuePair<Id<Special>,Special>(SpecialId(6), sp6), new KeyValuePair<Id<Special>,Special>(SpecialId(7), sp7), new KeyValuePair<Id<Special>,Special>(SpecialId(8), sp8), new KeyValuePair<Id<Special>,Special>(SpecialId(9), sp9), new KeyValuePair<Id<Special>,Special>(SpecialId(10), sp10), new KeyValuePair<Id<Special>,Special>(SpecialId(11), sp11), new KeyValuePair<Id<Special>,Special>(SpecialId(12), sp12), new KeyValuePair<Id<Special>,Special>(SpecialId(13), sp13), } ); }
public void RoundTripCourses() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); RectangleF mapBounds = new RectangleF(0, 0, 200, 300); Course course1, course2, course3, course4, course5; undomgr.BeginCommand(61, "Command1"); course1 = new Course(CourseKind.Normal, "White", 15000, 1); course1.descKind = DescriptionKind.Symbols; course1.secondaryTitle = "White is right"; course1.load = 0; course1.firstCourseControl = CourseControlId(1); course1.UpdateUnknownPageSizes(mapBounds, 15000); eventDB.AddCourse(course1); course2 = new Course(CourseKind.Normal, "Yellow", 15000, 2); course2.hideVariationsOnMap = true; course2.descKind = DescriptionKind.SymbolsAndText; course2.climb = 95; course2.labelKind = ControlLabelKind.Code; course2.firstCourseControl = CourseControlId(0); course2.printArea = new PrintArea(false, true, new RectangleF(50, 70, 200, 100)); course2.partPrintAreas[1] = new PrintArea(false, false, new RectangleF(10, 20, 30, 40), 1.1F); course2.partPrintAreas[0] = new PrintArea(true, false, new RectangleF(70, 10, 130, 140)); course2.partOptions[1] = new PartOptions() { ShowFinish = true }; course2.partOptions[0] = new PartOptions() { ShowFinish = false }; course2.relaySettings = new RelaySettings(6, 43, 3); course2.UpdateUnknownPageSizes(mapBounds, 15000); eventDB.AddCourse(course2); course3 = new Course(CourseKind.Score, "Rambo", 10000, 3); course3.secondaryTitle = ""; course3.firstCourseControl = CourseControlId(2); course3.load = 125; course3.climb = 0; course3.firstControlOrdinal = 7; course3.labelKind = ControlLabelKind.SequenceAndCode; course3.descKind = DescriptionKind.Text; course3.partPrintAreas[1] = new PrintArea(true, true, new RectangleF(-10, -20, 90, 80), 0.9F); course3.UpdateUnknownPageSizes(mapBounds, 15000); eventDB.AddCourse(course3); course4 = new Course(CourseKind.Score, "Silly1", 10000, 3); course4.secondaryTitle = ""; course4.firstCourseControl = CourseControlId(2); course4.load = 0; course4.climb = 25; course4.overrideCourseLength = 4243; course4.firstControlOrdinal = 3; course4.labelKind = ControlLabelKind.SequenceAndScore; course4.descKind = DescriptionKind.SymbolsAndText; course4.partPrintAreas[1] = new PrintArea(false, false, new RectangleF(-10, -20, 90, 80)); course4.partOptions[1] = new PartOptions() { ShowFinish = false }; course4.UpdateUnknownPageSizes(mapBounds, 15000); eventDB.AddCourse(course4); course5 = new Course(CourseKind.Score, "Silly2", 10000, 3); course5.secondaryTitle = ""; course5.firstCourseControl = CourseControlId(2); course5.load = 125; course5.climb = 0; course5.firstControlOrdinal = 1; course5.labelKind = ControlLabelKind.CodeAndScore; course5.descKind = DescriptionKind.Symbols; course5.partPrintAreas[1] = new PrintArea(false, false, new RectangleF(-10, -20, 90, 80), 1.25F); FixedBranchAssignments relayBranchAssignments = new FixedBranchAssignments(); relayBranchAssignments.AddBranchAssignment('B', 1); relayBranchAssignments.AddBranchAssignment('A', 2); relayBranchAssignments.AddBranchAssignment('A', 3); relayBranchAssignments.AddBranchAssignment('C', 4); course5.relaySettings = new RelaySettings(10, 5, 6, relayBranchAssignments); course5.UpdateUnknownPageSizes(mapBounds, 15000); eventDB.AddCourse(course5); 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")); Assert.AreEqual(eventDB.GetCourse(CourseId(1)), course1); Assert.AreEqual(eventDB.GetCourse(CourseId(2)), course2); Assert.AreEqual(eventDB.GetCourse(CourseId(3)), course3); Assert.AreEqual(eventDB.GetCourse(CourseId(4)), course4); Assert.AreEqual(eventDB.GetCourse(CourseId(5)), course5); TestUtil.TestEnumerableAnyOrder(eventDB.AllCoursePairs, new KeyValuePair <Id <Course>, Course>[] { new KeyValuePair <Id <Course>, Course>(CourseId(1), course1), new KeyValuePair <Id <Course>, Course>(CourseId(2), course2), new KeyValuePair <Id <Course>, Course>(CourseId(3), course3), new KeyValuePair <Id <Course>, Course>(CourseId(4), course4), new KeyValuePair <Id <Course>, Course>(CourseId(5), course5), } ); }
public void RoundTripControlPoints() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); ControlPoint ctl1, ctl2, ctl3, ctl4, ctl5, ctl6, ctl7, ctl8; undomgr.BeginCommand(61, "Command1"); ctl1 = new ControlPoint(ControlPointKind.Start, null, new PointF(5, 0)); ctl1.symbolIds[1] = "2.8"; ctl1.symbolIds[2] = "8.5"; eventDB.AddControlPoint(ctl1); ctl2 = new ControlPoint(ControlPointKind.Normal, "31", new PointF(10, 10)); ctl2.symbolIds[0] = "0.3"; ctl2.symbolIds[1] = "2.4"; ctl2.columnFText = "2m"; ctl2.customCodeLocation = true; ctl2.codeLocationAngle = 97F; eventDB.AddControlPoint(ctl2); ctl3 = new ControlPoint(ControlPointKind.CrossingPoint, null, new PointF(13, -7.8F)); ctl3.symbolIds[0] = "13.2"; ctl3.orientation = 94.5F; eventDB.AddControlPoint(ctl3); ctl4 = new ControlPoint(ControlPointKind.Normal, "32", new PointF(20, -10.5F)); ctl4.symbolIds[1] = "3.7"; ctl4.symbolIds[5] = "12.1"; ctl4.gaps = new Dictionary<int,CircleGap[]>(); ctl4.gaps.Add(15000, CircleGap.ComputeCircleGaps(0xFFFFFFDF)); ctl4.gaps.Add(10000, CircleGap.ComputeCircleGaps(0xFF00FFFF)); ctl4.descriptionText = "very marshy spot"; ctl4.punches = new PunchPattern(); ctl4.punches.size = 9; ctl4.punches.dots = new bool[ctl4.punches.size, ctl4.punches.size]; ctl4.punches.dots[0, 0] = true; ctl4.punches.dots[4, 4] = true; ctl4.punches.dots[8, 8] = true; ctl4.punches.dots[8, 0] = true; eventDB.AddControlPoint(ctl4); ctl5 = new ControlPoint(ControlPointKind.Normal, "GO", new PointF(35.4F, -22.5F)); ctl5.symbolIds[0] = "0.1N"; ctl5.symbolIds[1] = "5.5"; ctl5.symbolIds[2] = "5.2"; ctl5.symbolIds[3] = "10.1"; ctl5.symbolIds[4] = "11.1N"; ctl5.symbolIds[5] = "12.3"; eventDB.AddControlPoint(ctl5); ctl6 = new ControlPoint(ControlPointKind.Finish, null, new PointF(30.3F, -27.11F)); ctl6.symbolIds[0] = "14.2"; eventDB.AddControlPoint(ctl6); ctl7 = new ControlPoint(ControlPointKind.Normal, "QX", new PointF(43, 7.1F)); ctl7.symbolIds[1] = "3.6"; ctl7.descTextBefore = "hi there"; ctl7.descTextAfter = "bye there"; eventDB.AddControlPoint(ctl7); ctl8 = new ControlPoint(ControlPointKind.MapExchange, null, new PointF(133, 7.8F)); ctl8.symbolIds[0] = "13.5"; eventDB.AddControlPoint(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")); TestUtil.TestEnumerableAnyOrder(eventDB.AllControlPointPairs, new KeyValuePair<Id<ControlPoint>, ControlPoint>[] { new KeyValuePair<Id<ControlPoint>,ControlPoint>(ControlId(1), ctl1), new KeyValuePair<Id<ControlPoint>,ControlPoint>(ControlId(2), ctl2), new KeyValuePair<Id<ControlPoint>,ControlPoint>(ControlId(3), ctl3), new KeyValuePair<Id<ControlPoint>,ControlPoint>(ControlId(4), ctl4), new KeyValuePair<Id<ControlPoint>,ControlPoint>(ControlId(5), ctl5), new KeyValuePair<Id<ControlPoint>,ControlPoint>(ControlId(6), ctl6), new KeyValuePair<Id<ControlPoint>,ControlPoint>(ControlId(7), ctl7), new KeyValuePair<Id<ControlPoint>,ControlPoint>(ControlId(8), ctl8) } ); }
public void RoundTripLeg() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); Leg leg1, leg2, leg3, leg4, leg5, leg6; ControlPoint ctl1, ctl2; Id <ControlPoint> ctlId1, ctlId2; undomgr.BeginCommand(81, "Command1"); ctl1 = new ControlPoint(ControlPointKind.Normal, "31", new PointF(10, 10)); ctl1.symbolIds[0] = "0.3"; ctl1.symbolIds[1] = "2.4"; ctl1.columnFText = "2m"; ctlId1 = eventDB.AddControlPoint(ctl1); ctl2 = new ControlPoint(ControlPointKind.Normal, "32", new PointF(20, -10.5F)); ctl2.symbolIds[1] = "3.7"; ctl2.symbolIds[5] = "12.1"; ctl2.gaps = new Dictionary <int, CircleGap[]>(); ctl2.gaps.Add(15000, CircleGap.ComputeCircleGaps(0xFFFFFFDF)); ctl2.gaps.Add(10000, CircleGap.ComputeCircleGaps(0xFF00FFFF)); ctl2.descriptionText = "very marshy spot"; ctlId2 = eventDB.AddControlPoint(ctl2); leg1 = new Leg(ctlId1, ctlId2); eventDB.AddLeg(leg1); leg2 = new Leg(ctlId1, ctlId2); leg2.flagging = FlaggingKind.All; eventDB.AddLeg(leg2); leg3 = new Leg(ctlId1, ctlId2); leg3.flagging = FlaggingKind.Begin; leg3.flagStartStop = new PointF(5, -7.5F); leg3.bends = new PointF[2] { leg3.flagStartStop, new PointF(17, 6) }; eventDB.AddLeg(leg3); leg4 = new Leg(ctlId1, ctlId2); leg4.flagging = FlaggingKind.End; leg4.flagStartStop = new PointF(5, -7.5F); leg4.bends = new PointF[1] { leg4.flagStartStop }; leg4.gaps = new LegGap[2] { new LegGap(2, 0.3F), new LegGap(3.4F, 0.4F) }; eventDB.AddLeg(leg4); leg5 = new Leg(ctlId1, ctlId2); leg5.gaps = new LegGap[3] { new LegGap(0.9F, 0.3F), new LegGap(3.4F, 0.4F), new LegGap(4.5F, 1.1F) }; eventDB.AddLeg(leg5); leg6 = new Leg(ctlId1, ctlId2); leg6.flagging = FlaggingKind.IssuePointMiddle; leg6.flagStartStop = new PointF(5, -7.5F); leg6.bends = new PointF[1] { leg6.flagStartStop }; eventDB.AddLeg(leg6); undomgr.EndCommand(81); eventDB.Validate(); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); eventDB.Validate(); TestUtil.TestEnumerableAnyOrder(eventDB.AllLegPairs, new KeyValuePair <Id <Leg>, Leg>[] { new KeyValuePair <Id <Leg>, Leg>(LegId(1), leg1), new KeyValuePair <Id <Leg>, Leg>(LegId(2), leg2), new KeyValuePair <Id <Leg>, Leg>(LegId(3), leg3), new KeyValuePair <Id <Leg>, Leg>(LegId(4), leg4), new KeyValuePair <Id <Leg>, Leg>(LegId(5), leg5), new KeyValuePair <Id <Leg>, Leg>(LegId(6), leg6) } ); }
public void ChangeNum() { int changeNum; Id<TestObject> id; TestObject o; UndoMgr undomgr = new UndoMgr(5); ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr); changeNum = objstore.ChangeNum; undomgr.BeginCommand(57, "Command1"); o = new TestObject(5, "hello", 5.4F); id = objstore.Add(o); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; objstore.Remove(new Id<TestObject>(1)); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; id = objstore.Add(o); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; objstore.Replace(new Id<TestObject>(2), o); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; undomgr.EndCommand(57); undomgr.Undo(); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; undomgr.Redo(); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; }
public void RoundTripControlPoints() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); ControlPoint ctl1, ctl2, ctl3, ctl4, ctl5, ctl6, ctl7, ctl8, ctl9, ctl10, ctl11; undomgr.BeginCommand(61, "Command1"); ctl1 = new ControlPoint(ControlPointKind.Start, null, new PointF(5, 0)); ctl1.symbolIds[1] = "2.8"; ctl1.symbolIds[2] = "8.5"; eventDB.AddControlPoint(ctl1); ctl2 = new ControlPoint(ControlPointKind.Normal, "31", new PointF(10, 10)); ctl2.symbolIds[0] = "0.3"; ctl2.symbolIds[1] = "2.4"; ctl2.columnFText = "2m"; ctl2.customCodeLocation = true; ctl2.codeLocationAngle = 97F; eventDB.AddControlPoint(ctl2); ctl3 = new ControlPoint(ControlPointKind.CrossingPoint, null, new PointF(13, -7.8F)); ctl3.symbolIds[0] = "13.2"; ctl3.orientation = 94.5F; eventDB.AddControlPoint(ctl3); ctl4 = new ControlPoint(ControlPointKind.Normal, "32", new PointF(20, -10.5F)); ctl4.symbolIds[1] = "3.7"; ctl4.symbolIds[5] = "12.1"; ctl4.gaps = new Dictionary <int, CircleGap[]>(); ctl4.gaps.Add(15000, CircleGap.ComputeCircleGaps(0xFFFFFFDF)); ctl4.gaps.Add(10000, CircleGap.ComputeCircleGaps(0xFF00FFFF)); ctl4.descriptionText = "very marshy spot"; ctl4.punches = new PunchPattern(); ctl4.punches.size = 9; ctl4.punches.dots = new bool[ctl4.punches.size, ctl4.punches.size]; ctl4.punches.dots[0, 0] = true; ctl4.punches.dots[4, 4] = true; ctl4.punches.dots[8, 8] = true; ctl4.punches.dots[8, 0] = true; eventDB.AddControlPoint(ctl4); ctl5 = new ControlPoint(ControlPointKind.Normal, "GO", new PointF(35.4F, -22.5F)); ctl5.symbolIds[0] = "0.1N"; ctl5.symbolIds[1] = "5.5"; ctl5.symbolIds[2] = "5.2"; ctl5.symbolIds[3] = "10.1"; ctl5.symbolIds[4] = "11.1N"; ctl5.symbolIds[5] = "12.3"; eventDB.AddControlPoint(ctl5); ctl6 = new ControlPoint(ControlPointKind.Finish, null, new PointF(30.3F, -27.11F)); ctl6.symbolIds[0] = "14.2"; eventDB.AddControlPoint(ctl6); ctl7 = new ControlPoint(ControlPointKind.Normal, "QX", new PointF(43, 7.1F)); ctl7.symbolIds[1] = "3.6"; ctl7.descTextBefore = "hi there"; ctl7.descTextAfter = "bye there"; eventDB.AddControlPoint(ctl7); ctl8 = new ControlPoint(ControlPointKind.MapExchange, null, new PointF(133, 7.8F)); ctl8.symbolIds[0] = "13.5"; eventDB.AddControlPoint(ctl8); ctl9 = new ControlPoint(ControlPointKind.MapIssue, null, new PointF(40.3F, -7.11F)); ctl9.symbolIds[0] = "13.6"; ctl9.mapIssueKind = MapIssueKind.Beginning; eventDB.AddControlPoint(ctl9); ctl10 = new ControlPoint(ControlPointKind.MapIssue, null, new PointF(-17.2F, 7.01F)); ctl10.symbolIds[0] = "13.6"; ctl10.mapIssueKind = MapIssueKind.Middle; eventDB.AddControlPoint(ctl10); ctl11 = new ControlPoint(ControlPointKind.MapIssue, null, new PointF(1.3F, 14.5F)); ctl11.symbolIds[0] = "13.6"; ctl11.mapIssueKind = MapIssueKind.End; eventDB.AddControlPoint(ctl11); 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")); TestUtil.TestEnumerableAnyOrder(eventDB.AllControlPointPairs, new KeyValuePair <Id <ControlPoint>, ControlPoint>[] { new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(1), ctl1), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(2), ctl2), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(3), ctl3), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(4), ctl4), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(5), ctl5), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(6), ctl6), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(7), ctl7), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(8), ctl8), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(9), ctl9), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(10), ctl10), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(11), ctl11) } ); }
public void LoadModifySave() { Id<TestObject> id; UndoMgr undomgr = new UndoMgr(5); ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr); string xmlText = @"<?xml version=""1.0"" encoding=""utf-16""?> <testobjects> <testobject id=""2"" x=""8"" f=""9.4"">goodbye</testobject> <testobject id=""4"" x=""11"" f=""1.4"">foo</testobject> </testobjects>"; XmlInput xmlinput = new XmlInput(new StringReader(xmlText), "testfile"); xmlinput.CheckElement("testobjects"); xmlinput.Read(); objstore.Load(xmlinput); xmlinput.Dispose(); undomgr.BeginCommand(57, "Command1"); id = objstore.Add(new TestObject(5, "hello", 5.4F)); Assert.AreEqual(5, id.id); id = objstore.Add(new TestObject(9, "bat", 9.9F)); Assert.AreEqual(6, id.id); undomgr.EndCommand(57); undomgr.BeginCommand(58, "Command2"); objstore.Replace(new Id<TestObject>(2), new TestObject(-9, "elvis", 9.1F)); objstore.Remove(new Id<TestObject>(4)); undomgr.EndCommand(58); TextWriter writer = new StringWriter(); XmlTextWriter xmloutput = new XmlTextWriter(writer); xmloutput.Formatting = Formatting.Indented; xmloutput.Namespaces = false; xmloutput.WriteStartDocument(); xmloutput.WriteStartElement("testobjects"); objstore.Save(xmloutput); xmloutput.WriteEndElement(); xmloutput.WriteEndDocument(); xmloutput.Close(); Assert.AreEqual( @"<?xml version=""1.0"" encoding=""utf-16""?> <testobjects> <testobject id=""2"" x=""-9"" f=""9.1"">elvis</testobject> <testobject id=""5"" x=""5"" f=""5.4"">hello</testobject> <testobject id=""6"" x=""9"" f=""9.9"">bat</testobject> </testobjects>", writer.ToString()); }
public void AutoRenumber2() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); Event ev = new Event(); Id<ControlPoint>[] ids = new Id<ControlPoint>[10]; undomgr.BeginCommand(123, "Add controls"); ids[0] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "64", new PointF())); //64 ids[1] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "69", new PointF())); //69 ids[2] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "67", new PointF())); //67 ids[3] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "71", new PointF())); //71 ids[4] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "73", new PointF())); //65 ids[5] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "61", new PointF())); //62 ids[6] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "66", new PointF())); //63 ids[7] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "60", new PointF())); //60 ids[8] = eventDB.AddControlPoint(new ControlPoint(ControlPointKind.Normal, "70", new PointF())); //70 ev.mapScale = 15000; ev.firstControlCode = 60; ev.disallowInvertibleCodes = true; eventDB.ChangeEvent(ev); ChangeEvent.AutoRenumberControls(eventDB); undomgr.EndCommand(123); Assert.AreEqual("64", eventDB.GetControl(ids[0]).code); Assert.AreEqual("69", eventDB.GetControl(ids[1]).code); Assert.AreEqual("67", eventDB.GetControl(ids[2]).code); Assert.AreEqual("71", eventDB.GetControl(ids[3]).code); Assert.AreEqual("65", eventDB.GetControl(ids[4]).code); Assert.AreEqual("62", eventDB.GetControl(ids[5]).code); Assert.AreEqual("63", eventDB.GetControl(ids[6]).code); Assert.AreEqual("60", eventDB.GetControl(ids[7]).code); Assert.AreEqual("70", eventDB.GetControl(ids[8]).code); }
public void Present() { Id<TestObject> id; TestObject o; UndoMgr undomgr = new UndoMgr(5); ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr); undomgr.BeginCommand(57, "Command1"); o = new TestObject(5, "hello", 5.4F); id = objstore.Add(o); Assert.AreEqual(1, id.id); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(1))); Assert.IsFalse(objstore.IsPresent(new Id<TestObject>(2))); objstore.CheckPresent(new Id<TestObject>(1)); try { objstore.IsPresent(new Id<TestObject>(2)); Assert.Fail("should throw"); } catch { } }
public void RoundTripEvent() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); Event e = new Event(); e.title = "Hello"; e.notes = "These are my notes"; e.mapType = MapType.OCAD; e.mapFileName = "C:\\hello.ocad"; e.mapScale = 14000; e.allControlsPrintScale = 10000; e.allControlsDescKind = DescriptionKind.SymbolsAndText; e.printArea = new PrintArea(false, false, new RectangleF(50, 70, 200, 300)); e.punchcardFormat.boxesAcross = 7; e.punchcardFormat.boxesDown = 5; e.punchcardFormat.leftToRight = false; e.punchcardFormat.topToBottom = true; undomgr.BeginCommand(198, "change event"); eventDB.ChangeEvent(e); undomgr.EndCommand(198); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput1_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput1_temp.xml")); Assert.AreEqual(e, eventDB.GetEvent()); Assert.AreEqual(7, e.punchcardFormat.boxesAcross); /* --- */ undomgr.Clear(); eventDB = new EventDB(undomgr); e.title = "Hi"; e.notes = null; e.mapType = MapType.None; e.mapFileName = null; e.courseAppearance.purpleColorBlend = true; undomgr.BeginCommand(198, "change event"); eventDB.ChangeEvent(e); undomgr.EndCommand(198); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput2_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput2_temp.xml")); Assert.AreEqual(e, eventDB.GetEvent()); /* --- */ undomgr.Clear(); eventDB = new EventDB(undomgr); e.title = "Hi"; e.notes = null; e.mapType = MapType.Bitmap; e.mapFileName = TestUtil.GetTestFile("eventdb\\maps\\testoutput3.jpg"); e.mapScale = 12000; e.mapDpi = 330; e.allControlsPrintScale = 7500; e.allControlsDescKind = DescriptionKind.Text; e.descriptionLangId = "bg"; e.courseAppearance.useOcadOverprint = true; undomgr.BeginCommand(198, "change event"); eventDB.ChangeEvent(e); undomgr.EndCommand(198); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput3_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput3_temp.xml")); Assert.AreEqual(e, eventDB.GetEvent()); /* --- */ undomgr.Clear(); eventDB = new EventDB(undomgr); e.title = "Hi"; e.notes = null; e.mapType = MapType.None; e.mapFileName = null; e.mapScale = 12000; e.mapDpi = 330; e.allControlsPrintScale = 7500; e.allControlsDescKind = DescriptionKind.Text; e.courseAppearance.lineWidth = 1.3F; e.courseAppearance.controlCircleSize = 0.9F; e.courseAppearance.centerDotDiameter = 0.53F; e.courseAppearance.numberHeight = 1.1F; e.courseAppearance.numberBold = true; e.courseAppearance.numberOutlineWidth = 0.5F; e.courseAppearance.autoLegGapSize = 2.75F; e.courseAppearance.useDefaultPurple = false; e.courseAppearance.purpleC = 0.4F; e.courseAppearance.purpleM = 0.5F; e.courseAppearance.purpleY = 0.6F; e.courseAppearance.purpleK = 0.74F; e.courseAppearance.descriptionsPurple = true; undomgr.BeginCommand(198, "change event"); eventDB.ChangeEvent(e); undomgr.EndCommand(198); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput5_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput5_temp.xml")); Assert.AreEqual(e, eventDB.GetEvent()); /* --- */ undomgr.Clear(); eventDB = new EventDB(undomgr); e.title = "Mr. Event"; e.notes = null; e.mapType = MapType.OCAD; e.mapFileName = TestUtil.GetTestFile("eventdb\\My Map-File.ocad"); e.ignoreMissingFonts = true; List<SymbolText> texts = new List<SymbolText>(); SymbolText text1 = new SymbolText(), text2 = new SymbolText(), text3 = new SymbolText(); text1.Lang = "en"; text1.Gender = ""; text1.Plural = false; text1.Text = "man-made & cool object"; text2.Lang = "en"; text2.Gender = ""; text2.Plural = true; text2.Text = "man-made & cool objects"; text3.Lang = "bg"; text3.Gender = "masculine"; text3.Plural = false; text3.Text = "bulgarish mm"; texts.Add(text1); texts.Add(text2); texts.Add(text3); e.customSymbolText["6.1"] = texts; texts = new List<SymbolText>(); text1.Lang = "en"; text1.Gender = ""; text1.Plural = false; text1.Text = "boopsie"; text1.Case = ""; texts.Add(text1); e.customSymbolText["6.2"] = texts; e.customSymbolKey["6.2"] = true; e.customSymbolKey["6.1"] = false; undomgr.BeginCommand(198, "change event"); eventDB.ChangeEvent(e); undomgr.EndCommand(198); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput4_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput4_temp.xml")); Assert.AreEqual(e, eventDB.GetEvent()); }
public void ComputeLegLengthBends() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); ControlPoint control1, control2; Leg leg1; Event ev = new Event(); control1 = new ControlPoint(ControlPointKind.Normal, "31", new PointF(4.5F, -10.1F)); control2 = new ControlPoint(ControlPointKind.Normal, "32", new PointF(-6.8F, 14.1F)); undomgr.BeginCommand(123, "Add controls"); Id<ControlPoint> id1 = eventDB.AddControlPoint(control1); Id<ControlPoint> id2 = eventDB.AddControlPoint(control2); leg1 = new Leg(id1, id2); leg1.bends = new PointF[] { new PointF(7, 8), new PointF(10, 14) }; Id<Leg> legId = eventDB.AddLeg(leg1); ev.mapScale = 15000; eventDB.ChangeEvent(ev); undomgr.EndCommand(123); float length = QueryEvent.ComputeLegLength(eventDB, id1, id2, legId); Assert.AreEqual(626.7, length, 0.01); SymPath path = QueryEvent.GetLegPath(eventDB, id1, id2); Assert.AreEqual(new SymPath(new PointF[] { new PointF(4.5F, -10.1F), new PointF(7, 8), new PointF(10, 14), new PointF(-6.8F, 14.1F) }), path); }