Files
DataWall/LuaLibs/WProcessFreeContour.lua
T
Dario Sassi 1e84898671 DataWall :
- corretta lavorazione LapJoint senza fondo con 3 lati.
2020-11-17 19:41:49 +00:00

722 lines
30 KiB
Lua

-- ProcessFreeContour.lua by Egaltech s.r.l. 2020/11/18
-- Gestione calcolo profilo libero per Pareti
-- Tabella per definizione modulo
local WPF = {}
-- Include
require( 'EgtBase')
local WL = require( 'WallLib')
EgtOutLog( ' WProcessFreeContour started', 1)
-- Dati
local WD = require( 'WallData')
local WM = require( 'WMachiningLib')
local WHISK_OFFS = 0.1
local WHISK_SAFE = 5
local MIN_LEN_CUT = 30
---------------------------------------------------------------------
-- Riconoscimento della feature
function WPF.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 WPF.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 dMillDiam = 20
local dMaxDepth = 0
if EgtMdbSetCurrMachining( sMilling) 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
-- verifico se ciclo chiuso
local bClosed = ( abs( vFace[1].AngPrev) > 0.1)
-- ciclo di inserimento delle fresate sulle facce del contorno in esame
local i = 1
-- se faccia finale con fine non lavorato, forzo partenza da prima faccia non tutta saltata (tipo 4)
if bClosed and ( vFace[#vFace].Type == 4 or ( vFace[#vFace].Type & 2) ~= 0) then
while i <= #vFace and vFace[i].Type == 4 do
i = i + 1
end
end
-- se facce tutte da saltare, parto dall'inizio
local bAllType4 = ( i > #vFace)
if bAllType4 then 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 = vFace[i].Width + WD.CUT_EXTRA
local vtNz = vFace[i].Norm:getZ()
if vtNz < 0 then
dDepth = dDepth - dMillDiam * abs( vtNz) / sqrt( 1 - vtNz * vtNz)
end
-- se affondamento superiore ai limiti della fresa
if dDepth > dMaxDepth then
-- lo limito e tolgo eventuali Tabs
dDepth = dMaxDepth
EgtSetMachiningParam( MCH_MP.LEAVETAB, false)
end
-- aggiungo geometria
EgtSetMachiningGeometry( {{ Proc.Id, vFace[i].Fac}})
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
local nSCC = MCH_SCC.ADIR_ZP
if abs( vFace[i].Norm:getZ()) < GEO.EPS_SMALL then
nSCC = MCH_SCC.ADIR_YP
end
EgtSetMachiningParam( MCH_MP.SCC, nSCC)
-- 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 = vFace[i].Width + WD.CUT_EXTRA
local vtNz = vFace[i].Norm:getZ()
if vtNz < 0 then
dDepth = dDepth - dMillDiam * abs( vtNz) / sqrt( 1 - vtNz * vtNz)
end
-- se affondamento superiore ai limiti della fresa
if dDepth > dMaxDepth then
-- lo limito e tolgo eventuali Tabs
dDepth = dMaxDepth
EgtSetMachiningParam( MCH_MP.LEAVETAB, false)
end
-- aggiungo geometria
local vGeom = {{ Proc.Id, vFace[i].Fac}}
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, EgtIf( bAllType4, nil, 1))
while j and ( ( vFace[j].Type & 1) ~= 0 or vFace[j].Type == 4) do
table.insert( vGeom, { Proc.Id, vFace[j].Fac})
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( j + 1 <= #vFace, j + 1, EgtIf( bAllType4 or not bClosed, nil, 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 AddSawings( sSawing, vFace, Proc, nRawId, b3Raw)
-- recupero i dati dell'utensile
local dSawDiam = 0
local dMaxDepth = 0
if EgtMdbSetCurrMachining( sSawing) 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
-- ciclo di inserimento dei tagli con sega a catena
for i = 1, #vFace do
-- se inizio faccia non tagliato completamente, inserisco un ripasso con sega a catena
if ( vFace[i].Type & 1) ~= 0 then
-- inserisco la lavorazione
local sName = 'Free_' .. ( EgtGetName( Proc.PartId) or tostring( Proc.PartId))
local nMchId = EgtAddMachining( sName, sSawing)
if not nMchId then
local sErr = 'Error adding machining ' .. sName .. '-' .. sSawing
EgtOutLog( sErr)
return false, sErr
end
-- calcolo l'affondamento
local dDepth = min( vFace[i].Width + WD.CUT_EXTRA, dMaxDepth)
-- aggiungo geometria
EgtSetMachiningGeometry( {{ Proc.Id, vFace[i].Fac}})
local dSal = - dSawDiam / 2
local dEal = vFace[i].Whisk - vFace[i].Len - dSawDiam / 2
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.NONE)
-- eseguo
if not EgtApplyMachining( true, false) then
local _, sErr = EgtGetLastMachMgrError()
EgtSetOperationMode( nMchId, false)
return false, sErr
end
end
-- se fine faccia non tagliato completamente o faccia non tagliata completamente e abbastanza lunga, inserisco un ripasso con sega a catena
if ( vFace[i].Type & 1) ~= 0 or ( vFace[i].Type == 4 and vFace[i].Len > dSawDiam + 1) then
-- inserisco la lavorazione
local sName = 'Free_' .. ( EgtGetName( Proc.PartId) or tostring( Proc.PartId))
local nMchId = EgtAddMachining( sName, sSawing)
if not nMchId then
local sErr = 'Error adding machining ' .. sName .. '-' .. sSawing
EgtOutLog( sErr)
return false, sErr
end
-- calcolo l'affondamento
local dDepth = min( vFace[i].Width + WD.CUT_EXTRA, dMaxDepth)
-- aggiungo geometria
EgtSetMachiningGeometry( {{ Proc.Id, vFace[i].Fac}})
local dSal = - dSawDiam / 2
local dEal = - dSawDiam / 2
if ( vFace[i].Type & 2) ~= 0 then
dSal = vFace[i].Whisk - vFace[i].Len - dSawDiam / 2
end
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.NONE)
-- eseguo
if not EgtApplyMachining( true, false) then
local _, sErr = EgtGetLastMachMgrError()
EgtSetOperationMode( nMchId, false)
return false, sErr
end
end
end
return true
end
---------------------------------------------------------------------
local function AddCuts( sCutting, vFace, Proc, nRawId, b3Raw, dSawThick)
-- 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
-- indice del successivo
local j = EgtIf( i < #vFace, i + 1, 1)
-- 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, vFace[i].Fac}})
-- assegno affondamento
local dDepth = vFace[i].Depth
local vtNz = vFace[i].Norm:getZ()
if vtNz < 0 then
dDepth = dDepth - dSawThick * abs( vtNz)
end
EgtSetMachiningParam( MCH_MP.DEPTH, dDepth)
-- verifico se va invertita la direzione di lavorazione perchè faccia verso l'alto (angolo maggiore di 0.01 deg)
local bInvert = ( vFace[i].Norm:getZ() > 0.0001745)
-- imposto inversione
EgtSetMachiningParam( MCH_MP.INVERT, bInvert)
-- imposto lato di lavoro
EgtSetMachiningParam( MCH_MP.WORKSIDE, EgtIf( bInvert, MCH_SAW_WS.LEFT, MCH_SAW_WS.RIGHT))
-- lato mandrino sempre a sinistra (rotazione lama oraria)
EgtSetMachiningParam( MCH_MP.HEADSIDE, MCH_SAW_HS.LEFT)
-- assegno i dati di attacco (sicurezza solo se angolo interno)
local nLeadIn = MCH_SAW_LI.CENT
if ( not bInvert and ( vFace[i].Type & 1) ~= 0) or ( bInvert and ( vFace[i].Type & 2) ~= 0) then
nLeadIn = MCH_SAW_LI.STRICT
end
EgtSetMachiningParam( MCH_MP.LEADINTYPE, nLeadIn)
if ( not bInvert and vFace[i].AngPrev < -0.1) or ( bInvert and vFace[j].AngPrev < -0.1) then
EgtSetMachiningParam( MCH_MP.STARTADDLEN, -WHISK_SAFE)
end
-- assegno i dati di uscita (sicurezza solo se angolo interno)
local nLeadOut = MCH_SAW_LO.CENT
if ( not bInvert and ( vFace[i].Type & 2) ~= 0) or ( bInvert and ( vFace[i].Type & 1) ~= 0) then
nLeadOut = MCH_SAW_LO.STRICT
end
EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, nLeadOut)
if ( not bInvert and vFace[j].AngPrev < -0.1) or ( bInvert and vFace[i].AngPrev < -0.1) then
EgtSetMachiningParam( MCH_MP.ENDADDLEN, -WHISK_SAFE)
end
-- posizione braccio porta testa
EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.NONE)
-- 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 curva associata
local bOpposite = false
local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i')
if AuxId then
AuxId = AuxId + Proc.Id
local vtExtr= EgtCurveExtrusion( AuxId, GDB_RT.GLOB)
if vtExtr then
bOpposite = ( Proc.Grp == 4 and vtExtr:getZ() < 0) or ( Proc.Grp == 3 and vtExtr:getZ() > 0)
end
end
-- recupero la lavorazione di taglio con lama e i suoi parametri
local sCutting, dSawDiam, dSawThick, dSawMaxDepth = WM.FindCutting( 'Standard')
if not sCutting then
local sErr = 'Error : cutting not found in library'
EgtOutLog( sErr)
return false, sErr
end
-- recupero i dati di tutte le facce
local vFace = {}
for i = 1, Proc.Fct do
-- indice faccia corrente e precedente
local nFac = EgtIf( bOpposite, Proc.Fct - i, i - 1)
local nPrecFac
if bOpposite then
nPrecFac = EgtIf( i == 1, 0, nFac + 1)
else
nPrecFac = EgtIf( i == 1, Proc.Fct - 1, i - 2)
end
-- recupero centro e normale della faccia
local ptCen, vtN = EgtSurfTmFacetCenter( Proc.Id, nFac, GDB_ID.ROOT)
-- recupero le dimensioni della faccia
local _, dLen, dWidth = WL.GetFaceHvRefDim( Proc.Id, nFac)
-- recupero l'angolo con la faccia precedente
local bAdj, _, _, dAng = EgtSurfTmFacetsContact( Proc.Id, nPrecFac, nFac, GDB_ID.ROOT)
-- salvo i dati
vFace[i] = { Fac = nFac, Cen = ptCen, Norm = vtN, Len = dLen, Width = dWidth, AngPrev = EgtIf( bAdj, dAng, 0)}
end
-- analizzo le facce
local dMaxWidth = 0
for i = 1, #vFace do
-- aggiorno la massima larghezza
if vFace[i].Width > dMaxWidth then
dMaxWidth = vFace[i].Width
end
-- 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 vtOrt = Vector3d( vFace[i].Norm:getX(), vFace[i].Norm:getY(), 0) ; vtOrt:normalize()
local vtDir = Vector3d( vtOrt) ; vtDir:rotate( Z_AX(), -90)
local vtUp = Vector3d( vtDir) ; vtUp:rotate( vFace[i].Norm, -90)
local ptIni = vFace[i].Cen + vFace[i].Width / 2 * vtUp + ( vFace[i].Len / 2 + WHISK_OFFS) * vtDir + WHISK_OFFS * vtOrt
local ptDir = ptIni + ( vFace[i].Whisk - WHISK_OFFS) * vtDir
local ptCross = ptDir + ( dSawThick - WHISK_OFFS) * vtOrt
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 vtOrt = Vector3d( vFace[i].Norm:getX(), vFace[i].Norm:getY(), 0) ; vtOrt:normalize()
local vtDir = Vector3d( vtOrt) ; vtDir:rotate( Z_AX(), 90)
local vtUp = Vector3d( vtDir) ; vtUp:rotate( vFace[i].Norm, 90)
local ptIni = vFace[i].Cen + vFace[i].Width / 2 * vtUp + ( vFace[i].Len / 2 + WHISK_OFFS) * vtDir + WHISK_OFFS * vtOrt
local ptDir = ptIni + ( vFace[i].Whisk - WHISK_OFFS) * vtDir
local ptCross = ptDir + ( dSawThick - WHISK_OFFS) * vtOrt
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
-- eventuali stampe
for i = 1, #vFace do
local Face = vFace[i]
local sOut = 'Face '..tostring( Face.Fac)..' C'..tostring( Face.Cen)..' N'..tostring( Face.Norm)..
' L='..EgtNumToString( Face.Len, 1)..' W='..EgtNumToString( Face.Width, 1)..' Ap='..EgtNumToString( Face.AngPrev, 1)..
' D='..EgtNumToString( Face.Depth, 1)..' B='..EgtNumToString( Face.Whisk, 1)..' T='..tostring( Face.Type)
EgtOutLog( sOut)
end
-- inserimento dei tagli di lama
local bCtOk, sCtErr = AddCuts( sCutting, vFace, Proc, nRawId, b3Raw, dSawThick)
if not bCtOk then return bCtOk, sCtErr end
-- recupero la lavorazione con sega a catena
local sSawing = WM.FindSawing( 'Sawing')
-- recupero la lavorazione di fresatura
local sMilling, dMillMaxDepth = WM.FindMilling( 'FreeContour', dMaxWidth + WD.CUT_EXTRA)
if not sMilling and not sSawing then
sMilling = WM.FindMilling( 'FreeContour')
if not sMilling then
local sErr = 'Error : milling not found in library'
EgtOutLog( sErr)
return false, sErr
end
end
-- se possibile, inserimento delle fresature
if sMilling then
local bMlOk, sMlErr = AddMillings( sMilling, vFace, Proc, nRawId, b3Raw)
if not bMlOk then return bMlOk, sMlErr end
-- altrimenti provo con la sega a catena
else
local bCsOk, sCSErr = AddSawings( sSawing, vFace, Proc, nRawId, b3Raw)
if not bCsOk then return bCsOk, sCsErr 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 : 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
-- lo limito e tolgo eventuali Tabs
dDepth = dMaxDepth
EgtSetMachiningParam( MCH_MP.LEAVETAB, false)
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
local nSCC = MCH_SCC.ADIR_ZP
if AreSameOrOppositeVectorApprox( vtExtr, Z_AX()) then
nSCC = EgtIf( Proc.Box:getDimX() >= Proc.Box:getDimY(), MCH_SCC.ADIR_YP, MCH_SCC.ADIR_XP)
end
EgtSetMachiningParam( MCH_MP.SCC, nSCC)
-- 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
local nSCC = MCH_SCC.ADIR_ZP
if AreSameVectorApprox( vtExtr, Z_AX()) then
nSCC = EgtIf( Proc.Box:getDimX() >= Proc.Box:getDimY(), MCH_SCC.ADIR_YP, MCH_SCC.ADIR_XP)
end
EgtSetMachiningParam( MCH_MP.SCC, nSCC)
-- 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 WPF.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 WPF