cd0d0fe1c9
- aggiunta possibilità di posizionare i pezzi nei quattro angoli della tavola (da WD.ORIG_CORNER con valori BL,TL,BR,TR) - corretta classificazione Tagli con Lama.
284 lines
11 KiB
Lua
284 lines
11 KiB
Lua
-- WallExec.lua by Egaltech s.r.l. 2020/11/12
|
|
-- Libreria esecuzione lavorazioni per Pareti
|
|
|
|
-- Tabella per definizione modulo
|
|
local WallExec = {}
|
|
|
|
-- Include
|
|
require( 'EgtBase')
|
|
|
|
-- Carico i dati globali e libero tutti gli altri
|
|
_G.package.loaded.WallData = nil
|
|
local WD = require( 'WallData')
|
|
|
|
-- Carico le librerie
|
|
_G.package.loaded.WMachiningLib = nil
|
|
local WM = require( 'WMachiningLib')
|
|
_G.package.loaded.WallLib = nil
|
|
local WL = require( 'WallLib')
|
|
_G.package.loaded.WProcessCut = nil
|
|
local Cut = require( 'WProcessCut')
|
|
_G.package.loaded.WProcessLapJoint = nil
|
|
local LapJoint = require( 'WProcessLapJoint')
|
|
_G.package.loaded.WProcessDrill = nil
|
|
local Drill = require( 'WProcessDrill')
|
|
_G.package.loaded.WProcessFreeContour = nil
|
|
local FreeContour = require( 'WProcessFreeContour')
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
-- *** Inserimento delle pareti nel pannello ***
|
|
-------------------------------------------------------------------------------------------------------------
|
|
function WallExec.ProcessWalls( dRawL, dRawW, dRawH, vWall)
|
|
|
|
-- Creazione nuovo gruppo di lavoro
|
|
local sMgName = EgtGetMachGroupNewName( 'Mach')
|
|
local NewMgId = EgtAddMachGroup( sMgName)
|
|
if not NewMgId then
|
|
local sOut = 'Errore nella creazione del gruppo di lavoro ' .. sMgName
|
|
return false, sOut
|
|
end
|
|
-- Impostazione della tavola
|
|
EgtSetTable( 'Tab')
|
|
-- Area tavola
|
|
local b3Tab = EgtGetTableArea()
|
|
-- Calcolo posizione estremo di riferimento della tavola rispetto a sua origine in BL
|
|
local OrigOnTab
|
|
local nCorner
|
|
if WD.ORIG_CORNER == 'TL' then
|
|
nCorner = MCH_CR.TL
|
|
OrigOnTab = Point3d( 0, b3Tab:getDimY(), 0)
|
|
elseif WD.ORIG_CORNER == 'BL' then
|
|
nCorner = MCH_CR.BL
|
|
OrigOnTab = Point3d(0, 0, 0)
|
|
elseif WD.ORIG_CORNER == 'TR' then
|
|
nCorner = MCH_CR.TR
|
|
OrigOnTab = Point3d( b3Tab:getDimX(), b3Tab:getDimY(), 0)
|
|
else -- 'BR'
|
|
nCorner = MCH_CR.BR
|
|
OrigOnTab = Point3d( b3Tab:getDimX(), 0, 0)
|
|
end
|
|
-- Impostazione dell'attrezzaggio di default
|
|
EgtImportSetup()
|
|
-- Creazione del grezzo e suo posizionamento in macchina
|
|
local nRaw = EgtAddRawPart( Point3d(0,0,0), dRawL, dRawW, dRawH, WD.RAWCOL)
|
|
EgtMoveToCornerRawPart( nRaw, OrigOnTab, nCorner)
|
|
-- Inserimento dei pezzi nel grezzo
|
|
for i = 1, #vWall do
|
|
-- assegno identificativo pezzo
|
|
local Pz = vWall[i].Id
|
|
-- dati del pezzo
|
|
local b3Part = EgtGetBBoxGlob( Pz or GDB_ID.NULL, GDB_BB.EXACT)
|
|
local b3Solid = vWall[i].Box
|
|
if b3Part:isEmpty() or b3Solid:isEmpty() then break end
|
|
local PartLen = b3Solid:getDimX()
|
|
local PartWidth = b3Solid:getDimY()
|
|
local PartHeight = b3Solid:getDimZ()
|
|
-- creo o pulisco gruppo geometrie aggiuntive
|
|
if not WL.CreateOrEmptyAddGroup( Pz) then
|
|
local sOut = 'Error creating Additional Group in Part ' .. tostring( Pz)
|
|
return false, sOut
|
|
end
|
|
-- inserisco il pezzo nel grezzo
|
|
EgtDeselectPartObjs( Pz)
|
|
local ptPos = Point3d( dRawL - vWall[i].PosX - PartLen, vWall[i].PosZ, ( dRawH - PartHeight) / 2)
|
|
EgtAddPartToRawPart( Pz, ptPos, nRaw)
|
|
end
|
|
return true
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
-- *** Inserimento delle lavorazioni nelle pareti ***
|
|
-------------------------------------------------------------------------------------------------------------
|
|
local function CollectFeatures( PartId, b3Raw)
|
|
-- recupero le feature
|
|
local vProc = {}
|
|
local LayerId = {}
|
|
LayerId[1] = EgtGetFirstNameInGroup( PartId or GDB_ID.NULL, 'Outline')
|
|
LayerId[2] = EgtGetFirstNameInGroup( PartId or GDB_ID.NULL, 'Processings')
|
|
for nInd = 1, #LayerId do
|
|
local ProcId = EgtGetFirstInGroup( LayerId[nInd] or GDB_ID.NULL)
|
|
while ProcId do
|
|
local nEntType = EgtGetType( ProcId)
|
|
if nEntType == GDB_TY.SRF_MESH or nEntType == GDB_TY.EXT_TEXT or
|
|
nEntType == GDB_TY.CRV_LINE or nEntType == GDB_TY.CRV_ARC or nEntType == GDB_TY.CRV_BEZ or nEntType == GDB_TY.CRV_COMPO then
|
|
local nGrp = EgtGetInfo( ProcId, 'GRP', 'i')
|
|
local nPrc = EgtGetInfo( ProcId, 'PRC', 'i')
|
|
local nDo = EgtGetInfo( ProcId, 'DO', 'i') or 1
|
|
local nCutId = EgtGetInfo( EgtGetParent( EgtGetParent( ProcId)), 'CUTID', 'i') or 0
|
|
local nTaskId = EgtGetInfo( ProcId, 'TASKID', 'i') or 0
|
|
if nGrp and nPrc and nDo == 1 then
|
|
local Proc = {}
|
|
Proc.PartId = PartId
|
|
Proc.Id = ProcId
|
|
Proc.Grp = nGrp
|
|
Proc.Prc = nPrc
|
|
Proc.Flg = 1
|
|
Proc.Fct = EgtSurfTmFacetCount( ProcId) or 0
|
|
Proc.Diam = 0
|
|
Proc.Fcs = 0
|
|
Proc.Fce = 0
|
|
Proc.CutId = nCutId
|
|
Proc.TaskId = nTaskId
|
|
Proc.Box = EgtGetBBoxGlob( ProcId, GDB_BB.STANDARD)
|
|
if Proc.Box and not Proc.Box:isEmpty() then
|
|
if Drill.Identify( Proc) then
|
|
Proc.Diam, Proc.Fcs, Proc.Fce = Drill.GetData( Proc, b3Raw)
|
|
end
|
|
table.insert( vProc, Proc)
|
|
else
|
|
EgtOutLog( ' Feature ' .. tostring( Proc.Id) .. ' is empty (no geometry)')
|
|
end
|
|
end
|
|
end
|
|
ProcId = EgtGetNext( ProcId)
|
|
end
|
|
end
|
|
return vProc
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
local function ClassifyFeatures( vProc, b3Raw)
|
|
for i = 1, #vProc do
|
|
local Proc = vProc[i]
|
|
-- se taglio
|
|
if Cut.Identify( Proc) then
|
|
local bOk = Cut.Classify( Proc, b3Raw)
|
|
if not bOk then Proc.Flg = 0 end
|
|
-- se tasca
|
|
elseif LapJoint.Identify( Proc) then
|
|
local bOk = LapJoint.Classify( Proc, b3Raw)
|
|
if not bOk then Proc.Flg = 0 end
|
|
-- se foratura
|
|
elseif Drill.Identify( Proc) then
|
|
local bOk = Drill.Classify( Proc, b3Raw)
|
|
if not bOk then Proc.Flg = 0 end
|
|
-- se contorno libero, outile o aperture
|
|
elseif FreeContour.Identify( Proc) then
|
|
local bOk = FreeContour.Classify( Proc, b3Raw)
|
|
if not bOk then Proc.Flg = 0 end
|
|
end
|
|
end
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
local function PrintFeatures( vProc)
|
|
EgtOutLog( ' *** Feature List ***')
|
|
for i = 1, #vProc do
|
|
local Proc = vProc[i]
|
|
local sOut = string.format( ' Part=%3d Proc=%3d Grp=%1d Prc=%3d TC=%2d/%d Flg=%2d Fcse=%1d,%1d Diam=%.2f Fct=%2d Box=%s',
|
|
Proc.PartId, Proc.Id, Proc.Grp, Proc.Prc, Proc.TaskId, Proc.CutId,
|
|
Proc.Flg, Proc.Fcs, Proc.Fce, Proc.Diam, Proc.Fct, tostring( Proc.Box))
|
|
EgtOutLog( sOut)
|
|
end
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
local function AddFeatureMachining( Proc, nRawId, b3Raw)
|
|
local bOk = true
|
|
local sErr = ''
|
|
-- se taglio (1/2-010-X) o taglio longitudinale (0/3/4-010-X)
|
|
if Cut.Identify( Proc) then
|
|
-- esecuzione taglio
|
|
bOk, sErr = Cut.Make( Proc, nRawId, b3Raw)
|
|
-- se tasca (3/4-030-X)
|
|
elseif LapJoint.Identify( Proc) then
|
|
-- esecuzione tasca
|
|
bOk, sErr = LapJoint.Make( Proc, nRawId, b3Raw)
|
|
-- se foratura ( 3/4-040-X)
|
|
elseif Drill.Identify( Proc) then
|
|
-- esecuzione foratura
|
|
bOk, sErr = Drill.Make( Proc, nRawId, b3Raw)
|
|
-- se contorno libero, outline o apertura ( 0/3/4-250/251/252-X)
|
|
elseif FreeContour.Identify( Proc) then
|
|
-- esecuzione contorno
|
|
bOk, sErr = FreeContour.Make( Proc, nRawId, b3Raw)
|
|
-- altrimenti feature non riconosciuta
|
|
else
|
|
bOk = false
|
|
sErr = 'Feature type non recognized for machining'
|
|
end
|
|
return bOk, sErr
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
local function MoveMachiningsAtEnd( nPhase, nType, sStartName)
|
|
local nOperId = EgtGetPhaseDisposition( nPhase)
|
|
local nLastId = EgtGetLastOperation()
|
|
local nInsertId = nLastId
|
|
while nOperId do
|
|
local nNextOperId = EgtGetNextOperation( nOperId)
|
|
if EgtGetOperationPhase( nOperId) == nPhase and EgtGetOperationType( nOperId) == nType and
|
|
( not sStartName or string.sub( EgtGetName( nOperId), 1, #sStartName) == sStartName) then
|
|
EgtRelocateGlob( nOperId, nInsertId, GDB_IN.AFTER)
|
|
nInsertId = nOperId
|
|
end
|
|
if nOperId == nLastId then
|
|
break
|
|
end
|
|
nOperId = nNextOperId
|
|
end
|
|
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
local function SortMachinings()
|
|
local nPhase = 1
|
|
-- Sposto i tagli di lama alla fine
|
|
MoveMachiningsAtEnd( nPhase, MCH_OY.SAWING)
|
|
-- Sposto i tagli con sega a catena dopo i tagli di lama
|
|
MoveMachiningsAtEnd( nPhase, MCH_OY.MORTISING, 'Csaw_')
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
function WallExec.ProcessFeatures()
|
|
-- errori e stato
|
|
local nTotErr = 0
|
|
local Stats = {}
|
|
-- recupero il grezzo e il suo box
|
|
local nRawId = EgtGetFirstRawPart()
|
|
local b3Raw = EgtGetRawPartBBox( nRawId)
|
|
-- raccolgo l'elenco delle feature da lavorare, ciclando sui pezzi
|
|
local vProc = {}
|
|
local nPartId = EgtGetFirstPartInRawPart( nRawId)
|
|
while nPartId do
|
|
-- recupero le feature di lavorazione della parete
|
|
local vPartProc = CollectFeatures( nPartId, b3Raw)
|
|
vProc = EgtJoinTables( vProc, vPartProc)
|
|
nPartId = EgtGetNextPartInRawPart( nPartId)
|
|
end
|
|
-- classifico le feature
|
|
ClassifyFeatures( vProc, b3Raw)
|
|
-- ordino le feature
|
|
-- *** TODO ***
|
|
-- debug
|
|
if EgtGetDebugLevel() >= 1 then
|
|
PrintFeatures( vProc)
|
|
end
|
|
-- inserisco le lavorazioni
|
|
for i = 1, #vProc do
|
|
-- creo la lavorazione
|
|
local Proc = vProc[i]
|
|
if Proc.Flg ~= 0 then
|
|
local bOk, sMsg = AddFeatureMachining( Proc, nRawId, b3Raw)
|
|
if not bOk then
|
|
nTotErr = nTotErr + 1
|
|
table.insert( Stats, {Err=1, Msg=sMsg, Rot=0, CutId=Proc.CutId, TaskId=Proc.TaskId})
|
|
elseif sMsg and #sMsg > 0 then
|
|
table.insert( Stats, {Err=-1, Msg=sMsg, Rot=0, CutId=Proc.CutId, TaskId=Proc.TaskId})
|
|
else
|
|
table.insert( Stats, {Err=0, Msg='', Rot=0, CutId=Proc.CutId, TaskId=Proc.TaskId})
|
|
end
|
|
else
|
|
local sMsg = 'Feature not machinable by orientation'
|
|
table.insert( Stats, {Err=1, Msg=sMsg, Rot=0, CutId=Proc.CutId, TaskId=Proc.TaskId})
|
|
end
|
|
end
|
|
-- riordino le lavorazioni
|
|
SortMachinings()
|
|
-- restituzione risultati
|
|
return ( nTotErr == 0), Stats
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------
|
|
return WallExec
|