Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Legumosity and IsC4 properties to ICrop and rename ICrop to IPlant #2542

Merged
merged 3 commits into from
Apr 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions ApsimNG/Presenters/PropertyPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void UpdateModel(Model model)

if (this.properties[i].DisplayType == DisplayAttribute.DisplayTypeEnum.CultivarName)
{
ICrop crop = this.GetCrop(this.properties);
IPlant crop = this.GetCrop(this.properties);
if (crop != null)
{
cell.DropDownStrings = this.GetCultivarNames(crop);
Expand Down Expand Up @@ -302,7 +302,7 @@ private void FormatGrid()
else if (this.properties[i].DisplayType == DisplayAttribute.DisplayTypeEnum.CultivarName)
{
cell.EditorType = EditorTypeEnum.DropDown;
ICrop crop = this.GetCrop(this.properties);
IPlant crop = this.GetCrop(this.properties);
if (crop != null)
{
cell.DropDownStrings = this.GetCultivarNames(crop);
Expand Down Expand Up @@ -337,20 +337,20 @@ private void FormatGrid()
cell.EditorType = EditorTypeEnum.DropDown;
cell.DropDownStrings = StringUtilities.EnumToStrings(cellValue);
}
else if (cellValue.GetType() == typeof(ICrop))
else if (cellValue.GetType() == typeof(IPlant))
{
cell.EditorType = EditorTypeEnum.DropDown;
List<string> cropNames = new List<string>();
foreach (Model crop in Apsim.FindAll(this.model, typeof(ICrop)))
foreach (Model crop in Apsim.FindAll(this.model, typeof(IPlant)))
{
cropNames.Add(crop.Name);
}

cell.DropDownStrings = cropNames.ToArray();
}
else if (this.properties[i].DataType == typeof(ICrop))
else if (this.properties[i].DataType == typeof(IPlant))
{
List<string> plantNames = Apsim.FindAll(this.model, typeof(ICrop)).Select(m => m.Name).ToList();
List<string> plantNames = Apsim.FindAll(this.model, typeof(IPlant)).Select(m => m.Name).ToList();
cell.EditorType = EditorTypeEnum.DropDown;
cell.DropDownStrings = plantNames.ToArray();
}
Expand All @@ -372,15 +372,15 @@ private void FormatGrid()
/// <summary>Get a list of cultivars for crop.</summary>
/// <param name="crop">The crop.</param>
/// <returns>A list of cultivars.</returns>
private string[] GetCultivarNames(ICrop crop)
private string[] GetCultivarNames(IPlant crop)
{
if (crop.CultivarNames.Length == 0)
{
Simulations simulations = Apsim.Parent(crop as IModel, typeof(Simulations)) as Simulations;
Replacements replacements = Apsim.Child(simulations, typeof(Replacements)) as Replacements;
if (replacements != null)
{
ICrop replacementCrop = Apsim.Child(replacements, (crop as IModel).Name) as ICrop;
IPlant replacementCrop = Apsim.Child(replacements, (crop as IModel).Name) as IPlant;
if (replacementCrop != null)
{
return replacementCrop.CultivarNames;
Expand Down Expand Up @@ -428,13 +428,13 @@ private string[] GetFieldNames()
/// </summary>
/// <param name="properties">The list of properties to look through.</param>
/// <returns>The found crop or null if none found.</returns>
private ICrop GetCrop(List<VariableProperty> properties)
private IPlant GetCrop(List<VariableProperty> properties)
{
foreach (VariableProperty property in properties)
{
if (property.DataType == typeof(ICrop))
if (property.DataType == typeof(IPlant))
{
ICrop plant = property.Value as ICrop;
IPlant plant = property.Value as IPlant;
if (plant != null)
{
return plant;
Expand All @@ -443,7 +443,7 @@ private ICrop GetCrop(List<VariableProperty> properties)
}

// Not found so look for one in scope.
return Apsim.Find(this.model, typeof(ICrop)) as ICrop;
return Apsim.Find(this.model, typeof(IPlant)) as IPlant;
}

/// <summary>
Expand Down Expand Up @@ -501,9 +501,9 @@ private void SetPropertyValue(VariableProperty property, object value)
throw new ApsimXException(this.model, "Invalid property type: " + property.DataType.ToString());
}
}
else if (typeof(ICrop).IsAssignableFrom(property.DataType))
else if (typeof(IPlant).IsAssignableFrom(property.DataType))
{
value = Apsim.Find(this.model, value.ToString()) as ICrop;
value = Apsim.Find(this.model, value.ToString()) as IPlant;
}
else if (property.DataType == typeof(DateTime))
{
Expand Down
8 changes: 4 additions & 4 deletions ApsimNG/Resources/Toolboxes/ManagementToolbox.apsimx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Models
Accumulator accumulatedRain;

[Description("Crop")]
public ICrop Crop { get; set; }
public IPlant Crop { get; set; }
[Description("Sowing date (d-mmm)")]
public string SowDate { get; set; }
[Display(DisplayType = DisplayAttribute.DisplayTypeEnum.CultivarName)]
Expand Down Expand Up @@ -98,7 +98,7 @@ namespace Models
Accumulator accumulatedRain;

[Description("Crop")]
public ICrop Crop { get; set; }
public IPlant Crop { get; set; }
[Description("Start of sowing window (d-mmm)")]
public string StartDate { get; set; }
[Description("End of sowing window (d-mmm)")]
Expand Down Expand Up @@ -166,7 +166,7 @@ namespace Models
public class Script : Model
{
[Description("Crop")]
public ICrop Crop { get; set; }
public IPlant Crop { get; set; }

[EventSubscribe("DoManagement")]
private void OnDoManagement(object sender, EventArgs e)
Expand Down Expand Up @@ -242,7 +242,7 @@ namespace Models
[Link] Fertiliser Fertiliser;

[Description("Crop to be fertilised")]
public ICrop Crop { get; set; }
public IPlant Crop { get; set; }

[Description("Amount of fertiliser to be applied (kg/ha)")]
public double Amount { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion ApsimNG/Views/ActivityLedgerGridView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ public bool ReadOnly
private string AsString(object obj)
{
string result;
if (obj is ICrop)
if (obj is IPlant)
result = (obj as IModel).Name;
else
result = obj.ToString();
Expand Down
2 changes: 1 addition & 1 deletion ApsimNG/Views/GridView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ public IGridCell GetCell(int columnIndex, int rowIndex)
private string AsString(object obj)
{
string result;
if (obj is ICrop)
if (obj is IPlant)
result = (obj as IModel).Name;
else
result = obj.ToString();
Expand Down
24 changes: 20 additions & 4 deletions Models/AgPasture/AgPasture.PastureSpecies.Organs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ namespace Models.AgPasture
{
/// <summary>Describes a generic above ground organ of a pasture species.</summary>
[Serializable]
public class PastureAboveGroundOrgan : AboveGround
public class PastureAboveGroundOrgan : IRemovableBiomass
{
/// <summary>Parent plant for this organ</summary>
private PastureSpecies parentPlant;

/// <summary>Constructor, initialise tissues.</summary>
/// <param name="parentPlant">Parent plant for the organ</param>
/// <param name="numTissues">The number of tissues in the organ</param>
public PastureAboveGroundOrgan(int numTissues)
public PastureAboveGroundOrgan(PastureSpecies parentPlant, int numTissues)
{
this.parentPlant = parentPlant;
// Typically four tissues above ground, three live and one dead
TissueCount = numTissues;
Tissue = new GenericTissue[TissueCount];
Expand All @@ -36,7 +41,7 @@ public PastureAboveGroundOrgan(int numTissues)
internal GenericTissue[] Tissue { get; set; }

/// <summary>Return live biomass. Used by STOCK</summary>
Biomass Live
public Biomass Live
{
get
{
Expand All @@ -49,7 +54,7 @@ Biomass Live
}

/// <summary>Return dead biomass. Used by STOCK</summary>
Biomass Dead
public Biomass Dead
{
get
{
Expand All @@ -61,7 +66,18 @@ Biomass Dead
}
}

/// <summary>Gets a value indicating whether the biomass is above ground or not</summary>
public bool IsAboveGround { get { return true; } }

/// <summary>
/// Biomass removal logic for this organ.
/// </summary>
/// <param name="biomassRemoveType">Name of event that triggered this biomass remove call.</param>
/// <param name="biomassToRemove">Biomass to remove</param>
public void RemoveBiomass(string biomassRemoveType, OrganBiomassRemovalType biomassToRemove)
{
throw new NotImplementedException();
}

#region Organ specific characteristics ----------------------------------------------------------------------------

Expand Down
23 changes: 19 additions & 4 deletions Models/AgPasture/AgPasture.PastureSpecies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Models.AgPasture
[PresenterName("UserInterface.Presenters.PropertyPresenter")]
[ValidParent(ParentType = typeof(Zone))]
[ValidParent(ParentType = typeof(Sward))]
public class PastureSpecies : Model, ICrop, ICanopy, IUptake
public class PastureSpecies : Model, IPlant, ICanopy, IUptake
{
#region Links, events and delegates -------------------------------------------------------------------------------

Expand Down Expand Up @@ -211,6 +211,21 @@ public CanopyEnergyBalanceInterceptionlayerType[] LightProfile

#region ICrop implementation --------------------------------------------------------------------------------------

/// <summary>Gets a value indicating how leguminous a plant is</summary>
public double Legumosity
{
get
{
if (SpeciesFamily == PastureSpecies.PlantFamilyType.Legume)
return 1;
else
return 0;
}
}

/// <summary>Gets a value indicating whether the biomass is from a c4 plant or not</summary>
public bool IsC4 { get { return PhotosyntheticPathway == PastureSpecies.PhotosynthesisPathwayType.C4; } }

/// <summary>Gets a list of cultivar names (not used by AgPasture).</summary>
public string[] CultivarNames
{
Expand Down Expand Up @@ -3608,9 +3623,9 @@ private void OnSimulationCommencing(object sender, EventArgs e)
nLayers = mySoil.Thickness.Length;

// set up the organs (use 4 or 2 tissues, the last is dead)
leaves = new PastureAboveGroundOrgan(4);
stems = new PastureAboveGroundOrgan(4);
stolons = new PastureAboveGroundOrgan(4);
leaves = new PastureAboveGroundOrgan(this, 4);
stems = new PastureAboveGroundOrgan(this, 4);
stolons = new PastureAboveGroundOrgan(this, 4);
rootZones = new List<PastureBelowGroundOrgan>();
plantZoneRoots = new PastureBelowGroundOrgan(2, nLayers,
myWaterAvailableMethod, myNitrogenAvailableMethod,
Expand Down
2 changes: 1 addition & 1 deletion Models/AgPasture/AgPasture.Sward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Models.AgPasture
[ViewName("UserInterface.Views.GridView")]
[PresenterName("UserInterface.Presenters.PropertyPresenter")]
[ValidParent(ParentType = typeof(Zone))]
public class Sward : Model, ICrop
public class Sward : Model
{
#region Links, events and delegates -------------------------------------------------------------------------------

Expand Down
16 changes: 15 additions & 1 deletion Models/Core/ApsimFile/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Models.Core.ApsimFile
public class Converter
{
/// <summary>Gets the lastest .apsimx file format version.</summary>
public static int LastestVersion { get { return 27; } }
public static int LastestVersion { get { return 28; } }

/// <summary>Converts to file to the latest version.</summary>
/// <param name="fileName">Name of the file.</param>
Expand Down Expand Up @@ -821,5 +821,19 @@ private static void UpgradeToVersion27(XmlNode node, string fileName)
}
}
}

/// <summary>
/// Upgrades to version 28. Change ICrop to IPlant
/// </summary>
/// <param name="node">The node to upgrade.</param>
/// <param name="fileName">The name of the .apsimx file</param>
private static void UpgradeToVersion28(XmlNode node, string fileName)
{
foreach (XmlNode manager in XmlUtilities.FindAllRecursivelyByType(node, "manager"))
{
ConverterUtilities.SearchReplaceManagerCode(manager, " ICrop", " IPlant");
ConverterUtilities.SearchReplaceManagerCode(manager, "(ICrop)", "(IPlant)");
}
}
}
}
8 changes: 7 additions & 1 deletion Models/Core/ICrop.cs → Models/Core/IPlant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ namespace Models.Core
/// crops must have. In effect this interface describes the interactions
/// between a crop and the other models in APSIM.
/// </summary>
public interface ICrop
public interface IPlant
{
/// <summary>Gets a value indicating how leguminous a plant is</summary>
double Legumosity { get; }

/// <summary>Gets a value indicating whether the biomass is from a c4 plant or not</summary>
bool IsC4 { get; }

/// <summary> Is the plant alive?</summary>
bool IsAlive { get; }

Expand Down
4 changes: 2 additions & 2 deletions Models/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private void SetParametersInObject(Model script, XmlElement xmlElement)
if (property != null)
{
object value;
if (property.PropertyType.Name == "ICrop")
if (property.PropertyType.Name == "IPlant")
value = Apsim.Find(this, element.InnerText);
else
value = ReflectionUtilities.StringToObject(property.PropertyType, element.InnerText);
Expand All @@ -329,7 +329,7 @@ private XmlElement GetParametersInObject(Model script)
object value = property.GetValue(script, null);
if (value == null)
value = "";
else if (value is ICrop)
else if (value is IPlant)
value = (value as IModel).Name;
XmlUtilities.SetValue(doc.DocumentElement, property.Name,
ReflectionUtilities.ObjectToString(value));
Expand Down
3 changes: 2 additions & 1 deletion Models/Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
<Compile Include="Plant\Functions\AccumulateByNumericPhase.cs" />
<Compile Include="Plant\Functions\TrackerFunction.cs" />
<Compile Include="Plant\Functions\ArrayFunction.cs" />
<Compile Include="Plant\Interfaces\IRemovableBiomass.cs" />
<Compile Include="Plant\Phenology\BBCH.cs" />
<Compile Include="Storage\DataStore.cs" />
<Compile Include="Graph\GraphPage.cs" />
Expand Down Expand Up @@ -483,7 +484,7 @@
<Compile Include="Graph\Axis.cs" />
<Compile Include="Graph\Series.cs" />
<Compile Include="Clock.cs" />
<Compile Include="Core\ICrop.cs" />
<Compile Include="Core\IPlant.cs" />
<Compile Include="Graph\Graph.cs" />
<Compile Include="Utilities\Accumulator.cs" />
<Compile Include="WaterModel\CNReductionForCover.cs" />
Expand Down
26 changes: 1 addition & 25 deletions Models/Plant/Interfaces/IOrgan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,18 @@
// Copyright (c) APSIM Initiative
// </copyright>
//-----------------------------------------------------------------------
using System.Collections.Generic;

namespace Models.PMF.Interfaces
{
/// <summary>
/// Base organ model
/// Organ interface
/// </summary>
public interface IOrgan
{
/// <summary>
/// The Name of the organ.
/// </summary>
string Name { get; set; }

/// <summary>
/// Biomass removal logic for this organ.
/// </summary>
/// <param name="biomassRemoveType">Name of event that triggered this biomass remove call.</param>
/// <param name="biomassToRemove">Biomass to remove</param>
void DoRemoveBiomass(string biomassRemoveType, OrganBiomassRemovalType biomassToRemove);


}

/// <summary>An above ground interface</summary>
public interface AboveGround { }

/// <summary>A below ground interface</summary>
public interface BelowGround { }

/// <summary>Indicates the organ is a reproductive one.</summary>
public interface Reproductive { }

/// <summary>Indicates the organ transpires</summary>
public interface Transpiring { }

}


Expand Down
Loading