public frmMorphologicalUnits(UnitsNet.Units.VolumeUnit vol, UnitsNet.Units.MassUnit mass, UnitsNet.Units.DurationUnit duration) { InitializeComponent(); VolumeUnit = vol; MassUnit = mass; DurationUnit = duration; }
/// <summary> /// Update the boundary flux with the new units. This shouldn't trigger a recalculation /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void BoundaryUnitsChanged(object sender, EventArgs e) { valBoundaryFlux.ValueChanged -= MinFlux_Changed; UnitsNet.Units.VolumeUnit newVolUnit = ((GCDUnits.FormattedUnit <UnitsNet.Units.VolumeUnit>)cboBoundaryUnits.SelectedItem).Unit; valBoundaryFlux.Value = (decimal)Analysis.BoundaryFlux.As(newVolUnit); valBoundaryFlux.ValueChanged += MinFlux_Changed; }
/// <summary> /// /// </summary> /// <param name="changeStats"></param> /// <returns></returns> /// <remarks>This method is needed by budget segregation as well</remarks> protected void GenerateSummaryXML(DoDStats changeStats, FileInfo outputPath) { string templatePath = Path.Combine(Project.ProjectManager.ExcelTemplatesFolder.FullName, "GCDSummary.xml"); System.Text.StringBuilder outputText = default(System.Text.StringBuilder); try { using (System.IO.StreamReader objReader = new System.IO.StreamReader(templatePath)) { outputText = new System.Text.StringBuilder(objReader.ReadToEnd()); } } catch (Exception ex) { Exception ex2 = new Exception("Error reading the GCD summary XML template file", ex); ex.Data["Excel Template Path"] = templatePath; throw ex2; } UnitsNet.Area ca = Project.ProjectManager.Project.CellArea; UnitsNet.Units.LengthUnit lu = Project.ProjectManager.Project.Units.VertUnit; UnitsNet.Units.AreaUnit au = Project.ProjectManager.Project.Units.ArUnit; UnitsNet.Units.VolumeUnit vu = Project.ProjectManager.Project.Units.VolUnit; string abbr = UnitsNet.Length.GetAbbreviation(lu); outputText.Replace("[LinearUnits]", abbr); outputText.Replace("[TotalAreaOfErosionRaw]", changeStats.ErosionRaw.GetArea(ca).As(au).ToString(CultureInfo.InvariantCulture)); outputText.Replace("[TotalAreaOfErosionThresholded]", changeStats.ErosionThr.GetArea(ca).As(au).ToString(CultureInfo.InvariantCulture)); outputText.Replace("[TotalAreaOfDepositionRaw]", changeStats.DepositionRaw.GetArea(ca).As(au).ToString(CultureInfo.InvariantCulture)); outputText.Replace("[TotalAreaOfDepositionThresholded]", changeStats.DepositionThr.GetArea(ca).As(au).ToString(CultureInfo.InvariantCulture)); outputText.Replace("[TotalVolumeOfErosionRaw]", changeStats.ErosionRaw.GetVolume(ca, Project.ProjectManager.Project.Units).As(vu).ToString(CultureInfo.InvariantCulture)); outputText.Replace("[TotalVolumeOfErosionThresholded]", changeStats.ErosionThr.GetVolume(ca, Project.ProjectManager.Project.Units).As(vu).ToString(CultureInfo.InvariantCulture)); outputText.Replace("[ErrorVolumeOfErosion]", changeStats.ErosionErr.GetVolume(ca, Project.ProjectManager.Project.Units).As(vu).ToString(CultureInfo.InvariantCulture)); outputText.Replace("[TotalVolumeOfDepositionRaw]", changeStats.DepositionRaw.GetVolume(ca, Project.ProjectManager.Project.Units).As(vu).ToString(CultureInfo.InvariantCulture)); outputText.Replace("[TotalVolumeOfDepositionThresholded]", changeStats.DepositionThr.GetVolume(ca, Project.ProjectManager.Project.Units).As(vu).ToString(CultureInfo.InvariantCulture)); outputText.Replace("[ErrorVolumeOfDeposition]", changeStats.DepositionErr.GetVolume(ca, Project.ProjectManager.Project.Units).As(vu).ToString(CultureInfo.InvariantCulture)); try { using (StreamWriter objWriter = new StreamWriter(outputPath.FullName)) { objWriter.Write(outputText); } } catch (Exception ex) { Exception ex2 = new Exception("Error writing the GCD summary XML template file", ex); ex.Data["Excel Template Path"] = templatePath; throw ex2; } }
public static void SelectUnit(System.Windows.Forms.ComboBox cbo, UnitsNet.Units.VolumeUnit unit) { foreach (FormattedUnit <UnitsNet.Units.VolumeUnit> cboUnit in cbo.Items) { if (cboUnit.Unit == unit) { cbo.SelectedItem = cboUnit; return; } } }
public static GCDProject Load(FileInfo projectFile) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(projectFile.FullName); XmlNode nodProject = xmlDoc.SelectSingleNode("Project"); string name = nodProject.SelectSingleNode("Name").InnerText; string desc = nodProject.SelectSingleNode("Description").InnerText; string gcdv = nodProject.SelectSingleNode("GCDVersion").InnerText; DateTime dtCreated = DateTime.Parse(nodProject.SelectSingleNode("DateTimeCreated").InnerText); UnitsNet.Units.LengthUnit horiz = (UnitsNet.Units.LengthUnit)Enum.Parse(typeof(UnitsNet.Units.LengthUnit), nodProject.SelectSingleNode("Units/Horizontal").InnerText); UnitsNet.Units.LengthUnit vert = (UnitsNet.Units.LengthUnit)Enum.Parse(typeof(UnitsNet.Units.LengthUnit), nodProject.SelectSingleNode("Units/Vertical").InnerText); UnitsNet.Units.AreaUnit area = (UnitsNet.Units.AreaUnit)Enum.Parse(typeof(UnitsNet.Units.AreaUnit), nodProject.SelectSingleNode("Units/Area").InnerText); UnitsNet.Units.VolumeUnit vol = (UnitsNet.Units.VolumeUnit)Enum.Parse(typeof(UnitsNet.Units.VolumeUnit), nodProject.SelectSingleNode("Units/Volume").InnerText); GCDConsoleLib.GCD.UnitGroup units = new GCDConsoleLib.GCD.UnitGroup(vol, area, vert, horiz); UnitsNet.Area cellArea = UnitsNet.Area.From(0, area); XmlNode nodCellArea = nodProject.SelectSingleNode("CellArea"); if (!string.IsNullOrEmpty(nodCellArea.InnerText)) { cellArea = UnitsNet.Area.From(double.Parse(nodCellArea.InnerText, CultureInfo.InvariantCulture), area); } ProjectManager.Project = new GCDProject(name, desc, projectFile, dtCreated, gcdv, cellArea, units); foreach (XmlNode nodOnline in nodProject.SelectNodes("Online/*")) { ProjectManager.Project.OnlineParams[nodOnline.Name] = nodOnline.InnerText; } // Load masks before DEMs. DEMs will load error surfaces that refer to masks foreach (XmlNode nodMask in nodProject.SelectNodes("Masks/Mask")) { if (nodMask.SelectSingleNode("Field") is XmlNode) { // Regular or directional mask if (nodMask.SelectSingleNode("Items") is XmlNode) { ProjectManager.Project.Masks.Add(new Masks.RegularMask(nodMask)); } else { ProjectManager.Project.Masks.Add(new Project.Masks.DirectionalMask(nodMask)); } } else { // Area of interest ProjectManager.Project.Masks.Add(new Project.Masks.AOIMask(nodMask)); } } // Load profile routes before DEMs, Ref Surfs and DoDs that might refer to // routes in their linear extractions foreach (XmlNode nodRoute in nodProject.SelectNodes("ProfileRoutes/ProfileRoute")) { ProjectManager.Project.ProfileRoutes.Add(new Project.ProfileRoutes.ProfileRoute(nodRoute)); } foreach (XmlNode nodDEM in nodProject.SelectNodes("DEMSurveys/DEM")) { DEMSurvey dem = new DEMSurvey(nodDEM); ProjectManager.Project.DEMSurveys.Add(dem); } foreach (XmlNode nodRefSurf in nodProject.SelectNodes("ReferenceSurfaces/ReferenceSurface")) { Surface surf = new Surface(nodRefSurf, true, true); ProjectManager.Project.ReferenceSurfaces.Add(surf); } foreach (XmlNode nodDoD in nodProject.SelectNodes("DoDs/DoD")) { DoDBase dod = null; if (nodDoD.SelectSingleNode("Threshold") is XmlNode) { dod = new DoDMinLoD(nodDoD); } else if (nodDoD.SelectSingleNode("ConfidenceLevel") is XmlNode) { dod = new DoDProbabilistic(nodDoD); } else { dod = new DoDPropagated(nodDoD); } ProjectManager.Project.DoDs.Add(dod); } foreach (XmlNode nodInter in nodProject.SelectNodes("InterComparisons/InterComparison")) { InterComparison inter = new InterComparison(nodInter, ProjectManager.Project.DoDs); ProjectManager.Project.InterComparisons.Add(inter); } foreach (XmlNode nodItem in nodProject.SelectNodes("MetaData/Item")) { ProjectManager.Project.MetaData[nodItem.SelectSingleNode("Key").InnerText] = nodItem.SelectSingleNode("Value").InnerText; } return(ProjectManager.Project); }
/// <summary> /// /// </summary> /// <param name="units"></param> /// <param name="volUnit"></param> /// <remarks>remember to filter out morphological totals</remarks> public void UpdateChart(System.IO.DirectoryInfo outputDir, IEnumerable <GCDCore.Project.Morphological.IBudgetGraphicalResults> units, UnitsNet.Units.VolumeUnit volUnit, bool bBudgetSeg, bool directional) { cmsChart = new UtilityForms.ChartContextMenu(outputDir, "morphological"); chtData.ContextMenuStrip = cmsChart.CMS; // Update the Y axis volume units chtData.ChartAreas.ToList <ChartArea>().ForEach(x => x.AxisY.Title = string.Format("Volume ({0})", Volume.GetAbbreviation(volUnit))); // Clear all series data points chtData.Series.ToList <Series>().ForEach(x => x.Points.Clear()); // Hide the second chart area if this is a non-directional budget seg chtData.ChartAreas[1].Visible = !bBudgetSeg || (bBudgetSeg && directional); CustomLabelsCollection xAxisLabels = chtData.ChartAreas[0].AxisX.CustomLabels; double maxY = 0; double cumVolume = 0; foreach (GCDCore.Project.Morphological.IBudgetGraphicalResults unit in units) { double labelStart = chtData.Series[EROSION_CHART_SERIES].Points.Count; double labelEnd = labelStart + 3; xAxisLabels.Add(new CustomLabel(labelStart, labelEnd, unit.Name, 0, LabelMarkStyle.Box)); chtData.Series[EROSION_CHART_SERIES].Points.AddY(unit.VolErosion.As(volUnit)); chtData.Series[EROSION_CHART_SERIES].Points.AddY(0); chtData.Series[EROSION_CHART_SERIES].Points.AddY(0); chtData.Series[DEPOSIT_CHART_SERIES].Points.AddY(0); chtData.Series[DEPOSIT_CHART_SERIES].Points.AddY(unit.VolDeposition.As(volUnit)); chtData.Series[DEPOSIT_CHART_SERIES].Points.AddY(0); chtData.Series[ERROR___CHART_SERIES].Points.AddY(new object[] { unit.VolErosion.As(volUnit), (unit.VolErosion - unit.VolErosionErr).As(volUnit), (unit.VolErosion + unit.VolErosionErr).As(volUnit) }); chtData.Series[ERROR___CHART_SERIES].Points.AddY(new object[] { unit.VolDeposition.As(volUnit), (unit.VolDeposition - unit.VolDepositionErr).As(volUnit), (unit.VolDeposition + unit.VolDepositionErr).As(volUnit) }); chtData.Series[ERROR___CHART_SERIES].Points.AddY(new object[] { 0, 0, 0 }); maxY = Math.Max(maxY, (unit.VolErosion + unit.VolErosionErr).As(volUnit)); maxY = Math.Max(maxY, (unit.VolDeposition + unit.VolDepositionErr).As(volUnit)); cumVolume += unit.VolDeposition.As(volUnit) - unit.VolErosion.As(volUnit); if (!bBudgetSeg) { chtData.Series[VOLOUT__CHART_SERIES].Points.AddXY(unit.Name, unit.SecondGraphValue.As(volUnit)); } else { cumVolume += unit.VolDeposition.As(volUnit) - unit.VolErosion.As(volUnit); chtData.Series[VOLOUT__CHART_SERIES].Points.AddXY(unit.Name, cumVolume); } } chtData.ChartAreas[0].AxisY.Maximum = Math.Ceiling(maxY); chtData.ChartAreas[0].AxisY.RoundAxisValues(); foreach (int i in new List <int> { 0, 1 }) { chtData.ChartAreas[i].AxisX.TitleFont = Properties.Settings.Default.ChartFont; chtData.ChartAreas[i].AxisX.LabelStyle.Font = Properties.Settings.Default.ChartFont; chtData.ChartAreas[i].AxisY.TitleFont = Properties.Settings.Default.ChartFont; chtData.ChartAreas[i].AxisY.LabelStyle.Font = Properties.Settings.Default.ChartFont; } chtData.Legends[0].Font = Properties.Settings.Default.ChartFont; // The data displayed on the second chart depends if this is being used for Morphological or Bs chtData.Series[VOLOUT__CHART_SERIES].LegendText = !bBudgetSeg ? "Volume Out" : "Cumulative Volume Change"; chtData.Series[VOLOUT__CHART_SERIES].IsVisibleInLegend = !bBudgetSeg || directional; }
protected void GenerateChangeBarGraphicFiles(DirectoryInfo analysisFolder, DoDStats stats, int fChartWidth, int fChartHeight, string sFilePrefix = "") { ElevationChangeBarViewer barViewer = new ElevationChangeBarViewer(); if (!string.IsNullOrEmpty(sFilePrefix)) { if (!sFilePrefix.EndsWith("_")) { sFilePrefix += "_"; } } DirectoryInfo figuresFolder = Project.DoDBase.FiguresFolderPath(analysisFolder); figuresFolder.Create(); UnitsNet.Area ca = GCDCore.Project.ProjectManager.Project.CellArea; UnitsNet.Units.LengthUnit lu = Project.ProjectManager.Project.Units.VertUnit; UnitsNet.Units.AreaUnit au = Project.ProjectManager.Project.Units.ArUnit; UnitsNet.Units.VolumeUnit vu = Project.ProjectManager.Project.Units.VolUnit; string abbr = UnitsNet.Length.GetAbbreviation(lu); barViewer.Refresh( stats.ErosionThr.GetArea(ca).As(au), stats.DepositionThr.GetArea(ca).As(au), abbr, ElevationChangeBarViewer.BarTypes.Area, true); barViewer.Save(new FileInfo(Path.Combine(figuresFolder.FullName, sFilePrefix + "ChangeBars_AreaAbsolute.png")), fChartWidth, fChartHeight); barViewer.Refresh( stats.ErosionThr.GetArea(ca).As(au), stats.DepositionThr.GetArea(ca).As(au), abbr, ElevationChangeBarViewer.BarTypes.Area, false); barViewer.Save(new FileInfo(Path.Combine(figuresFolder.FullName, sFilePrefix + "ChangeBars_AreaRelative.png")), fChartWidth, fChartHeight); barViewer.Refresh( stats.ErosionThr.GetVolume(ca, Project.ProjectManager.Project.Units).As(vu), stats.DepositionThr.GetVolume(ca, Project.ProjectManager.Project.Units).As(vu), stats.NetVolumeOfDifference_Thresholded.As(vu), stats.ErosionErr.GetVolume(ca, Project.ProjectManager.Project.Units).As(vu), stats.DepositionErr.GetVolume(ca, Project.ProjectManager.Project.Units).As(vu), stats.NetVolumeOfDifference_Error.As(vu), abbr, ElevationChangeBarViewer.BarTypes.Volume, true); barViewer.Save(new FileInfo(Path.Combine(figuresFolder.FullName, sFilePrefix + "ChangeBars_VolumeAbsolute.png")), fChartWidth, fChartHeight); barViewer.Refresh( stats.ErosionThr.GetVolume(ca, Project.ProjectManager.Project.Units).As(vu), stats.DepositionThr.GetVolume(ca, Project.ProjectManager.Project.Units).As(vu), stats.NetVolumeOfDifference_Thresholded.As(vu), stats.ErosionErr.GetVolume(ca, Project.ProjectManager.Project.Units).As(vu), stats.DepositionErr.GetVolume(ca, Project.ProjectManager.Project.Units).As(vu), stats.NetVolumeOfDifference_Error.As(vu), abbr, ElevationChangeBarViewer.BarTypes.Volume, false); barViewer.Save(new FileInfo(Path.Combine(figuresFolder.FullName, sFilePrefix + "ChangeBars_VolumeRelative.png")), fChartWidth, fChartHeight); barViewer.Refresh( stats.AverageDepthErosion_Thresholded.As(lu), stats.AverageDepthDeposition_Thresholded.As(lu), stats.AverageNetThicknessOfDifferenceADC_Thresholded.As(lu), stats.AverageDepthErosion_Error.As(lu), stats.AverageDepthDeposition_Error.As(lu), stats.AverageThicknessOfDifferenceADC_Error.As(lu), abbr, ElevationChangeBarViewer.BarTypes.Vertical, true); barViewer.Save(new FileInfo(Path.Combine(figuresFolder.FullName, sFilePrefix + "ChangeBars_DepthAbsolute.png")), fChartWidth, fChartHeight); barViewer.Refresh( stats.AverageDepthErosion_Thresholded.As(lu), stats.AverageDepthDeposition_Thresholded.As(lu), stats.AverageNetThicknessOfDifferenceADC_Thresholded.As(lu), stats.AverageDepthErosion_Error.As(lu), stats.AverageDepthDeposition_Error.As(lu), stats.AverageThicknessOfDifferenceADC_Error.As(lu), abbr, ElevationChangeBarViewer.BarTypes.Vertical, false); barViewer.Save(new FileInfo(Path.Combine(figuresFolder.FullName, sFilePrefix + "ChangeBars_DepthRelative.png")), fChartWidth, fChartHeight); }