-- ProcessFreeContour.lua by Egaltech s.r.l. 2020/06/30 -- 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 WM = require( 'WMachiningLib') local WHISK_SAFE = 5 local MIN_LEN_CUT = 1 --------------------------------------------------------------------- -- 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 GetOtherRegions( nPartId) local vOthers = {} local nOtherId = EgtGetFirstPartInRawPart( EgtGetFirstRawPart() or GDB_ID.NULL) while nOtherId do local nRegId = EgtGetFirstInGroup( EgtGetFirstNameInGroup( nOtherId, 'Outline') or GDB_ID.NULL) while nRegId do local vtN = EgtSurfFrNormVersor( nRegId, GDB_ID.ROOT) if EgtExistsInfo( nRegId, 'REGION') and vtN and AreSameVectorApprox( vtN, Z_AX()) then local b3Reg = EgtGetBBoxGlob( nRegId, GDB_BB.STANDARD) if b3Reg then table.insert( vOthers, { PartId = nOtherId, RegId = nRegId, Box = b3Reg}) end end nRegId = EgtGetNext( nRegId) end nOtherId = EgtGetNextPartInRawPart( nOtherId) end return vOthers end --------------------------------------------------------------------- local function AddMillings( sMilling, vFace, Proc, nRawId, b3Raw) -- 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 -- ciclo di inserimento delle fresate sulle facce del contorno in esame, partendo da prima faccia non di tipo 4 local i = 1 while i <= #vFace and vFace[i].Type == 4 do i = i + 1 end while i <= #vFace do -- se inizio faccia senza taglio e non è successiva di senza taglio, inserisco una fresatura local j if abs( vFace[i].AngPrev) > 0.1 then j = EgtIf( i == 1, #vFace, i - 1) end if ( vFace[i].Type & 1) ~= 0 and ( not j or ( vFace[j].Type == 0 or vFace[j].Type == 1)) then -- inserisco la lavorazione local sName = 'Free_' .. ( EgtGetName( Proc.PartId) or tostring( Proc.PartId)) local nMchId = EgtAddMachining( sName, sMilling) if not nMchId then local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling EgtOutLog( sErr) return false, sErr end -- calcolo l'affondamento local dDepth = min( vFace[i].Width + WD.CUT_EXTRA, dMaxDepth) -- aggiungo geometria EgtSetMachiningGeometry( {{ Proc.Id, i - 1}}) local dSal = 0 local dEal = vFace[i].Whisk - vFace[i].Len EgtSetMachiningParam( MCH_MP.STARTADDLEN, dSal) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal) -- percorso da non invertire EgtSetMachiningParam( MCH_MP.INVERT, false) -- assegno utilizzo faccia EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_DOWN) -- assegno affondamento EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- assegno lato di lavoro EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT) -- 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 -- se tutta la faccia o la sua fine senza taglio, inserisco una fresatura if ( vFace[i].Type & 2) ~= 0 or vFace[i].Type == 4 then -- inserisco la lavorazione local sName = 'Free_' .. ( EgtGetName( Proc.PartId) or tostring( Proc.PartId)) local nMchId = EgtAddMachining( sName, sMilling) if not nMchId then local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling EgtOutLog( sErr) return false, sErr end -- calcolo l'affondamento local dDepth = min( vFace[i].Width + WD.CUT_EXTRA, dMaxDepth) -- aggiungo geometria local vGeom = {{ Proc.Id, i - 1}} local dSal = EgtIf( ( vFace[i].Type & 2) ~= 0, vFace[i].Whisk - vFace[i].Len, 0) local dEal = 0 i = i + 1 local j = EgtIf( i <= #vFace, i, 1) while ( vFace[j].Type & 1) ~= 0 or vFace[j].Type == 4 do table.insert( vGeom, { Proc.Id, j - 1}) dEal = EgtIf( ( vFace[j].Type & 1) ~= 0, vFace[j].Whisk - vFace[j].Len, 0) if ( vFace[j].Type & 1) ~= 0 then break end i = i + 1 j = EgtIf( i <= #vFace, i, 1) end EgtSetMachiningGeometry( vGeom) EgtSetMachiningParam( MCH_MP.STARTADDLEN, dSal) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal) -- percorso da non invertire EgtSetMachiningParam( MCH_MP.INVERT, false) -- assegno utilizzo faccia EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_DOWN) -- assegno affondamento EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- assegno lato di lavoro EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT) -- 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 else i = i + 1 end end return true end --------------------------------------------------------------------- local function AddCuts( sCutting, vFace, Proc, nRawId, b3Raw) -- ciclo di inserimento dei tagli sulle facce del contorno in esame for i = 1, #vFace do -- se non è faccia da saltare, inserisco il taglio di lama if vFace[i].Type ~= 4 then -- inserisco la lavorazione 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, vFace[i].Depth) -- assegno il lato di lavoro EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT) -- assegno i dati di attacco (sicurezza solo se angolo interno) local nLeadIn = EgtIf( ( vFace[i].Type & 1) == 0, MCH_SAW_LI.CENT, MCH_SAW_LI.STRICT) EgtSetMachiningParam( MCH_MP.LEADINTYPE, nLeadIn) if vFace[i].AngPrev < -0.1 then EgtSetMachiningParam( MCH_MP.STARTADDLEN, -WHISK_SAFE) end -- assegno i dati di uscita (sicurezza solo se angolo interno) local nLeadOut = EgtIf( ( vFace[i].Type & 2) == 0, MCH_SAW_LO.CENT, MCH_SAW_LO.STRICT) EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, nLeadOut) local j = EgtIf( i < #vFace, i + 1, 1) if vFace[j].AngPrev < -0.1 then EgtSetMachiningParam( MCH_MP.ENDADDLEN, -WHISK_SAFE) 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 end end return true 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 di fresatura local sMilling = WM.FindMilling( 'FreeContour') if not sMilling then local sErr = 'Error : milling not found in library' EgtOutLog( sErr) return false, sErr end -- recupero la lavorazione di taglio con lama local sCutting = WM.FindCutting( 'Standard') if not sCutting then local sErr = 'Error : cutting not found in library' EgtOutLog( sErr) return false, sErr end -- recupero i dati della lama local dSawDiam = 400 local dSawThick = 10 local dSawMaxDepth = 0 if EgtMdbSetCurrMachining( sCutting) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dSawDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dSawDiam dSawThick = EgtTdbGetCurrToolParam( MCH_TP.THICK) or dSawThick dSawMaxDepth = EgtTdbGetCurrToolMaxDepth() or dSawMaxDepth 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 precedente 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 -- analizzo le facce for i = 1, #vFace do -- verifico l'affondamento local dDepth = WD.CUT_EXTRA if vFace[i].Width + WD.CUT_EXTRA > dSawMaxDepth then dDepth = dSawMaxDepth - vFace[i].Width end -- lunghezza baffo local dElev = vFace[i].Width + dDepth local dWhisk = dElev * sqrt( dSawDiam / dElev - 1) + WHISK_SAFE -- determino la lunghezza del taglio passante e il tipo di attacco e uscita local dLen = vFace[i].Len local nType = 0 if vFace[i].AngPrev < -0.1 then dLen = dLen - dWhisk nType = nType + 1 end if vFace[EgtIf( i < Proc.Fct, i + 1, 1)].AngPrev < -0.1 then dLen = dLen - dWhisk nType = nType + 2 end -- se lunghezza non significativa, non va inserito il taglio if dLen < MIN_LEN_CUT then nType = 4 end vFace[i].Depth = dDepth vFace[i].Whisk = dWhisk vFace[i].Type = nType end -- recupero le regioni degli altri pezzi local vOthers = GetOtherRegions( Proc.PartId) -- verifico i baffi sporgenti dei tagli rispetto alle altre regioni local nAddGrpId = WL.GetAddGroup( Proc.PartId) for i = 1, #vFace do -- verifico il baffo iniziale if vFace[i].Type ~= 4 and ( vFace[i].Type & 1) == 0 then -- creo il rettangolo del baffo local vtDir = Vector3d( vFace[i].Norm) ; vtDir:rotate( Z_AX(), -90) local ptIni = vFace[i].Cen + vFace[i].Len / 2 * vtDir local ptDir = ptIni + vFace[i].Whisk * vtDir local ptCross = ptDir + dSawThick * vFace[i].Norm local WhId = EgtSurfFrRectangle3P( nAddGrpId, ptIni, ptCross, ptDir, GDB_RT.GLOB) local b3Wh = EgtGetBBoxGlob( WhId or GDB_ID.NULL, GDB_BB.STANDARD) -- verifico se interferisce con gli altri pezzi for j = 1, #vOthers do if OverlapsXY( b3Wh, vOthers[j].Box) then local nClass = EgtSurfFrChunkSimpleClassify( WhId, 0, vOthers[j].RegId, 0) if nClass ~= GDB_RC.OUT then local dLen = vFace[i].Len - vFace[i].Whisk + EgtIf( ( vFace[i].Type & 2) ~= 0, -vFace[i].Whisk, 0) if dLen >= MIN_LEN_CUT then vFace[i].Type = vFace[i].Type + 1 else vFace[i].Type = 4 end break end end end EgtErase( WhId) end -- verifico il baffo finale if vFace[i].Type ~= 4 and ( vFace[i].Type & 2) == 0 then -- creo il rettangolo del baffo local vtDir = Vector3d( vFace[i].Norm) ; vtDir:rotate( Z_AX(), 90) local ptIni = vFace[i].Cen + vFace[i].Len / 2 * vtDir local ptDir = ptIni + vFace[i].Whisk * vtDir local ptCross = ptDir + dSawThick * vFace[i].Norm local WhId = EgtSurfFrRectangle3P( nAddGrpId, ptIni, ptCross, ptDir, GDB_RT.GLOB) local b3Wh = EgtGetBBoxGlob( WhId or GDB_ID.NULL, GDB_BB.STANDARD) -- verifico se interferisce con gli altri pezzi for j = 1, #vOthers do if OverlapsXY( b3Wh, vOthers[j].Box) then local nClass = EgtSurfFrChunkSimpleClassify( WhId, 0, vOthers[j].RegId, 0) if nClass ~= GDB_RC.OUT then local dLen = vFace[i].Len - vFace[i].Whisk + EgtIf( ( vFace[i].Type & 1) ~= 0, -vFace[i].Whisk, 0) if dLen >= MIN_LEN_CUT then vFace[i].Type = vFace[i].Type + 2 else vFace[i].Type = 4 end break end end end EgtErase( WhId) end end -- inserimento dei tagli di lama local bCtOk, sCtErr = AddCuts( sCutting, vFace, Proc, nRawId, b3Raw) if not bCtOk then return bCtOk, sCtErr end -- inserimento delle fresature local bMlOk, sMlErr = AddMillings( sMilling, vFace, Proc, nRawId, b3Raw) if not bMlOk then return bMlOk, sMlErr 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 : 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 : 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 = WM.FindMilling( 'FreeContour') if not sMilling then local sErr = 'Error : 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 : 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 = WM.FindPocketing( 'Pocket', nil, dDepth) if not sPocketing then local sErr = 'Error : 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 : 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