private void OnPresetGroupChanged(object sender, EventArgs e) { if (PresetList.SelectedItems.Count != 1) { return; } if (CurrentPreset != null && CurrentPreset.guid == PresetList.SelectedItems.First().preset.guid) { return; } CurrentPreset = PresetList.SelectedItems.First().preset.Clone(); this.txtName.Text = CurrentPreset.Name; this.txtInfo.Text = CurrentPreset.Description; WpfFunc.CmbSelect(this.cmbUndo, CurrentPreset.AutoUndo.ToString()); foreach (var item in CurrentPreset.Items.Values) { item.Sync(); } PresetItemList.UpdateItems(CurrentPreset.Items.Values.ToList()); CollapseAll(); }
private void Cleanup(object sender, CancelEventArgs e) { this.startWatcher.Stop(); this.stopWatcher.Stop(); this.settings.Data.MainWindowInfo.Top = this.Top; this.settings.Data.MainWindowInfo.Left = this.Left; this.settings.Data.MainWindowInfo.Width = this.Width; this.settings.Data.MainWindowInfo.Height = this.Height; this.settings.Data.MainWindowInfo.WindowState = this.WindowState; this.settings.Data.PresetGroups = PresetGroups.FromContext(this.dataContext); this.settings.Data.CurrentPresetGroup = PresetGroup.FromContext(this.dataContext[DataPath.CurrentPresetGroup] as NotifyingDataContext).Name; foreach (var presetGroup in this.settings.Data.PresetGroups) { foreach (var presetGroupRow in presetGroup.Rows) { if (presetGroupRow.Process.Id <= 0) { continue; } presetGroupRow.PreviousProcess.Id = presetGroupRow.Process.Id; presetGroupRow.Process.Id = 0; } } this.settings.SaveSettings(); }
private void BtnAddPreset_Click(object sender, RoutedEventArgs e) { InputWnd wnd = new InputWnd(Translate.fmt("msg_preset_name"), Translate.fmt("msg_preset_some"), App.Title); if (wnd.ShowDialog() != true || wnd.Value.Length == 0) { return; } var newPreset = new PresetGroup(); newPreset.Name = wnd.Value; App.presets.UpdatePreset(newPreset); }
private void BtnUndo_Click(object sender, RoutedEventArgs e) { CurrentPreset = null; OnPresetGroupChanged(null, null); }
private void exportButton_Click(object sender, EventArgs e) { if (savePresetList.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { ConstantLookup constants = new ConstantLookup(); constants.Populate(tiaPortal, plcSoftware); Dictionary <string, List <PresetTag> > tag_groups = tagGroups(presetList); PlcBlockGroup plc_preset_group = plcSoftware.BlockGroup.Groups.Find("Preset"); if (plc_preset_group == null) { MessageBox.Show("No group named Preset found for PLC " + plcSoftware.Name); return; } Dictionary <string, PresetGroup> preset_groups = new Dictionary <string, PresetGroup>(); foreach (string group_name in tag_groups.Keys) { PresetGroup group = new PresetGroup(); string preset_db_name = "sDB_Preset_" + group_name; PlcBlock preset_db = plc_preset_group.Blocks.Find(preset_db_name); if (preset_db == null) { MessageBox.Show("No block named " + preset_db_name + " found for PLC " + plcSoftware.Name); return; } XmlDocument doc; try { doc = TIAutils.ExportPlcBlockXML(preset_db); } catch (Exception ex) { MessageBox.Show("Failed to export block " + preset_db_name + ": " + ex.Message); return; } if (doc.DocumentElement.SelectSingleNode("/Document/SW.Blocks.GlobalDB//if:Section[@Name='Static']", XMLUtil.nameSpaces) is XmlElement static_elem) { group.preset_names = PresetValueParser.GetPresetNames(static_elem, constants); group.preset_colors = PresetValueParser.GetPresetColors(static_elem, constants); group.presets = new List <PresetDocument.PresetInfo>(); var tags = tag_groups[group_name]; foreach (var tag in tags) { var values = PresetValueParser.GetPresetValue(static_elem, tag.tagPath, constants); var enabled = PresetValueParser.GetPresetEnabled(static_elem, tag.tagPath, constants); Console.WriteLine(tag.tagPath + ":" + (string.Join(",", values))); group.presets.Add(new PresetDocument.PresetInfo() { tag = tag, values = values, enabled = enabled }); } preset_groups[group_name] = group; } else { MessageBox.Show("No static section found for " + preset_db_name); return; } } PresetDocument.Save(savePresetList.FileName, preset_groups, cultureComboBox.SelectedItem.ToString()); } catch (Exception ex) { MessageBox.Show("Failed to export preset list: " + ex.Message); } } }