-- ProcessFreeContour.lua by Egaltech s.r.l. 2020/06/24 -- Gestione calcolo profilo libero per Pareti -- Tabella per definizione modulo local ProcessFreeContour = {} -- Include require( 'EgtBase') local WL = require( 'WallLib') EgtOutLog( ' ProcessFreeContour started', 1) -- Dati local WD = require( 'WallData') local ML = require( 'MachiningLib') --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessFreeContour.Identify( Proc) return ( ( Proc.Grp == 0 or Proc.Grp == 3 or Proc.Grp == 4) and ( Proc.Prc == 250 or Proc.Prc == 251 or Proc.Prc == 252)) end --------------------------------------------------------------------- -- Classificazione della feature function ProcessFreeContour.Classify( Proc, b3Raw) -- verifico se di tipo pocket local bPocket = ( EgtGetInfo( Proc.Id, 'PCKT', 'i') == 1) -- recupero la curva associata local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') if not AuxId then return false end AuxId = AuxId + Proc.Id local vtN = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) -- se tasca if bPocket then local bDown = ( vtN:getZ() < - 0.5) return false -- se altrimenti profilo orizzontale elseif abs( vtN:getZ()) < 0.5 then return false -- se altrimenti profilo verticale che non interessa tutta la sezione elseif Proc.Box:getMax():getZ() < b3Raw:getMax():getZ() - 2 then return false -- altrimenti è profilo verticale che interessa tutta la sezione else return true end end --------------------------------------------------------------------- local function MakeByCut( Proc, nRawId, b3Raw) -- ingombro del pezzo local Ls = EgtGetFirstNameInGroup( Proc.PartId, 'Box') local b3Solid = EgtGetBBoxGlob( Ls 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 la lavorazione local sCutting = ML.FindCutting( 'Standard') if not sCutting then local sErr = 'Error : cutting not found in library' EgtOutLog( sErr) return false, sErr end -- recupero i dati dell'utensile local dSawDiam = 400 local dMaxDepth = 0 if EgtMdbSetCurrMachining( sCutting) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dSawDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dSawDiam dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth end end -- recupero i dati di tutte le facce local vFace = {} for i = 1, Proc.Fct do -- recupero centro e normale della faccia local ptCen, vtN = EgtSurfTmFacetCenter( Proc.Id, i - 1, GDB_ID.ROOT) -- recupero le dimensioni della faccia local _, dLen, dWidth = WL.GetFaceHvRefDim( Proc.Id, i - 1) -- recupero l'angolo con la faccia successiva local bAdj, _, _, dAng = EgtSurfTmFacetsContact( Proc.Id, EgtIf( i == 1, Proc.Fct - 1, i - 2), i -1, GDB_ID.ROOT) -- salvo i dati vFace[i] = { Cen = ptCen, Norm = vtN, Len = dLen, Width = dWidth, AngPrev = EgtIf( bAdj, dAng, 0)} end -- ciclo sulle facce del contorno in esame for i = 1, Proc.Fct do -- verifico l'affondamento local dDepth = WD.CUT_EXTRA if vFace[i].Width + WD.CUT_EXTRA > dMaxDepth then dDepth = dMaxDepth - vFace[i].Width end -- lunghezza baffo local dElev = vFace[i].Width + dDepth local dWhisk = dElev * sqrt( dSawDiam / dElev - 1) -- determino la lunghezza del taglio passante e il tipo di attacco e uscita local dLen = vFace[i].Len local nLeadIn = MCH_SAW_LI.CENT local nLeadOut = MCH_SAW_LO.CENT if vFace[i].AngPrev < -0.1 then dLen = dLen - dWhisk nLeadIn = MCH_SAW_LI.STRICT end if vFace[EgtIf( i < Proc.Fct, i + 1, 1)].AngPrev < -0.1 then dLen = dLen - dWhisk nLeadOut = MCH_SAW_LO.STRICT end -- se lunghezza significativa, inserisco la lavorazione if dLen > 1 then local sName = 'Cut_' .. ( EgtGetName( Proc.PartId) or tostring( Proc.PartId)) .. '_' .. tostring( i) local nMchId = EgtAddMachining( sName, sCutting) if not nMchId then local sErr = 'Error adding machining ' .. sName .. '-' .. sCutting EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( { { Proc.Id, i - 1}}) -- percorso da non invertire EgtSetMachiningParam( MCH_MP.INVERT, false) -- assegno affondamento EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- assegno il lato di lavoro EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT) -- assegno il tipo di attacco EgtSetMachiningParam( MCH_MP.LEADINTYPE, nLeadIn) -- assegno il tipo di uscita EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, nLeadOut) -- posizione braccio porta testa EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_XP) -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchId, false) return false, sErr end end end return true end --------------------------------------------------------------------- local function MakeByMill( Proc, nRawId, b3Raw) -- ingombro del pezzo local Ls = EgtGetFirstNameInGroup( Proc.PartId, 'Box') local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD) if not b3Solid then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' part box not found' EgtOutLog( sErr) return false, sErr end -- recupero e verifico l'entità curva local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 if AuxId then AuxId = AuxId + Proc.Id end if not AuxId or ( EgtGetType( AuxId) & GDB_FY.GEO_CURVE) == 0 then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' missing profile geometry' EgtOutLog( sErr) return false, sErr end -- recupero i dati della curva e del profilo local dDepth = abs( EgtCurveThickness( AuxId)) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) local b3Aux = EgtGetBBoxGlob( AuxId, GDB_BB.STANDARD) local bToolInv = ( vtExtr:getZ() < -0.1) -- recupero la lavorazione local sMilling = ML.FindMilling( 'FreeContour') 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 dMaxDepth = 0 if EgtMdbSetCurrMachining( sMilling) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth end end -- eventuale spezzatura sul tratto più lungo se curva chiusa --BL.PutStartOnLonger( AuxId) -- verifiche per affondamento if b3Aux:getDimZ() > b3Raw:getDimZ() - 1.0 then dDepth = min( dDepth, b3Raw:getDimZ()) + WD.CUT_EXTRA end if dDepth > dMaxDepth then dDepth = dMaxDepth end -- inserisco la lavorazione local sName = 'Free_' .. ( 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 -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) -- percorso da non invertire EgtSetMachiningParam( MCH_MP.INVERT, false) -- se estrusione da sotto, inverto direzione fresa if bToolInv then EgtSetMachiningParam( MCH_MP.TOOLINVERT, true) end -- assegno affondamento EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- assegno lato di lavoro if Proc.Grp == 0 then EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.CENTER) elseif ( Proc.Grp == 3 and not bToolInv) or ( Proc.Grp == 4 and bToolInv) then EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) elseif ( Proc.Grp == 3 and bToolInv) or ( Proc.Grp == 4 and not bToolInv) then EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT) end -- posizione braccio porta testa EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_XP) -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchId, false) return false, sErr end return true end --------------------------------------------------------------------- local function MakeByPocket( Proc, nRawId, b3Raw) -- recupero e verifico l'entità curva local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 if AuxId then AuxId = AuxId + Proc.Id end if not AuxId or ( EgtGetType( AuxId) & GDB_FY.GEO_CURVE) == 0 then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' missing profile geometry' EgtOutLog( sErr) return false, sErr end -- recupero i dati della curva e del profilo local dDepth = abs( EgtCurveThickness( AuxId)) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) --local bToolInv = ( vtExtr:getZ() < -0.1) -- recupero la lavorazione local sPocketing = ML.FindPocketing( 'Pocket', nil, dDepth) 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 = '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( {{ AuxId, -1}}) -- imposto posizione braccio porta testa if vtExtr: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 dDepth > dMaxDepth + 10 * GEO.EPS_SMALL then dDepth = dMaxDepth local sWarn = 'Warning in process ' .. tostring( Proc.Id) .. ' : elevation bigger than max tool depth' EgtOutLog( sWarn) end EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- imposto elevazione EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dMaxDepth, 1) .. ';') -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end return true end --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessFreeContour.Make( Proc, nRawId, b3Raw) -- recupero la tipologia local bPocket = ( EgtGetInfo( Proc.Id, 'PCKT', 'i') == 1) -- se svuotatura if bPocket then return MakeByPocket( Proc, nRawId, b3Raw) -- se lati diritti, taglio con lama e pulizia angoli con fresa elseif true then return MakeByCut( Proc, nRawId, b3Raw) -- altrimenti contornatura else return MakeByMill( Proc, nRawId, b3Raw) end end --------------------------------------------------------------------- return ProcessFreeContour