Ejemplo n.º 1
0
        public PresetGenerate(TiaPortal portal, IEngineeringCompositionOrObject top, List <HmiTarget> hmiTargets, string culture)
        {
            InitializeComponent();
            tiaPortal    = portal;
            FormClosing += FormClosingEventHandler;
            presetListView.AutoGenerateColumns = false;
            presetList = new PresetTagList
            {
                Culture = culture
            };
            presetListView.DataSource = presetList;

            writeButton.Enabled  = false;
            exportButton.Enabled = false;
            parser            = new TagParser(portal);
            parser.HandleTag += HandleTag;
            parser.ParseDone += ParseDone;
            parser.ParseAsync(top, log);

            IEngineeringCompositionOrObject node = top;

            while (node.Parent is PlcBlockGroup)
            {
                node = node.Parent;
            }
            PlcBlockGroup top_group = (PlcBlockGroup)node;

            resultGroup = top_group.Groups.Find("Preset");
            if (resultGroup == null)
            {
                resultGroup = top_group.Groups.Create("Preset");
            }
            while (node != null && !(node is PlcSoftware))
            {
                node = node.Parent;
            }
            if (node == null)
            {
                throw new Exception("No PlcSoftware node found");
            }
            plcSoftware = (PlcSoftware)node;
            typeGroup   = plcSoftware.TypeGroup.Groups.Find("Preset");
            if (typeGroup == null)
            {
                typeGroup = plcSoftware.TypeGroup.Groups.Create("Preset");
            }
            this.hmiTargets = hmiTargets;

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

            cultureComboBox.Items.Clear();
            cultureComboBox.Items.AddRange(langs.Select(l => l.Culture.Name).ToArray());
            cultureComboBox.SelectedItem = culture;
        }
Ejemplo n.º 2
0
        private Dictionary <string, List <PresetTag> > tagGroups(PresetTagList presets)
        {
            Dictionary <string, List <PresetTag> > tag_groups = new Dictionary <string, List <PresetTag> >();

            foreach (PresetTagList.Row r in presets)
            {
                List <PresetTag> tags;
                // Add the tags to all groups in the tag
                foreach (string group_name in r.Tag.presetGroups)
                {
                    if (!tag_groups.TryGetValue(group_name, out tags))
                    {
                        tags = new List <PresetTag>();
                    }
                    tags.Add(r.Tag);
                    tags.Sort();
                    tag_groups[group_name] = tags;
                }
            }
            return(tag_groups);
        }