// Copyright (C) Stichting Deltares 2023. 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; namespace Deltares.Dam.Data.UISupport; public class ConfigurationManager { private const int maxModelCount = 10; // #Bka added SpencerHigh/SpencerLow as quick fix. Should be reset to 8 private static ConfigurationStatus[,,] configurationStatus; /// /// Initializes a new instance of the class. /// public ConfigurationManager() { InitDefaultStatus(); } /// /// Indexer /// /// /// /// /// public ConfigurationStatus this[DamProjectType damProjectType, FailureMechanismSystemType failureMechanismSystemType, int i] { get { return configurationStatus[(int) damProjectType, (int) failureMechanismSystemType, i]; } set { configurationStatus[(int) damProjectType, (int) failureMechanismSystemType, i] = value; } } [field: ThreadStatic] public static ConfigurationManager Instance { get; } = new ConfigurationManager(); /// /// Gets the available dam project types. /// /// public ICollection GetAvailableDamProjectTypes() { return new[] { DamProjectType.Calamity, DamProjectType.Design }; } /// /// Gets the available failure mechanisms. /// /// Type of the dam project. /// public ICollection GetAvailableFailureMechanisms(DamProjectType damProjectType) { var availableList = new List(); foreach (FailureMechanismSystemType failureMechanismSystemType in Enum.GetValues(typeof(FailureMechanismSystemType))) { for (var i = 0; i < maxModelCount; i++) { if (this[damProjectType, failureMechanismSystemType, i] == ConfigurationStatus.Available) { availableList.Add(failureMechanismSystemType); break; } } } return availableList; } /// /// Gets the available mechanism models. /// /// Type of the dam project. /// Type of the failure mechanism system. /// public ICollection GetAvailableMechanismModels(DamProjectType damProjectType, FailureMechanismSystemType failureMechanismSystemType) { var availableList = new List(); for (var i = 0; i < maxModelCount; i++) { if (this[damProjectType, failureMechanismSystemType, i] == ConfigurationStatus.Available) { switch (failureMechanismSystemType) { case FailureMechanismSystemType.Piping: var pipingModeltype = (PipingModelType) i; availableList.Add(pipingModeltype); break; case FailureMechanismSystemType.StabilityInside: case FailureMechanismSystemType.StabilityOutside: availableList.Add((MStabModelType) i); break; } } } if (failureMechanismSystemType == FailureMechanismSystemType.StabilityInside) { object item = availableList[0]; availableList[0] = availableList[1]; availableList[1] = item; } return availableList; } private static int GetLength() where T : struct { return Enum.GetValues(typeof(T)).Length; } /// /// Inits the default status. /// private void InitDefaultStatus() { configurationStatus = new ConfigurationStatus[GetLength(), GetLength(), maxModelCount]; foreach (DamProjectType damProjectType in Enum.GetValues(typeof(DamProjectType))) { foreach (FailureMechanismSystemType failureMechanismSystemType in Enum.GetValues(typeof(FailureMechanismSystemType))) { for (var i = 0; i < maxModelCount; i++) { this[damProjectType, failureMechanismSystemType, i] = ConfigurationStatus.NotImplemented; } } } // This is the place to enable new possible failure mechanisms and models this[DamProjectType.Design, FailureMechanismSystemType.StabilityInside, (int) MStabModelType.Bishop] = ConfigurationStatus.Available; this[DamProjectType.Design, FailureMechanismSystemType.StabilityInside, (int) MStabModelType.UpliftVan] = ConfigurationStatus.Available; this[DamProjectType.Design, FailureMechanismSystemType.StabilityInside, (int) MStabModelType.BishopUpliftVan] = ConfigurationStatus.Available; this[DamProjectType.Design, FailureMechanismSystemType.StabilityOutside, (int) MStabModelType.Bishop] = ConfigurationStatus.Available; this[DamProjectType.Design, FailureMechanismSystemType.Piping, (int) PipingModelType.Sellmeijer] = ConfigurationStatus.Available; this[DamProjectType.Design, FailureMechanismSystemType.Piping, (int) PipingModelType.Sellmeijer2Forces] = ConfigurationStatus.NotAvailable; this[DamProjectType.Design, FailureMechanismSystemType.Piping, (int) PipingModelType.Sellmeijer4Forces] = ConfigurationStatus.Available; this[DamProjectType.Design, FailureMechanismSystemType.Piping, (int) PipingModelType.Bligh] = ConfigurationStatus.Available; this[DamProjectType.Design, FailureMechanismSystemType.Piping, (int) PipingModelType.Wti2017] = ConfigurationStatus.Available; this[DamProjectType.Calamity, FailureMechanismSystemType.StabilityInside, (int) MStabModelType.Bishop] = ConfigurationStatus.Available; this[DamProjectType.Calamity, FailureMechanismSystemType.StabilityInside, (int) MStabModelType.UpliftVan] = ConfigurationStatus.Available; this[DamProjectType.Calamity, FailureMechanismSystemType.StabilityOutside, (int) MStabModelType.Bishop] = ConfigurationStatus.Available; this[DamProjectType.Calamity, FailureMechanismSystemType.Piping, (int) PipingModelType.Sellmeijer] = ConfigurationStatus.Available; this[DamProjectType.Calamity, FailureMechanismSystemType.Piping, (int) PipingModelType.Sellmeijer4Forces] = ConfigurationStatus.Available; this[DamProjectType.Calamity, FailureMechanismSystemType.Piping, (int) PipingModelType.Bligh] = ConfigurationStatus.Available; this[DamProjectType.DamLiveConfiguration, FailureMechanismSystemType.StabilityInside, (int) MStabModelType.Bishop] = ConfigurationStatus.Available; this[DamProjectType.DamLiveConfiguration, FailureMechanismSystemType.StabilityInside, (int) MStabModelType.UpliftVan] = ConfigurationStatus.Available; this[DamProjectType.DamLiveConfiguration, FailureMechanismSystemType.Piping, (int) PipingModelType.Wti2017] = ConfigurationStatus.Available; } }