From ce3fbd9b939b8bfbf6b2e6b78812977210457a05 Mon Sep 17 00:00:00 2001 From: "daniele.nicoli" Date: Fri, 5 Jun 2026 15:53:39 +0200 Subject: [PATCH] LapJoint CleanCorner - corretto calcolo inclinazione utensile (per utensili con angoli diversi) corretta e ottimizzata funzione controllo collisioni CalcInterference() e aggiunta inclinazione utensile in caso di Proc=25 Q01=2 --- LuaLibs/ProcessLapJoint.lua | 154 ++++++++++++++++++++++++------------ 1 file changed, 103 insertions(+), 51 deletions(-) diff --git a/LuaLibs/ProcessLapJoint.lua b/LuaLibs/ProcessLapJoint.lua index fea7633..f9924e7 100644 --- a/LuaLibs/ProcessLapJoint.lua +++ b/LuaLibs/ProcessLapJoint.lua @@ -2099,6 +2099,27 @@ local function MakeRoundCleanCornerOrContour( Proc, nPhase, nRawId, nPartId, b3R end end +--------------------------------------------------------------------- +local function CalcInterference( nNewProc, vtExtr, ptCentr, ToolData) + -- controllo collisione tagliente - finito + local ptCentrGrid1 = ptCentr + ( vtExtr * ( 10 * GEO.EPS_SMALL)) + local frOriTool = Frame3d( ptCentrGrid1, vtExtr) + local bColl1 = EgtTestConeSurface( frOriTool, ToolData.dToolDiam/2, ToolData.dToolTotDiam/2, ToolData.dCutEdgeLen, nNewProc, 0, GDB_RT.GLOB) + if bColl1 then return true end + -- controllo collisione gambo - finito + local ptCentrGrid2 = ptCentr + ( vtExtr * ToolData.dCutEdgeLen) + frOriTool = Frame3d( ptCentrGrid2, vtExtr) + local bColl2 = EgtTestCylSurface( frOriTool, ( ToolData.dStemDiameter + ( 10 * GEO.EPS_SMALL)) / 2, ToolData.dStemLen, nNewProc, 0, GDB_RT.GLOB) + if bColl2 then return true end + -- controllo collisione TH - finito + local ptCentrGrid3 = ptCentr + ( vtExtr * ( ToolData.dCutEdgeLen + ToolData.dStemLen)) + frOriTool = Frame3d( ptCentrGrid3, vtExtr) + local bColl3 = EgtTestCylSurface( frOriTool, ToolData.dDiamTh/2, ToolData.dLenTh, nNewProc, 0, GDB_RT.GLOB) + if bColl3 then return true end + -- restituisco risultato controllo collisioni + return false +end + --------------------------------------------------------------------- local function MakeSharpCleanCorner( Proc, nPhase, nRawId, nPartId, b3Raw, nFacInd, nAddGrpId, dDiam) @@ -2111,6 +2132,43 @@ local function MakeSharpCleanCorner( Proc, nPhase, nRawId, nPartId, b3Raw, nFacI local sMilling local dMaxDepth = 0 + -- recupero la lavorazione non calcolando l'elevazione + sMilling = ML.FindMilling( 'CleanCorner', ( 0.5 * dDiam)) + if not sMilling then + local sErr = 'Error : CleanCorner not found in library' + EgtOutLog( sErr) + return false, sErr + end + + -- recupero i dati dell'utensile + local ToolData = { + dToolTotDiam = 20, + dToolDiam = 20, + dSideAng = 0, + dCutEdgeLen = 20, + dToolLength = 20, + dStemDiameter = 20, + dStemLen = 20, + dDiamTh = 20, + dLenTh = 20 + } + if EgtMdbSetCurrMachining( sMilling) then + local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then + ToolData.dToolTotDiam = EgtTdbGetCurrToolParam( MCH_TP.TOTDIAM) or ToolData.dToolTotDiam + ToolData.dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or ToolData.dToolDiam + ToolData.dSideAng = EgtTdbGetCurrToolParam( MCH_TP.SIDEANG) or ToolData.dSideAng + ToolData.dCutEdgeLen = abs( EgtTdbGetCurrToolParam( MCH_TP.THICK)) or ToolData.dCutEdgeLen + ToolData.dToolLength = EgtTdbGetCurrToolParam( MCH_TP.LEN) or ToolData.dToolLength + ToolData.dStemDiameter = EgtTdbGetCurrToolParam( MCH_TP.STEMDIAM) or ToolData.dStemDiameter + ToolData.dDiamTh = EgtTdbGetCurrToolThDiam() or ToolData.dDiamTh + ToolData.dLenTh = EgtTdbGetCurrToolThLength() or ToolData.dLenTh + -- calcolo il secondo diametro del cono + ToolData.dToolTotDiam = ToolData.dToolDiam + ( abs( ToolData.dCutEdgeLen) * tan( ToolData.dSideAng)) * 2 + ToolData.dStemLen = ToolData.dToolLength - ToolData.dCutEdgeLen - ToolData.dLenTh + end + end + -- cerco l'angolo di riferimento dove applicare il percorso di pulitura, altrimenti esco local _, nIdLine, tFacAdj = ChooseCorner( Proc, nFacInd) if #tFacAdj == 0 then @@ -2136,6 +2194,8 @@ local function MakeSharpCleanCorner( Proc, nPhase, nRawId, nPartId, b3Raw, nFacI -- versore direzione local vtExtr = tFacAdj[nIdLine][nIdIniPoint] - tFacAdj[nIdLine][nIdEndPoint] vtExtr:normalize() + -- versore direzione di uscita + local vtExtrExit -- inserisco le prime tre linee if nIdIniPoint and nIdEndPoint then -- se fresatura da sotto salto la lavorazione @@ -2144,16 +2204,24 @@ local function MakeSharpCleanCorner( Proc, nPhase, nRawId, nPartId, b3Raw, nFacI EgtOutLog( sErr) return false, sErr end - -- sommo i tre versori per avre una direzione media - vtExtr = vtN1 + vtN2 + vtN3 + -- sommo i tre versori per avere una direzione media + vtExtrExit = vtN2 + vtN3 + vtExtrExit:normalize() + -- calcolo la componente Z dipendente dall'angolo tilt + local dAlfa = EgtClamp( ToolData.dSideAng, 15, 30) + local dGamma = 90 - asin( sqrt( 2) * sin( dAlfa)) + local dTanGamma = sin( dGamma) / cos( dGamma) + vtExtr = vtExtrExit + ( vtN2 ^ vtN3) * dTanGamma vtExtr:normalize() - -- recupero la lavorazione non calcolando l'elevazione - sMilling = ML.FindMilling( 'CleanCorner', ( 0.5 * dDiam)) - if not sMilling then - local sErr = 'Error : CleanCorner not found in library' + local vtCheck = Vector3d(vtExtr) + + -- controllo se c'è collisione con le facce della superfice + if CalcInterference( Proc.Id, vtCheck, tFacAdj[nIdLine][nIdEndPoint], ToolData) then + local sErr = 'Collision detected between clean corner tool and surface' EgtOutLog( sErr) - return false, sErr + return true, '' end + -- recupero i dati dell'utensile ( temporaneo, per compensare errore nella lavorazione) if EgtMdbSetCurrMachining( sMilling) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) @@ -6283,24 +6351,6 @@ local function ReorderFacesFromTab( nIdSurf, vFace) return nIdSurf end ---------------------------------------------------------------------- -local function CalcInterference( nNewProc, vtExtr, ptCentr, dDiam1, dDiam2, - dTall1, dTall2, dDiam3, dTall3) - local ptCentrGrid1 = ptCentr + ( vtExtr * 0.01) - local frOriTool = Frame3d( ptCentrGrid1, vtExtr) - local bColl1 = EgtTestConeSurface( frOriTool, dDiam1/2, dDiam2/2, dTall1, nNewProc, 0, GDB_RT.GLOB) - if bColl1 then return true end - local ptCentrGrid2 = ptCentr + ( vtExtr * ( dTall1 + 0.01)) - frOriTool = Frame3d( ptCentrGrid2, vtExtr) - 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, nNewProc, 0, GDB_RT.GLOB) - if bColl3 then return true end - -- restituisco risultato controllo collisioni - return false -end --------------------------------------------------------------------- local function MakeLocalSurf( ptP1, ptP2, ptP3, nAddGrpId) @@ -6331,8 +6381,7 @@ end --------------------------------------------------------------------- local function AddMillCornerMachining( nPartId, nNewProc, nFacInd, tFacAdj, nAddGrpId, dToolDiam, sMilling, dOffsAng, - dDiam1, dDiam2, dTall1, - dTall2, dDiam3, dTall3, bMakeLocSurf, vFace, vtN) + ToolData, bMakeLocSurf, vFace, vtN) -- variabili costruzione geometria local pAuxId = {} @@ -6412,8 +6461,7 @@ local function AddMillCornerMachining( nPartId, nNewProc, nFacInd, tFacAdj, nAdd vtCheck:rotate( vtN, dOffsAng) end -- controllo se c'è collisione con le facce della superfice - if CalcInterference( nNewProc.Id, vtCheck, tFacAdj[nIdEndPoint], dDiam1, dDiam2, - dTall1, dTall2, dDiam3, dTall3) then + if CalcInterference( nNewProc.Id, vtCheck, tFacAdj[nIdEndPoint], ToolData) then local sErr = 'Collision detect from clean corner tool and surface' EgtOutLog( sErr) return true, '' @@ -6561,32 +6609,39 @@ local function AddMillCorner( vFace, Proc, dToolDiam, nAddGrpId, nMasterNewProc, -- se ripresa angolo con fresa cono 60° con ripresa -- recupero la lavorazione di fresatura - sMilling, dMaxDepth = ML.FindMilling( 'CleanCorner60') + sMilling, dMaxDepth = ML.FindMilling( 'CleanCorner') if not sMilling then - local sErr = 'Error : CleanCorner 60 not found in library' + local sErr = 'Error : CleanCorner not found in library' EgtOutLog( sErr) return false, sErr end -- recupero i dati dell'utensile - local dMillDiam = 20 - local dMillTotDiam = 20 - local dMillDiamTh = 20 - local dToolLength = 20 - local dThickTool = 20 - local dSideAng = 0 + local ToolData = { + dToolTotDiam = 20, + dToolDiam = 20, + dSideAng = 0, + dCutEdgeLen = 20, + dToolLength = 20, + dStemDiameter = 20, + dStemLen = 20, + dDiamTh = 20, + dLenTh = 20 + } if EgtMdbSetCurrMachining( sMilling) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then - dMillDiamTh = EgtTdbGetCurrToolThDiam() or dMillDiamTh - dMillTotDiam = EgtTdbGetCurrToolParam( MCH_TP.TOTDIAM) or dMillTotDiam - dSideAng = EgtTdbGetCurrToolParam( MCH_TP.SIDEANG) or dSideAng - dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam - dThickTool = EgtTdbGetCurrToolParam( MCH_TP.THICK) or dThickTool - dToolLength = EgtTdbGetCurrToolParam( MCH_TP.LEN) or dToolLength - dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth -- qui è la distanza dal portautensile + ToolData.dToolTotDiam = EgtTdbGetCurrToolParam( MCH_TP.TOTDIAM) or ToolData.dToolTotDiam + ToolData.dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or ToolData.dToolDiam + ToolData.dSideAng = EgtTdbGetCurrToolParam( MCH_TP.SIDEANG) or ToolData.dSideAng + ToolData.dCutEdgeLen = abs( EgtTdbGetCurrToolParam( MCH_TP.THICK)) or ToolData.dCutEdgeLen + ToolData.dToolLength = EgtTdbGetCurrToolParam( MCH_TP.LEN) or ToolData.dToolLength + ToolData.dStemDiameter = EgtTdbGetCurrToolParam( MCH_TP.STEMDIAM) or ToolData.dStemDiameter + ToolData.dDiamTh = EgtTdbGetCurrToolThDiam() or ToolData.dDiamTh + ToolData.dLenTh = EgtTdbGetCurrToolThLength() or ToolData.dLenTh -- calcolo il secondo diametro del cono - dMillTotDiam = dMillDiam + ( abs(dThickTool) * tan(dSideAng)) * 2 + ToolData.dToolTotDiam = ToolData.dToolDiam + ( abs( ToolData.dCutEdgeLen) * tan( ToolData.dSideAng)) * 2 + ToolData.dStemLen = ToolData.dToolLength - ToolData.dCutEdgeLen - ToolData.dLenTh end end -- copio la feature nel layer di appoggio @@ -6664,21 +6719,18 @@ local function AddMillCorner( vFace, Proc, dToolDiam, nAddGrpId, nMasterNewProc, -- primo taglio local bOk, sErr = AddMillCornerMachining( Proc.PartId, nNewProc, nFacInd, tFacAdj, nAddGrpId, dToolDiam, sMilling, -dAngOffs, - dMillDiam, dMillTotDiam, abs( dThickTool), - dMaxDepth, dMillDiamTh, dToolLength, bMakeLocSurf, vFace, vtN) + ToolData, 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, vtN) + ToolData, 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, vtN) + ToolData, bMakeLocSurf, vFace, vtN) if not bOk then return bOk, sErr end end end