// 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 dike profile locations and text files containing dike schematizations.
///
public class DikeProfilesImporter : ProfilesImporter>
{
///
/// Creates a new instance of .
///
/// The dike 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 DikeProfilesImporter(ObservableList importTarget, ReferenceLine referenceLine, string filePath)
: base(referenceLine, filePath, importTarget) {}
protected override void CreateProfiles(ReadResult importProfileLocationResult,
ReadResult importDikeProfileDataResult)
{
IEnumerable importedDikeProfiles = CreateDikeProfiles(importProfileLocationResult.ImportedItems,
importDikeProfileDataResult.ImportedItems);
foreach (DikeProfile dikeProfile in importedDikeProfiles)
{
ImportTarget.Add(dikeProfile);
}
}
protected override void HandleUserCancellingImport()
{
log.Info(Resources.DikeProfilesImporter_HandleUserCancellingImport_dikeprofile_import_aborted);
base.HandleUserCancellingImport();
}
protected override bool DikeProfileDataIsValid(DikeProfileData data, string prflFilePath)
{
if (data.DikeGeometry.Any())
{
return true;
}
log.WarnFormat(Resources.DikeProfilesImporter_No_dike_geometry_file_0_skipped, prflFilePath);
return false;
}
private IEnumerable CreateDikeProfiles(IEnumerable dikeProfileLocationCollection,
ICollection dikeProfileDataCollection)
{
var dikeProfiles = new List();
foreach (ProfileLocation dikeProfileLocation in dikeProfileLocationCollection)
{
string id = dikeProfileLocation.Id;
var dikeProfileData = GetMatchingDikeProfileData(dikeProfileDataCollection, id);
if (dikeProfileData == null)
{
log.ErrorFormat(Resources.DikeProfilesImporter_GetMatchingDikeProfileData_no_dikeprofiledata_for_location_0_, id);
}
else
{
DikeProfile dikeProfile = CreateDikeProfile(dikeProfileLocation, dikeProfileData);
dikeProfiles.Add(dikeProfile);
}
}
return dikeProfiles;
}
private static DikeProfile CreateDikeProfile(ProfileLocation dikeProfileLocation, DikeProfileData dikeProfileData)
{
var dikeProfile = new DikeProfile(dikeProfileLocation.Point, dikeProfileData.DikeGeometry,
dikeProfileData.ForeshoreGeometry.Select(fg => fg.Point).ToArray(),
CreateBreakWater(dikeProfileData),
new DikeProfile.ConstructionProperties
{
Name = dikeProfileData.Id,
X0 = dikeProfileLocation.Offset,
Orientation = dikeProfileData.Orientation,
DikeHeight = dikeProfileData.DikeHeight
});
return dikeProfile;
}
}
}