Files
DataWall/LuaLibs/WProcessLapJoint.lua
T
Dario Sassi 767e7287a5 DataWall :
- sistemazioni varie durante prime prove con macchina S3.
2020-07-11 09:40:28 +00:00

253 lines
10 KiB
Lua

-- WProcessLapJoint.lua by Egaltech s.r.l. 2020/07/10
-- Gestione calcolo mezzo-legno per Pareti
-- Tabella per definizione modulo
local WPL = {}
-- Include
require( 'EgtBase')
local WL = require( 'WallLib')
EgtOutLog( ' WProcessLapJoint started', 1)
-- Dati
local WD = require( 'WallData')
local WM = require( 'WMachiningLib')
---------------------------------------------------------------------
-- Riconoscimento della feature
function WPL.Identify( Proc)
return ( ( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 16) or
( ( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 17) or
( ( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 20) or
( ( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 30) or
( ( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 32) or
( ( Proc.Grp == 4) and Proc.Prc == 39)
end
---------------------------------------------------------------------
-- Classificazione della feature
function WPL.Classify( Proc, b3Raw)
-- se 1 faccia
if Proc.Fct == 1 then
-- dati della faccia
local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT)
-- verifico se è lavorabile da sopra
return vtN:getZ() >= WD.NZ_MINA
-- se 2 facce
elseif Proc.Fct == 2 then
-- dati delle facce
local ptC = {}
local vtN = {}
ptC[1], vtN[1] = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT)
ptC[2], vtN[2] = EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT)
-- verifico se è lavorabile da sopra
return vtN[1]:getZ() >= WD.NZ_MINA or vtN[2]:getZ() >= WD.NZ_MINA
-- se più di 2 facce
else
local nFacInd, dElev, nFacInd2, dElev2 = WL.GetFaceWithMostAdj( Proc.Id, Proc.PartId)
if nFacInd < 0 then return false end
-- dati della faccia
local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, nFacInd, GDB_ID.ROOT)
-- verifico se è lavorabile da sopra
return vtN:getZ() >= WD.NZ_MINA
end
end
---------------------------------------------------------------------
local function MakeByPocketing( Proc, nFacet, nRawId, b3Raw)
-- dati della faccia
local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, nFacet, GDB_ID.ROOT)
local dElev = WL.GetFaceElevation( Proc.Id, nFacet, nPartId)
-- recupero la lavorazione
local sPocketing = WM.FindPocketing( 'Pocket', nil, dElev)
if not sPocketing then
local sErr = 'Error : pocketing not found in library'
EgtOutLog( sErr)
return false, sErr
end
-- recupero i dati dell'utensile
local dMillDiam = 20
local dMaxDepth = 0
if EgtMdbSetCurrMachining( sPocketing) then
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam
dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth
end
end
-- inserisco la lavorazione di svuotatura
local sName = 'Pock_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id))
local nMchFId = EgtAddMachining( sName, sPocketing)
if not nMchFId then
local sErr = 'Error adding machining ' .. sName .. '-' .. sPocketing
EgtOutLog( sErr)
return false, sErr
end
-- aggiungo geometria
EgtSetMachiningGeometry( {{ Proc.Id, nFacet}})
-- imposto posizione braccio porta testa
local nSCC = MCH_SCC.ADIR_ZP
if AreSameVectorApprox( vtN, Z_AX()) then
nSCC = EgtIf( Proc.Box:getDimX() >= Proc.Box:getDimY(), MCH_SCC.ADIR_YP, MCH_SCC.ADIR_XP)
end
EgtSetMachiningParam( MCH_MP.SCC, nSCC)
-- se elevazione superiore a massimo affondamento della fresa, riduco opportunamente
local dDepth = 0
if dElev > dMaxDepth + 10 * GEO.EPS_SMALL then
dDepth = dMaxDepth - dElev
local sWarn = 'Warning : elevation bigger than max tool depth'
EgtOutLog( sWarn)
end
EgtSetMachiningParam( MCH_MP.DEPTH, dDepth)
-- imposto elevazione
EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( min( dElev, dMaxDepth), 1) .. ';')
-- eseguo
if not EgtApplyMachining( true, false) then
local _, sErr = EgtGetLastMachMgrError()
EgtSetOperationMode( nMchFId, false)
return false, sErr
end
return true
end
---------------------------------------------------------------------
local function MakeOneFace( Proc, nRawId, b3Raw)
-- dati della faccia
local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT)
-- dimensioni della faccia
local _, dDimH, dDimV = WL.GetFaceHvRefDim( Proc.Id, 0)
-- recupero la lavorazione di taglio con lama e i suoi parametri
local sCutting, dSawDiam, dSawThick, dSawMaxDepth = WM.FindCutting( 'Standard')
-- se non inclinata o capacità di taglio non sufficiente, provo con svuotatura
if not sCutting or vtN:getZ() > 0.95 or dSawMaxDepth < dDimV + WD.CUT_SIC then
-- faccio con svuotatura
local nFacet = 0
return MakeByPocketing( Proc, nFacet, nRawId, b3Raw)
end
-- eseguo il taglio di lama
local sName = 'Cut_' .. ( EgtGetName( Proc.PartId) or tostring( Proc.PartId)) .. '_' .. tostring( Proc.Id)
local nMchId = EgtAddMachining( sName, sCutting)
if not nMchId then
local sErr = 'Error adding machining ' .. sName .. '-' .. sCutting
EgtOutLog( sErr)
return false, sErr
end
-- aggiungo geometria
EgtSetMachiningGeometry( { { Proc.Id, 0}})
-- percorso da non invertire
EgtSetMachiningParam( MCH_MP.INVERT, false)
-- assegno affondamento
EgtSetMachiningParam( MCH_MP.DEPTH, 0)
-- assegno il lato di lavoro
EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT)
-- assegno l'attacco e l'uscita
EgtSetMachiningParam( MCH_MP.LEADINTYPE, MCH_SAW_LI.CENT)
EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, MCH_SAW_LO.CENT)
-- nessun criterio per il braccio è necessario
EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.NONE)
-- eseguo
if not EgtApplyMachining( true, false) then
local _, sErr = EgtGetLastMachMgrError()
EgtSetOperationMode( nMchId, false)
return false, sErr
end
return true
end
---------------------------------------------------------------------
local function MakeTwoFaces( Proc, nRawId, b3Raw)
-- dati delle facce
local ptC = {}
local vtN = {}
ptC[1], vtN[1] = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT)
ptC[2], vtN[2] = EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT)
-- determino l'intersezione tra le due facce
local bAdj, ptP1, ptP2, dAng = EgtSurfTmFacetsContact( Proc.Id, 0, 1, GDB_ID.ROOT)
if not bAdj then
return false, 'Feature with two faces not adjacentes'
end
-- versore della linea di intersezione
local vtX = ptP2 - ptP1 ; vtX:normalize()
-- larghezza delle facce ortogonalmente all'intersezione
local dDimY = {}
for i = 1, 2 do
local vtY = vtN[i] ^ vtX ; vtY:normalize()
local frRef = Frame3d( ptC[i], ptC[i] + 100 * vtX, ptC[i] + 100 * vtY)
local b3Ref = EgtSurfTmGetFacetBBoxRef( Proc.Id, i - 1, GDB_BB.STANDARD, frRef)
dDimY[i] = b3Ref:getDimY()
end
-- recupero la lavorazione di taglio con lama e i suoi parametri
local sCutting, dSawDiam, dSawThick, dSawMaxDepth = WM.FindCutting( 'Standard')
-- se non inclinate o capacità di taglio non sufficiente, provo con svuotatura
if not sCutting or vtN[1]:getZ() > 0.95 or vtN[2]:getZ() > 0.95 or dSawMaxDepth < dDimY[1] + WD.CUT_SIC or dSawMaxDepth < dDimY[2] + WD.CUT_SIC then
-- cerco la faccia con il maggior numero di adiacenze
local nFacInd, _, nFacInd2 = WL.GetFaceWithMostAdj( Proc.Id, Proc.PartId)
local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nFacInd, GDB_ID.ROOT)
local nFacet = EgtIf( vtN:getZ() >= WD.NZ_MINA, nFacInd, nFacInd2)
-- eseguo la svuotatura
return MakeByPocketing( Proc, nFacet, nRawId, b3Raw)
end
-- ordino i tagli per fare prima quello meno inclinato
local nOrd = { 0, 1}
if vtN[2]:getZ() > vtN[1]:getZ() then
nOrd = { 1, 0}
end
-- eseguo i tagli di lama
for i = 1, 2 do
-- inserisco la lavorazione
local sName = 'Cut_' .. ( EgtGetName( Proc.PartId) or tostring( Proc.PartId)) .. '_' .. tostring( Proc.Id) .. '_' .. tostring( i)
local nMchId = EgtAddMachining( sName, sCutting)
if not nMchId then
local sErr = 'Error adding machining ' .. sName .. '-' .. sCutting
EgtOutLog( sErr)
return false, sErr
end
-- aggiungo geometria
EgtSetMachiningGeometry( { { Proc.Id, nOrd[i]}})
-- percorso da non invertire
EgtSetMachiningParam( MCH_MP.INVERT, false)
-- assegno affondamento
EgtSetMachiningParam( MCH_MP.DEPTH, 0)
-- assegno il lato di lavoro
EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT)
-- assegno l'attacco e l'uscita
EgtSetMachiningParam( MCH_MP.LEADINTYPE, MCH_SAW_LI.CENT)
EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, MCH_SAW_LO.CENT)
-- nessun criterio per il braccio è necessario
EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.NONE)
-- eseguo
if not EgtApplyMachining( true, false) then
local _, sErr = EgtGetLastMachMgrError()
EgtSetOperationMode( nMchId, false)
return false, sErr
end
end
return true
end
---------------------------------------------------------------------
local function MakeMoreFaces( Proc, nRawId, b3Raw)
-- cerco la faccia con il maggior numero di adiacenze
local nFacInd, _, nFacInd2 = WL.GetFaceWithMostAdj( Proc.Id, Proc.PartId)
local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nFacInd, GDB_ID.ROOT)
local nFacet = EgtIf( vtN:getZ() >= WD.NZ_MINA, nFacInd, nFacInd2)
-- eseguo la svuotatura
return MakeByPocketing( Proc, nFacet, nRawId, b3Raw)
end
---------------------------------------------------------------------
-- Applicazione della lavorazione
function WPL.Make( Proc, nRawId, b3Raw)
if Proc.Fct == 1 then
return MakeOneFace( Proc, nRawId, b3Raw)
elseif Proc.Fct == 2 then
return MakeTwoFaces( Proc, nRawId, b3Raw)
else
return MakeMoreFaces( Proc, nRawId, b3Raw)
end
end
---------------------------------------------------------------------
return WPL