Files
DataBeam/LuaLibs/FacesBySaw.lua
T
DarioS edeae8b993 DataBeam :
- modificata gestione pezzi piccoli da vista (ora grezzo più lungo anche con pezzi più lunghi)
- modificata scelta per attacco tg o perpendicolare con lama
- per taglio doppio aggiunta gestione nessun limite direzione da sotto per testa da sotto
- con testa da sotto su mortasa a coda di rondine aggiunto controllo possibilità di salita in Z (variabile macchina BD.DH_MAX_TOP)
- in fessure verticali su pezzi alti, verifica affondamento lama tenendo conto dell'altezza del pezzo.
2021-09-03 18:45:25 +02:00

183 lines
7.6 KiB
Lua

-- FacesBySaw.lua by Egaltech s.r.l. 2021/08/31
-- Gestione taglio con lama di feature con una, due o tre facce
-- 2021/08/31 DS Aggiunta gestione nessun limite direzione da sotto per testa da sotto.
-- Tabella per definizione modulo
local FacesBySaw = {}
-- Include
require( 'EgtBase')
local BL = require( 'BeamLib')
local DC = require( 'DiceCut')
EgtOutLog( ' FacesBySaw started', 1)
-- Dati
local BD = require( 'BeamData')
local ML = require( 'MachiningLib')
---------------------------------------------------------------------
function FacesBySaw.MakeTwo( Proc, nPhase, nRawId, nPartId, dOvmHead, sCutType, bUpdateIng, bDownHead)
-- bUpdateIng : parametro opzionale con default true
if bUpdateIng == nil then bUpdateIng = true end
-- recupero l'ingombro del grezzo di appartenenza
local b3Raw = EgtGetRawPartBBox( nRawId)
-- ingombro del pezzo
local Ls = EgtGetFirstNameInGroup( nPartId, 'Box')
local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD)
if not b3Solid then
local sErr = 'Error : part box not found'
EgtOutLog( sErr)
return false, sErr
end
-- verifico il numero di facce della tacca
if Proc.Fct < 2 then
local sErr = 'Error : TwoFacesBySaw facet number not supported'
EgtOutLog( sErr)
return false, sErr
end
-- 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 non siano orientate verso il basso
local bFaceOk = {}
bFaceOk[1] = ( vtN[1]:getZ() >= BD.NZ_MINB)
bFaceOk[2] = ( vtN[2]:getZ() >= BD.NZ_MINB)
if not bDownHead and not bFaceOk[1] and not bFaceOk[2] then
local sErr = 'Error : TwoFacesBySaw from bottom impossible'
EgtOutLog( sErr)
return false, sErr
end
-- recupero dati su giunzione tra facce
local bTouch, ptT1, ptT2, dAngT = EgtSurfTmFacetsContact( Proc.Id, 0, 1, GDB_ID.ROOT)
if not bTouch then
local sErr = 'Error : TwoFacesBySaw faces not touching'
EgtOutLog( sErr)
return false, sErr
end
-- calcolo direzione di lavoro
local vtRef = {}
local vtTg = ptT2 - ptT1 ;
vtRef[1] = vtN[1] ^ vtTg
if vtRef[1] * vtN[2] < 0 then vtRef[1] = - vtRef[1] end
vtRef[1]:normalize()
vtRef[2] = vtN[2] ^ vtTg
if vtRef[2] * vtN[1] < 0 then vtRef[2] = - vtRef[2] end
vtRef[2]:normalize()
-- determino quale faccia è più grande
local ptPs = ( ptT1 + ptT2) / 2
local dSqDim1 = ( ptC[1] - ptPs):sqlen()
local dSqDim2 = ( ptC[2] - ptPs):sqlen()
local nBigInd = EgtIf( dSqDim1 > dSqDim2 - 1., 1, 2)
local nSmaInd = 3 - nBigInd
local nUpInd = EgtIf( vtN[1]:getZ() > vtN[2]:getZ() - GEO.EPS_SMALL, 1, 2)
local nOtInd = 3 - nUpInd
-- metto in relazione la scelta facce con il confronto del versore Z con la scelta in base alla grandezza faccia
-- se la faccia più grande è messa secondaria e il suo versore Z non è negativo
if nOtInd == nBigInd and vtN[nBigInd]:getZ() > -5 * GEO.EPS_SMALL and vtN[nSmaInd]:getZ() < 0.866 then
nOtInd = nSmaInd
nUpInd = nBigInd
end
-- recupero la lavorazione
local sCutting = ML.FindCutting( sCutType)
if not sCutting then
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' cutting not found in library'
EgtOutLog( sErr)
return false, sErr
end
-- recupero i dati dell'utensile
local dSawDiam = 400
local dSawThick = 5
if EgtMdbSetCurrMachining( sCutting) then
local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID)
if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then
dSawDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dSawDiam
dSawThick = EgtTdbGetCurrToolParam( MCH_TP.THICK) or dSawThick
end
end
-- calcolo extra taglio
local dCutExtra = 0
if dAngT < -91 and dAngT > -179 then
dCutExtra = - dSawThick / tan( 180 + dAngT)
end
-- sistemo direzione limite da sotto (con testa da sotto limite Vz Down Up messo a -2 per non farlo mai intervenire)
local dNzLimDwnUp
if bDownHead then
dNzLimDwnUp = - 2
end
-- verifico se necessari tagli supplementari
local vCuts = DC.GetDice( EgtGetParent( Proc.Id), b3Solid, ptC[nUpInd], vtN[nUpInd], false, ptC[nOtInd], vtN[nOtInd])
--DC.PrintOrderCut( vCuts)
if #vCuts > 0 then
-- recupero gruppo per geometria addizionale
local nAddGrpId = BL.GetAddGroup( nPartId)
if not nAddGrpId then
local sErr = 'Error : missing AddGroup'
EgtOutLog( sErr)
return false, sErr
end
-- sistemo posizione nel DB e nome
for i = 1, #vCuts do
for j = 1, #vCuts[i] do
EgtRelocateGlob( vCuts[i][j], nAddGrpId)
EgtSetName( vCuts[i][j], 'AddCut_' .. tostring( Proc.Id))
EgtSetInfo( vCuts[i][j], 'TASKID', Proc.TaskId)
end
end
-- eseguo
for i = 1, #vCuts do
-- assegno il modo di tagliare
local vtOrthO = EgtIf( ( i % 2) == 1, vtRef[nOtInd], vtRef[nUpInd])
-- lavoro la faccia
for j = 1, #vCuts[i] do
-- se FAST, pezzo alto e ultimo taglio verticale -> allungo uscita per consentire eventuale rotazione B sul posto
local dAccEnd = 0
if not BD.C_SIMM and BD.MAX_HEIGHT_ROT_B_ABOVE and b3Raw:getDimZ() > BD.MAX_HEIGHT_ROT_B_ABOVE and vtOrthO:getZ() > 0.866 and j == #vCuts[i] then
dAccEnd = - ( dSawDiam / 2 + BD.CUT_SIC)
end
local bOk, sErr = BL.MakeOneFaceBySaw( vCuts[i][j], 0, sCutting, dSawDiam, vtOrthO, dNzLimDwnUp, dCutExtra, BD.CUT_SIC, 0, 0, dAccEnd, nil, b3Raw)
if not bOk then
return bOk, sErr
end
end
end
else
nUpInd = EgtIf( vtN[1]:getZ() > vtN[2]:getZ() - GEO.EPS_SMALL, 1, 2)
nOtInd = 3 - nUpInd
-- se prima faccia lavorata è da sotto scambio le facce
if vtN[nOtInd]:getZ() < -0.5 then
nUpInd, nOtInd = nOtInd, nUpInd
end
-- lavoro la prima faccia
local bOk, sErr = BL.MakeOneFaceBySaw( Proc.Id, nOtInd-1, sCutting, dSawDiam, vtRef[nOtInd], dNzLimDwnUp, dCutExtra, BD.CUT_SIC, 0, 0, 0, nil, b3Raw)
if not bOk then return bOk, sErr end
-- lavoro seconda faccia
bOk, sErr = BL.MakeOneFaceBySaw( Proc.Id, nUpInd-1, sCutting, dSawDiam, vtRef[nUpInd], dNzLimDwnUp, dCutExtra, BD.CUT_SIC, 0, 0, 0, nil, b3Raw)
if not bOk then
return bOk, sErr
end
end
-- eventuale segnalazione ingombro di testa o coda
local dMinHIng = min( 0.5 * BD.VICE_MINH, 0.5 * b3Raw:getDimZ())
if bUpdateIng and Proc.Box:getDimZ() > dMinHIng and Proc.Box:getMin():getZ() < b3Raw:getMin():getZ() + dMinHIng and
not ( abs( vtN[nBigInd]:getX()) < 0.05 and vtN[nBigInd]:getY() < 0 and Proc.Box:getDimX() > 500) then
if Proc.Head then
local dOffs = b3Solid:getMax():getX() - Proc.Box:getMin():getX()
BL.UpdateHCING( nRawId, dOffs)
elseif Proc.Tail then
local dOffs = Proc.Box:getMax():getX() - b3Solid:getMin():getX()
BL.UpdateTCING( nRawId, dOffs)
elseif Proc.Box:getCenter():getX() > b3Solid:getCenter():getX() then
local dOffs = b3Solid:getMax():getX() - Proc.Box:getMin():getX()
local dDist = b3Solid:getMax():getX() - Proc.Box:getMax():getX()
-- se concavo aumento la distanza (rimane una punta...)
if dAngT < 0 then dDist = dDist + 10 end
BL.UpdateHCING( nRawId, dOffs, dDist)
end
end
return true
end
return FacesBySaw