/// <summary> /// Load the specified workset. /// </summary> /// <param name="workset">The workset that is to be processed.</param> protected virtual void LoadWorkset(Workset_t workset) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } // Ensure that the TextChanged event is not triggered as a result of specifying the Text property of the TextBox control. m_TextBoxName.TextChanged -= new EventHandler(m_TextBoxName_TextChanged); m_TextBoxName.Text = workset.Name; m_TextBoxName.TextChanged += new EventHandler(m_TextBoxName_TextChanged); m_TextBoxHeader1.Text = workset.Column[0].HeaderText; m_ListItemCount = workset.Count; m_WatchItems = new WatchItem_t[workset.WatchItems.Length]; Array.Copy(workset.WatchItems, m_WatchItems, workset.WatchItems.Length); UpdateListBoxAvailable(m_WatchItems); // ------------------------------------ // Update the 'Column' ListBox control. // ------------------------------------- WatchItemAddRange(m_ListBox1, workset.Column[0]); UpdateCount(); m_TextBoxSecurityLevel.Text = Security.GetSecurityDescription(workset.SecurityLevel); }
/// <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> /// Create a new, empty chart recorder/fault log workset. /// </summary> private void CreateNewWorkset() { // WatchItem - populate the array defining which watch variables have been added to the workset. m_WatchItems = new WatchItem_t[Lookup.WatchVariableTableByOldIdentifier.RecordList.Count]; WatchItem_t watchItem; WatchVariable watchVariable; for (short oldIdentifier = 0; oldIdentifier < Lookup.WatchVariableTableByOldIdentifier.RecordList.Count; oldIdentifier++) { watchItem = new WatchItem_t(); watchItem.OldIdentifier = oldIdentifier; watchItem.Added = false; try { watchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[oldIdentifier]; if (watchVariable == null) { watchItem.Exists = false; } else { watchItem.Exists = true; } } catch (Exception) { watchItem.Exists = false; } m_WatchItems[oldIdentifier] = watchItem; } UpdateListBoxAvailable(m_WatchItems); ClearListBoxColumnItems(); m_ListItemCount = 0; UpdateCount(); }
/// <summary> /// For the specified workset file update: (a) the baseline workset; (b) the WatchItems, WatchElementList and CountMax properties of all other worksets and (c) /// the EntryCountMax field to be compatible with the new data dictionary. Also report any worksets that: (a) contain more watch values than are permitted /// or (b) include one or more invalid old identifier references. /// </summary> /// <param name="worksetCollectionFile">The structure containing the de-serialized workset file.</param> private void Update(ref WorksetCollectionFile_t worksetCollectionFile) { // Get the number of watch variables and the number of oldIdentifiers associated with the current data dictionary and the data dictionary associated with // the workset. int dataDictionaryOldIdentifierCount = Lookup.WatchVariableTableByOldIdentifier.RecordList.Count; int dataDictionaryWatchIdentifierCount = Lookup.WatchVariableTable.RecordList.Count; int worksetOldIdentifierCount = worksetCollectionFile.WorksetList[0].WatchItems.Length; int worksetWatchIdentifierCount = 0; for (int elementIndex = 0; elementIndex < worksetOldIdentifierCount; elementIndex++) { if (worksetCollectionFile.WorksetList[0].WatchItems[elementIndex].Exists == true) { worksetWatchIdentifierCount++; } } int watchVariablesAddedTo = 0; int watchVariablesDeletedFrom = 0; if (dataDictionaryOldIdentifierCount > worksetOldIdentifierCount) { watchVariablesAddedTo = dataDictionaryOldIdentifierCount - worksetOldIdentifierCount; watchVariablesDeletedFrom = watchVariablesAddedTo - (dataDictionaryWatchIdentifierCount - worksetWatchIdentifierCount); } else if (worksetOldIdentifierCount > dataDictionaryOldIdentifierCount) { watchVariablesDeletedFrom = worksetOldIdentifierCount - dataDictionaryOldIdentifierCount; watchVariablesAddedTo = watchVariablesDeletedFrom - (worksetWatchIdentifierCount - dataDictionaryWatchIdentifierCount); } // Check whether the WatchItems property of the worksets in the specified workset collection need be updated i.e. check whether any watch variables have been // added to or deleted from the the data dictionary since the workset was created. List<short> invalidOldIdentifierList; List<Workset_t> invalidOldIdentifierWorksetList, invalidWatchSizeWorksetList; if ((dataDictionaryOldIdentifierCount != worksetOldIdentifierCount) || (dataDictionaryWatchIdentifierCount != worksetWatchIdentifierCount)) { #region - [Error Reporting] - // Check whether any watch variables have been deleted from the current data dictionary since the worksets were defined. if (watchVariablesDeletedFrom > 0) { // Yes - Get a list of any old identifiers in the workset file that are incompatible with the current data dictionary. invalidOldIdentifierList = GetIncompatibleOldIdentifierList(worksetCollectionFile); if (invalidOldIdentifierList.Count > 0) { // Get the list of worksets that are effected. invalidOldIdentifierWorksetList = GetIncompatibleWorksetList(worksetCollectionFile, invalidOldIdentifierList); if (invalidOldIdentifierWorksetList.Count > 0) { ReportIncompatibleWorksets(invalidOldIdentifierWorksetList, invalidOldIdentifierList, worksetCollectionFile.WorksetCollectionType); } } } #endregion - [Error Reporting] - #region - [WatchItems/WatchElementList Update] - // ------------------------------------------------------------------------------------ // Update the WatchItems and WatchElementList fields of all of the workset in the file. // ------------------------------------------------------------------------------------ for (short worksetIndex = 0; worksetIndex < worksetCollectionFile.WorksetList.Count; worksetIndex++) { // Replicate the workset. Workset_t workset = new Workset_t(); workset.Replicate(worksetCollectionFile.WorksetList[worksetIndex]); //Create a new WatchItems propery for the current workset based upon the current data dictionary with the Added property of all elements set to false. workset.WatchItems = new WatchItem_t[dataDictionaryOldIdentifierCount]; WatchItem_t watchItem; for (short watchItemIndex = 0; watchItemIndex < dataDictionaryOldIdentifierCount; watchItemIndex++) { watchItem = new WatchItem_t(); watchItem.OldIdentifier = watchItemIndex; watchItem.Added = false; try { // Check whether the watch variable exists and set the Exists property of the watch item appropriately. WatchVariable watchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[watchItemIndex]; watchItem.Exists = (watchVariable == null) ? false : true; } catch (Exception) { watchItem.Exists = false; } workset.WatchItems[watchItemIndex] = watchItem; } // Update the WatchElementList and the WatchItems properties of the workset using the old identifier values stored in each column of the workset. workset.WatchElementList = new List<short>(); short oldIdentifier; for (int columnIndex = 0; columnIndex < workset.Column.Length; columnIndex++) { for (int rowIndex = 0; rowIndex < workset.Column[columnIndex].OldIdentifierList.Count; rowIndex++) { // Get the old identifier value. oldIdentifier = workset.Column[columnIndex].OldIdentifierList[rowIndex]; // Check whether the watch variable associated with the old identifier value exists in the current workset. try { WatchVariable watchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[oldIdentifier]; if (watchVariable == null) { // No, add the watch identifier value used to represent the watch variable not being defined in the current data dictionary. workset.WatchElementList.Add(CommonConstants.WatchIdentifierNotDefined); } else { // Add the watch identifier of the watch variable corresponding to the specified old identifier to the list of watch identifiers. workset.WatchElementList.Add(watchVariable.Identifier); // Update the Exists and Added properties of the WatchItem element corresponding to the specified old identifier. workset.WatchItems[oldIdentifier].Added = true; workset.WatchItems[oldIdentifier].Exists = true; } } catch (Exception) { // No, add the watch identifier value used to represent the watch variable not being defined in the current data dictionary. workset.WatchElementList.Add(CommonConstants.WatchIdentifierNotDefined); } } } workset.WatchElementList.Sort(); // Replace the workset. worksetCollectionFile.WorksetList[worksetIndex] = workset; #endregion - [WatchItems/WatchElementList Update] - } } // Only carry out watch size processing if the workset collection corresponds to a watch window workset. if (worksetCollectionFile.WorksetCollectionType == Configuration.WorksetCollectionType.RecordedWatch) { #region - [Error Reporting] - invalidWatchSizeWorksetList = GetIncompatibleWorksetList(worksetCollectionFile, Parameter.WatchSize); if (invalidWatchSizeWorksetList.Count > 0) { ReportIncompatibleWorksets(invalidWatchSizeWorksetList); } #endregion - [Error Reporting] - #region - [WatchSize Update] - // Update the EntryCountMax field of the workset file, if required. if (worksetCollectionFile.EntryCountMax != Parameter.WatchSize) { worksetCollectionFile.EntryCountMax = Parameter.WatchSize; } // Update the baseline workset and the EntryCount max field of individual worksets, if required. for (int worksetIndex = 0; worksetIndex < worksetCollectionFile.WorksetList.Count; worksetIndex++) { Workset_t workset; if (worksetCollectionFile.WorksetList[worksetIndex].CountMax != Parameter.WatchSize) { // If the workset is the baseline workset, update it. if (worksetIndex == 0) { workset = CreateBaselineWorkset(); } else { workset = worksetCollectionFile.WorksetList[worksetIndex]; workset.CountMax = Parameter.WatchSize; } worksetCollectionFile.WorksetList[worksetIndex] = workset; } } #endregion - [WatchSize Update] - } }
/// <summary> /// Create an array of watch items based upon the specified list of watch elements. /// </summary> /// <param name="watchElementList">The list containing the watch elements.</param> /// <param name="oldIdentifierCount">The number of entries in the old identifier lookup table associated with the current data dictionary.</param> /// <returns>The array of watch items showing which watch variables have been added to the workset.</returns> public WatchItem_t[] CreateWatchItems(List<short> watchElementList, int oldIdentifierCount) { WatchItem_t[] watchItems = new WatchItem_t[oldIdentifierCount]; WatchItem_t watchItem; WatchVariable watchVariable; // Create an array of watch items where the Added property of each watch item is set to false. for (short oldIdentifier = 0; oldIdentifier < oldIdentifierCount; oldIdentifier++) { watchItem = new WatchItem_t(); watchItem.OldIdentifier = oldIdentifier; watchItem.Added = false; try { watchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[oldIdentifier]; if (watchVariable == null) { watchItem.Exists = false; } else { watchItem.Exists = true; } } catch(Exception) { watchItem.Exists = false; } watchItems[oldIdentifier] = watchItem; } // Now update the Added property to reflect the list of watch elements. for (short watchElementIndex = 0; watchElementIndex < WatchElementList.Count; watchElementIndex++) { try { // Get the old identifier corresponding to the watch element and update the appropriate element of the WatchItems array. watchVariable = Lookup.WatchVariableTable.Items[watchElementList[watchElementIndex]]; if (watchVariable == null) { continue; } watchItems[watchVariable.OldIdentifier].Added = true; } catch (Exception) { continue; } } return watchItems; }
/// <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; }
/// <summary> /// Add the watch variables defined in the specified list of old identifiers to the specified <c>ListBox</c> control. /// </summary> /// <param name="listBox">The <c>ListBox</c> to which the items are to be added.</param> /// <param name="plotTabPage">The plot tab page of the workset that is to be added to the <c>ListBox</c> control.</param> protected void WatchItemAddRange(ListBox listBox, PlotTabPage_t plotTabPage) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } Cursor = Cursors.WaitCursor; List<short> oldIdentifierList = plotTabPage.OldIdentifierList; List<uint> displayMaskList = plotTabPage.DisplayMaskList; Debug.Assert(oldIdentifierList.Count == displayMaskList.Count, "FormPlotDefine.WatchItemAddRange() - oldIdentifierList.Count == displayMaskList.Count[]"); listBox.Items.Clear(); listBox.SuspendLayout(); WatchItem_t watchItem; short oldIdentifier; uint displayMask; for (int index = 0; index < oldIdentifierList.Count; index++) { watchItem = new WatchItem_t(); oldIdentifier = oldIdentifierList[index]; displayMask = displayMaskList[index]; watchItem.OldIdentifier = oldIdentifier; // The DisplayMask field is only applicable to bitmask watch variables and is used to define which bits of the bitmask watch variable. watchItem.DisplayMask = displayMask; watchItem.Added = true; listBox.Items.Add(watchItem); } listBox.PerformLayout(); Cursor = Cursors.Default; }
/// <summary> /// Update the <c>ListBox</c> control that displays the list of available watch variables that match the current search criteria with the list of currently /// available watch variables, sorted alpha-numerically. /// </summary> protected override void UpdateListBoxAvailable(WatchItem_t[] watchItems) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } Cursor = Cursors.WaitCursor; // The list of watch items that are to be added to the ListBox control. The type parameter must be an object type rather than a WatchItem_t type so that // the ToArray() method can be used to generate an object[] which can then be added to existing the ListBox.Items using the AddRange method. List<object> watchItemList = new List<object>(); WatchItem_t watchItem; for (short oldIdentifier = 0; oldIdentifier < watchItems.Length; oldIdentifier++) { watchItem = watchItems[oldIdentifier]; // Ensure that the DisplayMask field is set to display all bits if the watch varable is a bitmask watch variable. watchItem.DisplayMask = uint.MaxValue; // If the watch variable has been added to the workset, add it to the list of available watch variables, provided that it exists in the new // data dictionary. if ((watchItem.Exists == true) && (watchItem.Added == true)) { watchItemList.Add(watchItem); } } // Sort the list alpha-numerically. watchItemList.Sort(CompareWatchItemsByVariableName); // Now search the list for those variables that match the search text. List<object> searchItemList = watchItemList.FindAll(ContainsSearchText); // Add the items to the ListBox control. m_ListBoxAvailable.SuspendLayout(); m_ListBoxAvailable.Items.Clear(); m_ListBoxAvailable.Items.AddRange(searchItemList.ToArray()); m_ListBoxAvailable.PerformLayout(); // Update the watch variable count. m_LabelAvailableCount.Text = Resources.LegendAvailable + CommonConstants.Colon + m_ListBoxAvailable.Items.Count.ToString(); Cursor = Cursors.Default; }
/// <summary> /// Initializes an new instance of the form. This constructor is used when a new workset is being created. Populates the 'Available' /// <c>ListBox</c> controls with the appropriate watch variables. /// </summary> /// <param name="worksetCollection">The workset collection that is to be managed.</param> public FormWorksetDefine(WorksetCollection worksetCollection) { InitializeComponent(); m_WorksetCollection = worksetCollection; m_EntryCountMax = m_WorksetCollection.EntryCountMax; // Set the flag to indicate that the form has been called in order to add a new workset. m_CreateMode = true; // Use the default new name for the workset. m_DefaultNewWorksetName = Resources.NameNewWorksetDefault; // Ensure that the TextChanged event is not triggered as a result of specifying the Text property of the TextBox control. m_TextBoxName.TextChanged -= new EventHandler(m_TextBoxName_TextChanged); m_TextBoxName.Text = m_DefaultNewWorksetName; m_TextBoxName.TextChanged += new EventHandler(m_TextBoxName_TextChanged); // Update the security description to reflect the current security level. m_TextBoxSecurityLevel.Text = Security.Description; // --------- // WatchItem // --------- // Populate the array defining which watch variables have been added to the workset. m_WatchItems = new WatchItem_t[Lookup.WatchVariableTableByOldIdentifier.RecordList.Count]; WatchItem_t watchItem; WatchVariable watchVariable; for (short oldIdentifier = 0; oldIdentifier < Lookup.WatchVariableTableByOldIdentifier.RecordList.Count; oldIdentifier++) { watchItem = new WatchItem_t(); watchItem.OldIdentifier = oldIdentifier; watchItem.Added = false; try { watchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[oldIdentifier]; if (watchVariable == null) { watchItem.Exists = false; } else { watchItem.Exists = true; } } catch(Exception) { watchItem.Exists = false; } m_WatchItems[oldIdentifier] = watchItem; } UpdateListBoxAvailable(m_WatchItems); UpdateCount(); // Update the m_ListBoxSelected reference to point at the ListBox control associated with the default TabPage. m_ListBoxSelected = m_ListBox1; // ---------------------------- // OK, Cancel and Apply buttons. // ---------------------------- // Hide the Apply button in this mode and move the position of the OK and Cancel buttons. m_ButtonApply.Visible = false; m_ButtonOK.Location = m_ButtonCancel.Location; m_ButtonCancel.Location = m_ButtonApply.Location; EnableApplyAndOKButtons(); }
/// <summary> /// Add the watch variables defined in the specified list of old identifiers to the specified <c>ListBox</c> control. /// </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 virtual void WatchItemAddRange(ListBox listBox, Column_t worksetColumn) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } Cursor = Cursors.WaitCursor; List<short> oldIdentifierList = worksetColumn.OldIdentifierList; listBox.Items.Clear(); listBox.SuspendLayout(); WatchItem_t watchItem; short oldIdentifier; for (int index = 0; index < oldIdentifierList.Count; index++) { watchItem = new WatchItem_t(); oldIdentifier = oldIdentifierList[index]; watchItem.OldIdentifier = oldIdentifier; watchItem.Added = true; // The DisplayMask field is only applicable to bitmask watch variables and is used to define which bits of the bitmask watch variable // are to be plotted. watchItem.DisplayMask = uint.MaxValue; listBox.Items.Add(watchItem); } listBox.PerformLayout(); Cursor = Cursors.Default; }