diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index 94d6bcfd..f833b462 100644 Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ diff --git a/Step.Config/Config/serverConfig.xml b/Step.Config/Config/serverConfig.xml index 1f8b8d8a..ec1bcc1e 100644 --- a/Step.Config/Config/serverConfig.xml +++ b/Step.Config/Config/serverConfig.xml @@ -3,7 +3,7 @@ DEMO true - 127.0.0.1 + localhost 8080 Ares 37 OF diff --git a/Step.Config/Config/toolManagerConfig.xml b/Step.Config/Config/toolManagerConfig.xml new file mode 100644 index 00000000..76097b1b --- /dev/null +++ b/Step.Config/Config/toolManagerConfig.xml @@ -0,0 +1,15 @@ + + + true + false + true + true + true + true + true + true + true + true + true + true + \ No newline at end of file diff --git a/Step.Config/Config/toolManagerConfigValidator.xsd b/Step.Config/Config/toolManagerConfigValidator.xsd new file mode 100644 index 00000000..eca1defd --- /dev/null +++ b/Step.Config/Config/toolManagerConfigValidator.xsd @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Step.Config/ServerConfig.cs b/Step.Config/ServerConfig.cs index 866f3fd4..59c1cc79 100644 --- a/Step.Config/ServerConfig.cs +++ b/Step.Config/ServerConfig.cs @@ -23,6 +23,7 @@ namespace Step.Config public static List NcSoftKeysConfig; public static List InitialAlarmsConfig; public static List HeadsConfig; + public static ToolManagerConfigModel ToolManagerConfig; public static AreasConfigModel ProductionConfig; public static AreasConfigModel ToolingConfig; diff --git a/Step.Config/ServerConfigController.cs b/Step.Config/ServerConfigController.cs index 942a6cd9..04c4994a 100644 --- a/Step.Config/ServerConfigController.cs +++ b/Step.Config/ServerConfigController.cs @@ -24,6 +24,7 @@ namespace Step.Config ReadUserSoftKeysConfig(); ReadAlarmsConfig(); ReadHeadsConfig(); + ReadToolManagerConfig(); } catch (System.Xml.XmlException ex) { @@ -308,6 +309,31 @@ namespace Step.Config .ToList(); } + private static void ReadToolManagerConfig() + { + XDocument xmlConfigFile = GetXmlHandlerWithValidator(TOOL_MANAGER_CONFIG_SCHEMA_PATH, TOOL_MANAGER_CONFIG_PATH); + + // Read config from XML file + ToolManagerConfig = xmlConfigFile + .Elements() + .Select(x => new ToolManagerConfigModel() + { + FamilyOptIsActive = Convert.ToBoolean(x.Element("familyOptIsActive").Value), + ShankOptIsActive = Convert.ToBoolean(x.Element("shankOptIsActive").Value), + MagPositionIsActive = Convert.ToBoolean(x.Element("magPositionOptIsActive").Value), + OffsetOptIsActive = Convert.ToBoolean(x.Element("offsetOptIsActive").Value), + ReviveOptIsActive = Convert.ToBoolean(x.Element("reviveOptIsActive").Value), + GammaOptIsActive = Convert.ToBoolean(x.Element("gammaOptIsActive").Value), + LifeOptIsActive = Convert.ToBoolean(x.Element("lifeOptIsActive").Value), + TcpOptIsActive = Convert.ToBoolean(x.Element("tcpOptIsActive").Value), + CoolingOptIsActive = Convert.ToBoolean(x.Element("coolingOptIsActive").Value), + MultidimensionalShankOptIsActive = Convert.ToBoolean(x.Element("multidimensionalShankOptIsActive").Value), + SelfAdaptivePathOptIsActive = Convert.ToBoolean(x.Element("selfAdaptivePathOptIsActive").Value), + DynamicCompensationOptIsActive = Convert.ToBoolean(x.Element("dynamicCompensationOptIsActive").Value), + }) + .FirstOrDefault(); + } + #endregion Read config from file from configuration } } \ No newline at end of file diff --git a/Step.Config/Step.Config.csproj b/Step.Config/Step.Config.csproj index 4c735507..f3fe896a 100644 --- a/Step.Config/Step.Config.csproj +++ b/Step.Config/Step.Config.csproj @@ -47,6 +47,9 @@ + + PreserveNewest + PreserveNewest Designer @@ -93,6 +96,10 @@ Designer Always + + Designer + Always + diff --git a/Step.Core/ThreadsFunctions.cs b/Step.Core/ThreadsFunctions.cs index 9e89e03c..2d9b1a75 100644 --- a/Step.Core/ThreadsFunctions.cs +++ b/Step.Core/ThreadsFunctions.cs @@ -22,6 +22,7 @@ public static class ThreadsFunctions private static long ReadUserSoftKeysTimer = 0, ReadUserSoftKeysTimes = 0; private static long ReadAxesNamesTimer = 0, ReadAxesNamesTimes = 0; private static long ReadHeadsTimer = 0, ReadHeadsTimes = 0; + private static long ReadToolDataTimer = 0, ReadToolDataTimes = 0; private static Thread ConnThread; @@ -505,6 +506,7 @@ public static class ThreadsFunctions { // Get Data from config and PLC libraryError = ncHandler.GetActiveProgramInfo(out DTOActiveProgramDataModel active); + if (libraryError.errorCode != 0) ManageLibraryError(libraryError); else @@ -530,7 +532,53 @@ public static class ThreadsFunctions } } - #endregion Nc threads + public static void UpdateToolsData() + { + NcHandler ncHandler = new NcHandler(); + Stopwatch sw = new Stopwatch(); + + try + { + // Try connection + CmsError libraryError = ncHandler.Connect(); + if (libraryError.errorCode != 0) + ManageLibraryError(libraryError); + + while (true) + { + sw.Restart(); + + // Check if client is connected + if (ncHandler.numericalControl.NC_IsConnected()) + { + // Get new data from PLC + libraryError = ncHandler.GetUpdatedToolsData(out Dictionary updatedStatus, out Dictionary updatedLives); + MessageServices.Current.Publish(UPDATE_TOOLS_DATA, null, + new DTONewToolDataModel + { + UpdatedStatus = updatedStatus, + UpdatedLives = updatedLives + }); + } + else + TryNcConnection(); + sw.Stop(); + + //Update thread timer + ReadToolDataTimer += sw.ElapsedMilliseconds; + ReadToolDataTimes++; + + // Wait + Thread.Sleep(CalcSleepTime(1000, (int)sw.ElapsedMilliseconds)); + } + } + catch (ThreadAbortException) + { + ncHandler.Dispose(); + } + } + + #endregion Nc functions threads #region SupportFunctions @@ -689,6 +737,12 @@ public static class ThreadsFunctions ReadAxesNamesTimer = 0; ReadAxesNamesTimes = 0; } + if (ThreadsHandler.RunningThreadStatus.ContainsKey("UpdateToolsData") && ReadAxesNamesTimer != 0) + { + ThreadsHandler.RunningThreadStatus["UpdateToolsData"] = (ReadToolDataTimer / ReadToolDataTimes) + " mS"; + ReadToolDataTimer = 0; + ReadToolDataTimes = 0; + } MessageServices.Current.Publish(SEND_THREADS_STATUS, null, ThreadsHandler.RunningThreadStatus); diff --git a/Step.Core/ThreadsHandler.cs b/Step.Core/ThreadsHandler.cs index 44b8afdc..b27d424d 100644 --- a/Step.Core/ThreadsHandler.cs +++ b/Step.Core/ThreadsHandler.cs @@ -21,8 +21,8 @@ namespace Step.Core ThreadsFunctions.ReadUserSoftKeysData, ThreadsFunctions.ReadHeadsData, ThreadsFunctions.ReadAxesNamesData, - ThreadsFunctions.ReadActiveProgramData - + ThreadsFunctions.ReadActiveProgramData, + ThreadsFunctions.UpdateToolsData // ThreadsFunctions.ReadNcSoftKeysData, }; diff --git a/Step.Database/Controllers/NcToolManagerController.cs b/Step.Database/Controllers/NcToolManagerController.cs new file mode 100644 index 00000000..e5699f68 --- /dev/null +++ b/Step.Database/Controllers/NcToolManagerController.cs @@ -0,0 +1,445 @@ +using Step.Model.DatabaseModels; +using Step.Model.DTOModels.ToolModels; +using Step.Utils; +using System; +using System.Collections.Generic; +using System.Data.Entity; +using System.Linq; + +namespace Step.Database.Controllers +{ + public class NcToolManagerController : IDisposable + { + public DatabaseContext dbCtx; + + public NcToolManagerController() + { + // Initialize database context + dbCtx = new DatabaseContext(); + } + + public void Dispose() + { + // Clear database context + dbCtx.Dispose(); + } + + public List FindFamilies() + { + List families = dbCtx + .Families + .Include("Tools") + .ToList(); + + return families; + } + + public List GetFamilies() + { + List dbFamilies = FindFamilies(); + + return dbFamilies + .Select(x => (DTONcFamilyModel)x) + .ToList(); + } + + public List FindFamiliesByShankId(int shankId) + { + DbNcShankModel shank = FindShankWithTools(shankId); + // Get only families id + int[] ids = shank.Tools.Select(x => x.FamilyId).ToArray(); + + return FindFamilies() // Get Families + .Where(x => ids.Contains(x.FamilyId)) // Filter by ids + .ToList(); + } + + public DbNcToolModel FindTool(int toolId) + { + return dbCtx.Tools + .Where(x => x.ToolId == toolId) + .FirstOrDefault(); + } + + public DbNcShankModel FindShankWithTools(int shankId) + { + return dbCtx.Shanks + .Include("Tools") + .Where(x => x.ShankId == shankId) + .FirstOrDefault(); + } + + public DbNcFamilyModel FindFamily(int familyId) + { + return dbCtx + .Families + .Where(x => x.FamilyId == familyId) + .FirstOrDefault(); + } + + public List FindToolsWithDependencies() + { + List tools = dbCtx + .Tools + .Include("Family") + .Include("Shank") + .ToList(); + + return tools; + } + + public List FindToolsByShankIdWithDependencies(int shankId) + { + List tools = FindToolsWithDependencies() + .Where(x => x.ShankId == shankId) + .ToList(); + + return tools; + } + + public List FindTools() + { + List tools = dbCtx + .Tools + .ToList(); + + return tools; + } + + public List GetTools() + { + List dbTools = FindToolsWithDependencies(); + + return dbTools + .Select(x => (DTONcToolModel)x) + .ToList(); + } + + public List FindShanks() + { + List shanks = dbCtx + .Shanks + .Include("MagazinePosition") + .ToList(); + + return shanks; + } + + public DbNcShankModel FindShanksByPositions(int magazineId, int positionId) + { + DbNcShankModel shank = FindShanks() + .Where(x => x.MagazineId == magazineId && x.PositionId == positionId) + .FirstOrDefault(); + + return shank; + } + + public List GetShanks() + { + // Get shank from database + List dbShanks = dbCtx + .Shanks + .Include("Tools") + .ToList(); + + // Populate db shanks + List dtoShanks = dbShanks + .Select(x => (DTONcShankModel)x) + .ToList(); + // new List(); + //foreach (var shank in dbShanks) + //{ + // //dbCtx.Shanks.Attach(shank); + // DTONcShankModel dtoShank = (DTONcShankModel)shank; + + // dtoShanks.Add(dtoShank); + //} + + return dtoShanks; + } + + public DTONcShankModel GetShank(int shankId) + { + // Get shank from database + DbNcShankModel dbShank = dbCtx + .Shanks + .Where(x => x.ShankId == shankId) + .Include("Tools") + .FirstOrDefault(); + + // Convert into DTOModel + DTONcShankModel dtoShanks = (DTONcShankModel)dbShank; + + return dtoShanks; + } + + public List FindMagazinesPositions() + { + List positions = dbCtx + .MagazinePositions + .ToList(); + + return positions; + } + + public List FindMagazinePositions(byte magId) + { + return dbCtx + .MagazinePositions + .Where(x => x.MagazineId == magId) + .ToList(); + } + + + public List GetMagazinePositions(byte magId) + { + // Get only magazine positions that match with magazineId + List magPos = FindMagazinePositions(magId).Select(x => (DTONcMagazinePositionModel)x).ToList(); + // Get&filter shanks by magazineId in order to get only mounted shanks in the current magazineId + List shanks = dbCtx.Shanks.Where(x => x.MagazineId == magId).ToList(); + + foreach(DbNcShankModel shank in shanks) + { + // Populate magazinePosition shank Id + magPos + .Where(x => x.PositionId == shank.PositionId) + .FirstOrDefault() + .ShankId = shank.ShankId; + } + // Convert in DTOModel and return + return magPos; + } + + public DbNcMagazinePositionModel FindMagazinePosition(byte magId, byte posId) + { + DbNcMagazinePositionModel positions = dbCtx + .MagazinePositions + .Where(x => x.MagazineId == magId && x.PositionId == posId) + .FirstOrDefault(); + + return positions; + } + + public List GetMountedShanks(int magazineId) + { + List dtoShanks = GetShanks() + .Where(x => x.MagazineId != null) + .ToList(); + + return dtoShanks; + } + + public List GetMountedTools() + { + List tools = FindToolsWithDependencies() + .Where(x => x.Shank.MagazineId != null) + .ToList(); + + return tools; + } + + public List GetAvailableShanks() + { + List dtoShanks = GetShanks() + .Where(x => x.MagazineId == null && x.Tools.Count > 0) + .ToList(); + + return dtoShanks; + } + + public DbNcToolModel AddTool(DTONewNcToolModel dtoTool) + { + DbNcToolModel tool = (DbNcToolModel)dtoTool; + dbCtx.Tools.Add(tool); + + dbCtx.SaveChanges(); + // Get foreign key data + dbCtx.Entry(tool).Reference(x => x.Family).Load(); + dbCtx.Entry(tool).Reference(x => x.Shank).Load(); + + return tool; + } + + public DbNcToolModel UpdateTool(int toolId, DTONewNcToolModel dtoTool) + { + DbNcToolModel tool = FindTool(toolId); + + tool.Status = ((DbNcToolModel)dtoTool).Status; + var shankId = tool.ShankId; + + // Update db model + SupportFunctions.CopyProperties(dtoTool, tool); + tool.ShankId = shankId; + + // Save + dbCtx.SaveChanges(); + + return tool; + } + + public void DeleteTool(int toolId) + { + DbNcToolModel tool = FindTool(toolId); + DeleteTool(tool); + } + + public void DeleteTool(DbNcToolModel tool) + { + dbCtx.Tools.Remove(tool); + + dbCtx.SaveChanges(); + } + + public DbNcFamilyModel AddFamily(DTONewNcFamilyModel family) + { + DbNcFamilyModel dbFamily = (DbNcFamilyModel)family; + dbCtx.Families.Add(dbFamily); + + dbCtx.SaveChanges(); + + return dbFamily; + } + + public DbNcFamilyModel UpdateFamily(int familyId, DTONewNcFamilyModel family) + { + DbNcFamilyModel dbFamily = FindFamily(familyId); + // Copy data from NewModel to DbModel + SupportFunctions.CopyProperties(family, dbFamily); + // Set cooling byte + dbFamily.CoolingByte = ((DbNcFamilyModel)family).CoolingByte; + + dbCtx.SaveChanges(); + // Connect tools data + dbCtx.Entry(dbFamily).Collection(x => x.Tools).Load(); + + return dbFamily; + } + + public void DeleteFamily(DbNcFamilyModel family) + { + dbCtx.Families.Attach(family); + dbCtx.Families.Remove(family); + + dbCtx.SaveChanges(); + } + + public DbNcShankModel AddShank(DTONewNcShankModel shank) + { + DbNcShankModel dbShank = (DbNcShankModel)shank; + dbCtx.Shanks.Add(dbShank); + + dbCtx.SaveChanges(); + + + return dbShank; + } + + public DbNcShankModel UpdateShank(int shankId, DTONewNcShankModel dtoShank) + { + DbNcShankModel ncShank = FindShankWithTools(shankId); + + return UpdateShank(ncShank, dtoShank); + } + + public DbNcShankModel UpdateShank(DbNcShankModel dbShank, DTONewNcShankModel dtoShank) + { + dbShank.MagazinePositionType = dtoShank.MagazinePositionType; + + dbCtx.SaveChanges(); + + dbCtx.Entry(dbShank).Collection(x => x.Tools).Load(); + + return dbShank; + } + + public DbNcShankModel DeleteShank(int shankId) + { + DbNcShankModel shank = FindShankWithTools(shankId); + DeleteShank(shank); + + return shank; + } + + public void DeleteShank(DbNcShankModel shank) + { + dbCtx.Shanks.Remove(shank); + + dbCtx.SaveChanges(); + } + + public DbNcMagazinePositionModel UpdatePosition(DbNcMagazinePositionModel dbPos, DTONcMagazinePositionModel dtoPos) + { + dbCtx.MagazinePositions.Attach(dbPos); + dbPos.Type = dtoPos.Type; + dbPos.Disabled = dtoPos.Disabled; + + dbCtx.SaveChanges(); + + return dbPos; + } + + public DbNcMagazinePositionModel LoadShankInMagazine(byte magazineId, byte positionId, DbNcShankModel shank) + { + dbCtx.Shanks.Attach(shank); + // Set ids with new positions + shank.MagazineId = magazineId; + shank.PositionId = positionId; + + dbCtx.SaveChanges(); + + return FindMagazinePosition(magazineId, positionId); + } + + public DbNcMagazinePositionModel UnloadShankInMagazine(byte magazineId, byte positionId, DbNcShankModel shank) + { + dbCtx.Shanks.Attach(shank); + // set id to null + shank.MagazineId = null; + shank.PositionId = null; + + dbCtx.SaveChanges(); + + return FindMagazinePosition(magazineId, positionId); + } + + public DTONcShankModel LoadToolIntoShank(DbNcToolModel tool, int shankId) + { + dbCtx.Tools.Attach(tool); + // Set tool shankId + tool.ShankId = shankId; + + dbCtx.SaveChanges(); + + return GetShank(shankId); + } + + public DTONcShankModel UnloadToolFromShank(DbNcToolModel tool) + { + dbCtx.Tools.Attach(tool); + int? shankId = tool.ShankId; + // Set to null shankId + tool.ShankId = null; + + dbCtx.SaveChanges(); + + return GetShank(shankId.Value); + } + + public void SetupMagazinePositions(List config) + { + dbCtx.MagazinePositions.AddRange(config); + dbCtx.SaveChanges(); + } + + public void UpdateToolsData(List tools) + { + foreach (var tool in tools) + { + DbNcToolModel tmpTool = dbCtx.Tools.Where(x => x.ToolId == tool.ToolId).FirstOrDefault(); + tmpTool = tool; + } + + dbCtx.SaveChanges(); + } + } +} \ No newline at end of file diff --git a/Step.Database/DatabaseContext.cs b/Step.Database/DatabaseContext.cs index 0d393933..1f45c133 100644 --- a/Step.Database/DatabaseContext.cs +++ b/Step.Database/DatabaseContext.cs @@ -30,8 +30,14 @@ namespace Step.Database public DbSet MaintenanceFiles { get; set; } public DbSet FavoriteUserSoftkeys { get; set; } + public DbSet Families { get; set; } + public DbSet Shanks { get; set; } + public DbSet Tools { get; set; } + public DbSet MagazinePositions { get; set; } + // Create migration string - public static string CONNECTION_STRING = "Server = " + "localhost" + "; Database=" + DATABASE_NAME +";Uid="+ DATABASE_USER +";Pwd="+ DATABASE_PWD +";"; + public static string CONNECTION_STRING = "Server = " + "localhost" + "; Database=" + DATABASE_NAME + ";Uid=" + DATABASE_USER + ";Pwd=" + DATABASE_PWD + ";"; + // public static string CONNECTION_STRING = "Server = " + ServerStartupConfig.DatabaseAddress + "; Database=" + DATABASE_NAME +";Uid="+ DATABASE_USER +";Pwd="+ DATABASE_PWD +";"; public DatabaseContext() @@ -77,25 +83,19 @@ namespace Step.Database AllFunctionalityDisabled = functionsAccess.FindAllFunctionsAndDisableAll(); } } - catch (MySql.Data.MySqlClient.MySqlException ex) - { - if (ex.Number == 0) - { - //dbContext.Database.Initialize(true); - } - else if (ex.Number == 1042) // Can't find MySQLServer - { - Manage(ERROR_LEVEL.FATAL, ex); - } - else - { - Manage(ERROR_LEVEL.ERROR, ex); - } - } catch (Exception ex) { Manage(ERROR_LEVEL.FATAL, ex); } + + + //catch (MySql.Data.MySqlClient.MySqlException ex) + //{ + // if (ex.Number == 1042) // Can't find MySQLServer + // Manage(ERROR_LEVEL.FATAL, ex); + // else + // Manage(ERROR_LEVEL.ERROR, ex); + //} } public static void FindOrCreateMachineUniqueId() diff --git a/Step.Database/Migrations/201807251330036_InitMigration.Designer.cs b/Step.Database/Migrations/201807251330036_InitMigration.Designer.cs new file mode 100644 index 00000000..da3aab8b --- /dev/null +++ b/Step.Database/Migrations/201807251330036_InitMigration.Designer.cs @@ -0,0 +1,29 @@ +// +namespace Step.Database.Migrations +{ + using System.CodeDom.Compiler; + using System.Data.Entity.Migrations; + using System.Data.Entity.Migrations.Infrastructure; + using System.Resources; + + [GeneratedCode("EntityFramework.Migrations", "6.2.0-61023")] + public sealed partial class InitMigration : IMigrationMetadata + { + private readonly ResourceManager Resources = new ResourceManager(typeof(InitMigration)); + + string IMigrationMetadata.Id + { + get { return "201807251330036_InitMigration"; } + } + + string IMigrationMetadata.Source + { + get { return null; } + } + + string IMigrationMetadata.Target + { + get { return Resources.GetString("Target"); } + } + } +} diff --git a/Step.Database/Migrations/201807251330036_InitMigration.cs b/Step.Database/Migrations/201807251330036_InitMigration.cs new file mode 100644 index 00000000..9472ab58 --- /dev/null +++ b/Step.Database/Migrations/201807251330036_InitMigration.cs @@ -0,0 +1,268 @@ +namespace Step.Database.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class InitMigration : DbMigration + { + public override void Up() + { + CreateTable( + "dbo.family", + c => new + { + id = c.Int(nullable: false, identity: true), + name = c.String(unicode: false), + type = c.Byte(nullable: false), + right_size = c.Byte(nullable: false), + left_size = c.Byte(nullable: false), + tcp_table = c.Byte(nullable: false), + gamma = c.Byte(nullable: false), + rotation_type = c.Byte(nullable: false), + cooling_byte = c.Byte(nullable: false), + max_speed = c.Int(nullable: false), + max_load = c.Byte(nullable: false), + min_load_pct_autoload = c.Byte(nullable: false), + max_load_pct_autoload = c.Byte(nullable: false), + dynamic_compensation = c.Byte(nullable: false), + min_load_dynamic_comp = c.Byte(nullable: false), + max_load_dynamic_comp = c.Byte(nullable: false), + life_type = c.Byte(nullable: false), + nominal_life = c.Int(nullable: false), + revive_delta = c.Int(nullable: false), + }) + .PrimaryKey(t => t.id); + + CreateTable( + "dbo.tool", + c => new + { + id = c.Int(nullable: false, identity: true), + offset_length = c.Int(nullable: false), + residual_life = c.Int(nullable: false), + residual_revive = c.Int(nullable: false), + status = c.Byte(nullable: false), + family_id = c.Int(nullable: false), + shank_id = c.Int(), + offsetId1 = c.Int(), + offsetId2 = c.Int(), + offsetId3 = c.Int(), + }) + .PrimaryKey(t => t.id) + .ForeignKey("dbo.family", t => t.family_id, cascadeDelete: true) + .ForeignKey("dbo.shank", t => t.shank_id) + .Index(t => t.family_id) + .Index(t => t.shank_id); + + CreateTable( + "dbo.shank", + c => new + { + magazine_id = c.Byte(), + position_id = c.Byte(), + id = c.Int(nullable: false, identity: true), + balluf = c.Int(), + magazine_position_type = c.Byte(nullable: false), + }) + .PrimaryKey(t => t.id) + .ForeignKey("dbo.magazine_position", t => new { t.magazine_id, t.position_id }) + .Index(t => new { t.magazine_id, t.position_id }); + + CreateTable( + "dbo.magazine_position", + c => new + { + magazine_id = c.Byte(nullable: false), + position_id = c.Byte(nullable: false), + type = c.Byte(nullable: false), + disabled = c.Boolean(nullable: false), + }) + .PrimaryKey(t => new { t.magazine_id, t.position_id }); + + CreateTable( + "dbo.function_access", + c => new + { + id = c.Int(nullable: false, identity: true), + name = c.String(unicode: false), + write_level_min = c.Int(nullable: false), + read_level_min = c.Int(nullable: false), + area = c.String(unicode: false), + enabled = c.Boolean(nullable: false), + plc_id = c.Int(nullable: false), + }) + .PrimaryKey(t => t.id); + + CreateTable( + "dbo.machine", + c => new + { + id = c.Int(nullable: false, identity: true), + name = c.String(unicode: false), + unique_id = c.String(unicode: false), + }) + .PrimaryKey(t => t.id); + + CreateTable( + "dbo.machine_user", + c => new + { + id = c.Int(nullable: false, identity: true), + machine_id = c.Int(nullable: false), + user_id = c.Int(nullable: false), + role_id = c.Int(nullable: false), + }) + .PrimaryKey(t => t.id) + .ForeignKey("dbo.machine", t => t.machine_id, cascadeDelete: true) + .ForeignKey("dbo.role", t => t.role_id, cascadeDelete: true) + .ForeignKey("dbo.user", t => t.user_id, cascadeDelete: true) + .Index(t => new { t.machine_id, t.user_id }, unique: true, clustered: true, name: "unique_machine_user") + .Index(t => t.role_id); + + CreateTable( + "dbo.role", + c => new + { + id = c.Int(nullable: false, identity: true), + name = c.String(unicode: false), + level = c.Int(nullable: false), + }) + .PrimaryKey(t => t.id); + + CreateTable( + "dbo.user", + c => new + { + id = c.Int(nullable: false, identity: true), + username = c.String(nullable: false, unicode: false), + first_name = c.String(unicode: false), + last_name = c.String(unicode: false), + password = c.String(unicode: false), + security_stamp = c.String(unicode: false), + language = c.String(unicode: false), + }) + .PrimaryKey(t => t.id); + + CreateTable( + "dbo.maintenance_file", + c => new + { + id = c.Int(nullable: false, identity: true), + file_name = c.String(unicode: false), + local_file_name = c.String(unicode: false), + maintenance_id = c.Int(nullable: false), + user_id = c.Int(), + }) + .PrimaryKey(t => t.id) + .ForeignKey("dbo.maintenance", t => t.maintenance_id, cascadeDelete: true) + .ForeignKey("dbo.user", t => t.user_id) + .Index(t => t.maintenance_id) + .Index(t => t.user_id); + + CreateTable( + "dbo.maintenance", + c => new + { + id = c.Int(nullable: false, identity: true), + intervall = c.Double(), + deadline = c.DateTime(nullable: false, precision: 0), + type = c.Int(nullable: false), + counter_id = c.Int(nullable: false), + title = c.String(unicode: false), + description = c.String(unicode: false), + unit_of_measure = c.Int(), + creation_date = c.DateTime(nullable: false, precision: 0), + last_expiration_date = c.DateTime(precision: 0), + user_id = c.Int(), + }) + .PrimaryKey(t => t.id) + .ForeignKey("dbo.user", t => t.user_id) + .Index(t => t.user_id); + + CreateTable( + "dbo.maintenance_note", + c => new + { + id = c.Int(nullable: false, identity: true), + message = c.String(unicode: false), + user_id = c.Int(nullable: false), + maintenance_id = c.Int(nullable: false), + timestamp = c.DateTime(nullable: false, precision: 0), + }) + .PrimaryKey(t => t.id) + .ForeignKey("dbo.maintenance", t => t.maintenance_id, cascadeDelete: true) + .ForeignKey("dbo.user", t => t.user_id, cascadeDelete: true) + .Index(t => t.user_id) + .Index(t => t.maintenance_id); + + CreateTable( + "dbo.performed_maintenance", + c => new + { + id = c.Int(nullable: false, identity: true), + date = c.DateTime(nullable: false, precision: 0), + counter_value = c.Int(nullable: false), + maintenance = c.Int(nullable: false), + }) + .PrimaryKey(t => t.id) + .ForeignKey("dbo.maintenance", t => t.maintenance, cascadeDelete: true) + .Index(t => t.maintenance); + + CreateTable( + "dbo.session", + c => new + { + id = c.Int(nullable: false, identity: true), + token = c.String(unicode: false), + machine_user_id = c.Int(nullable: false), + }) + .PrimaryKey(t => t.id) + .ForeignKey("dbo.machine_user", t => t.machine_user_id, cascadeDelete: true) + .Index(t => t.machine_user_id); + + } + + public override void Down() + { + DropForeignKey("dbo.session", "machine_user_id", "dbo.machine_user"); + DropForeignKey("dbo.performed_maintenance", "maintenance", "dbo.maintenance"); + DropForeignKey("dbo.maintenance_note", "user_id", "dbo.user"); + DropForeignKey("dbo.maintenance_note", "maintenance_id", "dbo.maintenance"); + DropForeignKey("dbo.maintenance_file", "user_id", "dbo.user"); + DropForeignKey("dbo.maintenance_file", "maintenance_id", "dbo.maintenance"); + DropForeignKey("dbo.maintenance", "user_id", "dbo.user"); + DropForeignKey("dbo.machine_user", "user_id", "dbo.user"); + DropForeignKey("dbo.machine_user", "role_id", "dbo.role"); + DropForeignKey("dbo.machine_user", "machine_id", "dbo.machine"); + DropForeignKey("dbo.tool", "shank_id", "dbo.shank"); + DropForeignKey("dbo.shank", new[] { "magazine_id", "position_id" }, "dbo.magazine_position"); + DropForeignKey("dbo.tool", "family_id", "dbo.family"); + DropIndex("dbo.session", new[] { "machine_user_id" }); + DropIndex("dbo.performed_maintenance", new[] { "maintenance" }); + DropIndex("dbo.maintenance_note", new[] { "maintenance_id" }); + DropIndex("dbo.maintenance_note", new[] { "user_id" }); + DropIndex("dbo.maintenance", new[] { "user_id" }); + DropIndex("dbo.maintenance_file", new[] { "user_id" }); + DropIndex("dbo.maintenance_file", new[] { "maintenance_id" }); + DropIndex("dbo.machine_user", new[] { "role_id" }); + DropIndex("dbo.machine_user", "unique_machine_user"); + DropIndex("dbo.shank", new[] { "magazine_id", "position_id" }); + DropIndex("dbo.tool", new[] { "shank_id" }); + DropIndex("dbo.tool", new[] { "family_id" }); + DropTable("dbo.session"); + DropTable("dbo.performed_maintenance"); + DropTable("dbo.maintenance_note"); + DropTable("dbo.maintenance"); + DropTable("dbo.maintenance_file"); + DropTable("dbo.user"); + DropTable("dbo.role"); + DropTable("dbo.machine_user"); + DropTable("dbo.machine"); + DropTable("dbo.function_access"); + DropTable("dbo.magazine_position"); + DropTable("dbo.shank"); + DropTable("dbo.tool"); + DropTable("dbo.family"); + } + } +} diff --git a/Step.Database/Migrations/201807251330036_InitMigration.resx b/Step.Database/Migrations/201807251330036_InitMigration.resx new file mode 100644 index 00000000..2864c6cf --- /dev/null +++ b/Step.Database/Migrations/201807251330036_InitMigration.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 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 + + + dbo + + \ No newline at end of file diff --git a/Step.Database/Step.Database.csproj b/Step.Database/Step.Database.csproj index e70b1a2d..033d3cad 100644 --- a/Step.Database/Step.Database.csproj +++ b/Step.Database/Step.Database.csproj @@ -70,17 +70,17 @@ - + - - - 201807120908403_InitMigration.cs + + + 201807251330036_InitMigration.cs @@ -116,8 +116,8 @@ - - 201807120908403_InitMigration.cs + + 201807251330036_InitMigration.cs diff --git a/Step.Model/ConfigModels/ToolManagerConfigModel.cs b/Step.Model/ConfigModels/ToolManagerConfigModel.cs new file mode 100644 index 00000000..0279e931 --- /dev/null +++ b/Step.Model/ConfigModels/ToolManagerConfigModel.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Step.Model.ConfigModels +{ + public class ToolManagerConfigModel + { + public bool FamilyOptIsActive { get; set; } + public bool ShankOptIsActive { get; set; } + public bool MagPositionIsActive { get; set; } + public bool OffsetOptIsActive { get; set; } + public bool ReviveOptIsActive { get; set; } + public bool GammaOptIsActive { get; set; } + public bool LifeOptIsActive { get; set; } + public bool TcpOptIsActive { get; set; } + public bool CoolingOptIsActive { get; set; } + public bool MultidimensionalShankOptIsActive { get; set; } + public bool SelfAdaptivePathOptIsActive { get; set; } + public bool DynamicCompensationOptIsActive { get; set; } + } +} diff --git a/Step.Model/ConfigModels/ToolTableConfigModel.cs b/Step.Model/ConfigModels/ToolTableConfigModel.cs deleted file mode 100644 index cfd1fa2c..00000000 --- a/Step.Model/ConfigModels/ToolTableConfigModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Step.Model.ConfigModels -{ - public class ToolTableConfigModel - { - public bool FamilyOption; - public bool MultiToolOption; - public bool MagazinePosition; - } -} diff --git a/Step.Model/Constants.cs b/Step.Model/Constants.cs index 901b7a11..48003b1f 100644 --- a/Step.Model/Constants.cs +++ b/Step.Model/Constants.cs @@ -126,6 +126,9 @@ namespace Step.Model public const string NC_SOFTKEYS_CONFIG_SCHEMA_PATH = CONFIG_DIRECTORY + "ncSoftKeyConfigValidator.xsd"; public const string NC_SOFTKEYS_CONFIG_PATH = CONFIG_DIRECTORY + "ncSoftKeyConfig.xml"; + public const string TOOL_MANAGER_CONFIG_SCHEMA_PATH = CONFIG_DIRECTORY + "toolManagerConfigValidator.xsd"; + public const string TOOL_MANAGER_CONFIG_PATH = CONFIG_DIRECTORY + "toolManagerConfig.xml"; + public static string WEBSITE_DIRECTORY = Path.Combine(BASE_PATH, "..", "wwwroot"); public static string LANGUAGE_PACK_DIRECTORY = BASE_PATH + "\\languages\\"; public static string LANGUAGE_SCHEMA_PATH = BASE_PATH + "\\LanguageValidator.xsd"; @@ -136,6 +139,7 @@ namespace Step.Model public const string SEND_NC_STATUS = "NC_STATUS"; public const string SEND_THREADS_STATUS = "THREAD_STATUS"; public const string SHOW_MSG_UI = "SHOW_MSG_UI"; + public const string SEND_ERROR_TO_UI = "SEND_ERROR_TO_UI"; // MVVM Messages to signalR tasks public const string SEND_ALARMS = "SEND_ALARMS"; @@ -151,6 +155,7 @@ namespace Step.Model public const string SEND_AXIS_NAMES_DATA = "SEND_AXIS_NAMES_DATA"; public const string SEND_MAGAZINES_STATUS = "SEND_MAGAZINES_STATUS"; public const string SEND_ACTIVE_PROGRAM_DATA = "SEND_ACTIVE_PROGRAM_DATA"; + public const string UPDATE_TOOLS_DATA = "UPDATE_TOOLS_DATA"; public const string BROADCAST_DATA = "BROADCAST_DATA"; @@ -175,5 +180,13 @@ namespace Step.Model public const string TOOL_MANAGER = "toolManager"; public const string MAINTENANCE = "maintenance"; } + + public static class API_ERROR_KEYS + { + public const string INCORRECT_PARAMETERS = "error_incorrect_parameters"; + public const string MAGAZINE_POSITION_OCCUPIED = "error_magazine_position_occupied"; + public const string TOOL_IS_MOUNTED = "error_tool_mounted"; + public const string OPTION_NOT_ACTIVE = "error_option_not_active"; + } } } diff --git a/Step.Model/DTOModels/DTOHeadModel.cs b/Step.Model/DTOModels/DTOHeadModel.cs index 8b0f028e..e8e7642d 100644 --- a/Step.Model/DTOModels/DTOHeadModel.cs +++ b/Step.Model/DTOModels/DTOHeadModel.cs @@ -44,6 +44,11 @@ return true; } + + public override int GetHashCode() + { + return base.GetHashCode(); + } } public class DTOSpindleModel : DTOHeadModel @@ -73,6 +78,11 @@ // Call Parent equals return base.Equals(item); } + + public override int GetHashCode() + { + return base.GetHashCode(); + } } public class DTOAbrasiveWaterJet : DTOHeadModel @@ -102,6 +112,11 @@ // Call Parent equals return base.Equals(item); } + + public override int GetHashCode() + { + return base.GetHashCode(); + } } public class DTOWaterJet : DTOHeadModel @@ -123,5 +138,10 @@ // Call Parent equals return base.Equals(item); } + + public override int GetHashCode() + { + return base.GetHashCode(); + } } } \ No newline at end of file diff --git a/Step.Model/DTOModels/ToolModels/DTONcFamilyModel.cs b/Step.Model/DTOModels/ToolModels/DTONcFamilyModel.cs new file mode 100644 index 00000000..4697a390 --- /dev/null +++ b/Step.Model/DTOModels/ToolModels/DTONcFamilyModel.cs @@ -0,0 +1,242 @@ +using Step.Model.DatabaseModels; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Step.Model.DTOModels.ToolModels +{ + public class DTONewNcFamilyModel + { + [Required] + public string Name { get; set; } + + [Required] + public byte Type { get; set; } + + [Required] + public byte RightSize { get; set; } + + [Required] + public byte LeftSize { get; set; } + + [Required] + public byte TcpTable { get; set; } + + [Required] + public byte Gamma { get; set; } + + [Required] + public byte RotationType { get; set; } + + [Required] + public bool Cooling { get; set; } + [Required] + public bool Cooling1 { get; set; } + [Required] + public bool Cooling2 { get; set; } + [Required] + public bool Cooling3 { get; set; } + [Required] + public bool Cooling4 { get; set; } + [Required] + public bool Cooling5 { get; set; } + [Required] + public bool Cooling6 { get; set; } + [Required] + public bool Cooling7 { get; set; } + + [Required] + public int MaxSpeed { get; set; } + + [Required] + public byte MaxLoad { get; set; } + + [Required] + public byte MinLoadPctAutoload { get; set; } + + [Required] + public byte MaxLoadPctAutoload { get; set; } + + [Required] + public byte DynamicCompensation { get; set; } + + [Required] + public byte MinLoadDynamicCompensation { get; set; } + + [Required] + public byte MaxLoadDynamicCompensation { get; set; } + + [Required] + public byte LifeType { get; set; } + + [Required] + public int NominalLife { get; set; } + + [Required] + public int ReviveDelta { get; set; } + + public static explicit operator DTONewNcFamilyModel(DbNcFamilyModel obj) + { + // Get bit values + BitArray coolingByte = new BitArray(new byte[] { obj.CoolingByte }); + bool[] bits = new bool[8]; + coolingByte.CopyTo(bits, 0); + + return new DTONcFamilyModel() + { + Id = obj.FamilyId, + Name = obj.Name, + Type = obj.Type, + RightSize = obj.RightSize, + LeftSize = obj.LeftSize, + TcpTable = obj.TcpTable, + Gamma = obj.Gamma, + RotationType = obj.RotationType, + Cooling = bits[0], + Cooling1 = bits[1], + Cooling2 = bits[2], + Cooling3 = bits[3], + Cooling4 = bits[4], + Cooling5 = bits[5], + Cooling6 = bits[6], + Cooling7 = bits[7], + 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 + }; + } + + public static explicit operator DbNcFamilyModel(DTONewNcFamilyModel obj) + { + // Prepare status byte + bool[] result = new bool[8] { obj.Cooling, obj.Cooling1, obj.Cooling2, obj.Cooling3, obj.Cooling4, obj.Cooling5, obj.Cooling6, obj.Cooling7 }; + byte coolingByte = ConvertArrayToByte(result); + + return new DbNcFamilyModel() + { + Name = obj.Name, + Type = obj.Type, + RightSize = obj.RightSize, + LeftSize = obj.LeftSize, + TcpTable = obj.TcpTable, + Gamma = obj.Gamma, + RotationType = obj.RotationType, + CoolingByte = 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, + }; + } + + protected static byte ConvertArrayToByte(bool[] bits) + { + BitArray bitField = new BitArray(bits); //BitArray takes a bool[] + byte[] bytes = new byte[1]; + bitField.CopyTo(bytes, 0); + + return bytes[0]; + } + } + + public class DTONcFamilyModel : DTONewNcFamilyModel + { + public int Id { get; set; } + + public List Tools { get; set; } + + public static explicit operator DTONcFamilyModel(DbNcFamilyModel obj) + { + List tools = new List(); + + if (obj.Tools != null) + foreach (var tool in obj.Tools) + { + tools.Add((DTONcToolModel)tool); + } + + // Get bit values + BitArray coolingByte = new BitArray(new byte[] { obj.CoolingByte }); + bool[] bits = new bool[8]; + coolingByte.CopyTo(bits, 0); + + return new DTONcFamilyModel() + { + Id = obj.FamilyId, + Name = obj.Name, + Type = obj.Type, + RightSize = obj.RightSize, + LeftSize = obj.LeftSize, + TcpTable = obj.TcpTable, + Gamma = obj.Gamma, + RotationType = obj.RotationType, + Cooling = bits[0], + Cooling1 = bits[1], + Cooling2 = bits[2], + Cooling3 = bits[3], + Cooling4 = bits[4], + Cooling5 = bits[5], + Cooling6 = bits[6], + Cooling7 = bits[7], + 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, + Tools = tools + }; + } + + public static explicit operator DbNcFamilyModel(DTONcFamilyModel obj) + { + // Prepare status byte + bool[] result = new bool[8] { obj.Cooling, obj.Cooling1, obj.Cooling2, obj.Cooling3, obj.Cooling4, obj.Cooling5, obj.Cooling6, obj.Cooling7 }; + byte coolingByte = ConvertArrayToByte(result); + + return new DbNcFamilyModel() + { + FamilyId = obj.Id, + Name = obj.Name, + Type = obj.Type, + RightSize = obj.RightSize, + LeftSize = obj.LeftSize, + TcpTable = obj.TcpTable, + Gamma = obj.Gamma, + RotationType = obj.RotationType, + CoolingByte = 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, + }; + } + } +} diff --git a/Step.Model/DTOModels/ToolModels/DTONcMagazinePositionModel.cs b/Step.Model/DTOModels/ToolModels/DTONcMagazinePositionModel.cs new file mode 100644 index 00000000..bd0aac05 --- /dev/null +++ b/Step.Model/DTOModels/ToolModels/DTONcMagazinePositionModel.cs @@ -0,0 +1,47 @@ +using Step.Model.DatabaseModels; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Step.Model.DTOModels.ToolModels +{ + public class DTONcMagazinePositionModel + { + public byte MagazineId { get; set; } + + public byte PositionId { get; set; } + + [Required] + public bool Disabled { get; set; } + + [Required] + public byte Type { get; set; } + + public int? ShankId { get; set; } + + public static explicit operator DTONcMagazinePositionModel(DbNcMagazinePositionModel obj) + { + return new DTONcMagazinePositionModel() + { + MagazineId = obj.MagazineId, + PositionId = obj.PositionId, + Disabled = obj.Disabled, + Type = obj.Type + }; + } + + public static explicit operator DbNcMagazinePositionModel(DTONcMagazinePositionModel obj) + { + return new DbNcMagazinePositionModel() + { + MagazineId = obj.MagazineId, + PositionId = obj.PositionId, + Disabled = obj.Disabled, + Type = obj.Type + }; + } + } +} diff --git a/Step.Model/DTOModels/ToolModels/DTONcMountedShankModel.cs b/Step.Model/DTOModels/ToolModels/DTONcMountedShankModel.cs new file mode 100644 index 00000000..33f8b81d --- /dev/null +++ b/Step.Model/DTOModels/ToolModels/DTONcMountedShankModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Step.Model.DTOModels.ToolModels +{ + public class DTONcMountedShankModel + { + public byte PositionId; + public byte MagazineId; + public int ShankId; + } +} diff --git a/Step.Model/DTOModels/ToolModels/DTONcShankModel.cs b/Step.Model/DTOModels/ToolModels/DTONcShankModel.cs new file mode 100644 index 00000000..20460c0e --- /dev/null +++ b/Step.Model/DTOModels/ToolModels/DTONcShankModel.cs @@ -0,0 +1,83 @@ +using Step.Model.DatabaseModels; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Step.Model.DTOModels.ToolModels +{ + public class DTONewNcShankModel + { + [Required] + public ushort? Balluf { get; set; } + + [Required] + public byte MagazinePositionType { get; set; } + + public static explicit operator DTONewNcShankModel(DbNcShankModel obj) + { + return new DTONewNcShankModel() + { + Balluf = (ushort)obj.Balluf, + MagazinePositionType = obj.MagazinePositionType + }; + } + + public static explicit operator DbNcShankModel(DTONewNcShankModel obj) + { + return new DbNcShankModel() + { + Balluf = obj.Balluf, + MagazinePositionType = obj.MagazinePositionType + }; + } + } + + public class DTONcShankModel : DTONewNcShankModel + { + public int Id { get; set; } + + [Range(1, byte.MaxValue)] + public byte? MagazineId { get; set; } + + [Range(1, byte.MaxValue)] + public byte? PositionId { get; set; } + + public List Tools { get; set; } + + public static explicit operator DTONcShankModel(DbNcShankModel obj) + { + List tools = new List(); + + if (obj.Tools != null) + foreach (var tool in obj.Tools) + { + tools.Add((DTONcToolModel)tool); + } + + return new DTONcShankModel() + { + Id = obj.ShankId, + Balluf = (ushort)obj.Balluf, + MagazinePositionType = obj.MagazinePositionType, + MagazineId = obj.MagazineId, + PositionId = obj.PositionId, + Tools = tools + }; + } + + public static explicit operator DbNcShankModel(DTONcShankModel obj) + { + return new DbNcShankModel() + { + ShankId = obj.Id, + Balluf = obj.Balluf, + MagazinePositionType = obj.MagazinePositionType, + MagazineId = obj.MagazineId, + PositionId = obj.PositionId + }; + } + } +} diff --git a/Step.Model/DTOModels/ToolModels/DTONcToolModel.cs b/Step.Model/DTOModels/ToolModels/DTONcToolModel.cs new file mode 100644 index 00000000..7113af09 --- /dev/null +++ b/Step.Model/DTOModels/ToolModels/DTONcToolModel.cs @@ -0,0 +1,197 @@ +using Step.Model.DatabaseModels; +using System; +using System.Collections; +using System.ComponentModel.DataAnnotations; +using static CMS_CORE_Library.DataStructures; + +namespace Step.Model.DTOModels.ToolModels +{ + + public class DTONcTool + { + [Required] + public int OffsetLength { get; set; } + + [Required] + public int ResidualLife { get; set; } + + [Required] + public int ResidualRevive { get; set; } + + [Required] + // Foreign keys + public int FamilyId { get; set; } + + [Required] + public bool Disabled { get; set; } + + [Required] + public bool Broken { get; set; } + + [Required] + public bool Measured { get; set; } + + [Required] + public bool ClockwiseRotation { get; set; } + + [Required] + public bool CounterClockwiseRotation { get; set; } + + public int? ShankId { get; set; } + + public static explicit operator DTONcTool(DbNcToolModel obj) + { + // Get bit values + var statusBits = new BitArray(obj.Status); + bool[] bits = new bool[8]; + statusBits.CopyTo(bits, 0); + + return new DTONcTool() + { + FamilyId = obj.FamilyId, + ShankId = obj.ShankId == null ? 0 : obj.ShankId.Value, + OffsetLength = obj.OffsetLength, + ResidualLife = obj.ResidualLife, + ResidualRevive = obj.ResidualRevive, + Disabled = bits[0], + Broken = bits[1], + Measured = bits[2], + ClockwiseRotation = bits[3], + CounterClockwiseRotation = bits[4], + }; + } + + public static explicit operator DbNcToolModel(DTONcTool obj) + { + // Prepare status byte + bool[] result = new bool[8] { obj.Disabled, obj.Broken, obj.Measured, obj.ClockwiseRotation, obj.CounterClockwiseRotation, false, false, false }; + byte status = ConvertArrayToByte(result); + + return new DbNcToolModel() + { + FamilyId = obj.FamilyId, + ShankId = obj.ShankId, + OffsetLength = obj.OffsetLength, + ResidualLife = obj.ResidualLife, + ResidualRevive = obj.ResidualRevive, + Status = status + }; + } + + protected static byte ConvertArrayToByte(bool[] bits) + { + BitArray bitField = new BitArray(bits); //BitArray takes a bool[] + byte[] bytes = new byte[1]; + bitField.CopyTo(bytes, 0); + + return bytes[0]; + } + } + + public class DTONcToolModel : DTONcTool + { + public int Id { get; set; } + + public OffsetModel Offset1 { get; set; } + + public OffsetModel Offset2 { get; set; } + + public OffsetModel Offset3 { get; set; } + + public static explicit operator DTONcToolModel(DbNcToolModel obj) + { + // Get bit values + var statusBits = new BitArray(new byte[] { obj.Status }); + bool[] bits = new bool[8]; + statusBits.CopyTo(bits, 0); + + return new DTONcToolModel() + { + Id = obj.ToolId, + FamilyId = obj.FamilyId, + ShankId = obj.ShankId == null ? 0 : obj.ShankId.Value, + OffsetLength = obj.OffsetLength, + ResidualLife = obj.ResidualLife, + ResidualRevive = obj.ResidualRevive, + Disabled = bits[0], + Broken = bits[1], + Measured = bits[2], + ClockwiseRotation = bits[3], + CounterClockwiseRotation = bits[4], + }; + } + + public static explicit operator DbNcToolModel(DTONcToolModel obj) + { + // Prepare status byte + bool[] result = new bool[8] { obj.Disabled, obj.Broken, obj.Measured, obj.ClockwiseRotation, obj.CounterClockwiseRotation, false, false, false }; + byte status = ConvertArrayToByte(result); + + return new DbNcToolModel() + { + ToolId = obj.Id, + FamilyId = obj.FamilyId, + ShankId = obj.ShankId, + OffsetLength = obj.OffsetLength, + ResidualLife = obj.ResidualLife, + ResidualRevive = obj.ResidualRevive, + Status = status + }; + } + } + + public class DTONewNcToolModel : DTONcTool + { + public int? OffsetId1 { get; set; } + + public int? OffsetId2 { get; set; } + + public int? OffsetId3 { get; set; } + + + public static explicit operator DTONewNcToolModel(DbNcToolModel obj) + { + // Get bit values + var statusBits = new BitArray(obj.Status); + bool[] bits = new bool[8]; + statusBits.CopyTo(bits, 0); + + return new DTONewNcToolModel() + { + FamilyId = obj.FamilyId, + ShankId = obj.ShankId == null ? 0 : obj.ShankId.Value, + OffsetLength = obj.OffsetLength, + ResidualLife = obj.ResidualLife, + ResidualRevive = obj.ResidualRevive, + Disabled = bits[0], + Broken = bits[1], + Measured = bits[2], + ClockwiseRotation = bits[3], + CounterClockwiseRotation = bits[4], + OffsetId1 = obj.OffsetId1, + OffsetId2 = obj.OffsetId2, + OffsetId3 = obj.OffsetId3 + }; + } + + public static explicit operator DbNcToolModel(DTONewNcToolModel obj) + { + // Prepare status byte + bool[] result = new bool[8] { obj.Disabled, obj.Broken, obj.Measured, obj.ClockwiseRotation, obj.CounterClockwiseRotation, false, false, false}; + byte status = ConvertArrayToByte(result); + + return new DbNcToolModel() + { + FamilyId = obj.FamilyId, + ShankId = obj.ShankId, + OffsetLength = obj.OffsetLength, + ResidualLife = obj.ResidualLife, + ResidualRevive = obj.ResidualRevive, + Status = status, + OffsetId1 = obj.OffsetId1, + OffsetId2 = obj.OffsetId2, + OffsetId3 = obj.OffsetId3 + }; + } + } +} \ No newline at end of file diff --git a/Step.Model/DTOModels/ToolModels/DTONewToolDataModel.cs b/Step.Model/DTOModels/ToolModels/DTONewToolDataModel.cs new file mode 100644 index 00000000..d103e245 --- /dev/null +++ b/Step.Model/DTOModels/ToolModels/DTONewToolDataModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Step.Model.DTOModels.ToolModels +{ + public class DTONewToolDataModel + { + public Dictionary UpdatedStatus; + public Dictionary UpdatedLives; + } +} diff --git a/Step.Model/DTOModels/ToolModels/DTOSiemensToolModel.cs b/Step.Model/DTOModels/ToolModels/DTOSiemensToolModel.cs index b811a6f3..cec33a4d 100644 --- a/Step.Model/DTOModels/ToolModels/DTOSiemensToolModel.cs +++ b/Step.Model/DTOModels/ToolModels/DTOSiemensToolModel.cs @@ -61,6 +61,8 @@ namespace Step.Model.DTOModels.ToolModels [Required] public bool PreAlarm { get; set; } + public DTONcShankModel Shank { get; set; } + public static explicit operator SiemensToolModel(DTOSiemensToolModel dtoModel) { return new SiemensToolModel() @@ -91,7 +93,7 @@ namespace Step.Model.DTOModels.ToolModels public class DTOMagazinesPositionsModel { - [Required()] + [Required] public bool Disabled { get; set; } } diff --git a/Step.Model/DatabaseModels/NcFamilyModel.cs b/Step.Model/DatabaseModels/NcFamilyModel.cs new file mode 100644 index 00000000..803698bd --- /dev/null +++ b/Step.Model/DatabaseModels/NcFamilyModel.cs @@ -0,0 +1,95 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using static CMS_CORE_Library.DataStructures; + +namespace Step.Model.DatabaseModels +{ + [Table("family")] + public class DbNcFamilyModel + { + [Key] + [Column("id")] + public int FamilyId { get; set; } + + [Column("name")] + public string Name { get; set; } + + [Column("type")] + public byte Type { get; set; } + + [Column("right_size")] + public byte RightSize { get; set; } + + [Column("left_size")] + public byte LeftSize { get; set; } + + [Column("tcp_table")] + public byte TcpTable { get; set; } + + [Column("gamma")] + public byte Gamma { get; set; } + + [Column("rotation_type")] + public byte RotationType { get; set; } + + [Column("cooling_byte")] + public byte CoolingByte { get; set; } + + [Column("max_speed")] + public int MaxSpeed { get; set; } + + [Column("max_load")] + public byte MaxLoad { get; set; } + + [Column("min_load_pct_autoload")] + public byte MinLoadPctAutoload { get; set; } + + [Column("max_load_pct_autoload")] + public byte MaxLoadPctAutoload { get; set; } + + [Column("dynamic_compensation")] + public byte DynamicCompensation { get; set; } + + [Column("min_load_dynamic_comp")] + public byte MinLoadDynamicCompensation { get; set; } + + [Column("max_load_dynamic_comp")] + public byte MaxLoadDynamicCompensation { get; set; } + + [Column("life_type")] + public byte LifeType { get; set; } + + [Column("nominal_life")] + public int NominalLife { get; set; } + + [Column("revive_delta")] + public int ReviveDelta { get; set; } + + public List Tools { get; set; } + + public static explicit operator NcFamilyModel(DbNcFamilyModel obj) + { + return new NcFamilyModel() + { + Id = (ushort)obj.FamilyId, + Type = obj.Type, + RightSize = obj.RightSize, + LeftSize = obj.LeftSize, + TcpTable = obj.TcpTable, + Gamma = obj.Gamma, + CoolingByte = obj.CoolingByte, + RotationType = obj.RotationType, + MaxLoad = obj.MaxLoad, + MaxSpeed = (ushort)obj.MaxSpeed, + MinLoadPctAutoload = obj.MinLoadPctAutoload, + MaxLoadPctAutoload = obj.MaxLoadDynamicCompensation, + MinLoadDynamicCompensation = obj.MinLoadDynamicCompensation, + MaxLoadDynamicCompensation = obj.MaxLoadDynamicCompensation, + LifeType = obj.LifeType, + NominalLife = (uint)obj.NominalLife, + ReviveDelta = (ushort)obj.ReviveDelta + }; + } + } +} \ No newline at end of file diff --git a/Step.Model/DatabaseModels/NcMagazinePositionModel.cs b/Step.Model/DatabaseModels/NcMagazinePositionModel.cs new file mode 100644 index 00000000..aebd10be --- /dev/null +++ b/Step.Model/DatabaseModels/NcMagazinePositionModel.cs @@ -0,0 +1,33 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using static CMS_CORE_Library.DataStructures; + +namespace Step.Model.DatabaseModels +{ + [Table("magazine_position")] + public class DbNcMagazinePositionModel + { + [Key, Column("magazine_id", Order = 0)] + public byte MagazineId { get; set; } + + [Key, Column("position_id", Order = 1)] + public byte PositionId { get; set; } + + [Column("type")] + public byte Type { get; set; } + + [Column("disabled")] + public bool Disabled { get; set; } + + public static explicit operator NcMagazinePositionModel(DbNcMagazinePositionModel obj) + { + return new NcMagazinePositionModel() + { + MagazineId = obj.MagazineId, + PositionId = obj.PositionId, + Disabled = obj.Disabled ? (byte)1 : (byte)0, + Type = obj.Type + }; + } + } +} diff --git a/Step.Model/DatabaseModels/NcOffsetModel.cs b/Step.Model/DatabaseModels/NcOffsetModel.cs new file mode 100644 index 00000000..a88c8b2d --- /dev/null +++ b/Step.Model/DatabaseModels/NcOffsetModel.cs @@ -0,0 +1,28 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Step.Model.DatabaseModels +{ + [Table("offset")] + public class NcOffsetModel + { + [Key] + [Column("id")] + public int OffsetId { get; set; } + + [Column("nc_offset_id")] + public int NcOffsetId { get; set; } + + [Column("lenght")] + public double Lenght { get; set; } + + [Column("radius")] + public double Radius { get; set; } + + [Column("wear_length")] + public double WearLength { get; set; } + + [Column("wear_radius")] + public double WearRadius { get; set; } + } +} \ No newline at end of file diff --git a/Step.Model/DatabaseModels/NcShankModel.cs b/Step.Model/DatabaseModels/NcShankModel.cs new file mode 100644 index 00000000..5f60a73c --- /dev/null +++ b/Step.Model/DatabaseModels/NcShankModel.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using static CMS_CORE_Library.DataStructures; + +namespace Step.Model.DatabaseModels +{ + [Table("shank")] + public class DbNcShankModel + { + [Key] + [Column("id")] + public int ShankId { get; set; } + + [Column("balluf")] + public int? Balluf { get; set; } + + [Column("magazine_position_type")] + public byte MagazinePositionType { get; set; } + + [ForeignKey("MagazinePosition"), Column("magazine_id", Order = 0)] + public byte? MagazineId { get; set; } + + [ForeignKey("MagazinePosition"), Column("position_id", Order = 1)] + public byte? PositionId { get; set; } + + public DbNcMagazinePositionModel MagazinePosition { get; set; } + + public List Tools { get; set; } + + public static explicit operator NcShankModel(DbNcShankModel obj) + { + return new NcShankModel() + { + Id = obj.ShankId, + Balluf = obj.Balluf == null ? (ushort)0 : (ushort)obj.Balluf.Value, + MagazineId = obj.MagazineId == null ? (byte)0 : obj.MagazineId.Value, + PositionId = obj.PositionId == null ? (byte)0 : obj.PositionId.Value, + MagazinePositionType = obj.MagazinePositionType, + }; + } + } +} \ No newline at end of file diff --git a/Step.Model/DatabaseModels/NcToolModel.cs b/Step.Model/DatabaseModels/NcToolModel.cs new file mode 100644 index 00000000..76405821 --- /dev/null +++ b/Step.Model/DatabaseModels/NcToolModel.cs @@ -0,0 +1,66 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using static CMS_CORE_Library.DataStructures; + +namespace Step.Model.DatabaseModels +{ + [Table("tool")] + public class DbNcToolModel + { + [Key] + [Column("id")] + public int ToolId { get; set; } + + [Column("offset_length")] + public int OffsetLength { get; set; } + + [Column("residual_life")] + public int ResidualLife { get; set; } + + [Column("residual_revive")] + public int ResidualRevive { get; set; } + + [Column("status")] + public byte Status { get; set; } + + // Foreign keys + [Column("family_id")] + [ForeignKey("Family")] + public int FamilyId { get; set; } + + [Column("shank_id")] + [DatabaseGenerated(DatabaseGeneratedOption.None)] + + [ForeignKey("Shank")] + public int? ShankId { get; set; } + + [Column("offsetId1")] + public int? OffsetId1 { get; set; } + + [Column("offsetId2")] + public int? OffsetId2 { get; set; } + + [Column("offsetId3")] + public int? OffsetId3 { get; set; } + + public virtual DbNcFamilyModel Family { get; set; } + public virtual DbNcShankModel Shank { get; set; } + + public static explicit operator NcToolModel(DbNcToolModel obj) + { + return new NcToolModel() + { + Id = (ushort)obj.ToolId, + FamilyId = obj.FamilyId, + OffsetLength = (ushort)obj.OffsetLength, + ResidualLife = (ushort)obj.ResidualLife, + Status = obj.Status, + ResidualRevive = (ushort)obj.ResidualRevive, + ShankId = obj.ShankId == null ? 0 : obj.ShankId.Value, + OffsetId1 = obj.OffsetId1 == null ? 0 : obj.OffsetId1.Value, + OffsetId2 = obj.OffsetId2 == null ? 0 : obj.OffsetId2.Value, + OffsetId3 = obj.OffsetId3 == null ? 0 : obj.OffsetId3.Value + }; + } + } +} \ No newline at end of file diff --git a/Step.Model/DatabaseModels/RoleModel.cs.d.ts b/Step.Model/DatabaseModels/RoleModel.cs.d.ts deleted file mode 100644 index 6c9eab71..00000000 --- a/Step.Model/DatabaseModels/RoleModel.cs.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -declare module server { - interface roleModel { - roleId: number; - name: string; - level: number; - } -} diff --git a/Step.Model/DatabaseModels/UserModel.cs.d.ts b/Step.Model/DatabaseModels/UserModel.cs.d.ts deleted file mode 100644 index 6293daa4..00000000 --- a/Step.Model/DatabaseModels/UserModel.cs.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -declare module server { - interface userModel { - userId: number; - username: string; - firstName: string; - lastName: string; - password: string; - securityStamp: string; - _language: string; - language: { - parent: any; - lCID: number; - keyboardLayoutId: number; - name: string; - ietfLanguageTag: string; - displayName: string; - nativeName: string; - englishName: string; - twoLetterISOLanguageName: string; - threeLetterISOLanguageName: string; - threeLetterWindowsLanguageName: string; - compareInfo: { - name: string; - lCID: number; - version: { - fullVersion: number; - sortId: any; - }; - }; - textInfo: { - aNSICodePage: number; - oEMCodePage: number; - macCodePage: number; - eBCDICCodePage: number; - lCID: number; - cultureName: string; - isReadOnly: boolean; - listSeparator: string; - isRightToLeft: boolean; - }; - isNeutralCulture: boolean; - cultureTypes: any; - numberFormat: { - currencyDecimalDigits: number; - currencyDecimalSeparator: string; - isReadOnly: boolean; - currencyGroupSizes: number[]; - numberGroupSizes: number[]; - percentGroupSizes: number[]; - currencyGroupSeparator: string; - currencySymbol: string; - naNSymbol: string; - currencyNegativePattern: number; - numberNegativePattern: number; - percentPositivePattern: number; - percentNegativePattern: number; - negativeInfinitySymbol: string; - negativeSign: string; - numberDecimalDigits: number; - numberDecimalSeparator: string; - numberGroupSeparator: string; - currencyPositivePattern: number; - positiveInfinitySymbol: string; - positiveSign: string; - percentDecimalDigits: number; - percentDecimalSeparator: string; - percentGroupSeparator: string; - percentSymbol: string; - perMilleSymbol: string; - nativeDigits: string[]; - digitSubstitution: any; - }; - dateTimeFormat: { - aMDesignator: string; - calendar: { - minSupportedDateTime: Date; - maxSupportedDateTime: Date; - algorithmType: any; - isReadOnly: boolean; - eras: number[]; - twoDigitYearMax: number; - }; - dateSeparator: string; - firstDayOfWeek: any; - calendarWeekRule: any; - fullDateTimePattern: string; - longDatePattern: string; - longTimePattern: string; - monthDayPattern: string; - pMDesignator: string; - rFC1123Pattern: string; - shortDatePattern: string; - shortTimePattern: string; - sortableDateTimePattern: string; - timeSeparator: string; - universalSortableDateTimePattern: string; - yearMonthPattern: string; - abbreviatedDayNames: string[]; - shortestDayNames: string[]; - dayNames: string[]; - abbreviatedMonthNames: string[]; - monthNames: string[]; - isReadOnly: boolean; - nativeCalendarName: string; - abbreviatedMonthGenitiveNames: string[]; - monthGenitiveNames: string[]; - }; - calendar: { - minSupportedDateTime: Date; - maxSupportedDateTime: Date; - algorithmType: any; - isReadOnly: boolean; - eras: number[]; - twoDigitYearMax: number; - }; - optionalCalendars: { - minSupportedDateTime: Date; - maxSupportedDateTime: Date; - algorithmType: any; - isReadOnly: boolean; - eras: number[]; - twoDigitYearMax: number; - }[]; - useUserOverride: boolean; - isReadOnly: boolean; - }; - roleId: number; - role: server.RoleModel; - } -} diff --git a/Step.Model/Step.Model.csproj b/Step.Model/Step.Model.csproj index fc5396ee..cddcc589 100644 --- a/Step.Model/Step.Model.csproj +++ b/Step.Model/Step.Model.csproj @@ -67,6 +67,7 @@ + @@ -75,6 +76,11 @@ + + + + + DtsGenerator @@ -87,6 +93,7 @@ + @@ -109,6 +116,11 @@ + + + + + @@ -120,16 +132,6 @@ - - True - True - RoleModel.cs - - - True - True - UserModel.cs - True True diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index 760f384b..125c47bf 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -12,6 +12,7 @@ using Step.Model.DTOModels.ToolModels; using Step.Utils; using System; using System.Collections.Generic; +using System.Data.Entity; using System.Globalization; using System.Linq; using static CMS_CORE_Library.DataStructures; @@ -238,7 +239,6 @@ namespace Step.NC // Select distints //alarms.NcAlarms = alarms.NcAlarms?.GroupBy(x => x.Id).Select(x => x.First()).ToList(); - // Get NC max process number ushort maxProcNumber = 0; cmsError = numericalControl.NC_RProcessesNum(ref maxProcNumber); @@ -459,7 +459,7 @@ namespace Step.NC counters = new List(); // Get counters values from PLC CmsError cmsError = numericalControl.PLC_RMachineCounters(ref counters); - + return cmsError; } @@ -520,6 +520,7 @@ namespace Step.NC missingDays = TimeSpan.FromMinutes(-1 * (counter.Value - perfVal - SupportFunctions.ConvertInMinutes(currMaintenance.Interval.Value, currMaintenance.UnitOfMeasure.Value))); } break; + case MAINTENANCE_TYPE.EXP_DATE: { // Already performed @@ -536,6 +537,7 @@ namespace Step.NC } } break; + case MAINTENANCE_TYPE.TIME_INTERVAL: { // Get last performed, default value is maintenance creation date @@ -550,7 +552,7 @@ namespace Step.NC // percentage = Passed minutes since last maintenance * 100 / Interval percentage = (minutesPassedFromLastMaint * 100) / SupportFunctions.ConvertInMinutes(currMaintenance.Interval.Value, currMaintenance.UnitOfMeasure.Value); - missingDays = TimeSpan.FromMinutes( -1 * (minutesPassedFromLastMaint - SupportFunctions.ConvertInMinutes(currMaintenance.Interval.Value, currMaintenance.UnitOfMeasure.Value))); + missingDays = TimeSpan.FromMinutes(-1 * (minutesPassedFromLastMaint - SupportFunctions.ConvertInMinutes(currMaintenance.Interval.Value, currMaintenance.UnitOfMeasure.Value))); counter = new CounterModel(); } break; @@ -559,7 +561,7 @@ namespace Step.NC canEdit = false; using (MachinesUsersController machineUsersController = new MachinesUsersController()) { - if(currMaintenance.UserId != null) + if (currMaintenance.UserId != null) { // Check if user can edit the maintenance -> caller id - maintenance user id int comparision = machineUsersController.CompareUsersRole(userId, currMaintenance.UserId.Value, MachineConfig.MachineId); @@ -646,7 +648,7 @@ namespace Step.NC expiredMaintenance.Add(new DTOExpiredMaintenanceModel() { Id = currMaintenance.MaintenanceId, - ExpirationDate = (DateTime)currMaintenance.LastExpirationDate, + ExpirationDate = (DateTime)currMaintenance.LastExpirationDate, CreatedByCms = currMaintenance.UserId == null, Title = currMaintenance.UserId == null ? "" : currMaintenance.Title }); @@ -674,7 +676,6 @@ namespace Step.NC Title = currMaintenance.UserId == null ? "" : currMaintenance.Title, }); } - } break; @@ -828,7 +829,7 @@ namespace Step.NC ActualSpeed = head.ActualSpeed_Pressure, Load = head.Load_Abrasive, MountedTool = (ushort)head.MountedTool_Vacum, - Override = head.Override, + Override = head.Override, IsActive = head.IsActive, IsSelected = head.IsSelected, AbrasiveIsActive = head.AbrasiveIsActive @@ -892,7 +893,7 @@ namespace Step.NC if (cmsError.IsError()) return cmsError; - if( selectedProcess != 0) + if (selectedProcess != 0) { // Read axes names cmsError = numericalControl.AXES_RAxesNames(selectedProcess, ref plcAxes); @@ -902,7 +903,6 @@ namespace Step.NC Id = x.Id, Name = x.Name }).ToList(); - } return cmsError; @@ -941,7 +941,7 @@ namespace Step.NC public CmsError GetMagazineStatus(out DTOMagazineActionModel magazineStatus) { // Set up models - magazineStatus= new DTOMagazineActionModel(); + magazineStatus = new DTOMagazineActionModel(); MagazineActionModel libModel = new MagazineActionModel(); // Read status from NC CmsError cmsError = numericalControl.TOOLS_GetMagazinesStatus(ref libModel); @@ -953,6 +953,69 @@ namespace Step.NC return cmsError; } + // OSAI FANUC TOOL MANAGER + + public CmsError GetToolsData(out List dtoTools) + { + dtoTools = new List(); + + CmsError cmsError = NO_ERROR; + + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + List tools = toolsManager.FindToolsWithDependencies(); + + foreach (DbNcToolModel tool in tools) + { + DTONcToolModel dtoTool = (DTONcToolModel)tool; + + cmsError = GetToolData(tool, ref dtoTool); + + dtoTools.Add(dtoTool); + } + + return cmsError; + } + } + + public CmsError GetToolData(DbNcToolModel tool, ref DTONcToolModel dtoTool) + { + dtoTool = (DTONcToolModel)tool; + + OffsetModel offset = new OffsetModel(); + CmsError cmsError = NO_ERROR; + + if (tool.OffsetId1 != null && tool.OffsetId1 != 0) + { + // Read first offset data + cmsError = numericalControl.TOOLS_ROffset((short)tool.OffsetId1, ref offset); + if (cmsError.IsError()) + return cmsError; + + dtoTool.Offset1 = offset; + } + if (tool.OffsetId2 != null && tool.OffsetId2 != 0) + { + // Read second offset data + cmsError = numericalControl.TOOLS_ROffset((short)tool.OffsetId2, ref offset); + if (cmsError.IsError()) + return cmsError; + + dtoTool.Offset2 = offset; + } + if (tool.OffsetId3 != null && tool.OffsetId3 != 0) + { + // Read third offset data + cmsError = numericalControl.TOOLS_ROffset((short)tool.OffsetId3, ref offset); + if (cmsError.IsError()) + return cmsError; + + dtoTool.Offset3 = offset; + } + + return cmsError; + } + #endregion Read Data #region Write data @@ -982,7 +1045,7 @@ namespace Step.NC // Write in memory the request to restore the alarm return numericalControl.PLC_WRestoreMessage(id); } - + public CmsError RefreshAllAlarms() { return numericalControl.PLC_WRefreshAllMessages(); @@ -1014,8 +1077,8 @@ namespace Step.NC return numericalControl.PLC_WPowerOnData(id, true); } - #region Tools - + #region Siemens Tools + public CmsError AddTool(ref SiemensToolModel tool) { return numericalControl.TOOLS_WAddTool(ref tool); @@ -1106,7 +1169,7 @@ namespace Step.NC public CmsError UnloadToolInMagazine(int magazineId, int positionId) { - return numericalControl.TOOLS_WUnloadToolInMagazine(magazineId, positionId); + return numericalControl.TOOLS_WUnloadToolFromMagazine(magazineId, positionId); } public CmsError LoadTooolIntoShank(int shankId, int positionId, int toolId) @@ -1119,12 +1182,567 @@ namespace Step.NC return numericalControl.TOOLS_WUnloadToolFromShank(shankId, positionId); } - public CmsError GetFileList(string filePath, out PreviewFileModel fileList) + #endregion Siemens Tools + + // OSAI FANUC + + #region Osai/Fanuc Tools + + public DTONcToolModel AddTool(DTONewNcToolModel tool) { - throw new NotImplementedException(); + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + DbNcToolModel ncTool = toolsManager.AddTool(tool); + + DTONcToolModel dtoTool = new DTONcToolModel(); + GetToolData(ncTool, ref dtoTool); + + return dtoTool; + } } - #endregion + public CmsError UpdateTool(int toolId, DTONewNcToolModel newTool, out DTONcToolModel toolWithOffsets) + { + toolWithOffsets = new DTONcToolModel(); + + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) + { + // Update database tool Tool + DbNcToolModel dbTool = toolsManager.UpdateTool(toolId, newTool); + + // Populate updated tool with offset data + CmsError cmsError = GetToolData(dbTool, ref toolWithOffsets); + if (cmsError.IsError()) + { + dbContextTransaction.Rollback(); + return cmsError; + } + + bool startIsActive = false; + + // Check if tool is loaded into a shank + if (dbTool.ShankId != null) + { + // Check if shank is loaded into magazine + DbNcShankModel shank = toolsManager.FindShankWithTools(dbTool.ShankId.Value); + if (shank.MagazineId != null) + { + startIsActive = true; + // Create backup of data stored on the NC and block file accesses + cmsError = numericalControl.TOOLS_WStartEditData(); + if (cmsError.IsError()) + { + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + return cmsError; + } + + // Update tool + cmsError = UpdateNcTools(toolsManager); + } + } + + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + + return NO_ERROR; + } + } + } + + public CmsError UpdateNcTools(NcToolManagerController toolsManager = null) + { + if (toolsManager == null) + toolsManager = new NcToolManagerController(); + + List shanks = toolsManager + .FindShanks() + .Where(x => x.MagazineId != null) + .Select(x => (NcShankModel)x) + .ToList(); + + // Get tools + List tools = toolsManager + .FindTools() + .Select(x => (NcToolModel)x) + .Where(x => shanks.Any(y => y.Id == x.ShankId)) // Find only mounted tools + .ToList(); + + // Update tools + return numericalControl.TOOLS_WUpdateTools(tools); + } + + public CmsError DeleteNcTool(DbNcToolModel tool) + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) + { + // Delete db tool + toolsManager.DeleteTool(tool.ToolId); + + bool startIsActive = false; + CmsError cmsError = NO_ERROR; + + if (tool.ShankId != null) + { + // If tool is mounted than update Nc data + DbNcShankModel shank = toolsManager.FindShankWithTools(tool.ShankId.Value); + if (shank.MagazineId != null) + { + startIsActive = true; + // Create backup of data stored on the NC and block file accesses + cmsError = numericalControl.TOOLS_WStartEditData(); + if (cmsError.IsError()) + { + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + return cmsError; + } + + // Update Nc data + cmsError = UpdateNcTools(toolsManager); + } + } + + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + + return cmsError; + } + } + } + + public CmsError UpdateShank(int shankId, DTONewNcShankModel dtoShank, out DTONcShankModel shank) + { + shank = new DTONcShankModel(); + + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) + { + bool startIsActive = false; + CmsError cmsError = NO_ERROR; + + // Update db data + shank = (DTONcShankModel)toolsManager.UpdateShank(shankId, dtoShank); + if (shank.MagazineId != null) + { + startIsActive = true; + // Create backup of data stored on the NC and block file accesses + cmsError = numericalControl.TOOLS_WStartEditData(); + if (cmsError.IsError()) + { + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + return cmsError; + } + + // Update nc data + cmsError = UpdateNcShank(toolsManager); + } + + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + + return cmsError; + } + } + } + + public CmsError DeleteNcShank(int shankId) + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) + { + // Create backup of data stored on the NC and block file accesses + CmsError cmsError = numericalControl.TOOLS_WStartEditData(); + if (cmsError.IsError()) + return cmsError; + + // Delete database shank + DbNcShankModel deletedShank = toolsManager.DeleteShank(shankId); + bool startIsActive = false; + if (deletedShank.MagazineId != null) + { + startIsActive = true; + // Create backup of data stored on the NC and block file accesses + cmsError = numericalControl.TOOLS_WStartEditData(); + if (cmsError.IsError()) + { + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + return cmsError; + } + + // Update nc data + cmsError = UpdateNcShank(toolsManager); + } + + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + + return cmsError; + } + } + } + + private CmsError UpdateNcShank(NcToolManagerController toolsManager) + { + // Get mounted shanks + List shanks = toolsManager + .FindShanks() + .Where(x => x.MagazineId != null) + .Select(x => (NcShankModel)x) + .ToList(); + + // Update nc data + return numericalControl.TOOLS_WUpdateShanks(shanks); + } + + public DTONcFamilyModel AddFamily(DTONewNcFamilyModel family) + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + return (DTONcFamilyModel)toolsManager.AddFamily(family); + } + } + + public CmsError UpdateFamily(int familyId, DTONewNcFamilyModel family, out DTONcFamilyModel newFamily) + { + newFamily = new DTONcFamilyModel(); + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) + { + // Update db family + newFamily = (DTONcFamilyModel)toolsManager.UpdateFamily(familyId, family); + + // Create backup of data stored on the NC and block file accesses + CmsError cmsError = numericalControl.TOOLS_WStartEditData(); + if (cmsError.IsError()) + { + ManageErrorAndTransaction(cmsError, dbContextTransaction, true); + return cmsError; + } + + // Update Nc families + cmsError = UpdateNcFamily(toolsManager); + + ManageErrorAndTransaction(cmsError, dbContextTransaction, true); + + return cmsError; + } + } + } + + public CmsError DeleteNcFamily(DbNcFamilyModel family) + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) + { + // Create backup of data stored on the NC and block file accesses + CmsError cmsError = numericalControl.TOOLS_WStartEditData(); + if (cmsError.IsError()) + return cmsError; + + toolsManager.DeleteFamily(family); + // Update Nc families + cmsError = UpdateNcFamily(toolsManager); + + ManageErrorAndTransaction(cmsError, dbContextTransaction, true); + + return cmsError; + } + } + } + + private CmsError UpdateNcFamily(NcToolManagerController toolsManager) + { + // Get mounted shanks + List shanks = toolsManager + .FindShanks() + .Where(x => x.MagazineId != null) + .Select(x => (NcShankModel)x) + .ToList(); + + // Get tools + List tools = toolsManager + .FindTools() + .Select(x => (NcToolModel)x) + .Where(x => shanks.Any(y => y.Id == x.ShankId)) // Find only mounted tools + .ToList(); + + List families = toolsManager + .FindFamilies() + .Select(x => (NcFamilyModel)x) + .Where(x => tools.Any(y => y.FamilyId == x.Id)) // Find only families of mounted tools + .ToList(); + + // Update nc families + return numericalControl.TOOLS_WUpdateFamilies(families); + } + + public CmsError UpdateMagazinePosition(DbNcMagazinePositionModel dbPos, DTONcMagazinePositionModel dtoPos, out DTONcMagazinePositionModel magPos) + { + magPos = new DTONcMagazinePositionModel(); + + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + using (DbContextTransaction dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) + { + // Create backup of data stored on the NC and block file accesses + CmsError cmsError = StartEditData(); + if (cmsError.IsError()) + { + ManageErrorAndTransaction(cmsError, dbContextTransaction, true); + return cmsError; + } + + // Update database data + magPos = (DTONcMagazinePositionModel)toolsManager.UpdatePosition(dbPos, dtoPos); + + // Get magazines positions + List positions = toolsManager.FindMagazinesPositions() + .Select(x => (NcMagazinePositionModel)x) + .ToList(); + // Update Nc data + cmsError = numericalControl.TOOLS_WUpdateMagazinePositions(positions); + + ManageErrorAndTransaction(cmsError, dbContextTransaction, true); + + return cmsError; + } + } + } + + private void ManageErrorAndTransaction(CmsError cmsError, DbContextTransaction dbContextTransaction, bool ncStartIsActive) + { + // Check cmsError, manage transaction and if startIsActive = true manage Nc backup created with TOOLS_WStartEditData() + if (cmsError.IsError()) + { + // Close transaction + dbContextTransaction.Rollback(); + // Restore backup + if(ncStartIsActive) + numericalControl.TOOLS_WRestoreBackup(); + } + else + { + // Close transaction + dbContextTransaction.Commit(); + // Stop editing ncData + if (ncStartIsActive) + numericalControl.TOOLS_WStopEditData(); + } + } + + + public DTONcShankModel LoadIntoShank(DbNcToolModel tool, int shankId) + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + return toolsManager.LoadToolIntoShank(tool, shankId); + } + } + + public DTONcShankModel UnloadFromShank(DbNcToolModel tool) + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + return toolsManager.UnloadToolFromShank(tool); + } + } + + public CmsError SetupNcToolManager() + { + if (NcConfig.NcVendor != NC_VENDOR.SIEMENS) + { + return UpdateMagazinePositionConf(); + } + + return NO_ERROR; + } + + public CmsError UpdateMagazinePositionConf() + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + // Get database configured positions + List dbPositions = toolsManager.FindMagazinesPositions(); + if (dbPositions.Count <= 0) + { + CmsError cmsError = GetMagazineConfiguration(out List config); + if (cmsError.IsError()) + return cmsError; + + // Setup new positions list in order to be saved in the database + List fromConfigPosition = new List(); + foreach (var conf in config) + { + for (byte i = 1; i <= conf.MaxPositions; i++) + { + // Create new position + fromConfigPosition.Add(new DbNcMagazinePositionModel() + { + MagazineId = conf.Id, + PositionId = i, + Disabled = false, + Type = 0 + }); + } + } + + // Update database + toolsManager.SetupMagazinePositions(fromConfigPosition); + + return cmsError; + } + + return NO_ERROR; + } + } + + public CmsError GetMagazineConfiguration(out List config) + { + config = new List(); + // Read configuration + return numericalControl.TOOLS_RMagazineConfig(ref config); + } + + public CmsError StartEditData() + { + return numericalControl.TOOLS_WStartEditData(); + } + + public CmsError StopEditData() + { + return numericalControl.TOOLS_WStopEditData(); + } + + public CmsError StartEditTooling(int magazineId) + { + return numericalControl.TOOLS_WStartEditTooling(magazineId); + } + + public CmsError StopEditTooling(int magazineId) + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + // Get mounted shanks + List shanks = toolsManager + .FindShanks() + .Where(x => x.MagazineId != null) + .Select(x => (NcShankModel)x) + .ToList(); + + CmsError cmsError = numericalControl.TOOLS_WUpdateShanks(shanks); + if (cmsError.IsError()) + return cmsError; + + // Get magazine positions + List positions = toolsManager.FindMagazinesPositions() + .Select(x => (NcMagazinePositionModel)x) + .ToList(); + cmsError = numericalControl.TOOLS_WUpdateMagazinePositions(positions); + if (cmsError.IsError()) + return cmsError; + + // Get tools + List tools = toolsManager + .FindTools() + .Select(x => (NcToolModel)x) + .Where(x => shanks.Any(y => y.Id == x.ShankId)) // Find only mounted tools + .ToList(); + + // Update tools + cmsError = numericalControl.TOOLS_WUpdateTools(tools); + if (cmsError.IsError()) + return cmsError; + + List families = toolsManager + .FindFamilies() + .Select(x => (NcFamilyModel)x) + .Where(x => tools.Any(y => y.FamilyId == x.Id)) // Find only families of mounted tools + .ToList(); + // Update families + cmsError = numericalControl.TOOLS_WUpdateFamilies(families); + if (cmsError.IsError()) + return cmsError; + } + + return numericalControl.TOOLS_WStopEditTooling(magazineId); + } + + public CmsError GetUpdatedToolsData(out Dictionary updatedStatus, out Dictionary updatedLives) + { + updatedStatus = new Dictionary(); + updatedLives = new Dictionary(); + return numericalControl.TOOLS_RUpdatedToolsData(ref updatedStatus, ref updatedLives); + } + + public CmsError CheckIfShankCanFit(int magazineId, int positionId, DbNcShankModel shankToBeLoaded) + { + CmsError cmsError = GetMagazineConfiguration(out List magazinesConfig); + if (cmsError.IsError()) + return cmsError; + + NcMagazineConfigModel magConfig = magazinesConfig.Where(x => x.Id == magazineId).FirstOrDefault();// Get only current magazine config + + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + List magazineMountedTools = toolsManager.GetMountedTools(); + + // Check if there is a tool already mounted in magazineId and positionId + var toolAlreadyMounted = magazineMountedTools.Where(x => x.Shank.MagazineId == magazineId && x.Shank.PositionId == positionId).FirstOrDefault(); + if (toolAlreadyMounted != null) + return MAGAZINE_POSITION_OCCUPIED_ERROR; + + List families = toolsManager.FindFamiliesByShankId(shankToBeLoaded.ShankId); + + int maxRight = families.Max(x => x.RightSize); + int maxLeft = families.Max(x => x.LeftSize); + + // Check if tool can fit in the position considering other tools + foreach (var mountedTool in magazineMountedTools) + { + // Check if is not the same position && if is different check if the position is on the same magazine + if (mountedTool.Shank.PositionId != positionId && mountedTool.Shank.MagazineId == magazineId) + { + int decPosition, incPosition; + decPosition = incPosition = mountedTool.Shank.PositionId.Value; + // if it is a circular magazine move position before ( for left case ) or after ( right case ) the location you want to mount the tool + if (magConfig.Type != NC_MAGAZINE_TYPE.BOX_MAGAZINE) + { + decPosition = decPosition < positionId ? decPosition + magConfig.MaxPositions : decPosition; + incPosition = incPosition > positionId ? incPosition - magConfig.MaxPositions : incPosition; + } + + if (!(magConfig.Type == NC_MAGAZINE_TYPE.BOX_MAGAZINE && mountedTool.Shank.PositionId == 1)) + { + // Right check + // Calculate left space occupied (with mounted shank) + double leftMounted = decPosition - (mountedTool.Family.LeftSize / 2.0); + // Calculate right space needed (with shank to be loaded) + double rightToBeMount = positionId + (maxRight / 2.0); + if (leftMounted < rightToBeMount) + return MAGAZINE_POSITION_OCCUPIED_ERROR; + } + + if (!(magConfig.Type == NC_MAGAZINE_TYPE.BOX_MAGAZINE && mountedTool.Shank.PositionId == magConfig.MaxPositions)) + { + // Left check + // Calculate right space occupied (with mounted shank) + double rightMounted = incPosition + (mountedTool.Family.RightSize / 2.0); + // Calculate left space needed (with shank to be loaded) + double leftToBeMounted = positionId - (maxLeft / 2.0); + if (rightMounted > leftToBeMounted) + return MAGAZINE_POSITION_OCCUPIED_ERROR; + } + } + } + } + + return NO_ERROR; + } + + #endregion Osai/Fanuc Tools #endregion Write data } } \ No newline at end of file diff --git a/Step.NC/Step.NC.csproj b/Step.NC/Step.NC.csproj index 020d964c..eec04cd2 100644 --- a/Step.NC/Step.NC.csproj +++ b/Step.NC/Step.NC.csproj @@ -36,6 +36,7 @@ False ..\Libs\CMS_CORE_Library.dll + diff --git a/Step.UI/ServerControlWindow.Designer.cs b/Step.UI/ServerControlWindow.Designer.cs index 933df0c1..7748999d 100644 --- a/Step.UI/ServerControlWindow.Designer.cs +++ b/Step.UI/ServerControlWindow.Designer.cs @@ -37,24 +37,6 @@ namespace Step.UI this.StopServerItem = new System.Windows.Forms.ToolStripMenuItem(); this.openUiButton = new MetroFramework.Controls.MetroButton(); this.metroTabControl1 = new MetroFramework.Controls.MetroTabControl(); - this.NCInfo = new MetroFramework.Controls.MetroTabPage(); - this.CHNcConnected = new MetroFramework.Controls.MetroCheckBox(); - this.TXTTime = new MetroFramework.Controls.MetroTextBox(); - this.TXTLang = new MetroFramework.Controls.MetroTextBox(); - this.TXTNCProc = new MetroFramework.Controls.MetroTextBox(); - this.TXTSftVers = new MetroFramework.Controls.MetroTextBox(); - this.TXTCMSMach = new MetroFramework.Controls.MetroTextBox(); - this.TXTNcSerial = new MetroFramework.Controls.MetroTextBox(); - this.TXTName = new MetroFramework.Controls.MetroTextBox(); - this.TXTType = new MetroFramework.Controls.MetroTextBox(); - this.metroLabel8 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel7 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel6 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel5 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel4 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel3 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel2 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel1 = new MetroFramework.Controls.MetroLabel(); this.ThreadsInfo = new MetroFramework.Controls.MetroTabPage(); this.LISTThreadStatus = new MetroFramework.Controls.MetroListView(); this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); @@ -62,9 +44,11 @@ namespace Step.UI this.stopServerButton = new MetroFramework.Controls.MetroButton(); this.TestJSButton = new MetroFramework.Controls.MetroButton(); this.TXTstatus = new MetroFramework.Controls.MetroTextBox(); + this.TXTType = new System.Windows.Forms.Label(); + this.CHNcConnected = new MetroFramework.Controls.MetroCheckBox(); + this.label1 = new System.Windows.Forms.Label(); this.NotifyIconMenu.SuspendLayout(); this.metroTabControl1.SuspendLayout(); - this.NCInfo.SuspendLayout(); this.ThreadsInfo.SuspendLayout(); this.SuspendLayout(); // @@ -95,7 +79,7 @@ namespace Step.UI // openUiButton // this.openUiButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.openUiButton.Location = new System.Drawing.Point(12, 381); + this.openUiButton.Location = new System.Drawing.Point(8, 371); this.openUiButton.Name = "openUiButton"; this.openUiButton.Size = new System.Drawing.Size(104, 42); this.openUiButton.TabIndex = 1; @@ -106,385 +90,14 @@ namespace Step.UI // // metroTabControl1 // - this.metroTabControl1.Controls.Add(this.NCInfo); this.metroTabControl1.Controls.Add(this.ThreadsInfo); - this.metroTabControl1.Location = new System.Drawing.Point(12, 56); + this.metroTabControl1.Location = new System.Drawing.Point(8, 26); this.metroTabControl1.Name = "metroTabControl1"; this.metroTabControl1.SelectedIndex = 0; this.metroTabControl1.Size = new System.Drawing.Size(328, 323); this.metroTabControl1.TabIndex = 7; this.metroTabControl1.UseSelectable = true; // - // NCInfo - // - this.NCInfo.Controls.Add(this.CHNcConnected); - this.NCInfo.Controls.Add(this.TXTTime); - this.NCInfo.Controls.Add(this.TXTLang); - this.NCInfo.Controls.Add(this.TXTNCProc); - this.NCInfo.Controls.Add(this.TXTSftVers); - this.NCInfo.Controls.Add(this.TXTCMSMach); - this.NCInfo.Controls.Add(this.TXTNcSerial); - this.NCInfo.Controls.Add(this.TXTName); - this.NCInfo.Controls.Add(this.TXTType); - this.NCInfo.Controls.Add(this.metroLabel8); - this.NCInfo.Controls.Add(this.metroLabel7); - this.NCInfo.Controls.Add(this.metroLabel6); - this.NCInfo.Controls.Add(this.metroLabel5); - this.NCInfo.Controls.Add(this.metroLabel4); - this.NCInfo.Controls.Add(this.metroLabel3); - this.NCInfo.Controls.Add(this.metroLabel2); - this.NCInfo.Controls.Add(this.metroLabel1); - this.NCInfo.HorizontalScrollbarBarColor = true; - this.NCInfo.HorizontalScrollbarHighlightOnWheel = false; - this.NCInfo.HorizontalScrollbarSize = 10; - this.NCInfo.Location = new System.Drawing.Point(4, 38); - this.NCInfo.Name = "NCInfo"; - this.NCInfo.Size = new System.Drawing.Size(320, 281); - this.NCInfo.TabIndex = 0; - this.NCInfo.Text = "NC Info"; - this.NCInfo.VerticalScrollbarBarColor = true; - this.NCInfo.VerticalScrollbarHighlightOnWheel = false; - this.NCInfo.VerticalScrollbarSize = 10; - // - // CHNcConnected - // - this.CHNcConnected.AutoCheck = false; - this.CHNcConnected.AutoSize = true; - this.CHNcConnected.Location = new System.Drawing.Point(173, 17); - this.CHNcConnected.Name = "CHNcConnected"; - this.CHNcConnected.Size = new System.Drawing.Size(81, 15); - this.CHNcConnected.TabIndex = 50; - this.CHNcConnected.Text = "Connected"; - this.CHNcConnected.UseSelectable = true; - // - // TXTTime - // - // - // - // - this.TXTTime.CustomButton.Image = null; - this.TXTTime.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTTime.CustomButton.Name = ""; - this.TXTTime.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTTime.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTTime.CustomButton.TabIndex = 1; - this.TXTTime.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTTime.CustomButton.UseSelectable = true; - this.TXTTime.CustomButton.Visible = false; - this.TXTTime.Lines = new string[0]; - this.TXTTime.Location = new System.Drawing.Point(173, 241); - this.TXTTime.MaxLength = 32767; - this.TXTTime.Name = "TXTTime"; - this.TXTTime.PasswordChar = '\0'; - this.TXTTime.ReadOnly = true; - this.TXTTime.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTTime.SelectedText = ""; - this.TXTTime.SelectionLength = 0; - this.TXTTime.SelectionStart = 0; - this.TXTTime.ShortcutsEnabled = true; - this.TXTTime.Size = new System.Drawing.Size(138, 23); - this.TXTTime.TabIndex = 49; - this.TXTTime.UseSelectable = true; - this.TXTTime.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTTime.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // TXTLang - // - // - // - // - this.TXTLang.CustomButton.Image = null; - this.TXTLang.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTLang.CustomButton.Name = ""; - this.TXTLang.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTLang.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTLang.CustomButton.TabIndex = 1; - this.TXTLang.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTLang.CustomButton.UseSelectable = true; - this.TXTLang.CustomButton.Visible = false; - this.TXTLang.Lines = new string[0]; - this.TXTLang.Location = new System.Drawing.Point(173, 212); - this.TXTLang.MaxLength = 32767; - this.TXTLang.Name = "TXTLang"; - this.TXTLang.PasswordChar = '\0'; - this.TXTLang.ReadOnly = true; - this.TXTLang.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTLang.SelectedText = ""; - this.TXTLang.SelectionLength = 0; - this.TXTLang.SelectionStart = 0; - this.TXTLang.ShortcutsEnabled = true; - this.TXTLang.Size = new System.Drawing.Size(138, 23); - this.TXTLang.TabIndex = 48; - this.TXTLang.UseSelectable = true; - this.TXTLang.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTLang.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // TXTNCProc - // - // - // - // - this.TXTNCProc.CustomButton.Image = null; - this.TXTNCProc.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTNCProc.CustomButton.Name = ""; - this.TXTNCProc.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTNCProc.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTNCProc.CustomButton.TabIndex = 1; - this.TXTNCProc.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTNCProc.CustomButton.UseSelectable = true; - this.TXTNCProc.CustomButton.Visible = false; - this.TXTNCProc.Lines = new string[0]; - this.TXTNCProc.Location = new System.Drawing.Point(173, 183); - this.TXTNCProc.MaxLength = 32767; - this.TXTNCProc.Name = "TXTNCProc"; - this.TXTNCProc.PasswordChar = '\0'; - this.TXTNCProc.ReadOnly = true; - this.TXTNCProc.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTNCProc.SelectedText = ""; - this.TXTNCProc.SelectionLength = 0; - this.TXTNCProc.SelectionStart = 0; - this.TXTNCProc.ShortcutsEnabled = true; - this.TXTNCProc.Size = new System.Drawing.Size(138, 23); - this.TXTNCProc.TabIndex = 47; - this.TXTNCProc.UseSelectable = true; - this.TXTNCProc.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTNCProc.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // TXTSftVers - // - // - // - // - this.TXTSftVers.CustomButton.Image = null; - this.TXTSftVers.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTSftVers.CustomButton.Name = ""; - this.TXTSftVers.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTSftVers.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTSftVers.CustomButton.TabIndex = 1; - this.TXTSftVers.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTSftVers.CustomButton.UseSelectable = true; - this.TXTSftVers.CustomButton.Visible = false; - this.TXTSftVers.Lines = new string[0]; - this.TXTSftVers.Location = new System.Drawing.Point(173, 154); - this.TXTSftVers.MaxLength = 32767; - this.TXTSftVers.Name = "TXTSftVers"; - this.TXTSftVers.PasswordChar = '\0'; - this.TXTSftVers.ReadOnly = true; - this.TXTSftVers.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTSftVers.SelectedText = ""; - this.TXTSftVers.SelectionLength = 0; - this.TXTSftVers.SelectionStart = 0; - this.TXTSftVers.ShortcutsEnabled = true; - this.TXTSftVers.Size = new System.Drawing.Size(138, 23); - this.TXTSftVers.TabIndex = 46; - this.TXTSftVers.UseSelectable = true; - this.TXTSftVers.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTSftVers.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // TXTCMSMach - // - // - // - // - this.TXTCMSMach.CustomButton.Image = null; - this.TXTCMSMach.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTCMSMach.CustomButton.Name = ""; - this.TXTCMSMach.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTCMSMach.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTCMSMach.CustomButton.TabIndex = 1; - this.TXTCMSMach.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTCMSMach.CustomButton.UseSelectable = true; - this.TXTCMSMach.CustomButton.Visible = false; - this.TXTCMSMach.Lines = new string[0]; - this.TXTCMSMach.Location = new System.Drawing.Point(173, 125); - this.TXTCMSMach.MaxLength = 32767; - this.TXTCMSMach.Name = "TXTCMSMach"; - this.TXTCMSMach.PasswordChar = '\0'; - this.TXTCMSMach.ReadOnly = true; - this.TXTCMSMach.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTCMSMach.SelectedText = ""; - this.TXTCMSMach.SelectionLength = 0; - this.TXTCMSMach.SelectionStart = 0; - this.TXTCMSMach.ShortcutsEnabled = true; - this.TXTCMSMach.Size = new System.Drawing.Size(138, 23); - this.TXTCMSMach.TabIndex = 45; - this.TXTCMSMach.UseSelectable = true; - this.TXTCMSMach.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTCMSMach.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // TXTNcSerial - // - // - // - // - this.TXTNcSerial.CustomButton.Image = null; - this.TXTNcSerial.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTNcSerial.CustomButton.Name = ""; - this.TXTNcSerial.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTNcSerial.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTNcSerial.CustomButton.TabIndex = 1; - this.TXTNcSerial.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTNcSerial.CustomButton.UseSelectable = true; - this.TXTNcSerial.CustomButton.Visible = false; - this.TXTNcSerial.Lines = new string[0]; - this.TXTNcSerial.Location = new System.Drawing.Point(173, 96); - this.TXTNcSerial.MaxLength = 32767; - this.TXTNcSerial.Name = "TXTNcSerial"; - this.TXTNcSerial.PasswordChar = '\0'; - this.TXTNcSerial.ReadOnly = true; - this.TXTNcSerial.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTNcSerial.SelectedText = ""; - this.TXTNcSerial.SelectionLength = 0; - this.TXTNcSerial.SelectionStart = 0; - this.TXTNcSerial.ShortcutsEnabled = true; - this.TXTNcSerial.Size = new System.Drawing.Size(138, 23); - this.TXTNcSerial.TabIndex = 44; - this.TXTNcSerial.UseSelectable = true; - this.TXTNcSerial.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTNcSerial.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // TXTName - // - // - // - // - this.TXTName.CustomButton.Image = null; - this.TXTName.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTName.CustomButton.Name = ""; - this.TXTName.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTName.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTName.CustomButton.TabIndex = 1; - this.TXTName.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTName.CustomButton.UseSelectable = true; - this.TXTName.CustomButton.Visible = false; - this.TXTName.Lines = new string[0]; - this.TXTName.Location = new System.Drawing.Point(173, 67); - this.TXTName.MaxLength = 32767; - this.TXTName.Name = "TXTName"; - this.TXTName.PasswordChar = '\0'; - this.TXTName.ReadOnly = true; - this.TXTName.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTName.SelectedText = ""; - this.TXTName.SelectionLength = 0; - this.TXTName.SelectionStart = 0; - this.TXTName.ShortcutsEnabled = true; - this.TXTName.Size = new System.Drawing.Size(138, 23); - this.TXTName.TabIndex = 43; - this.TXTName.UseSelectable = true; - this.TXTName.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTName.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // TXTType - // - // - // - // - this.TXTType.CustomButton.Image = null; - this.TXTType.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTType.CustomButton.Name = ""; - this.TXTType.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTType.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTType.CustomButton.TabIndex = 1; - this.TXTType.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTType.CustomButton.UseSelectable = true; - this.TXTType.CustomButton.Visible = false; - this.TXTType.Lines = new string[0]; - this.TXTType.Location = new System.Drawing.Point(173, 38); - this.TXTType.MaxLength = 32767; - this.TXTType.Name = "TXTType"; - this.TXTType.PasswordChar = '\0'; - this.TXTType.ReadOnly = true; - this.TXTType.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTType.SelectedText = ""; - this.TXTType.SelectionLength = 0; - this.TXTType.SelectionStart = 0; - this.TXTType.ShortcutsEnabled = true; - this.TXTType.Size = new System.Drawing.Size(138, 23); - this.TXTType.TabIndex = 42; - this.TXTType.UseSelectable = true; - this.TXTType.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTType.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // metroLabel8 - // - this.metroLabel8.AutoSize = true; - this.metroLabel8.Location = new System.Drawing.Point(103, 245); - this.metroLabel8.Name = "metroLabel8"; - this.metroLabel8.Size = new System.Drawing.Size(64, 19); - this.metroLabel8.TabIndex = 41; - this.metroLabel8.Text = "NC Time:"; - this.metroLabel8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // metroLabel7 - // - this.metroLabel7.AutoSize = true; - this.metroLabel7.Location = new System.Drawing.Point(75, 216); - this.metroLabel7.Name = "metroLabel7"; - this.metroLabel7.Size = new System.Drawing.Size(92, 19); - this.metroLabel7.TabIndex = 40; - this.metroLabel7.Text = "NC Language:"; - this.metroLabel7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // metroLabel6 - // - this.metroLabel6.AutoSize = true; - this.metroLabel6.Location = new System.Drawing.Point(85, 187); - this.metroLabel6.Name = "metroLabel6"; - this.metroLabel6.Size = new System.Drawing.Size(82, 19); - this.metroLabel6.TabIndex = 39; - this.metroLabel6.Text = "Processes N:"; - this.metroLabel6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // metroLabel5 - // - this.metroLabel5.AutoSize = true; - this.metroLabel5.Location = new System.Drawing.Point(34, 158); - this.metroLabel5.Name = "metroLabel5"; - this.metroLabel5.Size = new System.Drawing.Size(133, 19); - this.metroLabel5.TabIndex = 38; - this.metroLabel5.Text = "NC Software Version:"; - this.metroLabel5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // metroLabel4 - // - this.metroLabel4.AutoSize = true; - this.metroLabel4.Location = new System.Drawing.Point(62, 129); - this.metroLabel4.Name = "metroLabel4"; - this.metroLabel4.Size = new System.Drawing.Size(105, 19); - this.metroLabel4.TabIndex = 37; - this.metroLabel4.Text = "CMS Machine Id"; - this.metroLabel4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // metroLabel3 - // - this.metroLabel3.AutoSize = true; - this.metroLabel3.Location = new System.Drawing.Point(89, 100); - this.metroLabel3.Name = "metroLabel3"; - this.metroLabel3.Size = new System.Drawing.Size(78, 19); - this.metroLabel3.TabIndex = 36; - this.metroLabel3.Text = "Nc Serial N:"; - this.metroLabel3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // metroLabel2 - // - this.metroLabel2.AutoSize = true; - this.metroLabel2.Location = new System.Drawing.Point(117, 71); - this.metroLabel2.Name = "metroLabel2"; - this.metroLabel2.Size = new System.Drawing.Size(50, 19); - this.metroLabel2.TabIndex = 35; - this.metroLabel2.Text = "Model:"; - this.metroLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // metroLabel1 - // - this.metroLabel1.AutoSize = true; - this.metroLabel1.Location = new System.Drawing.Point(112, 42); - this.metroLabel1.Name = "metroLabel1"; - this.metroLabel1.Size = new System.Drawing.Size(55, 19); - this.metroLabel1.TabIndex = 34; - this.metroLabel1.Text = "Vendor:"; - this.metroLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // // ThreadsInfo // this.ThreadsInfo.Controls.Add(this.LISTThreadStatus); @@ -512,13 +125,13 @@ namespace Step.UI this.LISTThreadStatus.Font = new System.Drawing.Font("Segoe UI", 12F); this.LISTThreadStatus.FullRowSelect = true; this.LISTThreadStatus.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; - this.LISTThreadStatus.Location = new System.Drawing.Point(0, 3); + this.LISTThreadStatus.Location = new System.Drawing.Point(-4, 0); this.LISTThreadStatus.MultiSelect = false; this.LISTThreadStatus.Name = "LISTThreadStatus"; this.LISTThreadStatus.OwnerDraw = true; this.LISTThreadStatus.Scrollable = false; this.LISTThreadStatus.ShowGroups = false; - this.LISTThreadStatus.Size = new System.Drawing.Size(324, 288); + this.LISTThreadStatus.Size = new System.Drawing.Size(328, 275); this.LISTThreadStatus.TabIndex = 2; this.LISTThreadStatus.UseCompatibleStateImageBehavior = false; this.LISTThreadStatus.UseSelectable = true; @@ -539,7 +152,7 @@ namespace Step.UI // stopServerButton // this.stopServerButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.stopServerButton.Location = new System.Drawing.Point(234, 381); + this.stopServerButton.Location = new System.Drawing.Point(230, 371); this.stopServerButton.Name = "stopServerButton"; this.stopServerButton.Size = new System.Drawing.Size(106, 42); this.stopServerButton.TabIndex = 3; @@ -551,7 +164,7 @@ namespace Step.UI // TestJSButton // this.TestJSButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.TestJSButton.Location = new System.Drawing.Point(122, 381); + this.TestJSButton.Location = new System.Drawing.Point(118, 371); this.TestJSButton.Name = "TestJSButton"; this.TestJSButton.Size = new System.Drawing.Size(106, 42); this.TestJSButton.TabIndex = 2; @@ -568,9 +181,9 @@ namespace Step.UI // // this.TXTstatus.CustomButton.Image = null; - this.TXTstatus.CustomButton.Location = new System.Drawing.Point(334, 1); + this.TXTstatus.CustomButton.Location = new System.Drawing.Point(324, 2); this.TXTstatus.CustomButton.Name = ""; - this.TXTstatus.CustomButton.Size = new System.Drawing.Size(21, 21); + this.TXTstatus.CustomButton.Size = new System.Drawing.Size(25, 25); this.TXTstatus.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; this.TXTstatus.CustomButton.TabIndex = 1; this.TXTstatus.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; @@ -579,7 +192,7 @@ namespace Step.UI this.TXTstatus.Enabled = false; this.TXTstatus.Lines = new string[] { "..."}; - this.TXTstatus.Location = new System.Drawing.Point(-1, 434); + this.TXTstatus.Location = new System.Drawing.Point(-1, 427); this.TXTstatus.MaxLength = 32767; this.TXTstatus.Name = "TXTstatus"; this.TXTstatus.PasswordChar = '\0'; @@ -589,23 +202,56 @@ namespace Step.UI this.TXTstatus.SelectionLength = 0; this.TXTstatus.SelectionStart = 0; this.TXTstatus.ShortcutsEnabled = true; - this.TXTstatus.Size = new System.Drawing.Size(356, 23); + this.TXTstatus.Size = new System.Drawing.Size(352, 30); this.TXTstatus.TabIndex = 8; this.TXTstatus.Text = "..."; this.TXTstatus.UseSelectable = true; this.TXTstatus.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); this.TXTstatus.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); // + // TXTType + // + this.TXTType.AutoSize = true; + this.TXTType.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.TXTType.Location = new System.Drawing.Point(179, 348); + this.TXTType.Name = "TXTType"; + this.TXTType.Size = new System.Drawing.Size(51, 13); + this.TXTType.TabIndex = 53; + this.TXTType.Text = "NcType"; + // + // CHNcConnected + // + this.CHNcConnected.AutoCheck = false; + this.CHNcConnected.ForeColor = System.Drawing.SystemColors.ControlText; + this.CHNcConnected.Location = new System.Drawing.Point(246, 345); + this.CHNcConnected.Name = "CHNcConnected"; + this.CHNcConnected.Size = new System.Drawing.Size(81, 20); + this.CHNcConnected.TabIndex = 52; + this.CHNcConnected.Text = "Connected"; + this.CHNcConnected.UseSelectable = true; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(134, 348); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(44, 13); + this.label1.TabIndex = 54; + this.label1.Text = "Vendor:"; + // // ServerControlWindow // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(350, 457); + this.Controls.Add(this.label1); + this.Controls.Add(this.TXTType); + this.Controls.Add(this.CHNcConnected); this.Controls.Add(this.TXTstatus); + this.Controls.Add(this.TestJSButton); this.Controls.Add(this.stopServerButton); this.Controls.Add(this.metroTabControl1); this.Controls.Add(this.openUiButton); - this.Controls.Add(this.TestJSButton); this.ForeColor = System.Drawing.SystemColors.ControlText; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Margin = new System.Windows.Forms.Padding(2); @@ -618,10 +264,9 @@ namespace Step.UI this.Theme = MetroFramework.MetroThemeStyle.Default; this.NotifyIconMenu.ResumeLayout(false); this.metroTabControl1.ResumeLayout(false); - this.NCInfo.ResumeLayout(false); - this.NCInfo.PerformLayout(); this.ThreadsInfo.ResumeLayout(false); this.ResumeLayout(false); + this.PerformLayout(); } @@ -631,24 +276,6 @@ namespace Step.UI private System.Windows.Forms.ToolStripMenuItem StopServerItem; private MetroFramework.Controls.MetroButton openUiButton; private MetroFramework.Controls.MetroTabControl metroTabControl1; - private MetroFramework.Controls.MetroTabPage NCInfo; - private MetroFramework.Controls.MetroCheckBox CHNcConnected; - private MetroFramework.Controls.MetroTextBox TXTTime; - private MetroFramework.Controls.MetroTextBox TXTLang; - private MetroFramework.Controls.MetroTextBox TXTNCProc; - private MetroFramework.Controls.MetroTextBox TXTSftVers; - private MetroFramework.Controls.MetroTextBox TXTCMSMach; - private MetroFramework.Controls.MetroTextBox TXTNcSerial; - private MetroFramework.Controls.MetroTextBox TXTName; - private MetroFramework.Controls.MetroTextBox TXTType; - private MetroFramework.Controls.MetroLabel metroLabel8; - private MetroFramework.Controls.MetroLabel metroLabel7; - private MetroFramework.Controls.MetroLabel metroLabel6; - private MetroFramework.Controls.MetroLabel metroLabel5; - private MetroFramework.Controls.MetroLabel metroLabel4; - private MetroFramework.Controls.MetroLabel metroLabel3; - private MetroFramework.Controls.MetroLabel metroLabel2; - private MetroFramework.Controls.MetroLabel metroLabel1; private MetroFramework.Controls.MetroButton stopServerButton; private MetroFramework.Controls.MetroButton TestJSButton; private MetroFramework.Controls.MetroTabPage ThreadsInfo; @@ -656,5 +283,8 @@ namespace Step.UI private System.Windows.Forms.ColumnHeader columnHeader1; private System.Windows.Forms.ColumnHeader columnHeader2; private MetroFramework.Controls.MetroTextBox TXTstatus; + private Label TXTType; + private MetroFramework.Controls.MetroCheckBox CHNcConnected; + private Label label1; } } \ No newline at end of file diff --git a/Step.UI/ServerControlWindow.cs b/Step.UI/ServerControlWindow.cs index 08458d99..42bbf327 100644 --- a/Step.UI/ServerControlWindow.cs +++ b/Step.UI/ServerControlWindow.cs @@ -42,7 +42,7 @@ namespace Step.UI MessageServices.Current.Subscribe(SHOW_MSG_UI, (a, b) => { - this.Invoke((MethodInvoker)delegate () { this.Focus(); MessageBox.Show(a.ToString()); }); + Invoke((MethodInvoker)delegate () { Focus(); MessageBox.Show(a.ToString()); }); }); } @@ -139,122 +139,92 @@ namespace Step.UI private void InitializeMessageListeners() { - MVVMListeners = new List(); - MVVMListeners.Add(MessageServices.Current.Subscribe(SEND_MESSAGE, (a, b) => + MVVMListeners = new List { + MessageServices.Current.Subscribe(SEND_MESSAGE, (a, b) => + { // Cast object to ErrorMessageModel ErrorMessageModel message = (ErrorMessageModel)a; // If error has a fatal level, icon must be error message.ErrorLevel = message.ErrorLevel > (int)ERROR_LEVEL.ERROR ? (int)ERROR_LEVEL.ERROR : message.ErrorLevel; - if (!this.IsDisposed) - this.Invoke((MethodInvoker)delegate () - { + if (!this.IsDisposed) + this.Invoke((MethodInvoker)delegate () + { // Open BalloonTip with data StepNotifyIcon.ShowBalloonTip(1000, message.Title, message.Message, (ToolTipIcon)message.ErrorLevel); //ShowMessage on UI TXTstatus.Text = "[" + DateTime.Now.ToString("T") + "] " + message.Message; - }); - })); - - MVVMListeners.Add(MessageServices.Current.Subscribe(SEND_NC_STATUS, (a, b) => - { - bool newNcStatus = (bool)a; - - if (ncStatus != newNcStatus) + }); + }), + // NC status handler + MessageServices.Current.Subscribe(SEND_NC_STATUS, (a, b) => { - ncStatus = newNcStatus; - string title = "NC not connected"; - string message = "Check NC connection"; - ToolTipIcon toolTipIcon = ToolTipIcon.Error; + bool newNcStatus = (bool)a; - if (ncStatus == true) + if (ncStatus != newNcStatus) { - title = "Nc connection established"; - message = "Comunication started"; - toolTipIcon = ToolTipIcon.Info; - } + ncStatus = newNcStatus; + string title = "NC not connected"; + string message = "Check NC connection"; + ToolTipIcon toolTipIcon = ToolTipIcon.Error; - if (!this.IsDisposed) - this.Invoke((MethodInvoker)delegate () + if (ncStatus) { - StepNotifyIcon.ShowBalloonTip(1000, title, message, toolTipIcon); - TXTstatus.Text = "[" + DateTime.Now.ToString("T") + "] " + title; - }); - } + title = "Nc connection established"; + message = "Comunication started"; + toolTipIcon = ToolTipIcon.Info; + } - if (ncStatus) - if (!this.IsDisposed) - this.Invoke((MethodInvoker)delegate () - { - StepNotifyIcon.Icon = Properties.Resources.Step_Icon; - }); - else - { - if (!this.IsDisposed) - this.Invoke((MethodInvoker)delegate () + if (!IsDisposed) + Invoke((MethodInvoker)delegate () { - TXTName.Text = ""; - TXTNcSerial.Text = ""; - TXTCMSMach.Text = ""; - TXTSftVers.Text = ""; - TXTNCProc.Text = ""; - TXTTime.Text = ""; - TXTLang.Text = ""; - StepNotifyIcon.Icon = Properties.Resources.Step_Disconnected; + // Show balloon with new status + StepNotifyIcon.ShowBalloonTip(1000, title, message, toolTipIcon); + TXTstatus.Text = "[" + DateTime.Now.ToString("T") + "] " + title; }); } - //Other type - if (!this.IsDisposed) - this.Invoke((MethodInvoker)delegate () - { - CHNcConnected.Checked = ncStatus; - }); - })); + if (ncStatus) + if (!IsDisposed) + Invoke((MethodInvoker)delegate () + { + StepNotifyIcon.Icon = Properties.Resources.Step_Icon; + }); - MVVMListeners.Add(MessageServices.Current.Subscribe(SEND_THREADS_STATUS, (a, b) => - { //Other type - if (!this.IsDisposed) - this.Invoke((MethodInvoker)delegate () - { - if (!isUpdatingThreads) + if (!IsDisposed) + Invoke((MethodInvoker)delegate () { - isUpdatingThreads = true; - Dictionary Threads = new Dictionary((Dictionary)a); + CHNcConnected.Checked = ncStatus; + }); + }), + // Threads status handler + MessageServices.Current.Subscribe(SEND_THREADS_STATUS, (a, b) => + { + //Other type + if (!IsDisposed) + Invoke((MethodInvoker)delegate () + { + if (!isUpdatingThreads) + { + isUpdatingThreads = true; + Dictionary Threads = new Dictionary((Dictionary)a); //Begin the update LISTThreadStatus.BeginUpdate(); //clear the List LISTThreadStatus.Items.Clear(); //Add all items foreach (KeyValuePair Thr in Threads) - LISTThreadStatus.Items.Add(new ListViewItem(new string[] { Thr.Key, Thr.Value })); + LISTThreadStatus.Items.Add(new ListViewItem(new string[] { Thr.Key, Thr.Value })); //End the update LISTThreadStatus.EndUpdate(); - isUpdatingThreads = false; - } - }); - })); - - MVVMListeners.Add(MessageServices.Current.Subscribe(SEND_GENERIC_DATA, (a, b) => - { - DTONcGenericDataModel data = (DTONcGenericDataModel)a; - - //Other type - if (!this.IsDisposed) - this.Invoke((MethodInvoker)delegate () - { - TXTName.Text = data.NcModel; - TXTNcSerial.Text = data.SerialNumber; - TXTCMSMach.Text = data.CmsMachineIdNumber; - TXTSftVers.Text = data.NcSoftwareVersion; - TXTNCProc.Text = data.ProcessNumber.ToString(); - TXTLang.Text = data.Language; - TXTTime.Text = data.DateTime.ToShortDateString() + " " + data.DateTime.ToShortTimeString(); - }); - })); + isUpdatingThreads = false; + } + }); + }) + }; } } } \ No newline at end of file diff --git a/Step.Utils/supportFunctions.cs b/Step.Utils/supportFunctions.cs index 08613588..bc4477fc 100644 --- a/Step.Utils/supportFunctions.cs +++ b/Step.Utils/supportFunctions.cs @@ -1,4 +1,5 @@ -using static Step.Model.Constants; +using System.Reflection; +using static Step.Model.Constants; namespace Step.Utils { @@ -21,7 +22,6 @@ namespace Step.Utils case "SPINDLE": return HEAD_TYPE.SPINDLE; case "AWJ": return HEAD_TYPE.AWJ; default: return HEAD_TYPE.WJ; - } } @@ -66,16 +66,39 @@ namespace Step.Utils switch (unit) { case MAINTENANCE_UNIT_OF_MEASURE.mm: - return number; + return number; + case MAINTENANCE_UNIT_OF_MEASURE.H: - return number * 60; + return number * 60; + case MAINTENANCE_UNIT_OF_MEASURE.D: - return number * (24 * 60); + return number * (24 * 60); + case MAINTENANCE_UNIT_OF_MEASURE.M: - return (30 * number) * (24 * 60); + return (30 * number) * (24 * 60); + default: - return number; + return number; + } + } + + public static void CopyProperties(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; + } + } } } } -} + +} \ No newline at end of file diff --git a/Step/Controllers/WebApi/NcToolManagerController.cs b/Step/Controllers/WebApi/NcToolManagerController.cs new file mode 100644 index 00000000..4ddfd1cc --- /dev/null +++ b/Step/Controllers/WebApi/NcToolManagerController.cs @@ -0,0 +1,575 @@ +using Step.Database.Controllers; +using Step.Model.DatabaseModels; +using Step.Model.DTOModels.ToolModels; +using Step.NC; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Web.Http; +using static CMS_CORE_Library.DataStructures; +using static Step.Config.ServerConfig; +using static Step.Model.Constants; + +namespace Step.Controllers.WebApi +{ + [RoutePrefix("api/tool_manager/nc")] + public class NcToolManagerApiController : ApiController + { + #region Tools + + [Route("tools"), HttpGet] + public IHttpActionResult GetNcToolTable() + { + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + CmsError cmsError = ncHandler.GetToolsData(out List tools); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(tools); + } + } + + [Route("tool"), HttpPost] + public IHttpActionResult AddTool([FromBody][Required]DTONewNcToolModel dtoTool) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + // Check if family exists + DbNcFamilyModel fam = toolsManager.FindFamily(dtoTool.FamilyId); + if (fam == null) + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + + // If option is active check if shank exists + if (ToolManagerConfig.ShankOptIsActive) + { + DbNcShankModel shank = toolsManager.FindShankWithTools(dtoTool.ShankId.Value); + if (shank == null) + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + } + else + { + // If option is not active create a shank + DTONewNcShankModel newShank = new DTONewNcShankModel() + { + Balluf = 0, + MagazinePositionType = 0 + }; + + // Create a new shank + DbNcShankModel ncShank = toolsManager.AddShank(newShank); + // Connect tool to new shank + dtoTool.ShankId = ncShank.ShankId; + } + } + + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + + // Add tool + DTONcToolModel newTool = ncHandler.AddTool(dtoTool); + + return Ok(newTool); + } + } + + [Route("tool/{toolId:int}"), HttpPut] + public IHttpActionResult PutTool(int toolId, [FromBody][Required]DTONewNcToolModel dtoTool) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + DbNcToolModel tool = null; + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + // Check if tool exists + tool = toolsManager.FindTool(toolId); + if (tool == null) + return NotFound(); + + if (tool.FamilyId != dtoTool.FamilyId) + { + // Check if family exists + DbNcFamilyModel fam = toolsManager.FindFamily(dtoTool.FamilyId); + if (fam == null) + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + } + + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + // Update + CmsError cmsError = ncHandler.UpdateTool(toolId, dtoTool, out DTONcToolModel newTool); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(newTool); + } + } + } + + [Route("tool/{toolId:int}"), HttpDelete] + public IHttpActionResult DeleteTool(int toolId) + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + DbNcToolModel tool = toolsManager.FindTool(toolId); + if (tool == null) + return NotFound(); + + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + + if (!ToolManagerConfig.ShankOptIsActive && tool.ShankId != null) + { + // If option is active find & delete tool shank + DbNcShankModel shank = toolsManager.FindShankWithTools(tool.ShankId.Value); + + CmsError cmsError = ncHandler.DeleteNcShank(shank.ShankId); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + } + + ncHandler.DeleteNcTool(tool); + + return Ok(); + } + } + } + + #endregion Tools + + #region Shanks + + [Route("shanks"), HttpGet] + public IHttpActionResult GetShanks() + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + return Ok(toolsManager.GetShanks()); + } + } + + [Route("shank"), HttpPost] + public IHttpActionResult AddShank([FromBody][Required] DTONewNcShankModel dtoShank) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + if (!ToolManagerConfig.ShankOptIsActive) + return BadRequest(API_ERROR_KEYS.OPTION_NOT_ACTIVE); + + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + DTONcShankModel shank = (DTONcShankModel)toolsManager.AddShank(dtoShank); + + return Ok(shank); + } + } + + [Route("shank/{shankId:int}"), HttpPut] + public IHttpActionResult PutShank(int shankId, [FromBody][Required]DTONewNcShankModel dtoShank) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + // Check if shank exists + DbNcShankModel shank = toolsManager.FindShankWithTools(shankId); + if (shank == null) + return NotFound(); + + using (NcHandler ncHandler = new NcHandler()) + { + CmsError cmsError = ncHandler.Connect(); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + // Update shank + cmsError = ncHandler.UpdateShank(shankId, dtoShank, out DTONcShankModel newShank); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(newShank); + } + } + } + + [Route("shank/{shankId:int}"), HttpDelete] + public IHttpActionResult DeleteShank(int shankId) + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + // Check if shank exists + DbNcShankModel shank = toolsManager.FindShankWithTools(shankId); + if (shank == null) + return NotFound(); + + using (NcHandler ncHandler = new NcHandler()) + { + CmsError cmsError = ncHandler.Connect(); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + cmsError = ncHandler.DeleteNcShank(shank.ShankId); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(); + } + } + } + + #endregion Shanks + + #region Families + + [Route("family"), HttpPost] + public IHttpActionResult AddFamily([FromBody][Required]DTONewNcFamilyModel dtoFamily) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + using (NcHandler ncHandler = new NcHandler()) + { + CmsError cmsError = ncHandler.Connect(); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + DTONcFamilyModel newFamily = ncHandler.AddFamily(dtoFamily); + + return Ok(newFamily); + } + } + + [Route("families"), HttpGet] + public IHttpActionResult GetFamilies() + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + List families = toolsManager.GetFamilies(); + + return Ok(families); + } + } + + [Route("family/{familyId:int}"), HttpPut] + public IHttpActionResult PutFamily(int familyId, [FromBody][Required]DTONewNcFamilyModel dtoFamily) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + // Check if family exists + DbNcFamilyModel family = toolsManager.FindFamily(familyId); + if (family == null) + return NotFound(); + + using (NcHandler ncHandler = new NcHandler()) + { + CmsError cmsError = ncHandler.Connect(); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + // Update into db and NC + cmsError = ncHandler.UpdateFamily(familyId, dtoFamily, out DTONcFamilyModel newFamily); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(newFamily); + } + } + } + + [Route("family/{familyId:int}"), HttpDelete] + public IHttpActionResult DeleteFamily(int familyId) + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + // Find if exists + DbNcFamilyModel family = toolsManager.FindFamily(familyId); + if (family == null) + return NotFound(); + + using (NcHandler ncHandler = new NcHandler()) + { + CmsError cmsError = ncHandler.Connect(); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + //Delete + cmsError = ncHandler.DeleteNcFamily(family); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(); + } + } + } + + #endregion Families + + #region Magazine positions + + [Route("magazines_positions"), HttpGet] + public IHttpActionResult GetMagazinesPositions() + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + List magazines = toolsManager.FindMagazinesPositions(); + + return Ok(magazines); + } + } + + [Route("magazine/{magazineId:int}/positions"), HttpGet] + public IHttpActionResult GetMagazinesPositions(byte magazineId) + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + List magazine = toolsManager.GetMagazinePositions(magazineId); + + return Ok(magazine); + } + } + + [Route("magazine/{magazineId}/position/{positionId}"), HttpPut] + public IHttpActionResult PutMagazinePosition([Required]byte magazineId, [Required]byte positionId, [FromBody]DTONcMagazinePositionModel dtoPos) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + // Check if magazine&position exists + DbNcMagazinePositionModel pos = toolsManager.FindMagazinePosition(magazineId, positionId); + if (pos == null) + return NotFound(); + + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + CmsError cmsError = ncHandler.UpdateMagazinePosition(pos, dtoPos, out DTONcMagazinePositionModel newPos); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(newPos); + } + } + } + + #endregion Magazine positions + + [Route("magazine/{magazineId:int}/mounted_shanks"), HttpGet] + public IHttpActionResult GetMagazineTools(byte magazineId) + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + // Check if magazine exists + List pos = toolsManager.FindMagazinePositions(magazineId); + if (pos.Count <= 0) + return NotFound(); + + List mountedShank = toolsManager.GetMountedShanks(magazineId); + + return Ok(mountedShank); + } + } + + [Route("magazine/available_shanks"), HttpGet] + public IHttpActionResult GetAvailableTools() + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + List shanks = toolsManager.GetAvailableShanks(); + + return Ok(shanks); + } + } + + [Route("magazine/{magazineId:int}/load/position/{positionId:int}"), HttpPut] + public IHttpActionResult LoadToolInToMagazine(byte magazineId, byte positionId, [FromBody][Required] DTOUpdateMagazineModel shankId) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + if (shankId.ToolId == 0) + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + + // Check data + DbNcShankModel shank; + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + // Check if shank exists + shank = toolsManager.FindShankWithTools(shankId.ToolId); + if (shank == null) + + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + // Check if shank is already loaded somewhere + if (shank.MagazineId != null) + return BadRequest(API_ERROR_KEYS.TOOL_IS_MOUNTED); + + // Check if magazine position exists + DbNcMagazinePositionModel magPos = toolsManager.FindMagazinePosition(magazineId, positionId); + if (magPos == null) + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + // Check if the mag pos is disabled + if (magPos.Disabled == true) + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + + using (NcHandler ncHandler = new NcHandler()) + { + // Get Configuration + ncHandler.Connect(); + + // Check if shank can fit + CmsError cmsError = ncHandler.CheckIfShankCanFit( + magazineId, + positionId, + shank // Get mounted tools + ); + + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + } + + // Update shank data + DTONcMagazinePositionModel magazinePos = (DTONcMagazinePositionModel)toolsManager.LoadShankInMagazine(magazineId, positionId, shank); + // Set shankId + magazinePos.ShankId = shank.ShankId; + + return Ok(magazinePos); + } + } + + [Route("magazine/{magazineId:int}/unload/position/{positionId:int}"), HttpPut] + public IHttpActionResult UnloadToolInToMagazine(byte magazineId, byte positionId, [FromBody][Required] DTOUpdateMagazineModel shankId) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + if (shankId.ToolId == 0) + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + + // Check data + DbNcShankModel shank; + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + // Check if shank exists + shank = toolsManager.FindShankWithTools(shankId.ToolId); + if (shank == null) + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + + // Check if magazine position exists + DbNcMagazinePositionModel magPos = toolsManager.FindMagazinePosition(magazineId, positionId); + if (magPos == null) + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + // Check if the mag pos is disabled + if (magPos.Disabled == true) + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + + // Check if magazine position is not occupied + DbNcShankModel shankMounted = toolsManager.FindShanksByPositions(magazineId, positionId); + if (shankMounted == null) + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + + DTONcMagazinePositionModel magazinePos = (DTONcMagazinePositionModel)toolsManager.UnloadShankInMagazine(magazineId, positionId, shank); + + return Ok(magazinePos); + } + } + + [Route("shank/{shankId:int}/load/tool/{toolId:int}"), HttpPut] + public IHttpActionResult LoadToolIntoShank(int shankId, int toolId) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + DbNcToolModel tool; + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + // Check if shank exists + DbNcShankModel shank = toolsManager.FindShankWithTools(shankId); + if (shank == null) + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + + tool = toolsManager.FindTool(toolId); + if (tool == null) + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + } + + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + + DTONcShankModel shank = ncHandler.LoadIntoShank(tool, shankId); + + return Ok(shank); + } + } + + [Route("shank/{shankId:int}/unload/tool/{toolId:int}"), HttpPut] + public IHttpActionResult UnloadToolIntoShank(int shankId, int toolId) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + DbNcToolModel tool; + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + // Check if shank exists + DbNcShankModel shank = toolsManager.FindShankWithTools(shankId); + if (shank == null) + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + + tool = toolsManager.FindTool(toolId); + if (tool == null) + return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + } + + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + + DTONcShankModel shank = ncHandler.UnloadFromShank(tool); + + return Ok(shank); + } + } + + [Route("start_edit_tooling/{magazineId:int}"), HttpPut] + public IHttpActionResult StartEditTooling(int magazineId) + { + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + + CmsError cmsError = ncHandler.StartEditTooling(magazineId); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(); + } + } + + [Route("stop_edit_tooling/{magazineId:int}"), HttpPut] + public IHttpActionResult StopEditTooling(int magazineId) + { + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + + CmsError cmsError = ncHandler.StopEditTooling(magazineId); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(); + } + } + } +} \ No newline at end of file diff --git a/Step/Controllers/WebApi/ToolTableController.cs b/Step/Controllers/WebApi/SiemensToolManagerController.cs similarity index 98% rename from Step/Controllers/WebApi/ToolTableController.cs rename to Step/Controllers/WebApi/SiemensToolManagerController.cs index 1f2b83de..48ab4e19 100644 --- a/Step/Controllers/WebApi/ToolTableController.cs +++ b/Step/Controllers/WebApi/SiemensToolManagerController.cs @@ -1,4 +1,5 @@ -using Step.Model.DTOModels.ToolModels; +using Step.Model.DatabaseModels; +using Step.Model.DTOModels.ToolModels; using Step.NC; using System; using System.Collections.Generic; @@ -10,7 +11,7 @@ using static CMS_CORE_Library.DataStructures; namespace Step.Controllers.WebApi { [RoutePrefix("api/tool_manager")] - public class ToolTableController : ApiController + public class SiemensToolManagerController : ApiController { [Route("tools"), HttpGet] public IHttpActionResult GetToolTable() @@ -416,7 +417,7 @@ namespace Step.Controllers.WebApi } [Route("shank/{shankId:int}/load/{positionId:int}/tool/{toolId:int}"), HttpPut] - public IHttpActionResult LoadToolFromShank(int shankId, int positionId, int toolId) + public IHttpActionResult LoadToolIntoShank(int shankId, int positionId, int toolId) { if (!ModelState.IsValid) return BadRequest(ModelState); diff --git a/Step/Listeners/Database/DatabaseTest.cs b/Step/Listeners/Database/DatabaseTest.cs deleted file mode 100644 index fcc94ec1..00000000 --- a/Step/Listeners/Database/DatabaseTest.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using Step.Database.Controllers; -using TeamDev.SDK.MVVM; - -namespace Step.Listeners.Database -{ - public static class DatabaseTest - { - public static void DbTest(string taskName) - { - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - using (UsersController usersController = new UsersController()) - { - //user.Create("test", "nuova", "nome", "last", 1, "italian"); - Console.WriteLine("DB scritto " + taskName + " Thread:" + Thread.CurrentThread.ManagedThreadId + " " + stopwatch.ElapsedMilliseconds); - } - } - } -} diff --git a/Step/Listeners/Database/SignalRDatabaseHandler.cs b/Step/Listeners/Database/SignalRDatabaseHandler.cs new file mode 100644 index 00000000..3af9cec9 --- /dev/null +++ b/Step/Listeners/Database/SignalRDatabaseHandler.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Step.Database.Controllers; +using Step.Model.DatabaseModels; +using Step.Model.DTOModels; +using Step.Model.DTOModels.ToolModels; +using Step.NC; +using TeamDev.SDK.MVVM; + +namespace Step.Listeners.Database +{ + public static class SignalRDatabaseHandler + { + public static void UpdateToolsData(object newData) + { + using (NcToolManagerController controller = new NcToolManagerController()) + { + // Convert input parameter + DTONewToolDataModel data = newData as DTONewToolDataModel; + + List updatedTools = new List(); + // Check if there are new data + if (data.UpdatedLives.Count != 0 || data.UpdatedStatus.Count != 0) + { + List dbTools = controller.FindTools(); + if(dbTools.Count > 0) + { + // Loop through new data + foreach (var live in data.UpdatedLives) + { + // Find tool and update residual life + var tmp = dbTools + .Where(x => x.ToolId == live.Key) // Get tool by id + ?.Select(x => { + x.ResidualLife = (int)live.Value; // Update data + return x; + }) + .FirstOrDefault(); + + if(tmp != null) + updatedTools.Add(tmp); + } + + foreach (var status in data.UpdatedStatus) + { + var tmp = dbTools + .Where(x => x.ToolId == status.Key) // Get tool by id + ?.Select(x => { + x.Status = status.Value; + return x; + }) + .FirstOrDefault(); + + if (tmp != null) + updatedTools.Add(tmp); + } + } + + // Update database + controller.UpdateToolsData(updatedTools); + + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + // Update nc data + ncHandler.UpdateNcTools(controller); + } + } + } + } + } +} diff --git a/Step/Listeners/ListenersHandler.cs b/Step/Listeners/ListenersHandler.cs index 94b7044b..2396565b 100644 --- a/Step/Listeners/ListenersHandler.cs +++ b/Step/Listeners/ListenersHandler.cs @@ -19,67 +19,71 @@ namespace Step.Listeners public static void Start() { - infos.Add(MessageServices.Current.Subscribe(SEND_ALARMS, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_ALARMS, (a, b) => { SignalRListener.SendAlarmsToClient(a as DTOAlarmsModel); })); - infos.Add(MessageServices.Current.Subscribe(SEND_POWER_ON_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_POWER_ON_DATA, (a, b) => { SignalRListener.SendPowerOnDataToClient(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_NC_STATUS, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_NC_STATUS, (a, b) => { SignalRListener.SendNcNetworkStatus(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_PROCESSES_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_PROCESSES_DATA, (a, b) => { SignalRListener.SendProcessesData(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_FUNCTIONALITY_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_FUNCTIONALITY_DATA, (a, b) => { SignalRListener.SendFunctionalityData(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_EXPIRED_MAINTENANCES_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_EXPIRED_MAINTENANCES_DATA, (a, b) => { SignalRListener.SendExpMaintenancesData(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_NC_SOFTKEYS_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_NC_SOFTKEYS_DATA, (a, b) => { SignalRListener.SendNcSoftKeysData(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_USER_SOFTKEYS_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_USER_SOFTKEYS_DATA, (a, b) => { SignalRListener.SendUserSoftKeysData(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_HEADS_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_HEADS_DATA, (a, b) => { SignalRListener.SendHeadsData(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_AXIS_NAMES_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_AXIS_NAMES_DATA, (a, b) => { SignalRListener.SendAxesNamesData(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_AXES, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_AXES, (a, b) => { SignalRListener.SendAxesToClient(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_MAGAZINES_STATUS, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_MAGAZINES_STATUS, (a, b) => { SignalRListener.SendMagazinesStatus(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_ACTIVE_PROGRAM_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_ACTIVE_PROGRAM_DATA, (a, b) => { SignalRListener.SendActiveProgramData(a); })); - infos.Add(MessageServices.Current.Subscribe(BROADCAST_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(BROADCAST_DATA, (a, b) => { SignalRListener.BroadcastData(); })); + infos.Add(MessageServices.Current.Subscribe(UPDATE_TOOLS_DATA, (a, b) => + { + SignalRDatabaseHandler.UpdateToolsData(a); + })); } public static void Stop() diff --git a/Step/Step.csproj b/Step/Step.csproj index 66139d96..b3fa6304 100644 --- a/Step/Step.csproj +++ b/Step/Step.csproj @@ -172,14 +172,13 @@ - - - + + - + diff --git a/Step/program.cs b/Step/program.cs index 28b115fa..225097d5 100644 --- a/Step/program.cs +++ b/Step/program.cs @@ -1,26 +1,26 @@ using Microsoft.Owin.Hosting; -using Step.UI; -using System.Threading; -using TeamDev.SDK.MVVM; using Step.Config; -using static Step.Config.ServerConfig; -using static Step.Utils.StepLogger; -using static Step.Model.Constants; -using Step.Database; using Step.Core; +using Step.Database; using Step.Listeners; -using System; +using Step.NC; +using Step.UI; using Step.Utils; -using System.Net.NetworkInformation; +using System; using System.Net; using System.Net.Sockets; +using System.Threading; +using TeamDev.SDK.MVVM; +using static Step.Config.ServerConfig; +using static Step.Model.Constants; +using static Step.Utils.StepLogger; namespace Step { public class Application { - public static readonly ManualResetEvent StopRequest = new ManualResetEvent(false); + //Set the Mutef of GUID private static Mutex CmsStepMutex = new Mutex(true, "{689e76ce-b845-49f0-919c-c26491079fca}"); @@ -29,7 +29,7 @@ namespace Step public static void Main() { LogInfo("Application started"); - + //Check if is already running an instance of this application if (!CmsStepMutex.WaitOne(TimeSpan.Zero, true)) ExceptionManager.Manage(ERROR_LEVEL.FATAL, "Only one istance of Step-Server can be executed!"); @@ -41,7 +41,7 @@ namespace Step ServerConfigController.ReadStartupConfig(); DatabaseContext.SetUpDbConnectionAndDbConfig(); - + // Register listener to "close application" messages MessageServices.Current.Subscribe(SEND_STOP_SERVER, (a, b) => { @@ -50,20 +50,26 @@ namespace Step ThreadSiemensHmi.StopWindow(); }); + // Setup Osai/fanuc toolManager + using (NcHandler handler = new NcHandler()) + { + handler.Connect(); + handler.SetupNcToolManager(); + } + // Start server services - if(!ValidateAddress(ServerStartupConfig.ServerAddress)) + if (!ValidateAddress(ServerStartupConfig.ServerAddress)) ExceptionManager.Manage(ERROR_LEVEL.FATAL, "IP Address not valid (must be one configured in Windows-OS)!"); StartOptions opt = new StartOptions(); opt.Urls.Add("http://localhost:" + ServerStartupConfig.ServerPort.ToString()); opt.Urls.Add("http://127.0.0.1:" + ServerStartupConfig.ServerPort.ToString()); - if (!String.IsNullOrWhiteSpace(ServerStartupConfig.ServerAddress.ToString())) + if (!string.IsNullOrWhiteSpace(ServerStartupConfig.ServerAddress.ToString())) opt.Urls.Add("http://" + ServerStartupConfig.ServerAddress.ToString() + ":" + ServerStartupConfig.ServerPort.ToString()); - using (WebApp.Start(opt)) + using (WebApp.Start(opt)) { - // Start Threads ThreadsHandler.Start(); // Start listeners @@ -71,8 +77,9 @@ namespace Step // Wait interrupt from client StopRequest.WaitOne(); - LogInfo("Application closed"); + LogInfo("Application closed"); } + // Stop Threads ThreadsHandler.Close(); // Stop messageservice listeners @@ -81,11 +88,12 @@ namespace Step ServerControlWindow.Stop(); } - private static Boolean ValidateAddress(String Addr) { + private static bool ValidateAddress(String Addr) + { //If is an asterisk is OK if (String.IsNullOrWhiteSpace(Addr) || Addr == "*") return true; - + //Find an IP Address foreach (IPAddress ipAddr in Array.FindAll(Dns.GetHostEntry(string.Empty).AddressList, a => a.AddressFamily == AddressFamily.InterNetwork)) { @@ -96,4 +104,4 @@ namespace Step return false; } } -} +} \ No newline at end of file