From 0497877abbe9845a2e8201f33893060b143f6e10 Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Thu, 14 May 2026 15:39:29 +0200 Subject: [PATCH] - in NestProcess ora si compilano correttamente le tabelle di grezzi e pezzi da nestare, in preparazione al neting --- NestProcess.lua | 158 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 113 insertions(+), 45 deletions(-) diff --git a/NestProcess.lua b/NestProcess.lua index 1a8a075..743780a 100644 --- a/NestProcess.lua +++ b/NestProcess.lua @@ -7,16 +7,6 @@ _ENV = EgtProtectGlobal() EgtEnableDebug( true) -- Include -local BeamLib = require( 'BeamLib') - ----------------------------------------------------------------------------------------------------------- --- stati che definiscono rotazione / inversione della parte -local STATE = { - STD = 1, -- Standard - ROT180 = 2, -- Rotazione 180deg attorno a X+ - INV = 3, -- Inversione (rotazione 180deg attorno a Z+) - INV_ROT180 = 4 -- Inversione + rotazione -} ---------------------------------------------------------------------------------------------------------- -- inventario grezzi @@ -32,16 +22,38 @@ function RawInventory:BuildStock() for i = 1, #LEN do self.Stock[#self.Stock + 1] = { - Length = LEN[i], - Count = QTY[i] + dLength = LEN[i], + nCount = QTY[i] } end return RawInventory end -function RawInventory:AddActiveBeam() - -- TODO da fare +-- aggiunge una nuova barra attiva rimuovendo il corrispondente dalla lista stock disponibili +function RawInventory:AddActiveBeam( nStockIndex) + + local CurrentStock = self.Stock[nStockIndex] + -- se barra disponibile posso aggiungerla a quelle attive + if CurrentStock and CurrentStock.nCount > 0 then + + -- update quantità a stock + CurrentStock.nCount = CurrentStock.nCount - 1 + + -- aggiungo una nuova barra attiva + local NewBeam = { + dTotalLength = CurrentStock.dLength, + dResidual = CurrentStock.dLength, + LastOffsetX = { 0, 0, 0, 0}, + LastVtN = Vector3d( 1, 0, 0), + NestedParts = {} + } + + table.insert( self.ActiveBeams, NewBeam) + return NewBeam + end + + return nil end ---------------------------------------------------------------------------------------------------------- @@ -49,48 +61,104 @@ end local PartTemplates = {} local JobPool = {} +function PartTemplates:GetInfoFromPart( id, sStateWithSide) + local OffsetX = {} + local vtN + + local sInfo = EgtGetInfo( id, sStateWithSide) + if not sInfo then + return + end + + local Info = EgtSplitString( sInfo, ';') + OffsetX = EgtSplitString( Info[1], ',') + vtN = VectorFromString( Info[2]) + + -- si convertono gli offset in numeri + for i = 1, #OffsetX do + OffsetX[i] = tonumber( OffsetX[i]) or 0 + end + + return OffsetX, vtN +end + function PartTemplates:AddPart( id) - PartTemplates[id] = {} - PartTemplates[id].dLength = EgtGetInfo( id, 'L', 'd') - -- TODO qua gli stati abilitati dovranno arrivare dalle alternatives - local VerticesHead = EgtSplitString( EgtGetInfo( id, 'HEADOFFSETX', 'd')) - local vtNHead = Vector3d( EgtSplitString( EgtGetInfo( id, 'HEADVTN', 'd'))) - local VerticesTail = EgtSplitString( EgtGetInfo( id, 'TAILOFFSETX', 'd')) - local vtNTail = Vector3d( EgtSplitString( EgtGetInfo( id, 'TAILVTN', 'd'))) - PartTemplates[id].States = { - [STATE.STD] = { - Head = { Vertices = VerticesHead, vtN = vtNHead}, - Tail = { Vertices = VerticesTail, vtN = vtNTail} - }, - [STATE.ROT180] = { - Head = { Vertices = BeamLib.RotateTableFromIndex( VerticesHead, 3), vtN = vtNHead}, - Tail = { Vertices = BeamLib.RotateTableFromIndex( VerticesTail, 3), vtN = vtNHead} - }, - [STATE.INV] = { - Head = { Vertices = VerticesTail, vtN = vtNTail}, - Tail = { Vertices = VerticesHead, vtN = vtNHead} - }, - [STATE.INV_ROT180] = { - Head = { Vertices = BeamLib.RotateTableFromIndex( VerticesTail, 3), vtN = vtNHead}, - Tail = { Vertices = BeamLib.RotateTableFromIndex( VerticesHead, 3), vtN = vtNHead} - } - } + self[id] = {} + self[id].dLength = EgtGetInfo( id, 'L', 'd') + self[id].States = {} + + local States = { '1000', '0010', '1000_INV', '0010_INV' } + + for _, sState in ipairs(States) do + local OffsetXHead, vtNHead = self:GetInfoFromPart( id, 'ALT' .. sState .. '_H') + local OffsetXTail, vtNTail = self:GetInfoFromPart( id, 'ALT' .. sState .. '_T') + + if OffsetXHead or OffsetXTail then + + if not OffsetXHead then + OffsetXHead = { 0, 0, 0, 0} + vtNHead = Vector3d( 1, 0, 0) + end + if not OffsetXTail then + OffsetXTail = { 0, 0, 0, 0} + vtNTail = Vector3d( -1, 0, 0) + end + + self[id].States[sState] = {} + local State = self[id].States[sState] + + State.Head = { + OffsetX = OffsetXHead, + vtN = vtNHead + } + State.Tail = { + OffsetX = OffsetXTail, + vtN = vtNTail + } + end + end end -- creazione combinata (si cicla una sola volta) di entrambe le tabelle local function BuildPartTemplatesAndJobPool() for id, nCount in pairs( PART) do PartTemplates:AddPart( id) + for _ = 1, nCount do + table.insert( JobPool, { id = id, bNested = false}) + end end return PartTemplates, JobPool end +---------------------------------------------------------------------------------------------------------- +-- script principale - - - - - +-- costruzione lista grezzi a stock disponibili RawInventory:BuildStock() -BuildPartTemplatesAndJobPool() \ No newline at end of file + +-- costruzione lista pezzi template con proprietà geometriche e lista pezzi fisici da nestare +BuildPartTemplatesAndJobPool() + +-- loop principale: scorre le barre, si già attive che a stock, e le riempie nel modo migliore possibile +while true do + local BestMove + local HighestScore = GEO.INFINITO + + -- 1 Si provano le barre già attive + + + -- 2 Si provano le barre ancora a stock + for i = 1, #RawInventory.Stock do + if RawInventory.Stock[i].nCount > 0 then + + end + end + + + -- 3 Procedi con nesting + + + + +end \ No newline at end of file