Files
Dario Sassi ef5170b6e6 DataWall 3.1c1 :
- modificati CleanCorner per gestire utensili conici con angolo di apertura tra 30 e 45 gradi (inclinazione calcolata in automatico)
- piccola modifica a Process per rielaborare file bwe da EgtBeamWall.
2026-03-30 16:33:53 +02:00

314 lines
13 KiB
Lua

-- Process.lua by Egaltech s.r.l. 2026/03/30
-- Gestione calcolo disposizione e lavorazioni per Pareti
-- Si opera sulla macchina corrente
-- 2020/12/09 Come per BatchProcess.lua si gestiscono anche rotazioni di inversione con valori negativi.
-- 2021/10/27 Come per BatchProcess.lua nel controllo spessore si deve considerare anche PosY.
-- 2022/05/02 Consentito allargamento area disponibile per grezzi su tavola da WallData.
-- Intestazioni
require( 'EgtBase')
_ENV = EgtProtectGlobal()
EgtEnableDebug( false)
-- Imposto direttorio libreria specializzata per Travi
EgtAddToPackagePath( WALL.BASEDIR .. '\\LuaLibs\\?.lua')
-- Verifico che la macchina corrente sia abilitata per la lavorazione delle Pareti
local sMachDir = EgtGetCurrMachineDir()
if not sMachDir then
EgtOutBox( 'Errore nel caricamento della macchina corrente', 'Lavora Pareti', 'ERROR')
return
end
if not EgtExistsFile( sMachDir .. '\\Wall\\WallData.lua') then
EgtOutBox( 'La macchina corrente non è configurata per lavorare pareti', 'Lavora Pareti', 'ERROR')
return
end
-- Elimino direttori altre macchine e imposto direttorio macchina corrente per ricerca librerie
EgtRemoveBaseMachineDirFromPackagePath()
EgtAddToPackagePath( sMachDir .. '\\Wall\\?.lua')
-- Segnalazione avvio
EgtOutLog( '*** Wall Process Start ***', 1)
-- Carico le librerie
_G.package.loaded.WallExec = nil
local WE = require( 'WallExec')
local WL = require( 'WallLib')
-- Carico i dati globali
local WD = require( 'WallData')
-- Variabili di modulo
local vWall = {}
local dRawH
-------------------------------------------------------------------------------------------------------------
-- *** Recupero le pareti selezionate ***
-------------------------------------------------------------------------------------------------------------
local function MyProcessInputData()
-- Recupero le travi selezionate
local nId = EgtGetFirstSelectedObj()
while nId do
local nPartId = EgtGetParent( EgtGetParent( nId or GDB_ID.NULL) or GDB_ID.NULL)
if nPartId then
local bFound = false
for i = 1, #vWall do
if vWall[i].Id == nPartId then
bFound = true
break
end
end
if not bFound then
table.insert( vWall, { Id = nPartId, Name = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))})
end
end
nId = EgtGetNextSelectedObj()
end
if #vWall == 0 then
EgtOutBox( 'Non sono state selezionate pareti', 'Lavora Pareti', 'ERROR')
return false
else
local sOut = ''
for i = 1, #vWall do
sOut = sOut .. vWall[i].Name .. ', '
end
sOut = sOut:sub( 1, -3)
EgtOutLog( 'Pareti selezionate : ' .. sOut, 1)
end
-- Ne recupero le dimensioni
for i = 1, #vWall do
local Ls = EgtGetFirstNameInGroup( vWall[i].Id, 'Box')
local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD)
if not b3Solid then
EgtOutBox( 'Box non definito per la parete ' .. vWall[i].Name, 'Lavora Pareti', 'ERROR')
return false
else
vWall[i].Box = b3Solid
end
end
-- Ne recupero la posizione
local CurrX = 50
for i = 1, #vWall do
local PosX = EgtGetInfo( vWall[i].Id, 'POSX', 'd') or CurrX
vWall[i].PosX = PosX
CurrX = CurrX + vWall[i].Box:getDimX() + 50
if WD.USE_POSY then
local PosY = EgtGetInfo( vWall[i].Id, 'POSY', 'd') or 0
vWall[i].PosY = max( PosY, 0)
else
vWall[i].PosY = 0
end
local PosZ = EgtGetInfo( vWall[i].Id, 'POSZ', 'd') or 50
vWall[i].PosZ = PosZ
end
-- Recupero informazione se progetto o produzione
local bProj = ( EgtGetInfo( EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo') or GDB_ID.NULL, 'PROJECT', 'i') == 1)
-- Verifico se progetto deriva da BeamWall
local _, _, sExt = EgtSplitPath( EgtGetCurrFilePath() or '')
local bBwProj = ( ( string.upper( sExt or '') == '.BWE'))
-- Eseguo eventuali rotazioni e inversioni testa-coda
for i = 1, #vWall do
local b3Solid = vWall[i].Box
-- rotazione
local dRotAng = EgtGetInfo( vWall[i].Id, 'ROTATED', 'd')
if dRotAng then
if abs( dRotAng) > GEO.EPS_ANG_SMALL and not bBwProj and not EgtExistsInfo( vWall[i].Id, 'ROTATED_DONE') then
local ptRotCen = b3Solid:getCenter()
EgtRotate( vWall[i].Id, ptRotCen, X_AX(), dRotAng, GDB_RT.GLOB)
b3Solid:rotate( ptRotCen, X_AX(), dRotAng)
end
EgtSetInfo( vWall[i].Id, 'ROTATED_DONE', dRotAng)
end
-- inversione
local dInvAng = EgtGetInfo( vWall[i].Id, 'INVERTED', 'd')
if dInvAng then
if abs( dInvAng - 180) > GEO.EPS_ANG_SMALL and abs( dInvAng + 180) > GEO.EPS_ANG_SMALL and not bBwProj and not EgtExistsInfo( vWall[i].Id, 'INVERTED_DONE') then
local ptInvCen = b3Solid:getCenter()
EgtRotate( vWall[i].Id, ptInvCen, Z_AX(), dInvAng - 180, GDB_RT.GLOB)
b3Solid:rotate( ptInvCen, Z_AX(), dInvAng - 180)
end
EgtSetInfo( vWall[i].Id, 'INVERTED_DONE', dInvAng)
end
-- correzioni per rotazioni non centrate di produzioni TS3 (quasi sempre multipli di 90 deg)
local sType = EgtGetInfo( vWall[i].Id, 'TYPE', 's')
if not bProj and not bBwProj and dRotAng and dInvAng and sType ~= 'LAYER' then
if abs( dInvAng - 0) < GEO.EPS_ANG_SMALL then
if abs( dRotAng - 180) < GEO.EPS_ANG_SMALL then
vWall[i].PosZ = vWall[i].PosZ - vWall[i].Box:getDimY()
elseif abs( dRotAng - 270) < GEO.EPS_ANG_SMALL then
vWall[i].PosZ = vWall[i].PosZ - vWall[i].Box:getDimY()
end
elseif abs( dInvAng - 90) < GEO.EPS_ANG_SMALL or abs( dInvAng + 270) < GEO.EPS_ANG_SMALL then
vWall[i].PosZ = vWall[i].PosZ - vWall[i].Box:getDimY()
if abs( dRotAng - 180) < GEO.EPS_ANG_SMALL or abs( dRotAng + 180) < GEO.EPS_ANG_SMALL then
vWall[i].PosX = vWall[i].PosX - vWall[i].Box:getDimX()
elseif abs( dRotAng - 270) < GEO.EPS_ANG_SMALL or abs( dRotAng + 90) < GEO.EPS_ANG_SMALL then
vWall[i].PosX = vWall[i].PosX - vWall[i].Box:getDimX()
end
elseif abs( dInvAng - 180) < GEO.EPS_ANG_SMALL or abs( dInvAng + 180) < GEO.EPS_ANG_SMALL then
vWall[i].PosX = vWall[i].PosX - vWall[i].Box:getDimX()
if abs( dRotAng - 0) < GEO.EPS_ANG_SMALL then
vWall[i].PosZ = vWall[i].PosZ - vWall[i].Box:getDimY()
elseif abs( dRotAng - 270) < GEO.EPS_ANG_SMALL or abs( dRotAng + 90) < GEO.EPS_ANG_SMALL then
vWall[i].PosZ = vWall[i].PosZ - vWall[i].Box:getDimY()
elseif abs( dRotAng - 90) < GEO.EPS_ANG_SMALL or abs( dRotAng + 270) < GEO.EPS_ANG_SMALL then
vWall[i].PosZ = vWall[i].PosZ - vWall[i].Box:getDimY()
end
elseif abs( dInvAng - 270) < GEO.EPS_ANG_SMALL or abs( dInvAng + 90) < GEO.EPS_ANG_SMALL then
if abs( dRotAng - 0) < GEO.EPS_ANG_SMALL then
vWall[i].PosX = vWall[i].PosX - vWall[i].Box:getDimX()
end
end
end
end
-- Ne verifico le dimensioni
dRawH = vWall[1].Box:getDimZ() + vWall[1].PosY
local vWallErr = {}
for i = 2, #vWall do
local dDimH = vWall[i].Box:getDimZ() + vWall[i].PosY
if abs( dDimH - dRawH) > 10 * GEO.EPS_SMALL then
table.insert( vWallErr, i)
end
end
if #vWallErr > 0 then
local sOut = 'Rimosse pareti con spessore diverso dalla prima :\n'
for i = #vWallErr, 1, -1 do
sOut = sOut .. vWall[vWallErr[i]].Name .. '\n'
EgtDeselectPartObjs( vWall[vWallErr[i]].Id)
table.remove( vWall, vWallErr[i])
end
EgtOutLog( sOut, 1)
EgtOutBox( sOut, 'Lavora Pareti', 'INFO')
EgtDraw()
return false
end
EgtDeselectAll()
return true
end
-------------------------------------------------------------------------------------------------------------
-- *** Inserimento delle pareti nel grezzo ***
-------------------------------------------------------------------------------------------------------------
local function MyProcessWalls()
-- Ingombro totale delle pareti
local b3Tot = BBox3d( ORIG())
for i = 1, #vWall do
local ptMin = Point3d( - vWall[i].PosX - vWall[i].Box:getDimX(), vWall[i].PosZ, 0)
local ptMax = Point3d( - vWall[i].PosX, vWall[i].PosZ + vWall[i].Box:getDimY(), 0)
b3Tot:Add( ptMin)
b3Tot:Add( ptMax)
end
local dBoxL = b3Tot:getDimX()
local dBoxW = b3Tot:getDimY()
EgtOutLog( 'Ltot : ' .. EgtNumToString( dBoxL, 1) .. ' Wtot : '.. EgtNumToString( dBoxW, 1), 1)
-- Eventuali dimensioni predefinite del pannello
local BtlInfoId = EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo') or GDB_ID.NULL
local dPanelLen = EgtGetInfo( BtlInfoId, 'PANELLEN', 'd') or WD.STD_RAW_LENGTH
local dPanelWidth = EgtGetInfo( BtlInfoId, 'PANELWIDTH', 'd') or WD.STD_RAW_WIDTH
-- Richiedo lunghezza del grezzo e sovramateriale di testa
local vsVal = EgtDialogBox( 'Lavora Pareti' .. ' (Ltot='.. EgtNumToString( dBoxL + 0.05, 1) .. ', Wtot=' .. EgtNumToString( dBoxW + 0.05, 1) .. ')',
{'Lunghezza grezzo', EgtNumToString( dPanelLen, 1)},
{'Larghezza grezzo', EgtNumToString( dPanelWidth, 1)})
if not vsVal then
EgtDraw()
return
end
local dRawL = EgtEvalNumExpr( vsVal[1])
if not dRawL then
local sOut = 'Lunghezza grezzo errata : ' .. vsVal[1]
EgtOutLog( sOut)
EgtOutBox( sOut, 'Lavora Pareti', 'WARNING')
EgtDraw()
return false
end
dRawL = min( dRawL, WD.MAX_LENGTH)
local dRawW = EgtEvalNumExpr( vsVal[2])
if not dRawW then
local sOut = 'Larghezza grezzo errata : ' .. vsVal[2]
EgtOutLog( sOut)
EgtOutBox( sOut, 'Lavora Pareti', 'WARNING')
EgtDraw()
return false
end
dRawW = min( dRawW, WD.MAX_WIDTH )
-- Verifico dimensioni massime grezzo
if dRawL > WD.MAX_LENGTH + 10 * GEO.EPS_SMALL or dRawW > WD.MAX_WIDTH + 10 * GEO.EPS_SMALL or dRawH > WD.MAX_HEIGHT + 10 * GEO.EPS_SMALL then
local sOut = 'Grezzo (' .. EgtNumToString( dRawL, 2) .. ' x ' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' ..
'oltre il limite della macchina ('..EgtNumToString( WD.MAX_LENGTH, 2)..' x '..EgtNumToString( WD.MAX_WIDTH, 2)..' x '..EgtNumToString( WD.MAX_HEIGHT, 2)..') '
EgtOutLog( sOut)
EgtOutBox( sOut, 'Lavora Pareti', 'WARNING')
EgtDraw()
return false
end
-- Verifico dimensioni minime del grezzo
if dRawL < WD.MIN_LENGTH - 10 * GEO.EPS_SMALL or dRawW < WD.MIN_WIDTH - 10 * GEO.EPS_SMALL or dRawH < WD.MIN_HEIGHT - 10 * GEO.EPS_SMALL then
local sOut = 'Grezzo (' .. EgtNumToString( dRawL, 2) .. ' x ' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' ..
'sotto il limite della macchina ('..EgtNumToString( WD.MIN_LENGTH, 2)..' x '..EgtNumToString( WD.MIN_WIDTH, 2)..' x '..EgtNumToString( WD.MIN_HEIGHT, 2)..')'
EgtOutLog( sOut)
EgtOutBox( sOut, 'Lavora Pareti', 'WARNING')
EgtDraw()
return false
end
-- Sistemo le pareti nel grezzo
return WE.ProcessWalls( dRawL, dRawW, dRawH, vWall)
end
-------------------------------------------------------------------------------------------------------------
-- *** Inserimento delle lavorazioni nelle travi ***
-------------------------------------------------------------------------------------------------------------
local function MyProcessFeatures()
local bOk, Stats = WE.ProcessFeatures()
local nErrCnt = 0
local nWarnCnt = 0
local sOutput = ''
for i = 1, #Stats do
if Stats[i].Err > 0 then
nErrCnt = nErrCnt + 1
sOutput = sOutput .. string.format( '[%d,%d] %s\n', Stats[i].CutId, Stats[i].TaskId, Stats[i].Msg)
elseif Stats[i].Err < 0 then
nWarnCnt = nWarnCnt + 1
sOutput = sOutput .. string.format( '[%d,%d] %s\n', Stats[i].CutId, Stats[i].TaskId, Stats[i].Msg)
end
end
if #sOutput > 0 then EgtOutLog( sOutput) end
if nErrCnt > 0 then
EgtOutBox( sOutput, 'Lavora Pareti', 'ERRORS')
EgtDraw()
return false
elseif nWarnCnt > 0 then
EgtOutBox( sOutput, 'Lavora Pareti', 'WARNINGS')
EgtDraw()
return true
end
return true
end
-------------------------------------------------------------------------------------------------------------
-- *** Esecuzione ***
-------------------------------------------------------------------------------------------------------------
if not MyProcessInputData() then return end
if not MyProcessWalls() then return end
-- Abilito Vmill
EgtSetInfo( EgtGetCurrMachGroup(), 'Vm', '1')
if not MyProcessFeatures() then return end