-- ProcessMortise.lua by Egaltech s.r.l. 2019/03/25 -- Gestione calcolo tacche per Travi -- Tabella per definizione modulo local ProcessBirdsMouth = {} -- Include require( 'EgtBase') local BL = require( 'BeamLib') local Tfs = require( 'TwoFacesBySaw') EgtOutLog( ' ProcessBirdsMouth started', 1) -- Dati local BD = require( 'BeamData') local Millings = require( 'MillingData') local Pocketings = require( 'PocketingData') --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessBirdsMouth.Identify( Proc) return ( ( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 20) end --------------------------------------------------------------------- -- Verifica se feature di testa function ProcessBirdsMouth.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 -- è di testa return true end --------------------------------------------------------------------- -- Verifica se feature di coda function ProcessBirdsMouth.IsTailFeature( Proc, b3Raw) -- verifico se è in coda if Proc.Box:getMin():getX() > b3Raw:getMin():getX() + BD.MAX_DIST_HTFEA then return false end -- è di coda return true end --------------------------------------------------------------------- -- Classificazione della feature function ProcessBirdsMouth.Classify( Proc) -- recupero il numero di facce della tacca local nFacCnt = EgtSurfTmFacetCount( Proc.Id) -- se 1 faccia if nFacCnt == 1 then return false -- se 2 facce elseif nFacCnt == 2 then -- dati delle facce local ptC = {} local vtN = {} ptC[1], vtN[1] = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT) ptC[2], vtN[2] = EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT) -- verifico se è lavorabile solo dal basso local bDown = (( vtN[1]:getZ() < BD.NZ_MINB and vtN[2]:getZ() < BD.NZ_MINB) or vtN[1]:getZ() < BD.NZ_MINA or vtN[2]:getZ() < BD.NZ_MINA) return true, bDown -- se più di due facce else -- recupero la faccia con il maggior numero di adiacenze più grande local nFacInd = BL.GetFaceWithMostAdj( Proc.Id) -- dati della faccia local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, nFacInd, GDB_ID.ROOT) -- verifico se è lavorabile solo dal basso local bDown = ( vtN:getZ() < BD.NZ_MINA) return true, bDown end end --------------------------------------------------------------------- -- Lavorazione con fresa --------------------------------------------------------------------- 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 --------------------------------------------------------------------- local function Make2FacesByMill( Proc, nPhase, nRawId, nPartId) -- recupero l'ingombro del grezzo di appartenenza local b3Raw = EgtGetRawPartBBox( nRawId) -- recupero il numero di facce della tacca local nFacCnt = EgtSurfTmFacetCount( Proc.Id) -- per ora solo caso con due facce if nFacCnt ~= 2 then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' BirdsMouth facet number not supported' EgtOutLog( sErr) return false, sErr end -- dati delle facce local ptC = {} local vtN = {} ptC[1], vtN[1] = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT) ptC[2], vtN[2] = EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT) -- dati medi local ptM = ( ptC[1] + ptC[2]) / 2 -- verifico non siano orientate verso il basso local bFaceOk = {} bFaceOk[1] = ( vtN[1]:getZ() >= BD.NZ_MINB) bFaceOk[2] = ( vtN[2]:getZ() >= BD.NZ_MINB) if not bFaceOk[1] and not bFaceOk[2] then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' BirdsMouth from bottom impossible' EgtOutLog( sErr) return false, sErr end -- scelta faccia da lavorare local nFacInd -- se entrambe possibili, scelgo quella con la normale più perpendicolare all'asse trave (se uguali, quella verso X+) if bFaceOk[1] and bFaceOk[2] then if abs( abs( vtN[1]:getX()) - abs( vtN[2]:getX())) < GEO.EPS_SMALL then if ptM:getX() > b3Raw:getCenter():getX() then nFacInd = EgtIf( vtN[1]:getX() > vtN[2]:getX(), 0, 1) else nFacInd = EgtIf( vtN[1]:getX() < vtN[2]:getX(), 0, 1) end else nFacInd = EgtIf( abs( vtN[1]:getX()) < abs( vtN[2]:getX()), 0, 1) end elseif bFaceOk[1] then nFacInd = 0 else nFacInd = 1 end local nOthInd = 1 - nFacInd -- recupero la lavorazione local nMill, sMilling = FindMilling( 'BirdsMouth') if not sMilling then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' milling not found in library' EgtOutLog( sErr) return false, sErr end -- inserisco la lavorazione di fresatura local sName = 'Mill_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMchFId = EgtAddMachining( sName, sMilling) if not nMchFId then local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ Proc.Id, nFacInd}}) -- imposto uso faccia e lato correzione if vtN[nOthInd+1]:getX() > 0 then EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.ORTHO_LEFT) else EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.ORTHO_RIGHT) end -- imposto lato di correzione EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) -- imposto posizione braccio porta testa if vtN[nFacInd+1]:getY() <= 0 then EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YM) else EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP) end -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end return true end --------------------------------------------------------------------- local function FindPocketing( sType) for i = 1, #Pocketings do local Pocketing = Pocketings[i] if Pocketing.Type == sType then return i, Pocketing.Name end end return 0 end --------------------------------------------------------------------- local function MakeMoreFacesByMill( Proc, nPhase, nRawId, nPartId) -- recupero l'ingombro del grezzo di appartenenza local b3Raw = EgtGetRawPartBBox( nRawId) -- recupero il numero di facce della tacca local nFacCnt = EgtSurfTmFacetCount( Proc.Id) assert( ( nFacCnt > 2), 'Error : MakeMoreFacesByMill in BirdsMouth with ' .. tostring( nFacCnt) .. ' faces') -- recupero la faccia con il maggior numero di adiacenze e l'elevazione relativa local nFacInd, dFacElev = BL.GetFaceWithMostAdj( Proc.Id) assert( nFacInd, 'Error : MakeMoreFacesByMill could not find reference face') -- dati della faccia local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, nFacInd, GDB_ID.ROOT) -- verifico non sia orientata verso il basso local bFaceOk = ( vtN:getZ() >= BD.NZ_MINB) if not bFaceOk then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' BirdsMouth from bottom impossible' EgtOutLog( sErr) return false, sErr end -- eventuali tagli preliminari -- per ora non previsti -- recupero la lavorazione local nMill, sPocketing = FindPocketing( 'Mortise') 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 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( {{ Proc.Id, nFacInd}}) -- imposto uso faccia EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.ORTHO_CONT) -- imposto posizione braccio porta testa if vtN: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 dFacElev > dMaxDepth + 10 * GEO.EPS_SMALL then EgtSetMachiningParam( MCH_MP.DEPTH, dMaxDepth - dFacElev) dFacElev = dMaxDepth local sWarn = 'Warning in process ' .. tostring( Proc.Id) .. ' : elevation bigger than max tool depth' EgtOutLog( sWarn) end -- imposto elevazione EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dFacElev, 1) .. ';') -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end return true end --------------------------------------------------------------------- local function MakeByMill( Proc, nPhase, nRawId, nPartId) -- recupero il numero di facce local nFacCnt = EgtSurfTmFacetCount( Proc.Id) -- richiamo la routine di lavorazione opportuna a seconda del numero di facce if nFacCnt <= 2 then return Make2FacesByMill( Proc, nPhase, nRawId, nPartId) else return MakeMoreFacesByMill( Proc, nPhase, nRawId, nPartId) end end --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessBirdsMouth.Make( Proc, nPhase, nRawId, nPartId) -- recupero l'ingombro del grezzo di appartenenza local b3Raw = EgtGetRawPartBBox( nRawId) -- dimensioni della feature local b3Fea = EgtGetBBoxGlob( Proc.Id, GDB_BB.STANDARD) -- numero di facce local nFacCnt = EgtSurfTmFacetCount( Proc.Id) -- se con due facce verifico che angolo non sia concavo e minore di - 90 deg local bConcClosed = false if nFacCnt == 2 then local _, _, _, dAng = EgtSurfTmFacetsContact( Proc.Id, 0, 1, GDB_ID.ROOT) bConcClosed = ( dAng < - 92) end -- con fresa local MAX_MILL_X = 80 local MAX_MILL_VOL = ( 80 * 240 * 20) / 2 -- se più di due facce o ( piccola o in coda e non concava chiusa) if nFacCnt > 2 or ((( b3Fea:getDimX() < MAX_MILL_X and b3Fea:getDimX() * b3Fea:getDimY() * b3Fea:getDimZ() < MAX_MILL_VOL) or b3Fea:getMin():getX() < b3Raw:getMin():getX() + 10) and not bConcClosed) then return MakeByMill( Proc, nPhase, nRawId, nPartId) -- con lama else return Tfs.Make( Proc, nPhase, nRawId, nPartId, 'HeadSide') end end --------------------------------------------------------------------- return ProcessBirdsMouth