// 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.Drawing;
using System.Linq;
using System.Windows.Forms;
using Core.Common.Base;
using Core.Common.Controls.TreeView;
using Core.Common.Gui.ContextMenu;
using Core.Common.Gui.Plugin;
using Ringtoets.Common.Data;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Forms.PresentationObjects;
using Ringtoets.Common.Forms.TreeNodeInfos;
using Ringtoets.GrassCoverErosionOutwards.Data;
using Ringtoets.GrassCoverErosionOutwards.Forms.PresentationObjects;
using Ringtoets.GrassCoverErosionOutwards.Forms.Properties;
using Ringtoets.GrassCoverErosionOutwards.Forms.PropertyClasses;
using Ringtoets.GrassCoverErosionOutwards.Forms.Views;
using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
namespace Ringtoets.GrassCoverErosionOutwards.Plugin
{
///
/// The plug-in for the .
///
public class GrassCoverErosionOutwardsPlugin : PluginBase
{
public override IEnumerable GetPropertyInfos()
{
yield return new PropertyInfo
{
GetObjectPropertiesData = context => context.WrappedData
};
yield return new PropertyInfo
{
GetObjectPropertiesData = context => context.Locations
};
yield return new PropertyInfo
{
GetObjectPropertiesData = context => context.Locations
};
}
public override IEnumerable GetViewInfos()
{
yield return new ViewInfo<
FailureMechanismSectionResultContext,
IEnumerable,
GrassCoverErosionOutwardsFailureMechanismResultView>
{
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 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()
};
yield return new TreeNodeInfo
{
Text = context => RingtoetsCommonDataResources.HydraulicBoundaryConditions_DisplayName,
Image = context => RingtoetsCommonFormsResources.GeneralFolderIcon,
ChildNodeObjects = nodeData => GetHydraulicBoundariesGroupContextChildNodeObjects(nodeData),
ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl)
.AddExportItem()
.AddSeparator()
.AddExpandAllItem()
.AddCollapseAllItem()
.Build()
};
yield return new TreeNodeInfo
{
Text = context => Resources.GrassCoverErosionOutwardsWaterLevelLocationsContext_DisplayName,
Image = context => RingtoetsCommonFormsResources.GenericInputOutputIcon,
ForeColor = context => context.WrappedData.HydraulicBoundaryDatabase == null ?
Color.FromKnownColor(KnownColor.GrayText) :
Color.FromKnownColor(KnownColor.ControlText),
ContextMenuStrip = GrassCoverErosionOutwardsWaterLevelLocationsContextMenuStrip
};
yield return new TreeNodeInfo
{
Text = context => Resources.GrassCoverErosionOutwardsWaveHeightLocationsContext_DisplayName,
Image = context => RingtoetsCommonFormsResources.GenericInputOutputIcon,
ForeColor = context => context.WrappedData.HydraulicBoundaryDatabase == null ?
Color.FromKnownColor(KnownColor.GrayText) :
Color.FromKnownColor(KnownColor.ControlText),
ContextMenuStrip = GrassCoverErosionOutwardsWaveHeightLocationsContextMenuStrip
};
}
#region ViewInfos
#region GrassCoverErosionOutwardsFailureMechanismResultView ViewInfo
private static bool CloseFailureMechanismResultViewForData(GrassCoverErosionOutwardsFailureMechanismResultView view, object o)
{
var assessmentSection = o as IAssessmentSection;
var failureMechanism = o as GrassCoverErosionOutwardsFailureMechanism;
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
#endregion
#region TreeNodeInfos
#region GrassCoverErosionOutwardsFailureMechanismContext TreeNodeInfo
private object[] FailureMechanismEnabledChildNodeObjects(GrassCoverErosionOutwardsFailureMechanismContext failureMechanismContext)
{
GrassCoverErosionOutwardsFailureMechanism failureMechanism = failureMechanismContext.WrappedData;
return new object[]
{
new CategoryTreeFolder(RingtoetsCommonFormsResources.FailureMechanism_Inputs_DisplayName, GetInputs(failureMechanism, failureMechanismContext.Parent), TreeFolderCategory.Input),
new HydraulicBoundariesGroupContext(failureMechanism, failureMechanismContext.Parent),
new CategoryTreeFolder(RingtoetsCommonFormsResources.FailureMechanism_Outputs_DisplayName, GetOutputs(failureMechanism), TreeFolderCategory.Output)
};
}
private object[] FailureMechanismDisabledChildNodeObjects(GrassCoverErosionOutwardsFailureMechanismContext failureMechanismContext)
{
return new object[]
{
new CommentContext(failureMechanismContext.WrappedData)
};
}
private static IList GetInputs(GrassCoverErosionOutwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection)
{
return new ArrayList
{
new FailureMechanismSectionsContext(failureMechanism, assessmentSection),
new ForeshoreProfilesContext(failureMechanism.ForeshoreProfiles, assessmentSection),
new CommentContext(failureMechanism)
};
}
private static IList GetOutputs(GrassCoverErosionOutwardsFailureMechanism failureMechanism)
{
return new ArrayList
{
new FailureMechanismSectionResultContext(failureMechanism.SectionResults, failureMechanism)
};
}
private ContextMenuStrip FailureMechanismEnabledContextMenuStrip(GrassCoverErosionOutwardsFailureMechanismContext grassCoverErosionOutwardsFailureMechanismContext, object parentData, TreeViewControl treeViewControl)
{
var builder = new RingtoetsContextMenuBuilder(Gui.Get(grassCoverErosionOutwardsFailureMechanismContext, treeViewControl));
return builder.AddToggleRelevancyOfFailureMechanismItem(grassCoverErosionOutwardsFailureMechanismContext, RemoveAllViewsForItem)
.AddSeparator()
.AddExpandAllItem()
.AddCollapseAllItem()
.AddSeparator()
.AddPropertiesItem()
.Build();
}
private void RemoveAllViewsForItem(GrassCoverErosionOutwardsFailureMechanismContext failureMechanismContext)
{
Gui.ViewCommands.RemoveAllViewsForItem(failureMechanismContext);
}
private ContextMenuStrip FailureMechanismDisabledContextMenuStrip(GrassCoverErosionOutwardsFailureMechanismContext grassCoverErosionOutwardsFailureMechanismContext, object parentData, TreeViewControl treeViewControl)
{
var builder = new RingtoetsContextMenuBuilder(Gui.Get(grassCoverErosionOutwardsFailureMechanismContext, treeViewControl));
return builder.AddToggleRelevancyOfFailureMechanismItem(grassCoverErosionOutwardsFailureMechanismContext, null)
.AddSeparator()
.AddExpandAllItem()
.AddCollapseAllItem()
.Build();
}
private object[] GetHydraulicBoundariesGroupContextChildNodeObjects(HydraulicBoundariesGroupContext hydraulicBoundariesGroupContext)
{
IAssessmentSection assessmentSection = hydraulicBoundariesGroupContext.AssessmentSection;
ObservableList locations = hydraulicBoundariesGroupContext.WrappedData.GrassCoverErosionOutwardsHydraulicBoundaryLocations;
return new object[]
{
new GrassCoverErosionOutwardsWaterLevelLocationsContext(assessmentSection, locations),
new GrassCoverErosionOutwardsWaveHeightLocationsContext(assessmentSection, locations)
};
}
#endregion
#region GrassCoverErosionOutwardsWaterLevelLocationsContext TreeNodeInfo
private ContextMenuStrip GrassCoverErosionOutwardsWaterLevelLocationsContextMenuStrip(GrassCoverErosionOutwardsWaterLevelLocationsContext nodeData, object parentData, TreeViewControl treeViewControl)
{
var designWaterLevelItem = new StrictContextMenuItem(
Resources.GrassCoverErosionOutwardsWaterLevelLocation_Calculate_All,
Resources.GrassCoverErosionOutwardsWaterLevelLocation_Calculate_All_ToolTip,
RingtoetsCommonFormsResources.CalculateAllIcon,
null);
designWaterLevelItem.Enabled = false;
if (nodeData.WrappedData.HydraulicBoundaryDatabase == null)
{
designWaterLevelItem.ToolTipText = Resources.GrassCoverErosionOutwardsWaterLevelLocation_No_HRD_To_Calculate;
}
return Gui.Get(nodeData, treeViewControl)
.AddCustomItem(designWaterLevelItem)
.AddSeparator()
.AddPropertiesItem()
.Build();
}
#endregion
#region GrassCoverErosionOutwardsWaveHeightLocationsContext TreeNodeInfo
private ContextMenuStrip GrassCoverErosionOutwardsWaveHeightLocationsContextMenuStrip(GrassCoverErosionOutwardsWaveHeightLocationsContext nodeData, object parentData, TreeViewControl treeViewControl)
{
var designWaterLevelItem = new StrictContextMenuItem(
RingtoetsCommonFormsResources.Calculate_all,
Resources.GrassCoverErosionOutwards_WaveHeight_Calculate_All_ToolTip,
RingtoetsCommonFormsResources.CalculateAllIcon,
null);
designWaterLevelItem.Enabled = false;
if (nodeData.WrappedData.HydraulicBoundaryDatabase == null)
{
designWaterLevelItem.ToolTipText = Resources.GrassCoverErosionOutwards_WaveHeight_No_HRD_To_Calculate;
}
return Gui.Get(nodeData, treeViewControl)
.AddCustomItem(designWaterLevelItem)
.AddSeparator()
.AddPropertiesItem()
.Build();
}
#endregion
#endregion
}
}