Beispiel #1
0
        /// <summary>
        /// Initialize a new instance of the class.
        /// </summary>
        /// <param name="watchControl">The watch control derived user control that called this form.</param>
        /// <exception cref="Exception">Thrown if the old Identifier associated with the control that called this form is not defined in the current data dictionary.</exception>
        public FormChangeWatch(WatchControl watchControl)
        {
            InitializeComponent();

            m_WatchControl = watchControl;

            // Use the communication interface associated with the client form.
            m_ICommunicationInterface = m_WatchControl.ClientForm as ICommunicationInterface <ICommunicationWatch>;
            Debug.Assert(m_ICommunicationInterface != null);

            // Register the event handler for the data update event.
            m_IDataUpdate = m_WatchControl.ClientForm as IDataUpdate;
            if (m_IDataUpdate != null)
            {
                m_IDataUpdate.DataUpdate += new EventHandler(DataUpdate);
            }

            m_IPollTarget = m_WatchControl.ClientForm as IPollTarget;
            Debug.Assert(m_IPollTarget != null);

            m_OldIdentifier = (short)m_WatchControl.Identifier;
            try
            {
                m_WatchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[m_OldIdentifier];
                if (m_WatchVariable == null)
                {
                    throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
                }
            }
            catch (Exception)
            {
                throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
            }

            m_WatchVariableName = m_WatchControl.VariableNameFieldText;
            Text = m_WatchVariableName;

            #region - [Units] -
            string units = m_WatchVariable.Units;
            m_LabelCurrentValueUnits.Text   = units;
            m_LabelAllowableRangeUnits.Text = units;
            m_LabelNewValueUnits.Text       = units;
            #endregion - [Units] -

            // Update the display by calling the DataUpdate event handler.
            DataUpdate(this, new EventArgs());
        }
        /// <summary>
        /// Initialize a new instance of the class.
        /// </summary>
        /// <param name="bitmaskControl">The <c>WatchControl</c> derived user control that called this form.</param>
        public FormChangeBitmask(WatchBitmaskControl bitmaskControl)
        {
            InitializeComponent();

            m_WatchControl = bitmaskControl;

            // Use the communication interface associated with the client form.
            m_ICommunicationInterface = m_WatchControl.ClientForm as ICommunicationInterface<ICommunicationWatch>;
            Debug.Assert(m_ICommunicationInterface != null);

            // Register the event handler for the data update event.
            m_IDataUpdate = m_WatchControl.ClientForm as IDataUpdate;
            if (m_IDataUpdate != null)
            {
                m_IDataUpdate.DataUpdate += new EventHandler(DataUpdate);
            }

            m_IPollTarget = m_WatchControl.ClientForm as IPollTarget;
            Debug.Assert(m_IPollTarget != null);

            m_OldIdentifier = (short)m_WatchControl.Identifier;
            try
            {
                m_WatchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[m_OldIdentifier];
                if (m_WatchVariable == null)
                {
                    throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
                }
            }
            catch(Exception)
            {
                throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
            }

            Debug.Assert(m_WatchVariable.VariableType == VariableType.Bitmask, "FormChangeBitmask.Ctor() - [m_WatchVariable.VariableType == VariableType.Bitmask]");

            Text = m_WatchVariable.Name;

            #region - [Units] -
            string units = m_WatchVariable.Units;
            m_LabelCurrentValueUnits.Text = units;
            m_LabelNewValueUnits.Text = units;
            #endregion - [Units] -

            #region - [NumericUpDown] -
            m_NumericUpDownNewValue.Hexadecimal = m_RadioButtonHex.Checked;
            m_NumericUpDownNewValue.DecimalPlaces = 0;
            m_NumericUpDownNewValue.Increment = 1;

            m_NumericUpDownNewValue.Maximum = (decimal)m_WatchVariable.MaxModifyValue;
            m_NumericUpDownNewValue.Minimum = (decimal)m_WatchVariable.MinModifyValue;
            
            // Initialize the NumericUpDown control Value property.
            try
            {
                m_NumericUpDownNewValue.Value = (decimal)m_WatchControl.Value;
            }
            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 - [ICheckBoxUInt32] -
            m_ICheckBoxUInt32 = new CheckBoxUInt32();
            CheckBox[] checkBoxes;
            ConfigureCheckBoxes(out checkBoxes);
            m_ICheckBoxUInt32.CheckBoxes = checkBoxes;
            m_ICheckBoxUInt32.SetText(m_OldIdentifier);
            m_ICheckBoxUInt32.SetChecked((uint)m_WatchControl.Value);
            #endregion - [ICheckBoxUInt32] -

            // Update the display by calling the DataUpdate event handler.
            DataUpdate(this, new EventArgs());

            // 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;
        }
        /// <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]);
            }
        }
        /// <summary>
        /// Initialize a new instance of the class.
        /// </summary>
        /// <param name="watchControl">The watch control derived user control that called this form.</param>
        /// <exception cref="Exception">Thrown if the old Identifier associated with the control that called this form is not defined in the current data dictionary.</exception>
        public FormChangeWatch(WatchControl watchControl)
        {
            InitializeComponent();

            m_WatchControl = watchControl;

            // Use the communication interface associated with the client form.
            m_ICommunicationInterface = m_WatchControl.ClientForm as ICommunicationInterface<ICommunicationWatch>;
            Debug.Assert(m_ICommunicationInterface != null);

            // Register the event handler for the data update event.
            m_IDataUpdate = m_WatchControl.ClientForm as IDataUpdate;
            if (m_IDataUpdate != null)
            {
                m_IDataUpdate.DataUpdate += new EventHandler(DataUpdate);
            }

            m_IPollTarget = m_WatchControl.ClientForm as IPollTarget;
            Debug.Assert(m_IPollTarget != null);

            m_OldIdentifier = (short)m_WatchControl.Identifier;
            try
            {
                m_WatchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[m_OldIdentifier];
                if (m_WatchVariable == null)
                {
                    throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
                }
            }
            catch (Exception)
            {
                throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
            }

            m_WatchVariableName = m_WatchControl.VariableNameFieldText;
            Text = m_WatchVariableName;

            #region - [Units] -
            string units = m_WatchVariable.Units;
            m_LabelCurrentValueUnits.Text = units;
            m_LabelAllowableRangeUnits.Text = units;
            m_LabelNewValueUnits.Text = units;
            #endregion - [Units] -

            // Update the display by calling the DataUpdate event handler.
            DataUpdate(this, new EventArgs());
        }
Beispiel #5
0
        /// <summary>
        /// Configure the watch user controls required to display the specified <paramref name="workset"/> and then add these to the specified 
        /// <paramref name="displayPanel"/>.
        /// </summary>
        /// <param name="workset">The workset that is to be used to configure the watch user controls.</param>
        /// <param name="displayPanel">The <c>Panel</c> to which the configured watch user controls are to be added.</param>
        /// <param name="watchControlSize">The size to make each watch user control.</param>
        /// <remarks>This method uses the <c>UserControl</c> class to: (a) layout and initialize all of the controls required to display the watch variables 
        /// associated with the specified worset and (b) add these to the tabpage/panel associated with the display.
        /// </remarks>
        protected void ConfigureDisplayPanel(Workset_t workset, Panel displayPanel, VariableControlSize_t watchControlSize)
        {
            // Skip, if the Dispose() method has been called.
            if (IsDisposed)
            {
                return;
            }

            // Clear the panel to which the controls are to be added.
            displayPanel.Hide();
            displayPanel.Controls.Clear();

            // Instantiate the watch control jagged array.
            m_WatchControls = new WatchControl[workset.Column.Length][];
            for (int columnIndex = 0; columnIndex < workset.Column.Length; columnIndex++)
            {
                m_WatchControls[columnIndex] = new WatchControl[workset.Column[columnIndex].OldIdentifierList.Count];
            }

            // Create a separate panel for each display column.
            Panel[] panelColumn = new Panel[workset.Column.Length];
            for (int columnIndex = 0; columnIndex < workset.Column.Length; columnIndex++)
            {
                panelColumn[columnIndex] = new Panel();
                panelColumn[columnIndex].AutoSize = true;
                panelColumn[columnIndex].Location = new Point(columnIndex * (watchControlSize.Size.Width + watchControlSize.Margin.Horizontal), 0);
                m_WatchControlLayout.WriteColumnHeaders(workset.Column[columnIndex].HeaderText, panelColumn[columnIndex], watchControlSize);
                m_WatchControlLayout.ConfigureWatchControls(m_WatchControls[columnIndex], panelColumn[columnIndex], watchControlSize,
                                                            workset.Column[columnIndex].OldIdentifierList);

                // Do not add the panel to the controls associated with the 'displayPanel' parameter if the last column of the workset does not contain any watch
                // variables AND no header text is defined. This ensures that the horizontal scroll bar is not displayed.
                if ((columnIndex == workset.Column.Length - 1) &&
                    (workset.Column[columnIndex].OldIdentifierList.Count == 0) &&
                    (workset.Column[columnIndex].HeaderText.Equals(string.Empty)))
                {
                    break;
                }
                else
                {
                    displayPanel.Controls.Add(panelColumn[columnIndex]);
                }
            }
            displayPanel.Show();
        }
        /// <summary>
        /// Initialize a new instance of the class.
        /// </summary>
        /// <param name="bitmaskControl">The <c>WatchControl</c> derived user control that called this form.</param>
        public FormChangeBitmask(WatchBitmaskControl bitmaskControl)
        {
            InitializeComponent();

            m_WatchControl = bitmaskControl;

            // Use the communication interface associated with the client form.
            m_ICommunicationInterface = m_WatchControl.ClientForm as ICommunicationInterface <ICommunicationWatch>;
            Debug.Assert(m_ICommunicationInterface != null);

            // Register the event handler for the data update event.
            m_IDataUpdate = m_WatchControl.ClientForm as IDataUpdate;
            if (m_IDataUpdate != null)
            {
                m_IDataUpdate.DataUpdate += new EventHandler(DataUpdate);
            }

            m_IPollTarget = m_WatchControl.ClientForm as IPollTarget;
            Debug.Assert(m_IPollTarget != null);

            m_OldIdentifier = (short)m_WatchControl.Identifier;
            try
            {
                m_WatchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[m_OldIdentifier];
                if (m_WatchVariable == null)
                {
                    throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
                }
            }
            catch (Exception)
            {
                throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
            }

            Debug.Assert(m_WatchVariable.VariableType == VariableType.Bitmask, "FormChangeBitmask.Ctor() - [m_WatchVariable.VariableType == VariableType.Bitmask]");

            Text = m_WatchVariable.Name;

            #region - [Units] -
            string units = m_WatchVariable.Units;
            m_LabelCurrentValueUnits.Text = units;
            m_LabelNewValueUnits.Text     = units;
            #endregion - [Units] -

            #region - [NumericUpDown] -
            m_NumericUpDownNewValue.Hexadecimal   = m_RadioButtonHex.Checked;
            m_NumericUpDownNewValue.DecimalPlaces = 0;
            m_NumericUpDownNewValue.Increment     = 1;

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

            // Initialize the NumericUpDown control Value property.
            try
            {
                m_NumericUpDownNewValue.Value = (decimal)m_WatchControl.Value;
            }
            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 - [ICheckBoxUInt32] -
            m_ICheckBoxUInt32 = new CheckBoxUInt32();
            CheckBox[] checkBoxes;
            ConfigureCheckBoxes(out checkBoxes);
            m_ICheckBoxUInt32.CheckBoxes = checkBoxes;
            m_ICheckBoxUInt32.SetText(m_OldIdentifier);
            m_ICheckBoxUInt32.SetChecked((uint)m_WatchControl.Value);
            #endregion - [ICheckBoxUInt32] -

            // Update the display by calling the DataUpdate event handler.
            DataUpdate(this, new EventArgs());

            // 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;
        }
Beispiel #7
0
        /// <summary>
        /// Configure the watch user controls required to display the specified <paramref name="workset"/> and then add these to the specified 
        /// <paramref name="displayPanel"/>.
        /// </summary>
        /// <param name="workset">The workset that is to be used to configure the watch user controls.</param>
        /// <param name="displayPanel">The <c>Panel</c> to which the configured watch user controls are to be added.</param>
        /// <param name="watchControlSize">The size to make each watch user control.</param>
        /// <remarks>This method uses the <c>UserControl</c> class to: (a) layout and initialize all of the controls required to display the watch variables 
        /// associated with the specified worset and (b) add these to the tabpage/panel associated with the display.
        /// </remarks>
        protected void ConfigureDisplayPanel(Workset_t workset, Panel displayPanel, VariableControlSize_t watchControlSize)
        {
            // Skip, if the Dispose() method has been called.
            if (IsDisposed)
            {
                return;
            }

            // Clear the panel to which the controls are to be added.
            displayPanel.Hide();
            displayPanel.Controls.Clear();

            // Instantiate the watch control jagged array.
            m_WatchControls = new WatchControl[workset.Column.Length][];
            for (int columnIndex = 0; columnIndex < workset.Column.Length; columnIndex++)
            {
                m_WatchControls[columnIndex] = new WatchControl[workset.Column[columnIndex].OldIdentifierList.Count];
            }

            // Create a separate panel for each display column.
            Panel[] panelColumn = new Panel[workset.Column.Length];
            for (int columnIndex = 0; columnIndex < workset.Column.Length; columnIndex++)
            {
                panelColumn[columnIndex] = new Panel();
                panelColumn[columnIndex].AutoSize = true;
                panelColumn[columnIndex].Location = new Point(columnIndex * (watchControlSize.Size.Width + watchControlSize.Margin.Horizontal), 0);
                m_WatchControlLayout.WriteColumnHeaders(workset.Column[columnIndex].HeaderText, panelColumn[columnIndex], watchControlSize);
                m_WatchControlLayout.ConfigureWatchControls(m_WatchControls[columnIndex], panelColumn[columnIndex], watchControlSize,
                                                            workset.Column[columnIndex].OldIdentifierList);
                displayPanel.Controls.Add(panelColumn[columnIndex]);
            }
            displayPanel.Show();
        }