From caa19c2f7e13dfb301a9d8f9a1f7b61f91c18528 Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Tue, 18 Sep 2018 18:07:33 +0200 Subject: [PATCH] Fix tool manager --- .../Controllers/NcToolManagerController.cs | 4 ++-- Step.NC/NcHandler.cs | 20 +++++++++++++++---- .../WebApi/NcToolManagerController.cs | 4 +++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Step.Database/Controllers/NcToolManagerController.cs b/Step.Database/Controllers/NcToolManagerController.cs index 6223a842..db830409 100644 --- a/Step.Database/Controllers/NcToolManagerController.cs +++ b/Step.Database/Controllers/NcToolManagerController.cs @@ -261,8 +261,8 @@ namespace Step.Database.Controllers .Where(x => x.ShankId == null || x.ShankId == 0) .ToList(); - return dtoTools; - } + return dtoTools; + } public DbNcToolModel AddTool(DTONewNcToolModel dtoTool) { diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index 7edbaf6e..882ce641 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -1249,7 +1249,7 @@ namespace Step.NC config = new ToolTableConfiguration(); CmsError cmsError = numericalControl.TOOLS_RConfiguration(ref config); - if (NcConfig.NcVendor != NC_VENDOR.SIEMENS && NcConfig.NcVendor != NC_VENDOR.DEMO) + if (NcConfig.NcVendor != NC_VENDOR.SIEMENS) { config.FamilyOptionActive = true; config.MultitoolOptionActive = true; @@ -1598,16 +1598,28 @@ namespace Step.NC return cmsError; } - public DTONcToolModel AddTool(DTONewNcToolModel tool) + public CmsError AddTool(DTONewNcToolModel tool, out DTONcToolModel dtoTool) { + dtoTool = new DTONcToolModel(); + using (NcToolManagerController toolsManager = new NcToolManagerController()) { DbNcToolModel ncTool = toolsManager.AddTool(tool); - DTONcToolModel dtoTool = new DTONcToolModel(); + + if (!ToolManagerConfig.OffsetOpt) + { + CmsError cmsError = UpdateToolOffsetId(ncTool.ToolId, 1, ncTool.ToolId, out DTONcToolModel toolWithOffset); + if (cmsError.IsError()) + return cmsError; + + ncTool.OffsetId1 = ncTool.ToolId; + } + GetToolData(ncTool, ref dtoTool); - return dtoTool; + + return NO_ERROR; } } diff --git a/Step/Controllers/WebApi/NcToolManagerController.cs b/Step/Controllers/WebApi/NcToolManagerController.cs index f24213a4..de913354 100644 --- a/Step/Controllers/WebApi/NcToolManagerController.cs +++ b/Step/Controllers/WebApi/NcToolManagerController.cs @@ -116,7 +116,9 @@ namespace Step.Controllers.WebApi ncHandler.Connect(); // Add tool - DTONcToolModel newTool = ncHandler.AddTool(dtoToolWithFamily); + CmsError cmsError = ncHandler.AddTool(dtoToolWithFamily, out DTONcToolModel newTool); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); return Ok(CreateToolAndFamilyObj(newTool, dtoToolWithFamily)); }