// 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.Collections; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using Core.Common.Controls.TreeView; using Core.Common.Gui.Plugin; using Ringtoets.Asphalt.Data; using Ringtoets.Asphalt.Forms.PresentationObjects; using Ringtoets.Asphalt.Forms.PropertyClasses; using Ringtoets.Asphalt.Forms.Views; using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.TreeNodeInfos; using Ringtoets.Integration.Plugin.FileImporters; using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources; using RingtoetsIntegrationPluginResources = Ringtoets.Integration.Plugin.Properties.Resources; namespace Ringtoets.Asphalt.Plugin { /// /// The plug-in for the . /// public class WaveImpactAsphaltCoverPlugin : PluginBase { public override IEnumerable GetPropertyInfos() { yield return new PropertyInfo(); } public override IEnumerable GetViewInfos() { yield return new ViewInfo, IEnumerable, WaveImpactAsphaltCoverFailureMechanismResultView> { GetViewName = (v, o) => RingtoetsCommonFormsResources.FailureMechanism_AssessmentResult_DisplayName, Image = RingtoetsCommonFormsResources.FailureMechanismSectionResultIcon, CloseForData = CloseFailureMechanismResultViewForData, GetViewData = context => context.WrappedData, AfterCreate = (view, context) => view.FailureMechanism = context.FailureMechanism }; } public override IEnumerable GetImportInfos() { yield return new ImportInfo { CreateFileImporter = (context, filePath) => new ForeshoreProfilesImporter(context.WrappedData, context.ParentAssessmentSection.ReferenceLine, filePath), Name = RingtoetsIntegrationPluginResources.ForeshoreProfilesImporter_DisplayName, Category = RingtoetsCommonFormsResources.Ringtoets_Category, Image = RingtoetsIntegrationPluginResources.Foreshore, FileFilter = RingtoetsCommonIOResources.DataTypeDisplayName_shape_file_filter, IsEnabled = context => context.ParentAssessmentSection.ReferenceLine != null }; } public override IEnumerable GetTreeNodeInfos() { yield return RingtoetsTreeNodeInfoFactory.CreateFailureMechanismContextTreeNodeInfo( FailureMechanismEnabledChildNodeObjects, FailureMechanismDisabledChildNodeObjects, FailureMechanismEnabledContextMenuStrip, FailureMechanismDisabledContextMenuStrip); yield return new TreeNodeInfo> { Text = context => RingtoetsCommonFormsResources.FailureMechanism_AssessmentResult_DisplayName, Image = context => RingtoetsCommonFormsResources.FailureMechanismSectionResultIcon, ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl) .AddOpenItem() .Build() }; } #region ViewInfos #region FailureMechanismSectionResultContext private static bool CloseFailureMechanismResultViewForData(WaveImpactAsphaltCoverFailureMechanismResultView view, object dataToCloseFor) { var viewData = view.Data; var assessmentSection = dataToCloseFor as IAssessmentSection; var failureMechanism = dataToCloseFor as WaveImpactAsphaltCoverFailureMechanism; var failureMechanismContext = dataToCloseFor as IFailureMechanismContext; if (assessmentSection != null) { return assessmentSection .GetFailureMechanisms() .OfType() .Any(fm => ReferenceEquals(viewData, fm.SectionResults)); } if (failureMechanismContext != null) { failureMechanism = failureMechanismContext.WrappedData; } return failureMechanism != null && ReferenceEquals(view.Data, failureMechanism.SectionResults); } #endregion #endregion #region TreeNodeInfos #region WaveImpactAsphaltCoverFailureMechanismContext private object[] FailureMechanismEnabledChildNodeObjects(WaveImpactAsphaltCoverFailureMechanismContext failureMechanismContext) { WaveImpactAsphaltCoverFailureMechanism wrappedData = failureMechanismContext.WrappedData; return new object[] { new CategoryTreeFolder(RingtoetsCommonFormsResources.FailureMechanism_Inputs_DisplayName, GetInputs(wrappedData, failureMechanismContext.Parent), TreeFolderCategory.Input), new CategoryTreeFolder(RingtoetsCommonFormsResources.FailureMechanism_Outputs_DisplayName, GetOutputs(wrappedData), TreeFolderCategory.Output) }; } private object[] FailureMechanismDisabledChildNodeObjects(WaveImpactAsphaltCoverFailureMechanismContext failureMechanismContext) { return new object[] { new CommentContext(failureMechanismContext.WrappedData) }; } private static IList GetInputs(WaveImpactAsphaltCoverFailureMechanism failureMechanism, IAssessmentSection assessmentSection) { return new ArrayList { new FailureMechanismSectionsContext(failureMechanism, assessmentSection), new ForeshoreProfilesContext(failureMechanism.ForeshoreProfiles, assessmentSection), new CommentContext(failureMechanism) }; } private IList GetOutputs(WaveImpactAsphaltCoverFailureMechanism failureMechanism) { return new ArrayList { new FailureMechanismSectionResultContext(failureMechanism.SectionResults, failureMechanism) }; } private ContextMenuStrip FailureMechanismEnabledContextMenuStrip(WaveImpactAsphaltCoverFailureMechanismContext failureMechanismContext, object parentData, TreeViewControl treeViewControl) { var builder = new RingtoetsContextMenuBuilder(Gui.Get(failureMechanismContext, treeViewControl)); return builder.AddToggleRelevancyOfFailureMechanismItem(failureMechanismContext, RemoveAllViewsForItem) .AddSeparator() .AddExpandAllItem() .AddCollapseAllItem() .AddSeparator() .AddPropertiesItem() .Build(); } private void RemoveAllViewsForItem(WaveImpactAsphaltCoverFailureMechanismContext failureMechanismContext) { Gui.ViewCommands.RemoveAllViewsForItem(failureMechanismContext); } private ContextMenuStrip FailureMechanismDisabledContextMenuStrip(WaveImpactAsphaltCoverFailureMechanismContext failureMechanismContext, object parentData, TreeViewControl treeViewControl) { var builder = new RingtoetsContextMenuBuilder(Gui.Get(failureMechanismContext, treeViewControl)); return builder.AddToggleRelevancyOfFailureMechanismItem(failureMechanismContext, null) .AddSeparator() .AddExpandAllItem() .AddCollapseAllItem() .Build(); } #endregion #endregion } }