/// <summary> /// User has added a series. /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event arguments</param> private void OnSeriesAdded(object sender, EventArgs e) { Series seriesToAdd; int seriesIndex = Array.IndexOf(this.seriesView.SeriesNames, this.seriesView.SelectedSeriesName); if (seriesIndex != -1) { seriesToAdd = ReflectionUtilities.Clone(this.graph.Series[seriesIndex]) as Series; } else { seriesToAdd = new Series(); seriesToAdd.XAxis = Axis.AxisType.Bottom; } List <Series> allSeries = new List <Series>(); allSeries.AddRange(graph.Series); allSeries.Add(seriesToAdd); seriesToAdd.Title = "Series" + allSeries.Count.ToString(); Commands.ChangeProperty command = new Commands.ChangeProperty(this.graph, "Series", allSeries); this.explorerPresenter.CommandHistory.Add(command); this.PopulateSeriesNames(); this.seriesView.SelectedSeriesName = seriesToAdd.Title; }
private Graph ConfigureGraph(Graph graph, string simulationName) { graph = (Graph)ReflectionUtilities.Clone(graph); graph.Parent = panel; graph.ParentAllDescendants(); // Apply transformation to graph. panel.Script.TransformGraph(graph, simulationName); if (panel.LegendOutsideGraph) { graph.LegendOutsideGraph = true; } if (panel.LegendOrientation != GraphPanel.LegendOrientationType.Default) { graph.LegendOrientation = (LegendOrientation)Enum.Parse(typeof(LegendOrientation), panel.LegendOrientation.ToString()); } if (panel.LegendPosition != GraphPanel.LegendPositionType.Default) { graph.LegendPosition = (LegendPosition)Enum.Parse(typeof(LegendPosition), panel.LegendPosition.ToString()); } return(graph); }
/// <summary> /// Calculate actual decomposition /// </summary> public SurfaceOrganicMatterDecompType CalculateActualSOMDecomp() { SurfaceOrganicMatterDecompType ActualSOMDecomp = new SurfaceOrganicMatterDecompType(); ActualSOMDecomp = ReflectionUtilities.Clone(PotentialSOMDecomp) as SurfaceOrganicMatterDecompType; double InitialResidueC = 0; // Potential residue decomposition provided by surfaceorganicmatter model double FinalResidueC = 0; // How much is left after decomposition double FractionDecomposed; for (int i = 0; i < PotentialSOMDecomp.Pool.Length; i++) { InitialResidueC += PotentialSOMDecomp.Pool[i].FOM.C; } FinalResidueC = SurfaceResidue.C[0]; FractionDecomposed = 1.0 - MathUtilities.Divide(FinalResidueC, InitialResidueC, 0); if (FractionDecomposed < 1) { } for (int i = 0; i < PotentialSOMDecomp.Pool.Length; i++) { ActualSOMDecomp.Pool[i].FOM.C = PotentialSOMDecomp.Pool[i].FOM.C * FractionDecomposed; ActualSOMDecomp.Pool[i].FOM.N = PotentialSOMDecomp.Pool[i].FOM.N * FractionDecomposed; } return(ActualSOMDecomp); }
protected void OnDoPotentialPlantGrowth(object sender, EventArgs e) { if (Plant.IsEmerged) { Detached.Clear(); FRGR = FRGRFunction.Value(); Height = HeightFunction.Value(); //Initialise biomass and nitrogen Leaves.Add(new PerrenialLeafCohort()); if (Leaves.Count == 1) { AddNewLeafMaterial(StructuralWt: InitialWtFunction.Value(), StorageWt: 0, StructuralN: InitialWtFunction.Value() * MinimumNConc.Value(), StorageN: InitialWtFunction.Value() * (MaximumNConc.Value() - MinimumNConc.Value()), SLA: SpecificLeafAreaFunction.Value()); } double LDR = LeafDevelopmentRate.Value(); foreach (PerrenialLeafCohort L in Leaves) { L.Age += LDR; } StartLive = ReflectionUtilities.Clone(Live) as Biomass; StartNReallocationSupply = NSupply.Reallocation; StartNRetranslocationSupply = NSupply.Retranslocation; } }
/// <summary> /// Gets the value of the variable/expression. /// </summary> private object GetVariableValue() { object value = null; try { value = locator.Get(variableName); } catch (Exception) { // Swallow exception because reporting sum(Wheat.Root.PlantZone.WaterUptake) will // throw an exception before the crop is sown. We don't want this to stop the // simulation. Instead, simply report null. } if (value is IFunction function) { value = function.Value(); } else if (value != null && (value.GetType().IsArray || value.GetType().IsClass)) { try { value = ReflectionUtilities.Clone(value); } catch (Exception err) { throw new Exception($"Cannot report variable \"{variableName}\": Variable is a non-reportable type: \"{value?.GetType()?.Name}\".", err); } } return(value); }
/// <summary>Stores a value into the values array.</summary> public void StoreValue() { object value = locator.Get(variableName); if (value == null) { throw new Exception($"Unable to locate report variable: {variableName}"); } if (value is IFunction function) { value = function.Value(); } else if (value != null && (value.GetType().IsArray || value.GetType().IsClass)) { try { value = ReflectionUtilities.Clone(value); } catch (Exception err) { throw new Exception($"Cannot report variable \"{variableName}\": Variable is a non-reportable type: \"{value?.GetType()?.Name}\".", err); } } valuesToAggregate.Add(value); }
/// <summary> /// Retrieve the current value and store it in our array of values. /// </summary> public virtual void StoreValue() { object value = Apsim.Get(this.parentModel.Parent, this.variableName, true); if (value == null) { Values.Add(null); } else { if (value != null && value is IFunction) { value = (value as IFunction).Value(); } else if (value.GetType().IsArray || value.GetType().IsClass) { try { value = ReflectionUtilities.Clone(value); } catch (Exception) { throw new ApsimXException(this.parentModel, "Cannot report variable " + this.variableName + ". Variable is not of a reportable type. Perhaps " + " it is a PMF Function that needs a .Value appended to the name."); } } Values.Add(value); } }
/// <summary>Retrieve the current value and store it in our array of values.</summary> public virtual object GetValue() { object value = null; // If we're at the end of the capture window, apply the aggregation. if (this.aggregationFunction != null) { if (!this.inCaptureWindow) { value = ApplyAggregation(); } } else { value = locator.Get(variableName); if (value == null) { Values.Add(null); } else { if (value != null && value is IFunction) { value = (value as IFunction).Value(); } else if (value.GetType().IsArray || value.GetType().IsClass) { try { value = ReflectionUtilities.Clone(value); } catch (Exception) { throw new Exception("Cannot report variable " + this.variableName + ". Variable is not of a reportable type. Perhaps " + " it is a PMF Function that needs a .Value appended to the name."); } } if (!haveGotUnits) { IVariable var = locator.GetObject(variableName); if (var != null) { Units = var.UnitsLabel; if (Units != null && Units.StartsWith("(") && Units.EndsWith(")")) { Units = Units.Substring(1, Units.Length - 2); } } haveGotUnits = true; } Values.Add(value); } } return(value); }
protected virtual void OnDoPotentialPlantGrowth(object sender, EventArgs e) { // save current state if (parentPlant.IsEmerged) { StartLive = ReflectionUtilities.Clone(Live) as Biomass; } }
/// <summary>Looks at a residue type and copies properties from the base type if one was specified.</summary> /// <param name="residueType">The residue to examine and change</param> private ResidueType FillDerived(ResidueType residueType) { ResidueType baseType = null; if (residueType.derived_from != null) { baseType = ResidueType.Find(type => StringUtilities.StringsAreEqual(type.fom_type, residueType.derived_from)); if (baseType != null) { baseType = FillDerived(baseType); // Make sure the base residue type has itself been filled } } if (baseType != null) { residueType = (ResidueType)ReflectionUtilities.Clone(residueType); if (residueType.fraction_C == 0) { residueType.fraction_C = baseType.fraction_C; } if (residueType.po4ppm == 0) { residueType.po4ppm = baseType.po4ppm; } if (residueType.nh4ppm == 0) { residueType.nh4ppm = baseType.nh4ppm; } if (residueType.no3ppm == 0) { residueType.no3ppm = baseType.no3ppm; } if (residueType.specific_area == 0) { residueType.specific_area = baseType.specific_area; } if (residueType.pot_decomp_rate == 0) { residueType.pot_decomp_rate = baseType.pot_decomp_rate; } if (residueType.cf_contrib == 0) { residueType.cf_contrib = baseType.cf_contrib; } if (residueType.fr_c == null) { residueType.fr_c = (double[])baseType.fr_c.Clone(); } if (residueType.fr_n == null) { residueType.fr_n = (double[])baseType.fr_n.Clone(); } if (residueType.fr_p == null) { residueType.fr_p = (double[])baseType.fr_p.Clone(); } } return(residueType); }
/// <summary> /// Clones an array. Never returns null. /// </summary> /// <param name="array"></param> private Array Clone(Array array, Type elementType) { if (array == null) { return(Array.CreateInstance(elementType, 0)); } return(ReflectionUtilities.Clone(array) as Array); }
/// <summary> /// Set solute to initialisation state /// </summary> public void Reset() { double[] initialkgha = soil.Initial.FindByPath(Name)?.Value as double[]; if (initialkgha == null) { kgha = new double[soil.Thickness.Length]; // Urea will fall to here. } else { kgha = ReflectionUtilities.Clone(initialkgha) as double[]; } }
/// <summary> /// Set solute to initialisation state /// </summary> public void Reset() { double[] initialkgha = initial.GetType().GetProperty(Name)?.GetValue(initial) as double[]; if (initialkgha == null) { kgha = new double[soilPhysical.Thickness.Length]; // Urea will fall to here. } else { kgha = ReflectionUtilities.Clone(initialkgha) as double[]; } }
/// <summary> /// Set solute to initialisation state /// </summary> public void Reset() { double[] initialkgha = soil.Initial.FindByPath(Name + "N")?.Value as double[]; if (initialkgha == null) { SetKgHa(SoluteSetterType.Other, new double[soil.Thickness.Length]); // Urea will fall to here. } else { SetKgHa(SoluteSetterType.Other, ReflectionUtilities.Clone(initialkgha) as double[]); } }
/// <summary> /// Set solute to initialisation state /// </summary> public void Reset() { double[] initialkgha = Apsim.Get(soil.Initial, Name + "N") as double[]; if (initialkgha == null) { kgha = new double[soil.Thickness.Length]; // Urea will fall to here. } else { kgha = ReflectionUtilities.Clone(initialkgha) as double[]; } }
private void CreatePageOfGraphs(string sim, Graph[] graphs) { IStorageReader storage = GetStorage(); GraphTab tab = new GraphTab(sim, this.presenter); for (int i = 0; i < graphs.Length; i++) { Graph graph = ReflectionUtilities.Clone(graphs[i]) as Graph; graph.Parent = panel; graph.ParentAllDescendants(); if (panel.LegendOutsideGraph) graph.LegendOutsideGraph = true; if (panel.LegendOrientation != GraphPanel.LegendOrientationType.Default) graph.LegendOrientation = (Graph.LegendOrientationType)Enum.Parse(typeof(Graph.LegendOrientationType), panel.LegendOrientation.ToString()); if (graph != null && graph.Enabled) { // Apply transformation to graph. panel.Script.TransformGraph(graph, sim); if (panel.LegendPosition != GraphPanel.LegendPositionType.Default) graph.LegendPosition = (Graph.LegendPositionType)Enum.Parse(typeof(Graph.LegendPositionType), panel.LegendPosition.ToString()); // Create and fill cache entry if it doesn't exist. if (!panel.Cache.ContainsKey(sim) || panel.Cache[sim].Count <= i) { try { int x = storage.GetSimulationID(sim); } catch (KeyNotFoundException) { throw new Exception($"Illegal simulation name: '{sim}'. Try running the simulation, and if that doesn't fix it, there is a problem with your config script."); } List<SeriesDefinition> definitions = graph.GetDefinitionsToGraph(storage, new List<string>() { sim }).ToList(); if (!panel.Cache.ContainsKey(sim)) panel.Cache.Add(sim, new Dictionary<int, List<SeriesDefinition>>()); panel.Cache[sim][i] = definitions; } tab.AddGraph(graph, panel.Cache[sim][i]); } if (processingThread.CancellationPending) return; } this.graphs.Add(tab); view.AddTab(tab, panel.NumCols); }
/// <summary>Retrieve the current value and store it in our array of values.</summary> public virtual object GetValue() { object value = null; // If we're at the end of the capture window, apply the aggregation. if (this.aggregationFunction != null) { //if (!this.inCaptureWindow) value = ApplyAggregation(); if (toHasNoYear && this.clock.Today.Day == this.toDate.Day && this.clock.Today.Month == this.toDate.Month) { this.valuesToAggregate.Clear(); } } else { value = locator.Get(variableName); if (value == null) { Values.Add(null); } else { if (value != null && value is IFunction) { value = (value as IFunction).Value(); } else if (value.GetType().IsArray || value.GetType().IsClass) { try { value = ReflectionUtilities.Clone(value); } catch (Exception) { throw new Exception("Cannot report variable " + this.variableName + ". Variable is not of a reportable type. Perhaps " + " it is a PMF Function that needs a .Value appended to the name."); } } Values.Add(value); } } return(value); }
/// <summary> /// Retrieve the current value and store it in our array of values. /// </summary> private void StoreValue() { object value = Apsim.Get(this.parentModel.Parent, this.variableName); if (value == null) { this.values.Add(null); } else { if (value.GetType().IsArray || value.GetType().IsClass) { value = ReflectionUtilities.Clone(value); } this.values.Add(value); } }
protected void OnDoPotentialPlantGrowth(object sender, EventArgs e) { if (Plant.IsEmerged) { Detached.Clear(); FRGR = FRGRFunction.Value(); Height = HeightFunction.Value(); //Initialise biomass and nitrogen cohort.AddLeaf(InitialWtFunction.Value(), MinimumNConc.Value(), MaximumNConc.Value(), SpecificLeafAreaFunction.Value()); double developmentRate = LeafDevelopmentRate.Value(); cohort.IncreaseAge(developmentRate); StartLive = ReflectionUtilities.Clone(Live) as Biomass; StartNReallocationSupply = NSupply.Reallocation; StartNRetranslocationSupply = NSupply.Retranslocation; } }
private void OnDoPotentialPlantGrowth(object sender, EventArgs e) { // save current state if (plant.IsEmerged) { startLive = ReflectionUtilities.Clone(Live) as Biomass; } if (leafInitialised) { FRGR = frgr.Value(); if (cover == null && extinctionCoefficient == null) { throw new Exception("\"CoverFunction\" or \"ExtinctionCoefficientFunction\" should be defined in " + this.Name); } if (cover != null) { LAI = (Math.Log(1 - CoverGreen) / (extinctionCoefficient.Value() * -1)); } if (area != null) { LAI = area.Value(); } Height = tallness.Value(); if (baseHeight == null) { BaseHeight = 0; } else { BaseHeight = baseHeight.Value(); } if (wideness == null) { Width = 0; } else { Width = wideness.Value(); } LAIDead = laiDead.Value(); } }
/// <summary> /// Retrieve the current value and store it in our aggregation array of values. /// </summary> private void StoreValueForAggregation() { if (this.clock.Today != this.lastStoreDate) { object value = locator.Get(variableName); if (value == null) { this.valuesToAggregate.Add(null); } else { if (value.GetType().IsArray || value.GetType().IsClass) { value = ReflectionUtilities.Clone(value); } this.valuesToAggregate.Add(value); } this.lastStoreDate = this.clock.Today; } }
/// <summary> /// Gets the value of the variable/expression. /// </summary> private object GetVariableValue() { object value = locator.Get(variableName); if (value is IFunction function) { value = function.Value(); } else if (value != null && (value.GetType().IsArray || value.GetType().IsClass)) { try { value = ReflectionUtilities.Clone(value); } catch (Exception err) { throw new Exception($"Cannot report variable \"{variableName}\": Variable is a non-reportable type: \"{value?.GetType()?.Name}\".", err); } } return(value); }
/// <summary> /// Copy a AnimalOutput object /// </summary> /// <returns>The clone of an animal output</returns> public AnimalOutput Copy() { return(ReflectionUtilities.Clone(this) as AnimalOutput); }