/// <summary>
        /// Add the watch variables defined in the specified workset column to the <c>ListBox</c> controls that display the description and the chart recorder scaling 
        /// information for each chart recorder channel.
        /// </summary>
        /// <param name="worksetColumn">The column of the workset that is to be added to the <c>ListBox</c> control.</param>
        protected void WatchItemAddRange(Column_t worksetColumn)
        {
            // Skip, if the Dispose() method has been called.
            if (IsDisposed)
            {
                return;
            }

            Cursor = Cursors.WaitCursor;

            m_ListBox1.Items.Clear();
            m_ListBoxChartScaleMin.Items.Clear();
            m_ListBoxChartScaleMax.Items.Clear();
            m_ListBoxUnits.Items.Clear();

            m_ListBox1.SuspendLayout();
            m_ListBoxChartScaleMin.SuspendLayout();
            m_ListBoxChartScaleMax.SuspendLayout();
            m_ListBoxUnits.SuspendLayout();

            WatchItem_t watchItem;
            short oldIdentifier;
            WatchVariable watchVariable;
            ChartScale_t chartScale;
            for (int index = 0; index < worksetColumn.OldIdentifierList.Count; index++)
            {
                watchItem = new WatchItem_t();
                oldIdentifier = worksetColumn.OldIdentifierList[index];
                watchItem.OldIdentifier = oldIdentifier;
                watchItem.Added = true;
                m_ListBox1.Items.Add(watchItem);

                // Check whether the watch variable exists.
                try
                {
                    watchVariable = watchVariable = Lookup.WatchVariableTableByOldIdentifier.RecordList[oldIdentifier];
                    if (watchVariable == null)
                    {
                        throw new Exception();
                    }

                    // Check whether the chart scaling for the current watch variable has been defined.
                    try
                    {
                        chartScale = worksetColumn.ChartScaleList[index];
                    }
                    catch (Exception)
                    {
                        // No - Set up the default chart scaling for the watch variable based upon the data dictionary.
                        chartScale = new ChartScale_t();
                        chartScale.ChartScaleMax = watchVariable.MaxChartScale;
                        chartScale.ChartScaleMin = watchVariable.MinChartScale;
                        chartScale.Units = watchVariable.Units;
                    }
                }
                catch (Exception)
                {
                    // Watch variable does not exist.
                    chartScale.ChartScaleMax = double.NaN;
                    chartScale.ChartScaleMin = double.NaN;
                    chartScale.Units = CommonConstants.VariableNotDefinedUnitsString;
                }

                m_ListBoxChartScaleMin.Items.Add(chartScale.ChartScaleMin);
                m_ListBoxChartScaleMax.Items.Add(chartScale.ChartScaleMax);
                m_ListBoxUnits.Items.Add(chartScale.Units);
            }

            m_ListBox1.PerformLayout();
            m_ListBoxChartScaleMin.PerformLayout();
            m_ListBoxChartScaleMax.PerformLayout();
            m_ListBoxUnits.PerformLayout();

            Cursor = Cursors.Default;
        }
        /// <summary>
        /// Convert the current user setting to a workset.
        /// </summary>
        /// <param name="worksetName">The name of the workset.</param>
        /// <returns>The user settings converted to a workset.</returns>
        protected Workset_t ConvertToWorkset(string worksetName)
        {
            // --------------------------------------------------------------------------
            // Copy the definitions to a new workset and update the WorksetManager class.
            // --------------------------------------------------------------------------
            Workset_t workset = new Workset_t();

            workset.Name = worksetName;
            workset.SampleMultiple = Workset_t.DefaultSampleMultiple;
            workset.CountMax = m_WorksetCollection.EntryCountMax;
            workset.SecurityLevel = Security.SecurityLevelCurrent;

            #region - [Column] -
            workset.Column = new Column_t[1];
            workset.Column[0].HeaderText = m_TextBoxHeader1.Text;
            workset.Column[0].OldIdentifierList = new List<short>();
            workset.Column[0].ChartScaleList = new List<ChartScale_t>();

            #region - [OldIdentifierList] -
            for (int index = 0; index < m_ListBox1.Items.Count; index++)
            {
                workset.Column[0].OldIdentifierList.Add(((WatchItem_t)m_ListBox1.Items[index]).OldIdentifier);
            }
            #endregion - [OldIdentifierList] -

            #region - [ChartScaleList] -
            // The old identifer associated with the current watch variable.
            short oldIdentifier;

            // The current watch variable.
            WatchVariable watchVariable;

            // A flag to indicate whether the current watch variable is to be displayed in hexadecimal format. True, if the variable is to be displayed in hex format.
            bool hexFormat = false;

            // The upper and lower chart scale values as a text string.
            string chartScaleLowerLimitText, chartScaleUpperLimitText;
            ChartScale_t chartScale = new ChartScale_t();

            // The current culture information. Used to parse hexadecimal values.
            CultureInfo provider = new CultureInfo(CommonConstants.CultureInfoString);

            // A flag to indicate whether the parse operationwas successful. True, if the parse was successful.
            bool successfulParse;
            for (int index = 0; index < m_ListBox1.Items.Count; index++)
            {
                // Get the watch variable associated with the current item.
                oldIdentifier = ((WatchItem_t)m_ListBox1.Items[index]).OldIdentifier;
                try
                {
                    watchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[oldIdentifier];
                    if (watchVariable == null)
                    {
                        throw new Exception();
                    }

                    // Determine the format of the watch variable.
                    hexFormat = (watchVariable.FormatString.ToLower().Equals(CommonConstants.DDFormatStringHex)) ? true : false;

                    chartScaleLowerLimitText = (string)m_ListBoxChartScaleLowerLimit.Items[index];
                    chartScaleUpperLimitText = (string)m_ListBoxChartScaleUpperLimit.Items[index];

                    if (m_ListBoxChartScaleLowerLimit.Items[index].Equals(CommonConstants.ChartScaleValueNotDefinedString))
                    {
                        chartScale.ChartScaleLowerLimit = double.NaN;
                    }
                    else
                    {
                        if (hexFormat == true)
                        {
                            uint lowerLimitAsUInt32;
                            string strippedChartScaleLowerLimitText;

                            // Strip out the leading HexValueIdentifier.
                            Debug.Assert(chartScaleLowerLimitText.Contains(CommonConstants.HexValueIdentifier), "FormConfigureChartRecorder.ConvertToWorkset() - [chartScaleLowerLimitText.Contains(HexValueIdentifier)]");
                            strippedChartScaleLowerLimitText = chartScaleLowerLimitText.Remove(0, CommonConstants.HexValueIdentifier.Length);

                            // Check that the value entered is a valid 32 bit hexadecimal value.
                            successfulParse = UInt32.TryParse(strippedChartScaleLowerLimitText, NumberStyles.HexNumber, provider, out lowerLimitAsUInt32);
                            if (successfulParse == false)
                            {
                                chartScale.ChartScaleLowerLimit = double.NaN;
                            }
                            else
                            {
                                chartScale.ChartScaleLowerLimit = lowerLimitAsUInt32;
                            }
                        }
                        else
                        {
                            double lowerLimitAsDouble;

                            // Check that the value entered is a valid 32 bit decimal value.
                            successfulParse = double.TryParse(chartScaleLowerLimitText, out lowerLimitAsDouble);
                            if (successfulParse == false)
                            {
                                chartScale.ChartScaleLowerLimit = double.NaN;
                            }
                            else
                            {
                                chartScale.ChartScaleLowerLimit = lowerLimitAsDouble;
                            }
                        }
                    }

                    if (m_ListBoxChartScaleUpperLimit.Items[index].Equals(CommonConstants.ChartScaleValueNotDefinedString))
                    {
                        chartScale.ChartScaleUpperLimit = double.NaN;
                    }
                    else
                    {
                        if (hexFormat == true)
                        {
                            uint upperLimitAsUInt32;
                            string strippedChartScaleUpperLimitText;

                            // Strip out the leading HexValueIdentifier.
                            Debug.Assert(chartScaleUpperLimitText.Contains(CommonConstants.HexValueIdentifier), "FormConfigureChartRecorder.ConvertToWorkset() - [chartScaleUpperLimitText.Contains(HexValueIdentifier)]");
                            strippedChartScaleUpperLimitText = chartScaleUpperLimitText.Remove(0, CommonConstants.HexValueIdentifier.Length);

                            // Check that the value entered is a valid 32 bit hexadecimal value.
                            successfulParse = UInt32.TryParse(strippedChartScaleUpperLimitText, NumberStyles.HexNumber, provider, out upperLimitAsUInt32);
                            if (successfulParse == false)
                            {
                                chartScale.ChartScaleUpperLimit = double.NaN;
                            }
                            else
                            {
                                chartScale.ChartScaleUpperLimit = upperLimitAsUInt32;
                            }
                        }
                        else
                        {
                            double upperLimitAsDouble;

                            // Check that the value entered is a valid 32 bit decimal value.
                            successfulParse = double.TryParse(chartScaleUpperLimitText, out upperLimitAsDouble);
                            if (successfulParse == false)
                            {
                                chartScale.ChartScaleUpperLimit = double.NaN;
                            }
                            else
                            {
                                chartScale.ChartScaleUpperLimit = upperLimitAsDouble;
                            }
                        }
                    }

                    chartScale.Units = (string)m_ListBoxUnits.Items[index];
                    workset.Column[0].ChartScaleList.Add(chartScale);
                }
                catch (Exception)
                {
                    // The watch variable does not exist, add an empty chart scale value.
                    chartScale.ChartScaleLowerLimit = double.NaN;
                    chartScale.ChartScaleUpperLimit = double.NaN;
                    chartScale.Units = CommonConstants.ChartScaleUnitsNotDefinedString;
                    workset.Column[0].ChartScaleList.Add(chartScale);
                }
            }
            #endregion - [ChartScaleList] -
            #endregion - [Column] -

            #region - [WatchItems] -
            workset.WatchItems = new WatchItem_t[m_WatchItems.Length];
            Array.Copy(m_WatchItems, workset.WatchItems, m_WatchItems.Length);
            #endregion - [WatchItems] -

            #region - [WatchElementList] -
            workset.WatchElementList = new List<short>();
   
            for (int rowIndex = 0; rowIndex < workset.Column[0].OldIdentifierList.Count; rowIndex++)
            {
                oldIdentifier = workset.Column[0].OldIdentifierList[rowIndex];
                try
                {
                    watchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[oldIdentifier];
                    if (watchVariable == null)
                    {
                        workset.WatchElementList.Add(CommonConstants.WatchIdentifierNotDefined);
                    }
                    else
                    {
                        workset.WatchElementList.Add(watchVariable.Identifier);
                    }
                }
                catch (Exception)
                {
                    workset.WatchElementList.Add(CommonConstants.WatchIdentifierNotDefined);
                }
            }
            workset.WatchElementList.Sort();
            #endregion - [WatchElementList] -

            #region - [Count] -
            workset.Count = workset.WatchElementList.Count;

            if (workset.Count != m_ListItemCount)
            {
                throw new ArgumentException(Resources.EMWorksetIntegrityCheckFailed, "FormWorksetDefineChartRecorder.ConvertToWorkset() - [workset.WatchElements.Count]");
            }
            #endregion - [Count] -

            return workset;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initialize a new instance of the structure. Creates a new workset based upon the specified name and list of watch identifiers.
        /// </summary>
        /// <param name="name">The name of the workset.</param>
        /// <param name="watchIdentifierList">The list of watch identifiers that are to be used to initialize the workset.</param>
        /// <param name="entryCountMax">The maximum number of entries that the workset can support.</param>
        /// <param name="columnCountMax">The maximum number of display columns that the workset can support.</param>
        /// <param name="securityLevel">The security level associated with the workset.</param>
        /// <remarks>
        /// All watch identifiers contained within the specified list will appear in the first column of the workset in the order that they appear in the list. The 
        /// watch element list is sorted by watch identifier value in ascending order.
        /// </remarks>
        public Workset_t(string name, List<short> watchIdentifierList, short entryCountMax, short columnCountMax, SecurityLevel securityLevel)
        {
            Debug.Assert(name != string.Empty, "Workset_t.Ctor() - [name != string.Empty]");
            Debug.Assert(watchIdentifierList != null, "Workset_t.Ctor() - [watchElementList != null]");
            Debug.Assert((watchIdentifierList.Count > 0), "Workset_t.Ctor() - [watchElementList.Count > 0");

            Name = name;
            SampleMultiple = DefaultSampleMultiple;
            CountMax = entryCountMax;
            SecurityLevel = securityLevel;

            // Create the WatchElementList property.
            WatchElementList = new List<short>();
            short watchIdentifier;
            for (int watchIdentifierIndex = 0; watchIdentifierIndex < watchIdentifierList.Count; watchIdentifierIndex++)
            {
                watchIdentifier = watchIdentifierList[watchIdentifierIndex];
                WatchElementList.Add(watchIdentifier);
            }

            WatchElementList.Sort();
            Count = WatchElementList.Count;

            #region - [Column] -
            Column = new Column_t[columnCountMax];
            for (int columnIndex = 0; columnIndex < columnCountMax; columnIndex++)
            {
                Column[columnIndex] = new Column_t();
                Column[columnIndex].HeaderText = (columnIndex == 0) ? Resources.LegendColumn + CommonConstants.Space + (columnIndex + 1).ToString() : string.Empty;
                Column[columnIndex].OldIdentifierList = new List<short>();
                Column[columnIndex].ChartScaleList = new List<ChartScale_t>();
            }

            // Add the old identifier values of the watch variables defined in the watch element list to the first column of the workset.
            WatchVariable watchVariable;
            ChartScale_t chartScale;
            for (short watchIdentifierIndex = 0; watchIdentifierIndex < WatchElementList.Count; watchIdentifierIndex++)
            {
                chartScale = new ChartScale_t();
               
                try
                {
                    watchVariable = Lookup.WatchVariableTable.Items[watchIdentifierList[watchIdentifierIndex]];
                    if (watchVariable == null)
                    {
                        throw new Exception();
                    }
                    else
                    {
                        Column[0].OldIdentifierList.Add(watchVariable.OldIdentifier);

                        // Set up the default chart scaling from the values in the data dictionary.
                        chartScale.ChartScaleUpperLimit = watchVariable.MaxChartScale;
                        chartScale.ChartScaleLowerLimit = watchVariable.MinChartScale;
                        chartScale.Units = watchVariable.Units;
                        Column[0].ChartScaleList.Add(chartScale);
                    }
                }
                catch (Exception)
                {
                    Column[0].OldIdentifierList.Add(CommonConstants.OldIdentifierNotDefined);

                    // Set the chart scaling values to represent an invalid entry.
                    chartScale.ChartScaleLowerLimit = double.NaN;
                    chartScale.ChartScaleUpperLimit = double.NaN;
                    chartScale.Units = CommonConstants.ChartScaleUnitsNotDefinedString;
                    Column[0].ChartScaleList.Add(chartScale);
                }
            }
            #endregion - [Column] -

            // This attribute is used to define the plot screen layout and is defined by the user when displaying the saved data file.
            PlotTabPages = null;

            WatchItems = new WatchItem_t[Lookup.WatchVariableTableByOldIdentifier.Items.Length];

            // Create the WatchItems property from the list of watch elements.
            WatchItems = CreateWatchItems(WatchElementList, Lookup.WatchVariableTableByOldIdentifier.Items.Length);
        }
        /// <summary>
        /// Add the watch variables defined in the specified workset column to the <c>ListBox</c> controls that display the description and the chart recorder scaling 
        /// information for each chart recorder channel.
        /// </summary>
        /// <param name="listBox">The <c>ListBox</c> to which the items are to be added.</param>
        /// <param name="worksetColumn">The column of the workset that is to be added to the <c>ListBox</c> control.</param>
        protected override void WatchItemAddRange(ListBox listBox, Column_t worksetColumn)
        {
            // Skip, if the Dispose() method has been called.
            if (IsDisposed)
            {
                return;
            }

            Cursor = Cursors.WaitCursor;

            listBox.Items.Clear();
            m_ListBoxChartScaleUpperLimit.Items.Clear();
            m_ListBoxChartScaleLowerLimit.Items.Clear();
            m_ListBoxUnits.Items.Clear();

            listBox.SuspendLayout();
            m_ListBoxChartScaleUpperLimit.SuspendLayout();
            m_ListBoxChartScaleLowerLimit.SuspendLayout();
            m_ListBoxUnits.SuspendLayout();

            bool hexFormat = false;
            WatchItem_t watchItem;
            short oldIdentifier;
            WatchVariable watchVariable;
            ChartScale_t chartScale;
            for (int index = 0; index < worksetColumn.OldIdentifierList.Count; index++)
            {
                watchItem = new WatchItem_t();
                oldIdentifier = worksetColumn.OldIdentifierList[index];
                watchItem.OldIdentifier = oldIdentifier;
                watchItem.Added = true;
                m_ListBox1.Items.Add(watchItem);

                // Check whether the watch variable exists.
                try
                {
                    watchVariable = Lookup.WatchVariableTableByOldIdentifier.RecordList[oldIdentifier];
                    if (watchVariable == null)
                    {
                        throw new Exception();
                    }

                    // Determine the format of the watch variable.
                    hexFormat = (watchVariable.FormatString.ToLower().Equals(CommonConstants.DDFormatStringHex)) ? true : false;

                    // Check whether the chart scaling for the current watch variable has been defined.
                    try
                    {
                        chartScale = worksetColumn.ChartScaleList[index];
                    }
                    catch (Exception)
                    {
                        // No - Set up the default chart scaling for the watch variable based upon the data dictionary.
                        chartScale = new ChartScale_t();
                        chartScale.ChartScaleLowerLimit = watchVariable.MinChartScale;
                        chartScale.ChartScaleUpperLimit = watchVariable.MaxChartScale;
                        chartScale.Units = watchVariable.Units;
                    }
                }
                catch (Exception)
                {
                    // Watch variable does not exist.
                    chartScale.ChartScaleLowerLimit = double.NaN;
                    chartScale.ChartScaleUpperLimit = double.NaN;
                    chartScale.Units = CommonConstants.ChartScaleUnitsNotDefinedString;
                }

                // Rather tha displaying 'NaN' if the chart scale values are undefined, display the default string used to represent a chart scale value that is not defined.
                if (chartScale.ChartScaleLowerLimit.Equals(double.NaN))
                {
                    m_ListBoxChartScaleLowerLimit.Items.Add(CommonConstants.ChartScaleValueNotDefinedString);
                }
                else
                {
                    if (hexFormat == true)
                    {
                        m_ListBoxChartScaleLowerLimit.Items.Add(CommonConstants.HexValueIdentifier + ((uint)chartScale.ChartScaleLowerLimit).ToString(CommonConstants.FormatStringHex));
                    }
                    else
                    {
                        m_ListBoxChartScaleLowerLimit.Items.Add(chartScale.ChartScaleLowerLimit.ToString(CommonConstants.FormatStringNumeric));
                    }
                }

                if (chartScale.ChartScaleUpperLimit.Equals(double.NaN))
                {
                    m_ListBoxChartScaleUpperLimit.Items.Add(CommonConstants.ChartScaleValueNotDefinedString);
                }
                else
                {
                    if (hexFormat == true)
                    {
                        m_ListBoxChartScaleUpperLimit.Items.Add(CommonConstants.HexValueIdentifier + ((uint)chartScale.ChartScaleUpperLimit).ToString(CommonConstants.FormatStringHex));
                    }
                    else
                    {
                        m_ListBoxChartScaleUpperLimit.Items.Add(chartScale.ChartScaleUpperLimit.ToString(CommonConstants.FormatStringNumeric));
                    }
                }

                m_ListBoxUnits.Items.Add(chartScale.Units);
            }

            listBox.PerformLayout();
            m_ListBoxChartScaleLowerLimit.PerformLayout();
            m_ListBoxChartScaleUpperLimit.PerformLayout();
            m_ListBoxUnits.PerformLayout();

            Cursor = Cursors.Default;
        }