-- ProcessTenon.lua by Egaltech s.r.l. 2023/03/28 -- Gestione calcolo tenone a coda di rondine per Travi -- 2021/04/08 Aggiunto controllo massimo materiale lavorabile dalla fresa. -- 2022/04/14 Aumentati un poco i limiti di orientamento verso il basso per FAST e PF. -- 2023/02/08 Aumentato il range per cui i tenoni vengono lavorati in sottosquadro. -- 2023/03/27 Migliorate condizioni scelta pretaglio con lama o fresa; gestione unificata con ProcessTenon. -- 2023/03/28 Corretta gestione faccia di base quando divisa in più parti per distanza massima da lavorare. -- 2024/02/29 Aumentato numero passaggi CR su tenone. Massimo 8 -- Tabella per definizione modulo local ProcessDtTenon = {} -- Include require( 'EgtBase') local BL = require( 'BeamLib') local Fbp = require( 'FaceByPocket') local Cut = require( 'ProcessCut') EgtOutLog( ' ProcessTenon started', 1) -- Dati local BD = require( 'BeamData') local ML = require( 'MachiningLib') --------------------------------------------------------------------- local function VerifyOrientation( Proc, vtN, b3Raw) -- se PF con testa da sotto o TURN, ammessa qualunque orientazione if ( BD.C_SIMM and BD.DOWN_HEAD) or BD.TURN then return true end -- se trave molto bassa if b3Raw:getDimZ() < 121 then -- se tenone praticamente in asse, accetto fino a -45 deg if abs( vtN:getY()) < 0.088 then return ( vtN:getZ() >= -0.7072) -- altrimenti accetto fino a -30deg else return ( vtN:getZ() >= -0.51) end -- se trave bassa elseif b3Raw:getDimZ() < 201 then -- se tenone praticamente in asse, accetto fino a -30 deg if abs( vtN:getY()) < 0.088 then return ( vtN:getZ() >= -0.51) -- se macchina Fast, pezzo stretto e inclinazione laterale non eccessiva, accetto fino a -27deg elseif ( not BD.C_SIMM) and abs( vtN:getY()) < 0.5 and b3Raw:getDimY() < 150.1 then return ( vtN:getZ() >= -0.454) -- altrimenti accetto fino a -23.5deg else return ( vtN:getZ() >= -0.399) end -- se trave medio-bassa elseif b3Raw:getDimZ() < 281 then -- se tenone praticamente in asse oppure pezzo stretto e inclinazione laterale non eccessiva, accetto fino a -25 deg if abs( vtN:getY()) < 0.088 or ( abs( vtN:getY()) < 0.5 and b3Raw:getDimY() < 150.1) then return ( vtN:getZ() >= -0.422) -- altrimenti, accetto fino a -15 deg else return ( vtN:getZ() >= -0.259) end -- se trave media elseif b3Raw:getDimZ() < 351 then -- se tenone praticamente in asse, accetto fino a -22 deg if abs( vtN:getY()) < 0.088 then return ( vtN:getZ() >= -0.375) -- altrimenti, accetto fino a -12.5 deg else return ( vtN:getZ() >= -0.216) end -- altrimenti else -- accetto fino a -12.5 deg return ( vtN:getZ() >= -0.216) end end --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessDtTenon.Identify( Proc) return ( ( Proc.Grp == 1 or Proc.Grp == 2) and Proc.Prc == 55) end --------------------------------------------------------------------- -- Classificazione della feature function ProcessDtTenon.Classify( Proc, b3Raw) -- recupero i dati della curva di contorno della faccia top local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') if not AuxId then return false end AuxId = AuxId + Proc.Id local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) -- verifico se il tenone è lavorabile solo da sotto local bDown = not VerifyOrientation( Proc, vtExtr, b3Raw) return true, bDown end --------------------------------------------------------------------- local function ApplyPocket( Proc, sPocketing, nStep, dSurfStep, nIdSurf, vtExtr) -- inserisco la lavorazione di svuotatura local sName = 'Pock_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. nStep local nMchFId = EgtAddMachining( sName, sPocketing) if not nMchFId then local sErr = 'Error adding machining ' .. sName .. '-' .. sPocketing return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ nIdSurf, -1}}) -- imposto uso faccia EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.ORTHO_CONT) if dSurfStep > 0 then local sNotes = EgtGetMachiningParam( MCH_MP.USERNOTES) or '' -- imposto elevazione sNotes = EgtSetValInNotes( sNotes, 'MaxElev', EgtNumToString( dSurfStep, 2)) EgtSetMachiningParam( MCH_MP.USERNOTES, sNotes) end -- imposto posizione braccio porta testa local nSCC = MCH_SCC.NONE if not BD.C_SIMM then nSCC = EgtIf( vtExtr:getX() < GEO.EPS_SMALL, MCH_SCC.ADIR_XM, MCH_SCC.ADIR_XP) end EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- eseguo if not ML.ApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end return true end --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessDtTenon.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) -- ingombro del grezzo local b3Raw = EgtGetRawPartBBox( nRawId) -- ingombro del pezzo local b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( nPartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) if not b3Solid then local sErr = 'Error : part box not found' EgtOutLog( sErr) return false, sErr end -- recupero e verifico l'entità curva local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') if AuxId then AuxId = AuxId + Proc.Id end if not AuxId or ( EgtGetType( AuxId) & GDB_FY.GEO_CURVE) == 0 then local sErr = 'Error : missing profile geometry' EgtOutLog( sErr) return false, sErr end -- recupero i dati della curva local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) local ptBC = EgtGP( AuxId, GDB_RT.GLOB) -- verifico che il tenone non sia orientato verso il basso if not VerifyOrientation( Proc, vtExtr, b3Raw) then local sErr = 'Error : DtTenon from bottom impossible' EgtOutLog( sErr) return false, sErr end -- determino altezza del tenone local frDtTen = Frame3d( ptBC, vtExtr) local b3DtTen = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, frDtTen) local dDtTenH = b3DtTen:getDimZ() -- assegno centro e normale della faccia top local vtN = vtExtr local ptC = ptBC + vtN * dDtTenH EgtOutLog( 'ptC=' .. tostring( ptC) ..' vtN=' .. tostring( vtN), 3) -- porto inizio curva a Zmax BL.PutStartOnTop( AuxId) -- ne determino l'asse local vtAx = EgtEV( AuxId, GDB_RT.GLOB) - EgtSV( AuxId, GDB_RT.GLOB) vtAx:normalize() -- abilitazione lavorazione da sotto local bMillUp = ( BD.DOWN_HEAD and vtExtr:getZ() > -0.259) local bMillDown = ( BD.DOWN_HEAD and vtExtr:getZ() < 0.174) -- se tenone inclinato o non esattamente alle estremità, necessario taglio di lama sulla testa if not AreSameOrOppositeVectorApprox( vtN, X_AX()) or ( Proc.Box:getMax():getX() < b3Raw:getMax():getX() - dOvmHead - 100 * GEO.EPS_SMALL and Proc.Box:getMin():getX() > b3Raw:getMin():getX() + 100 * GEO.EPS_SMALL) then -- recupero gruppo per geometria addizionale local nAddGrpId = BL.GetAddGroup( nPartId) if not nAddGrpId then local sErr = 'Error : missing AddGroup' EgtOutLog( sErr) return false, sErr end -- creo piano di taglio sulla testa del tenone e lo lavoro local AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptC, vtN, b3Solid, GDB_RT.GLOB) if AddId then EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) EgtSetInfo( AddId, 'TASKID', Proc.TaskId) -- solo per macchine tipo PF e simili: se pezzo piccolo, in coda, piano inclinato attorno a Z e inclinato verso il basso applico svuotatura if b3Solid:getDimX() < BD.LEN_SHORT_PART and vtExtr:getX() < 0 and abs( vtExtr:getY()) > 0.173 and vtExtr:getZ() < -0.1 and BD.C_SIMM then -- recupero la lavorazione local sPocketing = ML.FindPocketing( 'OpenPocket', nil, nil, nil, not bMillDown, bMillDown) if not sPocketing then local sErr = 'Error : pocketing '..sPockType..' not found in library' EgtOutLog( sErr) return false, sErr end -- eseguo le svuotature necessarie local bOk, sErr = Fbp.Make( Proc, AddId, 0, sPocketing, nPartId, b3Solid) if not bOk then return false, sErr end -- altrimenti applico taglio di lama else local CutProc = { Id = AddId, Grp = Proc.Grp, Prc = Proc.Prc, Box = Proc.Box, Fct = Proc.Fct, Flg = Proc.Flg, Head = Proc.Head, Tail = Proc.Tail, CutId = Proc.CutId, TaskId = Proc.TaskId, PartId = Proc.PartId} CutProc.AffectedFaces = BL.GetProcessAffectedFaces( CutProc) -- se esiste grezzo successivo non serve tagliare dal basso local bFromBottom local dTotalLength = 0 local nNextRawId = EgtGetNextRawPart( nRawId) while nNextRawId do dTotalLength = dTotalLength + EgtGetRawPartBBox( nNextRawId):getDimX() nNextRawId = EgtGetNextRawPart( nNextRawId) end if dTotalLength > BD.MinRaw and not Proc.Tail then bFromBottom = false else bFromBottom = ( b3Solid:getDimX() < BD.LEN_SHORT_PART and vtExtr:getZ() > 0.25) end local bOk, sErr = Cut.Make( CutProc, nPhase, nRawId, nPartId, dOvmHead, bFromBottom) if not bOk then return bOk, sErr end end end end -- recupero la lavorazione local sMillType = 'DtTenon' local sMilling = ML.FindMilling( sMillType .. EgtIf( bMillDown and not bMillUp, '_H2', ''), nil, nil, nil, nil, bMillUp, bMillDown) if not sMilling then local sErr = 'Error : milling not found in library' EgtOutLog( sErr) return false, sErr end -- recupero i dati dell'utensile local dTDiam = 50 local dMaxMat = 30 local bCW = true if EgtMdbSetCurrMachining( sMilling) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dTDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dTDiam dMaxMat = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) or dMaxMat local dSpeed = EgtMdbGetCurrMachiningParam( MCH_MP.SPEED) or 0 bCW = ( dSpeed >= 0) end end -- se necessario, cerco un utensile più lungo if dDtTenH > dMaxMat + 10 * GEO.EPS_SMALL then sMilling = ML.FindMilling( sMillType .. EgtIf( bMillDown and not bMillUp, '_H2', ''), nil, nil, nil, nil, bMillUp, bMillDown, nil, nil, 'Longest') if not sMilling then local sErr = 'Error : milling not found in library' EgtOutLog( sErr) return false, sErr end if not sMilling then local sErr = 'Error : DtTenon Height bigger than Tool Cutting edge' EgtOutLog( sErr) return false, sErr end -- riassegno dati utensile dTDiam = 50 dMaxMat = 30 bCW = true if EgtMdbSetCurrMachining( sMilling) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dTDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dTDiam dMaxMat = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) or dMaxMat local dSpeed = EgtMdbGetCurrMachiningParam( MCH_MP.SPEED) or 0 bCW = ( dSpeed >= 0) end end end -- calcolo distanza massima della curva dal punto più lontano della base tenone Dt (facet 0) local dMaxDist for i = 0, Proc.Fct - 1 do local ptFC, vtFN = EgtSurfTmFacetCenter( Proc.Id, i, GDB_ID.ROOT) if not AreSameVectorApprox( vtFN, vtN) or abs( ( ptFC - ptBC) * vtN) > 100 * GEO.EPS_SMALL then break end local nLoopId, nLoopCnt = EgtExtractSurfTmFacetLoops( Proc.Id, i, EgtGetParent( Proc.Id)) if nLoopId then local dUmin, dUmax = EgtCurveDomain( nLoopId) for dU = dUmin, dUmax do local ptP = EgtUP( nLoopId, dU, GDB_ID.ROOT) local ptNear = EgtNP( AuxId, ptP, GDB_ID.ROOT) local dDist = dist( ptP, ptNear) if not dMaxDist or dDist > dMaxDist then dMaxDist = dDist end end for j = 1, nLoopCnt do EgtErase( nLoopId + j - 1) end end end if not dMaxDist then local b3DtAux = EgtGetBBoxRef( AuxId, GDB_BB.STANDARD, frDtTen) dMaxDist = 2 * ( b3DtTen:getRadius() - b3DtAux:getRadius()) end EgtOutLog( 'MaxDist=' .. EgtNumToString( dMaxDist, 3), 3) -- Cicli di lavorazione (max 8) local MAX_PASS = 8 local nStep = min( ceil( dMaxDist / ( 0.7 * dTDiam)), MAX_PASS) local dStep = min( dMaxDist, 0.7 * dTDiam * MAX_PASS) / nStep for i = nStep, 1, -1 do -- inserisco la passata di lavorazione local sNameR = 'DtTn_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( i) local nMchRId = EgtAddMachining( sNameR, sMilling) if not nMchRId then local sErr = 'Error adding machining ' .. sNameR .. '-' .. sMilling EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) -- sistemo i parametri local dOffs = ( i - 1) * dStep EgtSetMachiningParam( MCH_MP.OFFSR, dOffs) local sUserNotes = EgtGetMachiningParam( MCH_MP.USERNOTES) or '' sUserNotes = EgtSetValInNotes( sUserNotes, 'MaxElev', EgtNumToString( dDtTenH, 1)) EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes) -- sistemo il lato e la direzione di lavoro EgtSetMachiningParam( MCH_MP.WORKSIDE, EgtIf( bCW, MCH_MILL_WS.LEFT, MCH_MILL_WS.RIGHT)) EgtSetMachiningParam( MCH_MP.INVERT, EgtIf( bCW, true, false)) -- imposto posizione braccio porta testa local nSCC = MCH_SCC.NONE if BD.TURN then if abs( vtAx:getY()) > abs( vtAx:getZ()) then nSCC = EgtIf( vtAx:getY() > 0, MCH_SCC.ADIR_YP, MCH_SCC.ADIR_YM) else nSCC = EgtIf( vtAx:getZ() > 0, MCH_SCC.ADIR_ZP, MCH_SCC.ADIR_ZM) end elseif not BD.C_SIMM then nSCC = MCH_SCC.ADIR_YM if abs( vtExtr:getY()) > 0.088 then nSCC = EgtIf( vtExtr:getX() < GEO.EPS_SMALL, MCH_SCC.ADIR_XM, MCH_SCC.ADIR_XP) end end EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- eseguo if not ML.ApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchRId, false) return false, sErr end end -- eventuale segnalazione ingombro di testa o coda if abs( vtN:getY()) > 0.1 or ( b3Raw:getDimZ() - Proc.Box:getDimZ()) < BD.MIN_HEIGHT then if Proc.Head then local dOffs = b3Raw:getMax():getX() - dOvmHead - Proc.Box:getMin():getX() if abs( vtN:getY()) < 0.1 and vtN:getZ() > 0.5 then dOffs = dOffs / 2 end BL.UpdateHCING( nRawId, dOffs) elseif Proc.Tail then local dOffs = Proc.Box:getMax():getX() - b3Solid:getMin():getX() if abs( vtN:getY()) < 0.1 and vtN:getZ() > 0.5 then dOffs = dOffs / 2 end BL.UpdateTCING( nRawId, dOffs) end end -- si controllano le ultime 5 facce della feature local nIndFace = -1 for i = 1, 5 do if abs( vtExtr * EgtSurfTmFacetNormVersor( Proc.Id, Proc.Fct-i, GDB_ID.ROOT)) < GEO.EPS_ANG_SMALL then nIndFace = Proc.Fct-i end end -- controllo se serve passaggio di finitura in caso il tenone non cominci dal bordo della trave (P14 > 0) if nIndFace > 0 then -- verifico se almeno uno dei punti iniziale e finale della curva giace in uno dei piani limite del pezzo, quindi se è un lato aperto local bOpen = false local ptIni = EgtSP( AuxId, GDB_RT.GLOB) local ptFin = EgtEP( AuxId, GDB_RT.GLOB) if ( abs( ptIni:getX() - b3Solid:getMax():getX()) < 100 * GEO.EPS_SMALL or abs( ptFin:getX() - b3Solid:getMax():getX()) < 100 * GEO.EPS_SMALL) or ( abs( ptIni:getX() - b3Solid:getMin():getX()) < 100 * GEO.EPS_SMALL or abs( ptFin:getX() - b3Solid:getMin():getX()) < 100 * GEO.EPS_SMALL) or ( abs( ptIni:getY() - b3Solid:getMax():getY()) < 100 * GEO.EPS_SMALL or abs( ptFin:getY() - b3Solid:getMax():getY()) < 100 * GEO.EPS_SMALL) or ( abs( ptIni:getY() - b3Solid:getMin():getY()) < 100 * GEO.EPS_SMALL or abs( ptFin:getY() - b3Solid:getMin():getY()) < 100 * GEO.EPS_SMALL) or ( abs( ptIni:getZ() - b3Solid:getMax():getZ()) < 100 * GEO.EPS_SMALL or abs( ptFin:getZ() - b3Solid:getMax():getZ()) < 100 * GEO.EPS_SMALL) or ( abs( ptIni:getZ() - b3Solid:getMin():getZ()) < 100 * GEO.EPS_SMALL or abs( ptFin:getZ() - b3Solid:getMin():getZ()) < 100 * GEO.EPS_SMALL) then bOpen = true end -- se entrambi i punti non sono sul limite pezzo if not bOpen then -- recupero la lavorazione sMillType = 'Tenon' sMilling = ML.FindMilling( sMillType .. EgtIf( bMillDown and not bMillUp, '_H2', ''), nil, nil, nil, nil, bMillUp, bMillDown) if not sMilling then local sErr = 'Error : milling to finish the tenon not found in library' EgtOutLog( sErr) return false, sErr end -- recupero i dati dell'utensile if EgtMdbSetCurrMachining( sMilling) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dTDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dTDiam dMaxMat = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) or dMaxMat local dSpeed = EgtMdbGetCurrMachiningParam( MCH_MP.SPEED) or 0 bCW = ( dSpeed >= 0) end -- inserisco la passata finale della lavorazione local sNameF = 'TenF_' .. ( 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, nIndFace}}) -- sistemo i parametri EgtSetMachiningParam( MCH_MP.DEPTH_STR, 'TH') -- sistemo il lato e la direzione di lavoro EgtSetMachiningParam( MCH_MP.WORKSIDE, EgtIf( bCW, MCH_MILL_WS.LEFT, MCH_MILL_WS.RIGHT)) EgtSetMachiningParam( MCH_MP.INVERT, EgtIf( bCW, true, false)) EgtSetMachiningParam( MCH_MP.LITANG, 0.7 * dTDiam) EgtSetMachiningParam( MCH_MP.LIPERP, 20) EgtSetMachiningParam( MCH_MP.LOTANG, 0.7 * dTDiam) EgtSetMachiningParam( MCH_MP.LOPERP, 20) local nFaceUse if vtExtr:getX() > -GEO.EPS_SMALL then nFaceUse = MCH_MILL_FU.PARAL_LEFT else nFaceUse = MCH_MILL_FU.PARAL_RIGHT end EgtSetMachiningParam( MCH_MP.FACEUSE, nFaceUse) -- imposto elevazione local sUserNotes = EgtGetMachiningParam( MCH_MP.USERNOTES) or '' sUserNotes = EgtSetValInNotes( sUserNotes, 'MaxElev', EgtNumToString( dDtTenH, 1)) EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes) -- imposto posizione braccio porta testa local nSCC = MCH_SCC.NONE if BD.TURN then if abs( vtAx:getY()) > abs( vtAx:getZ()) then nSCC = EgtIf( vtAx:getY() > 0, MCH_SCC.ADIR_YP, MCH_SCC.ADIR_YM) else nSCC = EgtIf( vtAx:getZ() > 0, MCH_SCC.ADIR_ZP, MCH_SCC.ADIR_ZM) end elseif not BD.C_SIMM then nSCC = MCH_SCC.ADIR_YM if abs( vtExtr:getY()) > 0.088 then nSCC = EgtIf( vtExtr:getX() < GEO.EPS_SMALL, MCH_SCC.ADIR_XM, MCH_SCC.ADIR_XP) end end EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- eseguo if not ML.ApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end end end end return true end --------------------------------------------------------------------- return ProcessDtTenon