diff --git a/LuaLibs/PanelSaw.lua b/LuaLibs/PanelSaw.lua index c61fbef..49a9fc5 100644 --- a/LuaLibs/PanelSaw.lua +++ b/LuaLibs/PanelSaw.lua @@ -3,7 +3,9 @@ -- Intestazioni require( 'EgtBase') -EgtEnableDebug( false) + +-- Dati +local WL = require ( 'WallLib') local PanelSaw = {} @@ -80,199 +82,192 @@ local function GetProjectInfo() return ProjectInfo end -local function GetFormattedLine( ValuesList, ValuesPlaceholders, FieldFixLength) - local sLine = '' - local Values = ValuesList - local nPos = 1 -- posizione partenza linea - - for j, Value in ipairs( Values) do - local Placeholder = ValuesPlaceholders[j] - local sFormatted = string.format( Placeholder, Value) - - -- se il campo ha lunghezza fissa, si aggiungono spazi - if FieldFixLength and FieldFixLength[j] then - local sFieldLength = FieldFixLength[j] - -- troncamento se troppo lungo - if #sFormatted > sFieldLength then - sFormatted = string.sub( sFormatted, 1, sFieldLength) - end - sFormatted = sFormatted .. string.rep(" ", sFieldLength - #sFormatted) - end - - sLine = sLine .. sFormatted - nPos = nPos + #sFormatted - - -- Aggiungi spazio solo se non è l'ultimo campo - if j < #Values then - sLine = sLine .. " " - nPos = nPos + 1 - end - end - return sLine -end - local function BuildCuttingList_Cutty( PanelList, SheetList, ProjectInfo) - local Lines = {} + -- se il numero di pezzi supera il limite, si devono creare più liste + local nMaxPanelsCount = 30 + local SplittedPanelList = WL.SplitTableInChunks( PanelList, nMaxPanelsCount) + local LinesToWriteList = {} - local F0 = { - Header = { 'F0'}, - HeaderPlaceholders = { '%s'}, - Values = { ' 7.70', '210700', '150300'}, - ValuesPlaceholders = { '%s', '%s', '%s'} - } + for nCurrentPanelList = 1, #SplittedPanelList do + local Lines = {} + LinesToWriteList[nCurrentPanelList] = {} - local F0b = { - Header = { 'F0b', '""', '""', '""', '""'}, - HeaderPlaceholders = { '%s', '%s', '%s', '%s', '%s'} - } + local F0 = { + Header = { 'F0'}, + HeaderPlaceholders = { '%s'}, + Values = { ' 7.70', '210700', '150300'}, + ValuesPlaceholders = { '%s', '%s', '%s'} + } - local F1 = { - Header = { 'F1', PanelList[1].dThickness, 0, 0, 0}, - HeaderPlaceholders = { '%s', '%.3f', '%.3f', '%.3f', '%.3f'}, - ValuesList = {}, - ValuesPlaceholders = { '%.3f', '%.3f', '%d', '%d', '%d', '%d', '%s', '%d', '%.3f', '%d', '%d', '%d', '%d'}, - FieldFixLength = { [6] = 29, [7] = 50} - } - for i = 1, #SheetList do - F1.ValuesList[i] = { SheetList[i].dLength, SheetList[i].dWidth, 99, 200, 1, 1, SheetList[i].sMaterial, 0, 1, 0, 0, 0, 0} + local F0b = { + Header = { 'F0b', '""', '""', '""', '""'}, + HeaderPlaceholders = { '%s', '%s', '%s', '%s', '%s'} + } + + local F1 = { + Header = { 'F1', SplittedPanelList[nCurrentPanelList][1].dThickness, 0, 0, 0}, + HeaderPlaceholders = { '%s', '%.3f', '%.3f', '%.3f', '%.3f'}, + ValuesList = {}, + ValuesPlaceholders = { '%.3f', '%.3f', '%d', '%d', '%d', '%-29d', '%-50s', '%d', '%.3f', '%d', '%d', '%d', '%d'}, + } + for i = 1, #SheetList do + F1.ValuesList[i] = { SheetList[i].dLength, SheetList[i].dWidth, 99, 200, 1, 1, SheetList[i].sMaterial, 0, 1, 0, 0, 0, 0} + end + + local F2 = { + Header = { 'F2', 0, 0, 0}, + HeaderPlaceholders = { '%s', '%d', '%d', '%d'}, + ValuesList = {}, + ValuesPlaceholders = { '%.3f', '%.3f', '%d', '%d', '%d', '%d', '%d', '%-20s', '%d', '%d', '%d', '%d', '%-50s', '%d', '%d', '%d', '%d', '%d', '%d', '%.3f', '%d', '%d', '%-85d', '%.3f', '%.3f'}, + } + for i = 1, #SplittedPanelList[nCurrentPanelList] do + F2.ValuesList[i] = { SplittedPanelList[nCurrentPanelList][i].dLength, SplittedPanelList[nCurrentPanelList][i].dWidth, SplittedPanelList[nCurrentPanelList][i].nQuantity, 0, 0, 0, 0, SplittedPanelList[nCurrentPanelList][i].nPdn, 0, 0, 0, 0, SplittedPanelList[nCurrentPanelList][i].sDescription, 0, 0, 0, 0, 1, 0, 1500, 0, 0, 0, 0, 0} + end + + local F7 = { + Header = { 'F7', 3052, 0}, + HeaderPlaceholders = { '%s', '%s', '%d'}, + ValuesList = { + { 218, 436}, + { 167, 669}, + { 204, 408}, + { 204, 204}, + { 204, 204}, + { 209, 209}, + { 167, 167}, + { 213, 213}, + { 229, 229}, + { 164, 164}, + { 150, 150} + }, + ValuesPlaceholders = { + { '%s', '%s'}, + { '%s', '%s'}, + { '%s', '%s'}, + { '%s', '%s'}, + { '%s', '%s'}, + { '%s', '%s'}, + { '%s', '%s'}, + { '%s', '%s'}, + { '%s', '%s'}, + { '%s', '%s'}, + { '%s', '%s'} + } + } + + local F7b = { + Header = { 'F7b', 0, 0, 0, 0}, + HeaderPlaceholders = { '%s', '%.3f', '%.3f', '%.3f', '%.3f'}, + Values = {}, + ValuesPlaceholders = {} + } + + local F8 = { + Header = { 'F8', 0, 0, 20, 20, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + HeaderPlaceholders = { '%s', '%.3f', '%.3f', '%d', '%d', '%d', '%d', '%.3f', '%d', '%d', '%d', '%d', '%d', '%d', '%.3f', '%d', '%d', '%d', '%d', '%d', '%d', '%.3f', '%.3f', '%.3f'} + } + + local F9 = { + Header = { 'F9', 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 4.3, 0, 0, 0, 2, 0, 2450, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + HeaderPlaceholders = { '%s', '%d', '%.3f', '%d', '%.3f', '%.3f', '%.3f', '%.3f', '%.3f', '%d', '%d', '%.3f', '%d', '%d', '%d', '%d', '%.3f', '%.3f', '%d', '%d', '%.3f', '%.3f', '%.3f', '%.3f', '%d', '%d', '%.3f', '%.3f'} + } + + local F3 = { + Header = { 'F3'}, + HeaderPlaceholders = { '%s'} + } + + local E0 = { + Header = { 'E0'}, + HeaderPlaceholders = { '%s'} + } + + -- F0 + table.insert( Lines, string.format( table.concat( F0.HeaderPlaceholders, ' '), table.unpack( F0.Header))) + table.insert( Lines, string.format( table.concat( F0.ValuesPlaceholders, ' '), table.unpack( F0.Values))) + + -- linea vuota + table.insert( Lines, '') + + -- F0b + table.insert( Lines, string.format( table.concat( F0b.HeaderPlaceholders, ' '), table.unpack( F0b.Header))) + + -- linea vuota + table.insert( Lines, '') + + -- F1 - sheets + table.insert( Lines, string.format( table.concat( F1.HeaderPlaceholders, ' '), table.unpack( F1.Header))) + for i = 1, #F1.ValuesList do + local Values = F1.ValuesList[i] + local Placeholders = F1.ValuesPlaceholders + table.insert( Lines, string.format( table.concat( Placeholders, ' '), table.unpack( Values))) + end + + -- linea vuota + table.insert( Lines, '') + + -- F2 - panels + table.insert( Lines, string.format( table.concat( F2.HeaderPlaceholders, ' '), table.unpack( F2.Header))) + for i = 1, #F2.ValuesList do + local Values = F2.ValuesList[i] + local Placeholders = F2.ValuesPlaceholders + table.insert( Lines, string.format( table.concat( Placeholders, ' '), table.unpack( Values))) + end + + -- linea vuota + table.insert( Lines, '') + + -- F7 + table.insert( Lines, string.format( table.concat( F7.HeaderPlaceholders, ' '), table.unpack( F7.Header))) + for i = 1, #F7.ValuesList do + local Values = F7.ValuesList[i] + local Placeholders = F7.ValuesPlaceholders[i] + table.insert( Lines, string.format( table.concat( Placeholders, ' '), table.unpack( Values))) + end + + -- linea vuota + table.insert( Lines, '') + + -- F7b + table.insert( Lines, string.format( table.concat( F7b.HeaderPlaceholders, ' '), table.unpack( F7b.Header))) + + -- linea vuota + table.insert( Lines, '') + + -- F8 + table.insert( Lines, string.format( table.concat( F8.HeaderPlaceholders, ' '), table.unpack( F8.Header))) + + -- linea vuota + table.insert( Lines, '') + + -- F9 + table.insert( Lines, string.format( table.concat( F9.HeaderPlaceholders, ' '), table.unpack( F9.Header))) + + -- linea vuota + table.insert( Lines, '') + + -- F3 + table.insert ( Lines, string.format( table.concat( F3.HeaderPlaceholders, ' '), table.unpack( F3.Header))) + + -- E0 + table.insert( Lines, string.format( table.concat( E0.HeaderPlaceholders, ' '), table.unpack( E0.Header))) + + -- linea vuota + table.insert( Lines, '') + + LinesToWriteList[nCurrentPanelList] = Lines end - local F2 = { - Header = { 'F2', 0, 0, 0}, - HeaderPlaceholders = { '%s', '%d', '%d', '%d'}, - ValuesList = {}, - ValuesPlaceholders = { '%.3f', '%.3f', '%d', '%d', '%d', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%.3f', '%d', '%d', '%d', '%.3f', '%.3f'}, - FieldFixLength = { [8] = 20, [13] = 50, [23] = 85} - } - for i = 1, #PanelList do - F2.ValuesList[i] = { PanelList[i].dLength, PanelList[i].dWidth, PanelList[i].nQuantity, 0, 0, 0, 0, PanelList[i].nPdn, 0, 0, 0, 0, PanelList[i].sDescription, 0, 0, 0, 0, 1, 0, 1500, 0, 0, 0, 0, 0} - end - local F7 = { - Header = { 'F7', 3052, 0}, - HeaderPlaceholders = { '%s', '%s', '%d'}, - ValuesList = { - { 218, 436}, - { 167, 669}, - { 204, 408}, - { 204, 204}, - { 204, 204}, - { 209, 209}, - { 167, 167}, - { 213, 213}, - { 229, 229}, - { 164, 164}, - { 150, 150} - }, - ValuesPlaceholders = { '%s', '%s'} - } - - local F7b = { - Header = { 'F7b', 0, 0, 0, 0}, - HeaderPlaceholders = { '%s', '%.3f', '%.3f', '%.3f', '%.3f'}, - Values = {}, - ValuesPlaceholders = {} - } - - local F8 = { - Header = { 'F8', 0, 0, 20, 20, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - HeaderPlaceholders = { '%s', '%.3f', '%.3f', '%d', '%d', '%d', '%d', '%.3f', '%d', '%d', '%d', '%d', '%d', '%d', '%.3f', '%d', '%d', '%d', '%d', '%d', '%d', '%.3f', '%.3f', '%.3f'} - } - - local F9 = { - Header = { 'F9', 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 4.3, 0, 0, 0, 2, 0, 2450, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - HeaderPlaceholders = { '%s', '%d', '%.3f', '%d', '%.3f', '%.3f', '%.3f', '%.3f', '%.3f', '%d', '%d', '%.3f', '%d', '%d', '%d', '%d', '%.3f', '%.3f', '%d', '%d', '%.3f', '%.3f', '%.3f', '%.3f', '%d', '%d', '%.3f', '%.3f'} - } - - local F3 = { - Header = { 'F3'}, - HeaderPlaceholders = { '%s'} - } - - local E0 = { - Header = { 'E0'}, - HeaderPlaceholders = { '%s'} - } - - -- F0 - table.insert( Lines, string.format( table.concat( F0.HeaderPlaceholders, ' '), table.unpack( F0.Header))) - table.insert( Lines, string.format( table.concat( F0.ValuesPlaceholders, ' '), table.unpack( F0.Values))) - - -- linea vuota - table.insert( Lines, '') - - -- F0b - table.insert( Lines, string.format( table.concat( F0b.HeaderPlaceholders, ' '), table.unpack( F0b.Header))) - - -- linea vuota - table.insert( Lines, '') - - -- F1 - sheets - table.insert( Lines, string.format( table.concat( F1.HeaderPlaceholders, ' '), table.unpack( F1.Header))) - for i = 1, #F1.ValuesList do - local sLine = GetFormattedLine( F1.ValuesList[i], F1.ValuesPlaceholders, F1.FieldFixLength) - table.insert( Lines, sLine) - end - - -- linea vuota - table.insert( Lines, '') - - -- F2 - panels - table.insert( Lines, string.format( table.concat( F2.HeaderPlaceholders, ' '), table.unpack( F2.Header))) - for i = 1, #F2.ValuesList do - local sLine = GetFormattedLine( F2.ValuesList[i], F2.ValuesPlaceholders, F2.FieldFixLength) - table.insert( Lines, sLine) - end - - -- linea vuota - table.insert( Lines, '') - - -- F7 - table.insert( Lines, string.format( table.concat( F7.HeaderPlaceholders, ' '), table.unpack( F7.Header))) - for i = 1, #F7.ValuesList do - local sLine = GetFormattedLine( F7.ValuesList[i], F7.ValuesPlaceholders, F7.FieldFixLength) - table.insert( Lines, sLine) - end - - -- linea vuota - table.insert( Lines, '') - - -- F7b - table.insert( Lines, string.format( table.concat( F7b.HeaderPlaceholders, ' '), table.unpack( F7b.Header))) - - -- linea vuota - table.insert( Lines, '') - - -- F8 - table.insert( Lines, string.format( table.concat( F8.HeaderPlaceholders, ' '), table.unpack( F8.Header))) - - -- linea vuota - table.insert( Lines, '') - - -- F9 - table.insert( Lines, string.format( table.concat( F9.HeaderPlaceholders, ' '), table.unpack( F9.Header))) - - -- linea vuota - table.insert( Lines, '') - - -- F3 - table.insert ( Lines, string.format( table.concat( F3.HeaderPlaceholders, ' '), table.unpack( F3.Header))) - - -- E0 - table.insert( Lines, string.format( table.concat( E0.HeaderPlaceholders, ' '), table.unpack( E0.Header))) - - -- linea vuota - table.insert( Lines, '') - - return Lines + return LinesToWriteList end local function BuildCuttingList( PanelList, sOutputType) - local LinesToWrite = {} + local LinesToWriteList = {} local SheetList = GetSheetList() local ProjectInfo = GetProjectInfo() local dRequiredThickness = PanelList[1].dThickness @@ -293,15 +288,15 @@ local function BuildCuttingList( PanelList, sOutputType) -- Casadei if sOutputType == 'CUTTY' then - LinesToWrite = BuildCuttingList_Cutty( PanelList, ActualSheetList, ProjectInfo) + LinesToWriteList = BuildCuttingList_Cutty( PanelList, ActualSheetList, ProjectInfo) - -- Homag Optimat + -- Homag elseif sOutputType == 'HOMAG' then end - return LinesToWrite + return LinesToWriteList end @@ -341,18 +336,20 @@ function PanelSaw.GenerateCuttingList( sOutputType) if sOutputType then -- costruzione lista istruzioni - local LinesToWrite = BuildCuttingList( PanelListSingleMaterial, sOutputType) + local LinesToWriteList = BuildCuttingList( PanelListSingleMaterial, sOutputType) - -- scrittura file - local sFilename = sCurrentNgePath .. 'CutList-' .. sCurrentNgeName .. '-' .. key .. '-' .. sOutputType - sFilename = sFilename:gsub( '%.', '_') - local hFile, nFileErr = io.open( sFilename, 'w') - if not hFile then - EgtOutLog( 'Error creating cutting list : IO error ' .. tostring( nFileErr)) - return false + for i = 1, #LinesToWriteList do + -- scrittura file + local sFilename = sCurrentNgePath .. 'CutList-' .. sCurrentNgeName .. '-' .. key .. '-' .. i .. sOutputType + sFilename = sFilename:gsub( '%.', '_') + local hFile, nFileErr = io.open( sFilename, 'w') + if not hFile then + EgtOutLog( 'Error creating cutting list : IO error ' .. tostring( nFileErr)) + return false + end + hFile:write( table.concat( LinesToWriteList[i], "\n")) + hFile:close() end - hFile:write( table.concat( LinesToWrite, "\n")) - hFile:close() -- se nessun tipo si deve scrivere un json semplice else diff --git a/LuaLibs/WallLib.lua b/LuaLibs/WallLib.lua index 3796cb8..4f411d9 100644 --- a/LuaLibs/WallLib.lua +++ b/LuaLibs/WallLib.lua @@ -552,5 +552,27 @@ function WallLib.IsFeatureCuttingEntireSection( b3Proc, dRawW, dRawH, dRawL) return ( ( ( abs( b3Proc:getDimY() - dRawW) < 10 * GEO.EPS_SMALL or b3Proc:getDimY() > dRawW) or ( abs( b3Proc:getDimX() - dRawL) < 10 * GEO.EPS_SMALL or b3Proc:getDimX() > dRawL)) and (abs(b3Proc:getDimZ() - dRawH) < 10 * GEO.EPS_SMALL or b3Proc:getDimZ() > dRawH)) end +------------------------------------------------------------------------------------------------------------- +-- Splitta una tabella in tabelle di dimensioni massima nMaxItemsCount +function WallLib.SplitTableInChunks( Table, nChunkSize) + local Result = {} + local Chunk = {} + + for i, v in ipairs( Table) do + table.insert( Chunk, v) + if #Chunk == nChunkSize then + table.insert( Result, Chunk) + Chunk = {} + end + end + + -- se rimangono elementi, li aggiungo + if #Chunk > 0 then + table.insert( Result, Chunk) + end + + return Result +end + ------------------------------------------------------------------------------------------------------------- return WallLib