protected override void OnLoad() { base.OnLoad(); // We need not just the XML for this profile node but the whole soil XML. OurComponent = Controller.ApsimData.Find(NodePath); ApsimFile.Component SoilComponent; if (OurComponent.Parent.Type == "factor") { XmlNode factorNode = OurComponent.Parent.ContentsAsXML; string initWaterPath = XmlHelper.Value(factorNode, "targets/target"); int posLastSlash = initWaterPath.LastIndexOf('/'); if (posLastSlash != -1) { string soilPath = initWaterPath.Remove(posLastSlash); SoilComponent = Controller.ApsimData.Find(soilPath); } else { throw new Exception("Cannot find soil node under: " + OurComponent.FullPath); } } else { SoilComponent = OurComponent.Parent; } if (SoilComponent.Type.ToLower() != "soil") { SoilComponent = SoilComponent.Parent; } if (SoilComponent.Type.ToLower() != "soil") { throw new Exception("Cannot find soil node under: " + OurComponent.FullPath); } XmlDocument soilDoc = new XmlDocument(); soilDoc.LoadXml(SoilComponent.FullXMLNoShortCuts()); if (OurComponent.Parent.Type == "factor") { // Install this InitWater under the Soil, replacing the existing one. XmlNode existingInitWater = XmlHelper.FindByType(soilDoc.DocumentElement, "InitialWater"); if (existingInitWater == null) { throw new Exception("Cannot find InitWater under soil"); } soilDoc.DocumentElement.RemoveChild(existingInitWater); soilDoc.DocumentElement.AppendChild(soilDoc.ImportNode(OurComponent.ContentsAsXML, true)); } Soil = Soil.Create(soilDoc.OuterXml); RelativeToCombo.Items.Clear(); RelativeToCombo.Items.Add("ll15"); RelativeToCombo.Items.AddRange(Soil.Water.CropNames); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["Name"] != null) { string FileName = Path.GetFileName(Request.QueryString["Name"]); Response.Clear(); Response.AppendHeader("Content-Disposition", "inline; filename=" + FileName + ".csv"); //Response.AppendHeader("Content-Disposition", "csv; Soils.csv"); Response.Buffer = false; Response.ContentType = "application/vnd.ms-excel"; // text/plain string SoilName = Request.QueryString["Name"]; ApsoilWeb.Service SoilsDB = new Apsoil.ApsoilWeb.Service(); Soil Soil = Soil.Create(SoilsDB.SoilXML(SoilName)); DataTable Data = new DataTable(); SoilDataTable.SoilToTable(Soil, Data); Response.Write(DataTableUtility.DataTableToCSV(Data, 0)); Response.Flush(); // send our content to the client browser. Response.SuppressContent = true; // stops .net from writing it's stuff. } }
public void DeserialiseSoil() { StreamReader F = new StreamReader("./Tests/Test.xml"); string Xml = F.ReadToEnd(); F.Close(); Soil.Create(Xml); }
public void TestImportFromPar() { Soil S = Soil.Create(SoilParFile.Import("./Temp.par")); Assert.AreEqual(S.Name, "BlackVertosol"); Assert.IsTrue(MathUtility.AreEqual(S.Water.BD, new double[] { 1.02, 1.03, 1.02, 1.02, 1.06, 1.11, 1.12, 1.15, 1.18, 1.2, 1.25 })); Assert.IsTrue(MathUtility.AreEqual(S.OC, new double[] { 1.04, 0.89, 0.89, 0.89, 0.77, 0.45, 0.27, 0.22, 0.16, 0.13, 0.12 })); Assert.IsTrue(MathUtility.AreEqual(S.Crop("nwheat").LL, new double[] { 0.290, 0.290, 0.320, 0.320, 0.350, 0.380, 0.410, 0.480, 0.470, 0.460, 0.440 })); }
/// <summary> /// Called whenever the control is loaded and made visible. /// </summary> protected override void OnLoad() { // We need not just the XML for this profile node but the whole soil XML. Component SoilComponent = Controller.ApsimData.Find(NodePath).Parent; if (SoilComponent.Type.ToLower() != "soil") { SoilComponent = SoilComponent.Parent; } Soil = Soil.Create(SoilComponent.FullXMLNoShortCuts()); Properties.OnLoad(Controller, NodePath, Data.OuterXml); Properties.OnLoad(Soil); // Get a component that represents the node we're to OurComponent = Controller.ApsimData.Find(NodePath); if (OurComponent.ShortCutTo != null) { OurComponent = OurComponent.ShortCutTo; } // Call OnLoad in our graph Graph = new SoilGraphUI(); Graph.Parent = this; Graph.Visible = true; Graph.Dock = DockStyle.Fill; Graph.BringToFront(); // Load in the splitter position. string SplitterPositionString = Configuration.Instance.Setting("SoilSplitterPosition"); if (SplitterPositionString != "") { TopPanel.Height = Convert.ToInt32(SplitterPositionString); } // add some extra items to the context menu. if (Grid.ContextMenuStrip != null && Grid.ContextMenuStrip.Items.Count != 8 && (OurComponent.Type == "Water" || OurComponent.Type == "Analysis")) { Grid.ContextMenuStrip.Items.Add(new ToolStripSeparator()); ToolStripMenuItem Item = (ToolStripMenuItem)Grid.ContextMenuStrip.Items.Add("Edit Metadata..."); Item.ShortcutKeys = Keys.Control | Keys.M; Item.Click += new System.EventHandler(OnMetadataClick); } panel1.Visible = OurComponent.Type == "Water"; }
private static void CheckSoils(ApsimFile.Component Data, ref string ErrorMessage) { if (Data.Type.ToLower() == "soil") { Soil ThisSoil = Soil.Create(Data.FullXML()); string Errors = ThisSoil.Check(true); if (!string.IsNullOrEmpty(Errors)) { ErrorMessage += Environment.NewLine + Data.FullPath + Environment.NewLine + StringManip.IndentText(Errors, 6); } } else if (Data.Type.ToLower() == "folder") { foreach (ApsimFile.Component Child in Data.ChildNodes) { CheckSoils(Child, ref ErrorMessage); } } }
public static void AddSoil(BaseController Controller) { //throw new NotImplementedException(); Soil NewSoil = Soil.Create(@"<Soil> <Water> <Thickness/> <BD/> </Water> <SoilWater/> <SoilOrganicMatter> <Thickness/> <OC/> <FBiom/> <FInert/> </SoilOrganicMatter> <Analysis/> </Soil>"); Controller.Selection.Add(NewSoil.ToXml(), true); }
/// <summary> /// First time the UI is created - find our parent soil. /// </summary> protected override void OnLoad() { // We need not just the XML for this profile node but the whole soil XML. OurComponent = Controller.ApsimData.Find(NodePath); ApsimFile.Component SoilComponent = OurComponent; panel1.Visible = SoilComponent.Type.ToLower() == "soil"; while (SoilComponent.Type.ToLower() != "soil" && SoilComponent.Parent != null) { SoilComponent = SoilComponent.Parent; } if (SoilComponent.Type != "Soil") { throw new Exception("Cannot find soil object"); } Soil = Soil.Create(SoilComponent.FullXMLNoShortCuts()); CalledFromProfileUI = false; }
/// <summary> /// Convert a soils XML file to a DataTable. The Soil XML can have multiple soils. /// </summary> public static DataTable SoilXMLToTable(XmlNode Xml, List <string> XMLPaths = null) { DataTable Table = new DataTable("SoilData"); List <XmlNode> SoilNodes = new List <XmlNode>(); if (XMLPaths == null) { XmlHelper.FindAllRecursivelyByType(Xml, "soil", ref SoilNodes); } else { // Go through all paths and look for <folder> nodes. When found // replace them with all nested soils. foreach (string Path in XMLPaths) { XmlNode Node = XmlHelper.Find(Xml, Path); if (Node == null) { } else if (Node.Name.Equals("soil", StringComparison.CurrentCultureIgnoreCase)) { SoilNodes.Add(Node); } else if (Node.Name.Equals("folder", StringComparison.CurrentCultureIgnoreCase)) { XmlHelper.FindAllRecursivelyByType(Node, "soil", ref SoilNodes); } } } foreach (XmlNode SoilNode in SoilNodes) { Soil mySoil = Soil.Create(SoilNode.OuterXml); SoilToTable(mySoil, Table); } return(Table); }
public static StateMachineClient CreateStateMachine(Sim s, HarvestPlant p, out Soil dummyIk) { dummyIk = Soil.Create(isDummyIk: true); StateMachineClient val = StateMachineClient.Acquire(s, "petgardening"); //dummyIk.SetHiddenFlags(HiddenFlags.Nothing); dummyIk.SetPosition(p.GetSoil().Position); Vector3 forward = p.GetSoil().Position - s.Position; dummyIk.SetForward(forward); dummyIk.AddToWorld(); val.SetActor("x", s); val.SetActor("gardenPlantBush", p); val.SetActor("gardenSoil", p.GetSoil()); val.SetActor("Dummy", dummyIk); if (!p.PlantDef.GetPlantHeight(out PlantHeight height)) { height = PlantHeight.Medium; } val.SetParameter("Plant Height", height); return(val); }
/// <summary>Check selected soils and show error messages.</summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OnCheckSoilsClick(object sender, EventArgs e) { string labelText = string.Empty; using (ApsoilWeb.Service soilsDB = new Apsoil.ApsoilWeb.Service()) { foreach (ListItem item in ListBox.Items) { if (item.Selected) { string soilPath = item.Text; Soil soil = Soil.Create(soilsDB.SoilXML(soilPath)); string messages = soil.Check(true); if (messages != string.Empty) { labelText += soilPath + "\r\n"; labelText += messages + "\r\n"; } } } } label3.Text = labelText.Replace("\r\n", "<br/>"); }
/// <summary> /// This is called directly by Google Earth when it wants KML data. /// </summary> private byte[] NetworkLinkData() { kml KmlContent = new kml(); Document KmlDoc = new Document("Test", ""); KmlContent.Documents.Add(KmlDoc); KML_22_Beta1.Style APSRUIcon = new KML_22_Beta1.Style(); APSRUIcon.IconStyle.Icon.Href.Text = "http://apsimdev.apsim.info/ApsoilWeb/shovel.png"; APSRUIcon.IconStyle.Scale.Value = 0.7; APSRUIcon.LabelStyle.Scale.Value = 0.7; APSRUIcon.id = "APSRUIconID"; KmlDoc.StyleSelector.Style.Add(APSRUIcon); Dictionary <string, Folder> Folders = new Dictionary <string, Folder>(); ApsoilWeb.Service SoilsDB = new Apsoil.ApsoilWeb.Service(); foreach (string Name in SoilsDB.AllSoilNames(false)) { string FolderName = Name; if (FolderName.Contains("/")) { FolderName = FolderName.Substring(0, FolderName.LastIndexOf('/')); } Soil Soil = Soil.Create(SoilsDB.SoilXML(Name)); if (Soil != null) { string BalloonDescription = "<p><b>" + Soil.Name + "</b></p><p><i>" + Soil.Comments + "</i></p>"; string DataSourceComments = Soil.DataSource; if (DataSourceComments != null && DataSourceComments != "") { BalloonDescription += "<p><i>Data source: " + DataSourceComments + "</i></p>"; } BalloonDescription += "<img src=\"" + ourPath + "SoilChart.aspx?Name=" + Name + "\"/>"; BalloonDescription += "<p><a href=\"" + ourPath + "GetSoil.aspx?Name=" + Name + "\">Download soil in APSIM format (copy and paste contents to your simulation).</a></p>"; BalloonDescription += "<p><a name=\"link_id\" id=\"link_id\" href=\"Download.html\" onclick=\"window.open('" + ourPath + "Excel.aspx?Name=" + Name + "');\">Download soil as an EXCEL spreadsheet</a></p>"; string SoilName = Soil.Name; if (Soil.ApsoilNumber != "") { SoilName = Soil.ApsoilNumber; } Placemark plmMyPlaceMark = new Placemark(SoilName, BalloonDescription, Soil.Latitude, Soil.Longitude, 0, altitudeModeEnum.clampToGround); plmMyPlaceMark.Description.UseCDATA = true; plmMyPlaceMark.Description.Text = BalloonDescription; plmMyPlaceMark.StyleUrl.Text = "#APSRUIconID"; Folder F = GetFolder(FolderName, Folders, KmlDoc); F.Features.Placemarks.Add(plmMyPlaceMark); } } KmlContent.NetworkLinkControl.Expires.Value = DateTime.Now.AddDays(7); KmlContent.NetworkLinkControl.LinkDescription.Text = "Characterised sites - " + DateTime.Now.ToString("dd MMM yyyy HH:mm:ss"); return(KmlContent.GetKMZ("NetworkData.kml")); }
public bool RunCommon() { if (mObjectsToPlant == null || mObjectsToPlant.Count == 0) { return false; } EWHerbLoreSkill skill = EWHerbLoreSkill.StartSkillGain(Actor); if (skill != null) { while (mObjectsToPlant.Count > 0) { PlantableObjectData data = mObjectsToPlant[0]; CurrentTarget = data.PlantableObject; CurrentSoil = data.Soil; if (Plant.DoPlantRoute(Actor, CurrentSoil)) { UnreservePlantablePlantingSucceeded(); Plant plant = CreatePlantFromSeed(CurrentTarget, CurrentSoil, Actor); plant.UpdateHealth(); plant.AddToUseList(Actor); AcquireStateMachine("eatharvestablepet"); mCurrentStateMachine.SetActor("x", Actor); mCurrentStateMachine.EnterState("x", "Enter"); SetParameter("IsEatingOnGround", paramValue: true); // Parrotting the dummyIK code from the plantMedium state machine mDummyIk = Soil.Create(isDummyIk: true); //mDummyIk.SetHiddenFlags(-1); mDummyIk.SetPosition(plant.GetSoil().Position); Vector3 forward = plant.GetSoil().Position - Actor.Position; mDummyIk.SetForward(forward); mDummyIk.AddToWorld(); BeginCommodityUpdates(); AddOneShotScriptEventHandler(201u, new SacsEventHandler(ScriptHandlerOnSimAboutToPlant)); AnimateSim("EatHarvestable"); skill.Planted(plant); AnimateSim("Exit"); EndCommodityUpdates(succeeded: true); plant.RemoveFromUseList(Actor); CurrentSoil.RemoveFromUseList(Actor); if (mDummyIk != null) { mDummyIk.Destroy(); mDummyIk = null; } EventTracker.SendEvent(EventTypeId.kGardened, Actor); if (PlantHelper.IsSeed(CurrentTarget)) { EventTracker.SendEvent(EventTypeId.kEventSeedPlanted, Actor, CurrentTarget); } EventTracker.SendEvent(EventTypeId.kPlantedObject, Actor, plant); } else { CleanupPlantInstances(data, Actor, PlantInteractionType); mObjectsToPlant.RemoveAt(0); } } skill.StopSkillGain(); skill.AddSkillPointsLevelClamped(200, 10); // Bonus, Planting takes animal thinking return true; } return false; }