void CheckCourse(string filename, CourseDesignator courseDesignator, string testName) { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); CourseView courseView, courseViewAllVariations; CourseLayout course; eventDB.Load(TestUtil.GetTestFile(filename)); eventDB.Validate(); // Create the course courseView = CourseView.CreateViewingCourseView(eventDB, courseDesignator); if (courseDesignator.IsVariation) { courseViewAllVariations = CourseView.CreateViewingCourseView(eventDB, courseDesignator.WithAllVariations()); } else { courseViewAllVariations = courseView; } course = new CourseLayout(); course.SetLayerColor(CourseLayer.AllVariations, 1, "Gray", 0, 0, 0, 0.4F, false); course.SetLayerColor(CourseLayer.MainCourse, 0, "Black", 0, 0, 0, 1F, false); course.SetLayerColor(CourseLayer.InvisibleObjects, 2, "DropTargets", 1F, 1F, 0, 0, false); TopologyFormatter formatter = new TopologyFormatter(); RectangleF rect = formatter.FormatCourseToLayout(symbolDB, courseViewAllVariations, courseView, course, Id <CourseControl> .None, Id <CourseControl> .None, CourseLayer.AllVariations, CourseLayer.MainCourse); // Render to a map Map map = course.RenderToMap(new CourseLayout.MapRenderOptions()); // Make drop targets visible. using (map.Write()) { foreach (SymDef symdef in map.AllSymdefs) { if (symdef.SymbolId == "781") { map.SetSymdefVisible(symdef, true); } } } // Render map to the graphics. Bitmap bm = new Bitmap((int)(1000 * rect.Width / rect.Height), 1000); using (Graphics g = Graphics.FromImage(bm)) { RenderOptions options = new RenderOptions(); options.usePatternBitmaps = true; options.minResolution = (float)(rect.Width / bm.Width); options.renderTemplates = RenderTemplateOption.MapAndTemplates; g.ScaleTransform((float)(bm.Width / rect.Width), -(float)(bm.Height / rect.Height)); g.TranslateTransform(-rect.Left, -rect.Top - rect.Height); g.Clear(Color.White); using (map.Read()) map.Draw(new GDIPlus_GraphicsTarget(g), rect, options, null); } TestUtil.CheckBitmapsBase(bm, "topologyformatter\\" + testName); }
void CheckCourse(string filename, CourseDesignator courseDesignator, string testName) { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); CourseView courseView, courseViewAllVariations; CourseLayout course; eventDB.Load(TestUtil.GetTestFile(filename)); eventDB.Validate(); // Create the course courseView = CourseView.CreateViewingCourseView(eventDB, courseDesignator); if (courseDesignator.IsVariation) courseViewAllVariations = CourseView.CreateViewingCourseView(eventDB, courseDesignator.WithAllVariations()); else courseViewAllVariations = courseView; course = new CourseLayout(); course.SetLayerColor(CourseLayer.AllVariations, 1, "Gray", 0, 0, 0, 0.4F, false); course.SetLayerColor(CourseLayer.MainCourse, 0, "Black", 0, 0, 0, 1F, false); TopologyFormatter formatter = new TopologyFormatter(); RectangleF rect = formatter.FormatCourseToLayout(symbolDB, courseViewAllVariations, courseView, course, CourseLayer.AllVariations, CourseLayer.MainCourse); // Render to a map Map map = course.RenderToMap(); // Make drop targets visible. using (map.Write()) { foreach (SymDef symdef in map.AllSymdefs) { if (symdef.SymbolId == "781") map.SetSymdefVisible(symdef, true); } } // Render map to the graphics. Bitmap bm = new Bitmap((int)(1000 * rect.Width / rect.Height), 1000); using (Graphics g = Graphics.FromImage(bm)) { RenderOptions options = new RenderOptions(); options.usePatternBitmaps = true; options.minResolution = (float)(rect.Width / bm.Width); options.renderTemplates = RenderTemplateOption.MapAndTemplates; g.ScaleTransform((float)(bm.Width / rect.Width), -(float)(bm.Height / rect.Height)); g.TranslateTransform(-rect.Left, -rect.Top - rect.Height); g.Clear(Color.White); using (map.Read()) map.Draw(new GDIPlus_GraphicsTarget(g), rect, options, null); } TestUtil.CheckBitmapsBase(bm, "topologyformatter\\" + testName); }