diff --git a/LuaLibs/ProcessLapJoint.lua b/LuaLibs/ProcessLapJoint.lua index a88bd24..fbe37de 100644 --- a/LuaLibs/ProcessLapJoint.lua +++ b/LuaLibs/ProcessLapJoint.lua @@ -1,4 +1,4 @@ --- ProcessLapJoint.lua by Egaltech s.r.l. 2021/06/04 +-- ProcessLapJoint.lua by Egaltech s.r.l. 2021/06/11 -- Gestione calcolo mezzo-legno per Travi -- 2019/10/08 Agg. gestione OpenPocket. -- 2021/01/24 Con sega a catena ora sempre impostato asse A. @@ -15,6 +15,7 @@ -- 2021/04/27 Antischeggia solo se feature trasversali. -- 2021/05/12 Semplificata gestione diametro minimo utensile per svuotatura. -- 2021/06/04 Su U passante con faccia perpendicolare aggiunta si forza Pocket. +-- 2021/06/11 Su U passante e profona se non bastano due svuotature su faccia ortogonale si fa anche la faccia di fondo per qaunto possibile. -- Tabella per definizione modulo local ProcessLapJoint = {} @@ -439,6 +440,19 @@ local function GetFaceAdj( Proc, nFacInd, dH, dV, bOutLog) return nFacAdj end +--------------------------------------------------------------------- +local function CalcCollisionSafety( vtDir) + local dCollSic = 8 * BD.COLL_SIC + if abs( vtDir:getX()) > 0.996 or abs( vtDir:getY()) > 0.996 or abs( vtDir:getZ()) > 0.996 then + dCollSic = 0 + elseif abs( vtDir:getX()) > 0.866 or abs( vtDir:getY()) > 0.866 or abs( vtDir:getZ()) > 0.866 then + dCollSic = 2 * BD.COLL_SIC + elseif abs( vtDir:getX()) > 0.707 or abs( vtDir:getY()) > 0.707 or abs( vtDir:getZ()) > 0.707 then + dCollSic = 5 * BD.COLL_SIC + end + return dCollSic +end + --------------------------------------------------------------------- -- Verifica se feature di testa function ProcessLapJoint.IsHeadFeature( Proc, b3Raw, dCurrOvmH) @@ -1833,7 +1847,7 @@ local function ExtractExternalPaths( nPathInt, nNumIdAux, vtOrtho, b3Solid, nAdd end --------------------------------------------------------------------- -local function MakeChamfer( Proc, b3FacesUsed, nAddGrpId, vtOrtho, b3Solid, nSurfInt, dDepthCham) +local function MakeChamfer( Proc, bIs3Faces, nAddGrpId, vtOrtho, b3Solid, nSurfInt, dDepthCham) -- Se variabile globale indica che lo smusso è gi stato fatto, esco if bMadeChamfer then @@ -1849,7 +1863,7 @@ local function MakeChamfer( Proc, b3FacesUsed, nAddGrpId, vtOrtho, b3Solid, nSur end -- ottengo le curve di contorno libero local nAuxId1, nAuxId2, nNumIdAux - if b3FacesUsed then + if bIs3Faces then -- nAuxId1, _ = EgtExtractSurfTmLoops( nSurfInt, nAddGrpId) -- EgtModifyCurveExtrusion( nAuxId1, vtOrtho, GDB_RT.GLOB) -- SetOpenSide( nAuxId1, vtOrtho, b3Solid, nAddGrpId, true) @@ -1870,7 +1884,7 @@ local function MakeChamfer( Proc, b3FacesUsed, nAddGrpId, vtOrtho, b3Solid, nSur for i = 1, nNumIdAux do local AuxId local vtExtr - if b3FacesUsed then + if bIs3Faces then if i == 1 then AuxId = nAuxId1 else @@ -1886,11 +1900,11 @@ local function MakeChamfer( Proc, b3FacesUsed, nAddGrpId, vtOrtho, b3Solid, nSur vtExtr, _, _ = EgtCurveArea( AuxId) end if vtExtr then - if not b3FacesUsed then + if not bIs3Faces then local fFrCurve = EgtGetGlobFrame( AuxId) vtExtr:toGlob( fFrCurve) end --- if b3FacesUsed and i == nNumIdAux then +-- if bIs3Faces and i == nNumIdAux then -- vtExtr = -vtExtr -- end -- Se normale entro certi limiti @@ -1916,11 +1930,11 @@ local function MakeChamfer( Proc, b3FacesUsed, nAddGrpId, vtOrtho, b3Solid, nSur end EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) -- assegno affondamento e offset radiale --- EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra - EgtIf( b3FacesUsed, (dDepth / 2), 0)) +-- EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra - EgtIf( bIs3Faces, (dDepth / 2), 0)) EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra) EgtSetMachiningParam( MCH_MP.OFFSR, dExtra) -- se opero su 3 facce e sono al secondo e ultimo percorso inverto la lavorazione --- if b3FacesUsed and i == nNumIdAux then +-- if bIs3Faces and i == nNumIdAux then -- EgtSetMachiningParam( MCH_MP.INVERT, true) -- end -- eseguo @@ -1949,21 +1963,21 @@ local function MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, rfFac, dH, dV, dElev, bForceUseBlade, dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace, bOrthoFacesMaster, nBottomFace, nChamfer, nAddGrpId, b3Solid, - dDepthCham, b3FacesUsed) + dDepthCham, bIs3Faces) local bOrthoFaces local sWarn -- ingombro del grezzo local b3Raw = EgtGetRawPartBBox( nRawId) -- ottengo la distanza tra la fine del pezzo e il pezzo successivo local dDistToNextPiece = EgtGetInfo( nRawId, 'BDST', 'd') or 5.4 - if b3FacesUsed then + if bIs3Faces then -- recupero la faccia con il maggior numero di adiacenze e l'elevazione relativa - local nFacInd1, dFacElev1, nFacInd2, dFacElev2 = BL.GetFaceWithMostAdj( Proc.Id, nPartId, b3FacesUsed) + local nFacInd1, dFacElev1, nFacInd2, dFacElev2 = BL.GetFaceWithMostAdj( Proc.Id, nPartId, bIs3Faces) if not nFacInd1 or nFacInd1 < 0 then if nFacInd1 == -1 then bOrthoFaces = nFacInd2 else - local sErr = 'Error : MakeByPockets could not find reference face' + local sErr = 'Error : MakeByChainOrSaw could not find reference face' EgtOutLog( sErr) return false, sErr end @@ -1978,7 +1992,7 @@ local function MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, -- verifico la direzione -- se devo inserire il chamfer if nChamfer > 0 then - local nOk, sErr = MakeChamfer( Proc, b3FacesUsed, nAddGrpId, vtOrtho, b3Solid, nSurfInt, dDepthCham) + local nOk, sErr = MakeChamfer( Proc, bIs3Faces, nAddGrpId, vtOrtho, b3Solid, nSurfInt, dDepthCham) if nOk < 0 then return false, sErr end end end @@ -2755,7 +2769,7 @@ local function GetUShapeWidth( Proc, nFacInd) end --------------------------------------------------------------------- -local function MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCham, nAddGrpId, sMchFindMaster, b3FacesUsed, b3Solid, bOrthoFacesMaster) +local function MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCham, nAddGrpId, sMchFindMaster, bIs3Faces, b3Solid, bOrthoFacesMaster) local bOrthoFaces local sWarn @@ -2765,9 +2779,9 @@ local function MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCha if sMchFindMaster and #sMchFindMaster > 0 then sMchFind = sMchFindMaster end - if b3FacesUsed then + if bIs3Faces then -- recupero la faccia con il maggior numero di adiacenze e l'elevazione relativa - local nFacInd, dFacElev, nFacInd2, dFacElev2 = BL.GetFaceWithMostAdj( Proc.Id, nPartId, b3FacesUsed) + local nFacInd, dFacElev, nFacInd2, dFacElev2 = BL.GetFaceWithMostAdj( Proc.Id, nPartId, bIs3Faces) if not nFacInd or nFacInd < 0 then if nFacInd == -1 then bOrthoFaces = nFacInd2 @@ -2787,7 +2801,7 @@ local function MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCha dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace, nSurfInt = GetTunnelDimension( Proc, nPartId) -- se devo inserire il chamfer if nChamfer > 0 then - local nOk, sErr = MakeChamfer( Proc, b3FacesUsed, nAddGrpId, vtOrtho, b3Solid, nSurfInt, dDepthCham) + local nOk, sErr = MakeChamfer( Proc, bIs3Faces, nAddGrpId, vtOrtho, b3Solid, nSurfInt, dDepthCham) if nOk < 0 then return -1, sErr end end -- se smusso non è esclusivo @@ -2801,40 +2815,42 @@ local function MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCha local nPathInt = EgtExtractSurfTmLoops( nSurfInt, nAddGrpId) EgtModifyCurveExtrusion( nPathInt, vtOrtho, GDB_RT.GLOB) -- se ho 3 facce, ciclo sulle entià del percorso per segnare quelle che sono aperte - if b3FacesUsed then + if bIs3Faces then SetOpenSide( nPathInt, vtOrtho, b3Solid, nAddGrpId) end -- variabili per parametri lavorazione local dMachDepth local dElev = 0 local bDoubleSide + -- imposto altezza aggiuntiva di elevazione + local dCollSic = CalcCollisionSafety( vtOrtho) -- se possibile svuotare completamente da una sola parte - if dMaxDepth > ( dDepth + 2) then - dMachDepth = (dDepth / 2) + 2 - dElev = dDepth + if dMaxDepth > ( dDepth + BD.CUT_EXTRA + dCollSic) then + dMachDepth = ( dDepth / 2) + BD.CUT_EXTRA + dElev = dDepth + BD.CUT_EXTRA else -- se direzione verso la verticale setto max affondamento possibile ed -- emetto messaggio di warning perché non lavorabile interamente if abs( vtOrtho:getZ()) >= 0.707 then - dMachDepth = dMaxDepth - (dDepth / 2) + dMachDepth = dMaxDepth - ( dDepth / 2) - dCollSic dElev = dMaxDepth sWarn = 'Warning : elevation bigger than max tool depth' EgtOutLog( sWarn) -- altrimenti setto il flag per fare la svuotatura da due parti else -- se l'altezza utensile riesce a lavorare completamente da due parti - if dMaxDepth > ( dDepth / 2) then - dMachDepth = 1 - dElev = ( dDepth / 2) + 1 + if dMaxDepth > ( dDepth / 2) + dCollSic + BD.CUT_EXTRA_MIN then + dMachDepth = BD.CUT_EXTRA_MIN + dElev = ( dDepth / 2) + BD.CUT_EXTRA_MIN -- altrimenti non si riesce in due passate, limito la profondità e setto l'elevazione else - dMachDepth = dMaxDepth - ( dDepth / 2) + dMachDepth = dMaxDepth - ( dDepth / 2) - dCollSic dElev = dMaxDepth -- se molto inclinato rispetto alla normale della faccia di riferimento, lavorazione non idonea per probabili collisioni local vtRef = Y_AX() if abs( vtOrtho:getX()) > abs( vtOrtho:getY()) and abs( vtOrtho:getX()) > abs( vtOrtho:getZ()) then vtRef = X_AX() - elseif abs( vtOrtho:getZ()) > abs( vtOrtho:getX()) and abs( vtOrtho:getZ()) > abs( vtOrtho:getX()) then + elseif abs( vtOrtho:getZ()) > abs( vtOrtho:getX()) and abs( vtOrtho:getZ()) > abs( vtOrtho:getY()) then vtRef = Z_AX() end if abs( vtOrtho * vtRef) < 0.5 then @@ -2845,7 +2861,7 @@ local function MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCha end end -- se lavorazione non idonea esco - if b3FacesUsed and bBadMach then + if bIs3Faces and bBadMach then local sErr = 'Impossible apply perpendicular pocketing: ' .. sPocketing return -2, sErr end @@ -2909,9 +2925,11 @@ local function MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCha if bDoubleSide then -- se anche lavorando dal lato opposto non riesco a svuotare completamente la fessura -- setto i parametri affondamento ed emetto warning - if 2 * dMaxDepth < dDepth then + local bComplete = true + if 2 * dMaxDepth < dDepth + 2 * BD.CUT_EXTRA + 2 * dCollSic then dMachDepth = dMaxDepth - (dDepth / 2) dElev = dMaxDepth + bComplete = false sWarn = 'Warning : elevation bigger than max tool depth' EgtOutLog( sWarn) end @@ -2963,6 +2981,64 @@ local function MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCha return -1, sErr end end + -- se non completo e U, cerco di lavorare anche la faccia di fondo (con il massimo affondamento possibile) + if not bComplete and bIs3Faces then + -- recupero la faccia da lavorare + local nFacInd = BL.GetFaceWithMostAdj( Proc.Id, nPartId) + local vtN + local bPock3rd = false + if nFacInd then + vtN = EgtSurfTmFacetNormVersor( Proc.Id, nFacInd, GDB_ID.ROOT) + bPock3rd = ( vtN and vtN:getZ() >= BD.NZ_MINA) + end + if bPock3rd then + -- inserisco la lavorazione di svuotatura + local sName = 'Pock3rd_' .. ( 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 -1, sErr + end + -- aggiungo geometria + EgtSetMachiningGeometry( {{ Proc.Id, nFacInd}}) + -- imposto posizione braccio porta testa + local nSCC = MCH_SCC.NONE + if not BD.C_SIMM then + if AreSameOrOppositeVectorApprox( vtN, Z_AX()) then + nSCC = MCH_SCC.ADIR_YM + elseif abs( vtN:getX()) < 0.1 then + nSCC = EgtIf( BL.IsPartFinalPhase( nPhase), MCH_SCC.ADIR_XM, MCH_SCC.ADIR_XP) + elseif vtN:getY() < GEO.EPS_SMALL then + nSCC = MCH_SCC.ADIR_YM + else + nSCC = MCH_SCC.ADIR_YP + end + end + EgtSetMachiningParam( MCH_MP.SCC, nSCC) + -- se tasca aperta, imposto opportuno attacco + if sMchFind == 'OpenPocket' then + EgtSetMachiningParam( MCH_MP.SUBTYPE, MCH_POCK_SUB.SPIRALIN) + end + -- inverto il percorso di lavorazione per lavorare sinistro + EgtSetMachiningParam( MCH_MP.INVERT, true) + -- imposto affondamento + EgtSetMachiningParam( MCH_MP.DEPTH, 0) + -- dichiaro non si generano sfridi per VMill + local sNotes = 'VMRS=0;' + EgtSetMachiningParam( MCH_MP.USERNOTES, sNotes) + -- eseguo + if not EgtApplyMachining( true, false) then + -- provo ad allargare leggermente la tasca + EgtSetMachiningParam( MCH_MP.OFFSR, -0.1) + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchFId, false) + return -1, sErr + end + end + end + end end return 1, sWarn, dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace end @@ -3413,14 +3489,7 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId, dOvmHead, bSinglePa if not bOk then return false, sErr end end -- imposto altezza aggiuntiva di elevazione - local dCollSic = 8 * BD.COLL_SIC - if abs( vtN:getX()) > 0.996 or abs( vtN:getY()) > 0.996 or abs( vtN:getZ()) > 0.996 then - dCollSic = 0 - elseif abs( vtN:getX()) > 0.866 or abs( vtN:getY()) > 0.866 or abs( vtN:getZ()) > 0.866 then - dCollSic = 2 * BD.COLL_SIC - elseif abs( vtN:getX()) > 0.707 or abs( vtN:getY()) > 0.707 or abs( vtN:getZ()) > 0.707 then - dCollSic = 5 * BD.COLL_SIC - end + local dCollSic = CalcCollisionSafety( vtN) -- abilitazione lavorazione da sotto local bMillUp = ( BD.DOWN_HEAD and vtN:getZ() > -0.259) local bMillDown = ( BD.DOWN_HEAD and vtN:getZ() < 0.342)