/// <summary> /// Instantiates and initializes an array of <c>PlotTabPage_t</c> structures to match the current plot display settings. This can then be used /// to set the <c>PlotTabPages</c> property of the workset associated with the current watch file. /// </summary> /// <param name="tabControl">The <c>TabControl</c> that is to be processed.</param> /// <param name="itemsRemoved">A flag to indicate that one or more items have been removed by the user.</param> /// <returns>An array of <c>PlotTabPage_t</c> structures corresponding to the current plot display settings.</returns> private PlotTabPage_t[] ConstructPlotTabPages(TabControl tabControl, out bool itemsRemoved) { itemsRemoved = false; // Initialize the PlotTabPage_t[] array. PlotTabPage_t[] plotTabPages = new PlotTabPage_t[tabControl.TabPages.Count]; for (int tabIndex = 0; tabIndex < tabControl.TabPages.Count; tabIndex++) { plotTabPages[tabIndex].HeaderText = tabControl.TabPages[tabIndex].Text; plotTabPages[tabIndex].OldIdentifierList = new List<short>(); plotTabPages[tabIndex].DisplayMaskList = new List<uint>(); } TableLayoutPanel tableLayoutPanel; for (int tabIndex = 0; tabIndex < tabControl.TabPages.Count; tabIndex++) { // Get the TableLayoutPanel control assoiated with the current TabPage. tableLayoutPanel = tabControl.TabPages[tabIndex].Controls[KeyTableLayoutPanel] as TableLayoutPanel; Debug.Assert(tableLayoutPanel != null, "FormDataStreamPlot.ConstructPlotTabPages - [tableLayoutPanel != null]"); // Skip if there are no plotter controls associated with the TableLayoutPanel. TableLayoutControlCollection controlCollection = tableLayoutPanel.Controls; if (controlCollection.Count == 0) { continue; ; } short oldIdentifierPrevious = CommonConstants.NotDefined; for (int controlIndex = 0; controlIndex < controlCollection.Count; controlIndex++) { // Get the old identifier associated with the plot. IPlotterWatch plotterWatch = controlCollection[controlIndex] as IPlotterWatch; // Skip if the control does not implement the IPlotterWatch interface. if (plotterWatch == null) { continue; } short oldIdentifier = plotterWatch.Identifier; // Check whether the old identifier is valid. try { WatchVariable watchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[oldIdentifier]; // Check whether the watch variable exists. if (watchVariable == null) { // No, skip this entry. continue; } } catch (Exception) { continue; } if ((plotterWatch as IPlotterScalar) != null) { if (plotterWatch.Removed == false) { plotTabPages[tabIndex].OldIdentifierList.Add(oldIdentifier); plotTabPages[tabIndex].DisplayMaskList.Add(uint.MaxValue); } else { itemsRemoved = true; } oldIdentifierPrevious = oldIdentifier; } else if ((plotterWatch as IPlotterEnumerator) != null) { if (plotterWatch.Removed == false) { plotTabPages[tabIndex].OldIdentifierList.Add(oldIdentifier); plotTabPages[tabIndex].DisplayMaskList.Add(uint.MaxValue); } else { itemsRemoved = true; } oldIdentifierPrevious = oldIdentifier; } else if ((plotterWatch as IPlotterBitmask) != null) { if (plotterWatch.Removed == false) { // A flag to indicate whether the plot is associated with: (true) a new bitmask watch variable or (false) another bit of // the current bitmask watch variable. bool newBitmask; // Check whether this represents a new bitmask watch variable or the plot of another bit of an existing bitmask watch // variable. if (oldIdentifier != oldIdentifierPrevious) { newBitmask = true; oldIdentifierPrevious = oldIdentifier; } else { newBitmask = false; } // Determine which bit of the bitmask the plot represents. ulong bitMask = (ulong)0x01 << (plotterWatch as IPlotterBitmask).Bit; if (newBitmask == true) { plotTabPages[tabIndex].OldIdentifierList.Add(oldIdentifier); plotTabPages[tabIndex].DisplayMaskList.Add((uint)bitMask); } else { // Get the value for the last entry in the DisplayMask list. int count = plotTabPages[tabIndex].DisplayMaskList.Count; uint displayMask = plotTabPages[tabIndex].DisplayMaskList[count - 1]; // Assert the current bit. displayMask |= (uint)bitMask; plotTabPages[tabIndex].DisplayMaskList.RemoveAt(count - 1); plotTabPages[tabIndex].DisplayMaskList.Add(displayMask); } } else { itemsRemoved = true; } } } } return plotTabPages; }
/// <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; }