diff --git a/LuaLibs/ProcessMortise.lua b/LuaLibs/ProcessMortise.lua index 42c9201..846a814 100644 --- a/LuaLibs/ProcessMortise.lua +++ b/LuaLibs/ProcessMortise.lua @@ -82,7 +82,8 @@ end --------------------------------------------------------------------- -- Aggiunge la lavorazione di pulizia angoli - local function AddCleanCornersMachining( nProcId, sMortising, nWorkFaceInd, vtN) + local function AddCleanCornersMachining( nProcId, sMortising, nWorkFaceInd, vtN, dDepth) + -- aggiungo la lavorazione local sName = 'Mort_' .. ( EgtGetName( nProcId) or tostring( nProcId)) .. '_CleanCorners1' local nMchFId = EgtAddMachining( sName, sMortising) if not nMchFId then @@ -90,19 +91,28 @@ end EgtOutLog( sErr) return false, sErr end - sName = EgtGetOperationName( nMchFId) - -- aggiungo geometria + -- imposto geometria EgtSetMachiningGeometry( {{ nProcId, nWorkFaceInd}}) - local nFaceUse = BL.GetNearestParalOpposite( vtN) - local vtOrtho = BL.GetVersRef( nFaceUse) - -- imposto angolo 3° asse rot - EgtSetMachiningParam( MCH_MP.BLOCKEDAXIS, BL.GetChainSawBlockedAxis( 1)) - EgtSetMachiningParam( MCH_MP.INITANGS, BL.GetChainSawInitAngs( vtN, vtOrtho, 1)) + -- imposto lato di lavoro e inversione + local vtFaceN = EgtSurfTmFacetNormVersor( nProcId, nWorkFaceInd, GDB_ID.ROOT) + local bInvert = ( vtFaceN:getZ() < -GEO.EPS_SMALL or vtFaceN:getY() > GEO.EPS_SMALL) + EgtSetMachiningParam( MCH_MP.WORKSIDE, EgtIf( bInvert, MCH_MORTISE_WS.LEFT, MCH_MORTISE_WS.RIGHT)) + EgtSetMachiningParam( MCH_MP.INVERT, bInvert) + -- se richiesto, imposto affondamento + if dDepth then + EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) + end -- imposto uso del lato faccia + local nFaceUse = BL.GetNearestParalOpposite( vtN) EgtSetMachiningParam( MCH_MP.FACEUSE, nFaceUse) -- applico il parametro plunge, che setta la lavorazione per affondare solamente, senza lavorare tutto il contorno; 1: solo lato iniziale, 2: solo lato finale, 3: entrambi sNotes = 'Plunge=3;' EgtSetMachiningParam( MCH_MP.USERNOTES, sNotes) + -- imposto angolo 3° asse rot + local vtOrtho = BL.GetVersRef( nFaceUse) + EgtSetMachiningParam( MCH_MP.BLOCKEDAXIS, BL.GetChainSawBlockedAxis( 1)) + EgtSetMachiningParam( MCH_MP.INITANGS, BL.GetChainSawInitAngs( vtN, vtOrtho, 1)) + -- calcolo la lavorazione if not ML.ApplyMachining( true, false) then if EgtGetOutstrokeInfo() then local _, sErr = EgtGetLastMachMgrError() @@ -128,77 +138,95 @@ end --------------------------------------------------------------------- -- Pulizia angoli nel caso sia settato il parametro P04=1 -local function CleanCorners( Proc, dMorH, vtN, bOpenBtm, AuxId) +local function CleanCorners( Proc, dMorH, vtN, bDoubleDir, AuxId) -- verifico se è attiva la pulizia e se l'orientamento della feature è adeguato local bCleanCorners = ( EgtGetInfo( Proc.Id, 'P04', 'i') == 1 and - ( AreSameOrOppositeVectorApprox( vtN, X_AX()) or - AreSameOrOppositeVectorApprox( vtN, Y_AX()) or - AreSameOrOppositeVectorApprox( vtN, Z_AX()))) + ( AreSameOrOppositeVectorApprox( vtN, X_AX()) or + AreSameOrOppositeVectorApprox( vtN, Y_AX()) or + AreSameOrOppositeVectorApprox( vtN, Z_AX()))) + if not bCleanCorners then + EgtOutLog( 'Warning: mortising not aligned with XYZ axes, corner cleaning skipped') + return + end -- cerco la lavorazione adatta local sMortisingCleanCorners = ML.FindSawing( 'Mortising') - if bCleanCorners and sMortisingCleanCorners then - local dSawWidth = 50 - local dSawThick = 12 - local dMaxDepth = 200 - -- se non trova la lavorazione non faccio nulla - if not sMortisingCleanCorners then - local sWarn = 'Warning: mortising tool not found, corner cleaning skipped' - EgtOutLog( sWarn) - return true, sWarn - else - -- recupero i dati dell'utensile - if EgtMdbSetCurrMachining( sMortisingCleanCorners) then - local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) - if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then - dSawWidth = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dSawWidth - dSawThick = EgtTdbGetCurrToolParam( MCH_TP.THICK) or dSawThick - dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth - end - end - -- al momento se l'utensile non arriva salto la lavorazione - local dFullMorH = EgtIf( bOpenBtm, dMorH * 2, dMorH) - if dFullMorH > dMaxDepth + 10 * GEO.EPS_SMALL then - local sWarn = 'Warning in corner cleaning with mortise: elevation (' .. EgtNumToString( dFullMorH, 1) .. ') bigger than max tool depth (' .. EgtNumToString( dMaxDepth, 1) .. ')' - EgtOutLog( sWarn) - return true, sWarn - end - -- verifico se la tasca ha dimensioni sufficienti per l'utensile - local nSurf = EgtSurfTmByFlatContour( EgtGetParent( AuxId), AuxId, 0.05) - local frMor, dMortiseWidth, dMortiseThick = EgtSurfTmFacetMinAreaRectangle( nSurf, 0, GDB_ID.ROOT) - if abs( frMor:getVersX() * X_AX()) < abs( frMor:getVersY() * X_AX()) then - dMortiseWidth, dMortiseThick = dMortiseThick, dMortiseWidth - end - EgtErase( nFlat) - if dSawWidth >= dMortiseWidth + 10 * GEO.EPS_SMALL or dSawThick >= dMortiseThick + 10 * GEO.EPS_SMALL then - local sWarn = 'warning in corner cleaning with mortise: pocket too small' - EgtOutLog( sWarn) - return true, sWarn - end - -- cerco le due facce migliori da lavorare - local nWorkFaceInd, nWorkFaceInd2 - if AreSameOrOppositeVectorApprox( vtN, X_AX()) then - nWorkFaceInd, _, _ = BL.FindFaceBestOrientedAsAxis( Proc, vtN ^ Y_AX()) - nWorkFaceInd2, _, _ = BL.FindFaceBestOrientedAsAxis( Proc, vtN ^ Y_AX(), nWorkFaceInd) - else - nWorkFaceInd, _, _ = BL.FindFaceBestOrientedAsAxis( Proc, vtN ^ X_AX()) - nWorkFaceInd2, _, _ = BL.FindFaceBestOrientedAsAxis( Proc, vtN ^ X_AX(), nWorkFaceInd) - end - -- lavoro la prima faccia - local bOk1, sErr = AddCleanCornersMachining( Proc.Id, sMortisingCleanCorners, nWorkFaceInd, vtN) - -- lavoro la seconda faccia - local bOk2, sErr2 = AddCleanCornersMachining( Proc.Id, sMortisingCleanCorners, nWorkFaceInd2, vtN) - if sErr2 then - if not sErr then sErr = '' end - if sErr ~= sErr2 then - sErr = EgtIf( #sErr > 0, sErr .. '\n' .. sErr2, sErr2) - end - end - if not bOk1 or not bOk2 then - return false, sErr - end - return true, sErr + if not sMortisingCleanCorners then + EgtOutLog( 'Warning: mortising tool not found, corner cleaning skipped') + return + end + -- recupero i dati dell'utensile + local dSawWidth = 50 + local dSawThick = 12 + local dMaxDepth = 200 + if EgtMdbSetCurrMachining( sMortisingCleanCorners) then + local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then + dSawWidth = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dSawWidth + dSawThick = EgtTdbGetCurrToolParam( MCH_TP.THICK) or dSawThick + dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth end end + -- se l'utensile non arriva in fondo, riduco l'affondamento + local sWarn + local dDepth + local bUseDoubleDir + if bDoubleDir then + if ( 2 * dMorH + dSawWidth / 2) > dMaxDepth + 10 * GEO.EPS_SMALL then + bUseDoubleDir = true + if ( dMorH + dSawWidth / 2) > dMaxDepth + 10 * GEO.EPS_SMALL then + dDepth = dMaxDepth + sWarn = 'Warning in corner cleaning with mortise: elevation (' .. EgtNumToString( dMorH + dSawWidth / 2, 1) .. ') bigger than max tool depth (' .. EgtNumToString( dMaxDepth, 1) .. ')' + EgtOutLog( sWarn) + else + dDepth = dMorH + dSawWidth / 2 + end + else + dDepth = 2 * dMorH + dSawWidth / 2 + end + else + if dMorH > dMaxDepth + 10 * GEO.EPS_SMALL then + dDepth = dMaxDepth + sWarn = 'Warning in corner cleaning with mortise: elevation (' .. EgtNumToString( dMorH, 1) .. ') bigger than max tool depth (' .. EgtNumToString( dMaxDepth, 1) .. ')' + EgtOutLog( sWarn) + end + end + -- verifico se la tasca ha dimensioni sufficienti per l'utensile + local nFlat = EgtSurfTmByFlatContour( EgtGetParent( AuxId), AuxId, 0.05) + local frMor, dMortiseWidth, dMortiseThick = EgtSurfTmFacetMinAreaRectangle( nFlat, 0, GDB_ID.ROOT) + if abs( frMor:getVersX() * X_AX()) < abs( frMor:getVersY() * X_AX()) then + dMortiseWidth, dMortiseThick = dMortiseThick, dMortiseWidth + end + EgtErase( nFlat) + if dSawWidth >= dMortiseWidth + 10 * GEO.EPS_SMALL or dSawThick >= dMortiseThick + 10 * GEO.EPS_SMALL then + sWarn = 'warning in corner cleaning with mortise: pocket too small' + EgtOutLog( sWarn) + return true, sWarn + end + -- cerco le due facce migliori da lavorare + local nWorkFaceInd, nWorkFaceInd2 + if AreSameOrOppositeVectorApprox( vtN, X_AX()) then + nWorkFaceInd, _, _ = BL.FindFaceBestOrientedAsAxis( Proc, vtN ^ Y_AX()) + nWorkFaceInd2, _, _ = BL.FindFaceBestOrientedAsAxis( Proc, vtN ^ Y_AX(), nWorkFaceInd) + else + nWorkFaceInd, _, _ = BL.FindFaceBestOrientedAsAxis( Proc, vtN ^ X_AX()) + nWorkFaceInd2, _, _ = BL.FindFaceBestOrientedAsAxis( Proc, vtN ^ X_AX(), nWorkFaceInd) + end + -- lavoro la prima faccia + local bOk1, sErr = AddCleanCornersMachining( Proc.Id, sMortisingCleanCorners, nWorkFaceInd, vtN, dDepth) + -- lavoro la seconda faccia + local bOk2, sErr2 = AddCleanCornersMachining( Proc.Id, sMortisingCleanCorners, nWorkFaceInd2, vtN, dDepth) + if sErr2 then sErr = ( sErr or '') .. EgtIf( sErr, '\n', '') .. sErr2 end + -- se richiesto di lavorare dall'altra parte + if bUseDoubleDir then + local bOk3, sErr3 = AddCleanCornersMachining( Proc.Id, sMortisingCleanCorners, nWorkFaceInd, -vtN, dDepth) + if sErr3 then sErr = ( sErr or '') .. EgtIf( sErr, '\n', '') .. sErr3 end + local bOk4, sErr4 = AddCleanCornersMachining( Proc.Id, sMortisingCleanCorners, nWorkFaceInd2, -vtN, dDepth) + if sErr4 then sErr = ( sErr or '') .. EgtIf( sErr, '\n', '') .. sErr4 end + end + if not bOk1 or not bOk2 or not bOk3 or not bOk4 then + return false, sErr + end + return true, sWarn end --------------------------------------------------------------------- @@ -280,7 +308,7 @@ function ProcessMortise.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) local dMove = bxMin:getZ()-bxMax:getZ() -- se il percorso ausiliario è esterno al grezzo, lo riavvicino if abs( dMove) > GEO.EPS_SMALL then - AuxId = EgtCopyGlob( AuxId, BL.GetAddGroup(nPartId)) + AuxId = EgtCopyGlob( AuxId, BL.GetAddGroup( nPartId)) EgtMove( AuxId, Vector3d(0,0,-dMove)) EgtMove( nFlat, Vector3d(0,0,-dMove)) frMor, dL, dW = EgtSurfTmFacetMinAreaRectangle( nFlat, 0, GDB_ID.ROOT) @@ -409,8 +437,12 @@ function ProcessMortise.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) local nSCC = MCH_SCC.NONE if bPockAngTrasm then nSCC = MCH_SCC.ADIR_NEAR - elseif not BD.C_SIMM then - if vtN:getY() < GEO.EPS_SMALL then + elseif not BD.C_SIMM then + if abs( vtN:getX()) < GEO.EPS_SMALL and abs( vtN:getY()) < GEO.EPS_SMALL then + nSCC = MCH_SCC.ADIR_YM + elseif abs( vtN:getX()) < GEO.EPS_SMALL then + nSCC = MCH_SCC.ADIR_XP + elseif vtN:getY() < GEO.EPS_SMALL then nSCC = EgtIf( bRevertSide, MCH_SCC.ADIR_YP, MCH_SCC.ADIR_YM) else nSCC = EgtIf( bRevertSide, MCH_SCC.ADIR_YM, MCH_SCC.ADIR_YP) @@ -449,12 +481,6 @@ function ProcessMortise.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) EgtSetOperationMode( nMchFId, false) return false, sErr end - -- verifico se necessaria la pulizia degli angoli ( tenone ad angoli non raggiati) e applico nel caso - local _, sWarn2 = CleanCorners( Proc, dMorH, vtN, bOpenBtm, AuxId) - if sWarn2 then - if not sWarn then sWarn = '' end - sWarn = EgtIf( #sWarn > 0, sWarn .. '\n' .. sWarn2, sWarn2) - end -- Se non c'è il fondo e la lavorazione non ha lavorato tutta la superficie per limite altezza utensile -- inserisco una ulteriore lavorazione contraria if bOpenBtm and not bForceOneSide and nDepthMin and abs(nDepthMin) > 0 then @@ -475,11 +501,19 @@ function ProcessMortise.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) -- sistemo la direzione di lavoro EgtSetMachiningParam( MCH_MP.INVERT, EgtIf( bCW, true, false)) -- imposto posizione braccio porta testa - if vtN:getY() < GEO.EPS_SMALL then - EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP) - else - EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YM) + local nSCC = MCH_SCC.NONE + if not BD.C_SIMM then + if abs( vtN:getX()) < GEO.EPS_SMALL and abs( vtN:getY()) < GEO.EPS_SMALL then + nSCC = MCH_SCC.ADIR_YM + elseif abs( vtN:getX()) < GEO.EPS_SMALL then + nSCC = MCH_SCC.ADIR_XP + elseif vtN:getY() < GEO.EPS_SMALL then + nSCC = MCH_SCC.ADIR_YP + else + nSCC = MCH_SCC.ADIR_YM + end end + EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- se altezza mortasa differente da altezza massima lavorabile if abs( dMorH - dMaxDepth) > GEO.EPS_SMALL then nDepthMin = -dMorH @@ -497,6 +531,12 @@ function ProcessMortise.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) return false, sErr end end + -- verifico se necessaria la pulizia degli angoli ( tenone ad angoli non raggiati) e applico nel caso + local _, sWarn2 = CleanCorners( Proc, dMorH, vtN, bOpenBtm and not bForceOneSide, AuxId) + if sWarn2 then + if not sWarn then sWarn = '' end + sWarn = EgtIf( #sWarn > 0, sWarn .. '\n' .. sWarn2, sWarn2) + end return true, sWarn end