-- ProcessMortise.lua by Egaltech s.r.l. 2019/08/27 -- Gestione calcolo mortase per Travi -- Tabella per definizione modulo local ProcessMortise = {} -- Include require( 'EgtBase') local BL = require( 'BeamLib') EgtOutLog( ' ProcessMortise started', 1) -- Dati local BD = require( 'BeamData') local ML = require( 'MachiningLib') --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessMortise.Identify( Proc) return ( (( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 50) or (( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 51) or (( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 53)) end --------------------------------------------------------------------- -- Classificazione della feature function ProcessMortise.Classify( Proc) -- recupero i dati della faccia di fondo local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT) -- verifico sia una superficie if not vtN then return false end -- verifico se la mortasa è lavorabile solo da sotto local bDown = ( vtN:getZ() < - 0.1) return true, bDown end --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessMortise.Make( Proc, nPhase, nRawId, nPartId) -- 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) & 256) == 0 then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' missing profile geometry' EgtOutLog( sErr) return false, sErr end -- se curva aperta la allungo e chiudo if not EgtCurveIsClosed( AuxId) then local _, nCount = EgtCurveDomain( AuxId) EgtCloseCurveCompo( AuxId) EgtSetInfo( AuxId, 'OPEN', nCount) end -- recupero i dati del bottom local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT) EgtOutLog( 'ptC=' .. tostring( ptC) ..' vtN=' .. tostring( vtN), 3) -- verifico che la mortasa non sia orientata verso il basso (-5 deg) if vtN:getZ() < - 0.1 then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' Mortise from bottom impossible' EgtOutLog( sErr) return false, sErr end -- determino altezza della mortasa local frMor = Frame3d( ptC, vtN) local b3Mor = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, frMor) local dMorH = b3Mor:getDimZ() -- elevazione del punto centro local _, dCenElev = BL.GetPointDirDepth( nRawId, ptC, vtN) dMorH = max( dMorH, dCenElev or 0) -- recupero la lavorazione local sPocketing = ML.FindPocketing( 'Mortise', 30) 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 dMillDiam = 20 local dMaxDepth = 0 if EgtMdbSetCurrMachining( sPocketing) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam dMaxDepth = ( EgtTdbGetCurrToolMaxDepth() or dMaxDepth) end end -- inserisco la lavorazione di svuotatura local sName = 'Mort_' .. ( 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( {{ AuxId, -1}}) -- imposto posizione braccio porta testa if vtN:getY() < GEO.EPS_SMALL 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 local sWarn if dMorH > dMaxDepth + 10 * GEO.EPS_SMALL then sWarn = 'Warning in mortise : elevation (' .. EgtNumToString( dMorH,1) .. ') bigger than max tool depth (' .. EgtNumToString( dMaxDepth,1) .. ')' EgtSetMachiningParam( MCH_MP.DEPTH, dMaxDepth - dMorH) dMorH = dMaxDepth EgtOutLog( sWarn .. ' (process ' .. tostring( Proc.Id) .. ')') end -- imposto elevazione EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dMorH, 1) .. ';') -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end return true, sWarn end --------------------------------------------------------------------- return ProcessMortise