public void Set_UserLibrary(CS_BuiltInSignalLibrary UserLib) { foreach (CS_BuiltInSignalLibrary oLib in oBSLibCollection.Libraries) { if (oLib.Name.Equals(UserLib.Name)) { return; //Library is already part of active libraries (BuiltInSignals.xml) } } oBSLibCollection.Libraries.Add(UserLib); AddLibrary(UserLib); }
private void AddLibrary(CS_BuiltInSignalLibrary oNewLib) { if (!(oNewLib == null)) { TreeNode nLib = TV_Libraries.Nodes.Add(oNewLib.Name, oNewLib.Name, 0, 0); foreach (CS_BuiltInSignal oSignal in oNewLib.Signals) { nLib.Nodes.Add(oSignal.Name, oSignal.Name, 1, 1); } nLib.Expand(); } }
private void UpDateActiveObjects(TreeNode ActiveNode) { if (!(ActiveNode == null)) { if (ActiveNode.Level == 0) { oActiveLibrary = oBSLibCollection.GetLibrary(ActiveNode.Text); ShowActiveLibrary(); } else if (ActiveNode.Level == 1) { oActiveLibrary = oBSLibCollection.GetLibrary(ActiveNode.Parent.Text); ShowSignal(ActiveNode.Text); } } }
private void OpenLibrary() { Dlg_OpenFile.FileName = ""; Dlg_OpenFile.Filter = "CANStream Built-in Signals | *.cbs"; Dlg_OpenFile.InitialDirectory = CANStreamTools.MyDocumentPath + "\\CANStream\\Built-In Signals libraries"; if (Dlg_OpenFile.ShowDialog().Equals(DialogResult.OK)) { oActiveLibrary = new CS_BuiltInSignalLibrary(); if (oActiveLibrary.ReadLibraryFile(Dlg_OpenFile.FileName)) { oBSLibCollection.AddLibrary(oActiveLibrary); AddLibrary(oActiveLibrary); bFrmMain_ReloadLibraries = true; } } }
private CS_BuiltInSignalLibrary CloneLibrary(CS_BuiltInSignalLibrary OriginalLib) { if (!(OriginalLib == null)) { CS_BuiltInSignalLibrary CloneLib = new CS_BuiltInSignalLibrary(); CloneLib.Name = OriginalLib.Name; CloneLib.Comment = OriginalLib.Comment; CloneLib.ReadOnly = OriginalLib.ReadOnly; foreach (CS_BuiltInSignal oSignal in OriginalLib.Signals) { CloneLib.Signals.Add(OriginalLib.CloneSignal(oSignal)); } return(CloneLib); } return(null); }
public Frm_BuiltInSignal(MainForm FrmMain) { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); //Library collection init oBSLibCollection = new CS_BuiltInSignalLibCollection(); if (File.Exists(CANStreamTools.CsDataPath + "\\BuiltInSignals.xml")) { if (oBSLibCollection.LoadLibrariesList(CANStreamTools.CsDataPath + "\\\\BuiltInSignals.xml")) { foreach (CS_BuiltInSignalLibrary oLib in oBSLibCollection.Libraries) { AddLibrary(oLib); } } } oActiveLibrary = null; oActiveSignal = null; oClipBoardItem = null; bCutOption = false; FrmParent = FrmMain; bFrmMain_ReloadLibraries = false; Cmb_SigType.Items.Clear(); string[] SigTypes = Enum.GetNames(typeof(CS_BuiltInSignalType)); foreach (string sSigTyp in SigTypes) { Cmb_SigType.Items.Add(sSigTyp); } }
/// <summary> /// Read the cycle configuration in a XML file /// </summary> /// <param name="fPath">Path of the file to read</param> /// <returns>Reading error flag: True = No Error / False = Error</returns> public bool Read_CycleConfiguration(string fPath) { if (!(fPath.Equals(""))) { XmlDocument oCycleConfig = new XmlDocument(); oCycleConfig.Load(fPath); XmlNode xCycleCfg = oCycleConfig.SelectSingleNode("CycleConfiguration"); if (!(xCycleCfg == null)) { //CAN Configuration XmlNode xCanCfg = xCycleCfg.SelectSingleNode("CANConfiguration"); if (!(xCanCfg == null)) { CanConfiguration = new CANMessagesConfiguration(); if (!(CanConfiguration.ReadCANConfigurationXmlNode(xCanCfg))) { return(false); } } else { return(false); //Node CANConfiguration not found } //Virtual channels libraries XmlNode xVirtualLib = xCanCfg.NextSibling; if (xVirtualLib.Name.Equals("CS_VirtualChannelsLibrary")) { VirtualChannelLibCollection = new CS_VCLibrariesCollection(); while (xVirtualLib.Name.Equals("CS_VirtualChannelsLibrary")) { CS_VirtualChannelsLibrary oLib = new CS_VirtualChannelsLibrary(); oLib.ReadLibraryXmlNode(xVirtualLib); VirtualChannelLibCollection.AddLibrary(oLib); xVirtualLib = xVirtualLib.NextSibling; } } //Built-In signals libraries XmlNode xSignalLib = xVirtualLib; if (xSignalLib.Name.Equals("CS_BuiltInSignalsLibrary")) { BuiltInSignalLibCollection = new CS_BuiltInSignalLibCollection(); while (xSignalLib.Name.Equals("CS_BuiltInSignalsLibrary")) { CS_BuiltInSignalLibrary oLib = new CS_BuiltInSignalLibrary(); oLib.ReadLibraryXmlNode(xSignalLib); BuiltInSignalLibCollection.AddLibrary(oLib); xSignalLib = xSignalLib.NextSibling; } } //Cycle parts properties XmlNode xPartProps = xCycleCfg.SelectSingleNode("CyclePartsProperties"); if (!(xPartProps == null)) { //Pre-cycle XmlNode xPreCycleProps = xPartProps.SelectSingleNode("PreCycleProperties"); if (!(xPreCycleProps == null)) { XmlAttribute xAtr; xAtr = xPreCycleProps.Attributes["TimeLength"]; if (!(xAtr == null)) { double t = 0; if (double.TryParse(xAtr.Value, out t)) { PreCycleProperties.TimeLength = t; } else { return(false); //Value of attribute TimeLength is not a number } } else { return(false); //Attribute TimeLength not found in node PreCycleProperties } xAtr = xPreCycleProps.Attributes["DataFile"]; if (!(xAtr == null)) { PreCycleProperties.DataFile = xAtr.Value; } else { return(false); //Attribute DataFile not found in node PreCycleProperties } } else { return(false); //Node PreCycleProperties not found } //In-Cycle XmlNode xInCycleProps = xPartProps.SelectSingleNode("InCycleProperties"); if (!(xInCycleProps == null)) { XmlAttribute xAtr; xAtr = xInCycleProps.Attributes["TimeLength"]; if (!(xAtr == null)) { double t = 0; if (double.TryParse(xAtr.Value, out t)) { InCycleProperties.TimeLength = t; } else { return(false); //Value of attribute TimeLength is not a number } } else { return(false); //Attribute TimeLength not found in node InCycleProperties } xAtr = xInCycleProps.Attributes["DataFile"]; if (!(xAtr == null)) { InCycleProperties.DataFile = xAtr.Value; } else { return(false); //Attribute DataFile not found in node InCycleProperties } } else { return(false); //Node InCycleProperties not found } //Post-Cycle XmlNode xPostCycleProps = xPartProps.SelectSingleNode("PostCycleProperties"); if (!(xPostCycleProps == null)) { XmlAttribute xAtr; xAtr = xPostCycleProps.Attributes["TimeLength"]; if (!(xAtr == null)) { double t = 0; if (double.TryParse(xAtr.Value, out t)) { PostCycleProperties.TimeLength = t; } else { return(false); //Value of attribute TimeLength is not a number } } else { return(false); //Attribute TimeLength not found in node PostCycleProperties } xAtr = xPostCycleProps.Attributes["DataFile"]; if (!(xAtr == null)) { PostCycleProperties.DataFile = xAtr.Value; } else { return(false); //Attribute DataFile not found in node PostCycleProperties } } else { return(false); //Node PostCycleProperties not found } } else { return(false); //Node CyclePartsProperties not found } //Cycle parameters XmlNode xCycleParams = xCycleCfg.SelectSingleNode("CycleParameters"); if (!(xCycleParams == null)) { Parameters = new List <CycleParameter>(); foreach (XmlNode xParam in xCycleParams.ChildNodes) { CycleParameter oParam = new CycleParameter(); XmlAttribute xAtr; XmlNode xData; //Parameter Name xAtr = xParam.Attributes["Name"]; if (!(xAtr == null)) { if (!(xAtr.Value.Equals(""))) { oParam.Name = xAtr.Value; } else { return(false); //Value of attribute Name is empty } } else { return(false); //Attribute Name not found in node xParam } //Parameter Message Id xAtr = xParam.Attributes["MessageId"]; if (!(xAtr == null)) { if (!(xAtr.Value.Equals(""))) { oParam.MsgId = xAtr.Value; } else { return(false); //Value of attribute MessageId is empty } } else { return(false); //Attribute MessageId not found in node xParam } //Pre-Cycle data xData = xParam.SelectSingleNode("PreCycleData"); if (!(xData == null)) { //Source xAtr = xData.Attributes["Source"]; if (!(xAtr == null)) { CycleDataSource Src = CycleDataSource.None; if (Enum.TryParse(xAtr.Value, out Src)) { oParam.PreCycle.Source = Src; } else { return(false); //Value of attribute Source is not part of enumeration } } else { return(false); //Attribute Source not found in node PreCycleData } //Data xAtr = xData.Attributes["Data"]; if (!(xAtr == null)) { if (!(xAtr.Value.Equals(""))) { oParam.PreCycle.Data = xAtr.Value; } else { return(false); //Value of attribute Data is empty } } else { return(false); //Attribute Data not found in node PreCycleData } //Library xAtr = xData.Attributes["Library"]; if (!(xAtr == null)) { if (!(xAtr.Value.Equals(""))) { oParam.PreCycle.Library = xAtr.Value; } else { return(false); //Value of attribute Library is empty } } else { return(false); //Attribute Library not found in node PreCycleData } } else { return(false); //Node PreCycleData not found } //In-cycle data xData = xParam.SelectSingleNode("InCycleData"); if (!(xData == null)) { //Source xAtr = xData.Attributes["Source"]; if (!(xAtr == null)) { CycleDataSource Src = CycleDataSource.None; if (Enum.TryParse(xAtr.Value, out Src)) { oParam.InCycle.Source = Src; } else { return(false); //Value of attribute Source is not part of enumeration } } else { return(false); //Attribute Source not found in node InCycleData } //Data xAtr = xData.Attributes["Data"]; if (!(xAtr == null)) { if (!(xAtr.Value.Equals(""))) { oParam.InCycle.Data = xAtr.Value; } else { return(false); //Value of attribute Data is empty } } else { return(false); //Attribute Data not found in node InCycleData } //Library xAtr = xData.Attributes["Library"]; if (!(xAtr == null)) { if (!(xAtr.Value.Equals(""))) { oParam.InCycle.Library = xAtr.Value; } else { return(false); //Value of attribute Library is empty } } else { return(false); //Attribute Library not found in node InCycleData } } else { return(false); //Node InCycleData not found } xData = xParam.SelectSingleNode("PostCycleData"); if (!(xData == null)) { //Source xAtr = xData.Attributes["Source"]; if (!(xAtr == null)) { CycleDataSource Src = CycleDataSource.None; if (Enum.TryParse(xAtr.Value, out Src)) { oParam.PostCycle.Source = Src; } else { return(false); //Value of attribute Source is not part of enumeration } } else { return(false); //Attribute Source not found in node PostCycleData } //Data xAtr = xData.Attributes["Data"]; if (!(xAtr == null)) { if (!(xAtr.Value.Equals(""))) { oParam.PostCycle.Data = xAtr.Value; } else { return(false); //Value of attribute Data is empty } } else { return(false); //Attribute Data not found in node PostCycleData } //Library xAtr = xData.Attributes["Library"]; if (!(xAtr == null)) { if (!(xAtr.Value.Equals(""))) { oParam.PostCycle.Library = xAtr.Value; } else { return(false); //Value of attribute Library is empty } } else { return(false); //Attribute Library not found in node PostCycleData } } else { return(false); //Node PostCycleData not found } Parameters.Add(oParam); } } else { return(false); //Node CycleParameters not found } } else { return(false); //Node CycleConfiguration not found } } else { return(false); //Path empty } FilePath = fPath; bModified = false; return(true); //No Error }
private void PasteItem() { if (!(oClipBoardItem == null)) { if (oClipBoardItem.GetType().Equals(typeof(CS_BuiltInSignalLibrary))) //Paste of a library { oActiveLibrary = CloneLibrary((CS_BuiltInSignalLibrary)oClipBoardItem); //Rename library if (oBSLibCollection.LibraryExists(oActiveLibrary.Name)) { int i = 1; while (oBSLibCollection.LibraryExists(oActiveLibrary.Name + "_" + i.ToString("D2"))) { i++; } oActiveLibrary.Name = oActiveLibrary.Name + "_" + i.ToString("D2"); } oActiveLibrary.CollectionParent = oBSLibCollection; oBSLibCollection.AddLibrary(oActiveLibrary); AddLibrary(oActiveLibrary); //Set flag to make the main form reloading libraries bFrmMain_ReloadLibraries = true; if (bCutOption) { DeleteItem(oClipBoardItem, true); bCutOption = false; } } if (oClipBoardItem.GetType().Equals(typeof(CS_BuiltInSignal))) //Paste of a signal { if (!(oActiveLibrary == null)) { oActiveSignal = oActiveLibrary.CloneSignal((CS_BuiltInSignal)oClipBoardItem); //Rename channel (if needed) if (oActiveLibrary.SignalExists(oActiveSignal.Name)) { int i = 1; while (oActiveLibrary.SignalExists(oActiveSignal.Name + "_" + i.ToString("D2"))) { i++; } oActiveSignal.Name = oActiveSignal.Name + "_" + i.ToString("D2"); } oActiveSignal.ParentLibrary = oActiveLibrary; oActiveLibrary.Signals.Add(oActiveSignal); //Set flag to make the main form reloading libraries bFrmMain_ReloadLibraries = true; TreeNode nLib = GetLibraryNode(oActiveLibrary.Name); if (!(nLib == null)) { nLib.Nodes.Add(oActiveSignal.Name, oActiveSignal.Name, 1, 1); } if (bCutOption) { DeleteItem(oClipBoardItem, true); bCutOption = false; } } } } }
private void Cmd_LibCreateClick(object sender, EventArgs e) { if (!(Txt_LibName.Text.Equals(""))) { if (Cmd_LibCreate.Text.Equals("Create")) //Creation of a new library { if (!(oBSLibCollection.LibraryExists(Txt_LibName.Text))) { oActiveLibrary = new CS_BuiltInSignalLibrary(); //Create the new library and add it to the library collection if (!(Txt_LibName.Text.Equals(""))) { if (!(Txt_LibName.Text.Contains(":"))) //":" Is used as separator between library & signal name for signal list in Cycle/Data Association form { oActiveLibrary.Name = Txt_LibName.Text; } else { MessageBox.Show("Signal library name cannot contains ':' !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } else { MessageBox.Show("Signal library must have a name !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } oActiveLibrary.Comment = rTxt_LibComment.Text; oActiveLibrary.ReadOnly = Chk_LibReadOnly.Checked; oBSLibCollection.AddLibrary(oActiveLibrary); //Set flag to make the main form reloading libraries bFrmMain_ReloadLibraries = true; //Show the library in the treeview TreeNode nLib = TV_Libraries.Nodes.Add(oActiveLibrary.Name, oActiveLibrary.Name, 0); } else { MessageBox.Show("Library " + Txt_LibName.Text + " already exists !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else //Modification of an existing library { int LibIndex = oBSLibCollection.GetLibraryIndex(oActiveLibrary.Name); TreeNode nLib = GetLibraryNode(oActiveLibrary.Name); bool bExists = false; for (int i = 0; i < oBSLibCollection.Libraries.Count; i++) { if (!(i == LibIndex)) { if (oBSLibCollection.Libraries[i].Name.Equals(Txt_LibName.Text)) { bExists = true; break; } } } if (!bExists) { //Update library instance if (!(Txt_LibName.Text.Equals(""))) { if (!(Txt_LibName.Text.Contains(":"))) //":" Is used as separator between library & signal name for signal list in Cycle/Data Association form { oActiveLibrary.Name = Txt_LibName.Text; } else { MessageBox.Show("Signal library name cannot contains ':' !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } else { MessageBox.Show("Signal library must have a name !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } oActiveLibrary.Comment = rTxt_LibComment.Text; oActiveLibrary.ReadOnly = Chk_LibReadOnly.Checked; oActiveLibrary.bModified = true; //Update library node in the treeview nLib.Text = Txt_LibName.Text; } else { MessageBox.Show("Library " + Txt_LibName.Text + " already exists !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } else { MessageBox.Show("Library must have a name !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void DeleteItem(object Item, bool bForced) { if (Item == null) { Item = GetActiveItem(); } if (!(Item == null)) { if (Item.GetType().Equals(typeof(CS_BuiltInSignalLibrary))) { CS_BuiltInSignalLibrary oLib = (CS_BuiltInSignalLibrary)Item; bool bConfirmed = true; if (!bForced) { bConfirmed = MessageBox.Show("Do you really want to remove the library " + oLib.Name + " ?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) .Equals(DialogResult.Yes); } if (bConfirmed) { TV_Libraries.Nodes.Remove(GetLibraryNode(oLib.Name)); oBSLibCollection.Libraries.Remove(oLib); //Set flag to make the main form reloading libraries bFrmMain_ReloadLibraries = true; } } if (Item.GetType().Equals(typeof(CS_BuiltInSignal))) { CS_BuiltInSignal oSignal = (CS_BuiltInSignal)Item; if (!(oSignal.ParentLibrary == null)) { CS_BuiltInSignalLibrary oLib = oSignal.ParentLibrary; //Remove node from the treeview TreeNode nLib = GetLibraryNode(oLib.Name); if (!(nLib == null)) { foreach (TreeNode nSignal in nLib.Nodes) { if (nSignal.Text.Equals(oSignal.Name)) { nLib.Nodes.Remove(nSignal); break; } } } //Remove channel from the library oLib.Signals.Remove(oSignal); oLib.bModified = true; //Set flag to make the main form reloading libraries bFrmMain_ReloadLibraries = true; } } } }