using System; using System.Collections.Generic; using System.Globalization; 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 DateTime DateTime; } public class PlcAlarmModel { public uint Id; public bool IsWarning; public bool RestorationIsActive; public List 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 bool AbrasiveIsActive; } public class AxisModel { public int Id; public string Name; } public class PreviewFileModel { public string Name; public string AbsolutePath; public bool IsDirectory; } public class InfoFile { public string Name; public DateTime CreationDate; public DateTime LastModDate; public List Content; public string PreviewBase64; } public class ActiveProgramDataModel { public string Path { get; set; } public List IsoLines { get; set; } public DateTime TimeLeft { get; set; } } #endregion Data structure models /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region Cms Errors Codes public class CmsError { public CMS_ERROR_CODES errorCode; public string localizationKey; public CmsError(CMS_ERROR_CODES errorCode, string message) { this.errorCode = errorCode; this.localizationKey = 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); } } 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, MAX_TOOL_REACHED = 12, MAX_EDGES_PER_TOOL_REACHED = 13, MAX_FAMILY_REACHED = 14, MAX_MULTITOOL_REACHED = 15, MAX_TOOLS_PER_MULTITOOL_REACHED = 16, MAX_MULTITOOL_LOCATION_REACHED = 17, MAG_POS_OCCUPIED = 18, MAGAZINE_OCCUPIED = 19, TOOL_IS_MOUNTED = 20, TOOL_AND_POSITION_NOT_MATCHING = 21 } public static CmsError NO_ERROR = new CmsError(CMS_ERROR_CODES.OK, ""); public static CmsError NOT_CONNECTED_ERROR = new CmsError(CMS_ERROR_CODES.NOT_CONNECTED, "error_not_connected"); public static CmsError PROC_NOT_FOUND_ERROR = new CmsError(CMS_ERROR_CODES.FUNCTION_NOT_ALLOWED, "error_process_not_found"); public static CmsError FUNCTION_NOT_ALLOWED_ERROR = new CmsError(CMS_ERROR_CODES.FUNCTION_NOT_ALLOWED, "error_function_not_allowed"); public static CmsError BIT_NOT_IN_RANGE_ERROR = new CmsError(CMS_ERROR_CODES.BIT_NOT_IN_RANGE, "error_bit_not_in_range"); public static CmsError BYTE_NOT_IN_RANGE_ERROR = new CmsError(CMS_ERROR_CODES.BYTE_NOT_IN_RANGE, "error_byte_not_in_range"); public static CmsError INCORRECT_PARAMETERS_ERROR = new CmsError(CMS_ERROR_CODES.INCORRECT_PARAMETERS, "error_incorrect_parameters"); public static CmsError INCORRECT_LANGUAGE_ERROR = new CmsError(CMS_ERROR_CODES.NC_LANGUAGE_ERROR, "error_invalid_language"); public static CmsError SIEMENS_ENVIRONMENT_NOT_FOUND_ERROR = new CmsError(CMS_ERROR_CODES.SIEMENS_ENVIRONMENT_NOT_FOUND, "error_siemens_enviroment_not_found_error"); public static CmsError SIEMENS_HMI_NOT_RUNNING_ERROR = new CmsError(CMS_ERROR_CODES.SIEMENS_HMI_NOT_RUNNING, "error_siemens_hmi_not_running"); public static CmsError MAX_TOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_TOOL_REACHED, "error_max_tool_reached"); public static CmsError MAX_EDGES_PER_TOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_EDGES_PER_TOOL_REACHED, "error_max_edges_per_tool_reached"); public static CmsError MAX_FAMILY_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_FAMILY_REACHED, "error_max_family_reached"); public static CmsError MAX_MULTITOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_MULTITOOL_REACHED, "error_max_multitools_reached"); public static CmsError MAX_TOOLS_PER_MULTITOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_TOOLS_PER_MULTITOOL_REACHED, "error_max_tools_per_multitool_reached"); public static CmsError MAX_MULTITOOL_LOCATION_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_MULTITOOL_LOCATION_REACHED, "error_max_multitools_location_reached"); public static CmsError MAGAZINE_POSITION_OCCUPIED_ERROR = new CmsError(CMS_ERROR_CODES.MAG_POS_OCCUPIED, "error_magazine_position_occupied"); public static CmsError MAGAZINE_BUSY_ERROR = new CmsError(CMS_ERROR_CODES.MAGAZINE_OCCUPIED, "error_magazine_occupied"); public static CmsError TOOL_IS_MOUNTED_ERROR = new CmsError(CMS_ERROR_CODES.TOOL_IS_MOUNTED, "error_tool_mounted"); public static CmsError TOOL_AND_POSITION_NOT_MATCHING_ERROR = new CmsError(CMS_ERROR_CODES.TOOL_IS_MOUNTED, "error_tool_and_position_not_matching"); #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 } /** Process-Status */ public enum PROC_STATUS : ushort { /** Idle-Status */ IDLE = 1, /** Run-Status */ RUN = 2, /** Hold-Status */ HOLD = 3, /** Error-Status */ ERROR = 4, /** Reset-Status */ RESET = 5, /** Emergency-Status */ EMERG = 6 }; /** CMS-Process-Mode */ public enum PROC_MODE : ushort { /** Automatic-Mode */ AUTO = 1, /** Edit-Mode */ EDIT = 2, /** Mdi-Mode */ MDI = 3, /** Remote-Mode */ REMOTE = 4, /** Teach-Mode */ TEACH = 5, /** Ref-Mode */ REF = 6, /** Jog-Mode */ JOG = 7, /** Joginc-Mode */ JOGINC = 8, /** Ret_on_Profile-Mode */ RETPROF = 9, /** Handle-Mode */ HANDLE = 10, /** Restart-Mode */ RESTART = 11, /** Error-Mode */ ERROR = 12 }; public static IFormatProvider numberFormat = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone(); #endregion Constants /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public enum MAGAZINE_ACTIONS { NONE = 0, LOADING = 1, UNLOADING = 2, TRANSFER = 4, GENERIC = 5 } public enum SIEMENS_MAGAZINE_TYPE { CHAIN = 1, REVOLVER = 3, BOX_MAGAZINE = 5, MAGAZINE_TOOL_BUFFER = 7, MAGAZINE_LOADING_STATION = 9 } public enum NC_MAGAZINE_TYPE { BOX_MAGAZINE = 0, DISK = 1, CHAIN = 2, } public enum POSITION_TYPE { MAGAZINE_LOCATION = 1, SPINDLE = 2, GRIPPER = 3, LOADER = 4, TRANSFER_LOCATION = 5, LOADING_STATION = 6, LOADING_POINT = 7 } public enum ROTATION { NONE = 0, CLOCKWHISE = 1, COUNTERCLOCKWHISE = 2 } #region Siemens Tool Manager Models public enum SIEMENS_LIFE_TYPE { NONE = 0, TIME = 1, COUNT = 2, WEAR = 4 } public class SiemensToolModel { public int Id; public string FamilyName; public int ChildId; public SIEMENS_LIFE_TYPE LifeType; 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 double MaxSpeed; public double MaxAcceleration; public int MagazineId; public int PositionId; public int MultitoolId; public List EdgesData; public SiemensToolModel() { EdgesData = new List(); } } public class EdgeModel { public int Id; public double ResidualLife; public double NominalLife; public double PreAlmLife; public Dictionary EdgeAdditionalParams; public EdgeModel() { EdgeAdditionalParams = new Dictionary(); } } 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 int MaxChilds; public int MagazineId; public int PositionId; public List ChildsTools; public ShankModel() { ChildsTools = new List(); } } public class ShankChildModel { public int Id; public int MultitoolId; public string FamilyName; public int ToolType; } public class FamilyModel { public string Name; public List ChildTools; public FamilyModel() { ChildTools = new List(); } } public class FamilyChildModel { public int Id; public int ChildId; public int ToolType; } public class PositionModel { public int PositionId; public int MagazineId; public POSITION_TYPE PhysicalType; public int Type; public bool Disabled; } public class EdgeConfigModel { public string Name; public string Path; public int Number; } public class MountedToolModel { public int PositionId; public int MagazineId; public int ToolId; public SiemensToolModel ChildTool; public ShankModel ChildShank; } public class NewToolInMagazineModel { public int PositionId; public int ToolId; } public class MagazineActionModel { public MAGAZINE_ACTIONS Action; public int OriginMagazine; public int OriginPosition; public int DestinationMagazine; public int DestinationPosition; public MagazineActionToolModel Tool; } public class MagazineActionToolModel { public int Id; public int ToolType; public string Name; public bool IsMultitool; } ///////////////// Tools Configuration public class FieldsConfiguration { public string Name; public string Type; public string Category; public bool ReadOnly; public Dictionary SelectValues; public uint MinValue; public uint MaxValue; } public class FamiliesConfiguration { public List FamilyConfiguration; public List ToolsConfiguration; } public class ShanksConfiguration { public List ShankConfiguration; public List ToolsConfiguration; } public class EdgesConfiguration { public List EdgeConfiguration; public Dictionary> EdgesAdditionalParamsConfiguration; } public class NcMagazineConfigModel { public byte Id; public NC_MAGAZINE_TYPE Type; public int MaxPositions; } public class SiemensMagazineConfigModel { public byte Id; public SIEMENS_MAGAZINE_TYPE Type; public int MaxPositions; public string Name; public bool LoadingIsActive; public int LoadPosition; } public class ToolTableConfiguration { public int MaxTools; public int MaxEdgesPerTools; public int MaxToolsPerFamily; public int MaxMultitools; public int MaxToolsPerMultitools; public bool MultitoolOptionActive; public bool FamilyOptionActive; public bool MagPositionOptionActive; public List Magazines; public List ToolsConfiguration; public FamiliesConfiguration FamiliesConfiguration; public ShanksConfiguration ShanksConfiguration; public List MagazinePosConfiguration; public EdgesConfiguration EdgesConfiguration; } #endregion Siemens Tool Manager Models #region Nc Tool Manager Models public class ToolManagerOptionsModel { public bool FamilyOpt { get; set; } public bool ShankOpt { get; set; } public bool MagPosTypeOpt { get; set; } public bool OffsetOpt { get; set; } public bool ReviveOpt { get; set; } public bool GammaOpt { get; set; } public bool LifeOpt { get; set; } public bool TcpOpt { get; set; } public bool CoolingOpt { get; set; } public bool MultidimensionalShankOpt { get; set; } public bool SelfAdaptivePathOpt { get; set; } public bool DynamicCompensationOpt { get; set; } public bool BallufOpt { get; set; } } public class OffsetModel { public short Id { get; set; } public double Length { get; set; } public double Radius { get; set; } public double WearLength { get; set; } public double WearRadius { get; set; } } public class NcShankModel { public int ShankId { get; set; } public int Balluf { get; set; } public byte MagazinePositionType { get; set; } public byte MagazineId { get; set; } public byte PositionId { get; set; } } public class NcToolModel { public int ToolId { get; set; } public int OffsetLength { get; set; } public int ResidualLife { get; set; } public int ResidualRevive { get; set; } public byte Status { get; set; } public int FamilyId { get; set; } public int ShankId { get; set; } public int OffsetId1 { get; set; } public int OffsetId2 { get; set; } public int OffsetId3 { get; set; } } public class NcFamilyModel { public int FamilyId { get; set; } public byte ToolType { get; set; } public byte TcpTable { get; set; } public byte Gamma { get; set; } public byte RotationType { get; set; } public byte CoolingByte { get; set; } public ushort MaxSpeed { get; set; } public byte MaxLoad { get; set; } public byte MinLoadPctAutoload { get; set; } public byte MaxLoadPctAutoload { get; set; } public ushort DynamicCompensation { get; set; } public byte MinLoadDynamicCompensation { get; set; } public byte MaxLoadDynamicCompensation { get; set; } public byte LifeType { get; set; } public int NominalLife { get; set; } public ushort ReviveDelta { get; set; } public byte RightSize { get; set; } public byte LeftSize { get; set; } } internal class NcFamilyFileModel { public int Id { get; set; } public byte ToolType { get; set; } public byte TcpTable { get; set; } public byte Gamma { get; set; } public byte RotationType { get; set; } public byte CoolingByte { get; set; } public ushort MaxSpeed { get; set; } public byte MaxLoad { get; set; } public byte MinLoadPctAutoload { get; set; } public byte MaxLoadPctAutoload { get; set; } public ushort DynamicCompensation { get; set; } public byte MinLoadDynamicCompensation { get; set; } public byte MaxLoadDynamicCompensation { get; set; } public byte LifeType { get; set; } public int NominalLife { get; set; } public ushort ReviveDelta { get; set; } public static explicit operator NcFamilyFileModel(NcFamilyModel obj) { return new NcFamilyFileModel() { Id = obj.FamilyId, ToolType = obj.ToolType, TcpTable = obj.TcpTable, Gamma = obj.Gamma, RotationType = obj.RotationType, CoolingByte = obj.CoolingByte, MaxSpeed = obj.MaxSpeed, MaxLoad = obj.MaxLoad, MinLoadDynamicCompensation = obj.MinLoadDynamicCompensation, MaxLoadDynamicCompensation = obj.MaxLoadDynamicCompensation, MaxLoadPctAutoload = obj.MaxLoadPctAutoload, MinLoadPctAutoload = obj.MinLoadPctAutoload, DynamicCompensation = obj.DynamicCompensation, LifeType = obj.LifeType, NominalLife = obj.NominalLife, ReviveDelta = obj.ReviveDelta }; } } internal class NcFamilySizeFileModel { public int Id { get; set; } public byte RightSize { get; set; } public byte LeftSize { get; set; } public static explicit operator NcFamilySizeFileModel(NcFamilyModel obj) { return new NcFamilySizeFileModel() { Id = obj.FamilyId, RightSize = obj.RightSize, LeftSize = obj.LeftSize }; } } public class NcMagazinePositionModel { public byte MagazineId { get; set; } public byte PositionId { get; set; } public byte Type { get; set; } public byte Disabled { get; set; } } #endregion Nc Tool Manager Models } }