-- ProcessDrill.lua by Egaltech s.r.l. 2019/04/11 -- Gestione calcolo forature per Travi -- Tabella per definizione modulo local ProcessDrill = {} -- Include require( 'EgtBase') EgtOutLog( ' ProcessDrill started', 1) -- Dati local BD = require( 'BeamData') local Drillings = require( 'DrillData') --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessDrill.Identify( Proc) return ( ( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 40) end --------------------------------------------------------------------- -- Classificazione della feature function ProcessDrill.IsHeadFeature( Proc, b3Raw, dCurrOvmH) return false end --------------------------------------------------------------------- -- Verifica se feature di coda function ProcessDrill.IsTailFeature( Proc, b3Raw) -- verifico se è in coda if Proc.Box:getMin():getX() > b3Raw:getMin():getX() + BD.MAX_DIST_HTFEA then return false end -- se entrata principale if Proc.Flg > 0 then local nFcs = EgtGetInfo( Proc.Id, 'FCS', 'i') or 0 return ( nFcs == 5 or nFcs == 6) -- altrimenti entrata opposta else local nFce = EgtGetInfo( Proc.Id, 'FCE', 'i') or 0 return ( nFce == 5 or nFce == 6) end end --------------------------------------------------------------------- local function FindDrilling( dDiam) -- ricerca sulle forature con punte, dal diametro maggiore al minore for i = #Drillings, 1, -1 do local Drilling = Drillings[i] if ( Drilling.Type == 'Drill' and Drilling.Diam < dDiam + 10 * GEO.EPS_SMALL and Drilling.Diam > dDiam - BD.DRILL_TOL - 10 * GEO.EPS_SMALL) then return i, Drilling.Name, Drilling.Type end end -- ricerca sull svuotature con frese, dal diametro maggiore al minore for i = #Drillings, 1, -1 do local Drilling = Drillings[i] if ( Drilling.Type == 'Pocket' and dDiam > Drilling.Diam + 10 * GEO.EPS_SMALL) then return i, Drilling.Name, Drilling.Type end end return 0 end --------------------------------------------------------------------- -- Verifica se da lavorare in due metà function ProcessDrill.Split( Proc) -- recupero e verifico l'entità foro local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 if AuxId then AuxId = AuxId + Proc.Id end if not AuxId or EgtGetType( AuxId) ~= GDB_TY.CRV_ARC then return false end -- recupero i dati del foro local dDiam = 2 * EgtArcRadius( AuxId) local dLen = abs( EgtCurveThickness( AuxId)) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) local bOpen = ( EgtGetInfo( Proc.Id, 'FCE', 'i') ~= 0) -- recupero la lavorazione local nDri, sDrilling = FindDrilling( dDiam) if not sDrilling then return bOpen end -- restituisco se va fatto in doppio return ( bOpen and dLen > Drillings[nDri].MaxMat + 10 * GEO.EPS_SMALL) end --------------------------------------------------------------------- -- Classificazione della feature function ProcessDrill.Classify( Proc, b3Raw) -- recupero e verifico l'entità foro local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 if AuxId then AuxId = AuxId + Proc.Id end if not AuxId or EgtGetType( AuxId) ~= GDB_TY.CRV_ARC then return false end -- recupero i dati del foro local dDiam = 2 * EgtArcRadius( AuxId) local dLen = abs( EgtCurveThickness( AuxId)) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) local ptCen = EgtCP( AuxId, GDB_RT.GLOB) if Proc.Flg == -2 then vtExtr = - vtExtr ptCen = ptCen + vtExtr * dLen end local bOpen = ( Proc.Fce ~= 0) local bFaceDown = ( ptCen:getZ() < b3Raw:getMin():getZ() + dDiam) -- verifico se il foro è fattibile solo da sotto local bDown = (( vtExtr:getZ() < BD.DRILL_VZ_MIN or bFaceDown) and ( not bOpen or Proc.Flg ~= 1)) return true, bDown end --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessDrill.Make( Proc, nPhase, nRawId, nPartId) -- recupero e verifico l'entità foro local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 if AuxId then AuxId = AuxId + Proc.Id end if not AuxId or EgtGetType( AuxId) ~= GDB_TY.CRV_ARC then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' missing drill geometry' EgtOutLog( sErr) return false, sErr end -- recupero i dati del foro local dDiam = 2 * EgtArcRadius( AuxId) local dLen = abs( EgtCurveThickness( AuxId)) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) if Proc.Flg == -2 then vtExtr = - vtExtr end local bOpen = ( Proc.Fcs ~= 0 and Proc.Fce ~= 0) -- verifico che il foro non sia fattibile solo da sotto local bToInvert = ( vtExtr:getZ() < BD.DRILL_VZ_MIN) if bToInvert and ( not bOpen or Proc.Flg ~= 1) then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' drilling from bottom impossible' EgtOutLog( sErr) return false, sErr end if bToInvert then vtExtr = - vtExtr end if Proc.Flg == -2 then bToInvert = true end -- recupero la lavorazione local nDri, sDrilling, nType = FindDrilling( dDiam) if not sDrilling then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' drilling not found in library' EgtOutLog( sErr) return false, sErr end -- inserisco la lavorazione local sName = 'Drill_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMchId = EgtAddMachining( sName, sDrilling) if not nMchId then local sErr = 'Error adding machining ' .. sName .. '-' .. sDrilling EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) -- eventuale inversione if nType == 'Drill' then EgtSetMachiningParam( MCH_MP.INVERT, bToInvert) else EgtSetMachiningParam( MCH_MP.TOOLINVERT, bToInvert) end -- imposto posizione braccio porta testa local nSCC = MCH_SCC.ADIR_YM if vtExtr:getY() > 100 * GEO.EPS_ZERO then nSCC = MCH_SCC.ADIR_YP end EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- se foro dai due lati, aggiusto l'affondamento if Proc.Flg == 2 or Proc.Flg == -2 then EgtSetMachiningParam( MCH_MP.DEPTH, dLen / 2 + BD.DRILL_OVERLAP) end -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchId, false) return false, sErr end return true end --------------------------------------------------------------------- return ProcessDrill