/// <summary> /// Convert the current user setting to a workset. /// </summary> /// <remarks> /// The conversion includes the chart scaling parameters. /// </remarks> /// <param name="worksetName">The name of the workset.</param> /// <returns>The user settings converted to a workset.</returns> protected override Workset_t ConvertToWorkset(string worksetName) { Workset_t workset = base.ConvertToWorkset(worksetName); workset.CountMax = Parameter.WatchSizeChartRecorder; #region - [ChartScaleList] - workset.Column[0].ChartScaleList = new List <ChartScale_t>(); // 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] - return(workset); }
/// <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); }
/// <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_ListBoxChartScaleLowerLimit.SuspendLayout(); m_ListBoxChartScaleUpperLimit.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; }
/// <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; }