Merge commit '62ca7479c72d02c99665d0f4c3a85a759ae2a5e9' into STR0002_ImproveSplitting

This commit is contained in:
andrea.villa
2024-06-10 15:25:45 +02:00
2 changed files with 89 additions and 93 deletions
+59 -65
View File
@@ -223,7 +223,7 @@ end
-------------------------------------------------------------------------------------------------------------
-- *** funzioni posizionamento pezzi all'interno della barra ***
-------------------------------------------------------------------------------------------------------------
function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, vBeam, bMachGroupOk)
function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, PARTS)
-- default per nuove costanti qualora non definite
BeamData.OVM_BLADE_HBEAM = ( BeamData.OVM_BLADE_HBEAM or 11)
@@ -236,13 +236,11 @@ function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, vBeam, b
BeamExec.CalcMinUnloadableRaw( dRawW, dRawH)
-- Creazione nuovo gruppo di lavoro
if not bMachGroupOk then
local sMgName = EgtGetMachGroupNewName( 'Mach_1')
local idNewMg = EgtAddMachGroup( sMgName)
if not idNewMg then
local sOut = 'Errore nella creazione del gruppo di lavoro ' .. sMgName
return false, sOut
end
local sMgName = EgtGetMachGroupNewName( 'Mach_1')
local idNewMg = EgtAddMachGroup( sMgName)
if not idNewMg then
local sOut = 'Errore nella creazione del gruppo di lavoro ' .. sMgName
return false, sOut
end
-- Impostazione della tavola
@@ -274,26 +272,23 @@ function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, vBeam, b
local dDeltaS = dOvmHead
local dDeltaSMin = 0
local dDeltaE = BeamData.OVM_MID
for i = 1, #vBeam do
-- assegno identificativo pezzo
local idPz = vBeam[i].id
for i = 1, #PARTS do
-- dati del pezzo
local b3Part = EgtGetBBoxGlob( idPz or GDB_ID.NULL, GDB_BB.EXACT)
local b3Solid = vBeam[i].b3Box
if b3Part:isEmpty() or b3Solid:isEmpty() then break end
local b3Part = EgtGetBBoxGlob( PARTS[i].id or GDB_ID.NULL, GDB_BB.EXACT)
if b3Part:isEmpty() or PARTS[i].b3Box:isEmpty() then break end
EgtOutLog( 'PartSez=' .. EgtNumToString( b3Part:getDimY(), 1) .. 'x' .. EgtNumToString( b3Part:getDimZ(), 1), 3)
-- se sezione compatibile e lunghezza disponibile sufficiente
local dPartLen = b3Solid:getDimX()
local dPartWidth = b3Solid:getDimY()
local dPartHeight = b3Solid:getDimZ()
local dPartLen = PARTS[i].b3Box:getDimX()
local dPartWidth = PARTS[i].b3Box:getDimY()
local dPartHeight = PARTS[i].b3Box:getDimZ()
local dNextLen = dLen - dDeltaS - dPartLen - dDeltaE
if (( abs( dPartWidth - dRawW) < 100 * GEO.EPS_SMALL and abs( dPartHeight - dRawH) < 100 * GEO.EPS_SMALL) or
( abs( dPartHeight - dRawW) < 100 * GEO.EPS_SMALL and abs( dPartWidth - dRawH) < 100 * GEO.EPS_SMALL)) and
dNextLen + dDeltaE >= 0 then
-- eventuale sovramateriale di testa
if i > 1 then
if vBeam[i].dPosX then
dDeltaS = max( vBeam[i].dPosX - ( dRawL - dLen), dDeltaSMin)
if PARTS[i].dPosX then
dDeltaS = max( PARTS[i].dPosX - ( dRawL - dLen), dDeltaSMin)
else
dDeltaS = max( dOvmMid - dDeltaE, 0)
end
@@ -302,49 +297,54 @@ function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, vBeam, b
local dCrawLen = min( dPartLen + dDeltaS + dDeltaE, dLen)
local dDelta = dCrawLen - dPartLen - dDeltaS
-- creo e posiziono il grezzo
local idRaw = EgtAddRawPart( Point3d(0,0,0), dCrawLen, dRawW, dRawH, BeamData.RAWCOL)
EgtMoveToCornerRawPart( idRaw, BeamData.ptOriXR, BeamData.dPosXR)
EgtMoveRawPart( idRaw, Vector3d( dLen - dRawL, 0, 0))
PARTS[i].idRaw = EgtAddRawPart( Point3d(0,0,0), dCrawLen, dRawW, dRawH, BeamData.RAWCOL)
EgtMoveToCornerRawPart( PARTS[i].idRaw, BeamData.ptOriXR, BeamData.dPosXR)
EgtMoveRawPart( PARTS[i].idRaw, Vector3d( dLen - dRawL, 0, 0))
-- assegno ordine in lavorazione
nCnt = nCnt + 1
EgtSetInfo( idRaw, 'ORD', nCnt)
EgtSetInfo( PARTS[i].idRaw, 'ORD', nCnt)
-- creo o pulisco gruppo geometrie aggiuntive
if not BeamLib.CreateOrEmptyAddGroup( idPz) then
local sOut = 'Error creating Additional Group in Part ' .. tostring( idPz)
if not BeamLib.CreateOrEmptyAddGroup( PARTS[i].id) then
local sOut = 'Error creating Additional Group in Part ' .. tostring( PARTS[i].id)
return false, sOut
end
-- aggiungo faccia per taglio iniziale al pezzo
BeamLib.AddPartStartFace( idPz, b3Solid)
BeamLib.AddPartStartFace( PARTS[i].id, PARTS[i].b3Box)
-- se sovramateriale di testa, lo notifico
if dDeltaS > 0.09 then
EgtSetInfo( idRaw, 'HOVM', dDeltaS)
EgtSetInfo( PARTS[i].idRaw, 'HOVM', dDeltaS)
if idPrevRaw then
EgtSetInfo( idPrevRaw, 'BDST', dDeltaS + dPrevDelta)
end
end
if dDeltaE > 0.09 then
EgtSetInfo( idRaw, 'TOVM', dDeltaE)
EgtSetInfo( PARTS[i].idRaw, 'TOVM', dDeltaE)
end
-- aggiungo faccia per taglio finale al pezzo
BeamLib.AddPartEndFace( idPz, b3Solid)
BeamLib.AddPartEndFace( PARTS[i].id, PARTS[i].b3Box)
-- inserisco il pezzo nel grezzo
EgtDeselectPartObjs( idPz)
local ptPos = b3Part:getMin() - b3Solid:getMin() + Vector3d( dDelta, ( dRawW - dPartWidth) / 2, ( dRawH - dPartHeight) / 2)
EgtAddPartToRawPart( idPz, ptPos, idRaw)
EgtDeselectPartObjs( PARTS[i].id)
local ptPos = b3Part:getMin() - PARTS[i].b3Box:getMin() + Vector3d( dDelta, ( dRawW - dPartWidth) / 2, ( dRawH - dPartHeight) / 2)
EgtAddPartToRawPart( PARTS[i].id, ptPos, PARTS[i].idRaw)
if abs( dPartWidth - dRawW) > 100 * GEO.EPS_SMALL then
-- rotazione attorno a centro geometria complessiva del pezzo
EgtRotatePartInRawPart( idPz, X_AX(), 90)
EgtRotatePartInRawPart( PARTS[i].id, X_AX(), 90)
-- correggo per eccentricità solido rispetto a geometria complessiva del pezzo
local vtEccOri = b3Solid:getCenter() - b3Part:getCenter()
local vtEccOri = PARTS[i].b3Box:getCenter() - b3Part:getCenter()
local vtEccRot = Vector3d( vtEccOri)
vtEccRot:rotate( X_AX(), 90)
EgtMovePartInRawPart( idPz, ( vtEccOri - vtEccRot))
EgtMovePartInRawPart( PARTS[i].id, ( vtEccOri - vtEccRot))
end
-- aggiorno la lunghezza residua della barra
dLen = dLen - dCrawLen
-- aggiorno grezzo precedente
idPrevRaw = idRaw
idPrevRaw = PARTS[i].idRaw
dPrevDelta = dDelta
PARTS[i].dDistanceToNextPiece = dDelta
PARTS[i].dRestLength = dLen
PARTS[i].b3Raw = EgtGetRawPartBBox( PARTS[i].idRaw)
PARTS[i].b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( PARTS[i].id, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD)
else
local sOut = 'Error: part L(' .. EgtNumToString( dPartLen, 1) .. ') too big for raw part L(' .. EgtNumToString( dLen - 0.1, 1) .. ')'
return false, sOut
@@ -359,6 +359,7 @@ function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, vBeam, b
-- Se rimasto materiale aggiungo grezzo dell'avanzo
if dLen > 10 then
PARTS[#PARTS].bNextIsRaw = true
local idRaw = EgtAddRawPart( Point3d(0,0,0), dLen, dRawW, dRawH, BeamData.RAWCOL)
EgtMoveToCornerRawPart( idRaw, BeamData.ptOriXR, BeamData.dPosXR)
EgtMoveRawPart( idRaw, Vector3d( dLen - dRawL, 0, 0))
@@ -467,8 +468,8 @@ local function CollectFeatures( Part)
-- recupero le feature
local vProc = {}
local LayerId = {}
LayerId[1] = BeamLib.GetAddGroup( Part.idPart)
LayerId[2] = EgtGetFirstNameInGroup( Part.idPart or GDB_ID.NULL, 'Processings')
LayerId[1] = BeamLib.GetAddGroup( Part.id)
LayerId[2] = EgtGetFirstNameInGroup( Part.id or GDB_ID.NULL, 'Processings')
for nInd = 1, 2 do
local ProcId = EgtGetFirstInGroup( LayerId[nInd] or GDB_ID.NULL)
while ProcId do
@@ -480,7 +481,7 @@ local function CollectFeatures( Part)
local nDo = EgtGetInfo( ProcId, 'DO', 'i') or 1
if nGrp and nPrc and nDo == 1 then
local Proc = {}
Proc.idPart = Part.idPart
Proc.idPart = Part.id
Proc.id = ProcId
-- id della feature btl ( se non presente info, si prende id dell'entità geometrica)
Proc.idFeature = EgtGetInfo( Proc.id, 'PRID', 's') or Proc.id
@@ -864,21 +865,15 @@ local function PrintFeatures( vProc, Part)
end
-------------------------------------------------------------------------------------------------------------
function BeamExec.ProcessFeatures()
function BeamExec.ProcessFeatures( PARTS)
-- ciclo sui pezzi
local nTotErr = 0
local Stats = {}
local nOrd = 1
local Part = {}
Part.idRaw = EgtGetFirstRawPart()
while Part.idRaw do
-- verifico che il grezzo contenga pezzi oppure sia abbastanza lungo da essere scaricato coi carrelli
Part.idPart = EgtGetFirstPartInRawPart( Part.idRaw)
Part.b3Raw = EgtGetRawPartBBox( Part.idRaw)
Part.b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( Part.idPart, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD)
if not Part.idPart and Part.b3Raw:getDimX() < BeamData.dMinRaw then break end
for nPart = 1, #PARTS do
if not PARTS[nPart].id and PARTS[nPart].b3Raw:getDimX() < BeamData.dMinRaw then break end
-- per ogni rotazione, calcolo come lavorare le feature per decidere posizionamento iniziale e in che rotazione verranno lavorate le singole feature
local vProcRot = {}
@@ -896,31 +891,31 @@ end
for dRotIndex = 1, 4 do
-- recupero le feature di lavorazione della trave
table.insert( vProcRot, CollectFeatures( Part))
table.insert( vProcRot, CollectFeatures( PARTS[nPart]))
-- recupero informazioni ausiliarie feature e dipendenze tra feature stesse
-- TODO le dipendenze cambiano in base alla rotazione del pezzo? probabilmente no
vProcRot[dRotIndex] = GetFeatureInfoAndDependency( vProcRot[dRotIndex], Part)
vProcRot[dRotIndex] = GetFeatureInfoAndDependency( vProcRot[dRotIndex], PARTS[nPart])
-- sceglie la strategia migliore tra quelle disponibili ( presenti nella tabella vProcRot[dRotIndex].AvailableStrategies)
vProcRot[dRotIndex] = GetBestStrategy( vProcRot[dRotIndex], Part)
vProcRot[dRotIndex] = GetBestStrategy( vProcRot[dRotIndex], PARTS[nPart])
-- ruoto il grezzo per calcolare la fattibilità delle lavorazioni nella prossima rotazione
-- vettore movimento grezzi per rotazione di 90deg ogni step
local dDeltaYZ = Part.b3Raw:getDimY() - Part.b3Raw:getDimZ()
local dDeltaYZ = PARTS[nPart].b3Raw:getDimY() - PARTS[nPart].b3Raw:getDimZ()
local vtMove = Vector3d( 0, dDeltaYZ / 2 * EgtIf( BeamData.RIGHT_LOAD, -1, 1), dDeltaYZ / 2)
local bPreMove = ( dDeltaYZ < 0)
-- ruoto le travi della fase corrente
if bPreMove then
EgtMoveRawPart( Part.idRaw, vtMove)
EgtMoveRawPart( PARTS[nPart].idRaw, vtMove)
end
EgtRotateRawPart( Part.idRaw, X_AX(), EgtIf( BeamData.RIGHT_LOAD, -90, 90))
EgtRotateRawPart( PARTS[nPart].idRaw, X_AX(), EgtIf( BeamData.RIGHT_LOAD, -90, 90))
if not bPreMove then
EgtMoveRawPart( Part.idRaw, vtMove)
EgtMoveRawPart( PARTS[nPart].idRaw, vtMove)
end
-- aggiorno info pezzo
Part.b3Raw = EgtGetRawPartBBox( Part.idRaw)
Part.b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( Part.idPart, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD)
PARTS[nPart].b3Raw = EgtGetRawPartBBox( PARTS[nPart].idRaw)
PARTS[nPart].b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( PARTS[nPart].id, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD)
end
@@ -941,17 +936,17 @@ end
if nOrd == 1 then
EgtSetCurrPhase( 1)
else
BeamLib.AddPhaseWithRawParts( Part, BeamData.ptOriXR, BeamData.dPosXR, 0)
BeamLib.AddPhaseWithRawParts( PARTS[nPart], BeamData.ptOriXR, BeamData.dPosXR, 0)
end
local nPhase = EgtGetCurrPhase()
local nDispId = EgtGetPhaseDisposition( nPhase)
EgtSetInfo( nDispId, 'TYPE', EgtIf( Part.idPart, 'START', 'REST'))
EgtSetInfo( nDispId, 'TYPE', EgtIf( PARTS[nPart].id, 'START', 'REST'))
EgtSetInfo( nDispId, 'ORD', nOrd)
EgtOutLog( ' *** Phase=' .. tostring( nPhase) .. ' Raw=' .. tostring( Part.idRaw) .. ' Part=' .. tostring( Part.idPart) .. ' ***', 1)
EgtOutLog( ' *** Phase=' .. tostring( nPhase) .. ' Raw=' .. tostring( PARTS[nPart].idRaw) .. ' Part=' .. tostring( PARTS[nPart].id) .. ' ***', 1)
-- debug
if EgtGetDebugLevel() >= 1 then
PrintFeatures( vProc, Part)
PrintFeatures( vProc, PARTS[nPart])
end
EgtOutLog( ' *** AddMachinings ***', 1)
@@ -964,14 +959,14 @@ end
-- TODO da fare
MACHININGS = {}
-- esegue le strategie migliori che ha precedentemente scelto e salva le lavorazioni nella lista globale
CalculateMachinings( vProc, Part)
CalculateMachinings( vProc, PARTS[nPart])
-- TODO riordinare lavorazioni ottimizzando cambio utensile/spezzone ecc..., mantenendo dipendenze definite prima
-- ordino le lavorazioni
-- OrderMachining( vProc, Part)
-- OrderMachining( vProc, PARTS[nPart])
-- aggiunge effettivamente le lavorazioni
MachiningLib.AddOperations( vProc, Part)
MachiningLib.AddOperations( vProc, PARTS[nPart])
-- TODO da rimuovere o lasciare solo per debug
@@ -985,7 +980,6 @@ end
EgtOutLog( ' *** End AddMachinings ***', 1)
-- passo al grezzo successivo
nOrd = nOrd + 1
Part.idRaw = EgtGetNextRawPart( Part.idRaw)
end
-- Aggiornamento finale di tutto
+30 -28
View File
@@ -60,11 +60,13 @@ end
local BeamExec = require( 'BeamExec')
-- Variabili globali
PARTS = {}
-- Carico i dati globali
local BeamData = require( 'BeamData')
-- Variabili di modulo
local vBeam = {}
local dRawW
local dRawH
@@ -79,47 +81,47 @@ local function MyProcessInputData()
local nPartId = EgtGetParent( EgtGetParent( nId or GDB_ID.NULL) or GDB_ID.NULL)
if nPartId then
local bFound = false
for i = 1, #vBeam do
if vBeam[i].id == nPartId then
for i = 1, #PARTS do
if PARTS[i].id == nPartId then
bFound = true
break
end
end
if not bFound then
table.insert( vBeam, { nInd = #vBeam + 1, id = nPartId, sName = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))})
table.insert( PARTS, { nInd = #PARTS + 1, id = nPartId, sName = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))})
end
end
nId = EgtGetNextSelectedObj()
end
if #vBeam == 0 then
if #PARTS == 0 then
EgtOutBox( 'Non sono state selezionate travi', 'Lavora Travi', 'ERROR')
return false
else
local sOut = ''
for i = 1, #vBeam do
sOut = sOut .. vBeam[i].sName .. ', '
for i = 1, #PARTS do
sOut = sOut .. PARTS[i].sName .. ', '
end
sOut = sOut:sub( 1, -3)
EgtOutLog( 'Travi selezionate : ' .. sOut, 1)
end
-- Ne recupero e verifico le dimensioni
for i = 1, #vBeam do
local Ls = EgtGetFirstNameInGroup( vBeam[i].id, 'Box')
for i = 1, #PARTS do
local Ls = EgtGetFirstNameInGroup( PARTS[i].id, 'Box')
local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD)
if not b3Solid then
EgtOutBox( 'Box non definito per la trave ' .. vBeam[i].sName, 'Lavora Travi', 'ERROR')
EgtOutBox( 'Box non definito per la trave ' .. PARTS[i].sName, 'Lavora Travi', 'ERROR')
return false
else
vBeam[i].b3Box = b3Solid
PARTS[i].b3Box = b3Solid
end
end
dRawW = vBeam[1].b3Box:getDimY()
dRawH = vBeam[1].b3Box:getDimZ()
dRawW = PARTS[1].b3Box:getDimY()
dRawH = PARTS[1].b3Box:getDimZ()
local vBeamErr = {}
for i = 2, #vBeam do
local dDimW = vBeam[i].b3Box:getDimY()
local dDimH = vBeam[i].b3Box:getDimZ()
for i = 2, #PARTS do
local dDimW = PARTS[i].b3Box:getDimY()
local dDimH = PARTS[i].b3Box:getDimZ()
if ( abs( dDimW - dRawW) > 10 * GEO.EPS_SMALL or abs( dDimH - dRawH) > 10 * GEO.EPS_SMALL) and
( abs( dDimH - dRawW) > 10 * GEO.EPS_SMALL or abs( dDimW - dRawH) > 10 * GEO.EPS_SMALL) then
table.insert( vBeamErr, i)
@@ -128,9 +130,9 @@ local function MyProcessInputData()
if #vBeamErr > 0 then
local sOut = 'Rimosse travi con sezioni diverse dalla prima :\n'
for i = #vBeamErr, 1, -1 do
sOut = sOut .. vBeam[vBeamErr[i]].sName .. '\n'
EgtDeselectPartObjs( vBeam[vBeamErr[i]].id)
table.remove( vBeam, vBeamErr[i])
sOut = sOut .. PARTS[vBeamErr[i]].sName .. '\n'
EgtDeselectPartObjs( PARTS[vBeamErr[i]].id)
table.remove( PARTS, vBeamErr[i])
end
EgtOutLog( sOut, 1)
EgtOutBox( sOut, 'Lavora Travi', 'INFO')
@@ -165,11 +167,11 @@ local function MyProcessBeams()
-- Lunghezza totale delle travi
local dTotLen = 0
for i = 1, #vBeam - 1 do
dTotLen = dTotLen + vBeam[i].b3Box:getDimX()
for i = 1, #PARTS - 1 do
dTotLen = dTotLen + PARTS[i].b3Box:getDimX()
end
dTotLen = dTotLen + max( vBeam[#vBeam].b3Box:getDimX(), BeamData.dMinRaw)
local dAddLen = BeamData.OVM_HEAD + ( #vBeam - 1) * BeamData.OVM_MID
dTotLen = dTotLen + max( PARTS[#PARTS].b3Box:getDimX(), BeamData.dMinRaw)
local dAddLen = BeamData.OVM_HEAD + ( #PARTS - 1) * BeamData.OVM_MID
EgtOutLog( 'Ltot : '..EgtNumToString( dTotLen, 1) .. ' Lagg : '..EgtNumToString( dAddLen, 1)..' MinUnloadRaw : '.. EgtNumToString( BeamData.dMinRaw + BeamData.OVM_MID, 1), 1)
-- Richiedo lunghezza del grezzo, sovramateriale di testa, forzatura verticale e ordinamento automatico secondo la lunghezza
@@ -256,7 +258,7 @@ local function MyProcessBeams()
-- Se richiesto, ordino le travi in senso di lunghezza crescente
local bOrd = ( vsVal[5] == 'true')
if bOrd then
table.sort( vBeam, function( B1, B2)
table.sort( PARTS, function( B1, B2)
if abs( B1.b3Box:getDimX() - B2.b3Box:getDimX()) < 1 then
return B1.nInd < B2.nInd
else
@@ -266,15 +268,15 @@ local function MyProcessBeams()
end
do
local sOut = ''
for i = 1, #vBeam do
sOut = sOut .. vBeam[i].sName .. ', '
for i = 1, #PARTS do
sOut = sOut .. PARTS[i].sName .. ', '
end
sOut = sOut:sub( 1, -3)
EgtOutLog( 'Travi ordinate : ' .. sOut, 1)
end
-- Sistemo le travi nel grezzo
local bOk, sErr = BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, vBeam)
local bOk, sErr = BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, PARTS)
if not bOk then
EgtOutLog( sErr)
EgtOutBox( sErr, 'Lavora Travi', 'ERROR')
@@ -288,7 +290,7 @@ end
-- *** Inserimento delle lavorazioni nelle travi ***
-------------------------------------------------------------------------------------------------------------
local function MyProcessFeatures()
local bOk, Stats = BeamExec.ProcessFeatures()
local bOk, Stats = BeamExec.ProcessFeatures( PARTS)
local nErrCnt = 0
local nWarnCnt = 0
local sOutput = ''