// Copyright (C) Stichting Deltares 2016. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections.Generic; using System.Linq; using Core.Common.Base; using Core.Common.IO.Readers; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.IO.DikeProfiles; using Ringtoets.Common.IO.Properties; namespace Ringtoets.Common.IO.FileImporters { /// /// Imports point shapefiles containing foreshore locations and text file containing the foreshore schematizations. /// public class ForeshoreProfilesImporter : ProfilesImporter> { /// /// Creates a new instance of . /// /// The foreshore profiles to import on. /// The reference line used to check if the /// objects found in the file are intersecting it. /// The path to the file to import from. /// Thrown when , /// or is null. public ForeshoreProfilesImporter(ObservableList importTarget, ReferenceLine referenceLine, string filePath) : base(referenceLine, filePath, importTarget) {} protected override void CreateProfiles(ReadResult importProfileLocationResult, ReadResult importDikeProfileDataResult) { IEnumerable importedForeshoreProfiles = CreateForeshoreProfiles(importProfileLocationResult.ImportedItems, importDikeProfileDataResult.ImportedItems); foreach (ForeshoreProfile foreshoreProfile in importedForeshoreProfiles) { ImportTarget.Add(foreshoreProfile); } } protected override void HandleUserCancellingImport() { log.Info(Resources.ForeshoreProfilesImporter_HandleUserCancellingImport_foreshoreprofile_import_aborted); base.HandleUserCancellingImport(); } protected override bool DikeProfileDataIsValid(DikeProfileData data, string prflFilePath) { if (data.DamType != DamType.None || data.ForeshoreGeometry.Any()) { return true; } log.WarnFormat(Resources.ForeshoreProfilesImporter_No_dam_no_foreshore_geometry_file_0_skipped, prflFilePath); return false; } private IEnumerable CreateForeshoreProfiles(ICollection dikeProfileLocationCollection, ICollection dikeProfileDataCollection) { var foreshoreProfiles = new List(); foreach (ProfileLocation dikeProfileLocation in dikeProfileLocationCollection) { string id = dikeProfileLocation.Id; var dikeProfileData = GetMatchingDikeProfileData(dikeProfileDataCollection, id); if (dikeProfileData == null) { log.ErrorFormat(Resources.ForeshoreProfilesImporter_GetMatchingForeshoreProfileData_no_foreshoreprofiledata_for_location_0_, id); } else { ForeshoreProfile foreshoreProfile = CreateForeshoreProfile(dikeProfileLocation, dikeProfileData); foreshoreProfiles.Add(foreshoreProfile); } } return foreshoreProfiles; } private static ForeshoreProfile CreateForeshoreProfile(ProfileLocation dikeProfileLocation, DikeProfileData dikeProfileData) { var foreshoreProfile = new ForeshoreProfile(dikeProfileLocation.Point, dikeProfileData.ForeshoreGeometry.Select(fg => fg.Point).ToArray(), CreateBreakWater(dikeProfileData), new ForeshoreProfile.ConstructionProperties { Name = dikeProfileData.Id, X0 = dikeProfileLocation.Offset, Orientation = dikeProfileData.Orientation }); return foreshoreProfile; } } }