-- ProcessLongCut.lua by Egaltech s.r.l. 2019/02/15 -- Gestione calcolo taglio longitudinale per Travi -- Tabella per definizione modulo local ProcessLongCut = {} -- Include require( 'EgtBase') EgtOutLog( ' ProcessLongCut started', 1) -- Dati local BD = require( 'BeamData') local Millings = require( 'MillingData') --------------------------------------------------------------------- -- 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) -- verifico le normali delle facce local nFacetCnt = EgtSurfTmFacetCount( Proc.Id) for i = 1, nFacetCnt do local vtN = EgtSurfTmFacetNormVersor( Proc.Id, i-1, GDB_ID.ROOT) if vtN:getZ() < - 0.707 then return true, true end end return true, false end --------------------------------------------------------------------- local function FindMilling( sType) for i = 1, #Millings do local Milling = Millings[i] if Milling.Type == sType then return i, Milling.Name end end return 0 end --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessLongCut.Make( Proc, nPhase, nRawId, nPartId) -- dati della faccia local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT) local dLen = Proc.Box:getDimX() local dWidth = sqrt( Proc.Box:getDimY() * Proc.Box:getDimY() + Proc.Box:getDimZ() * Proc.Box:getDimZ()) -- 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 che il taglio longitudinale non sia orientato verso il basso if vtN:getZ() < 0.0 then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' Longitudinal Cut from bottom impossible' EgtOutLog( sErr) return false, sErr end -- recupero la lavorazione local nMill, sMilling = 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 il diametro dell'utensile local dToolDiam = 0 if EgtMdbSetCurrMachining( sMilling) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dToolDiam end end local dStartDist = 0 if ( bLimXmin and vtN:getY() < 0) or ( bLimXmax and vtN:getY() > 0) then dStartDist = dToolDiam / 2 end local dEndDist = 0 if ( bLimXmin and vtN:getY() > 0) or ( bLimXmax and vtN:getY()< 0) then dEndDist = dToolDiam / 2 end -- se va fatta in 3 o più parti local nC = ceil( ( dLen - 2 * BD.LONGCUT_ENDLEN) / BD.LONGCUT_MAXLEN) if nC > 0 then local dC = ( dLen - 2 * BD.LONGCUT_ENDLEN) / nC nC = nC + 2 -- si percorre il lato basso della faccia local nM = 0 for i = 1, nC do -- ciclo sulle passate local nO = 1 local dStep = 0 if dWidth + 2 * BD.CUT_EXTRA > dToolDiam then nO = ceil(( dWidth + 2 * BD.CUT_EXTRA) / dToolDiam) if nO > 1 then dStep = ( dWidth + 2 * BD.CUT_EXTRA - dToolDiam) / ( nO - 1) 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, - BD.LONGCUT_ENDLEN - ( i - 2) * dC) EgtSetMachiningParam( MCH_MP.STARTADDLEN, dSal) local dEal = EgtIf( i == nC, -dEndDist, - BD.LONGCUT_ENDLEN - ( nC - i - 1) * dC) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal) -- imposto offset radiale (nullo se concavo) if k >1 then EgtSetMachiningParam( MCH_MP.OFFSR, ( k - 1) * dStep) else EgtSetMachiningParam( MCH_MP.OFFSR, - BD.CUT_EXTRA) end -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end end end -- altrimenti una o due parti else nC = EgtIf( dLen > BD.LONGCUT_ENDLEN, 2, 1) local dAccDist = EgtIf( nC == 2, dLen / 2, 0) -- si percorre il lato basso della faccia for i = 1, nC do -- inserisco le parti di lavorazione local sNameF = 'L2C_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) 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, - dAccDist) EgtSetMachiningParam( MCH_MP.STARTADDLEN, dSal) local dEal = EgtIf( i == nC, -dEndDist, - dAccDist) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal) -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end end -- se ci sono le facce limitanti for i = 1, Proc.Fct - 1 do -- inserisco la lavorazione local sNameF = 'L2C_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( i) 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, i}}) -- lato di lavoro e inversione EgtSetMachiningParam( MCH_MP.INVERT, true) EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) -- uso della faccia EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_DOWN) -- 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 end return true end --------------------------------------------------------------------- return ProcessLongCut