/// <summary>Writes PDF for specified auto-doc commands.</summary> /// <param name="section">The writer to write to.</param> /// <param name="tags">The autodoc tags.</param> /// <param name="workingDirectory">The working directory.</param> private void TagsToMigraDoc(Section section, List <AutoDocumentation.ITag> tags, string workingDirectory) { foreach (AutoDocumentation.ITag tag in tags) { if (tag is AutoDocumentation.Heading) { AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading; if (heading.headingLevel > 0 && heading.headingLevel <= 6) { if (heading.headingLevel == 1) { section.AddPageBreak(); } Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel); if (heading.headingLevel == 1) { para.Format.OutlineLevel = OutlineLevel.Level1; } else if (heading.headingLevel == 2) { para.Format.OutlineLevel = OutlineLevel.Level2; } else if (heading.headingLevel == 3) { para.Format.OutlineLevel = OutlineLevel.Level3; } else if (heading.headingLevel == 4) { para.Format.OutlineLevel = OutlineLevel.Level4; } else if (heading.headingLevel == 5) { para.Format.OutlineLevel = OutlineLevel.Level5; } else if (heading.headingLevel == 6) { para.Format.OutlineLevel = OutlineLevel.Level6; } } } else if (tag is AutoDocumentation.Paragraph) { AddFormattedParagraphToSection(section, tag as AutoDocumentation.Paragraph); } else if (tag is AutoDocumentation.GraphAndTable) { CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable, workingDirectory); } else if (tag is AutoDocumentation.Table) { CreateTable(section, tag as AutoDocumentation.Table, workingDirectory); } else if (tag is Graph) { GraphPresenter graphPresenter = new GraphPresenter(); GraphView graphView = new GraphView(); graphView.BackColor = System.Drawing.Color.White; graphView.FontSize = 12; graphView.Width = 500; graphView.Height = 500; graphPresenter.Attach(tag, graphView, ExplorerPresenter); string PNGFileName = graphPresenter.ExportToPDF(workingDirectory); section.AddImage(PNGFileName); string caption = (tag as Graph).Caption; if (caption != null) { section.AddParagraph(caption); } graphPresenter.Detach(); } else if (tag is Map) { Form f = new Form(); f.Width = 700; // 1100; f.Height = 500; // 600; MapPresenter mapPresenter = new MapPresenter(); MapView mapView = new MapView(); mapView.BackColor = System.Drawing.Color.White; mapView.Parent = f; (mapView as Control).Dock = DockStyle.Fill; f.Show(); mapPresenter.Attach(tag, mapView, ExplorerPresenter); Application.DoEvents(); Thread.Sleep(2000); Application.DoEvents(); string PNGFileName = mapPresenter.ExportToPDF(workingDirectory); section.AddImage(PNGFileName); mapPresenter.Detach(); f.Close(); } else if (tag is AutoDocumentation.Image) { AutoDocumentation.Image imageTag = tag as AutoDocumentation.Image; if (imageTag.image.Width > 700) { imageTag.image = ImageUtilities.ResizeImage(imageTag.image, 700, 500); } string PNGFileName = Path.Combine(workingDirectory, imageTag.name); imageTag.image.Save(PNGFileName, System.Drawing.Imaging.ImageFormat.Png); section.AddImage(PNGFileName); } } }
/// <summary>Writes PDF for specified auto-doc commands.</summary> /// <param name="section">The writer to write to.</param> /// <param name="tags">The autodoc tags.</param> /// <param name="workingDirectory">The working directory.</param> private void TagsToMigraDoc(Section section, List <AutoDocumentation.ITag> tags, string workingDirectory) { int figureNumber = 0; foreach (AutoDocumentation.ITag tag in tags) { if (tag is AutoDocumentation.Heading) { AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading; if (heading.headingLevel > 0 && heading.headingLevel <= 6) { //if (heading.headingLevel == 1) // section.AddPageBreak(); Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel); if (heading.headingLevel == 1) { para.Format.OutlineLevel = OutlineLevel.Level1; } else if (heading.headingLevel == 2) { para.Format.OutlineLevel = OutlineLevel.Level2; } else if (heading.headingLevel == 3) { para.Format.OutlineLevel = OutlineLevel.Level3; } else if (heading.headingLevel == 4) { para.Format.OutlineLevel = OutlineLevel.Level4; } else if (heading.headingLevel == 5) { para.Format.OutlineLevel = OutlineLevel.Level5; } else if (heading.headingLevel == 6) { para.Format.OutlineLevel = OutlineLevel.Level6; } } } else if (tag is AutoDocumentation.Paragraph) { AutoDocumentation.Paragraph paragraph = tag as AutoDocumentation.Paragraph; if (paragraph.text.Contains("![Alt Text]")) { figureNumber++; } paragraph.text = paragraph.text.Replace("[FigureNumber]", figureNumber.ToString()); AddFormattedParagraphToSection(section, paragraph); } else if (tag is AutoDocumentation.GraphAndTable) { CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable, workingDirectory); } else if (tag is GraphPage) { CreateGraphPage(section, tag as GraphPage, workingDirectory); } else if (tag is AutoDocumentation.NewPage) { section.AddPageBreak(); } else if (tag is AutoDocumentation.Table) { CreateTable(section, tag as AutoDocumentation.Table, workingDirectory); } else if (tag is Graph) { GraphPresenter graphPresenter = new GraphPresenter(); ExplorerPresenter.ApsimXFile.Links.Resolve(graphPresenter); GraphView graphView = new GraphView(); graphView.BackColor = OxyPlot.OxyColors.White; graphView.FontSize = 12; graphView.Width = 500; graphView.Height = 500; graphPresenter.Attach(tag, graphView, ExplorerPresenter); string PNGFileName = graphPresenter.ExportToPDF(workingDirectory); section.AddImage(PNGFileName); string caption = (tag as Graph).Caption; if (caption != null) { section.AddParagraph(caption); } graphPresenter.Detach(); graphView.MainWidget.Destroy(); } else if (tag is Map && (tag as Map).GetCoordinates().Count > 0) { MapPresenter mapPresenter = new MapPresenter(); MapView mapView = new MapView(null); mapPresenter.Attach(tag, mapView, ExplorerPresenter); string PNGFileName = mapPresenter.ExportToPDF(workingDirectory); if (!String.IsNullOrEmpty(PNGFileName)) { section.AddImage(PNGFileName); } mapPresenter.Detach(); mapView.MainWidget.Destroy(); } else if (tag is AutoDocumentation.Image) { AutoDocumentation.Image imageTag = tag as AutoDocumentation.Image; if (imageTag.image.Width > 700) { imageTag.image = ImageUtilities.ResizeImage(imageTag.image, 700, 500); } string PNGFileName = Path.Combine(workingDirectory, imageTag.name); imageTag.image.Save(PNGFileName, System.Drawing.Imaging.ImageFormat.Png); section.AddImage(PNGFileName); figureNumber++; } } }
/// <summary>Writes PDF for specified auto-doc commands.</summary> /// <param name="section">The writer to write to.</param> /// <param name="tags">The autodoc tags.</param> /// <param name="workingDirectory">The working directory.</param> private void TagsToMigraDoc(Section section, List <AutoDocumentation.ITag> tags, string workingDirectory) { int figureNumber = 0; foreach (AutoDocumentation.ITag tag in tags) { if (tag is AutoDocumentation.Heading) { AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading; if (heading.headingLevel > 0 && heading.headingLevel <= 6) { //if (heading.headingLevel == 1) // section.AddPageBreak(); Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel); if (heading.headingLevel == 1) { para.Format.OutlineLevel = OutlineLevel.Level1; } else if (heading.headingLevel == 2) { para.Format.OutlineLevel = OutlineLevel.Level2; } else if (heading.headingLevel == 3) { para.Format.OutlineLevel = OutlineLevel.Level3; } else if (heading.headingLevel == 4) { para.Format.OutlineLevel = OutlineLevel.Level4; } else if (heading.headingLevel == 5) { para.Format.OutlineLevel = OutlineLevel.Level5; } else if (heading.headingLevel == 6) { para.Format.OutlineLevel = OutlineLevel.Level6; } } } else if (tag is AutoDocumentation.Paragraph) { AutoDocumentation.Paragraph paragraph = tag as AutoDocumentation.Paragraph; if (paragraph.text.Contains("![Alt Text]")) { figureNumber++; } paragraph.text = paragraph.text.Replace("[FigureNumber]", figureNumber.ToString()); AddFormattedParagraphToSection(section, paragraph); } else if (tag is AutoDocumentation.GraphAndTable) { CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable, workingDirectory); } else if (tag is GraphPage) { CreateGraphPage(section, tag as GraphPage, workingDirectory); } else if (tag is AutoDocumentation.NewPage) { section.AddPageBreak(); } else if (tag is AutoDocumentation.Table) { CreateTable(section, tag as AutoDocumentation.Table, workingDirectory); } else if (tag is Graph) { GraphPresenter graphPresenter = new GraphPresenter(); ExplorerPresenter.ApsimXFile.Links.Resolve(graphPresenter); GraphView graphView = new GraphView(); graphView.BackColor = OxyPlot.OxyColors.White; graphView.FontSize = 12; graphView.Width = 500; graphView.Height = 500; graphPresenter.Attach(tag, graphView, ExplorerPresenter); string PNGFileName = graphPresenter.ExportToPDF(workingDirectory); section.AddImage(PNGFileName); string caption = (tag as Graph).Caption; if (caption != null) { section.AddParagraph(caption); } graphPresenter.Detach(); graphView.MainWidget.Destroy(); } else if (tag is Map && (tag as Map).GetCoordinates().Count > 0) { MapPresenter mapPresenter = new MapPresenter(); MapView mapView = new MapView(null); mapPresenter.Attach(tag, mapView, ExplorerPresenter); string PNGFileName = mapPresenter.ExportToPDF(workingDirectory); if (!String.IsNullOrEmpty(PNGFileName)) { section.AddImage(PNGFileName); } mapPresenter.Detach(); mapView.MainWidget.Destroy(); } else if (tag is AutoDocumentation.Image) { AutoDocumentation.Image imageTag = tag as AutoDocumentation.Image; if (imageTag.image.Width > 700) { imageTag.image = ImageUtilities.ResizeImage(imageTag.image, 700, 500); } string PNGFileName = Path.Combine(workingDirectory, imageTag.name); imageTag.image.Save(PNGFileName, System.Drawing.Imaging.ImageFormat.Png); section.AddImage(PNGFileName); figureNumber++; } else if (tag is DirectedGraph) { DirectedGraphPresenter presenter = new DirectedGraphPresenter(); ExplorerPresenter.ApsimXFile.Links.Resolve(presenter); DirectedGraphView view = new DirectedGraphView(); presenter.Attach(new DirectedGraphContainer(tag as DirectedGraph), view, ExplorerPresenter); Gtk.Window popupWin = new Gtk.Window(Gtk.WindowType.Popup); popupWin.SetSizeRequest(800, 800); // Move the window offscreen; the user doesn't need to see it. // This works with IE, but not with WebKit // Not yet tested on OSX if (ProcessUtilities.CurrentOS.IsWindows) { popupWin.Move(-10000, -10000); } popupWin.Add(view.MainWidget); popupWin.ShowAll(); while (Gtk.Application.EventsPending()) { Gtk.Application.RunIteration(); } string PNGFileName = presenter.ExportToPNG(workingDirectory); section.AddImage(PNGFileName); presenter.Detach(); view.MainWidget.Destroy(); } } }
/// <summary>Writes PDF for specified auto-doc commands.</summary> /// <param name="section">The writer to write to.</param> /// <param name="tags">The autodoc tags.</param> /// <param name="workingDirectory">The working directory.</param> private void TagsToMigraDoc(Section section, List <AutoDocumentation.ITag> tags, string workingDirectory) { int figureNumber = 0; foreach (AutoDocumentation.ITag tag in tags) { if (tag is AutoDocumentation.Heading) { AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading; if (heading.headingLevel > 0 && heading.headingLevel <= 6) { //if (heading.headingLevel == 1) // section.AddPageBreak(); Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel); if (heading.headingLevel == 1) { para.Format.OutlineLevel = OutlineLevel.Level1; } else if (heading.headingLevel == 2) { para.Format.OutlineLevel = OutlineLevel.Level2; } else if (heading.headingLevel == 3) { para.Format.OutlineLevel = OutlineLevel.Level3; } else if (heading.headingLevel == 4) { para.Format.OutlineLevel = OutlineLevel.Level4; } else if (heading.headingLevel == 5) { para.Format.OutlineLevel = OutlineLevel.Level5; } else if (heading.headingLevel == 6) { para.Format.OutlineLevel = OutlineLevel.Level6; } } } else if (tag is AutoDocumentation.Paragraph) { AutoDocumentation.Paragraph paragraph = tag as AutoDocumentation.Paragraph; if (paragraph.text.Contains("![Alt Text]")) { figureNumber++; } paragraph.text = paragraph.text.Replace("[FigureNumber]", figureNumber.ToString()); AddFormattedParagraphToSection(section, paragraph); } else if (tag is AutoDocumentation.GraphAndTable) { CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable, workingDirectory); } else if (tag is GraphPage) { CreateGraphPage(section, tag as GraphPage, workingDirectory); } else if (tag is AutoDocumentation.NewPage) { section.AddPageBreak(); } else if (tag is AutoDocumentation.Table) { CreateTable(section, tag as AutoDocumentation.Table, workingDirectory); } else if (tag is Graph) { GraphPresenter graphPresenter = new GraphPresenter(); ExplorerPresenter.ApsimXFile.Links.Resolve(graphPresenter); GraphView graphView = new GraphView(); graphView.BackColor = System.Drawing.Color.White; graphView.FontSize = 12; graphView.Width = 500; graphView.Height = 500; graphPresenter.Attach(tag, graphView, ExplorerPresenter); string PNGFileName = graphPresenter.ExportToPDF(workingDirectory); section.AddImage(PNGFileName); string caption = (tag as Graph).Caption; if (caption != null) { section.AddParagraph(caption); } graphPresenter.Detach(); } else if (tag is Map) { Form f = new Form(); f.FormBorderStyle = FormBorderStyle.None; f.Width = 650; // 1100; f.Height = 600; // 600; MapPresenter mapPresenter = new MapPresenter(); MapView mapView = new MapView(); mapView.BackColor = System.Drawing.Color.White; mapView.Parent = f; (mapView as Control).Dock = DockStyle.Fill; f.Show(); (tag as Map).Zoom = 1.4; mapPresenter.Attach(tag, mapView, ExplorerPresenter); Application.DoEvents(); Thread.Sleep(2000); Application.DoEvents(); string PNGFileName = mapPresenter.ExportToPDF(workingDirectory); var Image = new Bitmap(f.Width, f.Height); f.DrawToBitmap(Image, new Rectangle(0, 0, f.Width, f.Height)); Image.Save(PNGFileName); section.AddImage(PNGFileName); mapPresenter.Detach(); f.Close(); } else if (tag is AutoDocumentation.Image) { AutoDocumentation.Image imageTag = tag as AutoDocumentation.Image; if (imageTag.image.Width > 700) { imageTag.image = ImageUtilities.ResizeImage(imageTag.image, 700, 500); } string PNGFileName = Path.Combine(workingDirectory, imageTag.name); imageTag.image.Save(PNGFileName, System.Drawing.Imaging.ImageFormat.Png); section.AddImage(PNGFileName); figureNumber++; } } }