using System; using System.Collections.Generic; using System.ComponentModel; using System.Xml.Serialization; using Deltares.Standard; using Deltares.Standard.Attributes; using Deltares.Standard.EventPublisher; using DotSpatial.Projections; namespace Deltares.Dam.Data.UISupport { public class DAMNewProjectData : IVisibleEnabled { private DamProjectType damProjectType; private string damDataSourceFileName; private string damProjectFileName; private string sensorConfigurationFileName; private DamType damType = DamType.Primary; private List selectedDikeRingIds = new List(); private string dataSourceEsriProjection; private string dataSourceProjectionName; private bool dataSourceProjectionUserDefined; [Label("Calculation type")] [Description("Indicates the purpose of the calculations")] [XmlIgnore] public DamProjectType DamProjectType { get { return damProjectType; } set { DataEventPublisher.BeforeChange(this, "DamProjectType"); damProjectType = value; DataEventPublisher.AfterChange(this, "DamProjectType"); } } [Label("DAM datasource file")] [Description("Indicates which \".defx\" import definition file to use")] [XmlIgnore] public string DamDataSourceFileName { get { return damDataSourceFileName; } set { DataEventPublisher.BeforeChange(this, "DamDataSourceFileName"); damDataSourceFileName = value; DataEventPublisher.AfterChange(this, "DamDataSourceFileName"); } } [XmlIgnore] public string SensorConfigurationFileName { get { return sensorConfigurationFileName; } set { DataEventPublisher.BeforeChange(this, "SensorConfigurationFileName"); sensorConfigurationFileName = value; DataEventPublisher.AfterChange(this, "SensorConfigurationFileName"); } } [XmlIgnore] public string DamProjectFileName { get { return damProjectFileName; } set { DataEventPublisher.BeforeChange(this, "DamProjectFileName"); damProjectFileName = value; DataEventPublisher.AfterChange(this, "DamProjectFileName"); } } [Label("Dike type")] [Description("Indicates the type of dike")] [XmlIgnore] public DamType DamType { get { return damType; } set { DataEventPublisher.BeforeChange(this, "DamType"); damType = value; DataEventPublisher.AfterChange(this, "DamType"); } } [XmlIgnore] public string DataSourceEsriProjection { get { return dataSourceEsriProjection; } set { DataEventPublisher.BeforeChange(this, "DataSourceEsriProjection"); dataSourceEsriProjection = value; DataEventPublisher.AfterChange(this, "DataSourceEsriProjection"); try { var projection = ProjectionInfo.FromEsriString(value); DataSourceProjectionName = projection.Name ?? projection.ToString(); } catch (Exception) { DataSourceProjectionName = "Invalid projection"; } } } [XmlIgnore] [ReadOnly(true)] public string DataSourceProjectionName { get { return dataSourceProjectionName; } set { DataEventPublisher.BeforeChange(this, "DataSourceProjectionName"); dataSourceProjectionName = value; DataEventPublisher.AfterChange(this, "DataSourceProjectionName"); } } /// /// Selects the sensor configuration file. /// [Label("...")] public void SelectSensorConfigurationFile() { // This method is needed for the databinding to DamNewProjectDialog // The IsEnabled is implemented in this class // The UI code itself is implemented in the DamNewProjectDialog itself } /// /// Selects the projection. /// public void SelectProjection() { // This method is needed for the databinding to DamNewProjectDialog // The IsEnabled is implemented in this class // The UI code itself is implemented in the DamNewProjectDialog itself } public List SelectedDikeRingIds { get { return selectedDikeRingIds; } set { selectedDikeRingIds = value; } } public bool DataSourceProjectionUserDefined { get { return dataSourceProjectionUserDefined; } set { dataSourceProjectionUserDefined = value; } } public bool IsVisible(string property) { if (property == "SelectProjection") { return (string.IsNullOrEmpty(DataSourceEsriProjection) || DataSourceProjectionUserDefined); } return true; } public bool IsEnabled(string property) { if ((property == "SensorConfigurationFileName") || (property == "SelectSensorConfigurationFile")) { return (DamProjectType == DamProjectType.DamLiveConfiguration); } return true; } } }