-- ProcessLongCut.lua by Egaltech s.r.l. 2020/06/11 -- Gestione calcolo taglio longitudinale per Travi -- Tabella per definizione modulo local ProcessLongCut = {} -- Include require( 'EgtBase') local BL = require( 'BeamLib') EgtOutLog( ' ProcessLongCut started', 1) -- Dati local BD = require( 'BeamData') local ML = require( 'MachiningLib') --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessLongCut.Identify( Proc) return (( Proc.Grp == 0 or Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 10) end --------------------------------------------------------------------- -- Classificazione della feature function ProcessLongCut.Classify( Proc) -- se una sola faccia non ci sono limiti if Proc.Fct == 1 then return true, false end -- verifico la normale della faccia principale local vtN = EgtSurfTmFacetNormVersor( Proc.Id, 0, GDB_ID.ROOT) if vtN:getZ() < - 0.5 then return true, true end return true, false end --------------------------------------------------------------------- local function MakeSideFace( nId, nFac, nSide, sMilling, dToolDiam) -- inserisco la lavorazione local sNameF = 'L2C_' .. ( EgtGetName( nId) or tostring( nId)) .. '_' .. tostring( nFac) local nMchFId = EgtAddMachining( sNameF, sMilling) if not nMchFId then local sErr = 'Error adding machining ' .. sNameF .. '-' .. sMilling EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ nId, nFac}}) -- lato di lavoro e inversione EgtSetMachiningParam( MCH_MP.INVERT, true) EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) -- uso della faccia local nFaceUse = MCH_MILL_FU.PARAL_DOWN if nSide == -2 then nFaceUse = MCH_MILL_FU.PARAL_BACK elseif nSide == 2 then nFaceUse = MCH_MILL_FU.PARAL_FRONT end EgtSetMachiningParam( MCH_MP.FACEUSE, nFaceUse) -- annullo offset radiale EgtSetMachiningParam( MCH_MP.OFFSR, 0) -- attacco e uscita EgtSetMachiningParam( MCH_MP.LIPERP, 0) EgtSetMachiningParam( MCH_MP.LITANG, dToolDiam / 2 + 30) EgtSetMachiningParam( MCH_MP.LOPERP, 0) EgtSetMachiningParam( MCH_MP.LOTANG, dToolDiam / 2 + 30) -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end end --------------------------------------------------------------------- -- Applicazione della lavorazione local function MakeByPocketing( Proc, nPhase, nRawId, nPartId) -- recupero la faccia con il maggior numero di adiacenze e l'elevazione relativa local nFacInd, dFacElev = BL.GetFaceWithMostAdj( Proc.Id, nPartId) -- cerco la svuotatura opportuna local sPocketing = ML.FindPocketing( 'OpenPocket', Proc.Box:getDimX()) 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 dMaxDepth = 0 if EgtMdbSetCurrMachining( sPocketing) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dMaxDepth = ( EgtTdbGetCurrToolMaxDepth() or dMaxDepth) end end -- inserisco la lavorazione 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( {{ Proc.Id, 0}}) -- imposto uso faccia EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.ORTHO_CONT) -- imposto attacco per tasca aperta EgtSetMachiningParam( MCH_MP.SUBTYPE, MCH_POCK_SUB.SPIRALIN) -- se elevazione superiore a massimo affondamento della fresa, riduco opportunamente local sWarn if dFacElev > dMaxDepth + 10 * GEO.EPS_SMALL then EgtSetMachiningParam( MCH_MP.DEPTH, dMaxDepth - dFacElev) dFacElev = dMaxDepth sWarn = 'Warning in process ' .. tostring( Proc.Id) .. ' : elevation bigger than max tool depth' EgtOutLog( sWarn) end -- imposto elevazione e dichiaro non si generano sfridi per VMill local sNotes = 'MaxElev=' .. EgtNumToString( dFacElev, 1) .. ';' sNotes = sNotes .. 'VMRS=0;' EgtSetMachiningParam( MCH_MP.USERNOTES, sNotes) -- eseguo if not EgtApplyMachining( true, false) then -- provo ad allargare leggermente la tasca EgtSetMachiningParam( MCH_MP.OFFSR, -0.1) if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end end return true, sWarn end --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessLongCut.Make( Proc, nPhase, nRawId, nPartId) -- recupero l'ingombro del grezzo di appartenenza local b3Raw = EgtGetRawPartBBox( nRawId) -- dati della faccia local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT) local _, dLen, dWidth = EgtSurfTmFacetMinAreaRectangle( Proc.Id, 0, GDB_ID.ROOT) -- limitazioni su inizio e fine derivanti da altre facce local bLimXmin = false local bLimXmax = false if Proc.Fct >= 3 then bLimXmin = true bLimXmax = true elseif Proc.Fct >= 2 then local ptC1, vtN1 = EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT) if vtN1:getX() > 0 then bLimXmin = true else bLimXmax = true end end -- Verifico lato di lavorazione local nSide = 1 if vtN:getZ() < - 0.5 then nSide = -1 elseif vtN:getY() < -0.7071 then nSide = -2 elseif vtN:getY() > 0.7071 then nSide = 2 end local sWarn -- Se non limitato e da sopra e richiesto con doppio taglio di lama if not bLimXmin and not bLimXmax and nSide == 1 and EgtGetInfo( Proc.Id, 'Q05', 'i') == 1 then -- recupero la lavorazione local sCutting = ML.FindCutting( 'HeadSide') if not sCutting then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' sawing not found in library' EgtOutLog( sErr) return false, sErr end -- recupero i dati dell'utensile local dToolDiam = 0 local dMaxDepth = 0 if EgtMdbSetCurrMachining( sCutting) 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 -- determino se lavorazione da davanti o da dietro local bFront = ( vtN:getY() < 0) -- determino numero di parti local dStartAccDist = BD.LONGCUT_ENDLEN local dEndAccDist = BD.LONGCUT_ENDLEN local nC = ceil( ( dLen - dStartAccDist - dEndAccDist) / BD.LONGCUT_MAXLEN) local dC = 0 if nC > 0 then dC = dLen / ( nC + 2) dStartAccDist = dC dEndAccDist = dC nC = nC + 2 else if dLen > min( dStartAccDist, dEndAccDist) then nC = 2 dStartAccDist = dLen/2 dEndAccDist = dStartAccDist else nC = 1 dStartAccDist = 0 dEndAccDist = 0 end end -- determino l'utilizzo della faccia local nFaceUse = EgtIf( abs( vtN:getY()) > 0.01, MCH_MILL_FU.ORTHO_TOP, EgtIf( bFront, MCH_MILL_FU.ORTHO_BACK, MCH_MILL_FU.ORTHO_FRONT)) local nFaceUse2 = EgtIf( abs( vtN:getY()) > 0.01, MCH_MILL_FU.ORTHO_DOWN, EgtIf( bFront, MCH_MILL_FU.ORTHO_FRONT, MCH_MILL_FU.ORTHO_BACK)) -- si percorrono i lati alto e basso della faccia local nM = 0 for i = 1, nC do -- Posizione braccio portatesta local nSCC = EgtIf( ( BD.C_SIMM or i == 1 or i == nC - 1), MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) -- ciclo sulle passate local dOffset = ( dWidth + BD.DIM_STRIP_SMALL) / 2 ; local dLioTang = 0 local dLioPerp = ( dWidth - BD.DIM_STRIP_SMALL) / 2 + BD.CUT_SIC ; for k = 1, 2 do -- inserisco le parti di lavorazione nM = nM + 1 local sNameF = 'L2C_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( nM) local nMchFId = EgtAddMachining( sNameF, sCutting) if not nMchFId then local sErr = 'Error adding machining ' .. sNameF .. '-' .. sCutting EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ Proc.Id, 0}}) -- limito opportunamente la lavorazione local dSal = EgtIf( i == nC, 0, - dEndAccDist - ( nC - i - 1) * dC) local dEal = EgtIf( i == 1, 0, - dStartAccDist - ( i - 2) * dC) if ( not bFront and k == 1) or ( bFront and k == 2) then dSal, dEal = dEal, dSal end EgtSetMachiningParam( MCH_MP.STARTADDLEN, dSal) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal) -- imposto offset radiale EgtSetMachiningParam( MCH_MP.OFFSR, dOffset) -- imposto attacco/uscita EgtSetMachiningParam( MCH_MP.LITANG, dLioTang) EgtSetMachiningParam( MCH_MP.LIPERP, dLioPerp) EgtSetMachiningParam( MCH_MP.LOTANG, dLioTang) EgtSetMachiningParam( MCH_MP.LOPERP, dLioPerp) -- imposto posizione braccio porta testa per non ingombrare agli estremi EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- imposto uso della faccia EgtSetMachiningParam( MCH_MP.FACEUSE, EgtIf( k == 1, nFaceUse, nFaceUse2)) -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end end end -- se altrimenti non è sotto : lavorazione Long2Cut elseif nSide ~= - 1 then -- recupero la lavorazione local sMilling = ML.FindMilling( 'Long2Cut') 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 = 0 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 -- se chiuso e corto, applico svuotatura con fresa opportuna if bLimXmin and bLimXmax and Proc.Box:getDimX() < 2 * dToolDiam then return MakeByPocketing( Proc, nPhase, nRawId, nPartId) end -- determino la massima elevazione local dElev = 0 local ptT1 = b3Raw:getMax() local dDist1 = ( ptT1 - ptC) * vtN dElev = max( dElev, dDist1) local ptT2 = ptT1 - Y_AX() * b3Raw:getDimY() local dDist2 = ( ptT2 - ptC) * vtN dElev = max( dElev, dDist2) -- determino se lavorazione da davanti o da dietro local bFront = ( vtN:getY() < 0) -- determino gli estremi local dStartDist = 0 local dStartAccDist = BD.LONGCUT_ENDLEN local bStartFixed = true if ( bLimXmin and bFront) or ( bLimXmax and not bFront) then dStartDist = dToolDiam / 2 dStartAccDist = BD.LONGCUT_MAXLEN bStartFixed = false end local dEndDist = 0 local dEndAccDist = BD.LONGCUT_ENDLEN local bEndFixed = true if ( bLimXmin and not bFront) or ( bLimXmax and bFront) then dEndDist = dToolDiam / 2 dEndAccDist = BD.LONGCUT_MAXLEN bEndFixed = false end -- determino numero di parti in cui dividere la lavorazione local nC = ceil( ( dLen - dStartAccDist - dEndAccDist) / BD.LONGCUT_MAXLEN) local dC = 0 if nC > 0 then if bStartFixed and bEndFixed then dC = ( dLen - dStartAccDist - dEndAccDist) / nC elseif bStartFixed then dC = ( dLen - dStartAccDist) / ( nC + 1) dEndAccDist = dC elseif bEndFixed then dC = ( dLen - dEndAccDist) / ( nC + 1) dStartAccDist = dC else dC = dLen / ( nC + 2) dStartAccDist = dC dEndAccDist = dC end nC = nC + 2 else if dLen > min( dStartAccDist, dEndAccDist) then nC = 2 if bStartFixed and not bEndFixed then dStartAccDist = min( dStartAccDist, dLen/2) dEndAccDist = dLen - dStartAccDist elseif not bStartFixed and bEndFixed then dEndAccDist = min( dEndAccDist, dLen/2) dStartAccDist = dLen - dEndAccDist else dStartAccDist = dLen/2 dEndAccDist = dStartAccDist end else nC = 1 dStartAccDist = 0 dEndAccDist = 0 end end -- determino l'utilizzo della faccia local nFaceUse = EgtIf( abs( vtN:getY()) > 0.01, MCH_MILL_FU.ORTHO_DOWN, EgtIf( bFront, MCH_MILL_FU.ORTHO_FRONT, MCH_MILL_FU.ORTHO_BACK)) -- si percorre il lato basso della faccia local nM = 0 for i = 1, nC do -- Posizione braccio portatesta local nSCC if bFront then nSCC = EgtIf( ( BD.C_SIMM or i == 1 or i == nC - 1), MCH_SCC.ADIR_XM, MCH_SCC.ADIR_XP) else nSCC = EgtIf( ( BD.C_SIMM or i == 1 or i == nC - 1), MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) end -- ciclo sulle passate local nO = 1 local dStep = 0 if dWidth + 2 * BD.CUT_EXTRA > 0.8 * dToolDiam then nO = ceil(( dWidth + 2 * BD.CUT_EXTRA) / ( 0.6 * dToolDiam)) if nO > 1 then dStep = ( dWidth + 2 * BD.CUT_EXTRA) / nO end end for k = nO, 1, -1 do -- inserisco le parti di lavorazione nM = nM + 1 local sNameF = 'L2C_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( nM) local nMchFId = EgtAddMachining( sNameF, sMilling) if not nMchFId then local sErr = 'Error adding machining ' .. sNameF .. '-' .. sMilling EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ Proc.Id, 0}}) -- limito opportunamente la lavorazione local dSal = EgtIf( i == 1, -dStartDist, - dStartAccDist - ( i - 2) * dC) EgtSetMachiningParam( MCH_MP.STARTADDLEN, dSal) local dEal = EgtIf( i == nC, -dEndDist, - dEndAccDist - ( nC - i - 1) * dC) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal) -- imposto offset radiale EgtSetMachiningParam( MCH_MP.OFFSR, ( k - 1) * dStep - BD.CUT_EXTRA) -- imposto posizione braccio porta testa per non ingombrare agli estremi EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- imposto uso della faccia EgtSetMachiningParam( MCH_MP.FACEUSE, nFaceUse) -- verifico massimo affondamento rispetto ad elevazione if dElev > dMaxDepth + 10 * GEO.EPS_SMALL then sWarn = 'Warning in LongCut : depth (' .. EgtNumToString( dElev, 1) .. ') bigger than max tool depth (' .. EgtNumToString( dMaxDepth, 1) .. ')' end local dDepth = min( 0, dMaxDepth - dElev ) EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end end -- eventuale lavorazione della faccia limitante l'inizio if i == 1 and not bStartFixed then local vtIni = EgtIf( bFront, X_AX(), -X_AX()) for i = 1, Proc.Fct - 1 do local _, vtN = EgtSurfTmFacetCenter( Proc.Id, i, GDB_ID.ROOT) if vtIni * vtN > 0 then MakeSideFace( Proc.Id, i, nSide, sMilling, dToolDiam) end end end end -- eventuale lavorazione della faccia limitante la fine if not bEndFixed then local vtFin = EgtIf( bFront, -X_AX(), X_AX()) for i = 1, Proc.Fct - 1 do local _, vtN = EgtSurfTmFacetCenter( Proc.Id, i, GDB_ID.ROOT) if vtFin * vtN > 0 then MakeSideFace( Proc.Id, i, nSide, sMilling, dToolDiam) end end end -- altrimenti è sotto : lavorazione Long2CutDown else -- recupero la lavorazione local sMilling = ML.FindMilling( 'Long2CutDown') 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 = 0 local dMaxDepth = 0 local dThDiam = 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 dThDiam = EgtTdbGetCurrToolThDiam() or dThDiam end end -- larghezza faccia local _, _, dWidth = BL.GetFaceHvRefDim( Proc.Id, 0) -- aggiuntivo sull'affondamento local dAgg = BD.CUT_EXTRA -- determino se lavorazione da davanti o da dietro local bFront = ( vtN:getY() < 0) -- determino gli estremi local dStartDist = 0 local dStartAccDist = BD.LONGCUT_ENDLEN local bStartFixed = true if ( bLimXmin and bFront) or ( bLimXmax and not bFront) then dStartDist = dToolDiam / 2 dStartAccDist = BD.LONGCUT_MAXLEN bStartFixed = false end local dEndDist = 0 local dEndAccDist = BD.LONGCUT_ENDLEN local bEndFixed = true if ( bLimXmin and not bFront) or ( bLimXmax and bFront) then dEndDist = dToolDiam / 2 dEndAccDist = BD.LONGCUT_MAXLEN bEndFixed = false end -- determino il numero di parti in cui dividere la lavorazione local nC = ceil( ( dLen - dStartAccDist - dEndAccDist) / BD.LONGCUT_MAXLEN) local dC = 0 if nC > 0 then if bStartFixed and bEndFixed then dC = ( dLen - dStartAccDist - dEndAccDist) / nC elseif bStartFixed then dC = ( dLen - dStartAccDist) / ( nC + 1) dEndAccDist = dC elseif bEndFixed then dC = ( dLen - dEndAccDist) / ( nC + 1) dStartAccDist = dC else dC = dLen / ( nC + 2) dStartAccDist = dC dEndAccDist = dC end nC = nC + 2 else if dLen > min( dStartAccDist, dEndAccDist) then nC = 2 if bStartFixed and not bEndFixed then dStartAccDist = min( dStartAccDist, dLen/2) dEndAccDist = dLen - dStartAccDist elseif not bStartFixed and bEndFixed then dEndAccDist = min( dEndAccDist, dLen/2) dStartAccDist = dLen - dEndAccDist else dStartAccDist = dLen/2 dEndAccDist = dStartAccDist end else nC = 1 dStartAccDist = 0 dEndAccDist = 0 end end -- ciclo sulle parti local nM = 0 for j = 1, nC do -- Limitazioni della lavorazione local nPos = EgtIf( bFront, j, nC - j + 1) local dSal = EgtIf( nPos == 1, -dEndDist, -dEndAccDist - ( nPos - 2) * dC) local dEal = EgtIf( nPos == nC, -dStartDist, -dStartAccDist - ( nC - nPos - 1) * dC) -- Posizione braccio portatesta local nSCC if bFront then nSCC = EgtIf( ( BD.C_SIMM or j == 1 or j == nC - 1), MCH_SCC.ADIR_XM, MCH_SCC.ADIR_XP) else nSCC = EgtIf( ( BD.C_SIMM or j == 1 or j == nC - 1), MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) end -- inserisco le parti di lavorazione nM = nM + 1 local sNameF = 'L2C_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( nM) local nMchFId = EgtAddMachining( sNameF, sMilling) if not nMchFId then local sErr = 'Error adding machining ' .. sNameF .. '-' .. sMilling EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ Proc.Id, 0}}) -- limito opportunamente la lavorazione EgtSetMachiningParam( MCH_MP.STARTADDLEN, dSal) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal) -- imposto posizione braccio porta testa per non ingombrare agli estremi EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- imposto uso faccia EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_DOWN) -- imposto lato di lavoro e inversione EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) EgtSetMachiningParam( MCH_MP.INVERT, true) -- verifico massimo affondamento (tengo conto dell'inclinazione utensile e della pinza con estremità conica) local dCollSic = max( BD.COLL_SIC, ( dThDiam - dToolDiam) / 2 * abs( vtN:getY() / vtN:getZ()) - 3) if dWidth + dAgg > dMaxDepth - dCollSic then sWarn = 'Warning in LongCut : depth (' .. EgtNumToString( dWidth + dAgg, 1) .. ') bigger than max tool depth (' .. EgtNumToString( dMaxDepth - dCollSic, 1) .. ')' end local dDepth = min( dMaxDepth - dCollSic, dWidth + dAgg) EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end end end return true, sWarn end --------------------------------------------------------------------- return ProcessLongCut