Files
cms_thermo_active/Thermo.Active.Model/DTOModels/ThAxes/DTOAxisInfoModel.cs
T
2020-09-25 11:46:10 +02:00

138 lines
3.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Thermo.Active.Model.Constants;
namespace Thermo.Active.Model.DTOModels.ThAxes
{
public class DTOAxisInfoModel
{
/// <summary>
/// Actual position
/// </summary>
public int ID { get; set; } = 0;
/// <summary>
/// Actual position
/// </summary>
public string name { get; set; } = "";
/// <summary>
/// Type of axis
/// </summary>
public string type { get; set; } = "";
/// <summary>
/// Actual position
/// </summary>
public double position { get; set; } = 0;
/// <summary>
/// Actual Speed
/// </summary>
public double speed { get; set; } = 0;
/// <summary>
/// Actual Load
/// </summary>
public double load { get; set; } = 0;
/// <summary>
/// Error code (0=none)
/// </summary>
public int errorCode { get; set; } = 0;
/// <summary>
/// Movement
/// </summary>
public int movPhase { get; set; } = 0;
/// <summary>
/// Status Word
/// </summary>
public int statusCode { get; set; } = 0;
public override bool Equals(object obj)
{
// Object is not a GaugeModel instance
if (!(obj is DTOAxisInfoModel item))
return false;
if (ID != item.ID)
return false;
if (name != item.name)
return false;
if (Math.Round(Math.Abs(position - item.position), 1) >= Constants.EPSILON)
return false;
if (Math.Round(Math.Abs(speed - item.speed), 1) >= Constants.EPSILON)
return false;
if (Math.Round(Math.Abs(load - item.load), 1) >= Constants.EPSILON)
return false;
if (errorCode != item.errorCode)
return false;
if (movPhase != item.movPhase)
return false;
if (statusCode != item.statusCode)
return false;
return true;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
#if false
private bool CheckDictInt(IDictionary<string, int> x, IDictionary<string, int> y)
{
// early-exit checks
if (y == null)
return x == null;
if (x == null)
return false;
if (x.Count != y.Count)
return false;
// Check keys are the same
foreach (string k in x.Keys)
if (!y.ContainsKey(k))
return false;
// Check values are different
foreach (string k in x.Keys)
{
if (y[k] != x[k])
return false;
}
return true;
}
public bool CheckDictDouble(IDictionary<string, double> x, IDictionary<string, double> y)
{
// early-exit checks
if (y == null)
return x == null;
if (x == null)
return false;
if (x.Count != y.Count)
return false;
// Check keys are the same
foreach (string k in x.Keys)
if (!y.ContainsKey(k))
return false;
// Check values are different
foreach (string k in x.Keys)
{
double a = Math.Abs(y[k] - x[k]);
if (Math.Round(a, 3) >= Constants.EPSILON)
return false;
}
return true;
}
#endif
}
}