/// <summary> /// Convert a CANStream SignalAlarmValue structure into a Ctrl_GraphWindow GraphReferenceLine class /// </summary> /// <param name="sAlarm">CANStream SignalAlarmValue structure to convert</param> /// <returns>Ctrl_GraphWindow GraphReferenceLine class</returns> private static GraphReferenceLine GetSerieReferenceLineFromAlarm(SignalAlarmValue sAlarm) { GraphReferenceLine oRefLine = new GraphReferenceLine(); oRefLine.ReferenceValue = sAlarm.Value; oRefLine.ReferenceStyle.LineColor = sAlarm.BackColor; oRefLine.ReferenceTitlePosition = ScreenPositions.Left; return(oRefLine); }
private void Grid_RefLines_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == REF_LINE_MODE_COL && (!(e.RowIndex == -1))) { if (Grid_RefLines.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString().Equals(GraphSerieReferenceLineModes.Custom.ToString())) { GraphReferenceLine oLine = Get_ReferenceLineAtKey((int)Grid_RefLines.Rows[e.RowIndex].Tag); if (!(oLine == null)) { Grid_RefLines.Rows[e.RowIndex].Cells[REF_LINE_VALUE_COL].Value = oLine.ReferenceValue.ToString(); Grid_RefLines.Rows[e.RowIndex].Cells[REF_LINE_VALUE_COL].ReadOnly = false; } } else { Grid_RefLines.Rows[e.RowIndex].Cells[REF_LINE_VALUE_COL].Value = "-"; Grid_RefLines.Rows[e.RowIndex].Cells[REF_LINE_VALUE_COL].ReadOnly = true; } } }
/// <summary> /// Read a XML data file /// </summary> /// <param name="fPath">Path of the XML file to read</param> /// <param name="HeaderOnly">Read only data file header flag</param> /// <returns>Reading error flag: True = No Error / False = Error</returns> public bool Load_XmlDataFile(string fPath, bool HeaderOnly) { XmlNode xDataFile, xHeader, xChannels, xSamples; XmlNode xElemParent, xElemChild; this.DataSamplingMode = SamplingMode.MultipleRates; try { XmlDocument oXDoc = new XmlDocument(); oXDoc.Load(fPath); xDataFile = oXDoc.SelectSingleNode("XmlGraphDataFile"); #region XML Data file header //Header reading xHeader = xDataFile.SelectSingleNode("DataFileHeader"); //Data file start time xElemChild = xHeader.SelectSingleNode("DataStartTime"); this.DataStartTime = DateTime.FromBinary(long.Parse(xElemChild.InnerText)); //User comment xElemChild = xHeader.SelectSingleNode("DataUserComment"); this.UserComment = xElemChild.InnerText; //Data file user properties xElemParent = xHeader.SelectSingleNode("DataCustomProperties"); foreach (XmlNode xProp in xElemParent.ChildNodes) { GW_XmlDataFileCustomProperty oProp = new GW_XmlDataFileCustomProperty(); oProp.Name = xProp.Attributes["CustomPropertyName"].Value; string PropType = xProp.Attributes["CustomPropertyType"].Value; oProp.ParsePropertyStringValue(xProp.InnerText, PropType); this.XmlDataFileCustomProperties.Add(oProp); } #endregion #region XML Data files channels //Data reading if (!HeaderOnly) { xChannels = xDataFile.SelectSingleNode("DataFileChannels"); foreach (XmlNode xChan in xChannels.ChildNodes) { GW_DataChannel oChan = new GW_DataChannel(SamplingMode.MultipleRates); //Read channel properties oChan.KeyId = int.Parse(xChan.Attributes["ChanId"].Value); xElemChild = xChan.SelectSingleNode("ChannelName"); oChan.Name = xElemChild.InnerText; xElemChild = xChan.SelectSingleNode("ChannelDescription"); oChan.Description = xElemChild.InnerText; xElemChild = xChan.SelectSingleNode("ChannelUnit"); oChan.Unit = xElemChild.InnerText; xElemChild = xChan.SelectSingleNode("ValueFormat"); oChan.GraphicFormat.SetSerieValueFormatFromXmlNode(xElemChild); xElemParent = xChan.SelectSingleNode("ChannelReferenceLines"); if (!(xElemParent == null)) { foreach (XmlNode xRefLine in xElemParent.ChildNodes) { GraphReferenceLine oLine = new GraphReferenceLine(); if (oLine.Read_GraphLineXmlNode(xRefLine)) { oChan.ChannelReferenceLines.Add(oLine); } } } //Read channel samples xSamples = xChan.SelectSingleNode("ChannelSamples"); foreach (XmlNode xSerieSample in xSamples.ChildNodes) { SerieSample sSample = new SerieSample(); sSample.SampleTime = double.Parse(xSerieSample.Attributes["ST"].Value); sSample.SampleValue = double.Parse(xSerieSample.InnerText); oChan.Samples.Add(sSample); if (oChan.Samples.Count == 1) { oChan.Min = sSample.SampleValue; oChan.Max = sSample.SampleValue; } else { if (sSample.SampleValue < oChan.Min) { oChan.Min = sSample.SampleValue; } if (sSample.SampleValue > oChan.Max) { oChan.Max = sSample.SampleValue; } } } this.Channels.Add(oChan); } } #endregion } catch { return(false); } return(true); }
private List <GraphReferenceLine> Set_ReferenceLines() { double dTmp = 0; int iTmp = 0; List <GraphReferenceLine> oTmpLines = new List <GraphReferenceLine>(); foreach (DataGridViewRow oRow in Grid_RefLines.Rows) { GraphReferenceLine oLine = new GraphReferenceLine(); oLine.iKey = (int)oRow.Tag; if (!(Enum.TryParse(oRow.Cells[REF_LINE_MODE_COL].Value.ToString(), out oLine.ReferenceMode))) { MessageBox.Show("Unkown reference mode for reference line #" + (Grid_RefLines.Rows.IndexOf(oRow) + 1).ToString() + " !", FORM_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } if (oLine.ReferenceMode.Equals(GraphSerieReferenceLineModes.Custom)) { if (!(oRow.Cells[REF_LINE_VALUE_COL].Value == null)) { if (double.TryParse(oRow.Cells[REF_LINE_VALUE_COL].Value.ToString(), out dTmp)) { oLine.ReferenceValue = dTmp; } else { MessageBox.Show("Reference value for reference line #" + (Grid_RefLines.Rows.IndexOf(oRow) + 1).ToString() + " must be a numeric value !", FORM_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } } else { MessageBox.Show("Reference value for reference line #" + (Grid_RefLines.Rows.IndexOf(oRow) + 1).ToString() + " cannot be empty !", FORM_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } } oLine.ReferenceTitle = oRow.Cells[REF_LINE_TITLE_COL].Value.ToString(); oLine.Visible = (bool)oRow.Cells[REF_LINE_VISIBLE_COL].Value; if (!(Enum.TryParse(oRow.Cells[REF_LINE_STYLE_COL].Value.ToString(), out oLine.ReferenceStyle.LineStyle))) { MessageBox.Show("Unkown line style for reference line #" + (Grid_RefLines.Rows.IndexOf(oRow) + 1).ToString() + " !", FORM_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } oLine.ReferenceStyle.LineColor = oRow.Cells[REF_LINE_COLOR_COL].Style.BackColor; if (!(oRow.Cells[REF_LINE_WIDTH_COL].Value == null)) { if (int.TryParse(oRow.Cells[REF_LINE_WIDTH_COL].Value.ToString(), out iTmp)) { if (iTmp < 20) { oLine.ReferenceStyle.LineWidth = iTmp; } else { MessageBox.Show("Line width for reference line #" + (Grid_RefLines.Rows.IndexOf(oRow) + 1).ToString() + " must be less than 20 !", FORM_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } } else { MessageBox.Show("Line width for reference line #" + (Grid_RefLines.Rows.IndexOf(oRow) + 1).ToString() + " must be a numeric value !", FORM_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } } else { MessageBox.Show("Line width for reference line #" + (Grid_RefLines.Rows.IndexOf(oRow) + 1).ToString() + " cannot be empty !", FORM_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } if (!(Enum.TryParse(oRow.Cells[REF_LINE_VALUE_POS_COL].Value.ToString(), out oLine.ReferenceValuePosition))) { MessageBox.Show("Unkown value position for reference line #" + (Grid_RefLines.Rows.IndexOf(oRow) + 1).ToString() + " !", FORM_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } if (!(Enum.TryParse(oRow.Cells[REF_LINE_TITLE_POS_COL].Value.ToString(), out oLine.ReferenceTitlePosition))) { MessageBox.Show("Unkown title position for reference line #" + (Grid_RefLines.Rows.IndexOf(oRow) + 1).ToString() + " !", FORM_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } Font CellTag = (Font)oRow.Cells[REF_LINE_FONT].Tag; oLine.ReferenceValueFont = new GW_Font(CellTag.Name, CellTag.Size, CellTag.Bold, CellTag.Italic, true, CellTag.Strikeout, CellTag.Underline); oTmpLines.Add(oLine); } return(oTmpLines); }