private void Test() { textBox5.Text = ""; textBox6.Text = "?"; if (comboBox1.SelectedIndex == -1) { return; } Align align = Utils.StringToAlign(comboBox1.SelectedItem.ToString()); if (comboBox2.SelectedIndex == -1) { return; } Trim trim = Utils.StringToTrim(comboBox2.SelectedItem.ToString()); if (comboBox3.SelectedIndex == -1) { return; } Append append = Utils.StringToAppend(comboBox3.SelectedItem.ToString()); string appendString = textBox3.Text; if (append == HomeSimCockpitX.LCD.Append.None || appendString.Length > 0) { int characters = listView2.Items.Count; int start = 0; textBox5.Text = LCDArea.FormatText(align, trim, append, appendString, characters, textBox4.Text, out start); textBox6.Text = start.ToString(); } }
void DataGridView1CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (Working && e.RowIndex > -1 && e.ColumnIndex == 2) { LCDArea area = (LCDArea)dataGridView1.Rows[e.RowIndex].Tag; area.WriteText((string)dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value); } }
public AddEditLCDArea(XMLConfiguration configuration, int areIndex) { InitializeComponent(); _configuration = configuration; _areaIndex = areIndex; foreach (Enum s in Enum.GetValues(typeof(Align))) { comboBox1.Items.Add(HomeSimCockpitX.LCD.Utils.AlignToString((Align)s)); } foreach (Enum s in Enum.GetValues(typeof(Trim))) { comboBox2.Items.Add(HomeSimCockpitX.LCD.Utils.TrimToString((Trim)s)); } foreach (Enum s in Enum.GetValues(typeof(Append))) { comboBox3.Items.Add(HomeSimCockpitX.LCD.Utils.AppendToString((Append)s)); } Array.Sort(_configuration.LCDs); foreach (LCD lcd in _configuration.LCDs) { comboBox4.Items.Add(lcd); } if (areIndex < 0) { // dodanie nowego Text = "Dodaj nowy obszar"; } else { // edycja istniejącego LCDArea area = configuration.Areas[areIndex]; Text = "Edycja obszaru '" + area.ID + "'"; textBox1.Text = area.ID; textBox2.Text = area.Description; comboBox1.SelectedItem = Utils.AlignToString(area.Align); comboBox2.SelectedItem = Utils.TrimToString(area.Trim); comboBox3.SelectedItem = Utils.AppendToString(area.Append); textBox3.Text = area.AppendString; ShowCharacters(); } }
public LCDOutputVariable(LCDArea lcdArea) { _lcdArea = lcdArea; _id = string.Format("{0}", _lcdArea.ID); }
public void SetValue(object value) { LCDArea.WriteText((string)value); }
public RS232LCDArea(LCDArea lcdArea) { LCDArea = lcdArea; }
private void button1_Click(object sender, EventArgs e) { // sprawdzenie poprawności danych string id = textBox1.Text.Trim(); textBox1.Text = id; if (id.Length == 0) { MessageBox.Show(this, "Identyfikator nie może być pusty.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBox1.Focus(); return; } string description = textBox2.Text.Trim(); textBox2.Text = description; if (description.Length == 0) { //MessageBox.Show(this, "Opis nie może być pusty.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); //textBox2.Focus(); //return; } if (comboBox1.SelectedIndex == -1) { MessageBox.Show(this, "Nie wybrano rodzaju wyrównania.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); comboBox1.Focus(); return; } Align align = Utils.StringToAlign(comboBox1.SelectedItem.ToString()); if (comboBox2.SelectedIndex == -1) { MessageBox.Show(this, "Nie wybrano rodzaju przycięcia.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); comboBox2.Focus(); return; } Trim trim = Utils.StringToTrim(comboBox2.SelectedItem.ToString()); if (comboBox3.SelectedIndex == -1) { MessageBox.Show(this, "Nie wybrano rodzaju dołączenia.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); comboBox3.Focus(); return; } Append append = Utils.StringToAppend(comboBox3.SelectedItem.ToString()); string appendString = textBox3.Text; if (append != Append.None && appendString.Length == 0) { MessageBox.Show(this, "Nie wpisano ciągu dołączanego.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBox3.Focus(); return; } // sprawdzenie czy istnieje już obszar o takim id for (int i = 0; i < _configuration.Areas.Length; i++) { if (i == _areaIndex) { continue; } if (_configuration.Areas[i].ID == id) { MessageBox.Show(this, string.Format("Istnieje już obszar o identyfikatorze '{0}'.", id), "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBox1.Focus(); return; } } LCDArea area = null; List <LCDCharacter> characters = new List <LCDCharacter>(); if (_areaIndex > -1) { area = _configuration.Areas[_areaIndex]; characters.AddRange(_configuration.Areas[_areaIndex].Characters); } else { area = new LCDArea(); List <LCDArea> areas = new List <LCDArea>(); areas.AddRange(_configuration.Areas); areas.Add(area); _configuration.Areas = areas.ToArray(); characters.AddRange(Array.ConvertAll <RS232LCDCharacter, LCDCharacter>(_characters.ToArray(), new Converter <RS232LCDCharacter, LCDCharacter>(RS232LCDCharacter.Convert))); } if (characters.Count == 0) { MessageBox.Show(this, "Obszar musi składać się co najmniej z jednego znaku.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } area.ID = id; area.Description = description; area.Align = align; area.Trim = trim; area.Append = append; area.AppendString = appendString; area.Set(characters.ToArray()); area.ArrangeCharacters(); DialogResult = DialogResult.OK; }
public static XMLConfiguration Load() { if (__instance != null) { return(__instance); } if (!File.Exists(ConfigurationFilePath)) { throw new FileNotFoundException(ConfigurationFilePath); } XMLConfiguration c = new XMLConfiguration(); XmlDocument xml = new XmlDocument(); xml.Load(ConfigurationFilePath); // wczytanie interfejsów List <RS232Configuration> interfaces = new List <RS232Configuration>(); XmlNodeList nodes = xml.SelectNodes("/configuration/interfaces/interface"); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { RS232Configuration interf = RS232Configuration.Load(node); interfaces.Add(interf); } } c.Interfaces = interfaces.ToArray(); // wczytanie urządzeń z LCD List <LCDDevice> lcdDevices = new List <LCDDevice>(); nodes = xml.SelectNodes("/configuration/lcdDevices/lcdDevice"); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { LCDDevice lcdDevice = LCDDevice.Load(node, interfaces); if (lcdDevice != null) { lcdDevices.Add(lcdDevice); } } } c.LCDDevices = lcdDevices.ToArray(); // wczytanie LCD List <RS232LCD> lcds = new List <RS232LCD>(); nodes = xml.SelectNodes("/configuration/lcds/lcd"); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { RS232LCD lcd = RS232LCD.Load(lcdDevices, node); if (lcd != null) { lcds.Add(lcd); } } } c.LCDs = lcds.ToArray(); // wczytanie obszarów LCD List <LCDArea> areas = new List <LCDArea>(); nodes = xml.SelectNodes("/configuration/lcdAreas/area"); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { LCDArea area = new LCDArea(node, new LCDSet(lcds)); areas.Add(area); } } c.Areas = areas.ToArray(); // wczytanie urządzeń z LED List <LEDDevice> ledDevices = new List <LEDDevice>(); nodes = xml.SelectNodes("/configuration/ledDevices/ledDevice"); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { LEDDevice ledDevice = LEDDevice.Load(node, interfaces); if (ledDevice != null) { ledDevices.Add(ledDevice); } } } c.LEDDevices = ledDevices.ToArray(); // wczytanie LED List <LED> leds = new List <LED>(); nodes = xml.SelectNodes("/configuration/leds/led"); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { LED led = LED.Load(node, ledDevices); if (led != null) { leds.Add(led); } } } c.LEDs = leds.ToArray(); // wczytanie obszarów LED List <LEDGroup> ledGroups = new List <LEDGroup>(); nodes = xml.SelectNodes("/configuration/leds/leds"); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { LEDGroup ledGroup = LEDGroup.Load(node, leds); if (ledGroup != null) { ledGroups.Add(ledGroup); } } } c.LEDGroups = ledGroups.ToArray(); // wczytanie urządzeń z 7-LED List <LEDDisplayDevice> ledDisplayDevices = new List <LEDDisplayDevice>(); nodes = xml.SelectNodes("/configuration/ledDisplayDevices/ledDisplayDevice"); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { LEDDisplayDevice ledDisplayDevice = LEDDisplayDevice.Load(node, interfaces); if (ledDisplayDevice != null) { ledDisplayDevices.Add(ledDisplayDevice); } } } c.LEDDisplayDevices = ledDisplayDevices.ToArray(); // wczytanie 7-LED List <LEDDisplay> ledDisplays = new List <LEDDisplay>(); nodes = xml.SelectNodes("/configuration/ledDisplays/ledDisplay"); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { LEDDisplay ledDisplay = LEDDisplay.Load(node, ledDisplayDevices); if (ledDisplay != null) { ledDisplays.Add(ledDisplay); } } } c.LEDDisplays = ledDisplays.ToArray(); // wczytanie obszarów 7-LED List <LEDDisplayGroup> ledDisplayGroups = new List <LEDDisplayGroup>(); nodes = xml.SelectNodes("/configuration/ledDisplays/ledDisplays"); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { LEDDisplayGroup ledDisplayGroup = LEDDisplayGroup.Load(node, ledDisplays); if (ledDisplayGroup != null) { ledDisplayGroups.Add(ledDisplayGroup); } } } c.LEDDisplayGroups = ledDisplayGroups.ToArray(); // wczytanie słownika dla wyświetlaczy 7-segmentowych XmlNode dictionaryNode = xml.SelectSingleNode("/configuration/ledDisplaysDictionary"); c.LEDDisplaysDictionary = LEDDisplaysDictionary.Load(dictionaryNode); // wczytanie urządzeń Keys List <KeysDevice> keysDevices = new List <KeysDevice>(); nodes = xml.SelectNodes("/configuration/keysDevices/keysDevice"); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { KeysDevice keysDevice = KeysDevice.Load(node, interfaces); if (keysDevice != null) { keysDevices.Add(keysDevice); } } } c.KeysDevices = keysDevices.ToArray(); // wczytanie keys List <Key> keys = new List <Key>(); nodes = xml.SelectNodes("/configuration/keys/key"); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { Key key = Key.Load(node, keysDevices); if (key != null) { keys.Add(key); } } } c.Keys = keys.ToArray(); // wczytanie encoders List <Encoder> encoders = new List <Encoder>(); nodes = xml.SelectNodes("/configuration/encoders/encoder"); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { Encoder encoder = Encoder.Load(node, keysDevices); if (encoder != null) { encoders.Add(encoder); // przypisanie enkoderów do wejść (wykrywanie szybkiego kręcenia) foreach (Key key in c.Keys) { if (key.KeysDevice == encoder.KeysDevice) { if (key.Index == encoder.LeftIndex || key.Index == encoder.RightIndex) { key.Encoder = encoder; } } } } } } c.Encoders = encoders.ToArray(); // wczytanie stepper motors List <StepperDevice> stepperDevices = new List <StepperDevice>(); nodes = xml.SelectNodes("/configuration/stepperDevices/stepperDevice"); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { StepperDevice stepperDevice = StepperDevice.Load(node, interfaces); if (stepperDevice != null) { stepperDevices.Add(stepperDevice); } } } c.StepperDevices = stepperDevices.ToArray(); // wczytanie servo devices List <ServoDevice> servoDevices = new List <ServoDevice>(); nodes = xml.SelectNodes("/configuration/servoDevices/servoDevice"); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { ServoDevice servoDevice = ServoDevice.Load(node, interfaces); if (servoDevice != null) { servoDevices.Add(servoDevice); } } } c.ServoDevices = servoDevices.ToArray(); __instance = c; return(__instance); }