tbf/TBF/UI/Process/ProcessTabPageCtrl6.cs

713 lines
29 KiB
C#

///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Drawing;
using System.Windows.Forms;
using log4net;
using Common;
using Config.Entities;
using Results.Entities;
using TBF.Rig.Sequences;
using TBF.UiBridge;
using TBF.Resources;
#pragma warning disable 162 /// Disables 'Unreachable code detected' warning
namespace TBF.UI.Process
{
public partial class ProcessTabPageCtrl6 : UserControl
{
static readonly ILog log = LogManager.GetLogger(typeof(ProcessTabPageCtrl6));
MetersKind currentMetersKind;
int textBoxesCount;
Label[] sensor;
Label[] pulses;
Label[] refPulses;
Label[] volume;
Label[] error;
Label[] passed;
Label[] cmpndVolume;
Label[] cmpndError;
Label[] cmpndPassed;
bool pumpOn = true;
bool diverterToTank = true;
/// <summary>
/// Constructor, initializes anonymous event handlers
/// </summary>
public ProcessTabPageCtrl6()
{
currentMetersKind = MetersKind.Single;
InitializeComponent();
textBoxesCount = 6;
sensor = new Label[] { sensor1Label, sensor2Label, sensor3Label, sensor4Label, sensor5Label, sensor6Label };
pulses = new Label[] { pulses1Label, pulses2Label, pulses3Label, pulses4Label, pulses5Label, pulses6Label };
refPulses = new Label[] { refPulses1Label, refPulses2Label, refPulses3Label, refPulses4Label, refPulses5Label, refPulses6Label };
volume = new Label[] { volume1Label, volume2Label, volume3Label, volume4Label, volume5Label, volume6Label };
error = new Label[] { error1Label, error2Label, error3Label, error4Label, error5Label, error6Label };
passed = new Label[] { passed1Label, passed2Label, passed3Label, passed4Label, passed5Label, passed6Label };
cmpndVolume = new Label[] { volume1zLabel, volume2zLabel, volume3zLabel };
cmpndError = new Label[] { error1zLabel, error2zLabel, error3zLabel };
cmpndPassed = new Label[] { passed1zLabel, passed2zLabel, passed3zLabel };
Bridge.ProcedureSelectedHandler += delegate(object sndr, ProcedureSelectedEventArgs args)
{
try
{
if (InvokeRequired)
Invoke(new EventHandler<ProcedureSelectedEventArgs>(OnProcedureSelected), sndr, args);
else
OnProcedureSelected(sndr, args);
}
catch (Exception e) { log.ErrorFormat("ProcessTabPage.OnProcedureSelected() failed: {0}", e.Message); }
};
Bridge.TestSelectedHandler += delegate(object sender, TestSelectedEventArgs args)
{
try
{
if (InvokeRequired)
Invoke(new EventHandler<TestSelectedEventArgs>(OnTestSelected), sender, args);
else
OnTestSelected(sender, args);
}
catch (Exception e) { log.ErrorFormat("ProcessTabPage.OnTestSelected() failed: {0}", e.Message); }
};
Bridge.ProcessDataHandler += delegate(object sender, ProcessDataEventArgs args)
{
try
{
if (InvokeRequired)
Invoke(new EventHandler<ProcessDataEventArgs>(OnProcessDataChanged), sender, args);
else
OnProcessDataChanged(sender, args);
}
catch (Exception e) { log.ErrorFormat("ProcessTabPage.OnProcessDataChanged() failed: {0}", e.Message); }
};
Bridge.TestCompletedHandler += delegate(object sender, TestCompletedEventArgs args)
{
try
{
if (InvokeRequired)
Invoke(new EventHandler<TestCompletedEventArgs>(OnTestCompleted), sender, args);
else
OnTestCompleted(sender, args);
}
catch (Exception e) { log.ErrorFormat("ProcessTabPage.OnTestCompleted() failed: {0}", e.Message); }
};
Bridge.ProcedureCompletedHandler += delegate(object sender, ProcedureCompletedEventArgs args)
{
try
{
if (InvokeRequired)
Invoke(new EventHandler<ProcedureCompletedEventArgs>(OnProcedureCompleted), sender, args);
else
OnProcedureCompleted(sender, args);
}
catch (Exception e) { log.ErrorFormat("ProcessTabPage.OnProcedureCompleted() failed: {0}", e.Message); }
};
}
private void ProcessTabPageCtrl_Load(object sender, EventArgs e)
{
Localize();
Once();
ResetLabelsAndTargetVals();
ResetReadings();
}
void Localize()
{
airTempCapLabel.Text = string.Format("{0} [°C]:", Strings.Air_temperature);
airPressCapLabel.Text = string.Format("{0} [mbar]:", Strings.Air_pressure);
airHumiCapLabel.Text = string.Format("{0} [%]:", Strings.Air_humidity);
targetFlowLowCapLabel.Text = Strings.Target_flow_lo_m3h_;
targetFlowHighCapLabel.Text = Strings.Target_flow_hi_m3h_;
targetVolumeCapLabel.Text = Strings.Target_volume_l_;
targetRefCountCapLabel.Text = Strings.Target_ref_pulses_;
estmtdTimeCapLabel.Text = Strings.Estimated_time_s_;
prUpCapLabel.Text = string.Format("{0} [bar]:", Strings.Pr_up);
prDownCapLabel.Text = string.Format("{0} [bar]:", Strings.Pr_down);
tInCapLabel.Text = string.Format("{0} [°C]:", Strings.T_in);
tOutCapLabel.Text = string.Format("{0} [°C]:", Strings.T_out);
tDivCapLabel.Text = string.Format("{0} [°C]:", Strings.T_div);
regValvePosCapLabel.Text = string.Format("{0}:", Strings.Reg_valve_pos);
refPulsesCapLabel.Text = string.Format("{0}:", Strings.Ref_pulses);
refFreqCapLabel.Text = Strings.Ref_freq_Hz_;
refFlowCapLabel.Text = Strings.Ref_flow_m3h_;
refVolumeCapLabel.Text = Strings.Ref_volume_l_;
massCapLabel.Text = string.Format("{0} [kg]:", Strings.Mass);
massDiffCapLabel.Text = Strings.Mass_diff_kg_;
volumeCtvCapLabel.Text = string.Format("{0} [l]:", Strings.Volume);
refErrorCapLabel.Text = Strings.Ref_error_pct_;
GroupBox[] groupBoxes = new GroupBox[] { groupBox1, groupBox2, groupBox3, groupBox4, groupBox5, groupBox6 };
for (int i = 0; i < groupBoxes.Length; i++) groupBoxes[i].Text = string.Format(string.Format("{0} {1}", Strings.Meter, i + 1));
sensor1CapLabel.Text = sensor2CapLabel.Text = sensor3CapLabel.Text = sensor4CapLabel.Text = sensor5CapLabel.Text = sensor6CapLabel.Text = Strings.Sensor;
pulses1CapLabel.Text = pulses2CapLabel.Text = pulses3CapLabel.Text = pulses4CapLabel.Text = pulses5CapLabel.Text = pulses6CapLabel.Text = Strings.Pulses;
refPulses1CapLabel.Text = refPulses2CapLabel.Text = refPulses3CapLabel.Text = refPulses4CapLabel.Text = refPulses5CapLabel.Text = refPulses6CapLabel.Text = Strings.Ref_pulses;
volume1CapLabel.Text = volume2CapLabel.Text = volume3CapLabel.Text = volume4CapLabel.Text = volume5CapLabel.Text = volume6CapLabel.Text = Strings.Volume + ":";
error1CapLabel.Text = error2CapLabel.Text = error3CapLabel.Text = error4CapLabel.Text = error5CapLabel.Text = error6CapLabel.Text = Strings.Error + ":";
GroupBox[] groupBoxesZ = new GroupBox[] { groupBox1z, groupBox2z, groupBox3z };
for (int i = 0; i < groupBoxesZ.Length; i++) groupBoxesZ[i].Text = string.Format(Strings.Compound_meter_0, i + 1);
volume1zCapLabel.Text = volume2zCapLabel.Text = volume3zCapLabel.Text = Strings.Volume + ":";
error1zCapLabel.Text = error2zCapLabel.Text = error3zCapLabel.Text = Strings.Error + ":";
}
void Once()
{
}
/// <summary>
/// Called when a new procedure is selected
/// </summary>
void ResetLabelsAndTargetVals()
{
/// Target values
targetFlowLowLabel.Text = "---";
targetFlowHighLabel.Text = "---";
targetVolumeLabel.Text = "---";
targetRefCountLabel.Text = "---";
estmtdTimeLabel.Text = "---";
//
refFlowCmpntLabel.Text = "---";
regValveCmpntLabel.Text = "---";
/// Water pressure
prInCmpntLabel.Text = "---";
prOutCmpntLabel.Text = "---";
/// Water temperature
tInCmpntLabel.Text = "---";
tOutCmpntLabel.Text = "---";
tDivCmpntLabel.Text = "---";
scaleCmpntLabel.Text = "---";
if (currentMetersKind == MetersKind.Single)
{
watermeterPictureBox1z.Visible = false;
watermeterPictureBox2z.Visible = false;
watermeterPictureBox3z.Visible = false;
groupBox1z.Visible = false;
groupBox2z.Visible = false;
groupBox3z.Visible = false;
sensor1Label.Text = "---";
if (TBF.Data.WMsCount >= 2) { sensor2Label.Text = "---"; }
else { groupBox2.Visible = false; watermeterPictureBox2.Visible = false; }
if (TBF.Data.WMsCount >= 3) { sensor3Label.Text = "---"; }
else { groupBox3.Visible = false; watermeterPictureBox3.Visible = false; }
if (TBF.Data.WMsCount >= 4) { sensor4Label.Text = "---"; }
else { groupBox4.Visible = false; watermeterPictureBox4.Visible = false; }
if (TBF.Data.WMsCount >= 5) { sensor5Label.Text = "---"; }
else { groupBox5.Visible = false; watermeterPictureBox5.Visible = false; }
if (TBF.Data.WMsCount >= 6) { sensor6Label.Text = "---"; }
else { groupBox6.Visible = false; watermeterPictureBox6.Visible = false; }
}
else if (currentMetersKind == MetersKind.Combined)
{
watermeterPictureBox1.Visible = false;
watermeterPictureBox3.Visible = false;
watermeterPictureBox5.Visible = false;
sensor1Label.Text = "---";
sensor2Label.Text = "---";
watermeterPictureBox2.Visible = true;
watermeterPictureBox1z.Visible = true;
groupBox1z.Visible = true;
if (TBF.Data.WMsCount >= 4)
{
watermeterPictureBox4.Visible = true;
watermeterPictureBox2z.Visible = true;
groupBox3.Visible = true;
groupBox4.Visible = true;
groupBox2z.Visible = true;
sensor3Label.Text = "---";
sensor4Label.Text = "---";
}
else
{
watermeterPictureBox4.Visible = false;
watermeterPictureBox2z.Visible = false;
groupBox3.Visible = false;
groupBox4.Visible = false;
groupBox2z.Visible = false;
}
if (TBF.Data.WMsCount >= 6)
{
watermeterPictureBox6.Visible = true;
watermeterPictureBox3z.Visible = true;
groupBox5.Visible = true;
groupBox6.Visible = true;
groupBox3z.Visible = true;
sensor5Label.Text = "---";
sensor6Label.Text = "---";
}
else
{
watermeterPictureBox6.Visible = false;
watermeterPictureBox3z.Visible = false;
groupBox5.Visible = false;
groupBox6.Visible = false;
groupBox3z.Visible = false;
}
}
}
/// <summary>
/// Called when a new procedure or a new test procedure is selected
/// </summary>
void ResetReadings()
{
/// Top part
airTempLabel.Text = "---";
airPressLabel.Text = "---";
airHumiLabel.Text = "---";
refPulsesLabel.Text = "---";
refFreqLabel.Text = "---";
refFlowLabel.Text = "---";
refVolumeLabel.Text = "---";
regValvePosLabel.Text = "---";
tDivLabel.Text = "---";
tInLabel.Text = "---";
tOutLabel.Text = "---";
prUpLabel.Text = "---";
prDownLabel.Text = "---";
massLabel.Text = "---";
massDiffLabel.Text = "---";
volumeCtvLabel.Text = "---";
refErrorLabel.Text = "---";
/// Meters
pulses1Label.Text = "---";
refPulses1Label.Text = "---";
volume1Label.Text = "---";
error1Label.Text = "---";
passed1Label.Text = "---";
if (TBF.Data.WMsCount >= 2)
{
pulses2Label.Text = "---";
refPulses2Label.Text = "---";
volume2Label.Text = "---";
error2Label.Text = "---";
passed2Label.Text = "---";
}
if (currentMetersKind == MetersKind.Combined && TBF.Data.WMsCount >= 2)
{
volume1zLabel.Text = "---";
error1zLabel.Text = "---";
passed1zLabel.Text = "---";
}
if ((currentMetersKind == MetersKind.Single && TBF.Data.WMsCount >= 3) ||
(currentMetersKind == MetersKind.Combined && TBF.Data.WMsCount >= 4))
{
pulses3Label.Text = "---";
refPulses3Label.Text = "---";
volume3Label.Text = "---";
error3Label.Text = "---";
passed3Label.Text = "---";
}
if (TBF.Data.WMsCount >= 4)
{
pulses4Label.Text = "---";
refPulses4Label.Text = "---";
volume4Label.Text = "---";
error4Label.Text = "---";
passed4Label.Text = "---";
}
if (currentMetersKind == MetersKind.Combined && TBF.Data.WMsCount >= 4)
{
volume2zLabel.Text = "---";
error2zLabel.Text = "---";
passed2zLabel.Text = "---";
}
if ((currentMetersKind == MetersKind.Single && TBF.Data.WMsCount >= 5) ||
(currentMetersKind == MetersKind.Combined && TBF.Data.WMsCount >= 6))
{
pulses5Label.Text = "---";
refPulses5Label.Text = "---";
volume5Label.Text = "---";
error5Label.Text = "---";
passed5Label.Text = "---";
}
if (TBF.Data.WMsCount >= 6)
{
pulses6Label.Text = "---";
refPulses6Label.Text = "---";
volume6Label.Text = "---";
error6Label.Text = "---";
passed6Label.Text = "---";
}
if (currentMetersKind == MetersKind.Combined && TBF.Data.WMsCount >= 6)
{
volume3zLabel.Text = "---";
error3zLabel.Text = "---";
passed3zLabel.Text = "---";
}
}
void OnProcedureSelected(object sender, ProcedureSelectedEventArgs args)
{
currentMetersKind = args.Procedure.MetersKind;
ResetLabelsAndTargetVals();
ResetReadings();
Invalidate();
}
void OnTestSelected(object sender, TestSelectedEventArgs args)
{
/// Readings and target values
ResetReadings();
/// Target values
targetFlowLowLabel.Text = args.Test.Qfrom.ToString("F3");
targetFlowHighLabel.Text = args.Test.Qto.ToString("F3");
targetVolumeLabel.Text = args.Test.Volume.ToString("F1");
targetRefCountLabel.Text = args.TotalPulses.ToString();
estmtdTimeLabel.Text = args.Test.TestTime.ToString("F1");
/// Names of virtual bench components
if (args.BenchPath.PressMtrUp != null) prInCmpntLabel.Text = args.BenchPath.PressMtrUp.Name;
if (args.BenchPath.PressMtrDown != null) prOutCmpntLabel.Text = args.BenchPath.PressMtrDown.Name;
if (args.BenchPath.TempMtrUp != null) tInCmpntLabel.Text = args.BenchPath.TempMtrUp.Name;
if (args.BenchPath.TempMtrDown != null) tOutCmpntLabel.Text = args.BenchPath.TempMtrDown.Name;
if (args.OutputPath.TempDiv != null) tDivCmpntLabel.Text = args.OutputPath.TempDiv.Name;
if (args.OutputPath.FlowMeter != null) refFlowCmpntLabel.Text = args.OutputPath.FlowMeter.Name;
if (args.OutputPath.RegulValve != null) regValveCmpntLabel.Text = args.OutputPath.RegulValve.Name;
if (args.OutputPath.Scale != null) scaleCmpntLabel.Text = args.OutputPath.Scale.Name;
sensor1Label.Text = (args.MetersPath.RegisterReaders[0] == null) ? "" : args.MetersPath.RegisterReaders[0].Cfg.Name;
if (TBF.Data.WMsCount >= 2)
{
sensor2Label.Text = (args.MetersPath.RegisterReaders[1] == null) ? "" : args.MetersPath.RegisterReaders[1].Cfg.Name;
}
if (TBF.Data.WMsCount >= 3)
{
sensor3Label.Text = (args.MetersPath.RegisterReaders[2] == null) ? "" : args.MetersPath.RegisterReaders[2].Cfg.Name;
}
if (TBF.Data.WMsCount >= 4)
{
sensor4Label.Text = (args.MetersPath.RegisterReaders[3] == null) ? "" : args.MetersPath.RegisterReaders[3].Cfg.Name;
}
if (TBF.Data.WMsCount >= 5)
{
sensor5Label.Text = (args.MetersPath.RegisterReaders[4] == null) ? "" : args.MetersPath.RegisterReaders[4].Cfg.Name;
}
if (TBF.Data.WMsCount >= 6)
{
sensor6Label.Text = (args.MetersPath.RegisterReaders[5] == null) ? "" : args.MetersPath.RegisterReaders[5].Cfg.Name;
}
if (args.FeedingPath != null && (args.FeedingPath.Pump is Rig.GenericDevices.IPumpFM))
{
pumpPctTextBox.Visible = true;
pumpPctTextBox.Text = (args.FeedingPath.Pump as Rig.GenericDevices.IPumpFM).Power.ToString("F0") + " %";
}
else
{
pumpPctTextBox.Visible = false;
}
}
void OnProcessDataChanged(object sender, ProcessDataEventArgs args)
{
///
/// Always available
///
airTempLabel.Text = Common.Units.ConvertTo(Common.Unit.C, ProcessData.AmbTemp.Val).ToString("F1");
airPressLabel.Text = Common.Units.ConvertTo(Common.Unit.mbar, ProcessData.AmbPress.Val).ToString("F0");
airHumiLabel.Text = Common.Units.ConvertTo(Common.Unit.RPct, ProcessData.AmbHumi.Val).ToString("F1");
tInLabel.Text = ProcessData.TempUp.ToString();
tOutLabel.Text = ProcessData.TempDown.ToString();
tDivLabel.Text = ProcessData.TempDiv.ToString();
prUpLabel.Text = ProcessData.PressUp.ToString();
prDownLabel.Text = ProcessData.PressDown.ToString();
massLabel.Text = ProcessData.Mass.ToString();
if (args.TestPhase == Progress.FlowSetting ||
args.TestPhase == Progress.Test)
{
///
/// Available when setting the flow and during a test
///
refFreqLabel.Text = ProcessData.RefFreq.ToString();
refFlowLabel.Text = Utils.DoubleToStr(ProcessData.RefFlow.Val, 4);
}
if (args.TestPhase == Progress.Test)
{
///
/// Available only during a test
///
refPulsesLabel.Text = ProcessData.RefPulses.ToString();
double refVolume = ProcessData.LtrPerRefPulse * (double)ProcessData.RefPulses;
refVolumeLabel.Text = refVolume.ToString("F2");
double massDiff = ProcessData.Mass.Val - ProcessData.StartMass.Val;
massDiffLabel.Text = massDiff.ToString("F3");
double volumeCtv = 1000 * Config.Formulas.Buoyancy() * massDiff / Config.Formulas.WaterDensityFromTempPress((ProcessData.TempUp.Val + ProcessData.TempDown.Val) / 2,
(ProcessData.PressUp.Val + ProcessData.PressDown.Val) / 2);
volumeCtvLabel.Text = volumeCtv.ToString("F2");
double refError = Config.Formulas.ErrorFromVolumes(refVolume, volumeCtv);
refErrorLabel.Text = refError.ToString("F3");
if (currentMetersKind == MetersKind.Single)
{
for (int i = 0; i < Math.Min(textBoxesCount, ProcessData.RegisterReaders.Length); i++)
{
Rig.GenericDevices.IRegReader rr = ProcessData.RegisterReaders[i];
if (rr != null)
{
pulses[i].Text = rr.WMPulses.ToString();
refPulses[i].Text = rr.WMRefPulses.ToString();
volume[i].Text = rr.WMVolume.ToString("F1");
error[i].Text = Config.Formulas.ErrorFromVolumes(rr.WMVolume, rr.WMRefPulses * ProcessData.LtrPerRefPulse).ToString("F1");
}
}
}
else if (currentMetersKind == MetersKind.Combined)
{
for (int compMtr = 0; compMtr < TBF.Data.CompoundWMsCount; compMtr++)
{
int end = Math.Min(2 * compMtr + 2, Math.Min(textBoxesCount, ProcessData.RegisterReaders.Length));
double compoundVolume = 0;
for (int i = 2 * compMtr; i < end; i++)
{
Rig.GenericDevices.IRegReader rr = ProcessData.RegisterReaders[i];
if (rr != null)
{
pulses[i].Text = rr.WMPulses.ToString();
refPulses[i].Text = rr.WMRefPulses.ToString();
volume[i].Text = rr.WMVolume.ToString("F1");
error[i].Text = Config.Formulas.ErrorFromVolumes(rr.WMVolume, rr.WMRefPulses * ProcessData.LtrPerRefPulse).ToString("F1");
compoundVolume += rr.WMVolume;
}
}
cmpndVolume[compMtr].Text = compoundVolume.ToString("F1");
cmpndError[compMtr].Text = Config.Formulas.ErrorFromVolumes(compoundVolume, refVolume).ToString("F1");
}
}
}
//if (pumpOn != args.PumpOn || diverterToTank != args.DivToTank)
//{
// //if (pumpOn != args.PumpOn)
// //{
// // if (pumpOn) pumpPictureBox.Image = System.Resources.
// // else pumpPictureBox.Image = System.Resources.
// //}
// pumpOn = args.PumpOn;
// diverterToTank = args.DivToTank;
// Invalidate();
//}
}
void OnTestCompleted(object sender, TestCompletedEventArgs args)
{
if (args == null) return;
TestRslt tRes = args.TestRslt;
if (tRes == null) return;
airTempLabel.Text = tRes.AmbTempMean.ToString("F1");
airPressLabel.Text = Common.Units.ConvertTo(Common.Unit.mbar, tRes.AmbPressMean).ToString("F0");
airHumiLabel.Text = tRes.AmbHumiMean.ToString("F1");
tInLabel.Text = tRes.TempUpMean.ToString("F2");
tOutLabel.Text = tRes.TempDownMean.ToString("F2");
tDivLabel.Text = tRes.TempDivMean.ToString("F2");
prUpLabel.Text = tRes.PressUpMean.ToString("F2");
prDownLabel.Text = tRes.PressDownMean.ToString("F2");
massLabel.Text = ProcessData.Mass.ToString();
massDiffLabel.Text = (tRes.MassEnd - tRes.MassStart).ToString("F3");
refPulsesLabel.Text = tRes.PulsesMaster.ToString("F0");
refFreqLabel.Text = "---";
refFlowLabel.Text = Utils.DoubleToStr(tRes.FlowVolume, 4);
refVolumeLabel.Text = tRes.VolumeCTV.ToString("F2");
//regValvePosLabel.Text = tstRslt.
volumeCtvLabel.Text = tRes.VolumeCTV.ToString("F1");
refErrorLabel.Text = (tRes.ErrorMaster == 0) ? "---" : tRes.ErrorMaster.ToString("F3");
if (!tRes.Batch.Compound)
{
for (int i = 0; i < Math.Min(textBoxesCount, ProcessData.BatchRslts.Batch.WaterMeters.Count); i++)
{
WaterMeter wm = ProcessData.BatchRslts.Batch.WaterMeters[i];
MeterTestRslt mtr = (wm != null) ? wm.GetMeterTestRslt(args.TestName) : null;
if (mtr != null)
{
pulses[i].Text = mtr.PulsesMeter.ToString("F0");
refPulses[i].Text = mtr.PulsesMaster.ToString("F0");
volume[i].Text = mtr.VolumeMeter.ToString("F2");
error[i].Text = mtr.Error.ToString("F2");
passed[i].Text = mtr.Passed ? Strings.Passed : Strings.Failed;
}
}
}
else
{
for (int compMtr = 0; compMtr < TBF.Data.CompoundWMsCount; compMtr++)
{
WaterMeter wm = ProcessData.BatchRslts.Batch.WaterMeters[compMtr];
if (wm == null && !wm.Disabled) continue;
int end = Math.Min(textBoxesCount, TBF.Data.WMsCount);
MeterTestRslt mtrMain = wm.GetMeterTestRslt(args.TestName, CompoundMeterId.CompoundMain);
if ((mtrMain != null) && (2 * compMtr < end))
{
pulses[2 * compMtr].Text = mtrMain.PulsesMeter.ToString("F0");
refPulses[2 * compMtr].Text = mtrMain.PulsesMaster.ToString("F0");
volume[2 * compMtr].Text = mtrMain.VolumeMeter.ToString("F2");
error[2 * compMtr].Text = mtrMain.Error.ToString("F2");
passed[2 * compMtr].Text = mtrMain.Passed ? Strings.Passed : Strings.Failed;
}
MeterTestRslt mtrAux = wm.GetMeterTestRslt(args.TestName, CompoundMeterId.CompoundAux);
if ((mtrAux != null) && (2 * compMtr + 1 < end))
{
pulses[2 * compMtr + 1].Text = mtrAux.PulsesMeter.ToString("F0");
refPulses[2 * compMtr + 1].Text = mtrAux.PulsesMaster.ToString("F0");
volume[2 * compMtr + 1].Text = mtrAux.VolumeMeter.ToString("F2");
error[2 * compMtr + 1].Text = mtrAux.Error.ToString("F2");
passed[2 * compMtr + 1].Text = mtrAux.Passed ? Strings.Passed : Strings.Failed;
}
MeterTestRslt mtrComp = wm.GetMeterTestRslt(args.TestName, CompoundMeterId.Compound);
if (mtrComp != null)
{
cmpndVolume[compMtr].Text = mtrComp.VolumeMeter.ToString("F2");
cmpndError[compMtr].Text = mtrComp.Error.ToString("F2");
cmpndPassed[compMtr].Text = mtrComp.Passed ? Strings.Passed : Strings.Failed;
}
}
}
}
void OnProcedureCompleted(object sender, ProcedureCompletedEventArgs args)
{
}
private void ProcessTabPageCtrl_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Graphics formGraphics = this.CreateGraphics();
System.Drawing.SolidBrush filledBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);
System.Drawing.SolidBrush emptyBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Gray);
System.Drawing.SolidBrush benchBrush = (pumpOn ? filledBrush : emptyBrush);
int diam = 14; // pipe diameter (pixels)
int left = 20; // left-most pipe x-coordinate
int top = 14; // top-most pipe y-coordinate
int topLeft = 876;
int topRight = 966;
int divTop = 40;
int bottom = 504; // bottom-most pipe y-coordinate
int benchTop = 378; // bench-pipe top y-coordinate
int pumpLeft = 779;
int pumpWdth = 38;
/// Pipes
formGraphics.FillRectangle(filledBrush,new Rectangle(pumpLeft+pumpWdth, bottom-diam, 65, diam)); // tank -> pump
formGraphics.FillRectangle(benchBrush, new Rectangle(left, bottom-diam, pumpLeft-left, diam)); // pump ->bench horizontal
formGraphics.FillRectangle(benchBrush, new Rectangle(left, benchTop, diam, bottom-benchTop)); // ->bench vertical
formGraphics.FillRectangle(benchBrush, new Rectangle(left + diam, benchTop, topLeft-left, diam)); // bench horizontal
formGraphics.FillRectangle(benchBrush, new Rectangle(topLeft, top + diam, diam, benchTop-top-diam)); // bench -> top vertical
formGraphics.FillRectangle(benchBrush, new Rectangle(topLeft, top, topRight-topLeft, diam)); // top horizontal
formGraphics.FillRectangle(benchBrush, new Rectangle(topRight-diam, top+diam, diam, divTop-top-diam)); // top -> diverter vertical
/// Combined meters bypasses
if (watermeterPictureBox1z.Visible) PaintBypass(formGraphics, benchBrush, 186, benchTop + diam);
if (watermeterPictureBox2z.Visible) PaintBypass(formGraphics, benchBrush, 470, benchTop + diam);
if (watermeterPictureBox3z.Visible) PaintBypass(formGraphics, benchBrush, 754, benchTop + diam);
/// Diverter
int displacement = diverterToTank ? 25 : -25;
Point[] points = new Point[4];
points[0].X = topRight - diam;
points[0].Y = divTop;
points[1].X = topRight;
points[1].Y = divTop;
points[2].X = topRight + displacement;
points[2].Y = divTop + 50;
points[3].X = topRight - diam + displacement;
points[3].Y = divTop + 50;
formGraphics.FillPolygon(benchBrush, points);
/// Sink
formGraphics.FillEllipse(emptyBrush, topRight - diam / 2 - 45, divTop + 50, 40, 30);
formGraphics.DrawEllipse(Pens.Black, topRight - diam / 2 - 45, divTop + 50, 40, 30);
/// Tank
formGraphics.DrawRectangle(Pens.Black, topRight - diam / 2, divTop + 51, 60, 80);
emptyBrush.Dispose();
filledBrush.Dispose();
formGraphics.Dispose();
}
private void PaintBypass(System.Drawing.Graphics formGraphics, System.Drawing.SolidBrush brush, int startX, int startY)
{
int w = 80;
int h = 43;
int diam = 10; // pipe diameter (pixels)
formGraphics.FillRectangle(brush, new Rectangle(startX, startY, diam, h - diam));
formGraphics.FillRectangle(brush, new Rectangle(startX, startY + h - diam, w, diam));
formGraphics.FillRectangle(brush, new Rectangle(startX + w - diam, startY, diam, h));
}
}
}