Ejemplo n.º 1
0
        public XmlNode AddValueType(PathComponent path, MultilingualText comment, string start_value)
        {
            int[]      indices;
            XmlElement value_node = AddPathValues(type_section, path, null, out indices);

            return(AddPathAttributes(value_node, path, comment, start_value, indices));
        }
Ejemplo n.º 2
0
        public XmlNode AddPath(PathComponent path, MultilingualText comment, string start_value)
        {
            int[] indices;
            AddPathEnable(static_section, path.PrependPath(enable_prefix), out indices);
            AddPathEnable(static_section, path.PrependPath(enable_selected_prefix), out indices);

            AddPathValues(static_section, path.PrependPath(preset_selected_prefix), null, out indices);
            PathComponent preset_path = path.PrependPath(preset_prefix);
            XmlElement    value_node  = AddPathValues(static_section, preset_path, null, out indices);

            return(AddPathAttributes(value_node, preset_path, comment, start_value, indices));
        }
Ejemplo n.º 3
0
            MultilingualText readComment(XmlElement comment_elem)
            {
                MultilingualText comment    = new MultilingualText();
                XmlNodeList      text_elems = comment_elem.SelectNodes("if:MultiLanguageText", XMLUtil.nameSpaces);

                foreach (XmlNode t in text_elems)
                {
                    XmlElement mlt  = t as XmlElement;
                    string     lang = mlt.GetAttribute("Lang");

                    string text = mlt.InnerText;
                    comment.AddText(lang, text);
                }
                return(comment);
            }
Ejemplo n.º 4
0
        protected override void DoWork()
        {
            lock (portal)
            {
                try
                {
                    IntSet      idset = new IntSet();
                    XmlDocument doc   = new XmlDocument();
                    doc.LoadXml(Resources.InitialHMITextList);
                    XMLUtil.CollectID(doc.DocumentElement, idset);


                    XmlElement name_attr = doc.SelectSingleNode("/Document/Hmi.TextGraphicList.TextList/AttributeList/Name") as XmlElement;
                    name_attr.InnerText = list_name;

                    XmlElement entry_list = doc.SelectSingleNode("/Document/Hmi.TextGraphicList.TextList/ObjectList") as XmlElement;


                    {
                        MultilingualText text = new MultilingualText();
                        foreach (string culture in cultures)
                        {
                            text.AddText(culture, "?");
                        }
                        XmlElement entry = ListEntry(doc, 0, true, text);
                    }

                    List <int> keys = new List <int>(texts.Keys);
                    keys.Sort();
                    foreach (int k in keys)
                    {
                        XmlElement entry = ListEntry(doc, k, false, texts[k]);
                        entry_list.AppendChild(entry);
                        XMLUtil.ReplaceID(entry, idset);
                    }

                    TIAutils.ImportTextListXML(doc, text_lists);
                }
                catch (Exception ex)
                {
                    LogMessage(MessageLog.Severity.Error, "Failed create HMI text list:\n" + ex.Message);
                    return;
                }
            }
        }
Ejemplo n.º 5
0
            protected void readSubelement(XmlElement subelement, PathComponent parent)
            {
                string indices_str = subelement.GetAttribute("Path");

                string[] index_strings = indices_str.Split(path_sep);
                int[]    indices       = new int[index_strings.Length];
                for (int i = 0; i < index_strings.Length; i++)
                {
                    indices[i] = int.Parse(index_strings[i]);
                }
                PathComponent subs;
                int           subs_count = SubstituteIndices(parent, out subs, (indices as IList <int>).GetEnumerator());

                if (subs_count != indices.Length)
                {
                    if (!(subs is IndexComponent) ||
                        (subs_count != (indices.Length + ((IndexComponent)subs).Indices.Length)))
                    {
                        throw new Exception("Length of path in subelement doesn't match number of indices in path");
                    }
                    // It's the path of the array itself not an array item.
                    subs = subs.Parent;
                }
                XmlElement comment_elem = subelement.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    = subs,
                        Comment = comment
                    });
                }
            }
Ejemplo n.º 6
0
        private void WriteButton_Click(object sender, EventArgs e)
        {
            if (task_dialog == null)
            {
                task_dialog = new TaskDialog();
            }
            task_dialog.Clear();

            Project             proj  = tiaPortal.Projects[0];
            LanguageAssociation langs = proj.LanguageSettings.ActiveLanguages;

            string[] cultures        = langs.Select(l => l.Culture.Name).ToArray();
            string   default_culture = proj.LanguageSettings.ReferenceLanguage.Culture.Name;

            foreach (PresetTagList.Row row in presetList)
            {
                row.Tag.labels.AddMissingCultures(cultures, default_culture);
                if (row.Tag.state_labels != null)
                {
                    foreach (MultilingualText text in row.Tag.state_labels.Values)
                    {
                        text.AddMissingCultures(cultures, default_culture);
                    }
                }
            }
            // Sort the groups into separate lists of tags
            Dictionary <string, List <PresetTag> > tag_groups = tagGroups(presetList);


            ConstantLookup constants = new ConstantLookup();

            constants.Populate(tiaPortal, plcSoftware);

            // Create databases for all groups
            foreach (string group_name in tag_groups.Keys)
            {
                string db_name     = PRESET_DB_PREFIX + group_name;
                string hmi_db_name = PRESET_HMI_DB_PREFIX + group_name;
                var    tags        = tag_groups[group_name];

                string value_type_name  = "PresetValueType_" + group_name;
                string enable_type_name = "PresetEnableType_" + group_name;

                task_dialog.AddTask(new CreatePresetTypesTask(tiaPortal, tags, typeGroup, value_type_name, enable_type_name));
                string recall_block_name = "PresetRecall_" + group_name;
                task_dialog.AddTask(new CreatePresetRecallBlockTask(tiaPortal, tags, resultGroup, recall_block_name, value_type_name, enable_type_name));
                string store_block_name         = "PresetStore_" + group_name;
                string store_enabled_block_name = "PresetStoreEnabled_" + group_name;
                task_dialog.AddTask(new CreatePresetStoreBlockTask(tiaPortal, tags, resultGroup, store_block_name, store_enabled_block_name, value_type_name, enable_type_name));
            }

            task_dialog.AddTask(new CreatePlcCompileTask(tiaPortal, plcSoftware));

            foreach (HmiTarget hmi in hmiTargets)
            {
                // Create HMI tags
                TagFolder preset_tag_folder = hmi.TagFolder.Folders.Find("Preset");
                if (preset_tag_folder != null)
                {
                    task_dialog.AddTask(new CreateHmiPresetConstantTagsTask(tiaPortal, preset_tag_folder, constants));
                }
            }

            // Create HMI for all groups
            foreach (string group_name in tag_groups.Keys)
            {
                var    tags        = tag_groups[group_name];
                string db_name     = PRESET_DB_PREFIX + group_name;
                string hmi_db_name = PRESET_HMI_DB_PREFIX + group_name;

                foreach (HmiTarget hmi in hmiTargets)
                {
                    string            popup_name   = "PresetPopup_" + group_name;
                    ScreenPopupFolder popup_folder = hmi.ScreenPopupFolder;
                    ScreenPopup       popup        = popup_folder.ScreenPopups.Find(popup_name);
                    if (popup == null)
                    {
                        task_dialog.AddTask(new MessageTask("Skipping preset group " + group_name + " for HMI " + hmi.Name,
                                                            MessageLog.Severity.Info,
                                                            "Assuming preset group " + group_name + " is not used by this HMI since the pop-up screen " + popup_name + " was not found"));
                        continue;
                    }

                    String list_prefix = "PresetTextList_" + group_name + "_";
                    TextListComposition hmi_text_lists = hmi.TextLists;

                    // Text list that are candidates for deletion
                    List <String> delete_lists = new List <string>();
                    // Find all preset text lists
                    foreach (var list in hmi_text_lists)
                    {
                        if (list.Name.StartsWith(list_prefix))
                        {
                            delete_lists.Add(list.Name);
                        }
                    }

                    // Create text lists

                    int count = 1;
                    foreach (PresetTag tag in tags)
                    {
                        if (tag.state_labels != null)
                        {
                            string list_name = list_prefix + count;
                            delete_lists.Remove(list_name); // Don't delete this list
                            task_dialog.AddTask(new CreateHmiTextListTask(tiaPortal, list_name, hmi_text_lists, tag.state_labels));
                        }
                        count++;
                    }

                    // Delete old textlists
                    task_dialog.AddTask(new DeleteHmiTextListTask(tiaPortal, list_prefix, hmi_text_lists, delete_lists));

                    // Get number of presets configured
                    string count_entry_name          = "PresetCount_" + group_name;
                    ConstantLookup.Entry count_entry = constants.Lookup(count_entry_name);
                    if (count_entry == null)
                    {
                        throw new Exception("Global constant " + count_entry_name + " not found");
                    }


                    int nPresets = int.Parse(count_entry.value);

                    Dictionary <int, MultilingualText> preset_names = new Dictionary <int, MultilingualText>();
                    // Create preset name list


                    {
                        for (int p = 1; p <= nPresets; p++)
                        {
                            string           name_string = "<hmitag length='20' type='Text' name='PresetName_" + group_name + "_" + p + "'>Preset " + p + "</hmitag>";
                            MultilingualText text        = new MultilingualText();
                            foreach (string c in cultures)
                            {
                                text.AddText(c, name_string);
                            }
                            preset_names.Add(p, text);
                        }

                        string list_name = "PresetNameList_" + group_name;
                        task_dialog.AddTask(new CreateHmiTextListTask(tiaPortal, list_name, hmi_text_lists, preset_names));
                    }
                    // Create HMI tags
                    TagFolder preset_tag_folder = hmi.TagFolder.Folders.Find("Preset");
                    if (preset_tag_folder != null)
                    {
                        string table_name = "Preset_" + group_name;
                        task_dialog.AddTask(new CreatePresetHmiTagsTask(tiaPortal, tags, preset_tag_folder, table_name, group_name, db_name, hmi_db_name, nPresets));
                    }
                    else
                    {
                        MessageBox.Show("No HMI tag group name 'Preset' was found for HMI " + hmi.Name + ". No tag tables will be updated.");
                    }

                    // Load template screen

                    ScreenTemplate obj_templ = hmi.ScreenTemplateFolder.ScreenTemplates.Find("ObjectTemplate");
                    if (obj_templ != null)
                    {
                        XmlDocument templates = TIAutils.ExportScreenTemplateXML(obj_templ);

                        // Create popups
                        task_dialog.AddTask(new CreatePresetScreenPopupTask(tiaPortal, tags, popup_folder, templates, popup_name, group_name));
                    }
                    else
                    {
                        MessageBox.Show("No template screen named ObjectTemplate found for HMI " + hmi.Name + ". Some screens will not be updated.");
                    }
                }
            }


            task_dialog.Show();
        }
Ejemplo n.º 7
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);
            }
Ejemplo n.º 8
0
            public void Handler(string type, string data)
            {
                if (type == "preset")
                {
                    int p = data.IndexOf(':');
                    if (p < 0)
                    {
                        return;
                    }
                    string group = data.Substring(0, p).Trim();
                    if (group == "")
                    {
                        group = "main";
                    }
                    string   label  = data.Substring(p + 1).Trim();
                    String[] groups = group.Split(',');
                    if (preset.presetGroups != null && !preset.presetGroups.Equals(groups))
                    {
                        group = "<inconsistent>";
                    }
                    preset.presetGroups = groups;
                    if (preset.labels == null)
                    {
                        preset.labels = new MultilingualText(culture, label);
                    }
                    else
                    {
                        preset.labels.AddText(culture, label);
                    }
                }
                else if (type == "preset_default")
                {
                    preset.defaultValue = data.Trim();
                }
                else if (type == "preset_nostore")
                {
                    preset.noStore = true;
                }
                else if (type == "preset_unit")
                {
                    preset.unit = data.Trim();
                }
                else if (type == "preset_precision")
                {
                    int value;
                    if (int.TryParse(data, out value) && value >= 0)
                    {
                        preset.precision = value;
                    }
                }
                else if (type == "preset_min")
                {
                    float value;
                    if (float.TryParse(data, out value))
                    {
                        preset.min = value;
                    }
                }
                else if (type == "preset_max")
                {
                    float value;
                    if (float.TryParse(data, out value))
                    {
                        preset.max = value;
                    }
                }
                else if (type == "preset_order")
                {
                    int value;
                    if (int.TryParse(data, out value))
                    {
                        preset.order = value;
                    }
                }
                else if (type == "preset_state")
                {
                    int p = data.IndexOf(':');
                    if (p < 0)
                    {
                        return;
                    }
                    string value_str = data.Substring(0, p).Trim();

                    if (int.TryParse(value_str, out int value))
                    {
                        string label_str = data.Substring(p + 1).Trim();
                        if (preset.state_labels == null)
                        {
                            preset.state_labels = new Dictionary <int, MultilingualText>();
                        }
                        MultilingualText label;
                        if (preset.state_labels.TryGetValue(value, out label))
                        {
                            label.AddText(culture, label_str);
                        }
                        else
                        {
                            label = new MultilingualText(culture, label_str);
                            preset.state_labels.Add(value, label);
                        }
                    }
                }
            }
Ejemplo n.º 9
0
        protected XmlElement ListEntry(XmlDocument doc, int value, bool def, MultilingualText text)
        {
            XmlElement entry = doc.CreateElement("Hmi.TextGraphicList.TextListEntry");

            entry.SetAttribute("ID", "0");
            entry.SetAttribute("CompositionName", "Entries");

            XmlElement attr_list = doc.CreateElement("AttributeList");

            entry.AppendChild(attr_list);

            XmlElement default_entry = doc.CreateElement("DefaultEntry");

            default_entry.InnerText = def ? "true" : "false";
            attr_list.AppendChild(default_entry);

            XmlElement entry_type = doc.CreateElement("EntryType");

            entry_type.InnerText = "SingleValue";
            attr_list.AppendChild(entry_type);

            XmlElement from = doc.CreateElement("From");

            from.InnerText = value.ToString();
            attr_list.AppendChild(from);

            XmlElement to = doc.CreateElement("To");

            to.InnerText = value.ToString();
            attr_list.AppendChild(to);

            XmlElement obj_list = doc.CreateElement("ObjectList");

            entry.AppendChild(obj_list);

            XmlElement multi_text = doc.CreateElement("MultilingualText");

            multi_text.SetAttribute("ID", "0");
            multi_text.SetAttribute("CompositionName", "Text");
            obj_list.AppendChild(multi_text);

            XmlElement obj_list2 = doc.CreateElement("ObjectList");

            multi_text.AppendChild(obj_list2);

            foreach (string culture in text.Cultures)
            {
                XmlElement text_item = doc.CreateElement("MultilingualTextItem");
                text_item.SetAttribute("ID", "0");
                text_item.SetAttribute("CompositionName", "Items");
                obj_list2.AppendChild(text_item);

                XmlElement attr_list2 = doc.CreateElement("AttributeList");
                text_item.AppendChild(attr_list2);

                XmlElement culture_elem = doc.CreateElement("Culture");
                culture_elem.InnerText = culture;
                attr_list2.AppendChild(culture_elem);

                List <ParseText.FieldInfo> fields = null;
                XmlElement parsed_text            = ParseText.ParseTextToTextElement(doc, text[culture], ref fields);
                attr_list2.AppendChild(parsed_text);
            }
            return(entry);
        }