diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index 63dbfcff..fb7f2f66 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -2343,27 +2343,33 @@ namespace Step.NC 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 + if (positionId < decPosition) { - // 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 == 1)) + { + // 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 + if (positionId > incPosition) { - // 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; + if (!(magConfig.Type == NC_MAGAZINE_TYPE.BOX_MAGAZINE && mountedTool.Shank.PositionId == magConfig.MaxPositions)) + { + // 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; + } } } }