diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index c53832d3..3a419291 100644 Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ diff --git a/Step.Model/DTOModels/ToolModels/DTOSiemensToolModel.cs b/Step.Model/DTOModels/ToolModels/DTOSiemensToolModel.cs new file mode 100644 index 00000000..3281db9f --- /dev/null +++ b/Step.Model/DTOModels/ToolModels/DTOSiemensToolModel.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using static CMS_CORE_Library.DataStructures; + +namespace Step.Model.DTOModels.ToolModels +{ + public class DTOSiemensToolModel + { + [Required] + public string FamilyName { get; set; } + [Required] + public int MagazinePositionType; + [Required] + public int ToolType; + [Required] + public int LeftSize; + [Required] + public int RightSize; + [Required] + public ROTATION Rotation; + [Required] + public bool Cooling1; + [Required] + public bool Cooling2; + [Required] + public bool IsActive; + [Required] + public bool FixedPlace; + [Required] + public bool IsInhibited; + [Required] + public bool IsMeasured; + [Required] + public bool ChangeTool; + [Required] + public bool IsInUse; + [Required] + public bool PreAlarm; + + // public List> EdgesData; + } +} \ No newline at end of file diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index a7a16df5..dca53bc2 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -730,6 +730,17 @@ namespace Step.NC return numericalControl.PLC_WPowerOnData(id, true); } + #region Tools + + + public CmsError AddTool(ref SiemensToolModel tool) + { + return numericalControl.TOOLS_WAddTool(ref tool); + } + public CmsError UpdateTool(SiemensToolModel tool) + { + return numericalControl.TOOLS_WUpdateTool(tool); + } public CmsError AddFamily(string name, out FamilyModel family) { @@ -748,6 +759,18 @@ namespace Step.NC return numericalControl.TOOLS_WAddShank(ref shank); } + public CmsError UpdateFamilyName(string oldName, string newName) + { + return numericalControl.TOOLS_WUpdateFamilyData(oldName, newName); + } + + public CmsError UpdateMagazinePosition(MagazinePositionsModel magazinePosition) + { + return numericalControl.TOOLS_WUpdateMagazinesPositions(magazinePosition); + } + + + #endregion #endregion Write data } } \ No newline at end of file diff --git a/Step/Controllers/WebApi/ToolTableController.cs b/Step/Controllers/WebApi/ToolTableController.cs index 3a2b0f4e..5056a431 100644 --- a/Step/Controllers/WebApi/ToolTableController.cs +++ b/Step/Controllers/WebApi/ToolTableController.cs @@ -1,5 +1,8 @@ -using Step.NC; +using Step.Model.DTOModels.ToolModels; +using Step.NC; +using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Web.Http; using static CMS_CORE_Library.DataStructures; @@ -38,21 +41,78 @@ namespace Step.Controllers.WebApi } } - [Route("shanks"), HttpGet] - public IHttpActionResult GetShanks() + [Route("siemens/tool"), HttpPost] + public IHttpActionResult AddTool([FromBody][Required]DTOSiemensToolModel tool) { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + using (NcHandler ncHandler = new NcHandler()) { + // Convert from DTOModel to library model + SiemensToolModel siemensModel = ConvertFromDTOtoSiemensModel(tool); + ncHandler.Connect(); - CmsError libraryError = ncHandler.GetShanksData(out List shanks); + CmsError libraryError = ncHandler.AddTool(ref siemensModel); if (libraryError.IsError()) if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED) return BadRequest(libraryError.message); - return Ok(shanks); + return Ok(siemensModel); } } + [Route("siemens/tool/{id}"), HttpPut] + public IHttpActionResult UpdateTool(int id, [FromBody][Required]DTOSiemensToolModel tool) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + using (NcHandler ncHandler = new NcHandler()) + { + // Convert from DTOModel to library model + SiemensToolModel siemensModel = ConvertFromDTOtoSiemensModel(tool); + + ncHandler.Connect(); + CmsError libraryError = ncHandler.UpdateTool(siemensModel); + + if (libraryError.IsError()) + if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED) + return BadRequest(libraryError.message); + + return Ok(); + } + } + + private SiemensToolModel ConvertFromDTOtoSiemensModel(DTOSiemensToolModel dtoModel) + { + return new SiemensToolModel() + { + MagazinePositionType = dtoModel.MagazinePositionType, + ToolType = dtoModel.ToolType, + + FamilyName = dtoModel.FamilyName, + + IsActive = dtoModel.IsActive, + IsInhibited = dtoModel.IsInhibited, + IsInUse = dtoModel.IsInUse, + IsMeasured = dtoModel.IsMeasured, + ChangeTool = dtoModel.ChangeTool, + FixedPlace = dtoModel.FixedPlace, + PreAlarm = dtoModel.PreAlarm, + + Cooling1 = dtoModel.Cooling1, + Cooling2 = dtoModel.Cooling2, + LeftSize = dtoModel.LeftSize, + RightSize = dtoModel.RightSize, + Rotation = dtoModel.Rotation + }; + } + [Route("families"), HttpGet] public IHttpActionResult GetFamilies() { @@ -112,5 +172,62 @@ namespace Step.Controllers.WebApi return Ok(shank); } } + + [Route("shanks"), HttpGet] + public IHttpActionResult GetShanks() + { + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + CmsError libraryError = ncHandler.GetShanksData(out List shanks); + if (libraryError.IsError()) + if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED) + return BadRequest(libraryError.message); + + return Ok(shanks); + } + } + + [Route("family/{oldName}"), HttpPut] + public IHttpActionResult PutFamily(string oldName, [FromBody]dynamic body) + { + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + + + CmsError libraryError = ncHandler.UpdateFamilyName(oldName, body.name.ToString()); + if (libraryError.IsError()) + if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED) + return BadRequest(libraryError.message); + + return Ok(); + } + } + + [Route("magazine_position/{magazineId}/{position}"), HttpPut] + public IHttpActionResult PutMagazinePosition(int magazineId, int position, [FromBody]dynamic body) + { + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + if (magazineId == 0 || position == 0 || body == null || body.type == null) + return BadRequest(); + // Create Library model + MagazinePositionsModel pos = new MagazinePositionsModel() + { + Id = position, + MagazineId = magazineId, + Type = Convert.ToInt32(body.type) + }; + // Update + CmsError libraryError = ncHandler.UpdateMagazinePosition(pos); + if (libraryError.IsError()) + if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED) + return BadRequest(libraryError.message); + + return Ok(); + } + } } } \ No newline at end of file