-- ProcessDrill.lua by Egaltech s.r.l. 2019/08/29 -- Gestione calcolo forature per Travi -- Tabella per definizione modulo local ProcessDrill = {} -- Include require( 'EgtBase') EgtOutLog( ' ProcessDrill started', 1) -- Dati local BD = require( 'BeamData') local ML = require( 'MachiningLib') -- Costanti local TH_RAD = 35 -- raggio portautensile local COS_SLANT_LIM = 0.866 -- 30deg da piano --------------------------------------------------------------------- -- 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 -- 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 local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) -- se entrata principale if Proc.Flg > 0 then local nFcs = EgtGetInfo( Proc.Id, 'FCS', 'i') or 0 return ( ( nFcs == 5 or nFcs == 6) and vtExtr:getX() < -0.5) -- altrimenti entrata opposta else local nFce = EgtGetInfo( Proc.Id, 'FCE', 'i') or 0 return ( ( nFce == 5 or nFce == 6) and vtExtr:getX() > 0.5) end end --------------------------------------------------------------------- -- Verifica se da lavorare in due metà function ProcessDrill.Split( 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 bOpen = ( Proc.Fce ~= 0) -- recupero la lavorazione local sDrilling, _, dMaxMat = ML.FindDrilling( dDiam) if not sDrilling then return bOpen end -- restituisco se va fatto in doppio (solo fori orizzontali) return ( bOpen and dLen > dMaxMat + 10 * GEO.EPS_SMALL and ( abs( vtExtr:getY()) * b3Raw:getDimZ() > abs( vtExtr:getZ()) * b3Raw:getDimY() or Proc.Fce == 5 or Proc.Fce == 6)) 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 -- verifico se troppo inclinato e quindi non lavorabile if not ( Proc.Fcs == 5 or Proc.Fcs == 6) and abs( vtExtr:getX()) > COS_SLANT_LIM then return false, false end local bOpen = ( Proc.Fce ~= 0) local bFaceDown = ( ptCen:getZ() < b3Raw:getMin():getZ() + dDiam) and vtExtr:getZ() < -0.5 -- 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 sDrilling, nType = ML.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 -- recupero i dati dell'utensile local dMaxDepth = 20 if EgtMdbSetCurrMachining( sDrilling) then local bIsDrilling = ( EgtMdbGetCurrMachiningParam( MCH_MP.TYPE) == MCH_MY.DRILLING) local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then if bIsDrilling then dMaxDepth = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) or dMaxDepth else dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth end end end -- se foro intermedio e inclinato, limito il massimo affondamento if not ( Proc.Fcs == 5 or Proc.Fcs == 6) then local CosB = abs( vtExtr:getX()) if CosB < COS_SLANT_LIM then local TgA = CosB / sqrt( 1 - CosB * CosB) dMaxDepth = dMaxDepth - TH_RAD * TgA else dMaxDepth = 0 end 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) -- aggiusto l'affondamento local sMyWarn local dDepth = dLen if Proc.Flg == 2 or Proc.Flg == -2 then dDepth = dLen / 2 + BD.DRILL_OVERLAP end if dDepth > dMaxDepth + 10 * GEO.EPS_SMALL then sMyWarn = 'Warning in drill : depth (' .. EgtNumToString( dDepth, 1) .. ') bigger than max tool depth (' .. EgtNumToString( dMaxDepth, 1) .. ')' dDepth = dMaxDepth EgtOutLog( sMyWarn .. ' (process ' .. tostring( Proc.Id) .. ')') end EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- Note utente con dichiarazione nessuna generazione sfridi per Vmill local sUserNotes = 'VMRS=0;' -- se foratura, aggiungo alle note massima elevazione (coincide con affondamento) if nType == 'Drill' then sUserNotes = sUserNotes .. 'MaxElev=' .. EgtNumToString( dDepth, 1) .. ',' end EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes) -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchId, false) return false, sErr else local _, sWarn = EgtGetMachMgrWarning( 0) if EgtIsMachiningEmpty() then EgtSetOperationMode( nMchFId, false) return false, sWarn else return true, ( sMyWarn or sWarn) end end return true, sMyWarn end --------------------------------------------------------------------- return ProcessDrill