Beispiel #1
0
        /// <summary>
        /// Processes signal and returns a sequence of strings to print on screen
        /// </summary>
        /// <param name="signal"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        private IEnumerable <string> ProcessSignal(IPhasorDomainSignal signal, string unit)
        {
            // For each phasor in the signal
            foreach (var phasor in signal.Phasors)
            {
                // Start with description of the source
                var infoString = "Source: \"" + phasor.Key.Label.Label + "\" produces ";

                // Then, depending on the category
                switch (phasor.Key.FrequencyCategory)
                {
                case FrequencyCategory.DC:
                {
                    infoString += SIHelpers.ToAltSIStringExcludingSmallPrefixes(phasor.Value, unit, _RoundToDigit) + " DC";
                } break;

                case FrequencyCategory.AC:
                {
                    infoString += SIHelpers.ToAltSIStringExcludingSmallPrefixes(phasor.Value, unit, _RoundToDigit) + " AC";
                }
                break;
                }

                yield return(infoString);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Converts a <see cref="Complex"/> to an SIString, if parameter is a <see cref="string"/> uses it as the unit
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value is Complex c)
            {
                return(SIHelpers.ToAltSIStringExcludingSmallPrefixes(c, (parameter as string) ?? string.Empty, imaginaryAsJ: true));
            }

            return(string.Empty);
        }
            /// <summary>
            /// Converts a number to SIString using <see cref="CSharpEnhanced.Helpers.SIHelpers.ToS"/>
            /// </summary>
            /// <param name="value"></param>
            /// <param name="targetType"></param>
            /// <param name="parameter"></param>
            /// <param name="language"></param>
            /// <returns></returns>
            public object Convert(object value, Type targetType, object parameter, string language)
            {
                if (MathsHelpers.TryCastToDouble(value, out var result))
                {
                    return(_ExcludeSmallPrefixes ?
                           SIHelpers.ToSIStringExcludingSmallPrefixes(result, _Unit, _RoundToDigit, _MidpointRounding, _UseFullName) :
                           SIHelpers.ToSIString(result, _Unit, _RoundToDigit, _MidpointRounding, _UseFullName));
                }

                if (value is Complex c)
                {
                    return(_ExcludeSmallPrefixes ?
                           SIHelpers.ToAltSIStringExcludingSmallPrefixes(c, _Unit, _RoundToDigit, _MidpointRounding, _UseFullName) :
                           SIHelpers.ToAltSIString(c, _Unit, _RoundToDigit, _MidpointRounding, _UseFullName));
                }

                return(0);
            }