-- ProcessChamfer.lua by Egaltech s.r.l. 2020/09/01 -- Gestione calcolo profilo libero per Travi -- Tabella per definizione modulo local ProcessChamfer = {} -- Include require( 'EgtBase') local BL = require( 'BeamLib') EgtOutLog( ' ProcessChamfer started', 1) -- Dati local BD = require( 'BeamData') local ML = require( 'MachiningLib') --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessChamfer.Identify( Proc) return ( ( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 36) end --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessChamfer.Make( Proc, nPhase, nRawId, nPartId) -- verifico se ha geometria ausiliaria (onde) local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') if AuxId then AuxId = AuxId + Proc.Id end -- recupero la lavorazione local sMilling = ML.FindMilling( 'Chamfer') 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 dMillDiam = 10 local dMaxMat = 20 if EgtMdbSetCurrMachining( sMilling) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam dMaxMat = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) or dMaxMat end end -- se onde if AuxId then -- inserisco la lavorazione local sName = 'Chm_' .. ( 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 -- impongo lavorazione dall'alto local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) if vtExtr:getZ() < 0 then EgtSetMachiningParam( MCH_MP.TOOLINVERT, true) EgtSetMachiningParam( MCH_MP.INVERT, true) end -- lavoro tenendo l'utensile a sinistra EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) -- imposto lavorazione a metà tagliente e senza step EgtSetMachiningParam( MCH_MP.DEPTH, dMaxMat / 2) EgtSetMachiningParam( MCH_MP.STEP, 0) -- imposto attacchi e uscite EgtSetMachiningParam( MCH_MP.STARTADDLEN, 0) EgtSetMachiningParam( MCH_MP.LIPERP, 3) EgtSetMachiningParam( MCH_MP.LITANG, 6) EgtSetMachiningParam( MCH_MP.LEADINTYPE, MCH_MILL_LI.TANGENT) EgtSetMachiningParam( MCH_MP.ENDADDLEN, 0) EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, MCH_MILL_LO.AS_LI) -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) -- eseguo if not ML.ApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchId, false) return false, sErr end -- altrimenti smusso standard else -- normale ed elevazione della faccia principale local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT) local _, dH, dV = EgtSurfTmFacetMinAreaRectangle( Proc.Id, 0, GDB_ID.ROOT) local _, dElev = BL.GetPointDirDepth( nPartId, ptC, vtN) local bFront = ( vtN:getY() < 0) -- 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 -- calcolo eventuali accorciamenti per facce limitanti local dAllExtr if dElev < dMillDiam / 2 then dAllExtr = -sqrt( dMillDiam * dElev - dElev * dElev) else dAllExtr = -dMillDiam / 2 end local dStartAll = 0 local dEndAll = 0 if vtN:getY() < 0 then if bLimXmax then dStartAll = dAllExtr end if bLimXmin then dEndAll = dAllExtr end else if bLimXmax then dEndAll = dAllExtr end if bLimXmin then dStartAll = dAllExtr end end -- determino numero di parti local dLen = Proc.Box:getDimX() -- calcolo la differenza tra lunghezza faccia 0 e lunghezza feature -- per far corrispondere i punti di inizio-fine delle lavorazioni multiple (a passi) local dAddLen = (( dH - dLen) / EgtIf( bLimXmax and bLimXmin , 2, 1)) 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) nC = nC + 2 else if dLen > min( dStartAccDist, dEndAccDist) then nC = 2 dC = dLen / 2 else nC = 1 dC = 0 end end -- eseguo le diverse parti for i = 1, nC do -- inserisco la lavorazione local sName = 'Chm_' .. ( 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 -- lavoro tenendo l'utensile a sinistra EgtSetMachiningParam( MCH_MP.INVERT, true) EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) -- imposto lavorazione un poco sotto local sDepth = 'TH+'..EgtNumToString( BD.CUT_EXTRA) EgtSetMachiningParam( MCH_MP.DEPTH_STR, sDepth) EgtSetMachiningParam( MCH_MP.STEP, 0) -- imposto utilizzo faccia EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_DOWN) -- imposto attacchi e uscite local dSal, dEal if bFront then dSal = EgtIf( i == 1, dStartAll, -( i - 1) * dC - dAddLen + 0.5) dEal = EgtIf( i == nC, dEndAll, -( nC - i) * dC - dAddLen + 0.5) else dSal = EgtIf( i == nC, dStartAll, -( nC - i) * dC - dAddLen + 0.5) dEal = EgtIf( i == 1, dEndAll, -( i - 1) * dC - dAddLen + 0.5) end EgtSetMachiningParam( MCH_MP.STARTADDLEN, dSal) EgtSetMachiningParam( MCH_MP.LIPERP, dMillDiam / 4) EgtSetMachiningParam( MCH_MP.LITANG, 0) EgtSetMachiningParam( MCH_MP.LEADINTYPE, MCH_MILL_LI.LINEAR) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal) EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, MCH_MILL_LO.AS_LI) -- imposto posizione braccio porta testa per non ingombrare agli estremi local nSCC = EgtIf( ( BD.C_SIMM or i == 1), MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- aggiungo geometria EgtSetMachiningGeometry( {{ Proc.Id, 0}}) -- eseguo if not ML.ApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchId, false) return false, sErr end end end return true end --------------------------------------------------------------------- return ProcessChamfer