Beispiel #1
0
        private void ColorNode(TreeGridNode node)
        {
            int           index = (int)node.Cells["IndexColumn"].Value, indexSec = (int)node.Cells["SecondaryIndexColumn"].Value;
            RegisterEntry entry = RegList[index];

            //MessageBox.Show(entry.GetName() + ": [" + index + ", " + indexSec + "]");
            if (indexSec != -1)
            {
                entry = entry.GetFields()[indexSec];
            }
            for (int i = 0; i < treeGridView1.ColumnCount; i++)
            {
                if (entry.GetIsComment())
                {
                    node.Cells[i].Style.BackColor = Color.LimeGreen;
                }
                else if (!entry.GetValid())
                {
                    node.Cells[i].Style.BackColor = Color.Red;
                }
                else
                {
                    node.Cells[i].Style.BackColor = Color.White;
                }
            }
        }
Beispiel #2
0
        private void TreeGridView1_SelectionChanged(object sender, EventArgs e)
        {
            RegisterEntry re = null;

            foreach (TreeGridNode item in treeGridView1.SelectedRows)
            {
                try
                {
                    re = RegList[(int)item.Cells["IndexColumn"].Value];
                    int index = (int)item.Cells["SecondaryIndexColumn"].Value;
                    if (index != -1)
                    {
                        re = re.GetFields()[index];
                        //MessageBox.Show(re.GetIndex().ToString() + ", " + index);
                    }
                    else
                    {
                        //MessageBox.Show(re.GetIndex().ToString());
                    }
                    break;
                }
                catch (NullReferenceException)
                {
                    //do nothing for groups
                    return;
                }
            }
            if (re != null)
            {
                RegNameText.Text = re.GetName();
                CommentText.Text = re.GetComment();
                InitText.Text    = re.GetInit();
                int index = LSBOpts.FindStringExact(re.GetLSB().ToString());
                if (index == -1)
                {
                    index = 0;
                }
                LSBOpts.SelectedIndex = index;
                index = LSBOpts.FindStringExact(re.GetLSB().ToString());
                if (index == -1)
                {
                    index = 0;
                }
                LSBOpts.SelectedIndex = index;
                index = MSBOpts.FindStringExact(re.GetMSB().ToString());
                if (index == -1)
                {
                    index = 31;
                }
                MSBOpts.SelectedIndex = index;
                index = MAISOpts.FindStringExact(re.GetMAIS().ToString());
                if (index == -1)
                {
                    index = 0;
                }
                MAISOpts.SelectedIndex = index;
                index = TypeOpts.FindStringExact(re.GetRegType().ToString());
                if (index == -1)
                {
                    index = 0;
                }
                TypeOpts.SelectedIndex = index;
                index = FPGAOpts.FindStringExact(re.GetFPGA().ToString());
                if (index == -1)
                {
                    index = 0;
                }
                FPGAOpts.SelectedIndex     = index;
                RegGroupOpts.SelectedIndex = RegGroupOpts.FindStringExact(re.GetGroup());

                if (re.GetIsComment())
                {
                    ErrorMessage.Text = "";
                }
                else if (!re.GetValid())
                {
                    ErrorMessage.Text = re.GetReason();
                }
                else
                {
                    ErrorMessage.Text = "";
                }
            }
        }
Beispiel #3
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            if (PathToFile.Text.Equals(""))
            {
                SaveAsButton_Click(sender, e);
                return;
            }
            StreamReader file;

            try
            {
                file = new StreamReader("mycorrect.txt");
                string line;
                string res      = "";
                string title    = Path.GetFileNameWithoutExtension(PathToFile.Text);
                string date     = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");
                string introDec = "Original path: " + PathToFile.Text + "</br>The following is a documentation for " + title + ". The table " +
                                  "contains the registers created using the GUI.";
                //MessageBox.Show(Path.GetFileNameWithoutExtension(PathToFile.Text));
                string doc = "<html><head><title>" + title + " Documentation" + "</title>";
                doc += "<style>table, th, td { border: 1px solid black; } th, td {padding: 5px; text-align: center;}" + "</style></head><body>";
                doc += "<h1><font face = 'arial'><u>Documentation For " + title + "</h1></u>";
                doc += date;
                doc += "<h2>" + date + "<br/>" + introDec + "</h2>";
                doc += "<table style='width: 100 %'>";
                doc += "<tr><th>Name</th><th>Group</th><th>Address</th><th>Mais</th><th>LSB</th><th>MSB</th><th>TYPE</th><th>FPGA</th><th>Init</th><th>Comment</th></tr>";
                TreeGridNode last_node = null;
                for (int i = treeGridView1.Nodes.Count - 1; i >= 0; i--)
                {
                    TreeGridNode last_group = treeGridView1.Nodes[i];
                    if (last_group.HasChildren)
                    {
                        last_node = last_group.Nodes[last_group.Nodes.Count - 1];
                        if (last_node.HasChildren)
                        {
                            last_node = last_node.Nodes[last_node.Nodes.Count - 1];
                        }
                        break;
                    }
                }
                RegisterEntry last = RegList[(int)last_node.Cells["IndexColumn"].Value];
                int           k    = (int)last_node.Cells["SecondaryIndexColumn"].Value;
                if (k != -1)
                {
                    last = last.GetFields()[k];
                    //MessageBox.Show()
                }
                while ((line = file.ReadLine()) != null)
                {
                    if (line.Length == 0)
                    {
                        res += "\n";
                        continue;
                    }
                    //System.Console.WriteLine(line);
                    if ('#' == line[0])
                    {
                        continue;
                    }
                    if (line.Equals("0o0o0o0o0o0o0o0o0o0o0o0o0o00o0o0o0o0o0o00o0o0o0o0o0"))
                    {
                        break;
                    }
                    res += line + "\n";
                }
                string prop = "", names = "";
                foreach (string group in RegGroupOpts.Items)
                {
                    names += "\t\t -- " + group + "\n";
                    prop  += "\t\t -- " + group + "\n";
                    foreach (RegisterEntry l in RegList)
                    {
                        if (l.GetGroup().Equals(group))
                        {
                            List <RegisterEntry> fields = l.GetFields();

                            names += l.toName();

                            prop += l.ToEntry(l == last);

                            doc += l.ToXMLstring();

                            foreach (RegisterEntry f in fields)
                            {
                                names += f.toName();

                                prop += f.ToEntry(f == last);

                                doc += f.ToXMLstring();
                            }
                        }
                    }
                }

                doc += "</table></font></body></html>";
                res += names;
                while ((line = file.ReadLine()) != null)
                {
                    //System.Console.WriteLine(line);
                    if (line.Length == 0)
                    {
                        res += "\n";
                        continue;
                    }
                    if ('#' == line[0])
                    {
                        continue;
                    }
                    if (line.Equals("0o0o0o0o0o0o0o0o0o0o0o0o0o00o0o0o0o0o0o00o0o0o0o0o0"))
                    {
                        break;
                    }
                    res += line + '\n';
                }
                res += prop;
                while ((line = file.ReadLine()) != null)
                {
                    //System.Console.WriteLine(line);
                    if (line.Length == 0)
                    {
                        res += "\n";
                        continue;
                    }
                    if ('#' == line[0])
                    {
                        continue;
                    }
                    res += line + '\n';
                }
                file.Close();
                try
                {
                    File.WriteAllText(PathToFile.Text, res);
                    //MessageBox.Show(Path.GetDirectoryName(PathToFile.Text) + "\\" + title + "_doc.txt");
                    File.WriteAllText(Path.GetDirectoryName(PathToFile.Text) + "\\" + title + "_doc.html", doc);
                    saved             = true;
                    ErrorMessage.Text = "File Saved!";
                }
                catch
                {
                    MessageBox.Show("Invalid Path to File");
                }
            }
            catch (IOException t)
            {
                MessageBox.Show("ArgumentException " + t.ToString());
            }
        }
Beispiel #4
0
        /* Edit a register */
        private void Load_Click(object sender, EventArgs e)
        {
            RegisterEntry re   = null;
            TreeGridNode  node = null;

            foreach (TreeGridNode item in treeGridView1.SelectedRows)
            {
                try
                {
                    re = RegList[(int)item.Cells["IndexColumn"].Value];
                    int index = (int)item.Cells["SecondaryIndexColumn"].Value;
                    if (index != -1)
                    {
                        re = re.GetFields()[index];
                    }
                    node = item;
                    break;
                }
                catch (NullReferenceException)
                {
                    //do nothing for groups
                    return;
                }
            }
            if (re == null)
            {
                MessageBox.Show("Please select a register in order to edit");
                return;
            }
            string name = RegNameText.Text;

            if (!re.GetName().Equals(name))
            {
                MessageBox.Show("You can't edit a register's name");
                RegNameText.Text = re.GetName();
                return;
            }
            string        mais    = MAISOpts.Text;
            string        lsb     = LSBOpts.Text;
            string        msb     = MSBOpts.Text;
            string        type    = TypeOpts.Text;
            string        fpga    = FPGAOpts.Text;
            string        init    = InitText.Text;
            string        comment = CommentText.Text;
            string        group   = RegGroupOpts.Text;
            RegisterEntry entry;
            int           i = re.GetIndex(), j = re.GetSecondaryIndex();

            if (i == -1)
            {
                MessageBox.Show("No such register " + name);
                InitFields();
                return;
            }
            entry = RegList[i];
            if (j != -1)
            {
                entry = entry.GetFields()[j];
            }
            if (entry.GetIsComment())
            {
                MessageBox.Show("This register is a comment and can't be edited");
                //InitFields();
                return;
            }
            Enum.TryParse(type, out RegisterEntry.type_field t);
            RegisterEntry.type_field s = entry.GetRegType();
            if ((s == RegisterEntry.type_field.FIELD && t != RegisterEntry.type_field.FIELD) ||
                s != RegisterEntry.type_field.FIELD && t == RegisterEntry.type_field.FIELD)
            {
                MessageBox.Show("Can't edit a field or create one using Load");
                TypeOpts.SelectedIndex = (int)s;
                return;
            }
            if (!RegisterEntry.IsValidLsbMsb(msb, lsb))
            {
                MessageBox.Show("Can't edit an entry to have LSB > MSB");
                //InitFields();
                return;
            }
            Enum.TryParse(fpga, out RegisterEntry.fpga_field r);
            entry.EditRegister(mais, lsb, msb, t, r, init, comment, group);
            OpenValidation();
            UpdateDataBase();
            EditCell(node, entry.GetTableEntry());
        }