Exemplo n.º 1
0
 public static bool NextArrayPath(PathComponent path)
 {
     if (path is IndexComponent)
     {
         IndexComponent      index  = (IndexComponent)path;
         IList <ArrayLimits> limits = ((ARRAY)path.Parent.Type).Limits;
         for (int i = 0; i < index.Indices.Count(); i++)
         {
             if (index.Indices[i] < ((IntegerLiteral)limits[i].HighLimit).Value)
             {
                 index.Indices[i]++;
                 return(true);
             }
             else
             {
                 index.Indices[i] = ((IntegerLiteral)limits[i].LowLimit).Value;
             }
         }
     }
     if (path.Parent == null)
     {
         return(false);
     }
     return(NextArrayPath(path.Parent));
 }
Exemplo n.º 2
0
        protected override void DoWork()
        {
            lock (portal)
            {
                try
                {
                    TagTable table = folder.TagTables.Find(tableName);

                    if (table != null)
                    {
                        XmlDocument   table_doc       = TIAutils.ExportHMITagTableXML(table);
                        HMITagTable   editor          = new HMITagTable(table_doc);
                        PathComponent enable_selected = new MemberComponent("EnableSelected", new STRUCT(), new MemberComponent(hmiDbName, new STRUCT()));
                        PathComponent preset_selected = new MemberComponent("PresetSelected", new STRUCT(), new MemberComponent(hmiDbName, new STRUCT()));

                        int index = 1;
                        foreach (var tag in tags)
                        {
                            editor.AddIndexedTag("PresetEnable_" + groupName + "_", index, tag.tagPath.PrependPath(enable_selected).ToString());
                            editor.AddIndexedTag("PresetValue_" + groupName + "_", index, tag.tagPath.PrependPath(preset_selected).ToString(), tag.tagPath.Type);

                            index++;
                        }

                        ARRAY name_array = new ARRAY();
                        name_array.MemberType = new STRING();
                        PathComponent preset_names = new MemberComponent("Names", name_array, new MemberComponent(dbName, new STRUCT()));
                        ARRAY         color_array  = new ARRAY();
                        color_array.MemberType = INT.Type;
                        PathComponent preset_colors = new MemberComponent("Colors", color_array, new MemberComponent(dbName, new STRUCT()));
                        for (int p = 1; p <= nPresets; p++)
                        {
                            PathComponent name = new IndexComponent(new int[1] {
                                p
                            }, new STRING(), preset_names);
                            editor.AddIndexedTag("PresetName_" + groupName + "_", p, name.ToString());
                            PathComponent color = new IndexComponent(new int[1] {
                                p
                            }, INT.Type, preset_colors);
                            editor.AddIndexedTag("PresetColor_" + groupName + "_", p, color.ToString());
                        }
                        TIAutils.ImportHMITagTableXML(table_doc, folder);
                    }
                    else
                    {
                        LogMessage(MessageLog.Severity.Warning, "No tag table named '" + tableName + "' was found, skipping.");
                    }
                }
                catch (Exception ex)
                {
                    LogMessage(MessageLog.Severity.Error, "Failed to update tag table:\n" + ex.Message);
                    return;
                }
            }
        }
Exemplo n.º 3
0
        public static PathComponent InitializeArrayPath(PathComponent path, ConstantLookup constants)
        {
            PathComponent parent;

            if (path.Parent != null)
            {
                parent = InitializeArrayPath(path.Parent, constants);
            }
            else
            {
                parent = null;
            }

            if (path is IndexComponent)
            {
                IndexComponent index = (IndexComponent)path;

                int[] indices = new int[index.Indices.Count()];
                for (int i = 0; i < indices.Count(); i++)
                {
                    indices[i] = ((IntegerLiteral)((ARRAY)parent.Type).Limits[i].LowLimit).Value;
                }

                path = new IndexComponent(indices, index.Type, parent);
            }
            else
            {
                MemberComponent member     = (MemberComponent)path;
                DataType        type       = member.Type;
                ARRAY           array_type = path.Type as ARRAY;
                if (array_type != null)
                {
                    ARRAY new_array_type = new ARRAY();
                    new_array_type.MemberType = array_type.MemberType;
                    new_array_type.Limits     = new ArrayLimits[array_type.Limits.Count];
                    for (int i = 0; i < new_array_type.Limits.Count(); i++)
                    {
                        new_array_type.Limits[i] = new ArrayLimits(
                            new IntegerLiteral(array_type.Limits[i].LowLimit.ResolveInt(constants)),
                            new IntegerLiteral(array_type.Limits[i].HighLimit.ResolveInt(constants)));
                    }
                    type = new_array_type;
                }
                path = new MemberComponent(member.Name, type, parent);
            }


            return(path);
        }
Exemplo n.º 4
0
            // Substitute all indices in path with th low limit of the corresponding array
            protected PathComponent SubstituteIndicesLow(PathComponent path)
            {
                PathComponent parent_copy;

                if (path.Parent != null)
                {
                    parent_copy = SubstituteIndicesLow(path.Parent);
                }
                else
                {
                    parent_copy = null;
                }

                if (path is IndexComponent)
                {
                    IndexComponent ic      = (IndexComponent)path;
                    int[]          indices = new int[ic.Indices.Length];
                    if (!(ic.Parent is MemberComponent && ic.Parent.Type is ARRAY))
                    {
                        throw new Exception("Parent of index component is not an array");
                    }
                    ARRAY array_type = (ARRAY)ic.Parent.Type;
                    for (int l = 0; l < array_type.Limits.Count; l++)
                    {
                        Constant low = array_type.Limits[l].LowLimit;
                        if (!(low is IntegerLiteral))
                        {
                            throw new Exception("Low limity of array is not an integer constant.");
                        }
                        int low_limit = ((IntegerLiteral)low).Value;
                        indices[l] = low_limit;
                    }

                    return(new IndexComponent(indices, ic.Type, parent_copy));
                }
                else
                {
                    MemberComponent member = (MemberComponent)path;
                    return(new MemberComponent(member.Name, member.Type, parent_copy));
                }
            }
Exemplo n.º 5
0
            /// <summary>
            /// Makes a copy of the path with the indices substitutes
            /// </summary>
            /// <param name="path">Original path</param>
            /// <param name="substituted">Copy of path with new indices</param>
            /// <param name="indices">Indices to substitute</param>
            /// <returns>Number of indices in path</returns>
            protected static int SubstituteIndices(PathComponent path, out PathComponent substituted, IEnumerator <int> indices)
            {
                PathComponent parent_copy;
                int           subs_count;

                if (path.Parent != null)
                {
                    subs_count = SubstituteIndices(path.Parent, out parent_copy, indices);
                }
                else
                {
                    parent_copy = null;
                    subs_count  = 0;
                }

                if (path is IndexComponent)
                {
                    IndexComponent ic   = (IndexComponent)path;
                    IndexComponent copy = new IndexComponent(new int[ic.Indices.Length], ic.Type, parent_copy);
                    for (int i = 0; i < ic.Indices.Length; i++)
                    {
                        if (!indices.MoveNext())
                        {
                            break;
                        }
                        copy.Indices[i] = indices.Current;
                    }
                    subs_count += ic.Indices.Length;
                    substituted = copy;
                    return(subs_count);
                }
                else
                {
                    MemberComponent member = (MemberComponent)path;
                    substituted = new MemberComponent(member.Name, member.Type, parent_copy);
                    return(subs_count);
                }
            }
Exemplo n.º 6
0
            protected MemberComponent readMember(XmlElement member_elem, PathComponent parent)
            {
                string name = member_elem.GetAttribute("Name");



                string          type_str = member_elem.GetAttribute("Datatype");
                string          left;
                DataType        type       = DataTypeParser.Parse(type_str, out left);
                MemberComponent member     = new MemberComponent(name, type, parent);
                PathComponent   child_path = member;

                if (type is ARRAY)
                {
                    ARRAY array = (ARRAY)type;
                    child_path = new IndexComponent(new int[array.Limits.Count], array.MemberType, member);

                    if ((options & Options.NoSubelement) != 0)
                    {
                        if (member != child_path)
                        {
                            handle_tag(new HandleTagEventArgs()
                            {
                                Path    = SubstituteIndicesLow(child_path),
                                Comment = null
                            });
                        }
                    }
                }


                XmlElement       comment_elem = member_elem.SelectSingleNode("if:Comment", XMLUtil.nameSpaces) as XmlElement;
                MultilingualText comment      = null;

                if (comment_elem != null)
                {
                    comment = readComment(comment_elem);
                }
                if (((options & Options.AllowNoComment) != 0) || comment != null)
                {
                    handle_tag(new HandleTagEventArgs()
                    {
                        Path    = SubstituteIndicesLow(member),
                        Comment = comment
                    });
                }

                XmlNodeList member_elems = member_elem.SelectNodes("if:Member", XMLUtil.nameSpaces);

                foreach (XmlNode m in member_elems)
                {
                    MemberComponent submember = readMember((XmlElement)m, child_path);
                    if (child_path.Type is STRUCT)
                    {
                        STRUCT struct_type = (STRUCT)child_path.Type;
                        struct_type.Members.Add(new StructMember()
                        {
                            Name = submember.Name, MemberType = submember.Type
                        });
                    }
                }

                if ((options & Options.NoSubelement) == 0)
                {
                    XmlNodeList sub_elems = member_elem.SelectNodes("if:Subelement", XMLUtil.nameSpaces);
                    foreach (XmlNode s in sub_elems)
                    {
                        readSubelement(s as XmlElement, child_path);
                    }
                }

                return(member);
            }
Exemplo n.º 7
0
        public static PathComponent ParsePath(string str)
        {
            int           pos  = 0;
            PathComponent path = null;
            string        name;

            while (pos < str.Length)
            {
                if (str[pos] == '"')
                {
                    if (pos + 1 >= str.Length)
                    {
                        throw new ParseException("Path ends with '\"'");
                    }

                    int end = str.IndexOf('"', pos + 1);
                    if (end == -1)
                    {
                        throw new ParseException("No terminating '\"'");
                    }
                    name = str.Substring(pos + 1, end - pos - 1);
                    pos  = end + 1;
                }
                else
                {
                    int start = pos;
                    pos = str.IndexOfAny(MemberComponent.ESCAPED_CHARS, pos);
                    if (pos == -1)
                    {
                        pos = str.Length;
                    }
                    name = str.Substring(start, pos - start);
                }
                path = new MemberComponent(name, null, path);
                if (pos == str.Length)
                {
                    break;
                }
                if (str[pos] == '[')
                {
                    if (pos + 1 >= str.Length)
                    {
                        throw new ParseException("Path ends with '['");
                    }
                    int end = str.IndexOf(']', pos + 1);
                    if (end == -1)
                    {
                        throw new ParseException("No terminating ']'");
                    }
                    string   indices   = str.Substring(pos + 1, end - pos - 1);
                    string[] index_str = indices.Split(',');
                    path = new IndexComponent(index_str.Select(s => int.Parse(s)).ToArray <int>(), null, path);
                    pos  = end + 1;
                }
                if (pos == str.Length)
                {
                    break;
                }
                if (str[pos] != '.')
                {
                    throw new ParseException("Expected '.'");
                }
                pos++;
            }
            return(path);
        }