コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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;
                        }
                    }
                }
            }
        }
コード例 #3
0
        private void ShowSignal(string SignalName)
        {
            if (!(oActiveLibrary == null))
            {
                oActiveSignal = oActiveLibrary.GetSignal(SignalName);

                if (!(oActiveSignal == null))
                {
                    Txt_SigName.Text     = oActiveSignal.Name;
                    Cmb_SigType.Text     = oActiveSignal.Type.ToString();
                    Txt_SigDecimal.Text  = oActiveSignal.Decimals.ToString();
                    Txt_SigUnit.Text     = oActiveSignal.Unit;
                    rTxt_SigComment.Text = oActiveSignal.Description;

                    foreach (DataGridViewRow GridRow in Grid_SignalProperties.Rows)
                    {
                        if (GridRow.HeaderCell.Value.ToString().Equals("Frequency"))
                        {
                            GridRow.Cells[0].Value = oActiveSignal.Properties.Frequency;
                        }
                        else if (GridRow.HeaderCell.Value.ToString().Equals("Magnitude"))
                        {
                            GridRow.Cells[0].Value = oActiveSignal.Properties.Magnitude;
                        }
                        else if (GridRow.HeaderCell.Value.ToString().Equals("Offset"))
                        {
                            GridRow.Cells[0].Value = oActiveSignal.Properties.Offset;
                        }
                        else if (GridRow.HeaderCell.Value.ToString().Equals("Phase"))
                        {
                            GridRow.Cells[0].Value = oActiveSignal.Properties.Phase;
                        }
                        else if (GridRow.HeaderCell.Value.ToString().Equals("Width"))
                        {
                            GridRow.Cells[0].Value = oActiveSignal.Properties.Width;
                        }
                        else if (GridRow.HeaderCell.Value.ToString().Equals("StartValue"))
                        {
                            GridRow.Cells[0].Value = oActiveSignal.Properties.StartValue;
                        }
                        else if (GridRow.HeaderCell.Value.ToString().Equals("EndValue"))
                        {
                            GridRow.Cells[0].Value = oActiveSignal.Properties.EndValue;
                        }
                        else if (GridRow.HeaderCell.Value.ToString().Equals("Slope"))
                        {
                            GridRow.Cells[0].Value = oActiveSignal.Properties.Slope;
                        }
                        else if (GridRow.HeaderCell.Value.ToString().Equals("StartTime"))
                        {
                            GridRow.Cells[0].Value = oActiveSignal.Properties.StartTime;
                        }
                        else if (GridRow.HeaderCell.Value.ToString().Equals("MinValue"))
                        {
                            GridRow.Cells[0].Value = oActiveSignal.Properties.MinValue;
                        }
                        else if (GridRow.HeaderCell.Value.ToString().Equals("MaxValue"))
                        {
                            GridRow.Cells[0].Value = oActiveSignal.Properties.MaxValue;
                        }
                    }

                    TabCtrl_PropertiesEdit.SelectedIndex = 1;

                    Cmd_SigCreate.Text = "Modify";
                }
            }
        }
コード例 #4
0
        private bool SetActiveSignal()
        {
            if (oActiveSignal == null)
            {
                oActiveSignal = new CS_BuiltInSignal();
            }

            if (!(Txt_SigName.Text.Equals("")))
            {
                if (!(Txt_SigName.Text.Contains(":")))                 //":" Is used as separator between library & signal name for signal list in Cycle/Data Association form
                {
                    oActiveSignal.Name = Txt_SigName.Text;
                }
                else
                {
                    MessageBox.Show("Signal name cannot contains ':' !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }
            }
            else
            {
                MessageBox.Show("Signal must have a name !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }


            oActiveSignal.Unit        = Txt_SigUnit.Text;
            oActiveSignal.Description = rTxt_SigComment.Text;

            if (Cmb_SigType.SelectedIndex > 0)
            {
                oActiveSignal.Type = (CS_BuiltInSignalType)Enum.Parse(typeof(CS_BuiltInSignalType), Cmb_SigType.Text);
            }
            else
            {
                MessageBox.Show("Signal must have a type !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }

            if (!(Txt_SigDecimal.Text.Equals("")))
            {
                int dec = 0;
                if (int.TryParse(Txt_SigDecimal.Text, out dec))
                {
                    oActiveSignal.Decimals = dec;
                }
                else
                {
                    MessageBox.Show("Decimals of the signal must be a number !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }
            }
            else
            {
                oActiveSignal.Decimals = 0;
            }

            oActiveSignal.Properties = new CS_BuiltInSignalProperties();

            foreach (DataGridViewRow GridRow in Grid_SignalProperties.Rows)
            {
                double dec = 0;
                if (double.TryParse(GridRow.Cells[0].Value.ToString(), out dec))
                {
                    if (GridRow.HeaderCell.Value.ToString().Equals("Frequency"))
                    {
                        oActiveSignal.Properties.Frequency = dec;
                    }
                    else if (GridRow.HeaderCell.Value.ToString().Equals("Magnitude"))
                    {
                        oActiveSignal.Properties.Magnitude = dec;
                    }
                    else if (GridRow.HeaderCell.Value.ToString().Equals("Offset"))
                    {
                        oActiveSignal.Properties.Offset = dec;
                    }
                    else if (GridRow.HeaderCell.Value.ToString().Equals("Phase"))
                    {
                        oActiveSignal.Properties.Phase = dec;
                    }
                    else if (GridRow.HeaderCell.Value.ToString().Equals("Width"))
                    {
                        oActiveSignal.Properties.Width = dec;
                    }
                    else if (GridRow.HeaderCell.Value.ToString().Equals("StartValue"))
                    {
                        oActiveSignal.Properties.StartValue = dec;
                    }
                    else if (GridRow.HeaderCell.Value.ToString().Equals("EndValue"))
                    {
                        oActiveSignal.Properties.EndValue = dec;
                    }
                    else if (GridRow.HeaderCell.Value.ToString().Equals("Slope"))
                    {
                        oActiveSignal.Properties.Slope = dec;
                    }
                    else if (GridRow.HeaderCell.Value.ToString().Equals("StartTime"))
                    {
                        oActiveSignal.Properties.StartTime = dec;
                    }
                    else if (GridRow.HeaderCell.Value.ToString().Equals("MinValue"))
                    {
                        oActiveSignal.Properties.MinValue = dec;
                    }
                    else if (GridRow.HeaderCell.Value.ToString().Equals("MaxValue"))
                    {
                        oActiveSignal.Properties.MaxValue = dec;
                    }
                    else                     //Unknown properties...
                    {
                        MessageBox.Show("Unknown property " + GridRow.HeaderCell.Value.ToString() + " !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(false);
                    }
                }
                else
                {
                    MessageBox.Show("Property " + GridRow.HeaderCell.Value.ToString() + " of the signal must be a number !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }
            }

            return(true);
        }
コード例 #5
0
        private void Cmd_SigCreateClick(object sender, EventArgs e)
        {
            if (!(Txt_SigName.Text.Equals("")))
            {
                if (Cmd_SigCreate.Text.Equals("Create"))                 //Creation of a new signal
                {
                    if (!oActiveLibrary.SignalExists(Txt_SigName.Text))
                    {
                        oActiveSignal = new CS_BuiltInSignal();

                        if (SetActiveSignal())
                        {
                            //Add the channel into the active library
                            oActiveSignal.ParentLibrary = oActiveLibrary;
                            oActiveLibrary.Signals.Add(oActiveSignal);
                            oActiveLibrary.bModified = true;

                            //Set flag to make the main form reloading libraries
                            bFrmMain_ReloadLibraries = true;

                            //Add the channel node to the library node
                            TreeNode nLib = GetLibraryNode(oActiveLibrary.Name);
                            if (!(nLib == null))
                            {
                                nLib.Nodes.Add(oActiveSignal.Name, oActiveSignal.Name, 1, 1);
                                nLib.Expand();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Signal " + Txt_SigName.Text + " already exists in the library " + oActiveLibrary.Name + " !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else                 //Modification of an existing channel
                {
                    int      ChanIndex = oActiveLibrary.GetSignalIndex(oActiveSignal.Name);
                    TreeNode ChanNode  = GetChannelNode(oActiveLibrary.Name, oActiveSignal.Name);

                    bool bExist = false;
                    for (int iChan = 0; iChan < oActiveLibrary.Signals.Count; iChan++)
                    {
                        if (!(iChan == ChanIndex))
                        {
                            if (oActiveLibrary.Signals[iChan].Name.Equals(Txt_SigName.Text))
                            {
                                bExist = true;
                                break;
                            }
                        }
                    }

                    if (!bExist)
                    {
                        if (SetActiveSignal())
                        {
                            oActiveLibrary.bModified = true;
                            ChanNode.Text            = oActiveSignal.Name;

                            //Set flag to make the main form reloading libraries
                            bFrmMain_ReloadLibraries = true;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Signal " + Txt_SigName.Text + " already exists in the library " + oActiveLibrary.Name + " !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            else
            {
                MessageBox.Show("Signal must have a name !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
コード例 #6
0
        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;
                    }
                }
            }
        }