Exemplo n.º 1
0
        public DeleteHmiTextListTask(TiaPortal portal, string prefix, TextListComposition text_lists, List <String> list_names)
        {
            this.portal     = portal;
            this.text_lists = text_lists;
            this.list_names = list_names;
            this.prefix     = prefix;



            Description = "Delete old HMI text lists starting with " + prefix;
        }
Exemplo n.º 2
0
        public CreateHmiTextListTask(TiaPortal portal, string list_name, TextListComposition text_lists, IDictionary <int, MultilingualText> texts)
        {
            this.portal     = portal;
            this.text_lists = text_lists;
            this.list_name  = list_name;
            this.texts      = texts;

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

            cultures = langs.Select(l => l.Culture.Name);


            Description = "Create HMI text list " + list_name;
        }
Exemplo n.º 3
0
        //Export TextLists
        private static void ExportTextLists(HmiTarget hmitarget)
        {
            TextListComposition text = hmitarget.TextLists;

            foreach (TextList textList in text)
            {
                string extension = ".xml";
                var    fileInfo  = new FileInfo(exportLocation + @"\hmi_text_lists\xml\" + textList.Name + extension);
                try
                {
                    if (File.Exists(fileInfo.FullName))
                    {
                        File.Delete(fileInfo.FullName);
                    }
                    Console.WriteLine(textList.Name + " to " + fileInfo.FullName);
                    textList.Export(fileInfo, ExportOptions.WithDefaults);
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.ToString());
                }
            }
        }
Exemplo n.º 4
0
        static public void ImportTextListXML(XmlDocument doc, TextListComposition text_lists)
        {
            FileInfo path = TempFile.File("import_text_list_", "xml");

            try
            {
                XmlWriter writer = XmlWriter.Create(path.ToString());
                doc.Save(writer);
                writer.Close();
                text_lists.Import(path, ImportOptions.Override);
            }
            finally
            {
                try
                {
                    path.Delete();
                }
                catch (IOException e)
                {
                    Console.WriteLine("Failed to delete temporary file: " + e.Message);
                }
            }
        }
Exemplo n.º 5
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();
        }