/// <summary>Constructor</summary> /// <param name="job">The job to run.</param> /// <param name="name">The name of the job</param> /// <param name="presenter">The explorer presenter.</param> public RunCommand(List<JobManager.IRunnable> jobs, string name, ExplorerPresenter presenter) { this.jobs = jobs; this.jobName = name; this.explorerPresenter = presenter; jobManager = new JobManager(); }
/// <summary>Constructor</summary> /// <param name="job">The job to run.</param> /// <param name="name">The name of the job</param> /// <param name="presenter">The explorer presenter.</param> public RunCommand(JobManager.IRunnable job, string name, ExplorerPresenter presenter) { this.job = job; this.jobName = name; this.explorerPresenter = presenter; jobManager = new JobManager(); }
/// <summary> /// Constructor /// </summary> /// <param name="simulations">The top level simulations object.</param> /// <param name="simulation">The simulation object clicked on.</param> /// <param name="presenter">The explorer presenter.</param> public RunCommand(Simulations simulations, Model simulation, ExplorerPresenter presenter) { this.simulations = simulations; this.modelClicked = simulation; this.explorerPresenter = presenter; jobManager = new JobManager(); jobManager.AllJobsCompleted += OnComplete; }
/// <summary>Constructor</summary> /// <param name="job">The job to run.</param> /// <param name="name">The name of the job</param> /// <param name="presenter">The explorer presenter.</param> public RunCommand(JobManager.IRunnable job, string name, ExplorerPresenter presenter) { jobs = new List<JobManager.IRunnable>(); this.jobs.Add(job); this.jobName = name; this.explorerPresenter = presenter; jobManager = new JobManager(); }
/// <summary>Constructor</summary> /// <param name="job">The job to run.</param> /// <param name="name">The name of the job</param> /// <param name="presenter">The explorer presenter.</param> /// <param name="multiProcess">Use the multi-process runner?</param> public RunCommand(List<JobManager.IRunnable> jobs, string name, ExplorerPresenter presenter, bool multiProcess) { this.jobs = jobs; this.jobName = name; this.explorerPresenter = presenter; if (multiProcess) jobManager = new JobManagerMultiProcess(); else jobManager = new JobManager(); }
/// <summary>Add user documentation, based on the example.</summary> /// <param name="tags">The tags to add to.</param> /// <param name="modelName">Name of model to document.</param> private void AddUserDocumentation(List <AutoDocumentation.ITag> tags, string modelName) { // Look for some instructions on which models in the example file we should write. // Instructions will be in a memo in the validation .apsimx file IModel userDocumentation = Apsim.Get(ExplorerPresenter.ApsimXFile, ".Simulations.UserDocumentation") as IModel; string exampleFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..", "Examples", modelName + ".apsimx"); if (userDocumentation != null && userDocumentation.Children.Count > 0 && File.Exists(exampleFileName)) { // Write heading. tags.Add(new AutoDocumentation.Heading("User documentation", 1)); // Open the related example .apsimx file and get its presenter. ExplorerPresenter examplePresenter = ExplorerPresenter.MainPresenter.OpenApsimXFileInTab(exampleFileName, onLeftTabControl: true); Memo instructionsMemo = userDocumentation.Children[0] as Memo; string[] instructions = instructionsMemo.MemoText.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string instruction in instructions) { IModel model = Apsim.Find(examplePresenter.ApsimXFile, instruction); if (model != null) { examplePresenter.SelectNode(Apsim.FullPath(model)); while (Gtk.Application.EventsPending()) { Gtk.Application.RunIteration(); } if (model is Memo) { AutoDocumentation.DocumentModel(model, tags, 1, 0); } else { System.Drawing.Image image = null; if (model is Manager) { image = (examplePresenter.CurrentPresenter as ManagerPresenter).GetScreenshot(); } else { image = examplePresenter.GetScreenhotOfRightHandPanel(); } if (image != null) { string name = "Example" + instruction; tags.Add(new AutoDocumentation.Image() { name = name, image = image }); } } } } // Close the tab examplePresenter.MainPresenter.CloseTabContaining(examplePresenter.GetView().MainWidget); while (Gtk.Application.EventsPending()) { Gtk.Application.RunIteration(); } } }
/// <summary> /// Constructor /// </summary> public UpgradeForm(ExplorerPresenter explorerPresenter) { InitializeComponent(); this.explorerPresenter = explorerPresenter; }
private void Awake() { explorerPresenter = new ExplorerPresenter(this); goUpButton.onClick.AddListener(OnGoUp.Invoke); }
public void CreateGraphs() { Simulations sims = CreateTemplate(); sims.FileName = Path.ChangeExtension(Path.GetTempFileName(), ".apsimx"); DataStore storage = Apsim.Find(sims, typeof(DataStore)) as DataStore; storage.FileName = Path.ChangeExtension(sims.FileName, ".db"); // Run the file to populate the datastore. Runner runner = new Runner(sims); List <Exception> errors = runner.Run(); if (errors != null && errors.Count > 0) { throw errors[0]; } // Open the .apsimx file in the GUI. sims.Write(sims.FileName); ExplorerPresenter explorer = UITestsMain.MasterPresenter.OpenApsimXFileInTab(sims.FileName, true); GtkUtilities.WaitForGtkEvents(); // Create a graphs folder under the zone. IModel paddock = Apsim.Find(sims, typeof(Zone)); Folder graphs = new Folder(); graphs.Name = "Graphs"; var command = new AddModelCommand(Apsim.FullPath(paddock), graphs, explorer); explorer.CommandHistory.Add(command, true); // Add an empty graph to the folder. Models.Graph graph = new Models.Graph(); graph.Name = "Graph"; command = new AddModelCommand(Apsim.FullPath(graphs), graph, explorer); explorer.CommandHistory.Add(command, true); // Add an empty series to the graph. Models.Series series = new Models.Series(); series.Name = "Series"; command = new AddModelCommand(Apsim.FullPath(graph), series, explorer); explorer.CommandHistory.Add(command, true); // click on the series node. explorer.SelectNode(Apsim.FullPath(series)); GtkUtilities.WaitForGtkEvents(); // Get a reference to the OxyPlot PlotView via reflection. SeriesView seriesView = explorer.CurrentRightHandView as SeriesView; GraphView view = seriesView?.GraphView as GraphView; Assert.NotNull(view); PlotView plot = ReflectionUtilities.GetValueOfFieldOrProperty("plot1", view) as PlotView; Assert.NotNull(plot); // Series has no table name or x/y series names yet, so there should // be nothing shown on the graph. Assert.AreEqual(0, plot.Model.Series.Count); // Now draw some data on the graph. seriesView.DataSource.SelectedValue = "Report"; seriesView.X.SelectedValue = "n"; seriesView.Y.SelectedValue = "n2"; seriesView.SeriesType.SelectedValue = "Scatter"; GtkUtilities.WaitForGtkEvents(); // There should now be one series showing. Assert.AreEqual(1, plot.Model.Series.Count); // It should be a line series. Assert.True(plot.Model.Series[0] is LineSeries, "Graph series type is set to scatter, but the series object is not a LineSeries."); // Series colour should not be white, and should not be the same as the background colour. LineSeries line = plot.Model.Series[0] as LineSeries; OxyPlot.OxyColor empty = OxyPlot.OxyColor.FromArgb(0, 0, 0, 0); OxyPlot.OxyColor white = OxyPlot.OxyColor.FromArgb(0, 255, 255, 255); Assert.AreNotEqual(empty, line.Color, "Graph line series default colour is white on white."); Assert.AreNotEqual(white, line.Color, "Graph line series default colour is white on white."); // Legend should be visible but empty by default. Assert.True(plot.Model.IsLegendVisible); // todo - ensure legend is empty // Next, we want to change the legend position and ensure that the legend actually moves. // Click on the 'show in legend' checkbox. seriesView.ShowInLegend.IsChecked = true; GtkUtilities.WaitForGtkEvents(); // Double click on the middle of the legend. Cairo.Rectangle legendRect = plot.Model.LegendArea.ToRect(true); double x = (legendRect.X + (legendRect.X + legendRect.Width)) / 2; double y = (legendRect.Y + (legendRect.Y + legendRect.Height)) / 2; GtkUtilities.DoubleClick(plot, x, y, wait: true); // Default legend position should be top-left. Assert.AreEqual(plot.Model.LegendPosition, OxyPlot.LegendPosition.TopLeft); // Now we want to change the legend position. First, get a reference to the legend view // via the legend presenter, via the graph presenter, via the series presenter, via the explorer presenter. Assert.True(explorer.CurrentPresenter is SeriesPresenter); SeriesPresenter seriesPresenter = explorer.CurrentPresenter as SeriesPresenter; LegendPresenter legendPresenter = seriesPresenter.GraphPresenter.CurrentPresenter as LegendPresenter; // todo: should we add something like a GetView() method to the IPresenter interface? // It might be a bit of work to set up but would save us having to use reflection LegendView legendView = ReflectionUtilities.GetValueOfFieldOrProperty("view", legendPresenter) as LegendView; // The legend options are inside a Gtk expander. Assert.IsTrue(legendView.MainWidget.Parent is Expander); Expander expander = legendView.MainWidget.Parent as Expander; // The expander should be expanded and the options visible. Assert.IsTrue(expander.Expanded); Assert.IsTrue(legendView.MainWidget.Visible); // The legend view contains a combo box with the legend position options (top-right, bottom-left, etc). // This should really be refactored to use a public IDropDownView, which is much more convenient to use. // First, get a reference to the combo box via reflection. ComboBox combo = ReflectionUtilities.GetValueOfFieldOrProperty("combobox1", legendView) as ComboBox; // fixme - we should support all valid OxyPlot legend position types. foreach (Models.Graph.LegendPositionType legendPosition in Enum.GetValues(typeof(Models.Graph.LegendPositionType))) { string name = legendPosition.ToString(); GtkUtilities.SelectComboBoxItem(combo, name, wait: true); OxyPlot.LegendPosition oxyPlotEquivalent = (OxyPlot.LegendPosition)Enum.Parse(typeof(OxyPlot.LegendPosition), name); Assert.AreEqual(plot.Model.LegendPosition, oxyPlotEquivalent); } // If we change the graph to a box plot then the several unused properties should be disabled. // These are x variable dropdown, x cumulative, x on top, marker size/type checkboxes. // First, make sure that these options are sensitive to input and can be changed. Assert.IsTrue(seriesView.X.IsSensitive); Assert.IsTrue(seriesView.XCumulative.IsSensitive); Assert.IsTrue(seriesView.XOnTop.IsSensitive); Assert.IsTrue(seriesView.MarkerSize.IsSensitive); Assert.IsTrue(seriesView.MarkerType.IsSensitive); // Now change series type to box plot. GtkUtilities.SelectComboBoxItem(seriesView.SeriesType, "Box", wait: true); Assert.AreEqual(SeriesType.Box, series.Type); // Ensure the box plot is not white in light theme. plot = ReflectionUtilities.GetValueOfFieldOrProperty("plot1", view) as PlotView; Assert.NotNull(plot); BoxPlotSeries boxPlot = plot.Model.Series.OfType <BoxPlotSeries>().FirstOrDefault(); Assert.NotNull(boxPlot); Assert.AreNotEqual(empty, boxPlot.Fill); Assert.AreNotEqual(white, boxPlot.Fill); Assert.AreNotEqual(empty, boxPlot.Stroke); Assert.AreNotEqual(white, boxPlot.Stroke); // The controls should no longer be sensitive. Assert.IsFalse(seriesView.XCumulative.IsSensitive); Assert.IsFalse(seriesView.XOnTop.IsSensitive); Assert.IsFalse(seriesView.MarkerSize.IsSensitive); Assert.IsFalse(seriesView.MarkerType.IsSensitive); // Change the series type back to scatter. GtkUtilities.SelectComboBoxItem(seriesView.SeriesType, "Scatter", wait: true); // The controls should be sensitive once more. Assert.IsTrue(seriesView.X.IsSensitive); Assert.IsTrue(seriesView.XCumulative.IsSensitive); Assert.IsTrue(seriesView.XOnTop.IsSensitive); Assert.IsTrue(seriesView.MarkerSize.IsSensitive); Assert.IsTrue(seriesView.MarkerType.IsSensitive); }
/// <summary> /// Initializes a new instance of the <see cref="ExportNodeCommand"/> class. /// </summary> /// <param name="explorerPresenter">The explorer presenter</param> /// <param name="simulation">The simulation to document</param> public WriteDebugDoc(ExplorerPresenter explorerPresenter, Simulation simulation) { this.explorerPresenter = explorerPresenter; this.simulation = simulation; }
/// <summary>Constructor.</summary> public MoveModelCommand(Model model, Model newParent, TreeViewNode treeNodeDescription, ExplorerPresenter explorerPresenter) { if (model.ReadOnly) { throw new ApsimXException(model, string.Format("Unable to move {0} to {1} - {0} is read-only.", model.Name, newParent.Name)); } if (newParent.ReadOnly) { throw new ApsimXException(newParent, string.Format("Unable to move {0} to {1} - {1} is read-only.", model.Name, newParent.Name)); } fromModel = model; toParent = newParent; nodeDescription = treeNodeDescription; presenter = explorerPresenter; }
/// <summary>Constructor.</summary> /// <param name="pathOfParent">The path of the parent model to add the child to.</param> /// <param name="childStringToAdd">The string representation of the model to add.</param> /// <param name="explorerView">The explorer view to work with.</param> /// <param name="explorerPresenter">The explorer presenter to work with.</param> public AddModelCommand(string pathOfParent, string childStringToAdd, IExplorerView explorerView, ExplorerPresenter explorerPresenter) { parentPath = pathOfParent; childString = childStringToAdd; view = explorerView; presenter = explorerPresenter; }
/// <summary>Constructor.</summary> /// <param name="pathOfParent">The path of the parent model to add the child to.</param> /// <param name="textToAdd">The text string representation of the model to add.</param> /// <param name="explorerPresenter">The explorer presenter to work with.</param> public AddModelCommand(string pathOfParent, string textToAdd, ExplorerPresenter explorerPresenter) { parentPath = pathOfParent; xmlOrJson = textToAdd; presenter = explorerPresenter; }
/// <summary>Constructor.</summary> /// <param name="pathOfParent">The path of the parent model to add the child to.</param> /// <param name="child">The model to add.</param> /// <param name="explorerView">The explorer view to work with.</param> /// <param name="explorerPresenter">The explorer presenter to work with.</param> public AddModelCommand(string pathOfParent, IModel child, ExplorerPresenter explorerPresenter) { parentPath = pathOfParent; this.child = child; presenter = explorerPresenter; }
/// <summary> /// Create documentation based on the specified file. /// </summary> /// <param name="documentObject">The documentObject node that describes what to document.</param> /// <param name="apsimDirectory">The APSIM root directory.</param> /// <param name="destinationFolder">The folder where the PDF should be created.</param> /// <param name="destinationUrl">The server destination URL where all files will end up.</param> /// <returns>HTML snippet for a single model document.</returns> private static string CreateModelDocumentation(JObject documentObject, string apsimDirectory, string destinationFolder, string destinationUrl) { string href; string hrefName = documentObject["Name"].ToString(); if (documentObject["URL"] != null) { href = documentObject["URL"].ToString(); return(string.Format("<p><a href=\"{0}\" target=\"_blank\">{1}</a></p>", href, hrefName)); } else { var fileName = Path.Combine(apsimDirectory, documentObject["FileName"].ToString()); if (File.Exists(fileName)) { // Open the file. var simulations = FileFormat.ReadFromFile <Simulations>(fileName, out List <Exception> creationExceptions); if (creationExceptions?.Count > 0) { throw creationExceptions[0]; } // Create some necessary presenters and views. var mainPresenter = new MainPresenter(); var explorerPresenter = new ExplorerPresenter(mainPresenter); var explorerView = new ExplorerView(null); explorerPresenter.Attach(simulations, explorerView, explorerPresenter); // Document model. if (documentObject["ModelNameToDocument"] == null) { Console.WriteLine("Creating documentation from " + fileName); // Whole of simulation document. var createDoc = new CreateFileDocumentationCommand(explorerPresenter, destinationFolder); createDoc.Do(null); href = Path.GetFileName(createDoc.FileNameWritten); } else { Console.WriteLine("Creating model description documentation from " + fileName); // Specific model description documentation. var modelNameToDocument = documentObject["ModelNameToDocument"].ToString(); var model = simulations.FindInScope(modelNameToDocument) as IModel; if (model == null) { return(null); } var outputFileName = documentObject["OutputFileName"]?.ToString(); var createDoc = new CreateParamsInputsOutputsDocCommand(explorerPresenter, model, destinationFolder, outputFileName); createDoc.Do(null); href = Path.GetFileName(createDoc.FileNameWritten); } return(string.Format("<p><a href=\"{0}/{1}\" target=\"_blank\">{2}</a></p>", destinationUrl, href, hrefName)); } else { return(null); } } }
public void OpenTestFileInTab() { explorerPresenter = UITestUtilities.OpenResourceFileInTab(Assembly.GetExecutingAssembly(), "UnitTests.ApsimNG.Resources.SampleFiles.BasicSimulation.apsimx"); Structure.Add(new SampleModel(), explorerPresenter.ApsimXFile); }
/// <summary> /// Initializes a new instance of the <see cref="ExportNodeCommand"/> class. /// </summary> /// <param name="explorerPresenter">The explorer presenter.</param> /// <param name="nodePath">The node path.</param> public ExportNodeCommand(ExplorerPresenter explorerPresenter, string nodePath) { this.ExplorerPresenter = explorerPresenter; }