diff --git a/LuaLibs/ProcessLongCut.lua b/LuaLibs/ProcessLongCut.lua index 3f79280..8de28bc 100644 --- a/LuaLibs/ProcessLongCut.lua +++ b/LuaLibs/ProcessLongCut.lua @@ -62,6 +62,117 @@ function ProcessLongCut.Classify( Proc) return true, false end +--------------------------------------------------------------------- +-- Scelta posizione braccio +function ProcessLongCut.GetSCC( Proc, nFacet, nCuttingStep, bAreCuttingStepsTowardsHead, bIsTopBlade, nFaceUse, sMachining, bInvert) + + -- funzione per recuperare l'UUID utensile dalla lavorazione + local function GetToolUUID( sMachining) + if EgtMdbSetCurrMachining( sMachining) then + local sToolUUID = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + end + end + + -- funzione per calcolare i versori caratteristici di una feature + local function GetProcessSpecificVectors( Proc, nFacet, nFaceUse, bInvert) + local ptP1, ptPm, ptP2, vtV1, vtV2, dLen, dWidth = EgtSurfTmFacetOppositeSide( nSurfId, nFacet, BL.GetVersRef( nOrthoOpposite), GDB_ID.ROOT) + if not dLen or dLen < 1.1 or not dWidth or dWidth < 1.1 then + local sWarn = 'Face ' .. string.format( '%d,%d', nSurfId, nFacet) .. ' skipped : too small' + EgtOutLog( sWarn, 1) + return true, '' + end + local vtTg = ptP2 - ptP1 ; vtTg:normalize() + local dAllStart = 0 + local dAllEnd = 0 + -- se bilinea, scarto la parte più allineata con la direzione ortogonale (se deviazione angolare oltre 20 deg o lunghezza minore di dSawDiam/2 * cos( 20/2)) ma maggiore di un minimo + if ( ( ptPm - ptP1) - ( ptPm - ptP1) * vtTg * vtTg):len() > 100 * GEO.EPS_SMALL then + local vtTg1 = ptPm - ptP1 ; vtTg1:normalize() + local vtTg2 = ptP2 - ptPm ; vtTg2:normalize() + local dDist1 = dist( ptP1, ptPm) + local dDist2 = dist( ptP2, ptPm) + local dCosMax = 0.951 -- cos( 18°) + local dLenMin = 30 + local dLenMax = max( 0.5 * dSawDiam * 0.17365 + 1, 2 * dLenMin) + --if vtTg1 * vtTg2 < dCosMax or ( dDist1 < dLenMax and dDist1 > dLenMin) or ( dDist2 < dLenMax and dDist2 > dLenMin) then + if vtTg1 * vtTg2 < dCosMax then + local dOrtho1 = abs( vtTg1 * vtOrthO) + local dOrtho2 = abs( vtTg2 * vtOrthO) + if dOrtho1 < dOrtho2 or ( abs( dOrtho1 - dOrtho2) < 0.1 and dDist1 > 4 * dDist2) then + if dDist1 > dLenMin or dDist1 > 0.5 * dDist2 then + ptP2 = Point3d( ptPm) + dAllEnd = - dDist2 - 10 * GEO.EPS_SMALL + end + else + if dDist2 > dLenMin or dDist2 > 0.5 * dDist1 then + ptP1 = Point3d( ptPm) + dAllStart = - dDist1 - 10 * GEO.EPS_SMALL + end + end + vtTg = ptP2 - ptP1 ; vtTg:normalize() + end + end + local bWsRight = ( not bInvert) + local nWorkSide = EgtIf( bWsRight, MCH_MILL_WS.RIGHT, MCH_MILL_WS.LEFT) + -- Versore di riferimento + local vtRef = Vector3d( vtTg) + vtRef:rotate( vtN, EgtIf( bInvert, -90, 90)) + -- Versore esterno + local vtOut = vtRef - vtRef * vtTg * vtTg ; vtOut:normalize() + -- Versore ausiliario (direzione braccio) + local vtAux = Vector3d( vtN:getX(), vtN:getY(), 0) ; vtAux:normalize() + vtAux:rotate( Z_AX(), EgtIf( bWsRight, 90, -90)) + if vtAux:isSmall() then + vtAux = Vector3d( vtOut:getX(), vtOut:getY(), 0) ; vtAux:normalize() + else + if abs( vtAux * vtOut) < GEO.EPS_SMALL then + if abs( vtTg:getZ()) > 0.5 then + if vtAux * vtRef < 0 then + vtAux = - vtAux + end + elseif vtAux * vtTg > 0 then + vtAux = - vtAux + end + elseif vtAux * vtOut < 0 then + vtAux = - vtAux + end + end + EgtOutLog( 'vtN=' .. tostring( vtN) .. ' vtRef=' .. tostring( vtRef) .. ' vtOut=' .. tostring( vtOut) .. ' vtAux=' .. tostring( vtAux), 3) + return vtAux, vtRef, vtOut, vtTg + end + + local nSCC + local sToolUUID = GetToolUUID( sMachining) + local bIsBlade + if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sToolUUID) or '') then + bIsBlade = ( ( EgtTdbGetCurrToolParam( MCH_TP.TYPE) & MCH_TF.SAWBLADE) ~= 0) + end + + -- calcolo posizione braccio + -- se Fast e asse utensile diretto come Z posiziono l'aggregato in Y per avere il minore ingombro possibile + if not BD.C_SIMM and not BD.TURN and BL.AreSameVectorsApprox( vtN, Z_AX()) then + nSCC = MCH_SCC.ADIR_YM + -- se Fast o Turn posiziono l'aggregato in X per ottimizzare il pinzaggio + elseif not BD.C_SIMM then + if bAreCuttingStepsTowardsHead then + nSCC = EgtIf( ( not ( nCuttingStep == 1 or nCuttingStep == nC - 1)), MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) + else + nSCC = EgtIf( ( not ( nCuttingStep == 1 or nCuttingStep == nC - 1)), MCH_SCC.ADIR_XM, MCH_SCC.ADIR_XP) + end + -- per PF o simili e lama senza aggregato o fresa non do alcuna preferenza + elseif ( bIsBlade and not bIsTopBlade) or not bIsBlade then + nSCC = MCH_SCC.NONE + -- per PF o simili e lama con aggregato lo posiziono in Y per stare il più lontano possibile dalla trave + else + local vtAux = GetProcessSpecificVectors( Proc, nFacet, nFaceUse, bInvert) + if abs( vtAux:getX()) > abs( vtAux:getY()) - GEO.EPS_SMALL then + nSCC = EgtIf( ( vtAux:getX() > -GEO.EPS_SMALL), MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) + else + nSCC = EgtIf( ( vtAux:getY() > -GEO.EPS_SMALL), MCH_SCC.ADIR_YP, MCH_SCC.ADIR_YM) + end + + end + +end ----------------------------------------------------------------------------------------------- local function MakeSideFace( nId, nFac, nSide, sMilling, dToolDiam, bForcedLim, dDistToMachine, bUnderDir) if ( not BD.DOWN_HEAD or not BD.TURN) and nSide == -1 then @@ -869,7 +980,7 @@ function ProcessLongCut.Make( Proc, nPhase, nRawId, nPartId, bCustUseBlade, nCus -- inserisco tagli di lama for i = 1, nC do -- Posizione braccio portatesta - local nSCC = EgtIf( ( BD.C_SIMM or not ( i == 1 or i == nC - 1)), MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) + --local nSCC = EgtIf( ( BD.C_SIMM or not ( i == 1 or i == nC - 1)), MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) -- ciclo sulle passate local dLioTang = 0 for k = 1, 2 do @@ -1022,6 +1133,12 @@ function ProcessLongCut.Make( Proc, nPhase, nRawId, nPartId, bCustUseBlade, nCus EgtSetMachiningParam( MCH_MP.LIPERP, dLioPerp) EgtSetMachiningParam( MCH_MP.LOTANG, dLioTang) EgtSetMachiningParam( MCH_MP.LOPERP, dLioPerp) + + --- TEST + local bAreCuttingStepsTowardsHead = true + --- TEST + local nSCC = ProcessLongCut.GetSCC( Proc, 0, i, bAreCuttingStepsTowardsHead, bIsTopBladeCurrent, nFaceUse, EgtIf( bIsTopBladeCurrent, sCutting, sCuttingDn), bInvert) + -- se il flag uso lama custom abilitato (indica che questo script è lanciato dal ProcessCut) -- controllo se componente X versore è maggiore di un valore limite cambio la direzione della forcella if bCustUseBlade and abs(vtN:getX()) > 0.009 + 5 * GEO.EPS_SMALL then @@ -1184,17 +1301,6 @@ function ProcessLongCut.Make( Proc, nPhase, nRawId, nPartId, bCustUseBlade, nCus local nM = 0 local nCountMilHead = 0 for i = 1, nC do - -- Posizione braccio portatesta - local nSCC - if not BD.TURN then - if bFront then - nSCC = EgtIf( ( BD.C_SIMM or i == 1 or i == nC - 1), MCH_SCC.ADIR_XM, MCH_SCC.ADIR_XP) - else - nSCC = EgtIf( ( BD.C_SIMM or i == 1 or i == nC - 1), MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) - end - else - nSCC = EgtIf( nFaceUse == MCH_MILL_FU.ORTHO_DOWN, MCH_SCC.ADIR_ZP, EgtIf( nFaceUse == MCH_MILL_FU.ORTHO_FRONT, MCH_SCC.ADIR_YP, MCH_SCC.ADIR_YM)) - end -- ciclo sulle passate local nO = 1 local dStep = 0 @@ -1239,6 +1345,11 @@ function ProcessLongCut.Make( Proc, nPhase, nRawId, nPartId, bCustUseBlade, nCus EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal) -- imposto offset radiale EgtSetMachiningParam( MCH_MP.OFFSR, ( k - 1) * dStep - BD.CUT_EXTRA) + -- Posizione braccio portatesta + local nSCC = ProcessLongCut.GetSCC( Proc, 0, i, bAreCuttingStepsTowardsHead, nil, nFaceUse, sMilling, bInvert) + if BD.TURN then + nSCC = EgtIf( nFaceUse == MCH_MILL_FU.ORTHO_DOWN, MCH_SCC.ADIR_ZP, EgtIf( nFaceUse == MCH_MILL_FU.ORTHO_FRONT, MCH_SCC.ADIR_YP, MCH_SCC.ADIR_YM)) + end -- imposto posizione braccio porta testa per non ingombrare agli estremi EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- imposto uso della faccia @@ -1605,13 +1716,9 @@ function ProcessLongCut.Make( Proc, nPhase, nRawId, nPartId, bCustUseBlade, nCus local dSal = EgtIf( nPos == 1, -dEndDist, -dEndAccDist - ( nPos - 2) * dC + dOverLapExtend) local dEal = EgtIf( nPos == nC, -dStartDist, -dStartAccDist - ( nC - nPos - 1) * dC + dOverLapExtend) -- Posizione braccio portatesta - local nSCC + --local nSCC for k = 1, nPass do - if bFront then - nSCC = EgtIf( ( BD.C_SIMM or j == 1 or j == nC - 1), MCH_SCC.ADIR_XM, MCH_SCC.ADIR_XP) - else - nSCC = EgtIf( ( BD.C_SIMM or j == 1 or j == nC - 1), MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) - end + local nSCC = ProcessLongCut.GetSCC( Proc, nFacet, nCuttingStep, bAreCuttingStepsTowardsHead, bIsTopBlade, nFaceUse, sMachining, bInvert) -- inserisco le parti di lavorazione nM = nM + 1 local sNameF = EgtIf( vnHead[k] ~= 2, sPrefix, sPrefixDn) .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( nM)