Skip to content

Commit

Permalink
user interface handling of multi-part, null geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
philipbaileynar committed Nov 6, 2018
1 parent 16ddd46 commit f360279
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 25 deletions.
11 changes: 5 additions & 6 deletions GCDAddIn/Project/btnOpenProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ protected override void OnClick()
{
try
{
GCDCore.Project.ProjectManager.OpenProject(new System.IO.FileInfo(f.FileName));
GCDCore.Properties.Settings.Default.LastUsedProjectFolder = System.IO.Path.GetDirectoryName(f.FileName);
GCDCore.Properties.Settings.Default.Save();

btnProjectExplorer.ShowProjectExplorer(true);
if (GCDCore.Project.ProjectManager.OpenProject(new System.IO.FileInfo(f.FileName)))
{
btnProjectExplorer.ShowProjectExplorer(true);
}
}
catch (Exception ex)
{
MessageBox.Show(string.Format("Error reading the GCD project file '{0}'. Ensure that the file is a valid GCD project file with valid and complete XML contents.\n\n{1}", f.FileName, ex.Message), GCDCore.Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
GCDCore.GCDException.HandleException(ex);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions GCDConsoleLib/Vector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public override void Open(bool write = false)
{
Exception ex = new Exception("Could not open shapefile. Null dataset detected.");
ex.Data["File Path"] = GISFileInfo.FullName;
ex.Data["MultiPart"] = "true";
throw ex;
}
_drv = _ds.GetDriver();
Expand Down Expand Up @@ -451,7 +450,7 @@ private void _load(bool leaveopen = false)
{
Exception ex = new Exception("Multi-part geometries are detected in this file. This is not allowed.");
ex.Data["File Path"] = GISFileInfo.FullName;
ex.Data["MultiPart"] = "true";
ex.Data["Solution"] = "Remove all multipart features from this ShapeFile.";
throw ex;
}
else
Expand Down
40 changes: 30 additions & 10 deletions GCDCore/Project/ProjectManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;

namespace GCDCore.Project
{
Expand Down Expand Up @@ -93,21 +94,40 @@ public static void CreateProject(GCDProject project)
Project = project;
}

public static void OpenProject(FileInfo projectFile)
public static bool OpenProject(FileInfo projectFile)
{
Project = GCDProject.Load(projectFile);
}
bool success = false;

public static void RefreshProject()
{
Project = GCDProject.Load(Project.ProjectFile);
}
try
{
Project = GCDProject.Load(projectFile);
Properties.Settings.Default.LastUsedProjectFolder = Path.GetDirectoryName(projectFile.FullName);
Properties.Settings.Default.Save();
success = true;
}
catch (Exception ex)
{
success = false;

public static void OpenProject(GCDProject project)
{
Project = project;
string msg = string.Format("Failed to open the GCD project file:\n\n{0}", projectFile.FullName);

if (ex.Data.Contains("File Path"))
{
msg += string.Format("\n\n{0}\n\n{1}", ex.Message, ex.Data["File Path"]);
}

if (ex.Data.Contains("Solution"))
{
msg += string.Format("\n\n{0}",ex.Data["Solution"]);
}

MessageBox.Show(msg, Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
}

return success;
}


public static void CloseCurrentProject()
{
Project = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void OnRefresh(object sender, EventArgs e)
}
catch (Exception ex)
{
GCDException.HandleException(ex, "Error Editing GCD Project Item");
GCDException.HandleException(ex, "Error refreshing GCD project explorer tree.");
}
}

Expand Down
21 changes: 21 additions & 0 deletions GCDCore/UserInterface/SurveyLibrary/GISDatasetValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,26 @@ public static bool DSHorizUnitsMatchProject(GISDataset gisDS, string sTypeSingle
return true;
}

public static bool DSGeometryTypeMatches(Vector vectorDS, GDalGeometryType.SimpleTypes eGeometryType)
{
if (vectorDS.GeometryType.SimpleType != eGeometryType)
{
string requiredTypeName = string.Empty;
switch(eGeometryType)
{
case GDalGeometryType.SimpleTypes.Point: requiredTypeName = "point"; break;
case GDalGeometryType.SimpleTypes.LineString: requiredTypeName = "line";break;
case GDalGeometryType.SimpleTypes.Polygon: requiredTypeName = "polygon"; break;
default:
throw new Exception("Unhandled geometry type");
}

MessageBox.Show(string.Format("The selected feature class does not contain {0} geometry features. Please choose a {0} ShapeFile.", requiredTypeName),
"Geometry Type Mismatch", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}

return true;
}
}
}
7 changes: 4 additions & 3 deletions GCDCore/UserInterface/SurveyLibrary/frmPointDensity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ private bool ValidateForm()

if (ucPointCloud.SelectedItem is GCDConsoleLib.Vector)
{
if (!UserInterface.SurveyLibrary.GISDatasetValidation.DSHasSpatialRef(ucPointCloud.SelectedItem, "feature class", "feature classes") ||
!UserInterface.SurveyLibrary.GISDatasetValidation.DSSpatialRefMatchesProjectWithMsgbox(ucPointCloud.SelectedItem, "feature class", "feature classes") ||
!UserInterface.SurveyLibrary.GISDatasetValidation.DSHorizUnitsMatchProject(ucPointCloud.SelectedItem, "feature class", "feature classes"))
if (!GISDatasetValidation.DSHasSpatialRef(ucPointCloud.SelectedItem, "feature class", "feature classes") ||
!GISDatasetValidation.DSSpatialRefMatchesProjectWithMsgbox(ucPointCloud.SelectedItem, "feature class", "feature classes") ||
!GISDatasetValidation.DSHorizUnitsMatchProject(ucPointCloud.SelectedItem, "feature class", "feature classes") ||
!GISDatasetValidation.DSGeometryTypeMatches((Vector) ucPointCloud.SelectedItem, GDalGeometryType.SimpleTypes.Point))
{
ucPointCloud.Select();
return false;
Expand Down
6 changes: 3 additions & 3 deletions GCDStandalone/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void openGCDProjectToolStripMenuItem_Click(object sender, EventArgs e)
}
catch (Exception ex)
{
MessageBox.Show(string.Format("Error reading the GCD project file '{0}'. Ensure that the file is a valid GCD project file with valid and complete XML contents.\n\n{1}", f.FileName, ex.Message), GCDCore.Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
GCDCore.GCDException.HandleException(ex);
}
}

Expand All @@ -217,8 +217,8 @@ private void OpenGCDProject(string gcdProject)
{
// Set the project file path first (which will attempt to read the XML file and throw an error if anything goes wrong)
// Then set the settings if the read was successful.
ProjectManager.OpenProject(new System.IO.FileInfo(gcdProject));
GCDCore.Properties.Settings.Default.LastUsedProjectFolder = System.IO.Path.GetDirectoryName(gcdProject);
if (!ProjectManager.OpenProject(new System.IO.FileInfo(gcdProject)))
return;

try
{
Expand Down

0 comments on commit f360279

Please sign in to comment.