-- ProcessFreeContour.lua by Egaltech s.r.l. 2020/08/26 -- Gestione calcolo profilo libero per Travi -- Tabella per definizione modulo local ProcessFreeContour = {} -- Include require( 'EgtBase') local BL = require( 'BeamLib') EgtOutLog( ' ProcessFreeContour started', 1) -- Dati local BD = require( 'BeamData') local ML = require( 'MachiningLib') --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessFreeContour.Identify( Proc) return ( ( Proc.Grp == 0 or Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 250) end --------------------------------------------------------------------- -- Verifica se feature di testa function ProcessFreeContour.IsHeadFeature( Proc, b3Raw, dCurrOvmH) -- verifico se è in testa if Proc.Box:getMax():getX() < b3Raw:getMax():getX() - dCurrOvmH - BD.MAX_DIST_HTFEA then return false end -- la sua lunghezza non deve superare la metà della lunghezza della trave if Proc.Box:getDimX() > 0.5 * b3Raw:getDimX() then return false end -- se pocket, ne verifico la direzione di lavorazione local bPocket = ( EgtGetInfo( Proc.Id, 'PCKT', 'i') == 1) if bPocket then local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') if not AuxId then return false end AuxId = AuxId + Proc.Id local vtN = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) return ( vtN:getX() >= 0.5) end -- deve occupare una buona parte dell'area if Proc.Box:getDimY() * Proc.Box:getDimZ() > 0.45 * b3Raw:getDimY() * b3Raw:getDimZ() then return true end -- non è di testa return false end --------------------------------------------------------------------- -- Verifica se feature di coda function ProcessFreeContour.IsTailFeature( Proc, b3Raw) -- verifico se è in coda if Proc.Box:getMin():getX() > b3Raw:getMin():getX() + BD.MAX_DIST_HTFEA then return false end -- la sua lunghezza non deve superare la metà della lunghezza della trave if Proc.Box:getDimX() > 0.5 * b3Raw:getDimX() then return false end -- se pocket, ne verifico la direzione di lavorazione local bPocket = ( EgtGetInfo( Proc.Id, 'PCKT', 'i') == 1) if bPocket then local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') if not AuxId then return false end AuxId = AuxId + Proc.Id local vtN = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) return ( vtN:getX() <= - 0.5) end -- deve occupare una buona parte dell'area if Proc.Box:getDimY() * Proc.Box:getDimZ() > 0.45 * b3Raw:getDimY() * b3Raw:getDimZ() then return true end -- non è di coda return false end --------------------------------------------------------------------- -- Classificazione della feature function ProcessFreeContour.Classify( Proc, b3Raw) -- verifico se di tipo pocket local bPocket = ( EgtGetInfo( Proc.Id, 'PCKT', 'i') == 1) -- recupero la curva associata local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') if not AuxId then return false end AuxId = AuxId + Proc.Id local vtN = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) -- se tasca if bPocket then local bDown = ( vtN:getZ() < - 0.5) return true, bDown, false -- se altrimenti profilo orizzontale elseif abs( vtN:getZ()) < 0.5 then return true, false, false -- se altrimenti profilo verticale che non interessa tutta la sezione elseif Proc.Box:getDimZ() < 0.9 * b3Raw:getDimZ() then local bDown = ( vtN:getZ() < - 0.5) return true, bDown, false -- altrimenti è profilo verticale che interessa tutta la sezione else -- recupero la massima capacità di lavoro dell'utensile da utilizzare local sMilling, dMaxDepth = ML.FindMilling( 'FreeContour') if not sMilling then dMaxDepth = 0 end if Proc.Box:getDimZ() > dMaxDepth and BD.ROT90 then return true, false, true else return true, false, false end end end --------------------------------------------------------------------- local function CalcSpecialAdd( nCrv, bStartVsEnd, dToolDiam) -- recupero il dominio della curva local nUi, nUf = EgtCurveDomain( nCrv) if not nUi then return 0 end -- indici punti da analizzare local nOut = EgtIf( bStartVsEnd, nUi, nUf) local nIn = EgtIf( bStartVsEnd, nUi + 1, nUf - 1) -- tangenti prima e dopo il punto interno local vtPrev = EgtUV( nCrv, nIn, -1) local vtNext = EgtUV( nCrv, nIn, 1) -- se c'è perdita di tangenza (delta angolare oltre i 5 gradi) if vtPrev * vtNext < 0.996 then -- lunghezza del tratto local ptP0 = EgtUP( nCrv, nOut) local ptP1 = EgtUP( nCrv, nIn) local dDist = dist( ptP0, ptP1) -- se corto rispetto al raggio utensile, ritorno allugamento opportuno if dDist < 0.6 * dToolDiam then return ( 0.6 * dToolDiam - dDist + 1) end end return 0 end --------------------------------------------------------------------- local function MakeByMill( Proc, nPhase, nRawId, nPartId, dOvmHead) -- 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 -- recupero e verifico l'entità curva local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 if AuxId then AuxId = AuxId + Proc.Id end if not AuxId or ( EgtGetType( AuxId) & GDB_FY.GEO_CURVE) == 0 then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' missing profile geometry' EgtOutLog( sErr) return false, sErr end -- recupero i dati della curva e del profilo local dDepth = abs( EgtCurveThickness( AuxId)) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) local b3Aux = EgtGetBBoxGlob( AuxId, GDB_BB.STANDARD) local bToolInv = ( vtExtr:getZ() < -0.1) local bDown = ( b3Aux:getMin():getZ() < b3Raw:getMin():getZ() + 5) -- recupero la lavorazione local sMilling = ML.FindMilling( 'FreeContour') if not sMilling then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' milling not found in library' EgtOutLog( sErr) return false, sErr end -- recupero i dati dell'utensile local dToolDiam = 10 local dMaxDepth = 0 if EgtMdbSetCurrMachining( sMilling) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dToolDiam dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth end end -- ne verifico la lunghezza per eventuale spezzatura e lavorazione in doppio local nStep = 1 local dStep = 0 local dLenMax = BD.LONGCUT_ENDLEN if b3Aux:getDimX() > dLenMax then local dCrvLen = EgtCurveLength( AuxId) nStep = ceil( dCrvLen / dLenMax) dStep = dCrvLen / nStep EgtOutLog( string.format( 'CrvLen=%.1f StepNbr=%d StepLen=%.1f', dCrvLen, nStep, dStep), 3) end -- eventuale spezzatura sul tratto più lungo se curva chiusa BL.PutStartOnLonger( AuxId) -- verifiche per affondamento ( possibili lavorazioni in doppio) local bCross = false if abs( vtExtr:getY()) > 0.707 then if b3Aux:getDimY() > b3Raw:getDimY() - 1.0 then bCross = true dDepth = min( dDepth, b3Raw:getDimY()) end elseif abs( vtExtr:getZ()) > 0.707 then if b3Aux:getDimZ() > b3Raw:getDimZ() - 1.0 then bCross = true dDepth = min( dDepth, b3Raw:getDimZ()) end end local nDouble = 1 local bCanDouble = abs( vtExtr:getY()) > 0.707 and bCross local bStripOnSide = false if bCross then if nStep > 1 or ( bDown and b3Aux:getDimX() > 0.5 * b3Raw:getDimX()) then -- devo lasciare un codolo dDepth = dDepth - BD.DIM_STRIP bStripOnSide = true else -- devo affondare un poco oltre dDepth = dDepth + BD.CUT_EXTRA end end if dDepth > dMaxDepth then if bCanDouble then nDouble = 2 dDepth = min( 0.5 * dDepth, dMaxDepth) else dDepth = dMaxDepth end end -- se utensile orizzontale verso Y+, non in doppio e codolo da lasciare, devo invertire per lavorare sempre da Y- if vtExtr:getY() > 0.707 and nDouble == 1 and bStripOnSide then bToolInv = true end -- verifico se primo e ultimo tratti corti e con angolo local dStartAddSpec = CalcSpecialAdd( AuxId, true, dToolDiam) local dEndAddSpec = CalcSpecialAdd( AuxId, false, dToolDiam) -- eseguo for i = 1, nStep do for j = 1, nDouble do -- inserisco la lavorazione local sName = 'Free_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMchId = EgtAddMachining( sName, sMilling) if not nMchId then local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) -- eventuale accorciamento di testa if ( j == 1 and i > 1) or ( j == 2 and i < nStep) then local dStartAddLen = EgtIf( j == 1, - ( i - 1) * dStep, - ( nStep - i) * dStep) EgtSetMachiningParam( MCH_MP.STARTADDLEN, dStartAddLen) else EgtSetMachiningParam( MCH_MP.STARTADDLEN, EgtIf( j == 1, dStartAddSpec, dEndAddSpec)) end -- eventuale accorciamento di coda if ( j == 1 and i < nStep) or ( j == 2 and i > 1) then local dEndAddLen = EgtIf( j == 1, - ( nStep - i) * dStep, - ( i - 1) * dStep) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEndAddLen) else EgtSetMachiningParam( MCH_MP.ENDADDLEN, EgtIf( j == 1, dEndAddSpec, dStartAddSpec)) end -- se estrusione da sotto, inverto direzione fresa if ( j == 1 and bToolInv) or ( j == 2 and not bToolInv) then EgtSetMachiningParam( MCH_MP.TOOLINVERT, true) end -- se seconda passata, inverto direzione di lavoro if j == 2 then EgtSetMachiningParam( MCH_MP.INVERT, true) end -- assegno affondamento EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- assegno lato di lavoro if Proc.Grp == 0 then EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.CENTER) elseif ( Proc.Grp == 3 and not bToolInv) or ( Proc.Grp == 4 and bToolInv) then EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) elseif ( Proc.Grp == 3 and bToolInv) or ( Proc.Grp == 4 and not bToolInv) then EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT) end -- posizione braccio porta testa if Proc.Head then EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_XP) elseif Proc.Tail then EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_XM) elseif AreSameOrOppositeVectorApprox( vtExtr, Z_AX()) then EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP) end -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchId, false) return false, sErr end 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() > 0.75 * b3Raw:getDimZ() and Proc.Box:getMin():getZ() < b3Raw:getMin():getZ() + dMinHIng then if Proc.Head then local dOffs = b3Raw:getMax():getX() - dOvmHead - 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) end end return true end --------------------------------------------------------------------- local function MakeByPocket( Proc, nPhase, nRawId, nPartId, dOvmHead) -- recupero e verifico l'entità curva local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 if AuxId then AuxId = AuxId + Proc.Id end if not AuxId or ( EgtGetType( AuxId) & GDB_FY.GEO_CURVE) == 0 then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' missing profile geometry' EgtOutLog( sErr) return false, sErr end -- recupero i dati della curva e del profilo local dDepth = abs( EgtCurveThickness( AuxId)) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) --local bToolInv = ( vtExtr:getZ() < -0.1) -- recupero la lavorazione local sPocketing = ML.FindPocketing( 'Pocket', nil, dDepth) if not sPocketing then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' pocketing not found in library' EgtOutLog( sErr) return false, sErr end -- recupero i dati dell'utensile local dMillDiam = 20 local dMaxDepth = 0 if EgtMdbSetCurrMachining( sPocketing) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth end end -- inserisco la lavorazione di svuotatura local sName = 'Pock_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMchFId = EgtAddMachining( sName, sPocketing) if not nMchFId then local sErr = 'Error adding machining ' .. sName .. '-' .. sPocketing EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) -- imposto posizione braccio porta testa if vtExtr:getY() <= 0 then EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YM) else EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP) end -- se elevazione superiore a massimo affondamento della fresa, riduco opportunamente if dDepth > dMaxDepth + 10 * GEO.EPS_SMALL then dDepth = dMaxDepth local sWarn = 'Warning in process ' .. tostring( Proc.Id) .. ' : elevation bigger than max tool depth' EgtOutLog( sWarn) end EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- imposto elevazione EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dMaxDepth, 1) .. ';') -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end return true end --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessFreeContour.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) -- recupero la tipologia local bPocket = ( EgtGetInfo( Proc.Id, 'PCKT', 'i') == 1) -- se svuotatura if bPocket then return MakeByPocket( Proc, nPhase, nRawId, nPartId, dOvmHead) -- altrimenti contornatura else return MakeByMill( Proc, nPhase, nRawId, nPartId, dOvmHead) end end --------------------------------------------------------------------- return ProcessFreeContour