示例#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;
        }