Beispiel #1
0
        public HmiAttribute Clone()
        {
            HmiAttribute attr = new HmiAttribute();
            attr.InfoAttribute = this.InfoAttribute;

            attr.Name = new byte[Name.Length];
            attr.Data = new byte[Data.Length];
            attr.Note = new byte[Note.Length];

            Name.CopyTo(attr.Name, 0);
            Data.CopyTo(attr.Data, 0);
            Note.CopyTo(attr.Note, 0);

            return attr;
        }
        public HmiAttribute Clone()
        {
            HmiAttribute attr = new HmiAttribute();

            attr.InfoAttribute = this.InfoAttribute;

            attr.Name = new byte[Name.Length];
            attr.Data = new byte[Data.Length];
            attr.Note = new byte[Note.Length];

            Name.CopyTo(attr.Name, 0);
            Data.CopyTo(attr.Data, 0);
            Note.CopyTo(attr.Note, 0);

            return(attr);
        }
Beispiel #3
0
        public bool checkAttribute(HmiAttribute hmiAttr)
        {
            string note = Utility.GetString(hmiAttr.Note);
            if (note.Contains("~"))
            {
                byte[] attrVal;
                string[] attrs = note.Split(Utility.CHAR_TILDA);
                if (attrs.Length != 2)
                {
                    MessageBox.Show("Component attribute error:0".Translate());
                    return false;
                }

                string[] nameValue = attrs[1].Split(Utility.CHAR_EQUAL);
                if (nameValue.Length != 2)
                {
                    nameValue = attrs[1].Split(Utility.CHAR_GREAT);
                    if (nameValue.Length != 2)
                    {
                        MessageBox.Show("Component attribute error:1".Translate());
                        return false;
                    }
                    attrVal = GetAttributeValue(nameValue[0]);
                    if (attrVal != null
                     && attrVal.Length > 0
                     && attrVal[0] < byte.Parse(nameValue[1])
                        )
                        return false;
                }
                else
                {
                    attrVal = GetAttributeValue(nameValue[0]);
                    if (attrVal != null
                     && attrVal.Length > 0
                     && attrVal[0].ToString() != nameValue[1]
                        )
                        return false;
                }
            }

            if (hmiAttr.InfoAttribute.IsBinding == 1)
                IsBinding = 1;
            return true;
        }
Beispiel #4
0
        public void RefreshObject(HmiApplication app, HmiPage page, HmiObject obj)
        {
            if (app == null || page == null || obj == null)
            {
                Clear();
                return;
            }

            m_app  = app;
            m_page = page;
            m_obj  = obj;

            dataGrid.Rows.Clear();
            cbAttrValues.Visible = false;
            m_selectedRow        = -1;

            if (m_obj.Attributes.Count < 1)
            {
                MessageBox.Show("Control property data header error".Translate());
                return;
            }

            byte[] buffer = new byte[1];
            byte[] buffer2 = new byte[1];
            string objType = "";
            int    num3, row;

            dataGrid.Rows.Add();
            row = dataGrid.Rows.Count - 1;
            dataGrid.Rows[row].Cells["colValue"].Value = m_obj.ObjName;
            dataGrid.Rows[row].Cells["colName"].Value  = "objname";
            dataGrid.Rows[row].Cells["colType"].Value  = "objname";
            dataGrid.Rows[row].Cells["colInfo"].Value  = "Component name".Translate();
            if (m_obj.Attributes[0].Data[0] == HmiObjType.PAGE)
            {
                dataGrid.Rows[row].Cells["colValue"].ReadOnly = true;
            }
            else
            {
                dataGrid.Rows[row].Cells["colValue"].ReadOnly = false;
            }

            DataGridViewCellStyle style = new DataGridViewCellStyle
            {
                Font = new Font(dataGrid.Font.FontFamily, dataGrid.Font.Size, FontStyle.Regular)
            };

            dataGrid.Rows[row].DefaultCellStyle = style;
            m_obj.IsBinding = 0;
            for (int i = 1; i < m_obj.Attributes.Count; i++)
            {
                HmiAttribute attr = m_obj.Attributes[i];
                if ((m_obj.checkAttribute(attr) &&
                     (i != 1 ||
                      (m_obj.Attributes[0].Data[0] != HmiObjType.OBJECT_TYPE_CURVE &&
                       m_obj.Attributes[0].Data[0] != HmiObjType.TIMER
                      )
                     )
                     ) &&
                    attr.InfoAttribute.AttrType < 15
                    )
                {
                    dataGrid.Rows.Add();
                    row = dataGrid.Rows.Count - 1;
                    if (attr.InfoAttribute.AttrType < HmiAttributeType.String)
                    {
                        if (attr.InfoAttribute.Length == 1)
                        {
                            if (attr.InfoAttribute.AttrType == 5)
                            {
                                num3 = m_obj.GetNoteLength(Utility.GetString(attr.Name), true) - 1;
                                dataGrid.Rows[row].Cells["colValue"].Value = num3.ToString();
                            }
                            else if (attr.InfoAttribute.AttrType == HmiAttributeType.Selection)
                            {
                                style = new DataGridViewCellStyle
                                {
                                    BackColor = Color.FromArgb(0xe0, 0xe0, 0xe0),
                                    ForeColor = Color.Black
                                };
                                dataGrid.Rows[row].Cells["colValue"].Value = attr.Data[0].ToString();
                                string[] strArray = Utility.GetString(attr.Note).Split(Utility.CHAR_COLON);
                                if (strArray.Length > 1)
                                {
                                    strArray = strArray[1].Split(Utility.CHAR_SEMICOLON);
                                    if (Utility.GetInt(attr.Data[0].ToString()) < strArray.Length)
                                    {
                                        strArray = strArray[Utility.GetInt(attr.Data[0].ToString())].Split(Utility.CHAR_MINUS);
                                        if (strArray.Length == 2)
                                        {
                                            dataGrid.Rows[row].Cells["colValue"].Value = strArray[1];
                                        }
                                    }
                                }
                                dataGrid.Rows[row].DefaultCellStyle = style;
                            }
                            else
                            {
                                dataGrid.Rows[row].Cells["colValue"].Value = attr.Data[0].ToString();
                            }
                        }
                        else if (attr.InfoAttribute.Length == 2)
                        {
                            if (attr.InfoAttribute.AttrType == 1 && attr.Data.ToU16() == 0x350b)
                            {
                                dataGrid.Rows[row].Cells["colValue"].Value = "";
                            }
                            else if (attr.InfoAttribute.AttrType == 2 && attr.Data.ToU16() == 0xffff)
                            {
                                dataGrid.Rows[row].Cells["colValue"].Value = "";
                            }
                            else
                            {
                                dataGrid.Rows[row].Cells["colValue"].Value = attr.Data.ToU16().ToString();
                            }
                        }
                        else if (attr.InfoAttribute.Length == 4)
                        {
                            dataGrid.Rows[row].Cells["colValue"].Value = attr.Data.ToU32().ToString();
                        }
                    }
                    else
                    {
                        dataGrid.Rows[row].Cells["colValue"].Value = Utility.GetString(attr.Data);
                    }

                    dataGrid.Rows[row].Cells["colName"].Value      = Utility.GetString(attr.Name);
                    dataGrid.Rows[row].Cells["colType"].Value      = attr.InfoAttribute.AttrType.ToString();
                    dataGrid.Rows[row].Cells["colInfo"].Value      = Utility.GetString(attr.Note, Encoding.ASCII.GetBytes("~")[0]);
                    dataGrid.Rows[row].Cells["colIsBinding"].Value = attr.InfoAttribute.IsBinding.ToString();
                    dataGrid.Rows[row].Cells["colCanModify"].Value = attr.InfoAttribute.IsBinding.ToString();

                    if (attr.InfoAttribute.AttrType == HmiAttributeType.PicId ||
                        attr.InfoAttribute.AttrType == HmiAttributeType.Color ||
                        attr.InfoAttribute.AttrType == HmiAttributeType.Selection)
                    {
                        dataGrid.Rows[row].Cells["colValue"].ReadOnly = true;
                    }
                    else
                    {
                        dataGrid.Rows[row].Cells["colValue"].ReadOnly = false;
                    }

                    style = new DataGridViewCellStyle();
                    if (attr.InfoAttribute.CanModify == 1)
                    {
                        style.BackColor = Color.White;
                        style.ForeColor = Color.Green;
                        dataGrid.Rows[row].DefaultCellStyle = style;
                    }

                    if (attr.InfoAttribute.IsReturn == 1)
                    {
                        style.Font = new Font(dataGrid.Font.FontFamily, dataGrid.Font.Size, FontStyle.Bold);
                        dataGrid.Rows[row].DefaultCellStyle = style;
                    }
                }
            }

            if (m_obj.Attributes[0].Data[0] != HmiObjType.PAGE &&
                m_obj.ObjInfo.ObjType != HmiObjType.TIMER &&
                m_obj.ObjInfo.ObjType != HmiObjType.VAR
                )
            {
                dataGrid.Rows.Add();
                row = dataGrid.Rows.Count - 1;
                dataGrid.Rows[row].Cells["colValue"].Value    = m_obj.ObjInfo.Panel.X.ToString();
                dataGrid.Rows[row].Cells["colName"].Value     = "x";
                dataGrid.Rows[row].Cells["colType"].Value     = "x";
                dataGrid.Rows[row].Cells["colInfo"].Value     = "Coordinate X".Translate();
                dataGrid.Rows[row].Cells["colValue"].ReadOnly = false;

                dataGrid.Rows.Add();
                row = dataGrid.Rows.Count - 1;
                dataGrid.Rows[row].Cells["colValue"].Value    = m_obj.ObjInfo.Panel.Y.ToString();
                dataGrid.Rows[row].Cells["colName"].Value     = "y";
                dataGrid.Rows[row].Cells["colType"].Value     = "y";
                dataGrid.Rows[row].Cells["colInfo"].Value     = "Coordinate Y".Translate();
                dataGrid.Rows[row].Cells["colValue"].ReadOnly = false;
                dataGrid.Rows.Add();

                row  = dataGrid.Rows.Count - 1;
                num3 = (m_obj.ObjInfo.Panel.EndX - m_obj.ObjInfo.Panel.X) + 1;
                dataGrid.Rows[row].Cells["colValue"].Value    = num3.ToString();
                dataGrid.Rows[row].Cells["colName"].Value     = "w";
                dataGrid.Rows[row].Cells["colType"].Value     = "w";
                dataGrid.Rows[row].Cells["colInfo"].Value     = "Width".Translate();
                dataGrid.Rows[row].Cells["colValue"].ReadOnly = false;
                dataGrid.Rows.Add();

                row = dataGrid.Rows.Count - 1;
                dataGrid.Rows[row].Cells["colValue"].Value    = ((m_obj.ObjInfo.Panel.EndY - m_obj.ObjInfo.Panel.Y) + 1).ToString();
                dataGrid.Rows[row].Cells["colName"].Value     = "h";
                dataGrid.Rows[row].Cells["colType"].Value     = "h";
                dataGrid.Rows[row].Cells["colInfo"].Value     = "Height".Translate();
                dataGrid.Rows[row].Cells["colValue"].ReadOnly = false;
            }

            if (m_obj.Attributes.Count > 0 &&
                Utility.GetString(m_obj.Attributes[0].Name) == "lei"
                )
            {
                objType = Utility.GetString(m_obj.Attributes[0].Note, Encoding.ASCII.GetBytes("~")[0]);
            }

            tbAttrDescription.Text = "Click the attribute to display corresponding notes".Translate();
            tbObjIdType.Text       = "ID:" + m_obj.ObjId.ToString() + " " + objType;

            if (dataGrid.Rows.Count > 0)
            {
                dataGrid.Rows[0].Cells[0].Selected = false;
            }
        }
Beispiel #5
0
        public void PutCodes(List<byte[]> strings)
        {
            try
            {
                List<byte[]> attrs = getAttributes(strings, "att");
                int attrInfoSize = HmiOptions.InfoAttributeSize;
                Attributes.Clear();
                IsBinding = 0;
                foreach (byte[] attr in attrs)
                {
                    if (attr.Length >= (attrInfoSize + 8) && attr.Length < 0x400)
                    {
                        HmiAttribute hmiAttr = new HmiAttribute
                        {
                            Name = Utility.SubBytes(attr, 0, 8)
                        };
                        byte[] bytes = Utility.SubBytes(attr, 8, attrInfoSize);
                        hmiAttr.InfoAttribute = Utility.ToStruct<InfoAttribute>(bytes);
                        if (attr.Length >= (attrInfoSize + 8 + hmiAttr.InfoAttribute.DataLength))
                        {
                            hmiAttr.Data = Utility.SubBytes(attr, attrInfoSize + 8, hmiAttr.InfoAttribute.DataLength);
                            hmiAttr.Note = Utility.SubBytes(attr, attrInfoSize + 8 + hmiAttr.InfoAttribute.DataLength);
                            if (hmiAttr.InfoAttribute.AttrType == HmiAttributeType.String)
                            {
                                if (hmiAttr.Data.Length == 0 || hmiAttr.Data[hmiAttr.Data.Length - 1] != 0)
                                    hmiAttr.Data = Utility.MergeBytes(hmiAttr.Data, Utility.BYTE_ZERO);
                                hmiAttr.InfoAttribute.DataLength = (ushort)hmiAttr.Data.Length;
                                if (hmiAttr.InfoAttribute.DataLength > hmiAttr.InfoAttribute.Length)
                                    hmiAttr.InfoAttribute.Length = hmiAttr.InfoAttribute.DataLength;
                            }

                            if (Attributes.Count == 1)
                            {
                                string name = Utility.GetString(hmiAttr.Name);
                                if (name == "merry" || name == "memory")
                                    hmiAttr.Name = "vscope".ToBytes();
                                else if (name != "vscope")
                                    Attributes.AddNewAttribute(
                                                    "vscope",
                                                    1,
                                                    HmiAttributeType.Selection,
                                                    IsYesNo.No,
                                                    "0",
                                                    "Variable scope ( Local variable is only visible in current page, while global variable is visible  in all pages):0-local;1-global".Translate(),
                                                    0, 0, 1, 0
                                    );
                            }
                            Attributes.Add(hmiAttr);
                            checkAttribute(hmiAttr);
                        }
                    }
                }
                if (Attributes.Count == 1)
                    Attributes.AddNewAttribute("vscope", 1, HmiAttributeType.Selection, IsYesNo.No, "0", "Variable scope ( Local variable is only visible in current page, while global variable is visible  in all pages):0-local;1-global".Translate(), 0, 0, 1, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR occoured when setting component properties".Translate() + ex.Message);
            }

            Codes[0] = getAttributes(strings, "load");
            Codes[1] = getAttributes(strings, "down");
            Codes[2] = getAttributes(strings, "up");
            Codes[3] = getAttributes(strings, "slide");
        }
Beispiel #6
0
        public int GetNoteLength(string name, bool useMinus)
        {
            Range range = new Range
            {
                Begin = 0,
                End = 7
            };
            HmiAttribute attr = new HmiAttribute();
            if (useMinus)
            {
                string[] strArray = name.Split(Utility.CHAR_MINUS);
                if (strArray.Length != 2)
                    return 0;
                name = strArray[0];
            }

            for (int i = 0; i < Attributes.Count; i++)
            {
                int num2 = Utility.IndexOfEx(Attributes[i].Name, Utility.ToBytes(name), range, false);
                if (num2 != 0xffff
                 && (num2 == 7 || Attributes[i].Name[num2 + 1] == 0)
                 && Attributes[i].InfoAttribute.AttrType == HmiAttributeType.String
                    )
                    return Attributes[i].InfoAttribute.Length;
            }
            return 0;
        }
Beispiel #7
0
 public byte[] GetAttributeValue(string name)
 {
     Range range = new Range
     {
         Begin = 0,
         End = 7
     };
     HmiAttribute hmiAttr = new HmiAttribute();
     for (int i = 0; i < Attributes.Count; i++)
     {
         int idx = Utility.IndexOfEx(Attributes[i].Name, name.ToBytes(), range, false);
         if (idx != 0xffff && (idx == 7 || Attributes[i].Name[idx + 1] == 0))
             return Attributes[i].Data;
     }
     return null;
 }
Beispiel #8
0
        public string CheckAttributeValue(HmiAttribute hmiAttr)
        {
            try
            {
                if (hmiAttr.InfoAttribute.AttrType == HmiAttributeType.PicId)
                {
                    int num = hmiAttr.Data.ToU16();
                    if (num >= App.Pictures.Count)
                        return "Invalid Pic ID".Translate();
                }

                if (Utility.GetString(hmiAttr.Name) == "font"
                 && GetAttributeValue("txt") != null
                 && Utility.GetString(GetAttributeValue("txt")) != ""
                 && hmiAttr.Data[0] >= App.Fonts.Count
                    )
                    return "Invalid Font ID".Translate();
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
            return "";
        }
Beispiel #9
0
        public bool SetAttrValue(string name, string newval)
        {
            Range range = new Range
            {
                Begin = 0,
                End = 7
            };
            HmiAttribute attr = new HmiAttribute();
            for (int i = 0; i < Attributes.Count; i++)
            {
                int num2 = Utility.IndexOfEx(Attributes[i].Name, Utility.ToBytes(name, 8), range, false);
                if (num2 != 0xffff && (num2 == 7 || Attributes[i].Name[num2 + 1] == 0))
                {
                    attr = Attributes[i];
                    if ((attr.InfoAttribute.AttrType == 2) && (newval == ""))
                        newval = "65535";

                    if (attr.InfoAttribute.AttrType < HmiAttributeType.String)
                    {
                        int @int = Utility.GetInt(newval);
                        if ((@int > attr.InfoAttribute.MaxValue) || (@int < attr.InfoAttribute.MinValue))
                            return false;

                        if (attr.InfoAttribute.Length == 1)
                        {
                            if (attr.InfoAttribute.AttrType == 5)
                            {
                                string[] strArray = name.Split(Utility.CHAR_MINUS);
                                if (strArray.Length == 2)
                                    return SetAttrTextLength(strArray[0], newval);
                            }
                            else
                            {
                                attr.InfoAttribute.DataLength = 1;
                                attr.Data[0] = (byte)@int;
                            }
                        }
                        else if (attr.InfoAttribute.Length == 2)
                        {
                            attr.InfoAttribute.DataLength = 2;
                            attr.Data = Utility.ToBytes(((ushort)@int));
                        }
                        else if (attr.InfoAttribute.Length == 4)
                        {
                            attr.InfoAttribute.DataLength = 4;
                            attr.Data = Utility.ToBytes(((uint)@int));
                        }
                    }
                    else
                    {
                        byte[] valueBytes = newval.ToBytes();
                        if (valueBytes.Length >= attr.InfoAttribute.Length)
                        {
                            MessageBox.Show("Too long string, exceed the max length.".Translate());
                            return false;
                        }
                        attr.Data = valueBytes;
                        if (attr.Data.Length == 0 || attr.Data[attr.Data.Length - 1] != 0)
                            attr.Data = Utility.MergeBytes(attr.Data, Utility.BYTE_ZERO);
                        attr.InfoAttribute.DataLength = (ushort)attr.Data.Length;
                    }
                    Attributes[i] = attr;
                    break;
                }
            }
            return true;
        }
Beispiel #10
0
 public bool SetAttrTextLength(string name, string newval)
 {
     Range bufPos = new Range
     {
         Begin = 0,
         End = 7
     };
     HmiAttribute attr = new HmiAttribute();
     int @int = Utility.GetInt(newval);
     if (@int > 0xff)
     {
         MessageBox.Show("Max allowed string length: 255 bytes.".Translate());
         return false;
     }
     for (int i = 0; i < Attributes.Count; i++)
     {
         int endName = Utility.IndexOf(Attributes[i].Name, name, bufPos);
         if (endName != 0xffff
          && (endName == 7 || Attributes[i].Name[endName + 1] == 0)
          && Attributes[i].InfoAttribute.AttrType == HmiAttributeType.String
             )
         {
             if (Attributes[i].Data.Length <= (@int + 1))
             {
                 Attributes[i].InfoAttribute.Length = (ushort)(@int + 1);
                 return true;
             }
             MessageBox.Show("The value should not be smaller than length of current string in value \"txt\".".Translate());
             return false;
         }
     }
     return false;
 }