Files
cms-core-active/CMS_CORE_Library/DataStructures.cs
T
2018-05-04 15:32:01 +00:00

553 lines
17 KiB
C#

using System.Collections.Generic;
using static CMS_CORE.Nc;
namespace CMS_CORE_Library
{
public static class DataStructures
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Data structure models
#region Pre and Post Power on Models
public class PreAndPostPowerOnModel
{
public PrePowerOnModel PrePowerOn { get; set; }
public PostPowerOnModel PostPowerOn { get; set; }
public PreAndPostPowerOnModel()
{
PrePowerOn = new PrePowerOnModel();
PostPowerOn = new PostPowerOnModel();
}
public override bool Equals(object obj)
{
var item = obj as PreAndPostPowerOnModel;
if (item == null)
return false;
if (!PrePowerOn.Equals(item.PrePowerOn) || !PostPowerOn.Equals(item.PostPowerOn))
return false;
return true;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
public class PrePowerOnModel
{
public PowerOnDataModel PowerOn { get; set; }
public PowerOnDataModel AirPressure { get; set; }
public PowerOnDataModel ProtectionStatus { get; set; }
public PowerOnDataModel EmergencyButtons { get; set; }
public PowerOnDataModel SettingMode { get; set; }
public PowerOnDataModel StartingKey { get; set; }
public PrePowerOnModel()
{
PowerOn = new PowerOnDataModel();
AirPressure = new PowerOnDataModel();
ProtectionStatus = new PowerOnDataModel();
EmergencyButtons = new PowerOnDataModel();
SettingMode = new PowerOnDataModel();
StartingKey = new PowerOnDataModel();
}
public override bool Equals(object obj)
{
var item = obj as PrePowerOnModel;
if (item == null)
return false;
if (!PowerOn.Equals(item.PowerOn) ||
!AirPressure.Equals(item.AirPressure) ||
!ProtectionStatus.Equals(item.ProtectionStatus) ||
!EmergencyButtons.Equals(item.EmergencyButtons) ||
!SettingMode.Equals(item.SettingMode) ||
!StartingKey.Equals(item.StartingKey))
return false;
return true;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
public class PostPowerOnModel
{
public PowerOnDataModel AxisReset { get; set; }
public PowerOnDataModel WaterjetPump { get; set; }
public PostPowerOnModel()
{
AxisReset = new PowerOnDataModel();
WaterjetPump = new PowerOnDataModel();
}
public override bool Equals(object obj)
{
var item = obj as PostPowerOnModel;
if (item == null)
return false;
if (!AxisReset.Equals(item.AxisReset) ||
!WaterjetPump.Equals(item.WaterjetPump))
return false;
return true;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
public class PowerOnDataModel
{
public uint Id { get; set; }
public bool Active { get; set; }
public bool Clickable { get; set; }
public PowerOnDataModel()
{
Id = 0;
Active = false;
Clickable = false;
}
public override bool Equals(object obj)
{
var item = obj as PowerOnDataModel;
if (item == null)
return false;
if (Id != item.Id || Active != item.Active || Clickable != item.Clickable)
return false;
return true;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
#endregion Pre and Post Power on Models
// R-W MEMORY Cell
internal struct MEMORY_CELL
{
public readonly MEMORY_TYPE MemType;
public readonly int Address;
public readonly int SubAddress; //Only for Siemens
public readonly int Size;
public MEMORY_CELL(MEMORY_TYPE MType, int Addr, int SubAddr, int Sz)
{
MemType = MType;
Address = Addr;
SubAddress = SubAddr;
Size = Sz;
}
public MEMORY_CELL(MEMORY_TYPE MType, int Addr, int Sz)
{
MemType = MType;
Address = Addr;
SubAddress = 0;
Size = Sz;
}
}
public class AlarmModel
{
public uint Id;
public string Message;
public bool IsWarning;
public int Process;
}
public class PlcAlarmModel
{
public uint Id;
public bool IsWarning;
public bool RestorationIsActive;
public List<int> Process;
}
public class ProcessDataModel
{
public uint Id;
public string Type;
public bool IsInAlarm;
public string PartProgramName;
public string Status;
public bool Visible;
public ushort Reps;
public bool IsSelected;
}
public class FunctionalityModel
{
public uint Id;
public bool IsActive;
}
public struct StrobeModel
{
public uint Id;
public bool IsActive;
}
public class AxisResetDataModel
{
public bool IsActive;
public int Percentage;
public AxisResetDataModel()
{
IsActive = false;
Percentage = 0;
}
public override bool Equals(object obj)
{
var item = obj as AxisResetDataModel;
if (IsActive == item.IsActive && Percentage == item.Percentage)
return true;
else
return false;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
public struct CounterModel
{
public uint Id;
public uint Value;
}
public class SoftKeysModel
{
public uint Id;
public bool Active;
public bool Value;
}
public class HeadDataModel
{
public uint Id;
public byte Process;
public byte Override;
public ushort Load_Abrasive;
public int ActualSpeed_Pressure;
public short MountedTool_Vacum;
public bool IsActive;
public bool IsSelected;
public bool OverrideEditable;
}
public class AxisModel
{
public int Id;
public string Name;
}
#endregion Data structure models
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Cms Errors Codes
public enum CMS_ERROR_CODES : uint
{
OK = 0,
NC_PROD_ERROR = 1,
NOT_CONNECTED = 2,
PROC_NOT_FOUND = 3,
FUNCTION_NOT_ALLOWED = 4,
BIT_NOT_IN_RANGE = 5,
BYTE_NOT_IN_RANGE = 6,
INTERNAL_ERROR = 7,
INCORRECT_PARAMETERS = 8,
NC_LANGUAGE_ERROR = 9,
SIEMENS_ENVIRONMENT_NOT_FOUND = 10,
SIEMENS_HMI_NOT_RUNNING = 11
}
public class CmsError
{
public CMS_ERROR_CODES errorCode;
public string message;
public CmsError(CMS_ERROR_CODES errorCode, string message)
{
this.errorCode = errorCode;
this.message = message;
}
public bool IsError()
{
if (errorCode == CMS_ERROR_CODES.OK)
return false;
else
return true;
}
public static CmsError InternalError(string message)
{
return new CmsError(CMS_ERROR_CODES.INTERNAL_ERROR, message);
}
public static CmsError NcError(string message)
{
return new CmsError(CMS_ERROR_CODES.NC_PROD_ERROR, message);
}
}
internal static CmsError NO_ERROR = new CmsError(CMS_ERROR_CODES.OK, "");
internal static CmsError NOT_CONNECTED_ERROR = new CmsError(CMS_ERROR_CODES.NOT_CONNECTED, "CMS-Core-Error: Nc not Connected");
internal static CmsError PROC_NOT_FOUND_ERROR = new CmsError(CMS_ERROR_CODES.FUNCTION_NOT_ALLOWED, "CMS-Core-Error: Function not allowed for this type of NC");
internal static CmsError FUNCTION_NOT_ALLOWED_ERROR = new CmsError(CMS_ERROR_CODES.FUNCTION_NOT_ALLOWED, "CMS-Core-Error: Function not allowed for this type of NC");
internal static CmsError BIT_NOT_IN_RANGE_ERROR = new CmsError(CMS_ERROR_CODES.BIT_NOT_IN_RANGE, "CMS-Core-Error: Bit - number must be between 0 and 7");
internal static CmsError BYTE_NOT_IN_RANGE_ERROR = new CmsError(CMS_ERROR_CODES.BYTE_NOT_IN_RANGE, "CMS-Core-Error: Byte - number must be between 0 and 1");
internal static CmsError INCORRECT_PARAMETERS_ERROR = new CmsError(CMS_ERROR_CODES.INCORRECT_PARAMETERS, "CMS-Core-Error: Incorrect Parameters error");
internal static CmsError LANGUAGE_ERROR = new CmsError(CMS_ERROR_CODES.NC_LANGUAGE_ERROR, "CMS-Core-Error: Incorrect Language");
internal static CmsError SIEMENS_ENVIRONMENT_NOT_FOUND_ERROR = new CmsError(CMS_ERROR_CODES.SIEMENS_ENVIRONMENT_NOT_FOUND, "CMS-Core-Error: Siemens Environment not found");
internal static CmsError SIEMENS_HMI_NOT_RUNNING_ERROR = new CmsError(CMS_ERROR_CODES.SIEMENS_HMI_NOT_RUNNING, "CMS-Core-Error: Siemens HMI is not Running / Ready");
#endregion Cms Errors Codes
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Constants
public const int USER_SOFTKEYS_NUMBER = 128;
public const int NC_SOFTKEYS_NUMBER = 32;
public const int PROCESS_NUMBER = 6;
public const int ALARMS_NUMBER = 1024;
public const int HEADS_NUMBER = 20;
public enum HEAD_OVERRIDE_SIGN
{
PLUS = 0,
MINUS = 1
}
/** <summary>Process-Status</summary> */
public enum PROC_STATUS : ushort
{
/** <summary>Idle-Status</summary> */
IDLE = 1,
/** <summary>Run-Status</summary> */
RUN = 2,
/** <summary>Hold-Status</summary> */
HOLD = 3,
/** <summary>Error-Status</summary> */
ERROR = 4,
/** <summary>Reset-Status</summary> */
RESET = 5,
/** <summary>Emergency-Status</summary> */
EMERG = 6
};
/** <summary>CMS-Process-Mode</summary> */
public enum PROC_MODE : ushort
{
/** <summary>Automatic-Mode</summary> */
AUTO = 1,
/** <summary>Edit-Mode</summary> */
EDIT = 2,
/** <summary>Mdi-Mode</summary> */
MDI = 3,
/** <summary>Remote-Mode</summary> */
REMOTE = 4,
/** <summary>Teach-Mode</summary> */
TEACH = 5,
/** <summary>Ref-Mode</summary> */
REF = 6,
/** <summary>Jog-Mode</summary> */
JOG = 7,
/** <summary>Joginc-Mode</summary> */
JOGINC = 8,
/** <summary>Ret_on_Profile-Mode</summary> */
RETPROF = 9,
/** <summary>Handle-Mode</summary> */
HANDLE = 10,
/** <summary>Restart-Mode</summary> */
RESTART = 11,
/** <summary>Error-Mode</summary> */
ERROR = 12
};
#endregion Constants
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region ToolsConfig
public enum ROTATION
{
NONE = 0,
CLOCKWHISE = 1,
COUNTERCLOCKWHISE = 2
}
public enum MAGAZINE_TYPE
{
MAGAZINE = 0,
SPINDLE = 1,
MAGAZINE_GROUND = 2
}
public class FieldsConfiguration
{
public string Name;
public string Type;
public string Category;
public bool ReadOnly;
public Dictionary<int, string> SelectValues;
}
public class FamiliesConfiguration
{
public List<FieldsConfiguration> FamilyConfiguration;
public List<FieldsConfiguration> ToolsConfiguration;
}
public class ShanksConfiguration
{
public List<FieldsConfiguration> ShankConfiguration;
public List<FieldsConfiguration> ToolsConfiguration;
}
public class EdgesConfiguration
{
public List<FieldsConfiguration> EdgeConfiguration;
public Dictionary<int, List<string>> EdgesAdditionalParamsConfiguration;
}
public class MagazineModel
{
public int Id;
public MAGAZINE_TYPE Type;
}
public class ToolTableConfiguration
{
public List<MagazineModel> Magazines;
public List<FieldsConfiguration> ToolsConfiguration;
public FamiliesConfiguration FamiliesConfiguration;
public ShanksConfiguration ShanksConfiguration;
public List<FieldsConfiguration> MagazinePosConfiguration;
public EdgesConfiguration EdgesConfiguration;
}
public class SiemensToolModel
{
public int Id;
public string FamilyName;
public int ChildId;
public int MagazinePositionType;
public int ToolType;
public int LeftSize;
public int RightSize;
public ROTATION Rotation;
public bool Cooling1;
public bool Cooling2;
public bool IsEnabled;
public bool IsActive;
public bool InFixedPlace;
public bool IsInhibited;
public bool IsMeasured;
public bool InChangeTool;
public bool IsInUse;
public bool PreAlarm;
public List<EdgeModel> EdgesData;
}
public class EdgeModel
{
public int Id;
public double ResidualLife;
public double NominalLife;
public double PreAlmLife;
public Dictionary<string, double> EdgeAdditionalParams;
}
public class ShankModel
{
public int Id;
public string Name;
public bool IsEnabled;
public bool IsInhibited;
public bool InChangeTool;
public bool InFixedPlace;
public bool InUse;
public int LeftSize;
public int RightSize;
public int MagazinePositionType;
public List<ShankChildModel> ChildsTools;
}
public class ShankChildModel
{
public int Id;
public int MultitoolId;
public string FamilyName;
public int ToolType;
}
public class FamilyModel
{
public int Id;
public string Name;
public List<FamilyChildModel> ChildTools;
}
public class FamilyChildModel
{
public int Id;
public int ChildId;
public int ToolType;
}
public class MagazinePositionsModel
{
public int Id;
public int MagazineId;
public int Type;
}
public class EdgeConfigModel
{
public string Name;
public string Path;
}
#endregion ToolsConfig
}
}