From 91ab205dc8c537c1fc8de8695e3ac13ee541569c Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 3 Feb 2020 07:38:06 +0000 Subject: [PATCH] DataBeam : - correzioni e migliorie su tagli longitudinali singoli e doppi. --- LuaLibs/ProcessLongCut.lua | 71 +++++- LuaLibs/ProcessLongDoubleCut.lua | 370 ++++++++++++++++++++++++++----- 2 files changed, 374 insertions(+), 67 deletions(-) diff --git a/LuaLibs/ProcessLongCut.lua b/LuaLibs/ProcessLongCut.lua index d1e2000..0c3b995 100644 --- a/LuaLibs/ProcessLongCut.lua +++ b/LuaLibs/ProcessLongCut.lua @@ -309,7 +309,7 @@ function ProcessLongCut.Make( Proc, nPhase, nRawId, nPartId) dEndAccDist = BD.LONGCUT_MAXLEN bEndFixed = false end - -- determino numero di parti + -- determino numero di parti in cui dividere la lavorazione local nC = ceil( ( dLen - dStartAccDist - dEndAccDist) / BD.LONGCUT_MAXLEN) local dC = 0 if nC > 0 then @@ -451,25 +451,72 @@ function ProcessLongCut.Make( Proc, nPhase, nRawId, nPartId) local _, _, dWidth = BL.GetFaceHvRefDim( Proc.Id, 0) -- aggiuntivo sull'affondamento local dAgg = BD.CUT_EXTRA - -- determino il numero di parti in cui dividere la lavorazione - local dEndLen = BD.LONGCUT_ENDLEN - if dLen < 2 * dEndLen + BD.LONGCUT_MAXLEN then - dEndLen = dLen / 3 + -- determino se lavorazione da davanti o da dietro + local bFront = ( vtN:getY() < 0) + -- determino gli estremi + local dStartDist = 0 + local dStartAccDist = BD.LONGCUT_ENDLEN + local bStartFixed = true + if ( bLimXmin and bFront) or ( bLimXmax and not bFront) then + dStartDist = dToolDiam / 2 + dStartAccDist = BD.LONGCUT_MAXLEN + bStartFixed = false end - local nC = ceil( ( dLen - 2 * dEndLen) / BD.LONGCUT_MAXLEN) + local dEndDist = 0 + local dEndAccDist = BD.LONGCUT_ENDLEN + local bEndFixed = true + if ( bLimXmin and not bFront) or ( bLimXmax and bFront) then + dEndDist = dToolDiam / 2 + dEndAccDist = BD.LONGCUT_MAXLEN + bEndFixed = false + end + -- determino il numero di parti in cui dividere la lavorazione + local nC = ceil( ( dLen - dStartAccDist - dEndAccDist) / BD.LONGCUT_MAXLEN) local dC = 0 - if nC > 0 then dC = ( dLen - 2 * dEndLen) / nC end - nC = nC + 2 + if nC > 0 then + if bStartFixed and bEndFixed then + dC = ( dLen - dStartAccDist - dEndAccDist) / nC + elseif bStartFixed then + dC = ( dLen - dStartAccDist) / ( nC + 1) + dEndAccDist = dC + elseif bEndFixed then + dC = ( dLen - dEndAccDist) / ( nC + 1) + dStartAccDist = dC + else + dC = dLen / ( nC + 2) + dStartAccDist = dC + dEndAccDist = dC + end + nC = nC + 2 + else + if dLen > min( dStartAccDist, dEndAccDist) then + nC = 2 + if bStartFixed and not bEndFixed then + dStartAccDist = min( dStartAccDist, dLen/2) + dEndAccDist = dLen - dStartAccDist + elseif not bStartFixed and bEndFixed then + dEndAccDist = min( dEndAccDist, dLen/2) + dStartAccDist = dLen - dEndAccDist + else + dStartAccDist = dLen/2 + dEndAccDist = dStartAccDist + end + else + nC = 1 + dStartAccDist = 0 + dEndAccDist = 0 + end + end -- ciclo sulle parti local nM = 0 for j = 1, nC do -- Limitazioni della lavorazione - local nPos = EgtIf( vtN:getY() < 0, j, nC - j + 1) - local dSal = EgtIf( nPos == 1, 0, - dEndLen - ( nPos - 2) * dC) - local dEal = EgtIf( nPos == nC, 0, - dEndLen - ( nC - nPos - 1) * dC) + local nPos = EgtIf( bFront, j, nC - j + 1) + local dSal = EgtIf( nPos == 1, -dEndDist, -dEndAccDist - ( nPos - 2) * dC) + local dEal = EgtIf( nPos == nC, -dStartDist, -dStartAccDist - ( nC - nPos - 1) * dC) -- Posizione braccio portatesta local nSCC - if vtN:getY() < 0 then + if bFront then nSCC = EgtIf( ( j == 1 or j == nC - 1), MCH_SCC.ADIR_XM, MCH_SCC.ADIR_XP) else nSCC = EgtIf( ( j == 1 or j == nC - 1), MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) diff --git a/LuaLibs/ProcessLongDoubleCut.lua b/LuaLibs/ProcessLongDoubleCut.lua index aab7491..2ee9f34 100644 --- a/LuaLibs/ProcessLongDoubleCut.lua +++ b/LuaLibs/ProcessLongDoubleCut.lua @@ -1,4 +1,4 @@ --- ProcessLongDoubleCut.lua by Egaltech s.r.l. 2020/01/28 +-- ProcessLongDoubleCut.lua by Egaltech s.r.l. 2020/02/02 -- Gestione calcolo doppio taglio longitudinale per Travi -- Tabella per definizione modulo @@ -31,45 +31,166 @@ end -- Ritorna due valori : -- il primo indica il numero di facce longitudinali -- il secondo indica quante e quali facce limite sono presenti con questa codifica --- 0: nessuna faccia limite; 1: faccia limite a destra (X+); 2: faccia limite a sinistra (X-); 3: due facce limite. -function ProcessLong2Cut.IdentifyFaces( Proc) +-- 0: nessuna faccia limite; 1: faccia/e limite a destra (X-); 2: faccia/e limite a sinistra (X+); 3: due facce limite. +function ProcessLong2Cut.IdentifyFaces( Proc, bDefineFaces) -- verifico le normali delle facce local nFaceLong = 0 local nFaceLimit = 0 + local tFaceLong = {} + local tFaceLimit = {} + local tptC = {} + local tvtN = {} local nFacetCnt = EgtSurfTmFacetCount( Proc.Id) + local nLong = 0 + local nLimit = 0 + local bLimitPos + local bLimitNeg + for i = 1, nFacetCnt do local vtN = EgtSurfTmFacetNormVersor( Proc.Id, i-1, GDB_ID.ROOT) -- se è una faccia limite a sinistra if vtN:getX() > GEO.EPS_SMALL then - nFaceLimit = nFaceLimit + 2 + if not bLimitPos then + nFaceLimit = nFaceLimit + 2 + bLimitPos = true + end + -- se devo restituire una tabella con le facce limite + if bDefineFaces then + nLimit = nLimit + 1 + tFaceLimit[nLimit] = i-1 + end -- se è una faccia limite a destra elseif vtN:getX() < -GEO.EPS_SMALL then - nFaceLimit = nFaceLimit + 1 + if not bLimitNeg then + nFaceLimit = nFaceLimit + 1 + bLimitNeg = true + end + -- se devo restituire una tabella con le facce limite + if bDefineFaces then + nLimit = nLimit + 1 + tFaceLimit[nLimit] = i-1 + end -- altrimenti è una faccia longitudinale else nFaceLong = nFaceLong + 1 + -- se devo restituire una tabella con le facce longitudinali + if bDefineFaces then + nLong = nLong + 1 + tFaceLong[nLong] = i-1 + tptC[nLong], tvtN[nLong] = EgtSurfTmFacetCenter( Proc.Id, (i-1), GDB_ID.ROOT) + end end end - return nFaceLong, nFaceLimit + return nFaceLong, nFaceLimit, tFaceLong, tFaceLimit, tptC, tvtN +end + +--------------------------------------------------------------------- +local function MakeSideFace( nId, nFac, nSide, sMilling, dToolDiam) + -- inserisco la lavorazione + local sNameF = 'L2C_' .. ( EgtGetName( nId) or tostring( nId)) .. '_' .. tostring( nFac) + local nMchFId = EgtAddMachining( sNameF, sMilling) + if not nMchFId then + local sErr = 'Error adding machining ' .. sNameF .. '-' .. sMilling + EgtOutLog( sErr) + return false, sErr + end + -- aggiungo geometria + EgtSetMachiningGeometry( {{ nId, nFac}}) + -- lato di lavoro e inversione + EgtSetMachiningParam( MCH_MP.INVERT, true) + EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) + -- uso della faccia + local nFaceUse = MCH_MILL_FU.PARAL_DOWN + if nSide == -2 then + nFaceUse = MCH_MILL_FU.PARAL_BACK + elseif nSide == 2 then + nFaceUse = MCH_MILL_FU.PARAL_FRONT + end + EgtSetMachiningParam( MCH_MP.FACEUSE, nFaceUse) + -- annullo offset radiale + EgtSetMachiningParam( MCH_MP.OFFSR, 0) + -- attacco e uscita + EgtSetMachiningParam( MCH_MP.LIPERP, 0) + EgtSetMachiningParam( MCH_MP.LITANG, dToolDiam / 2 + 30) + EgtSetMachiningParam( MCH_MP.LOPERP, 0) + EgtSetMachiningParam( MCH_MP.LOTANG, dToolDiam / 2 + 30) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchFId, false) + return false, sErr + end +end + +--------------------------------------------------------------------- +-- Applicazione della lavorazione +local function MakeByPocketing( Proc, nPhase, nRawId, nPartId, nFacInd, dFacElev) + -- cerco la svuotatura opportuna + local sPocketing = ML.FindPocketing( 'OpenPocket', Proc.Box:getDimX()) + if not sPocketing then + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' pocketing not found in library' + EgtOutLog( sErr) + return false, sErr + end + -- recupero i dati dell'utensile + local dMaxDepth = 0 + if EgtMdbSetCurrMachining( sPocketing) then + local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then + dMaxDepth = ( EgtTdbGetCurrToolMaxDepth() or dMaxDepth) + end + end + -- inserisco la lavorazione + local sName = 'Pock_' .. ( 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 false, sErr + end + -- aggiungo geometria + EgtSetMachiningGeometry( {{ Proc.Id, nFacInd}}) + -- imposto uso faccia + EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.ORTHO_CONT) + -- imposto attacco per tasca aperta + EgtSetMachiningParam( MCH_MP.SUBTYPE, MCH_POCK_SUB.SPIRALIN) + -- se elevazione superiore a massimo affondamento della fresa, riduco opportunamente + local sWarn + if dFacElev > dMaxDepth + 10 * GEO.EPS_SMALL then + EgtSetMachiningParam( MCH_MP.DEPTH, dMaxDepth - dFacElev) + dFacElev = dMaxDepth + sWarn = 'Warning in process ' .. tostring( Proc.Id) .. ' : elevation bigger than max tool depth' + EgtOutLog( sWarn) + end + -- imposto elevazione e dichiaro non si generano sfridi per VMill + local sNotes = 'MaxElev=' .. EgtNumToString( dFacElev, 1) .. ';' + sNotes = 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 false, sErr + end + end + return true, sWarn end --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessLong2Cut.Make( Proc, nPhase, nRawId, nPartId) -- dati delle facce - local nFc = {0,1} + local nFaceLimit = 0 + local tFaceLong = {} + local tFaceLimit = {} local ptC = {} local vtN = {} - -- ciclo sulle facce per identificare le facce longitudinali - local nLongFct = 0 - for j = 1, Proc.Fct do - local ptCen, vtNrm = EgtSurfTmFacetCenter( Proc.Id, (j-1), GDB_ID.ROOT) - if abs( vtNrm:getX()) < GEO.EPS_SMALL then - nLongFct = nLongFct + 1 - ptC[nLongFct] = Point3d( ptCen) - vtN[nLongFct] = Vector3d( vtNrm) - end - end + -- carico i dati delle face già inserite nelle opportune tabelle + _, nFaceLimit, tFaceLong, tFaceLimit, ptC, vtN = ProcessLong2Cut.IdentifyFaces( Proc, true) + local dLen = EgtGetBBoxGlob( Proc.Id, GDB_BB.STANDARD):getDimX() -- verifico posizione (+1=sopra, -1=sotto, 0=sui lati) local nSide = 0 @@ -79,7 +200,7 @@ function ProcessLong2Cut.Make( Proc, nPhase, nRawId, nPartId) nSide = -1 end -- angolo diedro per stabilire se taglio convesso - local bInt, ptP1, ptP2, dAng = EgtSurfTmFacetsContact( Proc.Id, nFc[1], nFc[2], GDB_ID.ROOT) + local bInt, ptP1, ptP2, dAng = EgtSurfTmFacetsContact( Proc.Id, tFaceLong[1], tFaceLong[2], GDB_ID.ROOT) local bConvex local bOrtho local ptM @@ -113,12 +234,12 @@ function ProcessLong2Cut.Make( Proc, nPhase, nRawId, nPartId) end end local vWidth = {} - _, _, vWidth[1] = BL.GetFaceHvRefDim( Proc.Id, nFc[1]) - _, _, vWidth[2] = BL.GetFaceHvRefDim( Proc.Id, nFc[2]) + _, _, vWidth[1] = BL.GetFaceHvRefDim( Proc.Id, tFaceLong[1]) + _, _, vWidth[2] = BL.GetFaceHvRefDim( Proc.Id, tFaceLong[2]) local sWarn -- Se ho 2 face longitudinali e non limitato da altre facce e da sopra e richiesto con doppio taglio di lama - if nLongFct == 2 and Proc.Fct == 2 and nSide == 1 and EgtGetInfo( Proc.Id, 'Q01', 'i') == 1 then + if #tFaceLong == 2 and Proc.Fct == 2 and nSide == 1 and EgtGetInfo( Proc.Id, 'Q01', 'i') == 1 then -- recupero la lavorazione local sCutting = ML.FindCutting( 'HeadSide') if not sCutting then @@ -284,6 +405,7 @@ function ProcessLong2Cut.Make( Proc, nPhase, nRawId, nPartId) -- Se non è sotto : lavorazione Long2Cut elseif nSide ~= - 1 then + -- recupero la lavorazione local sMilling = ML.FindMilling( 'Long2Cut') if not sMilling then @@ -301,15 +423,74 @@ function ProcessLong2Cut.Make( Proc, nPhase, nRawId, nPartId) dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth end end - -- determino il numero di parti in cui dividere la lavorazione - local dEndLen = BD.LONGCUT_ENDLEN - if dLen < 2 * dEndLen + BD.LONGCUT_MAXLEN then - dEndLen = dLen / 3 + -- se chiuso e corto, applico svuotatura con fresa opportuna + if nFaceLimit == 3 and Proc.Box:getDimX() < 2 * dToolDiam then + -- ottengo le facce con il maggior numero di adiacenze e l'elevazione relativa + local nFacInd, dFacElev, nFacInd2, dFacElev2 = BL.GetFaceWithMostAdj( Proc.Id, nPartId) + if nFacInd > 0 and dFacElev then + local bOk, sErr = MakeByPocketing( Proc, nPhase, nRawId, nPartId, nFacInd, dFacElev) + if not bOk then return bOk, sErr end + end + if nFacInd2 and nFacInd2 > 0 and dFacElev2 then + return MakeByPocketing( Proc, nPhase, nRawId, nPartId, nFacInd2, dFacElev2) + end end - local nC = ceil( ( dLen - 2 * dEndLen) / BD.LONGCUT_MAXLEN) + -- determino gli estremi + local dStartDist = 0 + local dStartAccDist = BD.LONGCUT_ENDLEN + local bStartFixed = true + -- se ho facce limite a destra + if nFaceLimit % 2 == 1 then + dStartDist = dToolDiam / 2 + dStartAccDist = BD.LONGCUT_MAXLEN + bStartFixed = false + end + local dEndDist = 0 + local dEndAccDist = BD.LONGCUT_ENDLEN + local bEndFixed = true + -- se ho facce limite a sinistra + if nFaceLimit >= 2 then + dEndDist = dToolDiam / 2 + dEndAccDist = BD.LONGCUT_MAXLEN + bEndFixed = false + end + -- determino il numero di parti in cui dividere la lavorazione + local nC = ceil( ( dLen - dStartAccDist - dEndAccDist) / BD.LONGCUT_MAXLEN) local dC = 0 - if nC > 0 then dC = ( dLen - 2 * dEndLen) / nC end - nC = nC + 2 + if nC > 0 then + if bStartFixed and bEndFixed then + dC = ( dLen - dStartAccDist - dEndAccDist) / nC + elseif bStartFixed then + dC = ( dLen - dStartAccDist) / ( nC + 1) + dEndAccDist = dC + elseif bEndFixed then + dC = ( dLen - dEndAccDist) / ( nC + 1) + dStartAccDist = dC + else + dC = dLen / ( nC + 2) + dStartAccDist = dC + dEndAccDist = dC + end + nC = nC + 2 + else + if dLen > min( dStartAccDist, dEndAccDist) then + nC = 2 + if bStartFixed and not bEndFixed then + dStartAccDist = min( dStartAccDist, dLen/2) + dEndAccDist = dLen - dStartAccDist + elseif not bStartFixed and bEndFixed then + dEndAccDist = min( dEndAccDist, dLen/2) + dStartAccDist = dLen - dEndAccDist + else + dStartAccDist = dLen/2 + dEndAccDist = dStartAccDist + end + else + nC = 1 + dStartAccDist = 0 + dEndAccDist = 0 + end + end -- ciclo sulle parti local nM = 0 for j = 1, nC do @@ -326,18 +507,21 @@ function ProcessLong2Cut.Make( Proc, nPhase, nRawId, nPartId) for i = nIni, nFin do -- Limitazioni della lavorazione local nPos = EgtIf( i == 1, j, nC - j + 1) - local dSal = EgtIf( nPos == 1, 0, - dEndLen - ( nPos - 2) * dC) - local dEal = EgtIf( nPos == nC, 0, - dEndLen - ( nC - nPos - 1) * dC) + local dSal = EgtIf( nPos == 1, - EgtIf( i == nIni, dStartDist, dEndDist), - EgtIf( i == nIni, dStartAccDist, dEndAccDist) - ( nPos - 2) * dC) + local dEal = EgtIf( nPos == nC, - EgtIf( i == nIni, dEndDist, dStartDist), - EgtIf( i == nIni, dEndAccDist, dStartAccDist) - ( nC - nPos - 1) * dC) -- Posizione braccio portatesta local nSCC = EgtIf( ( j == 1 or j == nC - 1), MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) + -- Verifico se da fare di fianco perchè normale troppo verso il basso (minore di -30deg) + local bSide = ( vtN[vOrd[i]]:getZ() < -0.5) -- ciclo sulle passate local nO = 1 local dStep = 0 local dAgg = EgtIf( bConvex, 2 * BD.CUT_EXTRA, BD.CUT_EXTRA) - if vWidth[vOrd[i]] > 0.8 * dToolDiam then - nO = ceil( vWidth[vOrd[i]] / ( 0.6 * dToolDiam)) + local dLargh = vWidth[vOrd[i]] + if not bSide and dLargh > 0.8 * dToolDiam then + nO = ceil( dLargh / ( 0.6 * dToolDiam)) if nO > 1 then - dStep = vWidth[vOrd[i]] / nO + dStep = dLargh / nO end end for k = 1, nO do @@ -351,23 +535,29 @@ function ProcessLong2Cut.Make( Proc, nPhase, nRawId, nPartId) return false, sErr end -- aggiungo geometria - EgtSetMachiningGeometry( {{ Proc.Id, nFc[vOrd[i]]}}) + EgtSetMachiningGeometry( {{ Proc.Id, tFaceLong[vOrd[i]]}}) -- limito opportunamente la lavorazione EgtSetMachiningParam( MCH_MP.STARTADDLEN, dSal) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal) -- imposto posizione braccio porta testa per non ingombrare agli estremi EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- imposto uso faccia - EgtSetMachiningParam( MCH_MP.FACEUSE, vFaceUse[vOrd[i]]) + EgtSetMachiningParam( MCH_MP.FACEUSE, EgtIf( bSide, MCH_MILL_FU.PARAL_DOWN, vFaceUse[vOrd[i]])) -- imposto lato di lavoro e inversione EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) - EgtSetMachiningParam( MCH_MP.INVERT, false) - -- imposto offset radiale (nullo se concavo) - if k < nO then - EgtSetMachiningParam( MCH_MP.OFFSR, ( nO - k) * dStep) - else - EgtSetMachiningParam( MCH_MP.OFFSR, EgtIf( bConvex, - BD.CUT_EXTRA, 0)) + EgtSetMachiningParam( MCH_MP.INVERT, EgtIf( bSide, true, false)) + -- imposto offset radiale (nullo se concavo o di lato) + local dOffsR = EgtIf( k < nO, ( nO - k) * dStep, EgtIf( bConvex, - BD.CUT_EXTRA, 0)) + if bSide then dOffsR = 0 end + EgtSetMachiningParam( MCH_MP.OFFSR, dOffsR) + -- se di lato, imposto offset longitudinale + if bSide then + EgtSetMachiningParam( MCH_MP.OFFSL, - BD.CUT_EXTRA) end + -- attacco e uscita + local dLioPerp = EgtIf( bSide, dToolDiam, dLargh - dOffsR + BD.CUT_SIC) + EgtSetMachiningParam( MCH_MP.LIPERP, dLioPerp) + EgtSetMachiningParam( MCH_MP.LOPERP, dLioPerp) -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() @@ -376,8 +566,27 @@ function ProcessLong2Cut.Make( Proc, nPhase, nRawId, nPartId) end end end + -- se facce principali convesse, eventuale lavorazione della faccia limitante l'inizio (a destra) + if bConvex and j == 1 and not bStartFixed then + local vtIni = -X_AX() + for i = 1, #tFaceLimit do + local _, vtN = EgtSurfTmFacetCenter( Proc.Id, tFaceLimit[i], GDB_ID.ROOT) + if vtIni * vtN > 0 then + MakeSideFace( Proc.Id, tFaceLimit[i], nSide, sMilling, dToolDiam) + end + end + end + end + -- se facce principali convesse, eventuale lavorazione della faccia limitante la fine (a sinistra) + if bConvex and not bEndFixed then + local vtFin = X_AX() + for i = 1, #tFaceLimit do + local _, vtN = EgtSurfTmFacetCenter( Proc.Id, tFaceLimit[i], GDB_ID.ROOT) + if vtFin * vtN > 0 then + MakeSideFace( Proc.Id, tFaceLimit[i], nSide, sMilling, dToolDiam) + end + end end - -- altrimenti è sotto : lavorazione Long2CutDown else -- recupero la lavorazione @@ -390,24 +599,73 @@ function ProcessLong2Cut.Make( Proc, nPhase, nRawId, nPartId) -- recupero i dati dell'utensile local dToolDiam = 0 local dMaxDepth = 0 + local dThDiam = 0 if EgtMdbSetCurrMachining( sMilling) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dToolDiam dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth + dThDiam = EgtTdbGetCurrToolThDiam() or dThDiam end end -- aggiuntivo sull'affondamento local dAgg = EgtIf( bConvex, BD.CUT_EXTRA, 0) - -- determino il numero di parti in cui dividere la lavorazione - local dEndLen = BD.LONGCUT_ENDLEN - if dLen < 2 * dEndLen + BD.LONGCUT_MAXLEN then - dEndLen = dLen / 3 + -- determino gli estremi + local dStartDist = 0 + local dStartAccDist = BD.LONGCUT_ENDLEN + local bStartFixed = true + -- se ho facce limite a destra + if nFaceLimit % 2 == 1 then + dStartDist = dToolDiam / 2 + dStartAccDist = BD.LONGCUT_MAXLEN + bStartFixed = false end - local nC = ceil( ( dLen - 2 * dEndLen) / BD.LONGCUT_MAXLEN) + local dEndDist = 0 + local dEndAccDist = BD.LONGCUT_ENDLEN + local bEndFixed = true + -- se ho facce limite a sinistra + if nFaceLimit >= 2 then + dEndDist = dToolDiam / 2 + dEndAccDist = BD.LONGCUT_MAXLEN + bEndFixed = false + end + -- determino il numero di parti in cui dividere la lavorazione + local nC = ceil( ( dLen - dStartAccDist - dEndAccDist) / BD.LONGCUT_MAXLEN) local dC = 0 - if nC > 0 then dC = ( dLen - 2 * dEndLen) / nC end - nC = nC + 2 + if nC > 0 then + if bStartFixed and bEndFixed then + dC = ( dLen - dStartAccDist - dEndAccDist) / nC + elseif bStartFixed then + dC = ( dLen - dStartAccDist) / ( nC + 1) + dEndAccDist = dC + elseif bEndFixed then + dC = ( dLen - dEndAccDist) / ( nC + 1) + dStartAccDist = dC + else + dC = dLen / ( nC + 2) + dStartAccDist = dC + dEndAccDist = dC + end + nC = nC + 2 + else + if dLen > min( dStartAccDist, dEndAccDist) then + nC = 2 + if bStartFixed and not bEndFixed then + dStartAccDist = min( dStartAccDist, dLen/2) + dEndAccDist = dLen - dStartAccDist + elseif not bStartFixed and bEndFixed then + dEndAccDist = min( dEndAccDist, dLen/2) + dStartAccDist = dLen - dEndAccDist + else + dStartAccDist = dLen/2 + dEndAccDist = dStartAccDist + end + else + nC = 1 + dStartAccDist = 0 + dEndAccDist = 0 + end + end -- ciclo sulle parti local nM = 0 for j = 1, nC do @@ -415,8 +673,8 @@ function ProcessLong2Cut.Make( Proc, nPhase, nRawId, nPartId) for i = 1, 2 do -- Limitazioni della lavorazione local nPos = EgtIf( i == 1, j, nC - j + 1) - local dSal = EgtIf( nPos == 1, 0, - dEndLen - ( nPos - 2) * dC) - local dEal = EgtIf( nPos == nC, 0, - dEndLen - ( nC - nPos - 1) * dC) + local dSal = EgtIf( nPos == 1, - EgtIf( i == 1, dStartDist, dEndDist), - EgtIf( i == 1, dStartAccDist, dEndAccDist) - ( nPos - 2) * dC) + local dEal = EgtIf( nPos == nC, - EgtIf( i == 1, dEndDist, dStartDist), - EgtIf( i == 1, dEndAccDist, dStartAccDist) - ( nC - nPos - 1) * dC) -- Posizione braccio portatesta local nSCC = MCH_SCC.ADIR_XP -- inserisco le parti di lavorazione @@ -429,7 +687,7 @@ function ProcessLong2Cut.Make( Proc, nPhase, nRawId, nPartId) return false, sErr end -- aggiungo geometria - EgtSetMachiningGeometry( {{ Proc.Id, nFc[vOrd[i]]}}) + EgtSetMachiningGeometry( {{ Proc.Id, tFaceLong[vOrd[i]]}}) -- limito opportunamente la lavorazione EgtSetMachiningParam( MCH_MP.STARTADDLEN, dSal) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal) @@ -440,10 +698,12 @@ function ProcessLong2Cut.Make( Proc, nPhase, nRawId, nPartId) -- imposto lato di lavoro e inversione EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) EgtSetMachiningParam( MCH_MP.INVERT, true) - if vWidth[vOrd[i]] + dAgg > dMaxDepth - BD.COLL_SIC then - sWarn = 'Warning in LongDoubleCut : depth (' .. EgtNumToString( vWidth[vOrd[i]] + dAgg, 1) .. ') bigger than max tool depth (' .. EgtNumToString( dMaxDepth - BD.COLL_SIC, 1) .. ')' + -- verifico massimo affondamento (tengo conto dell'inclinazione utensile e della pinza con estremità conica) + local dCollSic = max( BD.COLL_SIC, ( dThDiam - dToolDiam) / 2 * abs( vtN[vOrd[i]]:getY() / vtN[vOrd[i]]:getZ()) - 3) + if vWidth[vOrd[i]] + dAgg > dMaxDepth - dCollSic then + sWarn = 'Warning in LongDoubleCut : depth (' .. EgtNumToString( vWidth[vOrd[i]] + dAgg, 1) .. ') bigger than max tool depth (' .. EgtNumToString( dMaxDepth - dCollSic, 1) .. ')' end - local dDepth = min( dMaxDepth - BD.COLL_SIC, vWidth[vOrd[i]] + dAgg) + local dDepth = min( dMaxDepth - dCollSic, vWidth[vOrd[i]] + dAgg) EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- eseguo if not EgtApplyMachining( true, false) then