-- ProcessDrill.lua by Egaltech s.r.l. 2019/08/03 -- Gestione calcolo doppi tagli di lama per Travi -- Tabella per definizione modulo local ProcessDoubleCut = {} -- Include require( 'EgtBase') local BL = require( 'BeamLib') local DC = require( 'DiceCut') local Cut = require( 'ProcessCut') EgtOutLog( ' ProcessDoubleCut started', 1) -- Dati local BD = require( 'BeamData') local ML = require( 'MachiningLib') --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessDoubleCut.Identify( Proc) return ( ( Proc.Grp == 1 or Proc.Grp == 2) and Proc.Prc == 11) end --------------------------------------------------------------------- -- Classificazione della feature function ProcessDoubleCut.Classify( Proc) -- numero delle facce local nFacetCnt = EgtSurfTmFacetCount( Proc.Id) -- se due facce, verifico se convesso local bConvex = true if nFacetCnt == 2 then local _, _, _, dAng = EgtSurfTmFacetsContact( Proc.Id, 0, 1, GDB_ID.ROOT) bConvex = ( dAng > 0) end -- verifico le normali delle facce for i = 1, nFacetCnt do local vtN = EgtSurfTmFacetNormVersor( Proc.Id, i-1, GDB_ID.ROOT) if not bConvex and vtN:getZ() < - 0.72 then return true, true end end return true, false end --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessDoubleCut.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) -- ingombro del grezzo 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 -- 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) -- normale media per capire se taglio di testa o di coda local vtNm = ( vtN[1] + vtN[2]) ; vtNm:normalize() local bHead = ( vtNm:getX() > 0) -- angolo diedro per stabilire se taglio convesso local _, ptP1, ptP2, dAng = EgtSurfTmFacetsContact( Proc.Id, 0, 1, GDB_ID.ROOT) local vtDir = ptP1 - ptP2 ; vtDir:normalize() local bOnY = abs( vtDir:getZ()) > 0.5 and ( abs( vtDir:getZ()) + abs( vtDir:getX()) > abs( vtDir:getY())) local bConvex = ( dAng > 0) local dLen = dist( ptP1, ptP2) local ptPs = ( ptP1 + ptP2) / 2 -- determino quale faccia è più grande 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 = ML.FindCutting( EgtIf( bHead, 'HeadSide', 'TailSide')) 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 dMaxDepth = 0 if EgtMdbSetCurrMachining( sCutting) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dSawDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dSawDiam dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth end end -- se convesso, lo tratto come due tagli singoli if bConvex 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 -- lavoro per prima la faccia più diretta in alto local vOrd = { 1, 2} if vtN[2]:getZ() > vtN[1]:getZ() then vOrd = { 2, 1} end -- creo piano di taglio coincidente con la prima faccia e lo lavoro local AddId = EgtSurfTmPlaneInBBox( EgtGetParent( Proc.Id), ptC[vOrd[1]], vtN[vOrd[1]], b3Solid, GDB_RT.GLOB) if AddId then EgtRelocate( AddId, nAddGrpId) EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) -- applico lavorazione local CutProc = { Id = AddId, Grp = Proc.Grp, Prc = Proc.Prc, Box = Proc.Box, Fct = Proc.Fct, Flg = Proc.Flg} local bOk, sErr = Cut.Make( CutProc, nPhase, nRawId, nPartId, 0) if not bOk then return bOk, sErr end end -- creo piano di taglio coincidente con la seconda faccia e lo lavoro AddId = EgtSurfTmPlaneInBBox( EgtGetParent( Proc.Id), ptC[vOrd[2]], vtN[vOrd[2]], b3Solid, GDB_RT.GLOB) if AddId then EgtRelocate( AddId, nAddGrpId) EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) -- applico lavorazione local CutProc = { Id = AddId, Grp = Proc.Grp, Prc = Proc.Prc, Box = Proc.Box, Fct = Proc.Fct, Flg = Proc.Flg} local bOk, sErr = Cut.Make( CutProc, nPhase, nRawId, nPartId, 0) if not bOk then return bOk, sErr end end -- altrimenti else -- 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)) EgtSetInfo( vCuts[i][j], 'TASKID', Proc.TaskId) end end -- eseguo for i = 1, #vCuts do -- determino il modo di tagliare local k, l = nBigInd, nSmaInd if ( i % 2 == 1) == ( not bConvex) then k, l = l, k end local nOrthoOpposite if bOnY then local bFront = ( ptC[k]:getY() < ptPs:getY()) nOrthoOpposite = EgtIf( bFront, MCH_MILL_FU.ORTHO_BACK, MCH_MILL_FU.ORTHO_FRONT) else if bConvex then if dLen < dMaxDepth then local bFront = ( vtN[k]:getY() < 0.02) nOrthoOpposite = EgtIf( bFront, MCH_MILL_FU.ORTHO_BACK, MCH_MILL_FU.ORTHO_FRONT) else local bOver = ( ptC[k]:getZ() > ptC[l]:getZ()) nOrthoOpposite = EgtIf( bOver, MCH_MILL_FU.ORTHO_DOWN, MCH_MILL_FU.ORTHO_TOP) end else local bOver = ( ptC[k]:getZ() > ptC[l]:getZ()) nOrthoOpposite = EgtIf( bOver, MCH_MILL_FU.ORTHO_DOWN, MCH_MILL_FU.ORTHO_TOP) end end -- lavoro la faccia for j = 1, #vCuts[i] do local bOk, sErr = BL.MakeOneFaceBySaw( vCuts[i][j], 0, sCutting, dSawDiam, nOrthoOpposite, nil, 0, BD.CUT_SIC, 0, 0, nil, b3Raw) if not bOk then return bOk, sErr end end end end -- se non ci sono tagli supplementari o convesso, tagli diretti delle facce if #vCuts == 0 then -- imposto eventuale affondamento aggiuntivo local dExtraCut = EgtIf( bConvex, BD.CUT_EXTRA, 0) -- eseguo sulle due facce for j = 1, 2 do -- determino ordine dei tagli local i = j if not bOnY and ptC[1]:getZ() > ptC[2]:getZ() then i = 3 - j end -- lavoro la faccia local nOrthoOpposite if bOnY then local bFront = ( ptC[i]:getY() < ptPs:getY()) nOrthoOpposite = EgtIf( bFront, MCH_MILL_FU.ORTHO_BACK, MCH_MILL_FU.ORTHO_FRONT) else if bConvex then if dLen < dMaxDepth then local bFront = ( vtN[i]:getY() < 0.02) nOrthoOpposite = EgtIf( bFront, MCH_MILL_FU.ORTHO_BACK, MCH_MILL_FU.ORTHO_FRONT) else nOrthoOpposite = MCH_MILL_FU.ORTHO_DOWN end else local bOver = ( ptC[i]:getZ() > ptC[3-i]:getZ()) nOrthoOpposite = EgtIf( bOver, MCH_MILL_FU.ORTHO_DOWN, MCH_MILL_FU.ORTHO_TOP) end end local bOk, sErr = BL.MakeOneFaceBySaw( Proc.Id, i - 1, sCutting, dSawDiam, nOrthoOpposite, nil, dExtraCut, BD.CUT_SIC, 0, 0, nil, b3Raw) if not bOk then return bOk, sErr end end end end -- eventuale segnalazione ingombro di testa o coda if Proc.Head then local dOffs = b3Raw:getMax():getX() - dOvmHead - Proc.Box:getMin():getX() if vtNm:getZ() > 0.5 then dOffs = 0.5 * dOffs end BL.UpdateHCING( nRawId, dOffs) elseif Proc.Tail then local dOffs = Proc.Box:getMax():getX() - b3Raw:getMin():getX() if vtNm:getZ() > 0.5 then dOffs = 0.5 * dOffs end BL.UpdateTCING( nRawId, dOffs) end return true end --------------------------------------------------------------------- return ProcessDoubleCut