6eaba8a577
- primo rilascio.
147 lines
5.5 KiB
Lua
147 lines
5.5 KiB
Lua
-- TwoFacesBySaw.lua by Egaltech s.r.l. 2019/03/28
|
|
-- Gestione taglio con lama di feature con due facce
|
|
|
|
-- Tabella per definizione modulo
|
|
local TwoFacesBySaw = {}
|
|
|
|
-- Include
|
|
require( 'EgtBase')
|
|
local BL = require( 'BeamLib')
|
|
local DC = require( 'DiceCut')
|
|
|
|
EgtOutLog( ' TwoFacesBySaw started', 1)
|
|
|
|
-- Dati
|
|
local BD = require( 'BeamData')
|
|
local Cuttings = require( 'CutData')
|
|
|
|
----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
local function FindCutting( sType)
|
|
for i = 1, #Cuttings do
|
|
local Cutting = Cuttings[i]
|
|
if Cutting.Type == sType then
|
|
return i, Cutting.Name
|
|
end
|
|
end
|
|
return 0
|
|
end
|
|
|
|
---------------------------------------------------------------------
|
|
function TwoFacesBySaw.Make( Proc, nPhase, nRawId, nPartId, 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 nOrthoOpposite = {}
|
|
local vtTg = ptT2 - ptT1 ;
|
|
local vtRef1 = vtN[1] ^ vtTg
|
|
if vtRef1 * vtN[2] < 0 then vtRef1 = - vtRef1 end
|
|
local vtRef2 = vtN[2] ^ vtTg
|
|
if vtRef2 * vtN[1] < 0 then vtRef2 = - vtRef2 end
|
|
nOrthoOpposite[1] = BL.GetNearestOrthoOpposite( vtRef1)
|
|
nOrthoOpposite[2] = BL.GetNearestOrthoOpposite( vtRef2)
|
|
-- 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
|
|
-- recupero la lavorazione
|
|
local _, sCutting = 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 < -92 then
|
|
dCutExtra = - dSawThick / tan( 180 + dAngT)
|
|
end
|
|
-- verifico se necessari tagli supplementari
|
|
local vCuts = DC.GetDice( EgtGetParent( Proc.Id), b3Solid, ptC[nBigInd], vtN[nBigInd], false, ptC[nSmaInd], vtN[nSmaInd])
|
|
--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))
|
|
end
|
|
end
|
|
-- eseguo
|
|
for i = 1, #vCuts do
|
|
-- assegno il modo di tagliare
|
|
local nOrtOpp = EgtIf( ( i % 2) == 1, nOrthoOpposite[nSmaInd], nOrthoOpposite[nBigInd])
|
|
-- lavoro la faccia
|
|
for j = 1, #vCuts[i] do
|
|
local bOk, sErr = BL.MakeOneFaceBySaw( vCuts[i][j], 0, sCutting, dSawDiam, nOrtOpp, dCutExtra, BD.CUT_SIC, 0, nil, b3Raw)
|
|
if not bOk then
|
|
return bOk, sErr
|
|
end
|
|
end
|
|
end
|
|
return true
|
|
else
|
|
-- lavoro la prima faccia
|
|
local bOk, sErr = BL.MakeOneFaceBySaw( Proc.Id, 0, sCutting, dSawDiam, nOrthoOpposite[1], dCutExtra, BD.CUT_SIC, 0, nil, b3Raw)
|
|
if not bOk then return bOk, sErr end
|
|
-- lavoro seconda faccia
|
|
bOk, sErr = BL.MakeOneFaceBySaw( Proc.Id, 1, sCutting, dSawDiam, nOrthoOpposite[2], dCutExtra, BD.CUT_SIC, 0, nil, b3Raw)
|
|
if not bOk then return bOk, sErr end
|
|
return true
|
|
end
|
|
end
|
|
|
|
return TwoFacesBySaw |