- in NestProcess creato il loop di base dello script. Mancano funzioni accessorie

This commit is contained in:
luca.mazzoleni
2026-05-14 16:44:12 +02:00
parent 0497877abb
commit f90dd95880
+40 -19
View File
@@ -15,6 +15,19 @@ local RawInventory = {
ActiveBeams = {}
}
function RawInventory:GetNewBeam( dLength)
local NewBeam = {
dTotalLength = dLength,
dResidual = dLength,
LastOffsetX = { 0, 0, 0, 0},
LastVtN = Vector3d( 1, 0, 0),
NestedParts = {}
}
return NewBeam
end
function RawInventory:BuildStock()
if #LEN ~= #QTY then
error( 'NestProcess: invalid stock data')
@@ -41,13 +54,7 @@ function RawInventory:AddActiveBeam( nStockIndex)
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 = {}
}
local NewBeam = self:GetNewBeam( CurrentStock.dLength)
table.insert( self.ActiveBeams, NewBeam)
return NewBeam
@@ -140,25 +147,39 @@ RawInventory:BuildStock()
-- 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
-- loop principale: scorre le barre, sia già attive che a stock, e le riempie nel modo migliore possibile
-- per ogni giro sceglie la soluzione con punteggio più alto
while true do
local BestMove
local HighestScore = GEO.INFINITO
local dHighestScore = -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
for i = 1, #RawInventory.ActiveBeams do
local CurrentMove = FindBestPartForBeam( RawInventory.ActiveBeams[i], JobPool)
if CurrentMove and CurrentMove.dScore > dHighestScore then
dHighestScore = CurrentMove.dScore
BestMove = CurrentMove
BestMove.nActiveBeamIndex = i
end
end
-- 2 Si provano le barre ancora a stock
for i = 1, #RawInventory.Stock do
local VirtualBeam = RawInventory:GetNewBeam( RawInventory.Stock[i].dLength)
if RawInventory.Stock[i].nCount > 0 then
local CurrentMove = FindBestPartForBeam( VirtualBeam, JobPool)
if CurrentMove and CurrentMove.dScore > dHighestScore then
dHighestScore = CurrentMove.dScore
BestMove = CurrentMove
BestMove.nStockIndex = i
end
end
end
-- 3 Procedi con nesting
if BestMove then
CommitBestMove()
else
break
end
end