private void SetupView() { foreach (var screen in this.screenManager.Screens) { var screenTemplate = new ScreenTemplate { DataContext = screen, Margin = new System.Windows.Thickness(screen.Size.Left, screen.Size.Top, 0, 0), Width = screen.Size.Width, Height = screen.Size.Height, VerticalAlignment = System.Windows.VerticalAlignment.Top, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Foreground = screen.Id == this.selectedId ? Brushes.LightGreen : Brushes.White }; screenTemplate.Clicked += this.ScreenTemplate_Clicked; this.ScreenContainer.Children.Add(screenTemplate); } }
private void removeTemplate_Click(object sender, RoutedEventArgs e) { var ScreenTemplate = templateList.SelectedItem; using (TemplateContext db = new TemplateContext()) { if (ScreenTemplate != null) { ScreenTemplate screenTemplate = db.ScreenTemplates.Where(x => x.Id == (ScreenTemplate as ScreenTemplate).Id).FirstOrDefault(); for (int i = 0; i < screenTemplate.ScreenTemplateElements.Count; i++) { db.ScreenTemplateElements.Remove(screenTemplate.ScreenTemplateElements[i]); } db.ScreenTemplates.Remove(screenTemplate); } db.SaveChanges(); templateList.ItemsSource = db.ScreenTemplates.ToList(); } }
static public XmlDocument ExportScreenTemplateXML(ScreenTemplate template) { FileInfo path = TempFile.File("export_template_", "xml"); try { template.Export(path, ExportOptions.WithDefaults); XmlDocument doc = LoadDoc(path.ToString()); return(doc); } finally { try { path.Delete(); } catch (IOException e) { Console.WriteLine("Failed to delete temporary file: " + e.Message); } } }
public void SetScreenTemplate(ScreenTemplate screenTemplate) { ScreenTemplateNow = screenTemplate; IsChangedTemplate = false; try { for (int i = 0; i < 6; i++) { if (ScreenTemplateNow.ScreenTemplateElements[i].IsPlaylist == false) { string exp = ScreenTemplateNow.ScreenTemplateElements[i].Path.Split("\\").LastOrDefault().Split('.').LastOrDefault(); if (Utils.imageExp.Contains(exp)) { Image img = Utils.CreateImage(ScreenTemplateNow.ScreenTemplateElements[i].Path); (Elements.Children[i] as ListViewItem).Content = img; } else if (Utils.videoExp.Contains(exp)) { MediaElement video = Utils.CreateVideo(ScreenTemplateNow.ScreenTemplateElements[i].Path); (Elements.Children[i] as ListViewItem).Content = video; } else if (exp == "gif") { MediaElement video = Utils.CreateVideo(ScreenTemplateNow.ScreenTemplateElements[i].Path); (Elements.Children[i] as ListViewItem).Content = video; } } else { SetPlaylist(ScreenTemplateNow.ScreenTemplateElements[i].Path, Convert.ToInt32((Elements.Children[i] as ListViewItem).Uid)); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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(); }
public ScreensPageView(ScreenTemplate screenTemplate) { InitializeComponent(); SetScreenTemplate(screenTemplate); }