// 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.Windows.Forms; using Core.Common.Base; using Core.Components.Charting.Data; using Core.Components.Charting.Forms; using Ringtoets.Piping.Data; using Ringtoets.Piping.Forms.Properties; namespace Ringtoets.Piping.Forms.Views { /// /// This class is a view to show the piping input. /// public partial class PipingInputView : UserControl, IChartView, IObserver { private PipingInput data; private PipingCalculationScenario calculation; private ChartData surfaceLineData; /// /// Creates a new instance of . /// public PipingInputView() { InitializeComponent(); } /// /// Gets or sets the calculation the input belongs to. /// public PipingCalculationScenario Calculation { get { return calculation; } set { DetachFromData(); calculation = value; SetChartTitle(); AttachToData(); } } public object Data { get { return data; } set { var newValue = value as PipingInput; DetachFromData(); data = newValue; SetDataToChart(); AttachToData(); } } public IChartControl Chart { get { return chartControl; } } public void UpdateObserver() { SetChartTitle(); SetDataToChart(); } private void SetChartTitle() { if (calculation != null) { chartControl.ChartTitle = calculation.Name; } } private void SetDataToChart() { if (data != null) { surfaceLineData = AddOrUpdateChartData(surfaceLineData, GetSurfaceLineChartData()); } chartControl.Data.NotifyObservers(); } private ChartData GetSurfaceLineChartData() { if (data == null || data.SurfaceLine == null) { return PipingChartDataFactory.CreateEmptyLineData(Resources.RingtoetsPipingSurfaceLine_DisplayName); } return PipingChartDataFactory.Create(data.SurfaceLine); } private ChartData AddOrUpdateChartData(ChartData oldChartData, ChartData newChartData) { if (oldChartData != null) { chartControl.Data.Remove(oldChartData); } if (newChartData != null) { chartControl.Data.Add(newChartData); } return newChartData; } private void DetachFromData() { if (calculation != null) { calculation.Detach(this); } if (data != null) { data.Detach(this); } } private void AttachToData() { if (calculation != null) { calculation.Attach(this); } if (data != null) { data.Attach(this); } } } }