Ejemplo n.º 1
0
        /// <summary>
        /// Add a union data element.
        /// </summary>
        /// <param name="parentNode">parent that contains this union element</param>
        /// <param name="at">position where the new node is inserted before</param>
        /// <param name="defineType">if true invokes a define union type window</param>
        public void addUnionTypeNode(DataNode parentNode, int at, bool defineType)
        {
            FormUnion formUnion = new FormUnion();
            if (defineType)
            {
                formUnion.TypeName = "MyUnionType-" + Convert.ToString(++typeUnionCounter_);
            }
            else
            {
                formUnion.Text = "Build a union element";
                formUnion.ChangeLabel("Var Name:");
                formUnion.TypeName = "myUnion-" + Convert.ToString(parentNode.Nodes.Count);	//TODO: check for duplicate name
            }
            formUnion.setDataTypeSource(document_.getTypeNames());
            DialogResult r = formUnion.ShowDialog(view_);
            if (r==DialogResult.OK)
            {
                string varName = formUnion.TypeName;
                string discriminantType = formUnion.DiscriminantType;
                string blockSize = formUnion.BlockSize;
                int nBlockSize = 0;
                try
                {
                    nBlockSize = Convert.ToInt32(blockSize);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                UnionNode un = new UnionNode((defineType)?"":varName);
                un.setDiscriminantType(discriminantType);
                if (nBlockSize > 0)
                {
                    un.setBlockSize(nBlockSize);
                }
                AbstractNode aNode = un;
                if (defineType)
                {
                    aNode = new DefineTypeNode(formUnion.TypeName, un);
                }
                DataNode dn = new DataNode(aNode);

                int n = 0;
                foreach (ListViewItem itm in formUnion.getCases())
                {
                    string sval = itm.Text;
                    string stype = itm.SubItems[1].Text;
                    string svname = itm.SubItems[2].Text;
                    if (!stype.Equals(""))
                    {
                        //create a CaseNode
                        CaseNode cn = new CaseNode(sval, null);
                        //add data object as child node and case body of the case node
                        DataNode dcn = new DataNode(cn);
                        addChildNode(dcn, stype, svname);
                        addChildNode(dn, dcn, n++);
                    }
                }
                addChildNode(parentNode, dn, at);
                document_.setModified();
                parentNode.ExpandAll();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add a union data element.
        /// </summary>
        /// <param name="parentNode">parent that contains this union element</param>
        /// <param name="at">position where the new node is inserted before</param>
        /// <param name="defineType">if true invokes a define union type window</param>
        public void addUnionTypeNode(DataNode parentNode, int at, bool defineType)
        {
            FormUnion formUnion = new FormUnion();

            if (defineType)
            {
                formUnion.TypeName = "MyUnionType-" + Convert.ToString(++typeUnionCounter_);
            }
            else
            {
                formUnion.Text = "Build a union element";
                formUnion.ChangeLabel("Var Name:");
                formUnion.TypeName = "myUnion-" + Convert.ToString(parentNode.Nodes.Count);                     //TODO: check for duplicate name
            }
            formUnion.setDataTypeSource(document_.getTypeNames());
            DialogResult r = formUnion.ShowDialog(view_);

            if (r == DialogResult.OK)
            {
                string varName          = formUnion.TypeName;
                string discriminantType = formUnion.DiscriminantType;
                string blockSize        = formUnion.BlockSize;
                int    nBlockSize       = 0;
                try
                {
                    nBlockSize = Convert.ToInt32(blockSize);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                UnionNode un = new UnionNode((defineType)?"":varName);
                un.setDiscriminantType(discriminantType);
                if (nBlockSize > 0)
                {
                    un.setBlockSize(nBlockSize);
                }
                AbstractNode aNode = un;
                if (defineType)
                {
                    aNode = new DefineTypeNode(formUnion.TypeName, un);
                }
                DataNode dn = new DataNode(aNode);

                int n = 0;
                foreach (ListViewItem itm in formUnion.getCases())
                {
                    string sval   = itm.Text;
                    string stype  = itm.SubItems[1].Text;
                    string svname = itm.SubItems[2].Text;
                    if (!stype.Equals(""))
                    {
                        //create a CaseNode
                        CaseNode cn = new CaseNode(sval, null);
                        //add data object as child node and case body of the case node
                        DataNode dcn = new DataNode(cn);
                        addChildNode(dcn, stype, svname);
                        addChildNode(dn, dcn, n++);
                    }
                }
                addChildNode(parentNode, dn, at);
                document_.setModified();
                parentNode.ExpandAll();
            }
        }