/// <summary>
        /// Initialize a new instance of the class.
        /// </summary>
        /// <param name="scalarControl">The <c>WatchControl</c> derived user control that called this form.</param>
        public FormChangeScalar(WatchScalarControl scalarControl) : base(scalarControl)
        {
            InitializeComponent();
            Debug.Assert(m_WatchVariable != null, "FormChangeScalar.Ctor() - [m_WatchVariable != null]");
            Debug.Assert(m_WatchVariable.VariableType == VariableType.Scalar, "FormChangeScalar.Ctor() - [m_WatchVariable.VariableType == VariableType.Scalar]");

            if (m_WatchVariable.FormatString.ToLower() == FormatStringHexadecimal)
            {
                m_HexFormat = true;
            }

            #region - [NumericUpDown] -
            if (m_HexFormat == true)
            {
                m_NumericUpDownNewValue.Hexadecimal = true;

                m_NumericUpDownNewValue.DecimalPlaces = 0;
                m_NumericUpDownNewValue.Increment     = 1;
            }
            else
            {
                m_NumericUpDownNewValue.Hexadecimal = false;

                // Evaluate the DecimalPlaces and Increment properties associated with the NumericUpDown control based upon the watch variable scale-factor.
                double  scaleFactor = m_WatchVariable.ScaleFactor;
                int     decimalPlaces;
                decimal increment;
                General.GetDecimalPlaces(scaleFactor, out decimalPlaces);
                General.GetIncrement(scaleFactor, out increment);

                m_NumericUpDownNewValue.DecimalPlaces = decimalPlaces;
                m_NumericUpDownNewValue.Increment     = increment;
            }

            m_NumericUpDownNewValue.Maximum = (decimal)m_WatchVariable.MaxModifyValue;
            m_NumericUpDownNewValue.Minimum = (decimal)m_WatchVariable.MinModifyValue;

            // Initialize the NumericUpDown control Value property.
            m_DecimalPlaces           = m_NumericUpDownNewValue.DecimalPlaces;
            m_CurrentEngineeringValue = m_WatchControl.Value * m_WatchVariable.ScaleFactor;
            m_CurrentEngineeringValue = Math.Round(m_CurrentEngineeringValue, m_DecimalPlaces);
            try
            {
                m_NumericUpDownNewValue.Value = (decimal)m_CurrentEngineeringValue;
            }
            catch (Exception)
            {
                // The specified initial value is outside of the limits, set to the minimum value.
                m_NumericUpDownNewValue.Value = m_NumericUpDownNewValue.Minimum;
            }
            #endregion - [NumericUpDown] -

            #region - [Allowable Range] -
            if (m_HexFormat == true)
            {
                m_LabelAllowableRangeLowerValue.Text = HexValueIdentifier + ((long)m_WatchVariable.MinModifyValue).ToString("X");
                m_LabelAllowableRangeUpperValue.Text = HexValueIdentifier + ((long)m_WatchVariable.MaxModifyValue).ToString("X");
            }
            else
            {
                m_LabelAllowableRangeLowerValue.Text = m_WatchVariable.MinModifyValue.ToString(FormatStringNumericString);
                m_LabelAllowableRangeUpperValue.Text = m_WatchVariable.MaxModifyValue.ToString(FormatStringNumericString);
            }
            #endregion - [Allowable Range] -

            // Now that the display has been initialized, disable the apply button. This will only be re-enabled when the user has specified a new watch value.
            m_ButtonApply.Enabled = false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Instantiates a new <c>WatchControl</c> derived user control and configures the properties for each element of <paramref name="watchControls"/> based upon the 
        /// watch variables specified by <paramref name="oldIdentifierList"/>. Each user control is then added to the <c>Controls</c> property of <paramref name="panel"/>.
        /// </summary>
        /// <remarks>The length of the array should be equal to the count value associated with the list.</remarks>
        /// <param name="watchControls">The array of watch variable user controls that are to be configured.</param>
        /// <param name="panel">Reference to the <c>Panel</c> to which the user controls are to be added.</param>
        /// <param name="watchControlSize">The structure defining the size related parameters of the user control, <see cref="VariableControlSize_t"/>.</param>
        /// <param name="oldIdentifierList">The list of watch variable old identifiers.</param>
        /// <exception cref="ArgumentException">Thrown if the number of watch identifier entries in the list is incompatible with the length of the user control array.</exception>
        public void ConfigureWatchControls(WatchControl[] watchControls, Panel panel, VariableControlSize_t watchControlSize, List<short> oldIdentifierList)
        {
            // Skip, if the Dispose() method has been called.
            if (m_IsDisposed)
            {
                return;
            }

            Debug.Assert(oldIdentifierList.Count == watchControls.Length);

            // Work out the spacing between consecutive lines.
            int rowSpacing = watchControlSize.Size.Height + watchControlSize.Margin.Vertical;

            // Initialize the user controls.
            short oldIdentifier;
            WatchVariable watchVariable;
            for (int rowIndex = 0; rowIndex < oldIdentifierList.Count; rowIndex++)
            {
                oldIdentifier = oldIdentifierList[rowIndex];
                try
                {
                    watchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[oldIdentifier];
                    if (watchVariable == null)
                    {
                        // The specified watch variable is not defined in the current data dictionary therefore display an empty user control showing the 'not-defined' text.
                        watchControls[rowIndex] = new WatchControl();
                    }
                    else
                    {
                        switch (watchVariable.VariableType)
                        {
                            case VariableType.Scalar:
                                watchControls[rowIndex] = new WatchScalarControl();
                                break;
                            case VariableType.Enumerator:
                                watchControls[rowIndex] = new WatchEnumeratorControl();
                                break;
                            case VariableType.Bitmask:
                                watchControls[rowIndex] = new WatchBitmaskControl();
                                break;
                            default:
                                break;
                        }
                    }
                }
                catch (Exception)
                {
                    watchVariable = null;

                    // The specified watch variable is not defined in the current data dictionary therefore display an empty user control showing the 'not-defined' text.
                    watchControls[rowIndex] = new WatchControl();
                }

                watchControls[rowIndex].WidthVariableNameField = watchControlSize.WidthVariableNameField;
                watchControls[rowIndex].WidthValueField = watchControlSize.WidthValueField;
                watchControls[rowIndex].WidthUnitsField = watchControlSize.WidthUnitsField;

                watchControls[rowIndex].ClientForm = m_Form;
                watchControls[rowIndex].TabIndex = m_TabIndex;
                watchControls[rowIndex].Location = new System.Drawing.Point(watchControlSize.Margin.Left, (rowIndex + 1) * rowSpacing);

                watchControls[rowIndex].ForeColorValueFieldZero = Color.ForestGreen;
                watchControls[rowIndex].ForeColorValueFieldNonZero = Color.ForestGreen;

                watchControls[rowIndex].Identifier = oldIdentifier;

                if (watchVariable == null)
                {
                    watchControls[rowIndex].AttributeFlags = AttributeFlags.PTUD_NOTUSED;
                }
                else
                {
                    watchControls[rowIndex].AttributeFlags = (AttributeFlags)watchVariable.AttributeFlags;
                }

                watchControls[rowIndex].Value = 0;

                // Add the user control to the specified panel.
                panel.Controls.Add(watchControls[rowIndex]);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initialize a new instance of the class.
        /// </summary>
        /// <param name="scalarControl">The <c>WatchControl</c> derived user control that called this form.</param>
        public FormChangeScalar(WatchScalarControl scalarControl) : base(scalarControl)
        {
            InitializeComponent();
            Debug.Assert(m_WatchVariable != null, "FormChangeScalar.Ctor() - [m_WatchVariable != null]");
            Debug.Assert(m_WatchVariable.VariableType == VariableType.Scalar, "FormChangeScalar.Ctor() - [m_WatchVariable.VariableType == VariableType.Scalar]");

            if (m_WatchVariable.FormatString.ToLower() == FormatStringHexadecimal)
            {
                m_HexFormat = true;
            }

            #region - [NumericUpDown] -
            if (m_HexFormat == true)
            {
                m_NumericUpDownNewValue.Hexadecimal = true;

                m_NumericUpDownNewValue.DecimalPlaces = 0;
                m_NumericUpDownNewValue.Increment = 1;
            }
            else
            {
                m_NumericUpDownNewValue.Hexadecimal = false;

                // Evaluate the DecimalPlaces and Increment properties associated with the NumericUpDown control based upon the watch variable scale-factor.
                double scaleFactor = m_WatchVariable.ScaleFactor;
                int decimalPlaces;
                decimal increment;
                General.GetDecimalPlaces(scaleFactor, out decimalPlaces);
                General.GetIncrement(scaleFactor, out increment);

                m_NumericUpDownNewValue.DecimalPlaces = decimalPlaces;
                m_NumericUpDownNewValue.Increment = increment;
            }

            m_NumericUpDownNewValue.Maximum = (decimal)m_WatchVariable.MaxModifyValue;
            m_NumericUpDownNewValue.Minimum = (decimal)m_WatchVariable.MinModifyValue;

            // Initialize the NumericUpDown control Value property.
            m_DecimalPlaces = m_NumericUpDownNewValue.DecimalPlaces;
            m_CurrentEngineeringValue = m_WatchControl.Value * m_WatchVariable.ScaleFactor;
            m_CurrentEngineeringValue = Math.Round(m_CurrentEngineeringValue, m_DecimalPlaces);
            try
            {
                m_NumericUpDownNewValue.Value = (decimal)m_CurrentEngineeringValue;
            }
            catch (Exception)
            {
                // The specified initial value is outside of the limits, set to the minimum value.
                m_NumericUpDownNewValue.Value = m_NumericUpDownNewValue.Minimum;
            }
            #endregion - [NumericUpDown] -

            #region - [Allowable Range] -
            if (m_HexFormat == true)
            {
                m_LabelAllowableRangeLowerValue.Text = HexValueIdentifier + ((long)m_WatchVariable.MinModifyValue).ToString("X");
                m_LabelAllowableRangeUpperValue.Text = HexValueIdentifier + ((long)m_WatchVariable.MaxModifyValue).ToString("X");
            }
            else
            {
                m_LabelAllowableRangeLowerValue.Text = m_WatchVariable.MinModifyValue.ToString(FormatStringNumericString);
                m_LabelAllowableRangeUpperValue.Text = m_WatchVariable.MaxModifyValue.ToString(FormatStringNumericString);
            }
            #endregion - [Allowable Range] -

            // Now that the display has been initialized, disable the apply button. This will only be re-enabled when the user has specified a new watch value.
            m_ButtonApply.Enabled = false;
        }