Exemplo n.º 1
0
        public HmiPage AddPage()
        {
            HmiPage page = new HmiPage(this);

            string name = "page";
            int    idx  = 0;

            for (; idx < 0xffff; idx++)
            {
                if (!FindPageByName(name + idx.ToString()))
                {
                    break;
                }
            }
            page.Name = name + idx.ToString();

            HmiPages.Add(page);
            RefreshPageId();

            HmiObject hmiObject = new HmiObject(this, page);

            hmiObject.ObjName = page.Name;

            page.HmiObjects.Add(hmiObject);
            RefreshObjId(page);
            hmiObject.SetScreenXY();
            return(HmiPages[HmiPages.Count - 1]);
        }
Exemplo n.º 2
0
        public HmiPage InsertPage(int index)
        {
            HmiPage item = new HmiPage(this);
            string  name = "newpage";
            int     idx  = 0;

            while (idx < 0xffff)
            {
                if (!FindPageByName(name + idx.ToString()))
                {
                    break;
                }
                ++idx;
            }
            item.Name = name + idx.ToString();
            HmiPages.Insert(index, item);
            RefreshPageId();
            HmiObject mobj = new HmiObject(this, item)
            {
                App     = this,
                ObjName = item.Name
            };

            item.HmiObjects.Add(mobj);
            mobj.SetScreenXY();
            RefreshObjId(item);
            return(item);
        }
Exemplo n.º 3
0
        public MemberAdd(HmiApplication app, HmiPage page, HmiObject obj)
        {
            m_app  = app;
            m_page = page;
            m_obj  = obj;

            InitializeComponent();
            Utility.Translate(this);
        }
Exemplo n.º 4
0
 public bool FindObjByName(HmiPage page, HmiObject obj, string name)
 {
     name = Utility.ToBytes(name, 4).ToString();
     foreach (HmiObject mobj in page.HmiObjects)
     {
         if (mobj.ObjName == name && mobj != obj)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 5
0
        public HmiPage CopyPage(int index)
        {
            HmiPage page = AddPage();

            page.HmiObjects[0]         = HmiPages[index].HmiObjects[0].CopyObject(this, page);
            page.HmiObjects[0].ObjName = page.Name;
            for (int i = 1; i < HmiPages[index].HmiObjects.Count; i++)
            {
                HmiObject copyeobj = HmiPages[index].HmiObjects[i].CopyObject(this, page);
                copyeobj.ObjName = HmiPages[index].HmiObjects[i].ObjName;
                page.HmiObjects.Add(copyeobj);
            }
            RefreshObjId(page);
            return(page);
        }
Exemplo n.º 6
0
        private bool objDetect(RichTextBox textCompile, HmiObject obj)
        {
            bool flag = true;

            if (obj.ObjInfo.Panel.X < 0 ||
                obj.ObjInfo.Panel.EndX >= App.LcdWidth ||
                obj.ObjInfo.Panel.Y < 0 ||
                obj.ObjInfo.Panel.EndY >= App.LcdHeight
                )
            {
                textCompile.AddRichTextString(
                    string.Concat("Page:".Translate(), Name, " Error:".Translate(), obj.ObjName, " Position Invalid:".Translate()),
                    Color.Red
                    );
                App.Errors++;
                flag = false;
            }

            for (int i = 0; i < obj.Attributes.Count; i++)
            {
                if (obj.Attributes[i].InfoAttribute.AttrType < 15 &&
                    obj.Attributes[i].InfoAttribute.CanModify == 1 &&
                    obj.checkAttribute(obj.Attributes[i])
                    )
                {
                    string err = obj.CheckAttributeValue(obj.Attributes[i]);
                    if (err != "")
                    {
                        textCompile.AddRichTextString(
                            string.Concat(
                                "Page:".Translate(),
                                Name,
                                " Error:".Translate(),
                                obj.ObjName + "." + obj.Attributes[i].Name.ToString(),
                                " InputVal Invalid:".Translate(),
                                err),
                            Color.Red);
                        App.Errors++;
                        flag = false;
                    }
                }
            }
            return(flag);
        }
Exemplo n.º 7
0
        public bool RenameObj(HmiPage page, HmiObject obj, string newname)
        {
            int length = newname.ToBytes().Length;

            if ((length == 0) || (length > 14))
            {
                MessageBox.Show("Min Length 1 byte, Max Length 14 byte".Translate());
                return(false);
            }
            if (!Utility.IsNameValid(newname))
            {
                return(false);
            }
            if (FindObjByName(page, obj, newname))
            {
                MessageBox.Show("Duplicate Name!".Translate());
                return(false);
            }
            obj.ObjName = newname;
            return(true);
        }
Exemplo n.º 8
0
 public void MakeObjName(HmiPage page, HmiObject obj, byte mark)
 {
     try
     {
         string str     = "";
         string newname = "";
         str = HmiObjType.GetNamePrefix(mark);
         for (int i = 0; i < 0xff; i++)
         {
             newname = str + i.ToString();
             if (!FindObjByName(page, obj, newname))
             {
                 obj.ObjName = newname;
                 break;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 9
0
        public void RefreshObject(HmiApplication app, HmiPage page, HmiObject obj)
        {
            try
            {
                SaveCodes();

                tabControl.Tag = "stop";
                if (app == null || page == null || obj == null)
                {
                    Clear();
                    return;
                }

                m_AppInf = app;
                m_Page   = page;
                m_Object = obj;

                if (obj.ObjId == 0)
                {
                    rbAutoLoad.Visible = rbLoadCommands.Visible = false;
                }
                else
                {
                    rbAutoLoad.Visible = rbLoadCommands.Visible = true;
                }

                tabControl.Enabled      = tbUserCode.Enabled = true;
                rbAutoLoad.Enabled      = rbLoadCommands.Enabled = true;
                cbTPPressCompId.Enabled = cbTPReleaseCompId.Enabled = true;

                if (obj.ObjInfo.Panel.loadlei == 1)
                {
                    rbAutoLoad.Checked = true;
                }
                else
                {
                    rbLoadCommands.Checked = true;
                }

                cbTPPressCompId.Checked   = ((obj.ObjInfo.Panel.SendKey & 2) > 0);
                cbTPReleaseCompId.Checked = ((obj.ObjInfo.Panel.SendKey & 1) > 0);

                int selectedIndex = tabControl.SelectedIndex;
                if (obj.Attributes[0].Data[0] == HmiObjType.OBJECT_TYPE_SLIDER)
                {
                    if (!tabControl.TabPages.Contains(pageTouchPressEvent))
                    {
                        tabControl.TabPages.Add(pageTouchPressEvent);
                    }
                    if (!tabControl.TabPages.Contains(pageTouchReleaseEvent))
                    {
                        tabControl.TabPages.Add(pageTouchReleaseEvent);
                    }
                    if (!tabControl.TabPages.Contains(pageTouchMove))
                    {
                        tabControl.TabPages.Add(pageTouchMove);
                    }

                    pageInitialization.Tag    = "Initialization".Translate();
                    pageTouchPressEvent.Tag   = "Touch Press Event".Translate();
                    pageTouchReleaseEvent.Tag = "Touch Release Event".Translate();
                    pageTouchMove.Tag         = "Touch Move".Translate();
                }
                else if (obj.Attributes[0].Data[0] == HmiObjType.TIMER)
                {
                    if (tabControl.TabPages.Contains(pageTouchPressEvent))
                    {
                        tabControl.TabPages.Remove(pageTouchPressEvent);
                    }
                    if (tabControl.TabPages.Contains(pageTouchReleaseEvent))
                    {
                        tabControl.TabPages.Remove(pageTouchReleaseEvent);
                    }
                    if (tabControl.TabPages.Contains(pageTouchMove))
                    {
                        tabControl.TabPages.Remove(pageTouchMove);
                    }
                    pageInitialization.Tag = "Timer Event".Translate();
                    rbAutoLoad.Visible     = false;
                    rbLoadCommands.Visible = false;
                }
                else
                {
                    if (!tabControl.TabPages.Contains(pageTouchPressEvent))
                    {
                        tabControl.TabPages.Add(pageTouchPressEvent);
                    }
                    if (!tabControl.TabPages.Contains(pageTouchReleaseEvent))
                    {
                        tabControl.TabPages.Add(pageTouchReleaseEvent);
                    }
                    if (tabControl.TabPages.Contains(pageTouchMove))
                    {
                        tabControl.TabPages.Remove(pageTouchMove);
                    }
                    pageInitialization.Tag    = "Initialization".Translate();
                    pageTouchPressEvent.Tag   = "Touch Press Event".Translate();
                    pageTouchReleaseEvent.Tag = "Touch Release Event".Translate();
                }
                if (selectedIndex >= tabControl.TabPages.Count)
                {
                    selectedIndex = 0;
                }

                tabControl.SelectedIndex = selectedIndex;
                attrLoad(selectedIndex);
                RefreshHead();
                tabControl.Tag = "save";
            }
            catch (Exception ex)
            {
                MessageBox.Show("Load Component Error".Translate() + " " + ex.Message);
            }
        }
Exemplo n.º 10
0
 public void delobj(HmiObject obj)
 {
     HmiObjects.RemoveAt(obj.ObjId);
     App.RefreshObjId(this);
 }
Exemplo n.º 11
0
        public bool Compile(RichTextBox textCompile)
        {
            byte index = 0;

            string[] pageTimers = new string[4];
            bool     flag       = true;

            List <byte[]> newlist = new List <byte[]>();
            List <byte[]> codes   = new List <byte[]>();

            byte[] binTFT     = new byte[HmiOptions.InfoPageObjectSize * HmiObjects.Count + 4];
            byte[] customData = new byte[0];

            Codes.Clear();
            ushort customDataAddress = (ushort)(App.OverBytes.Length - 4);

            try
            {
                int i;
                Utility.ToBytes(((uint)customDataAddress)).CopyTo(binTFT, 0);
                customDataAddress += (ushort)(binTFT.Length - 4);
                for (int idxObj = 0; idxObj < HmiObjects.Count; idxObj++)
                {
                    HmiObject hmiObj = HmiObjects[idxObj];
                    if (!objDetect(textCompile, hmiObj))
                    {
                        flag = false;
                        continue;
                    }

                    InfoPageObject infoPageObj;
                    infoPageObj.TouchState = 1;
                    if (hmiObj.ObjInfo.Panel.loadlei == 1)
                    {
                        infoPageObj.Visible = 1;
                    }
                    else
                    {
                        infoPageObj.Visible = 0;
                    }

                    infoPageObj.RefreshFlag = hmiObj.ObjInfo.Panel.loadlei;
                    Utility.ToBytes(infoPageObj).CopyTo(binTFT, idxObj * HmiOptions.InfoPageObjectSize + 4);

                    if (hmiObj.ObjInfo.IsCustomData == 0)
                    {
                        hmiObj.ObjInfo.AttributeStart = customDataAddress;
                        customData = Utility.ToBytes((uint)customDataAddress);
                        ushort objRamBytes = hmiObj.GetObjRamBytes(ref customData, customDataAddress);
                        if (objRamBytes != 0)
                        {
                            codes.Add(customData);
                            hmiObj.ObjInfo.AttributeLength = objRamBytes;
                            customDataAddress += hmiObj.ObjInfo.AttributeLength;
                        }
                    }
                }

                if (customDataAddress > HmiOptions.MaxCustomDataSize)
                {
                    textCompile.AddRichTextString(
                        string.Concat(
                            "Page:".Translate(),
                            Name,
                            " Error! Memory overflow:".Translate(), customDataAddress
                            ),
                        Color.Red
                        );
                    App.Errors++;
                    flag = false;
                }

                if (!flag)
                {
                    return(flag);
                }

                textCompile.AddRichTextString(
                    string.Concat(
                        "Page:".Translate(),
                        Name,
                        " OK! Occupy memory:".Translate(),
                        customDataAddress), Color.Black);

                customData = Utility.MergeBytes(Utility.ToBytes((uint)0xffff), Utility.ToBytes((uint)customDataAddress));
                codes.Add(customData);

                Codes.Add(Utility.PatternBytes("cre"));
                Codes.Add(binTFT);
                Utility.AppendList(Codes, codes);
                Codes.Add(Utility.PatternBytes("end"));

                newlist.Clear();
                for (int idxObj = 0; idxObj < HmiObjects.Count; idxObj++)
                {
                    if (HmiObjects[idxObj].ObjInfo.ObjType == HmiObjType.OBJECT_TYPE_CURVE)
                    {
                        newlist.Add(Utility.ToBytes("init " + idxObj.ToString()));
                    }
                }
                Utility.AppendList(Codes, newlist);

                index = 0;
                newlist.Clear();
                for (int idxObj = 0; idxObj < HmiObjects.Count; idxObj++)
                {
                    HmiObject obj = HmiObjects[idxObj];
                    if (obj.ObjInfo.ObjType == HmiObjType.TIMER)
                    {
                        if (index > 3)
                        {                               // Maximum 4 timer on page
                            if (index < 0xff)
                            {                           // One time message
                                textCompile.AddRichTextString("Page:".Translate() + Name + "Error! Only 4 Timers are allowed.".Translate(), Color.Red);
                                App.Errors++;
                                flag  = false;
                                index = 0xff;
                            }
                        }
                        else
                        {
                            newlist.Add(Utility.ToBytes("topen " + index.ToString() + "," + obj.ObjName + ".tim"));
                            Utility.AppendList(newlist, obj.Codes[0]);
                            newlist.Add(Utility.PatternBytes("tend"));

                            obj.TimerRefCodes.Clear();
                            obj.TimerRefCodes.Add(Utility.ToBytes("tpau " + index.ToString() + "," + obj.ObjName + ".tim," + obj.ObjName + ".en"));
                            pageTimers[index] = obj.ObjName;
                            ++index;
                        }
                    }
                }
                Utility.DeleteComments(newlist);
                Utility.AppendList(Codes, newlist);

                newlist.Clear();
                for (int idxObj = 0; idxObj < HmiObjects.Count; idxObj++)
                {
                    HmiObject obj = HmiObjects[idxObj];
                    if (obj.ObjInfo.Panel.loadlei == 1 &&
                        obj.Codes[0].Count > 0 &&
                        obj.ObjInfo.ObjType != HmiObjType.TIMER)
                    {
                        for (i = 0; i < obj.Codes[0].Count; ++i)
                        {
                            if (Utility.GetComType(obj.Codes[0][i]) == 0)
                            {
                                newlist.Add(obj.Codes[0][i]);
                            }
                        }
                    }
                }
                Utility.DeleteComments(newlist);
                Utility.AppendList(Codes, newlist);

                newlist.Clear();
                for (int idxObj = 0; idxObj < HmiObjects.Count; idxObj++)
                {
                    if (HmiObjects[idxObj].ObjInfo.Panel.loadlei == 1)
                    {
                        newlist.Add(Utility.ToBytes("oref " + idxObj.ToString() + ",0"));
                        newlist.Add(Utility.PatternBytes("if(sysda0==1)"));
                        newlist.Add(Utility.PatternBytes("{"));

                        HmiObjects[idxObj].GetLoadCodes(newlist, 0);

                        newlist.Add(Utility.ToBytes("cle_f " + idxObj.ToString() + ",0"));
                        newlist.Add(Utility.PatternBytes("}"));
                    }
                }
                Utility.AppendList(Codes, newlist);

                newlist.Clear();
                for (int idxObj = 0; idxObj < HmiObjects.Count; idxObj++)
                {
                    HmiObject obj = HmiObjects[idxObj];
                    if (obj.ObjInfo.Panel.loadlei == 1 &&
                        obj.Codes[0].Count > 0 &&
                        obj.ObjInfo.ObjType != HmiObjType.TIMER
                        )
                    {
                        for (i = 0; i < obj.Codes[0].Count; i++)
                        {
                            if (Utility.GetComType(obj.Codes[0][i]) == 1)
                            {
                                newlist.Add(obj.Codes[0][i]);
                            }
                        }
                    }
                }
                Utility.DeleteComments(newlist);
                Utility.AppendList(Codes, newlist);

                Codes.Add(Utility.PatternBytes("end"));
                return(flag);
            }
            catch (Exception ex)
            {
                textCompile.AddRichTextString("Exception: " + ex.Message, Color.Red);
            }
            return(false);
        }
Exemplo n.º 12
0
        private bool prepareToSave(
            ref InfoApp infoApp,
            bool compile,
            RichTextBox textCompile,
            SaveToFileData data
            )
        {
            infoApp.IsPotrait    = (byte)(IsPotrait ? 1 : 0);
            infoApp.ScreenWidth  = (IsPotrait ? LcdHeight : LcdWidth);
            infoApp.ScreenHeight = (IsPotrait ? LcdWidth : LcdHeight);

            bool   success          = true;
            ushort customDataLength = 0;

            OverBytes = Utility.ToBytes((uint)customDataLength);

            if (compile)
            {
                for (int idxPage = 0; idxPage < HmiPages.Count; idxPage++)
                {
                    HmiPage hmiPage = HmiPages[idxPage];
                    for (int idxObj = 0; idxObj < hmiPage.HmiObjects.Count; ++idxObj)
                    {
                        HmiObject hmiObj = hmiPage.HmiObjects[idxObj];

                        hmiObj.ObjInfo.ObjType      = hmiObj.Attributes[0].Data[0];
                        hmiObj.ObjInfo.IsCustomData = hmiObj.Attributes[1].Data[0];

                        if (hmiObj.ObjInfo.IsCustomData == 1)
                        {
                            hmiObj.ObjInfo.AttributeStart = customDataLength;
                            int objRambytes = hmiObj.GetObjRamBytes(ref OverBytes, customDataLength);
                            if (objRambytes != 0)
                            {
                                hmiObj.ObjInfo.AttributeLength = (ushort)objRambytes;
                                customDataLength += hmiObj.ObjInfo.AttributeLength;
                            }
                        }
                    }
                }
            }
            addString(OverBytes, data);

            List <byte[]> bts = new List <byte[]>();

            for (int idxPage = 0; idxPage < HmiPages.Count; idxPage++)
            {
                HmiPage hmiPage = HmiPages[idxPage];

                if (compile && !hmiPage.Compile(textCompile))
                {
                    success = false;
                }
                else
                {
                    Application.DoEvents();

                    InfoPage infoPage = new InfoPage
                    {
                        ObjCount = (byte)hmiPage.HmiObjects.Count,
                        Name     = Utility.ToStruct <InfoName>(Utility.ToBytes(hmiPage.Name, 14))
                    };
                    if (infoPage.ObjCount > 0)
                    {
                        infoPage.ObjStart = (ushort)data.m_infoObjects.Count;

                        for (int idxObj = 0; idxObj < hmiPage.HmiObjects.Count; idxObj++)
                        {
                            HmiObject hmiObj = hmiPage.HmiObjects[idxObj];
                            hmiObj.ObjInfo.Name = Utility.ToStruct <InfoName>(Utility.ToBytes(hmiObj.ObjName, 14));
                            bts.Clear();
                            if (compile)
                            {
                                hmiObj.CompileCodes(bts);
                            }
                            else
                            {
                                hmiObj.GetCodes(bts);
                            }

                            if (bts.Count > 0)
                            {
                                hmiObj.ObjInfo.StringInfoStart = (ushort)data.m_infoStrings.Count;
                                for (int k = 0; k < bts.Count; k++)
                                {
                                    addString(bts[k], data);
                                }

                                hmiObj.ObjInfo.StringInfoEnd = (ushort)((hmiObj.ObjInfo.StringInfoStart + bts.Count) - 1);
                            }
                            else
                            {
                                MessageBox.Show("Detect the component code is 0, error will occur when save the source file".Translate());
                                hmiObj.ObjInfo.StringInfoStart = 0xffff;
                                hmiObj.ObjInfo.StringInfoEnd   = 0xffff;
                            }
                            data.m_infoObjects.Add(hmiObj.ObjInfo);
                        }
                        infoPage.ObjEnd = (ushort)((infoPage.ObjStart + hmiPage.HmiObjects.Count) - 1);
                    }
                    else
                    {
                        infoPage.ObjStart = 0xffff;
                        infoPage.ObjEnd   = 0xffff;
                    }
                    if (compile)
                    {
                        infoPage.InstStart = (ushort)data.m_infoStrings.Count;
                        for (int num5 = 0; num5 < hmiPage.Codes.Count; num5++)
                        {
                            addString(hmiPage.Codes[num5], data);
                        }
                        infoPage.InstEnd = (ushort)(data.m_infoStrings.Count - 1);
                    }
                    else
                    {
                        infoPage.InstStart = 0xffff;
                        infoPage.InstEnd   = 0xffff;
                    }
                    data.m_infoPages.Add(infoPage);
                }
            }

            if (success)
            {
                infoApp.PageCount         = (ushort)data.m_infoPages.Count;
                infoApp.ObjectCount       = (ushort)data.m_infoObjects.Count;
                infoApp.FontCount         = (ushort)Fonts.Count;
                infoApp.PictureCount      = (ushort)Pictures.Count;
                infoApp.PictureImageStart = (uint)HmiOptions.InfoAppSize;

                if (compile)
                {
                    infoApp.PictureImageStart = 0x1000;
                }

                infoApp.FontImageStart  = infoApp.PictureImageStart + ((uint)getPictureImagesSize());
                infoApp.StringDataStart = infoApp.FontImageStart + ((uint)getFontImagesSize());
                if (compile)
                {
                    uint num6 = infoApp.StringDataStart % 0x1000;
                    if (num6 != 0)
                    {
                        infoApp.StringDataStart += 0x1000 - num6;
                    }
                }

                infoApp.FirmwareStart = infoApp.StringDataStart + (uint)data.m_stringDataAddress;
                infoApp.FirmwareSize  = 0;

                if (compile)
                {                       // Add bootloader if compile
                    StreamReader reader = new StreamReader(Path.Combine(Application.StartupPath, "fwc.bin"));
                    infoApp.FirmwareSize = (uint)reader.BaseStream.Length;
                    reader.Close();
                }

                infoApp.PageStart     = infoApp.FirmwareStart + infoApp.FirmwareSize;
                infoApp.ObjectStart   = infoApp.PageStart + ((uint)(data.m_infoPages.Count * HmiOptions.InfoPageSize));
                infoApp.PictureStart  = infoApp.ObjectStart + ((uint)(infoApp.ObjectCount * HmiOptions.InfoObjectSize));
                infoApp.StringStart   = infoApp.PictureStart + ((uint)(HmiOptions.InfoPictureSize * infoApp.PictureCount));
                infoApp.StringCount   = (uint)data.m_infoStrings.Count;
                infoApp.FontStart     = infoApp.StringStart + ((uint)(HmiOptions.InfoStringSize * data.m_infoStrings.Count));
                infoApp.FontDataStart = infoApp.FontStart + ((uint)(HmiOptions.InfoFontSize * infoApp.FontCount));
            }
            return(success);
        }
Exemplo n.º 13
0
        // private static List<InfoObject> m_Objects = new List<InfoObject>();
        // private static List<InfoPage> m_Pages = new List<InfoPage>();
        // private static List<byte[]> m_StringDatas = new List<byte[]>();
        // private static List<InfoString> m_Strings = new List<InfoString>();


        private bool readInfoApp(HmiApplication app, StreamReader reader)
        {
            List <InfoObject> m_Objects     = new List <InfoObject>();
            List <InfoPage>   m_Pages       = new List <InfoPage>();
            List <byte[]>     m_StringDatas = new List <byte[]>();
            List <InfoString> m_Strings     = new List <InfoString>();

            InfoApp infoApp;             // = new InfoApp();

            try
            {
                int idx;

                // Load Application Info
                reader.BaseStream.Position = 0L;
                byte[] buffer = new byte[HmiOptions.InfoAppSize];
                reader.BaseStream.Read(buffer, 0, buffer.Length);
                infoApp = Utility.ToStruct <InfoApp>(buffer);

                // Load Pictures and PictureImage
                app.Pictures.Clear();
                app.PictureImages.Clear();
                if (infoApp.PictureCount != 0)
                {
                    reader.BaseStream.Position = infoApp.PictureStart;
                    buffer = new byte[HmiOptions.InfoPictureSize];
                    for (idx = 0; idx < infoApp.PictureCount; idx++)
                    {
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        app.Pictures.Add(Utility.ToStruct <InfoPicture>(buffer));
                    }

                    reader.BaseStream.Position = infoApp.PictureImageStart;
                    for (idx = 0; idx < app.Pictures.Count; idx++)
                    {
                        buffer = new byte[app.Pictures[idx].Size];
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        app.PictureImages.Add(buffer);
                    }
                }

                // Load Fonts with FontImage
                app.Fonts.Clear();
                app.FontImages.Clear();
                if (infoApp.FontCount != 0)
                {
                    reader.BaseStream.Position = infoApp.FontStart;
                    buffer = new byte[HmiOptions.InfoFontSize];
                    for (idx = 0; idx < infoApp.FontCount; idx++)
                    {
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        app.Fonts.Add(Utility.ToStruct <InfoFont>(buffer));
                    }

                    reader.BaseStream.Position = infoApp.FontImageStart;
                    for (idx = 0; idx < app.Fonts.Count; idx++)
                    {
                        buffer = new byte[app.Fonts[idx].Size];
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        app.FontImages.Add(buffer);
                    }
                }

                if (infoApp.StringCount != 0)
                {
                    reader.BaseStream.Position = infoApp.StringStart;
                    buffer = new byte[HmiOptions.InfoStringSize];
                    for (idx = 0; idx < infoApp.StringCount; idx++)
                    {
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        m_Strings.Add(Utility.ToStruct <InfoString>(buffer));
                    }

                    reader.BaseStream.Position = infoApp.StringDataStart;
                    for (idx = 0; idx < m_Strings.Count; idx++)
                    {
                        buffer = new byte[m_Strings[idx].Size];
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        m_StringDatas.Add(buffer);
                    }
                }

                if (infoApp.PageCount != 0)
                {
                    reader.BaseStream.Position = infoApp.PageStart;
                    buffer = new byte[HmiOptions.InfoPageSize];
                    for (idx = 0; idx < infoApp.PageCount; idx++)
                    {
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        m_Pages.Add(Utility.ToStruct <InfoPage>(buffer));
                    }
                }

                if (infoApp.ObjectCount != 0)
                {
                    reader.BaseStream.Position = infoApp.ObjectStart;
                    buffer = new byte[HmiOptions.InfoObjectSize];
                    for (idx = 0; idx < infoApp.ObjectCount; idx++)
                    {
                        reader.BaseStream.Read(buffer, 0, buffer.Length);
                        m_Objects.Add(Utility.ToStruct <InfoObject>(buffer));
                    }
                }

                reader.Close();
                reader.Dispose();

                app.IsPotrait = (infoApp.IsPotrait == 1 ? true : false);
                app.LcdWidth  = (app.IsPotrait ? infoApp.ScreenHeight : infoApp.ScreenWidth);
                app.LcdHeight = (app.IsPotrait ? infoApp.ScreenWidth : infoApp.ScreenHeight);

                if (infoApp.VersionMajor == 0 && infoApp.VersionMinor < 30)
                {
                    HmiOptions.OpenTransparent = false;
                    for (int j = 0; j < app.PictureImages.Count; j++)
                    {
                        idx = 0;
                        while (idx < (app.PictureImages[j].Length - 1))
                        {
                            if ((app.PictureImages[j][idx] == HmiOptions.ColorTransparent) && (app.PictureImages[j][idx + 1] == 0))
                            {
                                app.PictureImages[j][idx] = (byte)HmiOptions.ColorTransparentReplace;
                            }
                            idx += 2;
                        }
                    }
                }
                else
                {
                    HmiOptions.OpenTransparent = false;
                }

                app.HmiPages.Clear();
                List <byte[]> strings = new List <byte[]>();

                for (int i = 0; i < m_Pages.Count; i++)
                {
                    HmiPage hmiPage = new HmiPage(app)
                    {
                        Name = Utility.GetString(Utility.ToBytes(m_Pages[i].Name))
                    };

                    if (m_Pages[i].ObjStart != 0xffff && m_Pages[i].ObjEnd != 0xffff)
                    {
                        for (idx = m_Pages[i].ObjStart; idx <= m_Pages[i].ObjEnd; idx++)
                        {
                            HmiObject hmiObject = new HmiObject(app, hmiPage)
                            {
                                ObjInfo = m_Objects[idx],
                                ObjName = Utility.GetString(Utility.ToBytes(m_Objects[idx].Name))
                            };
                            strings.Clear();
                            for (int k = m_Objects[idx].StringInfoStart; k <= m_Objects[idx].StringInfoEnd; k++)
                            {
                                strings.Add(m_StringDatas[k]);
                            }

                            hmiObject.PutCodes(strings);
                            hmiPage.HmiObjects.Add(hmiObject);
                        }
                    }
                    app.HmiPages.Add(hmiPage);
                }

                app.RefreshAllId();
                if (infoApp.VersionMajor == 0 && infoApp.VersionMinor == 8)
                {
                    foreach (HmiPage mpage2 in app.HmiPages)
                    {
                        if (mpage2.HmiObjects[0].Attributes.Count == 4 &&
                            Utility.GetString(mpage2.HmiObjects[0].Attributes[2].Name) == "pco"
                            )
                        {
                            mpage2.HmiObjects[0].Attributes[2].Name = Utility.ToBytes("bco", 8);
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                reader.Close();
                reader.Dispose();
                MessageBox.Show(ex.Message);
                return(false);
            }
        }
Exemplo n.º 14
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;
            }
        }