Prima versione funzionante pulizia spigoli con fresa a V su tasche non passanti

This commit is contained in:
andrea.villa
2025-11-26 16:20:10 +01:00
parent 675b730dcf
commit e0c4f85bfb
+57 -46
View File
@@ -5935,11 +5935,11 @@ local function CalcInterference( nNewProc, vtExtr, ptCentr, dDiam1, dDiam2,
if bColl1 then return true end
local ptCentrGrid2 = ptCentr + ( vtExtr * ( dTall1 + 0.01))
frOriTool = Frame3d( ptCentrGrid2, vtExtr)
local bColl2 = EgtTestCylSurface( frOriTool, dDiam2/2, (dTall2-dTall1), nNewProc, 0, GDB_RT.GLOB)
local bColl2 = EgtTestCylSurface( frOriTool, dDiam2/2, dTall2, nNewProc, 0, GDB_RT.GLOB)
if bColl2 then return true end
local ptCentrGrid3 = ptCentr + ( vtExtr * ( dTall2 + 0.01))
frOriTool = Frame3d( ptCentrGrid3, vtExtr)
local bColl3 = EgtTestCylSurface( frOriTool, dDiam3/2, (dTall3-dTall2), nNewProc, 0, GDB_RT.GLOB)
local bColl3 = EgtTestCylSurface( frOriTool, dDiam3/2, dTall3, nNewProc, 0, GDB_RT.GLOB)
if bColl3 then return true end
-- restituisco risultato controllo collisioni
return false
@@ -5975,7 +5975,7 @@ end
local function AddMillCornerMachining( nPartId, nNewProc, nFacInd, tFacAdj, nAddGrpId,
dToolDiam, sMilling, dOffsAng,
dDiam1, dDiam2, dTall1,
dTall2, dDiam3, dTall3, bMakeLocSurf, vFace)
dTall2, dDiam3, dTall3, bMakeLocSurf, vFace, vtN)
-- variabili costruzione geometria
local pAuxId = {}
@@ -6019,7 +6019,7 @@ local function AddMillCornerMachining( nPartId, nNewProc, nFacInd, tFacAdj, nAdd
local nIdIniPoint
local nIdEndPoint
if ptLocP1 and ptLocP2 then
if true or ( dist( ptLocP1, tFacAdj[4]) < GEO.EPS_SMALL) or ( dist( ptLocP2, tFacAdj[4]) < GEO.EPS_SMALL) then
if ( dist( ptLocP1, tFacAdj[4]) < GEO.EPS_SMALL) or ( dist( ptLocP2, tFacAdj[4]) < GEO.EPS_SMALL) then
nIdEndPoint = 4
nIdIniPoint = 5
elseif ( dist( ptLocP1, tFacAdj[5]) < GEO.EPS_SMALL) or ( dist( ptLocP2, tFacAdj[5]) < GEO.EPS_SMALL) then
@@ -6044,21 +6044,20 @@ local function AddMillCornerMachining( nPartId, nNewProc, nFacInd, tFacAdj, nAdd
vtExtrExit = vtN2 + vtN3
vtExtrExit:normalize()
-- calcolo angolo tilt di 45°
vtExtr = vtExtrExit + vtN1
vtExtr = vtExtrExit + vtN
vtExtr:normalize()
local vtCheck = Vector3d(vtExtr)
-- se ho un offset angolare ruoto il percorso
if abs(dOffsAng) > 100 * GEO.EPS_SMALL then
vtCheck:rotate( vtN1, dOffsAng)
vtCheck:rotate( vtN, dOffsAng)
end
-- TODO ripristinare
-- controllo se c'è collisione con le facce della superfice
--if CalcInterference( nNewProc.Id, vtCheck, tFacAdj[nIdEndPoint], dDiam1, dDiam2,
-- dTall1, dTall2, dDiam3, dTall3) then
-- local sErr = 'Collision detect from clean corner tool and surface'
-- EgtOutLog( sErr)
-- return true, ''
--end
if CalcInterference( nNewProc.Id, vtCheck, tFacAdj[nIdEndPoint], dDiam1, dDiam2,
dTall1, dTall2, dDiam3, dTall3) then
local sErr = 'Collision detect from clean corner tool and surface'
EgtOutLog( sErr)
return true, ''
end
nAuxId = EgtLine( nAddGrpId, tFacAdj[nIdIniPoint], tFacAdj[nIdEndPoint], GDB_RT.GLOB)
table.insert( pAuxId, nAuxId)
-- se offset angolare valido e/o negativo creo il baffo precedente
@@ -6076,14 +6075,14 @@ local function AddMillCornerMachining( nPartId, nNewProc, nFacInd, tFacAdj, nAdd
EgtTrimExtendCurveByLen( nAuxId , -dLenTrimExt, ptApPoint, GDB_RT.GLOB)
-- se ho l'offset angolare ruoto la linea per compensare la rotazione che verrà applicata
if abs(dOffsAng) > 100 * GEO.EPS_SMALL then
EgtRotate( nAuxId, tFacAdj[nIdEndPoint], vtN1, -dOffsAng, GDB_RT.GLOB)
EgtRotate( nAuxId, tFacAdj[nIdEndPoint], vtN, -dOffsAng, GDB_RT.GLOB)
end
-- prendo il nuovo punto finale
ptApPoint = EgtEP( nAuxId, GDB_RT.GLOB)
else
-- se ho l'offset angolare ruoto la linea per compensare la rotazione che verrà applicata
if abs(dOffsAng) > 100 * GEO.EPS_SMALL then
EgtRotate( nAuxId, tFacAdj[nIdEndPoint], vtN1, -dOffsAng, GDB_RT.GLOB)
EgtRotate( nAuxId, tFacAdj[nIdEndPoint], vtN, -dOffsAng, GDB_RT.GLOB)
end
end
table.insert( pAuxId, nAuxId)
@@ -6111,14 +6110,14 @@ local function AddMillCornerMachining( nPartId, nNewProc, nFacInd, tFacAdj, nAdd
EgtTrimExtendCurveByLen( nAuxId , -dLenTrimExt, ptApPoint, GDB_RT.GLOB)
-- se ho l'offset angolare ruoto la linea per compensare la rotazione che verrà applicata
if abs(dOffsAng) > 100 * GEO.EPS_SMALL then
EgtRotate( nAuxId, tFacAdj[nIdEndPoint], vtN1, -dOffsAng, GDB_RT.GLOB)
EgtRotate( nAuxId, tFacAdj[nIdEndPoint], vtN, -dOffsAng, GDB_RT.GLOB)
end
-- prendo il nuovo punto finale
ptApPoint = EgtEP( nAuxId, GDB_RT.GLOB)
else
-- se ho l'offset angolare ruoto la linea per compensare la rotazione che verrà applicata
if abs(dOffsAng) > 100 * GEO.EPS_SMALL then
EgtRotate( nAuxId, tFacAdj[nIdEndPoint], vtN1, -dOffsAng, GDB_RT.GLOB)
EgtRotate( nAuxId, tFacAdj[nIdEndPoint], vtN, -dOffsAng, GDB_RT.GLOB)
end
end
table.insert( pAuxId, nAuxId)
@@ -6147,7 +6146,7 @@ local function AddMillCornerMachining( nPartId, nNewProc, nFacInd, tFacAdj, nAdd
EgtModifyCurveExtrusion( AuxId, vtExtr, GDB_RT.GLOB)
-- se ho un offset angolare ruoto il percorso
if abs(dOffsAng) > 100 * GEO.EPS_SMALL then
EgtRotate( AuxId, tFacAdj[nIdEndPoint], vtN1, dOffsAng, GDB_RT.GLOB)
EgtRotate( AuxId, tFacAdj[nIdEndPoint], vtN, dOffsAng, GDB_RT.GLOB)
end
-- inserisco la lavorazione
local sName = 'Clean_' .. ( EgtGetName( nNewProc.Id) or tostring( nNewProc.Id))
@@ -6197,7 +6196,7 @@ local function AddMillCornerMachining( nPartId, nNewProc, nFacInd, tFacAdj, nAdd
end
---------------------------------------------------------------------
local function AddMillCorner( vFace, Proc, dToolDiam, nAddGrpId, nMasterNewProc)
local function AddMillCorner( vFace, Proc, dToolDiam, nAddGrpId, nMasterNewProc, vtN)
local sMilling, dMaxDepth
-- se ripresa angolo con fresa cono 60° con ripresa
@@ -6271,13 +6270,21 @@ local function AddMillCorner( vFace, Proc, dToolDiam, nAddGrpId, nMasterNewProc)
if vFace[i].PPrev then
ptLoc3 = vFace[i].PPrev
else
ptLoc3 = Point3d( vFace[i].Cen:getX(), vFace[i].Cen:getY(), ptLoc1:getZ())
if abs( vtN:getZ()) > abs( vtN:getY()) then
ptLoc3 = Point3d( vFace[i].Cen:getX(), vFace[i].Cen:getY(), ptLoc1:getZ())
else
ptLoc3 = Point3d( vFace[i].Cen:getX(), ptLoc1:getY(), vFace[i].Cen:getZ())
end
end
-- punto successivo ( precedente della faccia successiva)
local k = EgtIf( j < #vFace, j + 1, EgtIf( bClosed, 1, nil))
-- se è un percorso aperto prendo il punto medio della seconda faccia come punto locale 2
if not k then
ptLoc2 = Point3d( vFace[j].Cen:getX(), vFace[j].Cen:getY(), ptLoc1:getZ())
if abs( vtN:getZ()) > abs( vtN:getY()) then
ptLoc2 = Point3d( vFace[j].Cen:getX(), vFace[j].Cen:getY(), ptLoc1:getZ())
else
ptLoc2 = Point3d( vFace[j].Cen:getX(), ptLoc1:getY(), vFace[j].Cen:getZ())
end
else
ptLoc2 = vFace[k].PPrev
end
@@ -6298,20 +6305,20 @@ local function AddMillCorner( vFace, Proc, dToolDiam, nAddGrpId, nMasterNewProc)
local bOk, sErr = AddMillCornerMachining( Proc.PartId, nNewProc, nFacInd, tFacAdj, nAddGrpId,
dToolDiam, sMilling, -dAngOffs,
dMillDiam, dMillTotDiam, abs( dThickTool),
dMaxDepth, dMillDiamTh, dToolLength, bMakeLocSurf, vFace)
dMaxDepth, dMillDiamTh, dToolLength, bMakeLocSurf, vFace, vtN)
if not bOk then return bOk, sErr end
-- secondo taglio
bOk, sErr = AddMillCornerMachining( Proc.PartId, nNewProc, nFacInd, tFacAdj, nAddGrpId,
dToolDiam, sMilling, dAngOffs,
dMillDiam, dMillTotDiam, abs( dThickTool),
dMaxDepth, dMillDiamTh, dToolLength, bMakeLocSurf, vFace)
dMaxDepth, dMillDiamTh, dToolLength, bMakeLocSurf, vFace, vtN)
if not bOk then return bOk, sErr end
-- altrimenti ho un solo percorso
else
local bOk, sErr = AddMillCornerMachining( Proc.PartId, nNewProc, nFacInd, tFacAdj, nAddGrpId,
dToolDiam, sMilling, 0,
dMillDiam, dMillTotDiam, abs( dThickTool),
dMaxDepth, dMillDiamTh, dToolLength, bMakeLocSurf, vFace)
dMaxDepth, dMillDiamTh, dToolLength, bMakeLocSurf, vFace, vtN)
if not bOk then return bOk, sErr end
end
end
@@ -6348,7 +6355,7 @@ local function GetOtherRegions( nPartId)
end
---------------------------------------------------------------------
local function GetFacesData( nNewProc, dToolDiam, dToolMaxDepth, dToolThick, nAddGrpId, nPartId)
local function GetFacesData( nNewProc, dToolDiam, dToolMaxDepth, dToolThick, nAddGrpId, nPartId, vtNBottom)
local nNumFacet = EgtSurfTmFacetCount( nNewProc)
local vFace = {}
@@ -6367,17 +6374,26 @@ local function GetFacesData( nNewProc, dToolDiam, dToolMaxDepth, dToolThick, nAd
local bAdj, ptLocP1, ptLocP2, dAng = EgtSurfTmFacetsContact( nNewProc, nPrecFac, nFac, GDB_ID.ROOT)
-- verifico che l'adiacenza sia veramente con il precedente (percorro con normale a destra)
if bAdj then
if ( vtN ^ ( ptLocP1 - ptCen)) * Z_AX() > 0 then
-- bAdj = false
if ( vtN ^ ( ptLocP1 - ptCen)) * vtNBottom > 0 then
bAdj = false
end
end
-- salvo i dati
vFace[i] = { Fac = nFac, Cen = ptCen, Norm = vtN, Len = dLen, Width = dWidth, AngPrev = EgtIf( bAdj, dAng, 0)}
if bAdj then
if ptLocP1:getZ() < ptLocP2:getZ() then
vFace[i].PPrev = ptLocP1
-- se rivolto verso Z
if abs( vtNBottom:getZ()) > abs( vtNBottom:getY()) then
if ptLocP1:getZ() < ptLocP2:getZ() then
vFace[i].PPrev = ptLocP1
else
vFace[i].PPrev = ptLocP2
end
else
vFace[i].PPrev = ptLocP2
if vtNBottom:getY() > 0 then
vFace[i].PPrev = EgtIf( ptLocP1:getY() < ptLocP2:getY(), ptLocP1, ptLocP2)
else
vFace[i].PPrev = EgtIf( ptLocP1:getY() > ptLocP2:getY(), ptLocP1, ptLocP2)
end
end
end
end
@@ -6487,7 +6503,7 @@ local function GetFacesData( nNewProc, dToolDiam, dToolMaxDepth, dToolThick, nAd
end
---------------------------------------------------------------------
local function ReorderFaces( nIdSurf, nNumFacet)
local function ReorderFaces( nIdSurf, nNumFacet, vtNBottom)
-- cerco una faccia senza precedenti
local nFirstFac
for i = 1, nNumFacet do
@@ -6499,7 +6515,7 @@ local function ReorderFaces( nIdSurf, nNumFacet)
if j ~= i then
-- verifico se è precedente
local bAdj, ptP1, _, _ = EgtSurfTmFacetsContact( nIdSurf, i - 1, j - 1, GDB_ID.ROOT)
if bAdj and ( vtN ^ ( ptCen - ptP1)) * Z_AX() > 0 then
if bAdj and ( vtN ^ ( ptCen - ptP1)) * vtNBottom > 0 then
bFoundPrec = true
break
end
@@ -6522,7 +6538,7 @@ local function ReorderFaces( nIdSurf, nNumFacet)
for j = i + 1, nNumFacet do
-- verifico se è successiva
local bAdj, ptP1, _, _ = EgtSurfTmFacetsContact( nIdSurf, i - 1, j - 1, GDB_ID.ROOT)
if bAdj and ( vtN ^ ( ptP1 - ptCen)) * Z_AX() > 0 then
if bAdj and ( vtN ^ ( ptP1 - ptCen)) * vtNBottom > 0 then
EgtSurfTmSwapFacets( nIdSurf, i, j - 1)
break
end
@@ -6531,12 +6547,12 @@ local function ReorderFaces( nIdSurf, nNumFacet)
end
---------------------------------------------------------------------
local function RemoveBottomFaceAndReorder( Proc, nAddGrpId, nFaceToDel)
local function RemoveBottomFaceAndReorder( Proc, nAddGrpId, nFaceToDel, vtN)
-- copio la superfice nel gruppo ausiliario
local nNewProc = EgtCopyGlob( Proc.Id, nAddGrpId) or GDB_ID.NULL
EgtSurfTmRemoveFacet( nNewProc, nFaceToDel)
local nNumFacet = EgtSurfTmFacetCount( nNewProc)
ReorderFaces( nNewProc, nNumFacet)
ReorderFaces( nNewProc, nNumFacet, vtN)
return nNewProc, nNumFacet
end
@@ -7703,18 +7719,13 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId, dOvmHead, bSinglePa
if not sWarn then sWarn = '' end
sWarn = EgtIf( #sWarn > 0, sWarn .. '\n' .. sWarn2, sWarn2)
end
-- altrimenti pulizia spigoli con fresa a V
elseif nCleanCorner > 0 then
end
-- se richiesta pulizia spigoli con fresa a V
if nCleanCorner > 0 then
local dThElev = dToolThDiameter / 2 * sqrt( vtN:getX() * vtN:getX() + vtN:getY() * vtN:getY())
local nNewProc = RemoveBottomFaceAndReorder( Proc, nAddGrpId, nFacInd)
local vFace, dDepth = GetFacesData( nNewProc, dToolDiameter, dMaxToolMaterial, ( dToolDiameter/2), nAddGrpId, Proc.PartId)
-- se elevazione superiore a massimo affondamento della fresa, riduco opportunamente
if dDiam + dThElev > dMaxToolMaterial + 10 * GEO.EPS_SMALL then
dDepth = dMaxToolMaterial - dDiam - dThElev
sWarn = 'Warning : elevation bigger than max tool depth'
EgtOutLog( sWarn)
end
local bCleanCornerOk, sCleanCornerWarn = AddMillCorner( vFace, Proc, dToolDiameter, nAddGrpId, nNewProc)
local nNewProc = RemoveBottomFaceAndReorder( Proc, nAddGrpId, nFacInd, vtN)
local vFace, dDepth = GetFacesData( nNewProc, dToolDiameter, dMaxToolMaterial, ( dToolDiameter/2), nAddGrpId, Proc.PartId, vtN)
local bCleanCornerOk, sCleanCornerWarn = AddMillCorner( vFace, Proc, dToolDiameter, nAddGrpId, nNewProc, vtN)
if not bCleanCornerOk then return false, sCleanCornerWarn end
if sCleanCornerWarn then
if not sWarn then sWarn = '' end