Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/WaterBoardPostProcessRelativeProfiles.cs =================================================================== diff -u -r6436 -r6823 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/WaterBoardPostProcessRelativeProfiles.cs (.../WaterBoardPostProcessRelativeProfiles.cs) (revision 6436) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/WaterBoardPostProcessRelativeProfiles.cs (.../WaterBoardPostProcessRelativeProfiles.cs) (revision 6823) @@ -48,95 +48,92 @@ public static void CreateAbsoluteProfiles(WaterBoard waterBoard, CharacteristicPointType characteristicPointType) { const double moveAccuracy = 1e-6; - foreach (Dike dike in waterBoard.Dikes) + foreach (Location location in waterBoard.Dike.Locations) { - foreach (Location location in dike.Locations) + Segment orgSegment = location.Segment; + if (orgSegment != null) { - Segment orgSegment = location.Segment; - if (orgSegment != null) + double topSurfaceline = location.SurfaceLine2.CharacteristicPoints.Geometry.GetMaxZ(); + GeometryPoint characteristicGeometryPoint = location.SurfaceLine2.CharacteristicPoints.GetGeometryPoint(characteristicPointType); + var errorFound = false; + var newSegment = new Segment(); + newSegment.Name = $"Segment {orgSegment.Name}-{location.Name}"; + var soilProbabilityIndex = 0; + foreach (SoilGeometryProbability orgSoilGeometryProbability in orgSegment.SoilProfileProbabilities) { - double topSurfaceline = location.SurfaceLine2.CharacteristicPoints.Geometry.GetMaxZ(); - GeometryPoint characteristicGeometryPoint = location.SurfaceLine2.CharacteristicPoints.GetGeometryPoint(characteristicPointType); - var errorFound = false; - var newSegment = new Segment(); - newSegment.Name = $"Segment {orgSegment.Name}-{location.Name}"; - var soilProbabilityIndex = 0; - foreach (SoilGeometryProbability orgSoilGeometryProbability in orgSegment.SoilProfileProbabilities) + soilProbabilityIndex++; + try { - soilProbabilityIndex++; - try + if (characteristicGeometryPoint == null) { - if (characteristicGeometryPoint == null) - { - throw new WaterBoardPostProcessRelativeProfilesException($"Characteristic point {characteristicPointType} is not defined"); - } + throw new WaterBoardPostProcessRelativeProfilesException($"Characteristic point {characteristicPointType} is not defined"); + } - if (orgSoilGeometryProbability.SoilProfileType.Equals(SoilProfileType.SoilProfile2D)) - { - throw new WaterBoardPostProcessRelativeProfilesException("Cannot apply relative profiles for 2d soilprofiles"); - } + if (orgSoilGeometryProbability.SoilProfileType.Equals(SoilProfileType.SoilProfile2D)) + { + throw new WaterBoardPostProcessRelativeProfilesException("Cannot apply relative profiles for 2d soilprofiles"); + } - // Create a copy of the original SoilGeometryProbability - var newSoilGeometryProbability = new SoilGeometryProbability(); - newSoilGeometryProbability.Assign(orgSoilGeometryProbability); + // Create a copy of the original SoilGeometryProbability + var newSoilGeometryProbability = new SoilGeometryProbability(); + newSoilGeometryProbability.Assign(orgSoilGeometryProbability); - // Move all layer boundaries so toplevel of the soilprofile1D will be at level of specified characteristic point - // Dependent if deltaZ is positive or negative, the bottomLevel should be adjusted before or after adjusting the layers - // This is necessary, because the bottomlevel is adjusted automatically during adjustment of layers - SoilProfile1D soilProfile1D = newSoilGeometryProbability.SoilProfile; - soilProfile1D.Name = $"{orgSoilGeometryProbability.SoilProfile.Name}-{location.Name}-{soilProbabilityIndex}"; - double deltaZ = characteristicGeometryPoint.Z - soilProfile1D.TopLevel; - if (deltaZ < 0) - { - soilProfile1D.BottomLevel += deltaZ; - } + // Move all layer boundaries so toplevel of the soilprofile1D will be at level of specified characteristic point + // Dependent if deltaZ is positive or negative, the bottomLevel should be adjusted before or after adjusting the layers + // This is necessary, because the bottomlevel is adjusted automatically during adjustment of layers + SoilProfile1D soilProfile1D = newSoilGeometryProbability.SoilProfile; + soilProfile1D.Name = $"{orgSoilGeometryProbability.SoilProfile.Name}-{location.Name}-{soilProbabilityIndex}"; + double deltaZ = characteristicGeometryPoint.Z - soilProfile1D.TopLevel; + if (deltaZ < 0) + { + soilProfile1D.BottomLevel += deltaZ; + } - foreach (SoilLayer1D soilLayer1D in soilProfile1D.Layers) - { - soilLayer1D.TopLevel += deltaZ; - } + foreach (SoilLayer1D soilLayer1D in soilProfile1D.Layers) + { + soilLayer1D.TopLevel += deltaZ; + } - if (deltaZ > 0) - { - soilProfile1D.BottomLevel += deltaZ; - } + if (deltaZ > 0) + { + soilProfile1D.BottomLevel += deltaZ; + } - double profileTopLevel = soilProfile1D.TopLevel; - // If the top of the profile is moved below the top of the surface level, a gap appears which will be filled in later in the UI - // to the combined 2D. However, for Piping calculation the 1D profile itself needs to start at least at the top of the surface line - // too in order to perform a correct calculation. So extend the 1D profile here too! - if (Math.Abs(deltaZ) > moveAccuracy && profileTopLevel < topSurfaceline) + double profileTopLevel = soilProfile1D.TopLevel; + // If the top of the profile is moved below the top of the surface level, a gap appears which will be filled in later in the UI + // to the combined 2D. However, for Piping calculation the 1D profile itself needs to start at least at the top of the surface line + // too in order to perform a correct calculation. So extend the 1D profile here too! + if (Math.Abs(deltaZ) > moveAccuracy && profileTopLevel < topSurfaceline) + { + var newTopLayer = new SoilLayer1D { - var newTopLayer = new SoilLayer1D - { - SoilProfile = soilProfile1D, - MaintainLayerOrder = true, - TopLevel = topSurfaceline, - IsAquifer = false, - Soil = dike.SoilList.GetSoilByName(location.DikeEmbankmentMaterial) - }; - soilProfile1D.Layers.Insert(0, newTopLayer); - } - - // Add new SoilGeometryProbability to new segment and assign new segment to location - newSegment.SoilProfileProbabilities.Add(newSoilGeometryProbability); - // Add new soil profile to existing list. - dike.SoilProfiles.Add(soilProfile1D); + SoilProfile = soilProfile1D, + MaintainLayerOrder = true, + TopLevel = topSurfaceline, + IsAquifer = false, + Soil = waterBoard.Dike.SoilList.GetSoilByName(location.DikeEmbankmentMaterial) + }; + soilProfile1D.Layers.Insert(0, newTopLayer); } - catch (Exception e) - { - errorFound = true; - LogManager.Messages.Add(new LogMessage(LogMessageType.Error, location, - $"Error in location '{location.Name}' applying relative height for soilprofile '{orgSoilGeometryProbability.SoilGeometryName}': {e.Message} ")); - } - } - if (!errorFound) + // Add new SoilGeometryProbability to new segment and assign new segment to location + newSegment.SoilProfileProbabilities.Add(newSoilGeometryProbability); + // Add new soil profile to existing list. + waterBoard.Dike.SoilProfiles.Add(soilProfile1D); + } + catch (Exception e) { - location.Segment = newSegment; - waterBoard.Segments.Add(newSegment); + errorFound = true; + LogManager.Messages.Add(new LogMessage(LogMessageType.Error, location, + $"Error in location '{location.Name}' applying relative height for soilprofile '{orgSoilGeometryProbability.SoilGeometryName}': {e.Message} ")); } } + + if (!errorFound) + { + location.Segment = newSegment; + waterBoard.Segments.Add(newSegment); + } } } }