// Copyright (C) Stichting Deltares 2019. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI 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; using System.Collections.Generic; using System.Linq; using Deltares.Dam.Data; using Deltares.Geotechnics; using Deltares.Geotechnics.Soils; using Deltares.Geotechnics.SurfaceLines; using Deltares.Standard.Forms; using Deltares.Standard.Forms.DExpress; using Deltares.Standard.Reflection; namespace Deltares.Dam.Forms { public class DamContext: GeotechnicsContext { private bool wti = true; private Dictionary>> filters = new Dictionary>>(); private const string LocationScenarioInsideStability = "InsideStabilityScenarioCategory"; private const string LocationScenarioPiping = "PipingScenarioCategory"; private const string LocationScenarioPlLineSchematization = "PlLineSchematizationScenarioCategory"; public bool Wti { get { return wti; } set { wti = value; } } public DamContext() { SetUpFilterDictionary(); } private void SetUpFilterDictionary() { var locationScenarioFilter = new Dictionary>(); filters[typeof(Scenario)] = locationScenarioFilter; locationScenarioFilter.Add(LocationScenarioInsideStability, new List { StaticReflection.GetMemberName(x => x.LocationScenarioID), StaticReflection.GetMemberName(x => x.RiverLevel), StaticReflection.GetMemberName(x => x.DikeTableHeight), StaticReflection.GetMemberName(x => x.RequiredSafetyFactorStabilityInnerSlope), StaticReflection.GetMemberName(x => x.HeadPl3), StaticReflection.GetMemberName(x => x.HeadPl4), StaticReflection.GetMemberName(x => x.PolderLevel), StaticReflection.GetMemberName(x => x.HeadPl2) }); locationScenarioFilter.Add(LocationScenarioPiping, new List { StaticReflection.GetMemberName(x => x.LocationScenarioID), StaticReflection.GetMemberName(x => x.RiverLevel), StaticReflection.GetMemberName(x => x.DikeTableHeight), StaticReflection.GetMemberName(x => x.RequiredSafetyFactorPiping), StaticReflection.GetMemberName(x => x.HeadPl3), StaticReflection.GetMemberName(x => x.HeadPl4), StaticReflection.GetMemberName(x => x.PolderLevel), StaticReflection.GetMemberName(x => x.HeadPl2) }); locationScenarioFilter.Add(LocationScenarioPlLineSchematization, new List { StaticReflection.GetMemberName(x => x.LocationScenarioID), StaticReflection.GetMemberName(x => x.RiverLevel), StaticReflection.GetMemberName(x => x.PlLineOffsetBelowDikeTopAtRiver), StaticReflection.GetMemberName(x => x.PlLineOffsetBelowDikeTopAtPolder), StaticReflection.GetMemberName(x => x.PlLineOffsetBelowShoulderBaseInside), StaticReflection.GetMemberName(x => x.PlLineOffsetBelowDikeToeAtPolder), StaticReflection.GetMemberName(x => x.PlLineOffsetBelowDikeCrestMiddle), StaticReflection.GetMemberName(x => x.PlLineOffsetFactorBelowShoulderCrest), StaticReflection.GetMemberName(x => x.UsePlLineOffsetBelowDikeCrestMiddle), StaticReflection.GetMemberName(x => x.UsePlLineOffsetFactorBelowShoulderCrest), StaticReflection.GetMemberName(x => x.PolderLevel), }); } /// /// Returns the possible named filters for a given type. /// /// A type for which named filters will be returned. /// A of the named filters or null if no named filters exists. public IEnumerable GetColumnNamedFilters(Type type) { if (filters.ContainsKey(type)) { return filters[type].Keys.ToArray(); } return null; } /// /// Returns a list of visible properties for a type and a named filter returned by . /// /// A type for which named filters are defined. /// One of the named filters for this type. /// A list of visible properties. public IList GetFilteredColumns(Type type, string value) { if (filters.ContainsKey(type) && filters[type].ContainsKey(value)) { return filters[type][value]; } return null; } /// /// Method indicating a visibility override value for a given instance object. /// /// Object being evaluated. /// Name of the member which is part of . /// /// True if visible; False if hidden; Null if no override. /// public override bool? IsVisible(object source, string member) { var locationScenariosControl = source as LocationScenariosControl; if (null != locationScenariosControl) { if (member == StaticReflection.GetMemberName(x => x.SelectedContextFilter)) { return locationScenariosControl.HasItems; } } if (source is SoilList) { switch (member) { case "Soils" : return Wti; } } if (source is Location && member == StaticReflection.GetMemberName(x => x.SurfaceLine2)) { return false; } if (source is Location && member == StaticReflection.GetMemberName(x => x.LocalXZSurfaceLine2)) { return true; } // Make sure unwanted operations are hidden for the surface line grid for now. var grid = source as GridViewControl; if (grid != null) { if ((member == "AddRowCommand" || member == "DeleteRowCommand" || member == "PasteCommand" || member == "EditCommand") && (grid.Name == "SurfaceLinePointsGridControl")) { return false; } } if (source is VisualValidationResult) { // Make sure that for DAM, all repairers are not used. var vr = (VisualValidationResult) source; vr.Repairer = null; } return base.IsVisible(source, member); } /// /// Method indicating if the enabled override value for a given instance object. /// /// Object being evaluated. /// Name of the member which is part of . /// /// True if enabled; False if disabled; Null if no override. /// public override bool? IsEnabled(object source, string member) { // Make sure CharacteristicPoints can not be edited for now. if (source is CharacteristicPoint) { if (member == StaticReflection.GetMemberName(x => x.X) || member == StaticReflection.GetMemberName(x => x.Y) || member == StaticReflection.GetMemberName(x => x.Z)) { return false; } return true; } if (source is Soil && member != StaticReflection.GetMemberName(x => x.StrengthIncreaseExponent)) { return false; } var specification = source as DamProjectCalculationSpecification; if (specification != null) { if (member == "SelectedStabilityKernelType") { return Wti; } } return base.IsEnabled(source, member); } /// /// Returns a collection of allowed values for a property as part of the IDomain interface. /// This is used for populating drop down values in a drop down list. /// Note that this isn’t necessary when the property is defined as an enumeration. /// All enumeration values are used by default. /// /// The name of the property for which to return the possible values. /// /// A containing the possible values for the given property. /// public override ICollection GetDomain(string property) { if (property == "CharacteristicPointType") { return new List { CharacteristicPointType.SurfaceLevelOutside, CharacteristicPointType.DikeToeAtRiver, CharacteristicPointType.ShoulderTopOutside, CharacteristicPointType.ShoulderBaseOutside, CharacteristicPointType.DikeTopAtRiver, CharacteristicPointType.TrafficLoadOutside, CharacteristicPointType.TrafficLoadInside, CharacteristicPointType.DikeTopAtPolder, CharacteristicPointType.ShoulderBaseInside, CharacteristicPointType.ShoulderTopInside, CharacteristicPointType.DikeToeAtPolder, CharacteristicPointType.DitchDikeSide, CharacteristicPointType.BottomDitchDikeSide, CharacteristicPointType.BottomDitchPolderSide, CharacteristicPointType.DitchPolderSide, CharacteristicPointType.SurfaceLevelInside, CharacteristicPointType.None, }; } return base.GetDomain(property); } } }