// Copyright (C) Stichting Deltares 2018. 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.ComponentModel; using System.Windows.Forms; using Deltares.Dam.Data; using Deltares.Standard; using Deltares.Standard.Attributes; using Deltares.Standard.Calculate; using Deltares.Standard.EventPublisher; using Deltares.Standard.Forms; using Deltares.Standard.Forms.DExpress; namespace Deltares.Dam.Forms { public partial class WaterBoardPropertyControl : UserControl, IPropertyControl, IVisibleEnabled { private WaterBoard waterBoard; public WaterBoardPropertyControl() { InitializeComponent(); this.Name = "WaterBoard"; BindSupport.BindTextAndValue(this, this.NumberOfDikesLabel, this.NumberOfDikesTextEdit, typeof(WaterBoard), "NumberOfDikes"); BindSupport.BindTextAndValue(this, this.WaterLevelTimeSeriesFileNameLabel, this.WaterLevelTimeSeriesFileNameEdit, typeof(WaterBoard), "WaterLevelTimeSeriesFileName"); BindSupport.Bind(this.TimeSeriesGroupControl, this.FileSelectButton, this.GetType(), "BrowseTimeSeries"); FormsSupport.RepairRightAnchoredControls(this); FormsSupport.AdjustSizeToContents(this.TimeSeriesGroupControl); DataEventPublisher.OnAfterChange += DataEventPublisher_OnAfterChange; LocalizationSupport.Register(typeof(WaterBoard), this.CalculationGroup, this.groupControl1); BindSupport.Assign(this.TimeSeriesGroupControl, this); } private void DataEventPublisher_OnAfterChange(object sender, PublishEventArgs e) { if (this.InvokeRequired) { this.Invoke(new DataEventPublisherEventDelegate(this.DataEventPublisher_OnAfterChange), sender, e); } else { if (sender is CalculationManager) { bool running = ((CalculationManager)sender).IsRunning; this.CalculationGroup.Visible = running; if (!running) { this.CalculationProgressBar.EditValue = 0; } } else if (sender == waterBoard) { DataEventPublisher.AfterChange(this); } } } #region IPropertyControl Members public object SelectedObject { get { return waterBoard; } set { if (value is DamProjectData) { if (waterBoard != value) { waterBoard = ((DamProjectData)value).WaterBoard; this.CalculationGroup.Visible = false; } } else if (value is WaterBoard) { if (waterBoard != value) { waterBoard = value as WaterBoard; this.CalculationGroup.Visible = false; } } else if (value is DamJob) { if (value is WaterBoardJob) { if (waterBoard != ((WaterBoardJob)value).Subject) { waterBoard = ((WaterBoardJob) value).Subject as WaterBoard; this.CalculationGroup.Visible = false; } } } BindSupport.Assign(this, waterBoard); } } public bool IsVisible { get { return true; } } #endregion public void DoProgress(double progress) { if (this.InvokeRequired) { this.Invoke(new ProgressDelegate(this.DoProgress), progress); } else { this.CalculationProgressBar.EditValue = Math.Round(100 * progress); if (!this.CalculationGroup.Visible && progress < 1) { this.CalculationGroup.Visible = true; } this.Refresh(); } } [Label("...")] [Description("Browse for time series file")] private void BrowseTimeSeries() { this.SelectFileDialog.FileName = waterBoard.WaterLevelTimeSeriesFileName; if (this.SelectFileDialog.ShowDialog() == DialogResult.OK) { waterBoard.WaterLevelTimeSeriesFileName = this.SelectFileDialog.FileName; } } public bool IsEnabled(string property) { return true; } bool IVisibleEnabled.IsVisible(string property) { switch (property) { case "BrowseTimeSeries": return Data.Location.DamProjectType == DamProjectType.Calamity; default : return true; } } } }