TBF.UI.Bench.Paths controls support imperial units for flow.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2021 Sensus Slovensko a.s.
|
||||
/// Copyright (c) 2013-2022 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using log4net;
|
||||
using Common;
|
||||
using Common.Forms;
|
||||
using Config.Entities;
|
||||
using TBF.Rig.GenericDevices;
|
||||
@@ -26,6 +27,7 @@ namespace TBF.UI.Bench.Paths
|
||||
Name,
|
||||
Qfrom,
|
||||
Qto,
|
||||
FlowUnit,
|
||||
Selector,
|
||||
Pump,
|
||||
FixedColumnsCount,
|
||||
@@ -54,7 +56,11 @@ namespace TBF.UI.Bench.Paths
|
||||
.OrderBy(x => x.ItemNr).Asc
|
||||
.List();
|
||||
|
||||
foreach (var path in MyItems) path.OriName = path.Name;
|
||||
foreach (var path in MyItems)
|
||||
{
|
||||
path.OriName = path.Name;
|
||||
path.FlowUnit = TBF.Rig.Sequences.ProcessData.FlowUnit;
|
||||
}
|
||||
|
||||
SubItemClicked += new SubItemEventHandler(listViewEx_SubItemClicked);
|
||||
SubItemRightClicked += new SubItemEventHandler(listViewEx_SubItemRightClicked);
|
||||
@@ -62,11 +68,12 @@ namespace TBF.UI.Bench.Paths
|
||||
|
||||
/// ListViewEx columns
|
||||
TBF.LocalSettings ls = Program.LocalSettings;
|
||||
Columns.Add(Strings.Name, (ls.FeedingColumnCount > 0) ? ls.FeedingColumnWidths[0] : 60 * parent.Dpi / Constants.Dpi100pct);
|
||||
Columns.Add(string.Format("{0} [m3/h]", Strings.Q_from), (ls.FeedingColumnCount > 1) ? ls.FeedingColumnWidths[1] : 80 * parent.Dpi / Constants.Dpi100pct);
|
||||
Columns.Add(string.Format("{0} [m3/h]", Strings.Q_to), (ls.FeedingColumnCount > 2) ? ls.FeedingColumnWidths[2] : 80 * parent.Dpi / Constants.Dpi100pct);
|
||||
Columns.Add("Selector", (ls.FeedingColumnCount > 0) ? ls.FeedingColumnWidths[0] : 60 * parent.Dpi / Constants.Dpi100pct);
|
||||
Columns.Add(Strings.Pump, (ls.FeedingColumnCount > 3) ? ls.FeedingColumnWidths[3] : 60 * parent.Dpi / Constants.Dpi100pct);
|
||||
Columns.Add(Strings.Name, (ls.FeedingColumnCount > 0) ? ls.FeedingColumnWidths[0] : 60 * parent.Dpi / Constants.Dpi100pct);
|
||||
Columns.Add(Strings.Q_from, (ls.FeedingColumnCount > 1) ? ls.FeedingColumnWidths[1] : 80 * parent.Dpi / Constants.Dpi100pct);
|
||||
Columns.Add(Strings.Q_to, (ls.FeedingColumnCount > 2) ? ls.FeedingColumnWidths[2] : 80 * parent.Dpi / Constants.Dpi100pct);
|
||||
Columns.Add("Unit", (ls.FeedingColumnCount > 3) ? ls.FeedingColumnWidths[3] : 50 * parent.Dpi / Constants.Dpi100pct);
|
||||
Columns.Add("Selector", (ls.FeedingColumnCount > 4) ? ls.FeedingColumnWidths[4] : 60 * parent.Dpi / Constants.Dpi100pct);
|
||||
Columns.Add(Strings.Pump, (ls.FeedingColumnCount > 5) ? ls.FeedingColumnWidths[5] : 60 * parent.Dpi / Constants.Dpi100pct);
|
||||
int clmn = (int)Column.FixedColumnsCount;
|
||||
|
||||
foreach (var rv in parent.FeedingRegulValves)
|
||||
@@ -86,6 +93,10 @@ namespace TBF.UI.Bench.Paths
|
||||
}
|
||||
valvesCount = clmn - (int)Column.FixedColumnsCount - regvCount;
|
||||
|
||||
/// Flow unit
|
||||
var flowUnitBox = new ComboBox();
|
||||
for (Unit u = 0; u < Unit.Count; u++) if (Units.IsFlow(u)) flowUnitBox.Items.Add(u.ToDescription());
|
||||
|
||||
/// Pump
|
||||
ComboBox pumpCBox = new ComboBox();
|
||||
pumpCBox.Items.Add("---");
|
||||
@@ -95,10 +106,11 @@ namespace TBF.UI.Bench.Paths
|
||||
}
|
||||
|
||||
editors = new Control[fixedColumnsCount + regvCount + 64];
|
||||
///
|
||||
///
|
||||
editors[(int)Column.Name] = new TextBox(); /// Name
|
||||
editors[(int)Column.Qfrom] = new TextBox(); /// Q_from
|
||||
editors[(int)Column.Qto] = new TextBox(); /// Q_to
|
||||
editors[(int)Column.FlowUnit] = flowUnitBox; /// Flow unit
|
||||
editors[(int)Column.Selector] = new TextBox(); /// Selector
|
||||
editors[(int)Column.Pump] = pumpCBox;
|
||||
for (int i = 0; i < regvCount; i++)
|
||||
@@ -134,7 +146,8 @@ namespace TBF.UI.Bench.Paths
|
||||
|
||||
void listViewEx_SubItemClicked(object sender, SubItemEventArgs e)
|
||||
{
|
||||
if (!Unlocked || e.SubItem >= editors.Length) return;
|
||||
if (e.SubItem != (int)Column.FlowUnit && (!Unlocked || e.SubItem >= editors.Length)) return;
|
||||
|
||||
if ((e.Item.Tag is IHasItemNr) &&
|
||||
((e.Item.Tag as IHasItemNr).ItemNr < FixedRowsCount) &&
|
||||
(e.SubItem < fixedColumnsCount))
|
||||
@@ -160,6 +173,8 @@ namespace TBF.UI.Bench.Paths
|
||||
{
|
||||
item.SubItems[columnNr].Text = value;
|
||||
item.SubItems[columnNr].BackColor = backColor;
|
||||
|
||||
if (columnNr == (int)Column.FlowUnit) UpdateFlow(item, Units.FromDescription(value));
|
||||
}
|
||||
else if (item == e.Item)
|
||||
{
|
||||
@@ -172,10 +187,66 @@ namespace TBF.UI.Bench.Paths
|
||||
|
||||
void listViewEx_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e)
|
||||
{
|
||||
var entity = e.Item.Tag as Config.Entities.FeedingPath;
|
||||
float fdummy;
|
||||
|
||||
if (e.SubItem >= fixedColumnsCount + regvCount)
|
||||
{
|
||||
e.Item.SubItems[e.SubItem].BackColor = (e.DisplayText == Strings.open) ? Color.LightGray : Color.White;
|
||||
}
|
||||
else if (e.SubItem == (int)Column.Qfrom)
|
||||
{
|
||||
if (Utils.TryParseUFloat(e.DisplayText, out fdummy))
|
||||
{
|
||||
entity.QfromTextChngd = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
else if (e.SubItem == (int)Column.Qto)
|
||||
{
|
||||
if (Utils.TryParseUFloat(e.DisplayText, out fdummy))
|
||||
{
|
||||
entity.QtoTextChngd = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
else if (e.SubItem == (int)Column.FlowUnit)
|
||||
{
|
||||
Unit newUnit = Units.FromDescription(e.DisplayText);
|
||||
if (Units.IsFlow(newUnit))
|
||||
{
|
||||
UpdateFlow(e.Item, newUnit);
|
||||
}
|
||||
else
|
||||
{
|
||||
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateFlow(ListViewItem item, Unit newUnit)
|
||||
{
|
||||
var entity = item.Tag as Config.Entities.FeedingPath;
|
||||
if (entity == null || !Units.IsFlow(newUnit) || newUnit == entity.FlowUnit) return;
|
||||
Unit oriUnit = entity.FlowUnit;
|
||||
entity.FlowUnit = newUnit;
|
||||
|
||||
int ix = (int)Column.Qfrom;
|
||||
double flowM3ph = Units.ConvertFrom(oriUnit, Utils.ParseUDouble(item.SubItems[ix].Text));
|
||||
item.SubItems[ix].Text = Units.ConvertTo(newUnit, entity.QfromTextChngd ? flowM3ph : entity.Qfrom).ToString();
|
||||
|
||||
ix = (int)Column.Qto;
|
||||
flowM3ph = Units.ConvertFrom(oriUnit, Utils.ParseUDouble(item.SubItems[ix].Text));
|
||||
item.SubItems[ix].Text = Units.ConvertTo(newUnit, entity.QtoTextChngd ? flowM3ph : entity.Qto).ToString();
|
||||
}
|
||||
|
||||
public override void DrawOne(object myItem)
|
||||
@@ -186,8 +257,9 @@ namespace TBF.UI.Bench.Paths
|
||||
ListViewItem lvi = new ListViewItem(entity.Name);
|
||||
lvi.UseItemStyleForSubItems = false;
|
||||
|
||||
lvi.SubItems.Add(path.Qfrom.ToString());
|
||||
lvi.SubItems.Add(path.Qto.ToString());
|
||||
lvi.SubItems.Add(Units.ConvertTo(entity.FlowUnit, path.Qfrom).ToString()); /// Q_from
|
||||
lvi.SubItems.Add(Units.ConvertTo(entity.FlowUnit, path.Qto).ToString()); /// Q_to
|
||||
lvi.SubItems.Add(entity.FlowUnit.ToDescription());
|
||||
lvi.SubItems.Add(path.Selector);
|
||||
lvi.SubItems.Add(path.Pump != null ? path.Pump.Cfg.Name : "---");
|
||||
|
||||
@@ -233,11 +305,11 @@ namespace TBF.UI.Bench.Paths
|
||||
|
||||
float Qfrom;
|
||||
bool allOk = Utils.TryParseUFloat(lvi.SubItems[(int)Column.Qfrom].Text, out Qfrom);
|
||||
entity.Qfrom = Qfrom;
|
||||
entity.Qfrom = Units.ConvertFrom(entity.FlowUnit, Qfrom);
|
||||
|
||||
float Qto;
|
||||
allOk &= Utils.TryParseUFloat(lvi.SubItems[(int)Column.Qto].Text, out Qto);
|
||||
entity.Qto = Qto;
|
||||
entity.Qto = Units.ConvertFrom(entity.FlowUnit, Qto);
|
||||
|
||||
entity.Selector = lvi.SubItems[(int)Column.Selector].Text;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user