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); }
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; } } }
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(); }