Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamProject.cs
===================================================================
diff -u -r2414 -r2429
--- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamProject.cs (.../DamProject.cs) (revision 2414)
+++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamProject.cs (.../DamProject.cs) (revision 2429)
@@ -590,18 +590,17 @@
/// and reference to the map is set to it
///
/// the filename of the project
- /// The org project map in case of file save as; used to determine original location for 2d-geometries
- public void EnsureGeometries2DMapWithProject(string fileName, string orgProjectMap)
+ /// The org project map in case of file save as.
+ /// The directory in which the .defx file resides.
+ private void EnsureGeometries2DMapWithProject(string fileName, string projectDirectory, string dataSourceDirectory)
{
for (int dikeIndex = 0; dikeIndex < damProjectData.WaterBoard.Dikes.Count; dikeIndex++)
{
if (!String.IsNullOrEmpty(damProjectData.WaterBoard.Dikes[dikeIndex].MapForSoilGeometries2D))
{
- string sourceMapName = damProjectData.WaterBoard.Dikes[dikeIndex].MapForSoilGeometries2D;
- if (!Directory.Exists(sourceMapName))
- {
- sourceMapName = Path.Combine(orgProjectMap, sourceMapName);
- }
+ string mapForSoilGeometries = damProjectData.WaterBoard.Dikes[dikeIndex].MapForSoilGeometries2D;
+ string sourceMapName = DetermineGeometriesSource(mapForSoilGeometries, projectDirectory, dataSourceDirectory);
+
// Only copy files if map of geometries is assigned and exists
if (!String.IsNullOrEmpty(sourceMapName) && Directory.Exists(sourceMapName))
{
@@ -623,7 +622,24 @@
}
}
}
+
+ ///
+ /// Determines from which folder the soil geometry definitions should be retrieved from.
+ ///
+ /// The directory of the soil geometries as specified by the .defx file
+ /// The directory of the .damx project file.
+ /// The directory of the .defx file.
+ /// The directory of where the soil geometries reside.
+ private static string DetermineGeometriesSource(string soilGeometryDirectory, string projectDirectory, string dataSourceDirectory)
+ {
+ if (Directory.Exists(soilGeometryDirectory))
+ {
+ return soilGeometryDirectory;
+ }
+ var directory = Path.Combine(projectDirectory, soilGeometryDirectory);
+ return Directory.Exists(directory) ? directory : Path.Combine(dataSourceDirectory, soilGeometryDirectory);
+ }
///
/// Create a destination filename for new location of soilmaterials database
@@ -681,17 +697,25 @@
///
public void SaveXMLProject(string fileName, object project)
{
+ var damProject = project as DamProject;
+ string dataSourceFolder = null;
+ if (damProject != null)
+ {
+ dataSourceFolder = Path.GetDirectoryName(damProject.DamProjectData.DamDataSourceFileName);
+ }
+
fileName = Path.ChangeExtension(fileName, "damx");
- string orgProjectMap = ProjectMap;
+ string savedProjectMap = ProjectMap;
ProjectFileName = fileName;
- if (orgProjectMap == null)
+ if (savedProjectMap == null)
{
- orgProjectMap = ProjectMap;
+ savedProjectMap = ProjectMap;
}
+
DataEventPublisher.InvokeWithoutPublishingEvents(() =>
{
EnsureSoilmaterialsFileWithProject(fileName);
- EnsureGeometries2DMapWithProject(fileName, orgProjectMap);
+ EnsureGeometries2DMapWithProject(fileName, savedProjectMap, dataSourceFolder);
var xmlSerializer = new XmlSerializer();
xmlSerializer.Serialize(damProjectData, fileName);