Added load/unload into shank
Fixed magazine position returned data WIP loading/unloading rules
This commit is contained in:
@@ -385,7 +385,7 @@ public static class ThreadsFunctions
|
||||
ReadAxesNamesTimes++;
|
||||
|
||||
// Wait
|
||||
Thread.Sleep(CalcSleepTime(200, (int)sw.ElapsedMilliseconds));
|
||||
Thread.Sleep(CalcSleepTime(500, (int)sw.ElapsedMilliseconds));
|
||||
}
|
||||
}
|
||||
catch (ThreadAbortException)
|
||||
|
||||
@@ -128,11 +128,25 @@ namespace Step.Database.Controllers
|
||||
return dtoShanks;
|
||||
}
|
||||
|
||||
public DTONcShankModel GetShank(int shankId)
|
||||
{
|
||||
// Get shank from database
|
||||
NcShankModel dbShank = dbCtx
|
||||
.Shanks
|
||||
.Where(x => x.ShankId == shankId)
|
||||
.Include("Tools")
|
||||
.FirstOrDefault();
|
||||
|
||||
// Convert into DTOModel
|
||||
DTONcShankModel dtoShanks = (DTONcShankModel)dbShank;
|
||||
|
||||
return dtoShanks;
|
||||
}
|
||||
|
||||
public List<NcMagazinePositionModel> FindPositions()
|
||||
{
|
||||
List<NcMagazinePositionModel> positions = dbCtx
|
||||
.MagazinePositions
|
||||
.Include("Shank")
|
||||
.ToList();
|
||||
|
||||
return positions;
|
||||
@@ -146,6 +160,26 @@ namespace Step.Database.Controllers
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
public List<DTONcMagazinePositionModel> GetMagazinePositions(byte magId)
|
||||
{
|
||||
// Get only magazine positions that match with magazineId
|
||||
List<DTONcMagazinePositionModel> 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<NcShankModel> shanks = dbCtx.Shanks.Where(x => x.MagazineId == magId).ToList();
|
||||
|
||||
foreach(NcShankModel 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 NcMagazinePositionModel FindMagazinePosition(byte magId, byte posId)
|
||||
{
|
||||
NcMagazinePositionModel positions = dbCtx
|
||||
@@ -156,13 +190,6 @@ namespace Step.Database.Controllers
|
||||
return positions;
|
||||
}
|
||||
|
||||
//public List<NcOffsetModel> GetOffsets()
|
||||
//{
|
||||
// List<NcOffsetModel> offsets = dbCtx.Offsets.ToList();
|
||||
|
||||
// return offsets;
|
||||
//}
|
||||
|
||||
public List<DTONcShankModel> GetMountedShanks(int magazineId)
|
||||
{
|
||||
List<DTONcShankModel> dtoShanks = GetShanks()
|
||||
@@ -299,7 +326,7 @@ namespace Step.Database.Controllers
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
public NcMagazinePositionModel UpdatePosition(NcMagazinePositionModel dbPos, DTONcMagazinesPositionsModel dtoPos)
|
||||
public NcMagazinePositionModel UpdatePosition(NcMagazinePositionModel dbPos, DTONcMagazinePositionModel dtoPos)
|
||||
{
|
||||
dbPos.Type = dtoPos.Type;
|
||||
dbPos.Disabled = dtoPos.Disabled;
|
||||
@@ -332,5 +359,28 @@ namespace Step.Database.Controllers
|
||||
|
||||
return (DTONcShankModel)shank;
|
||||
}
|
||||
|
||||
public DTONcShankModel LoadToolIntoShank(NcToolModel tool, int shankId)
|
||||
{
|
||||
dbCtx.Tools.Attach(tool);
|
||||
|
||||
tool.ShankId = shankId;
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return GetShank(shankId);
|
||||
}
|
||||
|
||||
public DTONcShankModel UnloadToolFromShank(NcToolModel tool)
|
||||
{
|
||||
dbCtx.Tools.Attach(tool);
|
||||
int? shankId = tool.ShankId;
|
||||
|
||||
tool.ShankId = null;
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return GetShank(shankId.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ namespace Step.Database
|
||||
|
||||
public DbSet<NcFamilyModel> Families { get; set; }
|
||||
public DbSet<NcShankModel> Shanks { get; set; }
|
||||
public DbSet<NcOffsetModel> Offsets { get; set; }
|
||||
// public DbSet<NcOffsetModel> Offsets { get; set; }
|
||||
public DbSet<NcToolModel> Tools { get; set; }
|
||||
public DbSet<NcMagazinePositionModel> MagazinePositions { get; set; }
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
+1
-1
@@ -13,7 +13,7 @@ namespace Step.Database.Migrations
|
||||
|
||||
string IMigrationMetadata.Id
|
||||
{
|
||||
get { return "201807050940385_InitMigration"; }
|
||||
get { return "201807090630343_InitMigration"; }
|
||||
}
|
||||
|
||||
string IMigrationMetadata.Source
|
||||
-14
@@ -195,19 +195,6 @@ namespace Step.Database.Migrations
|
||||
.Index(t => t.user_id)
|
||||
.Index(t => t.maintenance_id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.offset",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
nc_offset_id = c.Int(nullable: false),
|
||||
lenght = c.Double(nullable: false),
|
||||
radius = c.Double(nullable: false),
|
||||
wear_length = c.Double(nullable: false),
|
||||
wear_radius = c.Double(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.performed_maintenance",
|
||||
c => new
|
||||
@@ -264,7 +251,6 @@ namespace Step.Database.Migrations
|
||||
DropIndex("dbo.tool", new[] { "family_id" });
|
||||
DropTable("dbo.session");
|
||||
DropTable("dbo.performed_maintenance");
|
||||
DropTable("dbo.offset");
|
||||
DropTable("dbo.maintenance_note");
|
||||
DropTable("dbo.maintenance");
|
||||
DropTable("dbo.maintenance_file");
|
||||
File diff suppressed because one or more lines are too long
@@ -78,9 +78,9 @@
|
||||
<Compile Include="Controllers\UsersController.cs" />
|
||||
<Compile Include="Controllers\MachinesUsersController.cs" />
|
||||
<Compile Include="DatabaseContext.cs" />
|
||||
<Compile Include="Migrations\201807050940385_InitMigration.cs" />
|
||||
<Compile Include="Migrations\201807050940385_InitMigration.Designer.cs">
|
||||
<DependentUpon>201807050940385_InitMigration.cs</DependentUpon>
|
||||
<Compile Include="Migrations\201807090630343_InitMigration.cs" />
|
||||
<Compile Include="Migrations\201807090630343_InitMigration.Designer.cs">
|
||||
<DependentUpon>201807090630343_InitMigration.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Migrations\Configuration.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
@@ -116,8 +116,8 @@
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Migrations\201807050940385_InitMigration.resx">
|
||||
<DependentUpon>201807050940385_InitMigration.cs</DependentUpon>
|
||||
<EmbeddedResource Include="Migrations\201807090630343_InitMigration.resx">
|
||||
<DependentUpon>201807090630343_InitMigration.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -180,6 +180,8 @@ namespace Step.Model
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(NcMagazinePositionModel obj)
|
||||
{
|
||||
return new DTONcMagazinePositionModel()
|
||||
{
|
||||
MagazineId = obj.MagazineId,
|
||||
PositionId = obj.PositionId,
|
||||
Disabled = obj.Disabled,
|
||||
Type = obj.Type
|
||||
};
|
||||
}
|
||||
|
||||
public static explicit operator NcMagazinePositionModel(DTONcMagazinePositionModel obj)
|
||||
{
|
||||
return new NcMagazinePositionModel()
|
||||
{
|
||||
MagazineId = obj.MagazineId,
|
||||
PositionId = obj.PositionId,
|
||||
Disabled = obj.Disabled,
|
||||
Type = obj.Type
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Step.Model.DTOModels.ToolModels
|
||||
{
|
||||
public class DTONcMountedShank
|
||||
public class DTONcMountedShankModel
|
||||
{
|
||||
public byte PositionId;
|
||||
public byte MagazineId;
|
||||
@@ -131,30 +131,4 @@ namespace Step.Model.DTOModels.ToolModels
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class DTONcMagazinesPositionsModel
|
||||
{
|
||||
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 DTONcMagazinesPositionsModel(NcMagazinePositionModel obj)
|
||||
{
|
||||
return new DTONcMagazinesPositionsModel()
|
||||
{
|
||||
MagazineId = obj.MagazineId,
|
||||
PositionId = obj.PositionId,
|
||||
Disabled = obj.Disabled,
|
||||
Type = obj.Type
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,8 @@
|
||||
<Compile Include="DTOModels\ToolModels\DTOEdgeModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTOMagazineStatusModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTONcFamilyModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTONcMountedTool.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTONcMagazinePositionModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTONcMountedShankModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTONcShankModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTONcToolModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTOShankModel.cs" />
|
||||
|
||||
+25
-4
@@ -1174,11 +1174,11 @@ namespace Step.NC
|
||||
}
|
||||
}
|
||||
|
||||
public NcMagazinePositionModel UpdateMagazinePosition(NcMagazinePositionModel dbPos, DTONcMagazinesPositionsModel dtoPos)
|
||||
public DTONcMagazinePositionModel UpdateMagazinePosition(NcMagazinePositionModel dbPos, DTONcMagazinePositionModel dtoPos)
|
||||
{
|
||||
using (NcToolManagerController toolsManager = new NcToolManagerController())
|
||||
{
|
||||
return toolsManager.UpdatePosition(dbPos, dtoPos);
|
||||
return (DTONcMagazinePositionModel)toolsManager.UpdatePosition(dbPos, dtoPos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1206,11 +1206,16 @@ namespace Step.NC
|
||||
}
|
||||
}
|
||||
|
||||
public DTONcMagazinesPositionsModel LoadToolInMagazine(byte magazineId, byte positionId, NcShankModel shank)
|
||||
public DTONcMagazinePositionModel LoadToolInMagazine(byte magazineId, byte positionId, NcShankModel shank)
|
||||
{
|
||||
using (NcToolManagerController toolsManager = new NcToolManagerController())
|
||||
{
|
||||
return (DTONcMagazinesPositionsModel)toolsManager.LoadShankInMagazine(magazineId, positionId, shank);
|
||||
// Update shank data
|
||||
DTONcMagazinePositionModel magPos = (DTONcMagazinePositionModel)toolsManager.LoadShankInMagazine(magazineId, positionId, shank);
|
||||
// Set magazineId
|
||||
magPos.ShankId = shank.ShankId;
|
||||
|
||||
return magPos;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1222,6 +1227,22 @@ namespace Step.NC
|
||||
}
|
||||
}
|
||||
|
||||
public DTONcShankModel LoadIntoShank(NcToolModel tool, int shankId)
|
||||
{
|
||||
using (NcToolManagerController toolsManager = new NcToolManagerController())
|
||||
{
|
||||
return toolsManager.LoadToolIntoShank(tool, shankId);
|
||||
}
|
||||
}
|
||||
|
||||
public DTONcShankModel UnloadIntoShank(NcToolModel tool)
|
||||
{
|
||||
using (NcToolManagerController toolsManager = new NcToolManagerController())
|
||||
{
|
||||
return toolsManager.UnloadToolFromShank(tool);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Osai/Fanuc Tools
|
||||
|
||||
#endregion Write data
|
||||
|
||||
@@ -4,6 +4,7 @@ using Step.Model.DTOModels.ToolModels;
|
||||
using Step.NC;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Web.Http;
|
||||
using static CMS_CORE_Library.DataStructures;
|
||||
using static Step.Config.ServerConfig;
|
||||
@@ -307,14 +308,14 @@ namespace Step.Controllers.WebApi
|
||||
{
|
||||
using (NcToolManagerController toolsManager = new NcToolManagerController())
|
||||
{
|
||||
List<NcMagazinePositionModel> magazine = toolsManager.FindMagazinePositions(magazineId);
|
||||
List<DTONcMagazinePositionModel> magazine = toolsManager.GetMagazinePositions(magazineId);
|
||||
|
||||
return Ok(magazine);
|
||||
}
|
||||
}
|
||||
|
||||
[Route("magazine/{magazineId}/position/{positionId}"), HttpPut]
|
||||
public IHttpActionResult PutMagazinePosition([Required]byte magazineId, [Required]byte positionId, [FromBody]DTONcMagazinesPositionsModel dtoPos)
|
||||
public IHttpActionResult PutMagazinePosition([Required]byte magazineId, [Required]byte positionId, [FromBody]DTONcMagazinePositionModel dtoPos)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
@@ -328,8 +329,8 @@ namespace Step.Controllers.WebApi
|
||||
|
||||
using (NcHandler ncHandler = new NcHandler())
|
||||
{
|
||||
pos = ncHandler.UpdateMagazinePosition(pos, dtoPos);
|
||||
return Ok(pos);
|
||||
DTONcMagazinePositionModel newPos = ncHandler.UpdateMagazinePosition(pos, dtoPos);
|
||||
return Ok(newPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -371,20 +372,35 @@ namespace Step.Controllers.WebApi
|
||||
if (shankId.ToolId == 0)
|
||||
return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS);
|
||||
|
||||
// Check data
|
||||
NcShankModel shank;
|
||||
using (NcToolManagerController toolsManager = new NcToolManagerController())
|
||||
{
|
||||
NcShankModel shank = toolsManager.FindShank(shankId.ToolId);
|
||||
// Check if shank exists
|
||||
shank = toolsManager.FindShank(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);
|
||||
|
||||
using (NcHandler ncHandler = new NcHandler())
|
||||
{
|
||||
ncHandler.Connect();
|
||||
DTONcMagazinesPositionsModel magPos = ncHandler.LoadToolInMagazine(magazineId, positionId, shank);
|
||||
|
||||
return Ok(magPos);
|
||||
}
|
||||
// Check if magazine position exists
|
||||
NcMagazinePositionModel 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())
|
||||
{
|
||||
ncHandler.Connect();
|
||||
DTONcMagazinePositionModel magazinePos = ncHandler.LoadToolInMagazine(magazineId, positionId, shank);
|
||||
|
||||
return Ok(magazinePos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Route("magazine/{magazineId:int}/unload/position/{positionId:int}"), HttpPut]
|
||||
@@ -395,19 +411,63 @@ namespace Step.Controllers.WebApi
|
||||
if (shankId.ToolId == 0)
|
||||
return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS);
|
||||
|
||||
// Check data
|
||||
NcShankModel shank;
|
||||
using (NcToolManagerController toolsManager = new NcToolManagerController())
|
||||
{
|
||||
NcShankModel shank = toolsManager.FindShank(shankId.ToolId);
|
||||
// Check if shank exists
|
||||
shank = toolsManager.FindShank(shankId.ToolId);
|
||||
if (shank == null)
|
||||
return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS);
|
||||
|
||||
using (NcHandler ncHandler = new NcHandler())
|
||||
{
|
||||
ncHandler.Connect();
|
||||
DTONcShankModel responseShank = ncHandler.UnloadToolInMagazine(magazineId, positionId, shank);
|
||||
// Check if magazine position exists
|
||||
NcMagazinePositionModel 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 occupied
|
||||
NcShankModel shankMounted = toolsManager.FindShanks().Where(x => x.MagazineId == magazineId && x.PositionId == positionId).FirstOrDefault();
|
||||
if (shankMounted != null)
|
||||
return BadRequest(API_ERROR_KEYS.MAGAZINE_POSITION_OCCUPIED);
|
||||
}
|
||||
|
||||
return Ok(responseShank);
|
||||
}
|
||||
using (NcHandler ncHandler = new NcHandler())
|
||||
{
|
||||
ncHandler.Connect();
|
||||
DTONcShankModel responseShank = ncHandler.UnloadToolInMagazine(magazineId, positionId, shank);
|
||||
|
||||
return Ok(responseShank);
|
||||
}
|
||||
}
|
||||
|
||||
[Route("shank/{shankId:int}/load/tool/{toolId:int}"), HttpPut]
|
||||
public IHttpActionResult LoadToolIntoShank(int shankId, int toolId)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
NcToolModel tool;
|
||||
using (NcToolManagerController toolsManager = new NcToolManagerController())
|
||||
{
|
||||
// Check if shank exists
|
||||
NcShankModel shank = toolsManager.FindShank(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,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);
|
||||
|
||||
Reference in New Issue
Block a user