/// <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>Attach the model and view to this presenter.</summary> /// <param name="model">The graph model to work with</param> /// <param name="view">The series view to work with</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.series = model as Series; this.seriesView = view as SeriesView; this.explorerPresenter = explorerPresenter; intellisense = new IntellisensePresenter(seriesView as ViewBase); intellisense.ItemSelected += OnIntellisenseItemSelected; Graph parentGraph = series.FindAncestor <Graph>(); if (parentGraph != null) { try { GraphPresenter = new GraphPresenter(); explorerPresenter.ApsimXFile.Links.Resolve(GraphPresenter); GraphPresenter.Attach(parentGraph, seriesView.GraphView, explorerPresenter); } catch (Exception err) { explorerPresenter.MainPresenter.ShowError(err); } } try { PopulateView(); } catch (Exception err) { explorerPresenter.MainPresenter.ShowError(err); } ConnectViewEvents(); }
/// <summary> /// Attach the specified Model and View. /// </summary> /// <param name="model">The axis model</param> /// <param name="view">The axis view</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { IModel folder = model as IModel; List <GraphView> views = new List <GraphView>(); var storage = folder.FindInScope <IDataStore>(); var graphPage = new GraphPage(); graphPage.Graphs.AddRange(folder.FindAllChildren <Graph>().Where(g => g.Enabled)); foreach (var graphSeries in graphPage.GetAllSeriesDefinitions(folder, storage.Reader)) { GraphView graphView = new GraphView(); GraphPresenter presenter = new GraphPresenter(); explorerPresenter.ApsimXFile.Links.Resolve(presenter); presenter.Attach(graphSeries.Graph, graphView, explorerPresenter, graphSeries.SeriesDefinitions); presenters.Add(presenter); views.Add(graphView); } if (views.Count > 0) { (view as IFolderView).SetContols(views); } }
/// <summary> /// Forces the equivalent graphs in each tab to use the same axes. /// ie. The LAI graphs in each simulation will have the same axes. /// </summary> private void StandardiseAxes() { // Loop over each graph. ie if each tab contains five // graphs, then loop over these five graphs. int graphsPerPage = panel.Cache.First().Value.Count; for (int i = 0; i < graphsPerPage; i++) { // Get all graph series for this graph from each simulation. // ie. get the data behind each lai graph in each simulation. List <SeriesDefinition> series = panel.Cache.Values.SelectMany(v => v[i]).ToList(); // Now draw all these series onto a single graph. GraphPresenter graphPresenter = new GraphPresenter(); GraphView graphView = new GraphView(view as ViewBase); presenter.ApsimXFile.Links.Resolve(graphPresenter); graphPresenter.Attach(graphs[0].Graphs[i].Graph, graphView, presenter); graphPresenter.DrawGraph(series); Axis[] axes = graphView.Axes.ToArray(); // This should always be length 2 foreach (GraphTab tab in graphs) { if (tab.Graphs[i].View != null) { FormatAxes(tab.Graphs[i].View, axes); } } } }
/// <summary>Detach the model and view from this presenter.</summary> public void Detach() { seriesView.EndEdit(); intellisense.ItemSelected -= OnIntellisenseItemSelected; GraphPresenter?.Detach(); intellisense.Cleanup(); DisconnectViewEvents(); }
/// <summary> /// Attach the model to the view. /// </summary> /// <param name="model">The underlying model we are to use</param> /// <param name="view">The underlying view we are to attach to</param> /// <param name="explorerPresenter">Our parent explorerPresenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.model = model as Model; this.view = view as IProfileView; this.explorerPresenter = explorerPresenter; this.view.ShowView(false); // Setup the property presenter and view. Hide the view if there are no properties to show. this.propertyPresenter = new PropertyPresenter(); this.propertyPresenter.Attach(this.model, this.view.PropertyGrid, this.explorerPresenter); // Create a list of profile (array) properties. Create a table from them and // hand the table to the profile grid. this.FindAllProperties(this.model); // Populate the grid this.PopulateGrid(); // Populate the graph. this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph"); if (this.graph == null) { this.view.ShowGraph(false); } else { parentForGraph = this.model.Parent as IModel; if (this.parentForGraph != null) { this.parentForGraph.Children.Add(this.graph); this.graph.Parent = this.parentForGraph; this.view.ShowGraph(true); int padding = (this.view as ProfileView).MainWidget.Allocation.Width / 2 / 2; this.view.Graph.LeftRightPadding = padding; this.graphPresenter = new GraphPresenter(); this.graphPresenter.Attach(this.graph, this.view.Graph, this.explorerPresenter); } } // Trap the invoking of the ProfileGrid 'CellValueChanged' event so that // we can save the contents. this.view.ProfileGrid.CellsChanged += this.OnProfileGridCellValueChanged; // Trap the right click on column header so that we can potentially put // units on the context menu. this.view.ProfileGrid.ColumnHeaderClicked += this.OnColumnHeaderClicked; // Trap the model changed event so that we can handle undo. this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged; this.view.ProfileGrid.ResizeControls(); this.view.PropertyGrid.ResizeControls(); this.view.ShowView(true); }
/// <summary> /// Attach the specified Model and View. /// </summary> /// <param name="model">The axis model</param> /// <param name="view">The axis view</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { IModel folder = model as IModel; List<UserControl> views = new List<UserControl>(); foreach (Graph graph in Apsim.Children(folder, typeof(Graph))) { GraphView graphView = new GraphView(); GraphPresenter presenter = new GraphPresenter(); presenter.Attach(graph, graphView, explorerPresenter); views.Add(graphView); } if (views.Count > 0) (view as IFolderView).SetContols(views); }
/// <summary> /// Attach the model and view to this presenter. /// </summary> /// <param name="model">The graph model to work with</param> /// <param name="view">The series view to work with</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.series = model as Series; this.seriesView = view as SeriesView; this.explorerPresenter = explorerPresenter; Graph parentGraph = Apsim.Parent(series, typeof(Graph)) as Graph; if (parentGraph != null) { graphPresenter = new GraphPresenter(); graphPresenter.Attach(parentGraph, seriesView.GraphView, explorerPresenter); } PopulateView(); ConnectViewEvents(); }
/// <summary> /// Attach the view to the model. /// </summary> /// <param name="model">The initial water model</param> /// <param name="view">The initial water view</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.initialWater = model as InitialWater; this.initialWaterView = view as IInitialWaterView; this.explorerPresenter = explorerPresenter as ExplorerPresenter; this.initialWaterView.RelativeToCrops = this.initialWater.RelativeToCrops; this.ConnectViewEvents(); this.PopulateView(); this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged; // Populate the graph. this.graph = Utility.Graph.CreateGraphFromResource("ApsimNG.Resources.InitialWaterGraph.xml"); this.graph.Parent = this.initialWater.Parent; this.graphPresenter = new GraphPresenter(); this.graphPresenter.Attach(this.graph, this.initialWaterView.Graph, this.explorerPresenter); }
/// <summary> /// Attach the specified Model and View. /// </summary> /// <param name="model">The axis model</param> /// <param name="view">The axis view</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { IModel folder = model as IModel; List <UserControl> views = new List <UserControl>(); foreach (Graph graph in Apsim.Children(folder, typeof(Graph))) { GraphView graphView = new GraphView(); GraphPresenter presenter = new GraphPresenter(); presenter.Attach(graph, graphView, explorerPresenter); views.Add(graphView); } if (views.Count > 0) { (view as IFolderView).SetContols(views); } }
/// <summary> /// Attach the view to the model. /// </summary> /// <param name="model">The initial water model</param> /// <param name="view">The initial water view</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.initialWater = model as InitialWater; this.initialWaterView = view as IInitialWaterView; this.explorerPresenter = explorerPresenter as ExplorerPresenter; this.initialWaterView.RelativeToCrops = this.initialWater.RelativeToCrops; this.ConnectViewEvents(); this.PopulateView(); this.explorerPresenter.CommandHistory.ModelChanged += OnModelChanged; // Populate the graph. this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph"); this.initialWater.Parent.Children.Add(this.graph); this.graph.Parent = this.initialWater.Parent; this.graphPresenter = new GraphPresenter(); this.graphPresenter.Attach(this.graph, this.initialWaterView.Graph, this.explorerPresenter); }
/// <summary> /// Attach the view to the model. /// </summary> /// <param name="model">The initial water model</param> /// <param name="view">The initial water view</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.xyPairs = model as XYPairs; this.xyPairsView = view as XYPairsView; this.explorerPresenter = explorerPresenter as ExplorerPresenter; // Create a list of profile (array) properties. PpoulateView wil create a table from them and // hand the table to the variables grid. this.FindAllProperties(this.xyPairs); this.PopulateView(); this.explorerPresenter.CommandHistory.ModelChanged += OnModelChanged; // Populate the graph. this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph"); this.xyPairs.Children.Add(this.graph); this.graph.Parent = this.xyPairs; this.graphPresenter = new GraphPresenter(); this.graphPresenter.Attach(this.graph, this.xyPairsView.Graph, this.explorerPresenter); }
/// <summary>Attach the model and view to this presenter.</summary> /// <param name="model">The graph model to work with</param> /// <param name="view">The series view to work with</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.series = model as Series; this.seriesView = view as SeriesView; this.explorerPresenter = explorerPresenter; intellisense = new IntellisensePresenter(seriesView as ViewBase); intellisense.ItemSelected += OnIntellisenseItemSelected; Graph parentGraph = Apsim.Parent(series, typeof(Graph)) as Graph; if (parentGraph != null) { graphPresenter = new GraphPresenter(); explorerPresenter.ApsimXFile.Links.Resolve(graphPresenter); graphPresenter.Attach(parentGraph, seriesView.GraphView, explorerPresenter); } PopulateView(); ConnectViewEvents(); }
/// <summary> /// Attach the view to the model. /// </summary> /// <param name="model">The initial water model</param> /// <param name="view">The initial water view</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public override void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.xYPairs = model as XYPairs; this.xYPairsView = view as XYPairsView; this.presenter = explorerPresenter as ExplorerPresenter; base.Attach(model, xYPairsView.VariablesGrid, explorerPresenter); // Create a list of profile (array) properties. PpoulateView wil create a table from them and // hand the table to the variables grid. this.FindAllProperties(this.xYPairs); this.PopulateView(); this.presenter.CommandHistory.ModelChanged += OnModelChanged; // Populate the graph. this.graph = Utility.Graph.CreateGraphFromResource("ApsimNG.Resources.XYPairsGraph.xml"); this.xYPairs.Children.Add(this.graph); this.graph.Parent = this.xYPairs; (this.graph.Series[0] as Series).XFieldName = graph.Parent.FullPath + ".X"; (this.graph.Series[0] as Series).YFieldName = graph.Parent.FullPath + ".Y"; this.graphPresenter = new GraphPresenter(); this.presenter.ApsimXFile.Links.Resolve(graphPresenter); this.graphPresenter.Attach(this.graph, this.xYPairsView.Graph, this.presenter); string xAxisTitle = LookForXAxisTitle(); if (xAxisTitle != null) { xYPairsView.Graph.FormatAxis(Axis.AxisType.Bottom, xAxisTitle, false, double.NaN, double.NaN, double.NaN, false); } string yAxisTitle = LookForYAxisTitle(); if (yAxisTitle != null) { xYPairsView.Graph.FormatAxis(Axis.AxisType.Left, yAxisTitle, false, double.NaN, double.NaN, double.NaN, false); } xYPairsView.Graph.FormatTitle(xYPairs.Parent.Name); }
/// <summary> /// Attach the specified Model and View. /// </summary> /// <param name="model">The axis model</param> /// <param name="view">The axis view</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { IModel folder = model as IModel; List <GraphView> views = new List <GraphView>(); foreach (Graph graph in Apsim.Children(folder, typeof(Graph))) { if (graph.Enabled) { GraphView graphView = new GraphView(); GraphPresenter presenter = new GraphPresenter(); explorerPresenter.ApsimXFile.Links.Resolve(presenter); presenter.Attach(graph, graphView, explorerPresenter); presenters.Add(presenter); views.Add(graphView); } } if (views.Count > 0) { (view as IFolderView).SetContols(views); } }
/// <summary> /// Attach the view to the model. /// </summary> /// <param name="model">The initial water model</param> /// <param name="view">The initial water view</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.xyPairs = model as XYPairs; this.xyPairsView = view as XYPairsView; this.explorerPresenter = explorerPresenter as ExplorerPresenter; // Create a list of profile (array) properties. PpoulateView wil create a table from them and // hand the table to the variables grid. this.FindAllProperties(this.xyPairs); this.PopulateView(); this.explorerPresenter.CommandHistory.ModelChanged += OnModelChanged; // Populate the graph. this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph"); this.xyPairs.Children.Add(this.graph); this.graph.Parent = this.xyPairs; this.graphPresenter = new GraphPresenter(); this.graphPresenter.Attach(this.graph, this.xyPairsView.Graph, this.explorerPresenter); string xAxisTitle = LookForXAxisTitle(); if (xAxisTitle != null) { xyPairsView.Graph.FormatAxis(Axis.AxisType.Bottom, xAxisTitle, false, double.NaN, double.NaN, double.NaN); } string yAxisTitle = LookForYAxisTitle(); if (yAxisTitle != null) { xyPairsView.Graph.FormatAxis(Axis.AxisType.Left, yAxisTitle, false, double.NaN, double.NaN, double.NaN); } xyPairsView.Graph.FormatTitle(xyPairs.Parent.Name); }
/// <summary> /// Attach the view to the model. /// </summary> /// <param name="model">The initial water model</param> /// <param name="view">The initial water view</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.xyPairs = model as XYPairs; this.xyPairsView = view as XYPairsView; this.explorerPresenter = explorerPresenter as ExplorerPresenter; // Create a list of profile (array) properties. PpoulateView wil create a table from them and // hand the table to the variables grid. this.FindAllProperties(this.xyPairs); this.PopulateView(); this.explorerPresenter.CommandHistory.ModelChanged += OnModelChanged; // Populate the graph. this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph"); this.xyPairs.Children.Add(this.graph); this.graph.Parent = this.xyPairs; (this.graph.Series[0] as Series).XFieldName = Apsim.FullPath(graph.Parent) + ".X"; (this.graph.Series[0] as Series).YFieldName = Apsim.FullPath(graph.Parent) + ".Y"; this.graphPresenter = new GraphPresenter(); this.graphPresenter.Attach(this.graph, this.xyPairsView.Graph, this.explorerPresenter); string xAxisTitle = LookForXAxisTitle(); if (xAxisTitle != null) xyPairsView.Graph.FormatAxis(Axis.AxisType.Bottom, xAxisTitle, false, double.NaN, double.NaN, double.NaN); string yAxisTitle = LookForYAxisTitle(); if (yAxisTitle != null) xyPairsView.Graph.FormatAxis(Axis.AxisType.Left, yAxisTitle, false, double.NaN, double.NaN, double.NaN); xyPairsView.Graph.FormatTitle(xyPairs.Parent.Name); }
/// <summary>Initializes a new instance of the <see cref="LegendPresenter"/> class.</summary> /// <param name="graphPresenter">The graph presenter.</param> public LegendPresenter(GraphPresenter graphPresenter) { this.graphPresenter = graphPresenter; }
/// <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(null); 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); } } }
/// <summary> /// Attach the model to the view. /// </summary> /// <param name="model">The underlying model we are to use</param> /// <param name="view">The underlying view we are to attach to</param> /// <param name="explorerPresenter">Our parent explorerPresenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.model = model as Model; this.view = view as IProfileView; profileGrid.Attach(model, this.view.ProfileGrid, explorerPresenter); this.explorerPresenter = explorerPresenter; this.view.ShowView(false); // Setup the property presenter and view. Hide the view if there are no properties to show. this.propertyPresenter = new PropertyPresenter(); this.propertyPresenter.Attach(this.model, this.view.PropertyGrid, this.explorerPresenter); // Create a list of profile (array) properties. Create a table from them and // hand the table to the profile grid. this.FindAllProperties(this.model); // Populate the grid this.PopulateGrid(); // Populate the graph. this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph"); if (this.graph == null) { this.view.ShowGraph(false); } else { this.parentForGraph = this.model.Parent as IModel; if (this.parentForGraph != null) { this.parentForGraph.Children.Add(this.graph); this.graph.Parent = this.parentForGraph; this.view.ShowGraph(true); int padding = (this.view as ProfileView).MainWidget.Allocation.Width / 2 / 2; this.view.Graph.LeftRightPadding = padding; this.graphPresenter = new GraphPresenter(); for (int col = 0; col < this.propertiesInGrid.Count; col++) { VariableProperty property = this.propertiesInGrid[col]; string columnName = property.Description; // crop colours if (property.CropName != null && columnName.Contains("LL")) { Series cropLLSeries = new Series(); cropLLSeries.Name = columnName; cropLLSeries.Colour = ColourUtilities.ChooseColour(this.graph.Children.Count); cropLLSeries.Line = LineType.Solid; cropLLSeries.Marker = MarkerType.None; cropLLSeries.Type = SeriesType.Scatter; cropLLSeries.ShowInLegend = true; cropLLSeries.XAxis = Axis.AxisType.Top; cropLLSeries.YAxis = Axis.AxisType.Left; cropLLSeries.YFieldName = "[Soil].DepthMidPoints"; cropLLSeries.XFieldName = "[" + (property.Object as Model).Name + "]." + property.Name; cropLLSeries.Parent = this.graph; this.graph.Children.Add(cropLLSeries); } } this.graphPresenter.Attach(this.graph, this.view.Graph, this.explorerPresenter); } } // Trap the invoking of the ProfileGrid 'CellValueChanged' event so that // we can save the contents. this.view.ProfileGrid.CellsChanged += this.OnProfileGridCellValueChanged; // Trap the right click on column header so that we can potentially put // units on the context menu. this.view.ProfileGrid.GridColumnClicked += this.OnGridColumnClicked; // Trap the model changed event so that we can handle undo. this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged; this.view.ShowView(true); }
/// <summary> /// Attach the model to the view. /// </summary> /// <param name="model">The underlying model we are to use</param> /// <param name="view">The underlying view we are to attach to</param> /// <param name="explorerPresenter">Our parent explorerPresenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.model = model as Model; this.view = view as IProfileView; profileGrid.Attach(model, this.view.ProfileGrid, explorerPresenter); this.explorerPresenter = explorerPresenter; this.view.ShowView(false); // Setup the property presenter and view. Hide the view if there are no properties to show. this.propertyPresenter = new PropertyPresenter(); this.propertyPresenter.Attach(this.model, this.view.PropertyGrid, this.explorerPresenter); // Create a list of profile (array) properties. Create a table from them and // hand the table to the profile grid. this.FindAllProperties(this.model); // Populate the grid this.PopulateGrid(); // Populate the graph. this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph"); if (this.graph == null) { this.view.ShowGraph(false); } else { // The graph's series contain many variables such as [Soil].LL. We now replace // these relative paths with absolute paths. foreach (Series series in Apsim.Children(graph, typeof(Series))) { series.XFieldName = series.XFieldName?.Replace("[Soil]", Apsim.FullPath(this.model.Parent)); series.X2FieldName = series.X2FieldName?.Replace("[Soil]", Apsim.FullPath(this.model.Parent)); series.YFieldName = series.YFieldName?.Replace("[Soil]", Apsim.FullPath(this.model.Parent)); series.Y2FieldName = series.Y2FieldName?.Replace("[Soil]", Apsim.FullPath(this.model.Parent)); } this.parentForGraph = this.model.Parent as IModel; if (this.parentForGraph != null) { this.parentForGraph.Children.Add(this.graph); this.graph.Parent = this.parentForGraph; this.view.ShowGraph(true); int padding = (this.view as ProfileView).MainWidget.Allocation.Width / 2 / 2; this.view.Graph.LeftRightPadding = padding; this.graphPresenter = new GraphPresenter(); for (int col = 0; col < this.propertiesInGrid.Count; col++) { string columnName = propertiesInGrid[col].ColumnName; if (columnName.Contains("\r\n")) { StringUtilities.SplitOffAfterDelimiter(ref columnName, "\r\n"); } // crop colours if (columnName.Contains("LL")) { Series cropLLSeries = new Series(); cropLLSeries.Name = columnName; cropLLSeries.Colour = ColourUtilities.ChooseColour(this.graph.Children.Count); cropLLSeries.Line = LineType.Solid; cropLLSeries.Marker = MarkerType.None; cropLLSeries.Type = SeriesType.Scatter; cropLLSeries.ShowInLegend = true; cropLLSeries.XAxis = Axis.AxisType.Top; cropLLSeries.YAxis = Axis.AxisType.Left; cropLLSeries.YFieldName = (parentForGraph is Soil ? Apsim.FullPath(parentForGraph) : "[Soil]") + ".DepthMidPoints"; cropLLSeries.XFieldName = Apsim.FullPath((propertiesInGrid[col].ObjectWithProperty as Model)) + "." + propertiesInGrid[col].PropertyName; //cropLLSeries.XFieldName = Apsim.FullPath(property.Object as Model) + "." + property.Name; cropLLSeries.Parent = this.graph; this.graph.Children.Add(cropLLSeries); } } explorerPresenter.ApsimXFile.Links.Resolve(graphPresenter); this.graphPresenter.Attach(this.graph, this.view.Graph, this.explorerPresenter); } } // Trap the invoking of the ProfileGrid 'CellValueChanged' event so that // we can save the contents. this.view.ProfileGrid.CellsHaveChanged += this.OnProfileGridCellValueChanged; // Trap the right click on column header so that we can potentially put // units on the context menu. this.view.ProfileGrid.ColumnMenuClicked += this.OnColumnMenuItemClicked; // Trap the model changed event so that we can handle undo. this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged; this.view.ShowView(true); }
/// <summary> /// Attach the model to the view. /// </summary> /// <param name="model">The underlying model we are to use</param> /// <param name="view">The underlying view we are to attach to</param> /// <param name="explorerPresenter">Our parent explorerPresenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.model = model as Model; this.view = view as IProfileView; this.explorerPresenter = explorerPresenter; // Setup the property presenter and view. Hide the view if there are no properties to show. this.propertyPresenter = new PropertyPresenter(); this.propertyPresenter.Attach(this.model, this.view.PropertyGrid, this.explorerPresenter); // Create a list of profile (array) properties. Create a table from them and // hand the table to the profile grid. this.FindAllProperties(this.model); // Populate the grid this.PopulateGrid(); // Populate the graph. this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph"); if (this.graph == null) { this.view.ShowGraph(false); } else { parentForGraph = this.model.Parent as IModel; if (this.parentForGraph != null) { this.parentForGraph.Children.Add(this.graph); this.graph.Parent = this.parentForGraph; this.view.ShowGraph(true); int padding = (this.view as ProfileView).MainWidget.Allocation.Width / 2 / 2; this.view.Graph.LeftRightPadding = padding; this.graphPresenter = new GraphPresenter(); this.graphPresenter.Attach(this.graph, this.view.Graph, this.explorerPresenter); } } // Trap the invoking of the ProfileGrid 'CellValueChanged' event so that // we can save the contents. this.view.ProfileGrid.CellsChanged += this.OnProfileGridCellValueChanged; // Trap the right click on column header so that we can potentially put // units on the context menu. this.view.ProfileGrid.ColumnHeaderClicked += this.OnColumnHeaderClicked; // Trap the model changed event so that we can handle undo. this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged; this.view.ProfileGrid.ResizeControls(); this.view.PropertyGrid.ResizeControls(); }
/// <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 < 4) { 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 (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 Graph) { GraphPresenter graphPresenter = new GraphPresenter(); GraphView graphView = new GraphView(); graphView.BackColor = System.Drawing.Color.White; 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(); } } }
/// <summary> /// Attach the model to the view. /// </summary> /// <param name="model">The underlying model we are to use</param> /// <param name="view">The underlying view we are to attach to</param> /// <param name="explorerPresenter">Our parent explorerPresenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.model = model as Model; this.view = view as IProfileView; profileGrid.Attach(model, this.view.ProfileGrid, explorerPresenter); this.explorerPresenter = explorerPresenter; this.view.ShowView(false); // Setup the property presenter and view. Hide the view if there are no properties to show. this.propertyPresenter = new PropertyPresenter(); this.propertyPresenter.Attach(this.model, this.view.PropertyGrid, this.explorerPresenter); propertyPresenter.ScalarsOnly = true; // Populate the grid this.PopulateGrid(); // Populate the graph. this.graph = Utility.Graph.CreateGraphFromResource("WaterGraph"); graph.Name = ""; if (this.graph == null) { this.view.ShowGraph(false); } else { // The graph's series contain many variables such as [Soil].LL. We now replace // these relative paths with absolute paths. foreach (Series series in graph.FindAllChildren <Series>()) { series.XFieldName = series.XFieldName?.Replace("[Soil]", this.model.Parent.FullPath); series.X2FieldName = series.X2FieldName?.Replace("[Soil]", this.model.Parent.FullPath); series.YFieldName = series.YFieldName?.Replace("[Soil]", this.model.Parent.FullPath); series.Y2FieldName = series.Y2FieldName?.Replace("[Soil]", this.model.Parent.FullPath); } this.parentForGraph = this.model.Parent as IModel; if (this.parentForGraph != null) { // Don't add the graph as a child of the soil. This causes problems // (see bug #4622), and adding the soil as a parent is sufficient. this.graph.Parent = this.parentForGraph; this.view.ShowGraph(true); int padding = (this.view as ProfileView).MainWidget.Allocation.Width / 2 / 2; this.view.Graph.LeftRightPadding = padding; this.graphPresenter = new GraphPresenter(); for (int i = 0; i < this.profileGrid.Properties.Length; i++) { string columnName = profileGrid.Properties[i].Name; if (columnName.Contains("\r\n")) { StringUtilities.SplitOffAfterDelimiter(ref columnName, "\r\n"); } // crop colours if (columnName.Contains("LL")) { if (profileGrid.Properties[i].Object is SoilCrop) { string soilCropName = (profileGrid.Properties[i].Object as SoilCrop).Name; string cropName = soilCropName.Replace("Soil", ""); columnName = cropName + " " + columnName; } Series cropLLSeries = new Series(); cropLLSeries.Name = columnName; cropLLSeries.Colour = ColourUtilities.ChooseColour(this.graph.Children.Count); cropLLSeries.Line = LineType.Solid; cropLLSeries.Marker = MarkerType.None; cropLLSeries.Type = SeriesType.Scatter; cropLLSeries.ShowInLegend = true; cropLLSeries.XAxis = Axis.AxisType.Top; cropLLSeries.YAxis = Axis.AxisType.Left; cropLLSeries.YFieldName = (parentForGraph is Soil ? parentForGraph.FullPath : "[Soil]") + ".Physical.DepthMidPoints"; cropLLSeries.XFieldName = ((profileGrid.Properties[i].Object as IModel)).FullPath + "." + profileGrid.Properties[i].Name; //cropLLSeries.XFieldName = ((property.Object as Model)).FullPath + "." + property.Name; cropLLSeries.Parent = this.graph; this.graph.Children.Add(cropLLSeries); } } this.graph.LegendPosition = Graph.LegendPositionType.RightTop; explorerPresenter.ApsimXFile.Links.Resolve(graphPresenter); this.graphPresenter.Attach(this.graph, this.view.Graph, this.explorerPresenter); graphPresenter.LegendInsideGraph = false; } } // Trap the model changed event so that we can handle undo. this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged; this.view.ShowView(true); }