Skip to content

Commit

Permalink
raster properties row formatting issue #232
Browse files Browse the repository at this point in the history
  • Loading branch information
philipbaileynar committed Aug 22, 2018
1 parent c733c41 commit db0d44f
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 147 deletions.
1 change: 1 addition & 0 deletions GCDCore/GCDCore.csproj
Expand Up @@ -308,6 +308,7 @@
<DependentUpon>frmOptions.cs</DependentUpon>
</Compile>
<Compile Include="UserInterface\GIS\BrowseGISLayerEventArgs.cs" />
<Compile Include="UserInterface\GridViewPropertyValueItem.cs" />
<Compile Include="UserInterface\IProjectItemForm.cs" />
<Compile Include="UserInterface\LinearExtraction\frmLinearExtractionProperties.cs">
<SubType>Form</SubType>
Expand Down
2 changes: 1 addition & 1 deletion GCDCore/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions GCDCore/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions GCDCore/Properties/Settings.settings
Expand Up @@ -101,5 +101,8 @@
<Setting Name="DeveloperPreview" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="PropertyGridLeftIndent" Type="System.Int32" Scope="Application">
<Value Profile="(Default)">16</Value>
</Setting>
</Settings>
</SettingsFile>
150 changes: 36 additions & 114 deletions GCDCore/UserInterface/ChangeDetection/ucDoDPropertiesGrid.cs
Expand Up @@ -14,12 +14,12 @@ namespace GCDCore.UserInterface.ChangeDetection
public partial class ucDoDPropertiesGrid : UserControl
{
public DoDBase DoD { get; internal set; }
private naru.ui.SortableBindingList<DoDProperty> DoDProperties;
private naru.ui.SortableBindingList<GridViewPropertyValueItem> DoDProperties;

public ucDoDPropertiesGrid()
{
InitializeComponent();
DoDProperties = new naru.ui.SortableBindingList<DoDProperty>();
DoDProperties = new naru.ui.SortableBindingList<GridViewPropertyValueItem>();
}

private void ucDoDPropertiesGrid_Load(object sender, EventArgs e)
Expand All @@ -32,15 +32,15 @@ private void ucDoDPropertiesGrid_Load(object sender, EventArgs e)

public void AddDoDProperty(string property, string value)
{
DoDProperties.Add(new DoDProperty(property, value));
DoDProperties.Add(new GridViewPropertyValueItem(property, value));
DoDProperties.ResetBindings();
}

private void grdData_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 0 && e.RowIndex > -1)
{
DoDProperty prop = (DoDProperty)grdData.Rows[e.RowIndex].DataBoundItem;
GridViewPropertyValueItem prop = (GridViewPropertyValueItem)grdData.Rows[e.RowIndex].DataBoundItem;

if (prop.Header)
{
Expand All @@ -51,171 +51,93 @@ private void grdData_CellFormatting(object sender, DataGridViewCellFormattingEve
grdData.Rows[e.RowIndex].Cells[0].Style.Padding = new Padding(prop.LeftPadding, 0, 0, 0);
}

if (prop is DoDPropertyProjectItem || prop is DoDPropertyRaster)
if (prop is GridViewGCDProjectItem || prop is GridViewRasterItem)
grdData.Rows[e.RowIndex].ContextMenuStrip = contextMenuStrip1;
}
}

public void Initialize(DoDBase dod)
{
DoDProperties.Add(new DoDProperty("Input Datasets"));
DoDProperties.Add(new DoDPropertyProjectItem("New Surface", dod.NewSurface.Name, dod.NewSurface));
DoDProperties.Add(new DoDPropertyProjectItem("Old Surface", dod.OldSurface.Name, dod.OldSurface));
DoDProperties.Add(new GridViewPropertyValueItem("Input Datasets"));
DoDProperties.Add(new GridViewGCDProjectItem("New Surface", dod.NewSurface.Name, dod.NewSurface));
DoDProperties.Add(new GridViewGCDProjectItem("Old Surface", dod.OldSurface.Name, dod.OldSurface));
if (dod is DoDPropagated)
{
DoDPropagated dodProp = dod as DoDPropagated;
DoDProperties.Add(new DoDPropertyProjectItem("New Error Surface", dodProp.NewError.Name, dodProp.NewError));
DoDProperties.Add(new DoDPropertyProjectItem("Old Error Surface", dodProp.OldError.Name, dodProp.OldError));
DoDProperties.Add(new GridViewGCDProjectItem("New Error Surface", dodProp.NewError.Name, dodProp.NewError));
DoDProperties.Add(new GridViewGCDProjectItem("Old Error Surface", dodProp.OldError.Name, dodProp.OldError));
}

if (dod.AOIMask == null)
DoDProperties.Add(new DoDProperty("Area Of Interest", dod.AOILabel));
DoDProperties.Add(new GridViewPropertyValueItem("Area Of Interest", dod.AOILabel));
else
DoDProperties.Add(new DoDPropertyProjectItem("Area Of Interest", dod.AOILabel, dod.AOIMask));
DoDProperties.Add(new GridViewGCDProjectItem("Area Of Interest", dod.AOILabel, dod.AOIMask));

DoDProperties.Add(new DoDProperty("Input Parameters"));
DoDProperties.Add(new DoDProperty("Uncertainty Analysis", dod.UncertaintyAnalysisLabel));
DoDProperties.Add(new GridViewPropertyValueItem("Input Parameters"));
DoDProperties.Add(new GridViewPropertyValueItem("Uncertainty Analysis", dod.UncertaintyAnalysisLabel));

DoDProperties.Add(new DoDProperty("Output Datasets"));
DoDProperties.Add(new DoDProperty("DoD Analysis Folder", ProjectManager.Project.GetRelativePath(dod.Folder.FullName)));
DoDProperties.Add(new DoDPropertyProjectItem("Thresholded DoD", ProjectManager.Project.GetRelativePath(dod.ThrDoD.Raster.GISFileInfo), dod.ThrDoD));
DoDProperties.Add(new DoDPropertyProjectItem("Raw DoD", ProjectManager.Project.GetRelativePath(dod.RawDoD.Raster.GISFileInfo), dod.RawDoD));
DoDProperties.Add(new GridViewPropertyValueItem("Output Datasets"));
DoDProperties.Add(new GridViewPropertyValueItem("DoD Analysis Folder", ProjectManager.Project.GetRelativePath(dod.Folder.FullName)));
DoDProperties.Add(new GridViewGCDProjectItem("Thresholded DoD", ProjectManager.Project.GetRelativePath(dod.ThrDoD.Raster.GISFileInfo), dod.ThrDoD));
DoDProperties.Add(new GridViewGCDProjectItem("Raw DoD", ProjectManager.Project.GetRelativePath(dod.RawDoD.Raster.GISFileInfo), dod.RawDoD));

DoDProperties.Add(new DoDProperty("Intermediate Datasets"));
DoDProperties.Add(new GridViewPropertyValueItem("Intermediate Datasets"));
if (dod is DoDPropagated)
{
DoDPropagated dodProp = dod as DoDPropagated;
DoDProperties.Add(new DoDPropertyRaster("Propagated Error Surface", dodProp.PropagatedError));
DoDProperties.Add(new GridViewRasterItem("Propagated Error Surface", dodProp.PropagatedError));

if (dod is DoDProbabilistic)
{
DoDProbabilistic dodProb = dod as DoDProbabilistic;

if (dodProb.SpatialCoherence == null)
{
DoDProperties.Add(new DoDPropertyRaster("Probability Raster", dodProb.PriorProbability));
DoDProperties.Add(new GridViewRasterItem("Probability Raster", dodProb.PriorProbability));
}
else
{
DoDProperties.Add(new DoDProperty("Spatial Coherence", string.Format("Bayesian updating with filter size of {0} X {0} cells", ((DoDProbabilistic)dod).SpatialCoherence.BufferSize)));
DoDProperties.Add(new DoDPropertyRaster("Probability Raster", dodProb.PriorProbability));
DoDProperties.Add(new DoDPropertyRaster("Posterior Raster", dodProb.PosteriorProbability));
DoDProperties.Add(new DoDPropertyRaster("Conditional Raster", dodProb.ConditionalRaster));
DoDProperties.Add(new DoDPropertyRaster("Surface Lowering Count", dodProb.SpatialCoherenceErosion));
DoDProperties.Add(new DoDPropertyRaster("Surface Raising Count", dodProb.SpatialCoherenceDeposition));
DoDProperties.Add(new GridViewPropertyValueItem("Spatial Coherence", string.Format("Bayesian updating with filter size of {0} X {0} cells", ((DoDProbabilistic)dod).SpatialCoherence.BufferSize)));
DoDProperties.Add(new GridViewRasterItem("Probability Raster", dodProb.PriorProbability));
DoDProperties.Add(new GridViewRasterItem("Posterior Raster", dodProb.PosteriorProbability));
DoDProperties.Add(new GridViewRasterItem("Conditional Raster", dodProb.ConditionalRaster));
DoDProperties.Add(new GridViewRasterItem("Surface Lowering Count", dodProb.SpatialCoherenceErosion));
DoDProperties.Add(new GridViewRasterItem("Surface Raising Count", dodProb.SpatialCoherenceDeposition));
}
}
}
DoDProperties.Add(new DoDPropertyRaster("Effective Threshold Surface", dod.ThrErr.Raster));
DoDProperties.Add(new GridViewRasterItem("Effective Threshold Surface", dod.ThrErr.Raster));

// Values from the thresholded DoD raster stats are optional
try
{
DoDProperties.Add(new DoDProperty("Output Raster Statistics"));
DoDProperties.Add(new GridViewPropertyValueItem("Output Raster Statistics"));
string vUnits = UnitsNet.Length.GetAbbreviation(ProjectManager.Project.Units.VertUnit);
dod.ThrDoD.Raster.ComputeStatistics();
Dictionary<string, decimal> stats = dod.ThrDoD.Raster.GetStatistics();
DoDProperties.Add(new DoDProperty("Thresholded DoD maximum raster value", stats["max"].ToString("n2") + vUnits));
DoDProperties.Add(new DoDProperty("Thresholded DoD minimum raster value", stats["min"].ToString("n2") + vUnits));
DoDProperties.Add(new DoDProperty("Thresholded DoD mean raster value", stats["mean"].ToString("n2") + vUnits));
DoDProperties.Add(new DoDProperty("Thresholded DoD standard deviation of raster values", stats["stddev"].ToString("n2") + vUnits));
DoDProperties.Add(new GridViewPropertyValueItem("Thresholded DoD maximum raster value", stats["max"].ToString("n2") + vUnits));
DoDProperties.Add(new GridViewPropertyValueItem("Thresholded DoD minimum raster value", stats["min"].ToString("n2") + vUnits));
DoDProperties.Add(new GridViewPropertyValueItem("Thresholded DoD mean raster value", stats["mean"].ToString("n2") + vUnits));
DoDProperties.Add(new GridViewPropertyValueItem("Thresholded DoD standard deviation of raster values", stats["stddev"].ToString("n2") + vUnits));
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Error calculating statistics from {0}, {1}", dod.ThrDoD.Raster.GISFileInfo.FullName, ex.Message));
}
}

private class DoDProperty
{
public string Property { get; protected set; }
public string Value { get; protected set; }
public readonly bool Header;

// Non-header cells are indented
public int LeftPadding { get { return Header ? 0 : 16; } }

/// <summary>
/// Default constructor required for grid binding
/// </summary>
public DoDProperty()
{

}

/// <summary>
/// Constructor for regular NON-HEADER items
/// </summary>
/// <param name="prop"></param>
/// <param name="value"></param>
public DoDProperty(string prop, string value)
{
Property = prop;
Value = value;
Header = false;
}

/// <summary>
/// Constructor for headers only
/// </summary>
/// <param name="header"></param>
public DoDProperty(string header)
{
Property = header;
Value = string.Empty;
Header = true;
}
}

private class DoDPropertyProjectItem : DoDProperty
{
public readonly GCDProjectItem ProjectItem;

public DoDPropertyProjectItem(string prop, string value, GCDProjectItem item)
: base(prop, value)
{
ProjectItem = item;
}

public DoDPropertyProjectItem(string prop, GCDProjectItem item)
: base(prop, string.Empty)
{
if (item is GCDProjectRasterItem)
Value = ProjectManager.Project.GetRelativePath(((GCDProjectRasterItem)item).Raster.GISFileInfo);
else if (item is GCDProjectVectorItem)
Value = ProjectManager.Project.GetRelativePath(((GCDProjectVectorItem)item).Vector.GISFileInfo);
}
}

private class DoDPropertyRaster : DoDProperty
{
public readonly GCDConsoleLib.Raster Raster;

public DoDPropertyRaster(string prop, string value, GCDConsoleLib.Raster raster)
: base(prop, value)
{
Raster = raster;
}

public DoDPropertyRaster(string prop, GCDConsoleLib.Raster raster)
: base(prop, string.Empty)
{
Raster = raster;
}
}

private void addToMapToolStripMenuItem_Click(object sender, EventArgs e)
{
if (grdData.SelectedRows.Count < 1)
return;

if (grdData.SelectedRows[0].DataBoundItem is DoDPropertyProjectItem)
if (grdData.SelectedRows[0].DataBoundItem is GridViewGCDProjectItem)
{
DoDPropertyProjectItem propItem = (DoDPropertyProjectItem)grdData.SelectedRows[0].DataBoundItem;
GridViewGCDProjectItem propItem = (GridViewGCDProjectItem)grdData.SelectedRows[0].DataBoundItem;
ProjectManager.AddNewProjectItemToMap(propItem.ProjectItem);
}
}

/// <summary>
/// Select the row that the user just right clicked on
/// </summary>
Expand Down
89 changes: 89 additions & 0 deletions GCDCore/UserInterface/GridViewPropertyValueItem.cs
@@ -0,0 +1,89 @@
using GCDCore.Project;
using System;

namespace GCDCore.UserInterface
{
/// <summary>
/// Class to manage the items put in a DataGridView that simply need a property and value pair.
/// </summary>
/// <remarks>
/// Header items have no value string and these are displayed in bold. Items with a value string
/// are indented by the software left indent setting</remarks>
public class GridViewPropertyValueItem
{
public string Property { get; protected set; }
public string Value { get; protected set; }
public readonly bool Header;

// Non-header cells are indented
public int LeftPadding { get { return Header ? 0 : GCDCore.Properties.Settings.Default.PropertyGridLeftIndent; } }

/// <summary>
/// Default constructor required for grid binding
/// </summary>
public GridViewPropertyValueItem()
{

}

/// <summary>
/// Constructor for regular NON-HEADER items
/// </summary>
/// <param name="prop"></param>
/// <param name="value"></param>
public GridViewPropertyValueItem(string prop, string value)
{
Property = prop;
Value = value;
Header = false;
}

/// <summary>
/// Constructor for headers only
/// </summary>
/// <param name="header"></param>
public GridViewPropertyValueItem(string header)
{
Property = header;
Value = string.Empty;
Header = true;
}
}

public class GridViewGCDProjectItem : GridViewPropertyValueItem
{
public readonly GCDProjectItem ProjectItem;

public GridViewGCDProjectItem(string prop, string value, GCDProjectItem item)
: base(prop, value)
{
ProjectItem = item;
}

public GridViewGCDProjectItem(string prop, GCDProjectItem item)
: base(prop, string.Empty)
{
if (item is GCDProjectRasterItem)
Value = ProjectManager.Project.GetRelativePath(((GCDProjectRasterItem)item).Raster.GISFileInfo);
else if (item is GCDProjectVectorItem)
Value = ProjectManager.Project.GetRelativePath(((GCDProjectVectorItem)item).Vector.GISFileInfo);
}
}

public class GridViewRasterItem : GridViewPropertyValueItem
{
public readonly GCDConsoleLib.Raster Raster;

public GridViewRasterItem(string prop, string value, GCDConsoleLib.Raster raster)
: base(prop, value)
{
Raster = raster;
}

public GridViewRasterItem(string prop, GCDConsoleLib.Raster raster)
: base(prop, string.Empty)
{
Raster = raster;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit db0d44f

Please sign in to comment.