public void OnUndoClick(object sender, EventArgs e) { try { this.explorerPresenter.CommandHistory.Undo(); explorerPresenter.Refresh(); } catch (Exception err) { explorerPresenter.MainPresenter.ShowError(err); } }
public void ShowModelStructure(object sender, EventArgs e) { IModel model = Apsim.Get(explorerPresenter.ApsimXFile, explorerPresenter.CurrentNodePath) as IModel; if (model != null) { foreach (IModel child in Apsim.ChildrenRecursively(model)) { child.IsHidden = !child.IsHidden; } explorerPresenter.PopulateContextMenu(explorerPresenter.CurrentNodePath); explorerPresenter.Refresh(); } }
public void Enabled(object sender, EventArgs e) { IModel model = Apsim.Get(explorerPresenter.ApsimXFile, explorerPresenter.CurrentNodePath) as IModel; if (model != null) { model.Enabled = !model.Enabled; foreach (IModel child in Apsim.ChildrenRecursively(model)) { child.Enabled = model.Enabled; } explorerPresenter.PopulateContextMenu(explorerPresenter.CurrentNodePath); explorerPresenter.Refresh(); } }
public void OnPasteClick(object sender, EventArgs e) { try { string internalCBText = this.explorerPresenter.GetClipboardText("_APSIM_MODEL"); string externalCBText = this.explorerPresenter.GetClipboardText("CLIPBOARD"); string text = string.IsNullOrEmpty(externalCBText) ? internalCBText : externalCBText; IModel currentNode = explorerPresenter.ApsimXFile.FindByPath(explorerPresenter.CurrentNodePath)?.Value as IModel; ICommand command = new AddModelCommand(currentNode, text); explorerPresenter.CommandHistory.Add(command, true); explorerPresenter.Refresh(); } catch (Exception err) { explorerPresenter.MainPresenter.ShowError(err); } }
public void IncludeInDocumentation(object sender, EventArgs e) { try { IModel model = Apsim.Get(explorerPresenter.ApsimXFile, explorerPresenter.CurrentNodePath) as IModel; model.IncludeInDocumentation = !model.IncludeInDocumentation; // toggle switch foreach (IModel child in Apsim.ChildrenRecursively(model)) { child.IncludeInDocumentation = model.IncludeInDocumentation; } explorerPresenter.PopulateContextMenu(explorerPresenter.CurrentNodePath); explorerPresenter.Refresh(); } catch (Exception err) { explorerPresenter.MainPresenter.ShowError(err); } }
public void ShowModelStructure(object sender, EventArgs e) { try { IModel model = explorerPresenter.ApsimXFile.FindByPath(explorerPresenter.CurrentNodePath)?.Value as IModel; if (model != null) { foreach (IModel child in model.FindAllDescendants()) { child.IsHidden = !child.IsHidden; } explorerPresenter.PopulateContextMenu(explorerPresenter.CurrentNodePath); explorerPresenter.Refresh(); } } catch (Exception err) { explorerPresenter.MainPresenter.ShowError(err); } }
/// <summary>The user has clicked the add button.</summary> /// <param name="sender">Event sender</param> /// <param name="e">Event arguments</param> private void OnAddButtonClicked(object sender, EventArgs e) { try { Apsim.ModelDescription selectedModelType = GetModelDescription(tree.SelectedNode); if (selectedModelType != null) { this.explorerPresenter.MainPresenter.ShowWaitCursor(true); IModel child; if (!(selectedModelType.ModelType == typeof(ModelCollectionFromResource)) && selectedModelType.ResourceString != null && selectedModelType.ResourceString.Contains('.')) { List <Exception> exceptions; var contents = ReflectionUtilities.GetResourceAsString(explorerPresenter.ApsimXFile.GetType().Assembly, selectedModelType.ResourceString); child = FileFormat.ReadFromString <Model>(contents, out exceptions); if (child.Children.Count == 1) { child = child.Children[0]; } } else { child = (IModel)Activator.CreateInstance(selectedModelType.ModelType, true); child.Name = selectedModelType.ModelName; if (child is ModelCollectionFromResource resource) { resource.ResourceName = selectedModelType.ResourceString; } } var command = new AddModelCommand(this.model, child); explorerPresenter.CommandHistory.Add(command, true); explorerPresenter.Refresh(); } } finally { this.explorerPresenter.MainPresenter.ShowWaitCursor(false); } }
/// <summary>The user has clicked the revert to button.</summary> /// <param name="sender">Event sender</param> /// <param name="e">Event arguments</param> private void OnRevertToButtonClicked(object sender, EventArgs e) { string checkpointName = view.List.SelectedValue; if (explorerPresenter.MainPresenter.AskQuestion("Are you sure you want to revert to checkpoint " + checkpointName + "?") == QuestionResponseEnum.Yes) { if (checkpointName != null) { try { explorerPresenter.MainPresenter.ShowWaitCursor(true); Simulations newSimulations = explorerPresenter.ApsimXFile.RevertCheckpoint(checkpointName); explorerPresenter.ApsimXFile = newSimulations; explorerPresenter.Refresh(); explorerPresenter.MainPresenter.ShowMessage("Reverted to checkpoint: " + checkpointName, Simulation.MessageType.Information); explorerPresenter.MainPresenter.ShowWaitCursor(false); } catch (Exception err) { explorerPresenter.MainPresenter.ShowError(err); } } } }