/// /// Copyright (c) 2020 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using System.Windows.Forms; using SchematicDrawing; namespace TBF.UI.Bench.EditSchDrawing { public partial class AddEdgeDlg : Form { IList drawingItems; public Sz EdgeSize; public string EdgeStr; public AddEdgeDlg() { InitializeComponent(); } public AddEdgeDlg(IList drawingItems) : this() { this.drawingItems = drawingItems; foreach (var di in drawingItems) { fromComponentComboBox.Items.Add(di.Name); toComponentComboBox.Items.Add(di.Name); } for (Sz sz = Sz.S; sz <= Sz.XL; sz++) sizeComboBox.Items.Add(sz); } private void okButton_Click(object sender, EventArgs e) { if (drawingItems == null) { MessageBox.Show("There are no components"); return; } IDrawingItemCfg from = null; DrawingShape dshapeFrom = null; foreach (var di in drawingItems) { if (di.Name == fromComponentComboBox.Text) { from = di; dshapeFrom = DrawingShape.GetDrawingShape(from.Shape, from.Sz); break; } } if (from == null || dshapeFrom == null) { MessageBox.Show("Invalid From component"); return; } IDrawingItemCfg to = null; DrawingShape dshapeTo = null; foreach (var di in drawingItems) { if (di.Name == toComponentComboBox.Text) { to = di; dshapeTo = DrawingShape.GetDrawingShape(to.Shape, to.Sz); break; } } if (to == null || dshapeTo == null) { MessageBox.Show("Invalid To component"); return; } EdgeSize = Sz.Count; for (Sz sz = Sz.S; sz <= Sz.XL; sz++) { if (sz.ToString() == sizeComboBox.Text) { EdgeSize = sz; break; } } if (EdgeSize == Sz.Count) { MessageBox.Show("Invalid Size"); return; } uint fromNode; if (!uint.TryParse(fromNodeTextBox.Text, out fromNode) || fromNode >= dshapeFrom.Nodes.Length) { MessageBox.Show("Invalid From node"); return; } uint toNode; if (!uint.TryParse(toNodeTextBox.Text, out toNode) || toNode >= dshapeTo.Nodes.Length) { MessageBox.Show("Invalid To node"); return; } EdgeStr = string.Format("{0}~{1}~{2}~{3}", from.Name, fromNode, to.Name, toNode); DialogResult = DialogResult.OK; Close(); } private void cancelButton_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } } }