public void AddCornerArea() { Setup("modes\\marymoor2.coursescribe"); // Select course 3. controller.SelectTab(3); // Course 3. CheckHighlightedLines(controller, -1, -1); // Click on area objects. MapViewer.DragAction dragAction = controller.LeftButtonDown(Pane.Map, new PointF(1, -2), 0.3F); Assert.AreEqual(MapViewer.DragAction.DelayedDrag, dragAction); controller.LeftButtonClick(Pane.Map, new PointF(1, -2), 0.3F); // Begin the add corner mode. controller.BeginAddSpecialCorner(); // Should have crosshair cursor ui.MouseMoved(-4, 7, 0.3F); Cursor cursor = controller.GetMouseCursor(Pane.Map, new PointF(-4, 7), 0.3F); Assert.AreSame(Cursors.Cross, cursor); // And the adding corner text. Assert.AreEqual(StatusBarText.AddingCorner, controller.StatusText); // Check the highlights CourseObj[] highlights = (CourseObj[])controller.GetHighlights(Pane.Map); Assert.AreEqual(1, highlights.Length); Assert.AreEqual(@"OOB: special:4 scale:1 path:N(3,7)--N(11,2)--N(0,-7)--N(-12,-3)--N(3,7)", highlights[0].ToString()); // Click to add a corner. dragAction = controller.LeftButtonDown(Pane.Map, new PointF(-4, 7), 0.3F); Assert.AreEqual(MapViewer.DragAction.None, dragAction); // Check the status text Assert.AreEqual(StatusBarText.DragCorner, controller.StatusText); // Check the cursor cursor = controller.GetMouseCursor(Pane.Map, new PointF(-4, 7), 0.3F); Assert.AreSame(Util.MoveHandleCursor, cursor); // Check the highlights highlights = (CourseObj[])controller.GetHighlights(Pane.Map); Assert.AreEqual(1, highlights.Length); Assert.AreEqual("OOB: special:4 scale:1 path:N(3,7)--N(11,2)--N(0,-7)--N(-12,-3)--N(-4,7)--N(3,7)", highlights[0].ToString()); // Make sure the special has a new corner. Special special = eventDB.GetSpecial(SpecialId(4)); Assert.AreEqual(5, special.locations.Length); Assert.AreEqual(new PointF(3, 7), special.locations[0]); Assert.AreEqual(new PointF(11, 2), special.locations[1]); Assert.AreEqual(new PointF(0, -7), special.locations[2]); Assert.AreEqual(new PointF(-12, -3), special.locations[3]); Assert.AreEqual(new PointF(-4, 7), special.locations[4]); }
// Get the text name for a control. private static string SpecialName(EventDB eventDB, Id <Special> specialId) { Special special = eventDB.GetSpecial(specialId); // Resources have the name "SpecialKind_xxx" where "xxx" is the enumeration name. return(SelectionDescriptionText.ResourceManager.GetString("SpecialName_" + special.kind.ToString())); }
public void RotateOptionalCrossing() { CourseObj[] highlights; // Select Course 3 controller.SelectTab(3); // Select mandatory crossing point. var dragAction = controller.LeftButtonDown(Pane.Map, new PointF(76, -5F), 0.2F); Assert.AreEqual(MapViewer.DragAction.DelayedDrag, dragAction); controller.LeftButtonClick(Pane.Map, new PointF(76, -5F), 0.3F); highlights = (CourseObj[])controller.GetHighlights(Pane.Map); Assert.AreEqual(1, highlights.Length); Assert.AreEqual(2, highlights[0].specialId.id); // Begin rotating mode. controller.BeginRotate(); highlights = (CourseObj[])controller.GetHighlights(Pane.Map); Assert.AreEqual(1, highlights.Length); CrossingCourseObj obj = (CrossingCourseObj)highlights[0]; Assert.AreEqual(new PointF(76, -4.8F), obj.location); // Should have correct status text. Assert.AreEqual(StatusBarText.RotatingObject, controller.StatusText); // Move the mouse somewhere (mouse buttons are up). ui.MouseMoved(31, -11, 0.1F); // The highlight should be in the same place, but rotated. highlights = (CourseObj[])controller.GetHighlights(Pane.Map); Assert.AreEqual(1, highlights.Length); obj = (CrossingCourseObj)highlights[0]; Assert.AreEqual(new PointF(76, -4.8F), obj.location); Assert.AreEqual(97.8F, obj.orientation, 0.1F); // Mouse down somewhere. MapViewer.DragAction action = controller.LeftButtonDown(Pane.Map, new PointF(44, 29), 0.1F); // The highlight should be in the same place, but rotated again. highlights = (CourseObj[])controller.GetHighlights(Pane.Map); Assert.AreEqual(1, highlights.Length); obj = (CrossingCourseObj)highlights[0]; Assert.AreEqual(new PointF(76, -4.8F), obj.location); Assert.AreEqual(43.4F, obj.orientation, 0.1F); // The control should have its orientation changed, but not its position. Special special = eventDB.GetSpecial(SpecialId(2)); Assert.AreEqual(new PointF(76, -4.8F), special.locations[0]); Assert.AreEqual(43.4F, special.orientation, 0.1F); }
// Describe a special. private static TextPart[] DescribeSpecial(EventDB eventDB, Id <Special> specialId, float scaleRatio, DescKind descKind) { Debug.Assert(descKind == DescKind.Tooltip || descKind == DescKind.DescPane); List <TextPart> list = new List <TextPart>(); Special special = eventDB.GetSpecial(specialId); // Name of the special. list.Add(new TextPart(TextFormat.Title, SpecialName(eventDB, specialId))); if (descKind == DescKind.DescPane) { // Special location. if (special.kind == SpecialKind.FirstAid || special.kind == SpecialKind.Water || special.kind == SpecialKind.Forbidden || special.kind == SpecialKind.OptCrossing || special.kind == SpecialKind.RegMark || special.kind == SpecialKind.Descriptions) { list.Add(new TextPart(TextFormat.Header, SelectionDescriptionText.Location + " ")); list.Add(new TextPart(TextFormat.SameLine, string.Format("({0:##0.0}, {1:##0.0})", special.locations[0].X, special.locations[0].Y))); } } if (special.kind == SpecialKind.Image) { list.Add(new TextPart(TextFormat.Header, SelectionDescriptionText.FileName + " ")); list.Add(new TextPart(TextFormat.SameLine, string.Format("{0}", special.text))); } if (special.kind == SpecialKind.Boundary || special.kind == SpecialKind.Line) { list.Add(new TextPart(TextFormat.Header, SelectionDescriptionText.Length)); list.Add(new TextPart(TextFormat.SameLine, string.Format("{0:#,###} m", QueryEvent.ComputeSpecialLength(eventDB, specialId)))); } // Line height for descriptions. if (special.kind == SpecialKind.Descriptions) { list.Add(new TextPart(TextFormat.Header, SelectionDescriptionText.LineHeight + " ")); list.Add(new TextPart(TextFormat.SameLine, string.Format("{0:#0.0} mm", Geometry.Distance(special.locations[0], special.locations[1]) / scaleRatio))); } // Which courses is it used in? list.Add(new TextPart(TextFormat.Header, (descKind == DescKind.Tooltip ? SelectionDescriptionText.UsedIn : SelectionDescriptionText.UsedInCourses))); if (special.allCourses) { list.Add(new TextPart(descKind == DescKind.Tooltip ? TextFormat.SameLine : TextFormat.NewLine, SelectionDescriptionText.CourseList_AllCourses)); } else { list.Add(new TextPart(descKind == DescKind.Tooltip ? TextFormat.SameLine : TextFormat.NewLine, CourseListText(eventDB, special.courses))); } return(list.ToArray()); }
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 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), } ); }