// 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.Common.Data;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Forms.Helpers;
using Ringtoets.Common.Forms.PresentationObjects;
using Ringtoets.Common.Forms.TreeNodeInfos;
using Ringtoets.HeightStructures.Data;
using Ringtoets.HeightStructures.Forms.PresentationObjects;
using Ringtoets.HeightStructures.Forms.Views;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources;
using HeightStructuresDataResources = Ringtoets.HeightStructures.Data.Properties.Resources;
using HeightStructuresFormsResources = Ringtoets.HeightStructures.Forms.Properties.Resources;
namespace Ringtoets.HeightStructures.Plugin
{
///
/// The GUI plug-in for the .
///
public class HeightStructuresGuiPlugin : GuiPlugin
{
public override IEnumerable GetViewInfos()
{
yield return new ViewInfo<
FailureMechanismSectionResultContext,
IEnumerable,
HeightStructuresFailureMechanismResultView
>
{
GetViewName = (v, o) => RingtoetsCommonDataResources.FailureMechanism_AssessmentResult_DisplayName,
Image = RingtoetsCommonFormsResources.FailureMechanismSectionResultIcon,
CloseForData = CloseFailureMechanismResultViewForData,
GetViewData = context => context.SectionResults,
AfterCreate = (view, context) => view.FailureMechanism = context.FailureMechanism
};
}
public override IEnumerable GetTreeNodeInfos()
{
yield return RingtoetsTreeNodeInfoFactory.CreateFailureMechanismContextTreeNodeInfo(
FailureMechanismEnabledChildNodeObjects,
FailureMechanismDisabledChildNodeObjects,
FailureMechanismEnabledContextMenuStrip,
FailureMechanismDisabledContextMenuStrip);
yield return RingtoetsTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(
CalculationGroupContextChildNodeObjects,
CalculationGroupContextContextMenuStrip,
CalculationGroupContextOnNodeRemoved);
yield return RingtoetsTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(
HeightStructuresFormsResources.CalculationIcon,
CalculationContextChildNodeObjects,
CalculationContextContextMenuStrip,
CalculationContextOnNodeRemoved);
yield return new TreeNodeInfo
{
Text = inputContext => HeightStructuresFormsResources.HeightStructuresInputContext_NodeDisplayName,
Image = inputContext => RingtoetsCommonFormsResources.GenericInputOutputIcon,
ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl)
.AddImportItem()
.AddExportItem()
.AddSeparator()
.AddPropertiesItem()
.Build()
};
yield return new TreeNodeInfo
{
Text = output => RingtoetsCommonFormsResources.CalculationOutput_DisplayName,
Image = output => RingtoetsCommonFormsResources.GeneralOutputIcon,
ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl)
.AddExportItem()
.AddSeparator()
.AddPropertiesItem()
.Build()
};
yield return RingtoetsTreeNodeInfoFactory.CreateEmptyProbabilisticOutputTreeNodeInfo(
EmptyProbabilisticOutputContextMenuStrip);
yield return new TreeNodeInfo>
{
Text = context => RingtoetsCommonDataResources.FailureMechanism_AssessmentResult_DisplayName,
Image = context => RingtoetsCommonFormsResources.FailureMechanismSectionResultIcon,
ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl)
.AddOpenItem()
.Build()
};
}
#region EmptyProbabilisticOutput TreeNodeInfo
private ContextMenuStrip EmptyProbabilisticOutputContextMenuStrip(EmptyProbabilisticOutput output, object parentData, TreeViewControl treeViewControl)
{
var builder = new RingtoetsContextMenuBuilder(Gui.Get(output, treeViewControl));
return builder.AddExportItem()
.AddSeparator()
.AddPropertiesItem()
.Build();
}
#endregion
#region HeightStructuresFailureMechanismResultView ViewInfo
private static bool CloseFailureMechanismResultViewForData(HeightStructuresFailureMechanismResultView view, object o)
{
var assessmentSection = o as IAssessmentSection;
var failureMechanism = o as HeightStructuresFailureMechanism;
var failureMechanismContext = o as IFailureMechanismContext;
if (assessmentSection != null)
{
return assessmentSection
.GetFailureMechanisms()
.OfType()
.Any(fm => ReferenceEquals(view.Data, fm.SectionResults));
}
if (failureMechanismContext != null)
{
failureMechanism = failureMechanismContext.WrappedData;
}
return failureMechanism != null && ReferenceEquals(view.Data, (failureMechanism).SectionResults);
}
#endregion
#region HeightStructuresFailureMechanismContext TreeNodeInfo
private object[] FailureMechanismEnabledChildNodeObjects(HeightStructuresFailureMechanismContext context)
{
HeightStructuresFailureMechanism wrappedData = context.WrappedData;
return new object[]
{
new CategoryTreeFolder(RingtoetsCommonFormsResources.FailureMechanism_Inputs_DisplayName, GetInputs(wrappedData, context.Parent), TreeFolderCategory.Input),
new HeightStructuresCalculationGroupContext(wrappedData.CalculationsGroup, wrappedData, context.Parent),
new CategoryTreeFolder(RingtoetsCommonFormsResources.FailureMechanism_Outputs_DisplayName, GetOutputs(wrappedData), TreeFolderCategory.Output)
};
}
private static IList GetInputs(HeightStructuresFailureMechanism failureMechanism, IAssessmentSection assessmentSection)
{
return new ArrayList
{
new FailureMechanismSectionsContext(failureMechanism, assessmentSection),
new CommentContext(failureMechanism)
};
}
private static IList GetOutputs(HeightStructuresFailureMechanism failureMechanism)
{
return new ArrayList
{
new FailureMechanismSectionResultContext(failureMechanism.SectionResults, failureMechanism)
};
}
private object[] FailureMechanismDisabledChildNodeObjects(HeightStructuresFailureMechanismContext context)
{
return new object[]
{
new CommentContext(context.WrappedData)
};
}
private ContextMenuStrip FailureMechanismEnabledContextMenuStrip(HeightStructuresFailureMechanismContext context, object parentData, TreeViewControl treeViewControl)
{
var builder = new RingtoetsContextMenuBuilder(Gui.Get(context, treeViewControl));
return builder.AddOpenItem()
.AddSeparator()
.AddToggleRelevancyOfFailureMechanismItem(context, RemoveAllViewsForItem)
.AddSeparator()
.AddPerformAllCalculationsInFailureMechanismItem(context, failureMechanismContext => { }, failureMechanismContext => "")
.AddClearAllCalculationOutputInFailureMechanismItem(context.WrappedData)
.AddSeparator()
.AddImportItem()
.AddExportItem()
.AddSeparator()
.AddExpandAllItem()
.AddCollapseAllItem()
.AddSeparator()
.AddPropertiesItem()
.Build();
}
private void RemoveAllViewsForItem(HeightStructuresFailureMechanismContext context)
{
Gui.ViewCommands.RemoveAllViewsForItem(context);
}
private ContextMenuStrip FailureMechanismDisabledContextMenuStrip(HeightStructuresFailureMechanismContext context, object parentData, TreeViewControl treeViewControl)
{
var builder = new RingtoetsContextMenuBuilder(Gui.Get(context, treeViewControl));
return builder.AddToggleRelevancyOfFailureMechanismItem(context, null)
.AddSeparator()
.AddExpandAllItem()
.AddCollapseAllItem()
.Build();
}
#endregion
#region HeightStructuresCalculationGroupContext TreeNodeInfo
private static object[] CalculationGroupContextChildNodeObjects(HeightStructuresCalculationGroupContext context)
{
var childNodeObjects = new List