// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. // // Purpose: CommonElements class provides references to common // chart classes like DataManager, ChartTypeRegistry, // ImageLoader and others. It is passed to different // chart elements to simplify access to those common // classes. // using System; using System.ComponentModel.Design; using System.Globalization; using FastReport.DataVisualization.Charting.Borders3D; using FastReport.DataVisualization.Charting.ChartTypes; using FastReport.DataVisualization.Charting.Data; using FastReport.DataVisualization.Charting.Formulas; using FastReport.DataVisualization.Charting.Utilities; namespace FastReport.DataVisualization.Charting { /// /// CommonElements class provides references to common chart classes like /// DataManager, ChartTypeRegistry, ImageLoader and others. It is passed /// to different chart elements to simplify access to those common classes. /// internal class CommonElements { #region Fields private Chart _chart; private ChartImage _chartPicture; // Reference to Chart Graphics Object internal ChartGraphics graph = null; /// /// Service Container /// internal IServiceContainer container = null; /// /// Indicates painting mode /// internal bool processModePaint = true; /// /// Indicates selection mode /// internal bool processModeRegions = false; // Private Fields private int _width = 0; private int _height = 0; #endregion #region Properties /// /// Reference to the Data Manager /// internal DataManager DataManager { get { return (DataManager)container.GetService(typeof(DataManager)); } } /// /// True if painting mode is active /// public bool ProcessModePaint { get { return processModePaint; } } /// /// True if Hot region or image maps mode is active /// public bool ProcessModeRegions { get { return processModeRegions; } } /// /// Reference to the hot regions object /// public HotRegionsList HotRegionsList { get { return ChartPicture.hotRegionsList; } } /// /// Reference to the Data Manipulator /// public DataManipulator DataManipulator { get { return ChartPicture.DataManipulator; } } /// /// Reference to the ImageLoader /// internal ImageLoader ImageLoader { get { return (ImageLoader)container.GetService(typeof(ImageLoader)); } } /// /// Reference to the Chart /// internal Chart Chart { get { if (_chart==null) _chart = (Chart)container.GetService(typeof(Chart)); return _chart; } } /// /// Reference to the ChartTypeRegistry /// internal ChartTypeRegistry ChartTypeRegistry { get { return (ChartTypeRegistry)container.GetService(typeof(ChartTypeRegistry)); } } /// /// Reference to the BorderTypeRegistry /// internal BorderTypeRegistry BorderTypeRegistry { get { return (BorderTypeRegistry)container.GetService(typeof(BorderTypeRegistry)); } } /// /// Reference to the FormulaRegistry /// internal FormulaRegistry FormulaRegistry { get { return (FormulaRegistry)container.GetService(typeof(FormulaRegistry)); } } /// /// Reference to the ChartPicture /// internal ChartImage ChartPicture { get { if (_chartPicture ==null) _chartPicture = (ChartImage)container.GetService(typeof(ChartImage)); return _chartPicture; } } /// /// Width of the chart picture /// internal int Width { get { return _width; } set { _width = value; } } /// /// Height of the chart picture /// internal int Height { get { return _height; } set { _height = value; } } #endregion #region Methods /// /// Constructor /// /// Service container. internal CommonElements(IServiceContainer container) { this.container = container; } #endregion #region String convertion helper methods /// /// Converts string to double. /// /// String to convert. /// Double result. internal static double ParseDouble(string stringToParse) { return ParseDouble(stringToParse, false); } /// /// Converts string to double. /// /// String to convert. /// if set to true the exception thrown. /// Double result. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "System.Double.TryParse(System.String,System.Globalization.NumberStyles,System.IFormatProvider,System.Double@)")] internal static double ParseDouble(string stringToParse, bool throwException) { Double result = 0.0; if (throwException) { result = double.Parse(stringToParse, NumberStyles.Any, CultureInfo.InvariantCulture); } else { bool parseSucceed = double.TryParse(stringToParse, NumberStyles.Any, CultureInfo.InvariantCulture, out result); if (!parseSucceed) { double.TryParse(stringToParse, NumberStyles.Any, CultureInfo.CurrentCulture, out result); } } return result; } /// /// Converts string to double. /// /// String to convert. /// Double result. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "System.Single.TryParse(System.String,System.Globalization.NumberStyles,System.IFormatProvider,System.Single@)")] internal static float ParseFloat(string stringToParse) { float result = 0f; bool parseSucceed = float.TryParse(stringToParse, NumberStyles.Any, CultureInfo.InvariantCulture, out result); if (!parseSucceed) { float.TryParse(stringToParse, NumberStyles.Any, CultureInfo.CurrentCulture, out result); } return result; } #endregion } }