From d35273d3e5044169b10676c1325fd449f97f2bdc Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Wed, 3 Apr 2019 17:14:28 +0200 Subject: [PATCH] Added block on tool cancellation when is mounted in magazine & Fixes --- Step.Core/ThreadsFunctions.cs | 6 +- .../Controllers/NcToolManagerController.cs | 11 +- Step.NC/NcToolTableHandler.cs | 20 +- .../WebApi/NcToolManagerController.cs | 316 +++++++++--------- .../tooling/components/tooling-equipment.ts | 16 + .../tooling/components/tooling-equipment.vue | 2 +- .../tooling/components/tooling-families.ts | 21 +- .../tooling/components/tooling-families.vue | 6 +- 8 files changed, 227 insertions(+), 171 deletions(-) diff --git a/Step.Core/ThreadsFunctions.cs b/Step.Core/ThreadsFunctions.cs index b77fa1e3..79e40d05 100644 --- a/Step.Core/ThreadsFunctions.cs +++ b/Step.Core/ThreadsFunctions.cs @@ -1024,12 +1024,8 @@ public static class ThreadsFunctions Manage(ERROR_LEVEL.FATAL, cmsError.localizationKey); break; case CMS_ERROR_CODES.SELECTED_PROCESS: - - Manage(ERROR_LEVEL.FATAL, cmsError.localizationKey); + Manage(ERROR_LEVEL.WARNING, cmsError.localizationKey); break; - //default: - // Manage(ERROR_LEVEL.WARNING, cmsError.localizationKey); - // break; } } diff --git a/Step.Database/Controllers/NcToolManagerController.cs b/Step.Database/Controllers/NcToolManagerController.cs index 42481e32..55828a17 100644 --- a/Step.Database/Controllers/NcToolManagerController.cs +++ b/Step.Database/Controllers/NcToolManagerController.cs @@ -62,7 +62,16 @@ namespace Step.Database.Controllers .FirstOrDefault(); } - public DbNcShankModel FindShankWithTools(int shankId) + public DbNcToolModel FindToolWithDependencies(int toolId) + { + return dbCtx.Tools + .Where(x => x.ToolId == toolId) + .Include("Family") + .Include("Shank") + .FirstOrDefault(); + } + + public DbNcShankModel FindShankWithTools(int shankId) { return dbCtx.Shanks .Include("Tools") diff --git a/Step.NC/NcToolTableHandler.cs b/Step.NC/NcToolTableHandler.cs index cb3a9010..26dd5330 100644 --- a/Step.NC/NcToolTableHandler.cs +++ b/Step.NC/NcToolTableHandler.cs @@ -105,7 +105,7 @@ namespace Step.NC { using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) { - // If option is active + // If family option is not active, update family data if (!ToolManagerConfig.FamilyOpt) { // Copy only family @@ -113,11 +113,6 @@ namespace Step.NC SupportFunctions.CopyProperties(dtoToolWithFamily, newFamily); // Update only family data newFamily = (DTONcFamilyModel)toolsManager.UpdateFamily(dtoToolWithFamily.FamilyId, newFamily); - - // Update Nc families - cmsError = UpdateNcFamily(toolsManager); - if (cmsError.IsError()) - ManageErrorAndTransaction(cmsError, dbContextTransaction, true); } // Update database tool Tool @@ -125,7 +120,7 @@ namespace Step.NC // Populate updated tool with offset data cmsError = GetToolData(dbTool, ref toolWithOffsets); - if (cmsError.IsError()) + if (cmsError.IsError()) { dbContextTransaction.Rollback(); return cmsError; @@ -141,7 +136,7 @@ namespace Step.NC if (shank.MagazineId != null) { startIsActive = true; - // Create backup of data stored on the NC and block file accesses + // Create backup of data stored on the NC and block memory/files accesses cmsError = numericalControl.TOOLS_WStartEditData(); if (cmsError.IsError()) { @@ -149,6 +144,15 @@ namespace Step.NC return cmsError; } + // If family option is not active, update NC data + if (!ToolManagerConfig.FamilyOpt) + { + // Update Nc families + cmsError = UpdateNcFamily(toolsManager); + if (cmsError.IsError()) + ManageErrorAndTransaction(cmsError, dbContextTransaction, true); + } + // Update tool cmsError = UpdateNcTools(toolsManager); } diff --git a/Step/Controllers/WebApi/NcToolManagerController.cs b/Step/Controllers/WebApi/NcToolManagerController.cs index 91a4c570..b8274387 100644 --- a/Step/Controllers/WebApi/NcToolManagerController.cs +++ b/Step/Controllers/WebApi/NcToolManagerController.cs @@ -62,101 +62,7 @@ namespace Step.Controllers.WebApi } } } - - //[Route("tool_old"), HttpPost] - //public IHttpActionResult AddTool([FromBody][Required]DTONewNcToolWithFamilyModel dtoToolWithFamily) - //{ - // if (!ModelState.IsValid) - // return BadRequest(ModelState); - - // short familyId = 0; - // using (NcToolManagerController toolsManager = new NcToolManagerController()) - // { - // // Check if option is active - // if (ToolManagerConfig.FamilyOpt) - // { - // if (dtoToolWithFamily.FamilyId == 0) - // { - // // If param equal to 0 create a new family - // DTONcFamilyModel newFamily = new DTONcFamilyModel() { Name = "NewFamily", LeftSize = 1, RightSize = 1 }; - // // Add new family & update family id - // DbNcFamilyModel newFam = toolsManager.AddFamily(newFamily); - // dtoToolWithFamily.FamilyId = newFam.FamilyId; - // dtoToolWithFamily.Name = newFam.Name; - // } - // else - // { - // // Check if family exists - // DbNcFamilyModel fam = toolsManager.FindFamily(dtoToolWithFamily.FamilyId); - // if (fam == null) - // return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); - - // // Update return data - // if (ToolManagerConfig.FamilyOpt) - // { - // dtoToolWithFamily.Name = fam.Name; - // } - // } - // } - // else - // { - // // Copy only family data from tool&fam model - // DTONcFamilyModel newFamily = new DTONcFamilyModel(); - // SupportFunctions.CopyProperties(dtoToolWithFamily, newFamily); - - // // Add new family - // DbNcFamilyModel dbFam = toolsManager.AddFamily(newFamily); - // if (dbFam == null) - // return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); - // dtoToolWithFamily.FamilyId = dbFam.FamilyId; - - // // Set common id - // familyId = dbFam.FamilyId; - // } - - // // Check if option is active - // if (!ToolManagerConfig.ShankOpt) - // { - // // 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, familyId); - // // Connect tool to new shank - // dtoToolWithFamily.ShankId = ncShank.ShankId; - // } - // else - // dtoToolWithFamily.ShankId = null; - // } - - // using (NcHandler ncHandler = new NcHandler()) - // { - // ncHandler.Connect(); - - // // Add tool - // CmsError cmsError = ncHandler.AddTool(dtoToolWithFamily, out DTONcToolModel newTool, familyId); - // if (cmsError.IsError()) - // return BadRequest(cmsError.localizationKey); - - // return Ok(CreateToolAndFamilyObj(newTool, dtoToolWithFamily)); - // } - //} - - public static DTONcToolWithFamilyModel DTO_TOOL_WITH_FAM = new DTONcToolWithFamilyModel() - { - Id = 0, - Name = "NewFam", - OffsetId1 = null, - OffsetId2 = null, - OffsetId3 = null, - LeftSize = 1, - RightSize = 1 - }; - + [Route("tool/{toolId:int}/{familyId:int}"), HttpPost] public IHttpActionResult AddToolWithId(short toolId, short familyId) { @@ -197,8 +103,10 @@ namespace Step.Controllers.WebApi } // Set return value - DTO_TOOL_WITH_FAM.FamilyId = dbFam.FamilyId; - DTO_TOOL_WITH_FAM.Name = dbFam.Name; + //DTO_TOOL_WITH_FAM.FamilyId = dbFam.FamilyId; + //DTO_TOOL_WITH_FAM.Name = dbFam.Name; + + SupportFunctions.CopyProperties(dbFam, DTO_TOOL_WITH_FAM); } else { @@ -297,52 +205,23 @@ namespace Step.Controllers.WebApi } } - private DTONcToolWithFamilyModel CreateToolAndFamilyObj(DTONcToolModel tool, DTONewNcToolWithFamilyModel familyData) - { - DTONcToolWithFamilyModel familyTool = new DTONcToolWithFamilyModel(); - // Copy family fields - SupportFunctions.CopyProperties(familyData, familyTool); - // Copy tool fields - SupportFunctions.CopyProperties(tool, familyTool); - - return familyTool; - } - - private DTONcToolWithFamilyModel CreateToolAndFamilyObj(DTONcToolModel tool, DTONcToolWithFamilyModel familyData) - { - DTONcToolWithFamilyModel familyTool = new DTONcToolWithFamilyModel(); - // Copy family fields - SupportFunctions.CopyProperties(familyData, familyTool); - // Copy tool fields - SupportFunctions.CopyProperties(tool, familyTool); - - return familyTool; - } - - private DTONcToolWithFamilyModel CreateToolAndFamilyObj(DTONcToolModel tool, DTONcFamilyModel familyData) - { - DTONcToolWithFamilyModel familyTool = new DTONcToolWithFamilyModel(); - // Copy family fields - SupportFunctions.CopyProperties(familyData, familyTool); - // Copy tool fields - SupportFunctions.CopyProperties(tool, familyTool); - - return familyTool; - } - [Route("tool/{toolId:int}"), HttpDelete] public IHttpActionResult DeleteTool(int toolId) { using (NcToolManagerController toolsManager = new NcToolManagerController()) { - DbNcToolModel tool = toolsManager.FindTool(toolId); + DbNcToolModel tool = toolsManager.FindToolWithDependencies(toolId); if (tool == null) return NotFound(); - // Check if tool is mounted in spindle - if (ToolIsInSpindle(toolId)) + // Check if tool is mounted in magazine (a tool to be mounted in spindle must be in magazine) + if(tool.Shank != null && tool.Shank.MagazineId != null && tool.Shank.PositionId != null) return BadRequest(API_ERROR_KEYS.TOOL_IS_MOUNTED); + // Check if tool is mounted in spindle + //if (ToolIsInSpindle(toolId)) + // return BadRequest(API_ERROR_KEYS.TOOL_IS_MOUNTED); + using (NcToolTableHandler ncHandler = new NcToolTableHandler()) { ncHandler.Connect(); @@ -571,8 +450,13 @@ namespace Step.Controllers.WebApi // Check if tools are mounted in spindle foreach (var tool in family.Tools) { - if (ToolIsInSpindle(tool.ToolId)) + // + var t = toolsManager.FindToolWithDependencies(tool.ToolId); + if(t.Shank != null && t.Shank.MagazineId != null && t.Shank.PositionId != null) return BadRequest(API_ERROR_KEYS.TOOL_IS_MOUNTED); + + //if (ToolIsInSpindle(tool.ToolId)) + // return BadRequest(API_ERROR_KEYS.TOOL_IS_MOUNTED); } using (NcToolTableHandler ncHandler = new NcToolTableHandler()) @@ -901,21 +785,6 @@ namespace Step.Controllers.WebApi } } - private bool ToolIsInSpindle(int toolId) - { - foreach (var head in LastHeadsData.ToList()) - { - if (head is DTOSpindleModel) - { - var spindle = head as DTOSpindleModel; - if (spindle.MountedTool == toolId) - return true; - } - } - - return false; - } - [Route("export"), HttpPost] public IHttpActionResult ExportToolTable() { @@ -964,7 +833,20 @@ namespace Step.Controllers.WebApi return Ok(); } - public bool IsValidJson(string jsonString, out DTOExportToolTableModel data) + #region Private Functions + + private static DTONcToolWithFamilyModel DTO_TOOL_WITH_FAM = new DTONcToolWithFamilyModel() + { + Id = 0, + Name = "NewFam", + OffsetId1 = null, + OffsetId2 = null, + OffsetId3 = null, + LeftSize = 1, + RightSize = 1 + }; + + private bool IsValidJson(string jsonString, out DTOExportToolTableModel data) { data = new DTOExportToolTableModel(); if (string.IsNullOrWhiteSpace(jsonString)) @@ -981,5 +863,139 @@ namespace Step.Controllers.WebApi return false; } } + + private DTONcToolWithFamilyModel CreateToolAndFamilyObj(DTONcToolModel tool, DTONewNcToolWithFamilyModel familyData) + { + DTONcToolWithFamilyModel familyTool = new DTONcToolWithFamilyModel(); + // Copy family fields + SupportFunctions.CopyProperties(familyData, familyTool); + // Copy tool fields + SupportFunctions.CopyProperties(tool, familyTool); + + return familyTool; + } + + private DTONcToolWithFamilyModel CreateToolAndFamilyObj(DTONcToolModel tool, DTONcToolWithFamilyModel familyData) + { + DTONcToolWithFamilyModel familyTool = new DTONcToolWithFamilyModel(); + // Copy family fields + SupportFunctions.CopyProperties(familyData, familyTool); + // Copy tool fields + SupportFunctions.CopyProperties(tool, familyTool); + + return familyTool; + } + + private DTONcToolWithFamilyModel CreateToolAndFamilyObj(DTONcToolModel tool, DTONcFamilyModel familyData) + { + DTONcToolWithFamilyModel familyTool = new DTONcToolWithFamilyModel(); + // Copy family fields + SupportFunctions.CopyProperties(familyData, familyTool); + // Copy tool fields + SupportFunctions.CopyProperties(tool, familyTool); + + return familyTool; + } + + private bool ToolIsInSpindle(int toolId) + { + foreach (var head in LastHeadsData.ToList()) + { + if (head is DTOSpindleModel) + { + var spindle = head as DTOSpindleModel; + if (!spindle.FixedHead && spindle.MountedTool == toolId) + return true; + } + } + + return false; + } + + #endregion } + + //[Route("tool_old"), HttpPost] + //public IHttpActionResult AddTool([FromBody][Required]DTONewNcToolWithFamilyModel dtoToolWithFamily) + //{ + // if (!ModelState.IsValid) + // return BadRequest(ModelState); + + // short familyId = 0; + // using (NcToolManagerController toolsManager = new NcToolManagerController()) + // { + // // Check if option is active + // if (ToolManagerConfig.FamilyOpt) + // { + // if (dtoToolWithFamily.FamilyId == 0) + // { + // // If param equal to 0 create a new family + // DTONcFamilyModel newFamily = new DTONcFamilyModel() { Name = "NewFamily", LeftSize = 1, RightSize = 1 }; + // // Add new family & update family id + // DbNcFamilyModel newFam = toolsManager.AddFamily(newFamily); + // dtoToolWithFamily.FamilyId = newFam.FamilyId; + // dtoToolWithFamily.Name = newFam.Name; + // } + // else + // { + // // Check if family exists + // DbNcFamilyModel fam = toolsManager.FindFamily(dtoToolWithFamily.FamilyId); + // if (fam == null) + // return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + + // // Update return data + // if (ToolManagerConfig.FamilyOpt) + // { + // dtoToolWithFamily.Name = fam.Name; + // } + // } + // } + // else + // { + // // Copy only family data from tool&fam model + // DTONcFamilyModel newFamily = new DTONcFamilyModel(); + // SupportFunctions.CopyProperties(dtoToolWithFamily, newFamily); + + // // Add new family + // DbNcFamilyModel dbFam = toolsManager.AddFamily(newFamily); + // if (dbFam == null) + // return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); + // dtoToolWithFamily.FamilyId = dbFam.FamilyId; + + // // Set common id + // familyId = dbFam.FamilyId; + // } + + // // Check if option is active + // if (!ToolManagerConfig.ShankOpt) + // { + // // 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, familyId); + // // Connect tool to new shank + // dtoToolWithFamily.ShankId = ncShank.ShankId; + // } + // else + // dtoToolWithFamily.ShankId = null; + // } + + // using (NcHandler ncHandler = new NcHandler()) + // { + // ncHandler.Connect(); + + // // Add tool + // CmsError cmsError = ncHandler.AddTool(dtoToolWithFamily, out DTONcToolModel newTool, familyId); + // if (cmsError.IsError()) + // return BadRequest(cmsError.localizationKey); + + // return Ok(CreateToolAndFamilyObj(newTool, dtoToolWithFamily)); + // } + //} + } \ No newline at end of file diff --git a/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.ts b/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.ts index 4926e441..f67d7620 100644 --- a/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.ts +++ b/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.ts @@ -529,6 +529,22 @@ public isEquipmentSelected(offset){ return false } + // Controllo se l'utensile può essere eliminato se in magazzino + public checkIfCanDeleteTool() { + if(this.selectedTool) { + // Check if magazine is in magazine + if (this.magazines.length > 0) { + var magId = this.getToolMagPosition(this.selectedTool.shankId) + var mag = this.magazines.find(d => d.id == magId); + + if (mag) + return true; + } + } + + return false + } + public getToolIcon = function (id) { if (id == 9999) return "../assets/iicons/Tools/Undefined.png" diff --git a/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.vue b/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.vue index eac3c77f..b7b2aa83 100644 --- a/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.vue +++ b/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.vue @@ -74,7 +74,7 @@
- +
{{'tooling_equipment_editlabel' | localize("Modifica utensile %d", selectedTool.id,selectedTool.familyName)}}
{{'tooling_equipment_editlabel' | localize("Modifica utensile %d", selectedTool.id)}}
{{'tooling_equipment_newlabel' | localize("Creazione Nuovo Utensile")}}
diff --git a/Step/wwwroot/src/app_modules/tooling/components/tooling-families.ts b/Step/wwwroot/src/app_modules/tooling/components/tooling-families.ts index 36f3f921..e319b04a 100644 --- a/Step/wwwroot/src/app_modules/tooling/components/tooling-families.ts +++ b/Step/wwwroot/src/app_modules/tooling/components/tooling-families.ts @@ -273,12 +273,12 @@ export default class toolingFamilies extends Vue { }, null); } - public checkIfCanEditTool() { + public checkIfCanEditFamily() { if(this.selectedTool){ // Check if magazine is locked if (this.magazines.length > 0) { - var magId = this.getToolMagPosition(this.selectedTool) + var magId = this.getToolMagPositionByFamily(this.selectedTool) var mag = this.magazines.find(d => d.id == magId); if (mag && !mag.loadingIsActive) return true; @@ -303,7 +303,22 @@ export default class toolingFamilies extends Vue { return false } - public getToolMagPosition = function (family) { + // Controllo se l'utensile può essere eliminato se in magazzino + public checkIfCanDeleteFamily() { + if(this.selectedTool) { + // Check if family is in magazine + if (this.magazines.length > 0) { + var magId = this.getToolMagPositionByFamily(this.selectedTool) + var mag = this.magazines.find(d => d.id == magId); + if (mag) + return true; + } + } + + return false + } + + public getToolMagPositionByFamily = function (family) { if(family.childTools){ for(let j = 0; j < family.childTools.length; j++) { var SH = this.ncShanks.filter(t => String(t.id).indexOf(family.childTools[j].shankId) >=0); diff --git a/Step/wwwroot/src/app_modules/tooling/components/tooling-families.vue b/Step/wwwroot/src/app_modules/tooling/components/tooling-families.vue index d3626cab..ad985512 100644 --- a/Step/wwwroot/src/app_modules/tooling/components/tooling-families.vue +++ b/Step/wwwroot/src/app_modules/tooling/components/tooling-families.vue @@ -114,7 +114,7 @@
- +
{{'tooling_families_boxright_editlabel' | localize("Modifica della famiglia %s", selectedTool.name)}}
{{'tooling_families_boxright_newlabel' | localize("Aggiunta nuova famiglia")}}
@@ -128,8 +128,8 @@