Files
Carlo Baronchelli 741791a0e4 Copia locale Iniziale
2022-05-19 16:04:07 +02:00

170 lines
6.6 KiB
Lua

-- FacesBySaw.lua by Egaltech s.r.l. 2020/11/13
-- Gestione taglio con lama di feature con una, due o tre facce
-- 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, sCutName)
-- 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 on process ' .. tostring( Proc.Id) .. ' 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 on process ' .. tostring( Proc.Id) .. ' 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 bFaceOk[1] and not bFaceOk[2] then
local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' 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 on process ' .. tostring( Proc.Id) .. ' 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[2] = vtN[2] ^ vtTg
if vtRef[2] * vtN[1] < 0 then vtRef[2] = - vtRef[2] end
-- 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, 2)
local nSmaInd = 3 - nBigInd
local nUpInd = EgtIf( vtN[1]:getZ() >= vtN[2]:getZ(), 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( sCutName)
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
-- 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 on process ' .. tostring( Proc.Id) .. ' 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
local bOk, sErr = BL.MakeOneFaceBySaw( vCuts[i][j], 0, sCutting, dSawDiam, vtOrthO, nil, dCutExtra, BD.CUT_SIC, 0, 0, nil, b3Raw)
if not bOk then
return bOk, sErr
end
end
end
else
nUpInd = EgtIf( vtN[1]:getZ() >= vtN[2]:getZ(), 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], nil, dCutExtra, BD.CUT_SIC, 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], nil, dCutExtra, BD.CUT_SIC, 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 Proc.Box:getDimZ() > dMinHIng and Proc.Box:getMin():getZ() < b3Raw:getMin():getZ() + dMinHIng 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()
BL.UpdateHCING( nRawId, dOffs, dDist)
end
end
return true
end
---------------------------------------------------------------------
function FacesBySaw.MakeThree( Proc, nPhase, nRawId, nPartId, sCutName)
return false
end
return FacesBySaw