Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -rec15ff35b39f333c422b8ca6988c34bd8573f134 -r16ffb4842cab4a8c457638eef546fd87bea3f0f6 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision ec15ff35b39f333c422b8ca6988c34bd8573f134) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 16ffb4842cab4a8c457638eef546fd87bea3f0f6) @@ -83,7 +83,9 @@ using Ringtoets.Integration.Service.MessageProviders; using Ringtoets.Piping.Data; using Ringtoets.Piping.Forms.PresentationObjects; +using Ringtoets.Revetment.Data; using Ringtoets.Revetment.Forms.PresentationObjects; +using Ringtoets.Revetment.Forms.Views; using Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityPointStructures.Forms.PresentationObjects; using Ringtoets.StabilityStoneCover.Data; @@ -398,6 +400,14 @@ Image = RingtoetsCommonFormsResources.EditDocumentIcon, CloseForData = CloseCommentViewForData }; + + yield return new ViewInfo + { + Image = RingtoetsCommonFormsResources.GenericInputOutputIcon, + GetViewName = (view, context) => RingtoetsCommonFormsResources.Calculation_Input, + GetViewData = context => context.Calculation, + CloseForData = CloseWaveConditionsInputViewForData + }; } public override IEnumerable GetImportInfos() @@ -770,6 +780,30 @@ } } + private class FailureMechanismContextAssociation + { + private readonly Func createFailureMechanismContext; + private readonly Type failureMechanismType; + + public FailureMechanismContextAssociation(Type failureMechanismType, Func createFailureMechanismContext) + { + this.createFailureMechanismContext = createFailureMechanismContext; + this.failureMechanismType = failureMechanismType; + } + + public bool Match(IFailureMechanism failureMechanism) + { + return failureMechanism.GetType() == failureMechanismType; + } + + public object Create(IFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + { + return createFailureMechanismContext(failureMechanism, assessmentSection); + } + } + + #region ViewInfos + #region FailureMechanismView ViewInfo private static bool CloseFailureMechanismViewForData(FailureMechanismView view, object o) @@ -851,39 +885,204 @@ #endregion - #region FailureMechanismSectionsContext TreeNodeInfo + #region Comment ViewInfo - private ContextMenuStrip FailureMechanismSectionsContextMenuStrip(FailureMechanismSectionsContext nodeData, object parentData, TreeViewControl treeViewControl) + private static bool CloseCommentViewForData(CommentView commentView, object o) { - return Gui.Get(nodeData, treeViewControl) - .AddImportItem() - .Build(); + var calculationGroupContext = o as ICalculationContext; + if (calculationGroupContext != null) + { + return GetCommentElements(calculationGroupContext.WrappedData) + .Any(commentElement => ReferenceEquals(commentView.Data, commentElement)); + } + + var calculationContext = o as ICalculationContext; + var calculation = calculationContext?.WrappedData as ICalculation; + if (calculation != null) + { + return ReferenceEquals(commentView.Data, calculation.Comments); + } + + var failureMechanism = o as IFailureMechanism; + + var failureMechanismContext = o as IFailureMechanismContext; + if (failureMechanismContext != null) + { + failureMechanism = failureMechanismContext.WrappedData; + } + + if (failureMechanism != null) + { + return GetCommentElements(failureMechanism) + .Any(commentElement => ReferenceEquals(commentView.Data, commentElement)); + } + + var assessmentSection = o as IAssessmentSection; + if (assessmentSection != null) + { + return GetCommentElements(assessmentSection) + .Any(commentElement => ReferenceEquals(commentView.Data, commentElement)); + } + + return false; } + private static IEnumerable GetCommentElements(CalculationGroup calculationGroup) + { + return calculationGroup.GetCalculations().Select(c => c.Comments); + } + + private static IEnumerable GetCommentElements(IAssessmentSection assessmentSection) + { + yield return assessmentSection.Comments; + foreach (Comment comment in assessmentSection.GetFailureMechanisms().SelectMany(GetCommentElements)) + { + yield return comment; + } + } + + private static IEnumerable GetCommentElements(IFailureMechanism failureMechanism) + { + yield return failureMechanism.InputComments; + yield return failureMechanism.OutputComments; + yield return failureMechanism.NotRelevantComments; + foreach (ICalculation calculation in failureMechanism.Calculations) + { + yield return calculation.Comments; + } + } + #endregion - private class FailureMechanismContextAssociation + #region WaveConditionsInputViewInfo + + private static bool CloseWaveConditionsInputViewForData(WaveConditionsInputView view, object o) { - private readonly Func createFailureMechanismContext; - private readonly Type failureMechanismType; + var context = o as WaveConditionsInputContext; + if (context != null) + { + return ReferenceEquals(view.Data, context.Calculation); + } + var calculation = o as IWaveConditionsCalculation; + if (calculation != null) + { + return ReferenceEquals(view.Data, calculation); + } - public FailureMechanismContextAssociation(Type failureMechanismType, Func createFailureMechanismContext) + IEnumerable calculations = GetCalculationsFromCalculationGroupContexts(o); + + IEnumerable failureMechanismCalculations = GetCalculationsFromFailureMechanisms(o); + if (failureMechanismCalculations != null) { - this.createFailureMechanismContext = createFailureMechanismContext; - this.failureMechanismType = failureMechanismType; + calculations = failureMechanismCalculations; } - public bool Match(IFailureMechanism failureMechanism) + return calculations != null && calculations.Any(c => ReferenceEquals(view.Data, c)); + } + + private static IEnumerable GetCalculationsFromFailureMechanisms(object o) + { + IEnumerable grassCoverErosionOutwardsCalculations = GetCalculationsFromFailureMechanism< + GrassCoverErosionOutwardsFailureMechanismContext, + GrassCoverErosionOutwardsFailureMechanism>(o); + + if (grassCoverErosionOutwardsCalculations != null && grassCoverErosionOutwardsCalculations.Any()) { - return failureMechanism.GetType() == failureMechanismType; + return grassCoverErosionOutwardsCalculations; } - public object Create(IFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + IEnumerable stabilityStoneCoverCalculations = GetCalculationsFromFailureMechanism< + StabilityStoneCoverFailureMechanismContext, + StabilityStoneCoverFailureMechanism>(o); + + if (stabilityStoneCoverCalculations != null && stabilityStoneCoverCalculations.Any()) { - return createFailureMechanismContext(failureMechanism, assessmentSection); + return stabilityStoneCoverCalculations; } + + IEnumerable waveImpactAsphaltCoverCalculations = GetCalculationsFromFailureMechanism< + WaveImpactAsphaltCoverFailureMechanismContext, + WaveImpactAsphaltCoverFailureMechanism>(o); + + return waveImpactAsphaltCoverCalculations; } + private static IEnumerable GetCalculationsFromFailureMechanism(object o) + where TContext : class, IFailureMechanismContext + where TFailureMechanism : class, IFailureMechanism + { + IEnumerable calculations = null; + + var failureMechanism = o as TFailureMechanism; + + var context = o as TContext; + if (context != null) + { + failureMechanism = context.WrappedData; + } + + var assessmentSection = o as IAssessmentSection; + if (assessmentSection != null) + { + failureMechanism = assessmentSection.GetFailureMechanisms() + .OfType() + .FirstOrDefault(); + } + + if (failureMechanism != null) + { + calculations = (IEnumerable)failureMechanism.Calculations; + } + + return calculations; + } + + private static IEnumerable GetCalculationsFromCalculationGroupContexts(object o) + { + IEnumerable calculations = null; + + var grassCoverErosionOutwardsCalculationGroupContext = o as GrassCoverErosionOutwardsWaveConditionsCalculationGroupContext; + if (grassCoverErosionOutwardsCalculationGroupContext != null) + { + calculations = grassCoverErosionOutwardsCalculationGroupContext.WrappedData + .GetCalculations() + .OfType(); + } + var stabilityStoneCoverCalculationGroupContext = o as StabilityStoneCoverWaveConditionsCalculationGroupContext; + if (stabilityStoneCoverCalculationGroupContext != null) + { + calculations = stabilityStoneCoverCalculationGroupContext.WrappedData + .GetCalculations() + .OfType(); + } + var waveImpactAsphaltCoverCalculationGroupContext = o as WaveImpactAsphaltCoverWaveConditionsCalculationGroupContext; + if (waveImpactAsphaltCoverCalculationGroupContext != null) + { + calculations = waveImpactAsphaltCoverCalculationGroupContext.WrappedData + .GetCalculations() + .OfType(); + } + + return calculations; + } + + #endregion + + #endregion + + #region TreeNodeInfos + + #region FailureMechanismSectionsContext TreeNodeInfo + + private ContextMenuStrip FailureMechanismSectionsContextMenuStrip(FailureMechanismSectionsContext nodeData, object parentData, TreeViewControl treeViewControl) + { + return Gui.Get(nodeData, treeViewControl) + .AddImportItem() + .Build(); + } + + #endregion + #region BackgroundData treeNodeInfo private ContextMenuStrip BackgroundDataMenuStrip(BackgroundData nodeData, object parentData, TreeViewControl treeViewControl) @@ -1010,75 +1209,6 @@ #endregion - #region Comment ViewInfo - - private static bool CloseCommentViewForData(CommentView commentView, object o) - { - var calculationGroupContext = o as ICalculationContext; - if (calculationGroupContext != null) - { - return GetCommentElements(calculationGroupContext.WrappedData) - .Any(commentElement => ReferenceEquals(commentView.Data, commentElement)); - } - - var calculationContext = o as ICalculationContext; - var calculation = calculationContext?.WrappedData as ICalculation; - if (calculation != null) - { - return ReferenceEquals(commentView.Data, calculation.Comments); - } - - var failureMechanism = o as IFailureMechanism; - - var failureMechanismContext = o as IFailureMechanismContext; - if (failureMechanismContext != null) - { - failureMechanism = failureMechanismContext.WrappedData; - } - - if (failureMechanism != null) - { - return GetCommentElements(failureMechanism) - .Any(commentElement => ReferenceEquals(commentView.Data, commentElement)); - } - - var assessmentSection = o as IAssessmentSection; - if (assessmentSection != null) - { - return GetCommentElements(assessmentSection) - .Any(commentElement => ReferenceEquals(commentView.Data, commentElement)); - } - - return false; - } - - private static IEnumerable GetCommentElements(CalculationGroup calculationGroup) - { - return calculationGroup.GetCalculations().Select(c => c.Comments); - } - - private static IEnumerable GetCommentElements(IAssessmentSection assessmentSection) - { - yield return assessmentSection.Comments; - foreach (Comment comment in assessmentSection.GetFailureMechanisms().SelectMany(GetCommentElements)) - { - yield return comment; - } - } - - private static IEnumerable GetCommentElements(IFailureMechanism failureMechanism) - { - yield return failureMechanism.InputComments; - yield return failureMechanism.OutputComments; - yield return failureMechanism.NotRelevantComments; - foreach (ICalculation calculation in failureMechanism.Calculations) - { - yield return calculation.Comments; - } - } - - #endregion - #region AssessmentSection TreeNodeInfo private static object[] AssessmentSectionChildNodeObjects(AssessmentSection nodeData) @@ -1534,5 +1664,7 @@ } #endregion + + #endregion } } \ No newline at end of file