126 lines
4.0 KiB
C#
126 lines
4.0 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using static Step.Model.Constants;
|
|
|
|
namespace Step.Utils
|
|
{
|
|
public static class SupportFunctions
|
|
{
|
|
public static SOFTKEY_TYPE GetSoftKeyType(string type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case "softKey_procedure": return SOFTKEY_TYPE.PROCEDURE;
|
|
case "softKey_group": return SOFTKEY_TYPE.GROUP;
|
|
default: return SOFTKEY_TYPE.TOGGLE;
|
|
}
|
|
}
|
|
|
|
public static HEAD_TYPE GetHeadType(string type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case "SPINDLE": return HEAD_TYPE.SPINDLE;
|
|
case "AWJ": return HEAD_TYPE.AWJ;
|
|
default: return HEAD_TYPE.WJ;
|
|
}
|
|
}
|
|
|
|
public static int GetPlcIdFromNcSoftKey(string softKey)
|
|
{
|
|
switch (softKey)
|
|
{
|
|
case "auto": return 1;
|
|
case "edit": return 2;
|
|
case "mdi": return 3;
|
|
case "dnc": return 4;
|
|
case "ref": return 5;
|
|
case "jog": return 6;
|
|
case "jogInc": return 7;
|
|
case "restart": return 8;
|
|
case "teach": return 9;
|
|
case "retract": return 10;
|
|
case "wcsMcs": return 11;
|
|
case "handle": return 12;
|
|
case "reset": return 13;
|
|
case "blk": return 14;
|
|
case "blkDel": return 15;
|
|
case "opStop": return 16;
|
|
case "dryRun": return 17;
|
|
case "prgTest": return 18;
|
|
case "manualHandleInterrupt": return 19;
|
|
case "teachIn": return 20;
|
|
case "incPlane": return 21;
|
|
case "plus": return 22;
|
|
case "minus": return 23;
|
|
case "rapid": return 24;
|
|
case "xOne": return 25;
|
|
case "xTen": return 26;
|
|
case "xHundred": return 27;
|
|
case "xThousand": return 28;
|
|
default: return -1;
|
|
}
|
|
}
|
|
|
|
public static double ConvertInMinutes(double number, MAINTENANCE_UNIT_OF_MEASURE unit)
|
|
{
|
|
switch (unit)
|
|
{
|
|
case MAINTENANCE_UNIT_OF_MEASURE.mm:
|
|
return number;
|
|
|
|
case MAINTENANCE_UNIT_OF_MEASURE.H:
|
|
return number * 60;
|
|
|
|
case MAINTENANCE_UNIT_OF_MEASURE.D:
|
|
return number * (24 * 60);
|
|
|
|
case MAINTENANCE_UNIT_OF_MEASURE.M:
|
|
return (30 * number) * (24 * 60);
|
|
|
|
default:
|
|
return number;
|
|
}
|
|
}
|
|
|
|
public static void CopyProperties<TParent, TChild>(TParent parent, TChild child) where TParent : class where TChild : class
|
|
{
|
|
var parentProperties = parent.GetType().GetProperties();
|
|
var childProperties = child.GetType().GetProperties();
|
|
|
|
foreach (var parentProperty in parentProperties)
|
|
{
|
|
foreach (var childProperty in childProperties)
|
|
{
|
|
if (parentProperty.Name == childProperty.Name && parentProperty.PropertyType == childProperty.PropertyType)
|
|
{
|
|
childProperty.SetValue(child, parentProperty.GetValue(parent));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static int GetNextId(IEnumerable<int> objIds)
|
|
{
|
|
if (objIds.Count() == 0)
|
|
return 1;
|
|
|
|
return objIds.Max() + 1;
|
|
}
|
|
|
|
public static int GetFirstId(IEnumerable<int> objIds)
|
|
{
|
|
List<int> listOfPossibleIds = Enumerable.Range(1, objIds.Max()).ToList();
|
|
|
|
IEnumerable<int> res = listOfPossibleIds.Except(objIds).ToList();
|
|
|
|
if (res.Count() > 0)
|
|
return res.First();
|
|
else
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
} |