-- ProcessLongCut.lua by Egaltech s.r.l. 2021/11/08 -- Gestione calcolo taglio longitudinale per Travi -- 2021/02/03 Corretto FaceUse con fresa orizzontale su taglio orizzontale. -- 2021/05/18 Possibile taglio con lama anche di fianco su macchina con testa da sotto. -- 2021/07/20 Possibile taglio con lama anche di fianco e da sotto su macchina con testa da sopra. -- 2021/07/20 Con utensile di fianco e con determinati angoli e se altezza utensile è inferiore all'altezza faccia -- è possibile fare doppio taglio opposto su tutte le facce(sopra, sotto e fianchi) -- 2021/09/03 Gestione facce lunghe non passanti con taglio di lama -- 2021/10/29 Aggiunta opzione tipo lavorazione 'LongCut'. -- 2021/11/04 Migliorata gestione sicurezza aggiuntiva in fresate di fianco (distinzione tra larga come tutta la faccia o meno). -- 2021/11/08 Se con lama e flag BD.USE_LONGCUT si lavora in direzione contraria allo standard. -- Tabella per definizione modulo local ProcessLongCut = {} -- Include require( 'EgtBase') local BL = require( 'BeamLib') local Fbs = require( 'FacesBySaw') EgtOutLog( ' ProcessLongCut started', 1) -- Dati local BD = require( 'BeamData') local ML = require( 'MachiningLib') local dLimMinPiece = BD.LEN_SHORT_PART or 1000 --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessLongCut.Identify( Proc) return (( Proc.Grp == 0 or Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 10) end --------------------------------------------------------------------- -- Classificazione della feature function ProcessLongCut.Classify( Proc) -- se una sola faccia non ci sono limiti if Proc.Fct == 1 then return true, false end -- verifico la normale della faccia principale local vtN = EgtSurfTmFacetNormVersor( Proc.Id, 0, GDB_ID.ROOT) if vtN:getZ() < - 0.5 then return true, true end return true, false end ----------------------------------------------------------------------------------------------- local function MakeSideFace( nId, nFac, nSide, sMilling, dToolDiam, bForcedLim, dDistToMachine, bUnderDir) -- inserisco la lavorazione local nM = 1 local nP = 1 local nFirstOverlap = 2 -- calcolo il numero di passata che devo fare per coprire l'impronta dells lama if dDistToMachine and abs(dDistToMachine) > 0 then nP = ceil( ( abs(dDistToMachine) + EgtIf( bForcedLim, 2 + nFirstOverlap, 2)) / ( dToolDiam - 2)) end for i = 1, nP do local sNameF = 'L2C_' .. ( EgtGetName( nId) or tostring( nId)) .. '_' .. tostring( nFac) .. '_' .. tostring( nM) 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}}) -- uso della faccia local nFaceUse if bForcedLim then nFaceUse = MCH_MILL_FU.ORTHO_LEFT -- lato di lavoro e inversione EgtSetMachiningParam( MCH_MP.INVERT, false) EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) else nFaceUse = EgtIf( bUnderDir, MCH_MILL_FU.PARAL_TOP, 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 -- lato di lavoro e inversione EgtSetMachiningParam( MCH_MP.INVERT, true) EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) end EgtSetMachiningParam( MCH_MP.FACEUSE, nFaceUse) -- modifico offset radiale if i < nP or i == 1 then EgtSetMachiningParam( MCH_MP.OFFSR, ((dToolDiam-2)*(i-1)) + EgtIf( bForcedLim, -nFirstOverlap, 0)) else local dPrevStep = (dToolDiam-2)*(i-2) EgtSetMachiningParam( MCH_MP.OFFSR, ( dDistToMachine + 2 - dToolDiam)) end -- 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 end --------------------------------------------------------------------- local function MakeAntiSplintBySaw( Proc, nFacet, vtN, b3Raw, nFacInd, bReduceDepth, bMillDown, sMasterCutting) -- Recupero la lavorazione di lama o prendo quella passata local sCutting if sMasterCutting and #sMasterCutting > 0 then sCutting = sMasterCutting else sCutting = ML.FindCutting( 'HeadSide' .. EgtIf( bMillDown, '_H2', '')) end if not sCutting then local sErr = 'Error : HeadSide (cutting) not found in library' EgtOutLog( sErr) return false, sErr end -- valuto l'angolo tra le due facce local bAdj, ptP1, ptP2, dAng = EgtSurfTmFacetsContact( Proc.Id, nFacInd, nFacet, GDB_ID.ROOT) local ptPm = (ptP1+ptP2)/2 -- ottengo il boundingBox e prendo le dimensioni lungo la normale (Z locale) che rappresenta l'elevazione della faccia -- laterale sul punto medio della linea in comune local frFc = Frame3d( ptPm, vtN) ; local b3BoxLoc = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, frFc) dDepth = b3BoxLoc:getDimZ() or 0 -- recupero i dati dell'utensile local dSawDiam = 400 local dSawThick = 0 local dMaxDepth = 0 if EgtMdbSetCurrMachining( sCutting) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dSawDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dSawDiam dSawThick = EgtTdbGetCurrToolParam( MCH_TP.THICK) or dSawThick dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth end end local dExtraOffs = 0 -- se profondità superiore al massimo lama modifico elevazione if dDepth > dMaxDepth then dExtraOffs = dMaxDepth - dDepth end -- se devo ridurre l'affondamento if bReduceDepth then local dLimitDepth = 100 -- se ho ridotto l'affondamento ne riduco ulteriormente l'affondamento (50mm) if abs(dExtraOffs) > 0 then if dMaxDepth > dLimitDepth then dExtraOffs = dLimitDepth - dDepth end else if dDepth > dLimitDepth then dExtraOffs = dLimitDepth - dDepth else dExtraOffs = - (dDepth/2) end end end -- eseguo il taglio local bMadeASbyBld, sWarn, nIdMach = Fbs.MakeOne( Proc.Id, nFacet, sCutting, dSawDiam, vtN, nil, ( -0.5 + dExtraOffs), BD.CUT_SIC, 0, 0, 0, nil, b3Raw) if bMadeASbyBld then sWarn = nil if abs(dExtraOffs) > 0 then sWarn = 'Warning : antisplint elevation is bigger than max tool depth' end end return bMadeASbyBld, sWarn, nIdMach, dSawThick, dMaxDepth, bAdj, dAng, dExtraOffs end --------------------------------------------------------------------- local function ManageAntiSplintBySaw( Proc, b3Raw, bIsU, vtN, nFacet, nFacInd, sWarn, bMillDown, bReduceDepth, sCutting) local bMadeASbyBld = false local nNumFac = EgtIf( bIsU, 2, 1) local nPrefSide = 1 -- di preferenza il motore è meglio tenerlo sinistra -- se a U cerco di ottimizzare il lato di lavoro della lama if bIsU then if abs( vtN:getY()) > 0.996 then nPrefSide = 0 elseif abs( vtN:getZ()) > 0.63 or abs( vtN:getY()) > 0.63 then -- se X è negativa allora devo tenere il motore a destra if vtN:getX() < -(10 * GEO.EPS_SMALL) then nPrefSide = 2 end end end -- va eseguito sulle facce diverse dalla principale local nPrevSCC = nil for nFacet = 0, nNumFac do if nFacet ~= nFacInd then -- lavoro local dSawThick = 0 local dMaxDepth = 200 local bAdj, dAng, dExtraOffs, sWarn2, nIdMach bMadeASbyBld, sWarn2, nIdMach, dSawThick, dMaxDepth, bAdj, dAng, dExtraOffs = MakeAntiSplintBySaw( Proc, nFacet, vtN, b3Raw, nFacInd, bReduceDepth, bMillDown, sCutting) if not bMadeASbyBld then return bMadeASbyBld, false, sWarn2 end if sWarn2 then if not sWarn then sWarn = '' end sWarn = EgtIf( #sWarn > 0, sWarn .. '\n' .. sWarn2, sWarn2) end -- se antischeggia veramente inserito perchè necessario if nIdMach then -- verifico se da invertire local bInvertMach = false local dDepth = 0 if bIsU then if abs(vtN:getZ()) > 0.63 or abs(vtN:getY()) > 0.63 then -- if abs(vtN:getZ()) > 0.7 or abs(vtN:getY()) > 0.7 then -- prendo il vettore normale alla faccia local _, vtNFc = EgtSurfTmFacetCenter( Proc.Id, nFacet, GDB_ID.ROOT) -- se superficie principale parallela al piano XZ if nPrefSide == 0 then -- se facce inclinate \\ allora mandrino a destra (per essere verso l'alto) if vtNFc:getX() * vtNFc:getZ() > 0 then nPrefSide = 2 -- altrimenti facce inclinate // quindi mandrino a sinistra (per essere ancora verso l'alto) else nPrefSide = 1 end end -- se faccia verso X+ e mandrino verso sinistra if vtNFc:getX() > 0 and nPrefSide == 1 then -- se angolo interno e circa -90 if abs( dAng + 90) < 5 then bInvertMach = true end -- se faccia verso X- e mandrino verso destra elseif vtNFc:getX() < 0 and nPrefSide == 2 then -- se angolo interno e circa -90 if abs( dAng + 90) < 5 then bInvertMach = true end end end end -- eseguo inversione if bInvertMach then local bToolInvert = EgtGetMachiningParam( MCH_MP.TOOLINVERT) local nWS = EgtGetMachiningParam( MCH_MP.WORKSIDE) local nInvWS = EgtIf( nWS == MCH_MILL_WS.RIGHT, MCH_MILL_WS.LEFT, MCH_MILL_WS.RIGHT) local nFaceUse = EgtGetMachiningParam( MCH_MP.FACEUSE) local bOrtUp = ( nFaceUse >= MCH_MILL_FU.ORTUP_DOWN and nFaceUse <= MCH_MILL_FU.ORTUP_RIGHT) if not bOrtUp then -- assegno i parametri invertiti EgtSetMachiningParam( MCH_MP.WORKSIDE, nInvWS) EgtSetMachiningParam( MCH_MP.TOOLINVERT, not bToolInvert) -- setto l'offset pari allo spessore lama EgtSetMachiningParam( MCH_MP.OFFSL, -dSawThick) end end -- posizione del braccio : se primo taglio la recupero, altrimenti la imposto if not nPrevSCC then nPrevSCC = EgtGetMachiningParam( MCH_MP.SCC) else EgtSetMachiningParam( MCH_MP.SCC, nPrevSCC) end -- rieseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nIdMach, false) return false, false, sErr end end end end return bMadeASbyBld, true, sWarn end --------------------------------------------------------------------- -- Applicazione della lavorazione local function MakeByPocketing( Proc, nPhase, nRawId, nPartId) -- recupero la faccia con il maggior numero di adiacenze e l'elevazione relativa local nFacInd, dFacElev = BL.GetFaceWithMostAdj( Proc.Id, nPartId) -- cerco la svuotatura opportuna local sPocketing = ML.FindPocketing( 'OpenPocket', Proc.Box:getDimX()) if not sPocketing then local sErr = 'Error : OpenPocket 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, 0}}) -- 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 : 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 ProcessLongCut.Make( Proc, nPhase, nRawId, nPartId, bCustUseBlade, nCustForceUseBladeOnNCF) -- recupero l'ingombro del grezzo di appartenenza local b3Raw = EgtGetRawPartBBox( nRawId) local b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( nPartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) -- dati della faccia local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT) local _, dLen, dWidth = EgtSurfTmFacetMinAreaRectangle( Proc.Id, 0, GDB_ID.ROOT) -- limitazioni su inizio e fine derivanti da altre facce local bLimXmin = false local bLimXmax = false if Proc.Fct >= 3 then bLimXmin = true bLimXmax = true elseif Proc.Fct >= 2 then local ptC1, vtN1 = EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT) if vtN1:getX() > 0 then bLimXmin = true else bLimXmax = true end end -- Verifico lato di lavorazione (limite di lato a 45deg per pinze che schiacciano) -- 14.07.2021 su richieste di alcuni clienti, se taglio di lato (assegnazione +/- 2) fare lo stesso con la lama lasciando il cordone centrale local nSide = 1 if vtN:getZ() < - 0.5 then nSide = -1 elseif vtN:getY() < -0.7072 then nSide = -2 elseif vtN:getY() > 0.7072 then nSide = 2 end -- Verifico se largo come faccia local bLarghAsFace = false if nSide == 1 or nSide == -1 then bLarghAsFace = ( Proc.Box:getDimY() > b3Solid:getDimY() - 10) else bLarghAsFace = ( Proc.Box:getDimZ() > b3Solid:getDimZ() - 10) end -- determino se lavorazione da davanti o da dietro local bFront = ( vtN:getY() < 0) -- ottengo la distanza tra la fine del pezzo e il pezzo successivo local dDistToNextPiece = EgtGetInfo( nRawId, 'BDST', 'd') or 5.4 local bForcedLim local sWarn ---------------------------------------------------------------------------------------------------------------------------------------- -- 2020/09/15 Fabio Squaratti: se sono attivi entrambe i Q05 (lavorare con lama) e Q07 (lavorare con fresa di fianco anche da sopra) -- allora vince il Q7, cioè si utilizza la fresa di fianco ( per i tagli da sopra) -- 2020/09/17 Fabio Squaratti: se lavorazione con fresa di fianco e se ci sono delle facce laterali, l'utensile deve arrivare -- fino al punto più vicino della faccia laterale (prima l'arretramento era sempre del rggio utensile). -- Questo viene fatto se Q07=1 o fresa da sotto ---------------------------------------------------------------------------------------------------------------------------------------- local nUseBlade = EgtIf( bCustUseBlade, 1, EgtGetInfo( Proc.Id, 'Q05', 'i') or 0) local bForceUseBladeOnNotThruFace if nCustForceUseBladeOnNCF then bForceUseBladeOnNotThruFace = nCustForceUseBladeOnNCF > 2 nUseBlade = EgtIf( nCustForceUseBladeOnNCF > 2, nCustForceUseBladeOnNCF-2, nCustForceUseBladeOnNCF) else -- bForceUseBladeOnNotThruFace = EgtGetInfo( Proc.Id, 'Q06', 'b') or false -- non viene più usato un nuovo Q (Q06) ma dipende dal valore del Q05 -- con nuovi valori 3: come 1 ma con forza lama su facce chiuse; 4: come 2 ma con forza lama su facce chiuse if nUseBlade > 2 then nUseBlade = nUseBlade - 2 bForceUseBladeOnNotThruFace = true end end -- se ho il parametro settato dal LapJoint (per ora è questo componente che setta questo parametro) allora setto a false l'uso della lama -- perchè se ha questo parametro a true significa che la lama è forzata ad essere usata local nUseMillOnSide if nCustForceUseBladeOnNCF then nUseMillOnSide = 0 else nUseMillOnSide = EgtGetInfo( Proc.Id, 'Q07', 'i') or 0 end -- se entrambe i Q sono attivi, disabilito lama if nUseMillOnSide > 0 then nUseBlade = 0 bForceUseBladeOnNotThruFace = false end local bCanUseBlade = false local bCanUseUnderBlade = false -- se lama abilitata per lavorare sopra e faccia da sopra if nUseBlade == 1 and nSide == 1 then bCanUseBlade = true end -- se lama abilitata per lavorare anche i fianchi e da sotto e non c'è testa da sotto if nUseBlade == 2 and not BD.DOWN_HEAD then if ( nSide == 1 or abs(nSide) == 2) and vtN:getZ() >= -0.0175 then bCanUseBlade = true end end -- se lama abilitata per lavorare i fianchi e da sotto e c'è testa da sotto if nUseBlade == 2 and BD.DOWN_HEAD then -- se faccia da sotto o di lato ma con versore Z negativo che supera i 30° da Z- if ( nSide == -1 or abs(nSide) == 2) and vtN:getZ() <= -0.5 then bCanUseUnderBlade = true end -- se faccia da sotto o di lato ma con versore Z negativo abilito la lavorazione con lame mixate if ( nSide == -1 or abs(nSide) == 2) and vtN:getZ() <= -0.0175 then bCanUseUnderBlade = true end -- se faccia da sopra o di lato ma con versore Z negativo verifico che abbia un angolo compatibile (28deg) per non avere extracorsa if ( nSide == 1 or abs(nSide) == 2) and vtN:getZ() >= -0.4695 then bCanUseBlade = true end end -- introduco messaggi di errore in caso sia settata la lama ma impossibile utilizzarla -- se si toglie questa parte il processo continua utilizzandi però la fresa ma per il vincolo del parametro Q non è possibile if nUseBlade == 2 and not BD.DOWN_HEAD and not bCanUseBlade then local sErr = 'Error, impossible use blade on negative side face' EgtOutLog( sErr) return false, sErr elseif nUseBlade == 1 and not bCanUseBlade then local sErr = 'Error, impossible use blade' EgtOutLog( sErr) return false, sErr elseif nUseBlade == 2 and BD.DOWN_HEAD and not bCanUseBlade and not bCanUseUnderBlade then local sErr = 'Error, impossible use blade' EgtOutLog( sErr) return false, sErr end -- Se non limitato o forzato uso lama e da sopra e richiesto con doppio taglio di lama e superiore al limite minimo if ( ( not bLimXmin and not bLimXmax) or bForceUseBladeOnNotThruFace) and ( bCanUseUnderBlade or bCanUseBlade) and nUseBlade > 0 and b3Solid:getDimX() > dLimMinPiece - 1 then local sCutting local dToolDiam = 0 local dThick = 0 local dMaxDepth = 0 local sCuttingDn local dToolDiamDn = 0 local dThickDn = 0 local dMaxDepthDn = 0 -- recupero la lavorazione if bCanUseUnderBlade then sCuttingDn = ML.FindCutting( 'HeadSide_H2') if not sCuttingDn then local sErr = 'Error : sawing HeadSide_H2 not found in library' EgtOutLog( sErr) return false, sErr end -- recupero i dati dell'utensile if EgtMdbSetCurrMachining( sCuttingDn) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dToolDiamDn = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dToolDiamDn dThickDn = EgtTdbGetCurrToolParam( MCH_TP.THICK) or dThickDn dMaxDepthDn = EgtTdbGetCurrToolMaxDepth() or dMaxDepthDn end end end if bCanUseBlade then local sCutType = EgtIf( BD.USE_LONGCUT, 'LongCut', 'HeadSide') sCutting = ML.FindCutting( sCutType) if not sCutting then local sErr = 'Error : sawing '..sCutType..' not found in library' EgtOutLog( sErr) return false, sErr end -- recupero i dati dell'utensile if EgtMdbSetCurrMachining( sCutting) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dToolDiam dThick = EgtTdbGetCurrToolParam( MCH_TP.THICK) or dThick dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth end end end -- se la fine (a sinistra) non è limitata e ho un pezzo successivo meno distante di metà raggio. setto la fine come limitata if ( bCanUseBlade or bCanUseUnderBlade) and ( dDistToNextPiece < dToolDiam/2 or dDistToNextPiece < dToolDiamDn/2) and not bLimXmin then if bForceUseBladeOnNotThruFace then bForcedLim = true bLimXmin = true else sWarn = 'Warning on saw cut : Cut machining can damage next piece' EgtOutLog( sWarn) end end -- disabilitato la selezione del codolo, prende sempre quello più piccolo. Non cancellare quello disabiliato in caso di ripristino local dDimStrip = BD.DIM_STRIP_SMALL * EgtIf( nSide == -1, -1, 1) -- determino gli estremi local bStartFixed local bEndFixed local dStartAccDist local dStartDist local dEndAccDist local dEndDist local dStartAccDistUp = BD.LONGCUT_ENDLEN local dStartDistUp = 0 local dEndAccDistUp = BD.LONGCUT_ENDLEN local dEndDistUp = 0 local dStartAccDistDn = BD.LONGCUT_ENDLEN local dStartDistDn = 0 local dEndAccDistDn = BD.LONGCUT_ENDLEN local dEndDistDn = 0 if bForceUseBladeOnNotThruFace then if bCanUseBlade then bStartFixed = true if bLimXmax then local dRadius = dToolDiam / 2 local dCat1 = dRadius - ( ( dWidth - dDimStrip) / 2) dStartDistUp = sqrt( ( dRadius * dRadius) - (dCat1 * dCat1)) dStartAccDistUp = BD.LONGCUT_MAXLEN bStartFixed = false end bEndFixed = true if bLimXmin then local dRadius = dToolDiam / 2 local dCat1 = dRadius - ( ( dWidth - dDimStrip) / 2) dEndDistUp = sqrt( ( dRadius * dRadius) - (dCat1 * dCat1)) dEndAccDistUp = BD.LONGCUT_MAXLEN bEndFixed = false end end if bCanUseUnderBlade then bStartFixed = true if bLimXmax then local dRadius = dToolDiamDn / 2 local dCat1 = dRadius - ( ( dWidth - dDimStrip) / 2) dStartDistDn = sqrt( ( dRadius * dRadius) - (dCat1 * dCat1)) dStartAccDistDn = BD.LONGCUT_MAXLEN bStartFixed = false end bEndFixed = true if bLimXmin then local dRadius = dToolDiamDn / 2 local dCat1 = dRadius - ( ( dWidth - dDimStrip) / 2) dEndDistDn = sqrt( ( dRadius * dRadius) - (dCat1 * dCat1)) dEndAccDistDn = BD.LONGCUT_MAXLEN bEndFixed = false end end end local nC local dC local nCUp local dCUp -- determino numero di parti if bCanUseBlade then nCUp = ceil( ( dLen - dStartAccDistUp - dEndAccDistUp) / BD.LONGCUT_MAXLEN) dCUp = 0 if nCUp > 0 then dCUp = ( dLen - dStartAccDistUp - dEndAccDistUp) / nCUp if dCUp < min( dStartAccDistUp, dEndAccDistUp) then dCUp = dLen / ( nCUp + 2) dStartAccDistUp = dCUp dEndAccDistUp = dCUp end nCUp = nCUp + 2 else if dLen > min( dStartAccDistUp, dEndAccDistUp) then nCUp = 2 dStartAccDistUp = dLen/2 dEndAccDistUp = dStartAccDistUp else nCUp = 1 dStartAccDistUp = 0 dEndAccDistUp = 0 end end end local nCDn local dCDn if bCanUseUnderBlade then nCDn = ceil( ( dLen - dStartAccDistDn - dEndAccDistDn) / BD.LONGCUT_MAXLEN) dCDn = 0 if nCDn > 0 then dCDn = ( dLen - dStartAccDistDn - dEndAccDistDn) / nCDn if dCDn < min( dStartAccDistDn, dEndAccDistDn) then dCDn = dLen / ( nCDn + 2) dStartAccDistDn = dCDn dEndAccDistDn = dCDn end nCDn = nCDn + 2 else if dLen > min( dStartAccDistDn, dEndAccDistDn) then nCDn = 2 dStartAccDistDn = dLen/2 dEndAccDistDn = dStartAccDistDn else nCDn = 1 dStartAccDistDn = 0 dEndAccDistDn = 0 end end end -- prendo il valore minimo di passi ( dato dal diametro utensile più grande) if nCUp then nC = nCUp dC = dCUp elseif nCDn then nC = nCDn dC = dCDn end local nFaceUse local nFaceUse2 -- se ho solo lama da sotto if bCanUseUnderBlade and not bCanUseBlade then -- determino l'utilizzo della faccia nFaceUse = EgtIf( abs( vtN:getY()) > 0.01, MCH_MILL_FU.ORTHO_TOP, EgtIf( bFront, MCH_MILL_FU.ORTHO_FRONT, MCH_MILL_FU.ORTHO_BACK)) nFaceUse2 = EgtIf( abs( vtN:getY()) > 0.01, MCH_MILL_FU.ORTHO_DOWN, EgtIf( bFront, MCH_MILL_FU.ORTHO_BACK, MCH_MILL_FU.ORTHO_FRONT)) else -- determino l'utilizzo della faccia nFaceUse = EgtIf( abs( vtN:getY()) > 0.01, MCH_MILL_FU.ORTHO_TOP, EgtIf( bFront, MCH_MILL_FU.ORTHO_BACK, MCH_MILL_FU.ORTHO_FRONT)) nFaceUse2 = EgtIf( abs( vtN:getY()) > 0.01, MCH_MILL_FU.ORTHO_DOWN, EgtIf( bFront, MCH_MILL_FU.ORTHO_FRONT, MCH_MILL_FU.ORTHO_BACK)) end -- si percorrono i lati alto e basso della faccia -- calcolo quanto è l'affondamento del taglio local dOffset = ( dWidth + dDimStrip) / 2 -- se lama da sotto verifico se la componente Y della profondità di taglio supera la capacità della lama if ( nSide == -1 or abs(nSide) == 2) and bCanUseUnderBlade then if (( dWidth - dDimStrip) / 2) > dMaxDepthDn then local sErr = 'Error : side depth is bigger than underneath blade cut depth' EgtOutLog( sErr) return false, sErr end end local nM = 0 -- se abilitata la lavorazione di lama su faccia chiusa, aggiungo le eventuali lavorazioni di antischeggia -- e di asporto dell'impronta lama if bForceUseBladeOnNotThruFace and ( bLimXmin or bLimXmax) then local nCountMilHead = 0 -- determino la massima elevazione local dElev = BL.GetFaceElevation( Proc.Id, 0, nPartId) -- recupero la lavorazione local sMilling if bCanUseUnderBlade then sMilling = ML.FindMilling( 'Long2Cut_H2', dElev) else sMilling = ML.FindMilling( 'Long2Cut', dElev) end if not sMilling then local sErr = 'Error : milling Long2Cut (_H2) not found in library' EgtOutLog( sErr) return false, sErr end -- recupero i dati dell'utensile local dToolDiam = 0 local dMaxDepth = 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 end end -- se ho facce di chiusura, per prima cosa faccio antischeggia -- come richiesto da Fabio Squaratti il 03/09/2021 if ( bLimXmin and not bForcedLim) or bLimXmax then local bOk, nFacet bMadeASbyBld, bOk, sWarn = ManageAntiSplintBySaw( Proc, b3Raw, (( bLimXmin and not bForcedLim) and bLimXmax), vtN, nFacet, 0, sWarn, bCanUseUnderBlade, nil, sCutting) if not bOk then return false, sWarn end end -- eventuale lavorazione della faccia limitante l'inizio if not bStartFixed then local vtIni = -X_AX() for j = 1, Proc.Fct - 1 do local _, vtN = EgtSurfTmFacetCenter( Proc.Id, j, GDB_ID.ROOT) if vtIni * vtN > 0 and nCountMilHead < 2 then MakeSideFace( Proc.Id, j, nSide, sMilling, dToolDiam, nil, max(dStartDistUp,dStartDistDn), bCanUseUnderBlade) nCountMilHead = nCountMilHead + 1 end end if bForcedLim and nCountMilHead < 1 then MakeSideFace( Proc.Id, 0, nSide, sMilling, dToolDiam, bForcedLim, max(dStartDistUp,dStartDistDn), bCanUseUnderBlade) nCountMilHead = nCountMilHead + 1 end end -- eventuale lavorazione della faccia limitante la fine if not bEndFixed then local vtFin = X_AX() for j = 1, Proc.Fct - 1 do local _, vtN = EgtSurfTmFacetCenter( Proc.Id, j, GDB_ID.ROOT) if vtFin * vtN > 0 and nCountMilHead < 2 then MakeSideFace( Proc.Id, j, nSide, sMilling, dToolDiam, nil, max(dEndDistUp,dEndDistDn), bCanUseUnderBlade) nCountMilHead = nCountMilHead + 1 end end if bForcedLim and nCountMilHead < 2 then MakeSideFace( Proc.Id, 0, nSide, sMilling, dToolDiam, bForcedLim, max(dEndDistUp,dEndDistDn), bCanUseUnderBlade) nCountMilHead = nCountMilHead + 1 end end end -- inserisco tagli di lama for i = 1, nC do -- Posizione braccio portatesta local nSCC = EgtIf( ( BD.C_SIMM or 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 local dLioPerp = ( dWidth - dDimStrip) / 2 + BD.CUT_SIC ; local bAddOpposite = true local dAddExtraPerp = 0 -- se faccia da sotto e angolo inferiore ai 12° o faccia di fianco e angolo inferiore a 15° (al di sotto di questo angolo -- l'attacco lama si comporta in modo diverso) allora calcolo il valore perpendicolare con la funzione CalcLeadInOutPerpGeom if ( nSide == -1 and abs(vtN:getY()) >= 0.2079) or ( abs(nSide) == 2 and abs(vtN:getZ()) >= 0.2588) then bAddOpposite = false end -- faccio in modo di calcolare il valore perpendicolare solo sulla faccia da sotto nel secondo passo o sulla faccia di fianco nel primo passo if nSide == 1 or ( nSide == -1 and k == 1) or ( abs(nSide) == 2 and k == 2) then bAddOpposite = false end if bAddOpposite then -- controllo se devo aggiungere un extra all'attacco perpendicolare if nSide == -1 then if vtN:getY() > 0 then dAddExtraPerp = Proc.Box:getMin():getY() - b3Solid:getMin():getY() elseif vtN:getY() < 0 then dAddExtraPerp = b3Solid:getMax():getY() - Proc.Box:getMax():getY() end elseif abs(nSide) == 2 then dAddExtraPerp = Proc.Box:getMin():getZ() - b3Solid:getMin():getZ() end dLioPerp = dLioPerp + dAddExtraPerp ------------------------------------------------------------------------------------------------------- -- disabilito questo calcolo dell'attacco perpendicolare perchè in alcune condizioni genera extra corsa ------------------------------------------------------------------------------------------------------- --[[ -- parametri di attacco/uscita local nOrthoOpposite = nFaceUse2 local b3Box = BBox3d( b3Raw) b3Box:expand( BD.CUT_SIC) -- linea o bilinea di lavorazione (qui uso nOrthoOpposite per ripetere esattamente il calcolo del Mach) local ptP1, ptPm, ptP2, vtV1, vtV2, dLen, dWidth2 = EgtSurfTmFacetOppositeSide( Proc.Id, 0, BL.GetVersRef( nOrthoOpposite), GDB_ID.ROOT) vtV1 = - vtV1 local bInvert = ( ptP2:getZ() < ptP1:getZ() - 100 * GEO.EPS_SMALL) if bInvert then ptP1, ptP2 = ptP2, ptP1 vtV1, vtV2 = vtV2, vtV1 end local vtTg = ptP2 - ptP1 ; vtTg:normalize() -- Versore di riferimento local vtRef = Vector3d( vtTg) local dCutExtra = 0 vtRef:rotate( vtN, EgtIf( bInvert, -90, 90)) local ptP1act = ptP1 local ptP2act = ptP2 _, dLioPerp, _, _ = Fbs.CalcLeadInOutPerpGeom( ptP1act, ptP2act, vtV1, vtV2, vtN, dToolDiam/2, vtRef, dCutExtra, b3Box) ]]-- end -- inserisco le parti di lavorazione nM = nM + 1 local sNameF local nMchFId if ( k == 1 and bCanUseBlade) or ( k == 2 and ( bCanUseBlade and not bCanUseUnderBlade)) then sNameF = 'L2C_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( nM) nMchFId = EgtAddMachining( sNameF, sCutting) if not nMchFId then local sErr = 'Error adding machining ' .. sNameF .. '-' .. sCutting EgtOutLog( sErr) return false, sErr end -- setto le variabili delle distanze dagli estremi dEndDist = dEndDistUp dEndAccDist = dEndAccDistUp dStartDist = dStartDistUp dStartAccDist = dStartAccDistUp elseif ( k == 2 and bCanUseUnderBlade) or ( k == 1 and ( bCanUseUnderBlade and not bCanUseBlade)) then sNameF = 'L2CD_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( nM) nMchFId = EgtAddMachining( sNameF, sCuttingDn) if not nMchFId then local sErr = 'Error adding machining ' .. sNameF .. '-' .. sCuttingDn EgtOutLog( sErr) return false, sErr end -- setto le variabili delle distanze dagli estremi dEndDist = dEndDistDn dEndAccDist = dEndAccDistDn dStartDist = dStartDistDn dStartAccDist = dStartAccDistDn end -- aggiungo geometria EgtSetMachiningGeometry( {{ Proc.Id, 0}}) -- limito opportunamente la lavorazione local dSal = EgtIf( i == nC, -dEndDist, - dEndAccDist - ( nC - i - 1) * dC) local dEal = EgtIf( i == 1, -dStartDist, - dStartAccDist - ( i - 2) * dC) if ( not bFront and k == 1) or ( bFront and k == 2) then dSal, dEal = dEal, dSal end -- se faccia da sotto inverto direzione utensile e profondità -- if nSide == -1 then -- if k == 1 and abs( vtN:getY()) > 0.01 and abs( vtN:getY()) <= 0.866 and abs( vtN:getY()) > 0.707 then -- -- imposto lato di correzione -- EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) -- else -- EgtSetMachiningParam( MCH_MP.TOOLINVERT, true) -- EgtSetMachiningParam( MCH_MP.DEPTH, dThick) -- end -- end if bCanUseBlade and bCanUseUnderBlade then EgtSetMachiningParam( MCH_MP.INVERT, true) EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT) dSal, dEal = dEal, dSal -- imposto uso della faccia EgtSetMachiningParam( MCH_MP.FACEUSE, EgtIf( k == 1, nFaceUse2, nFaceUse)) elseif bCanUseBlade and BD.USE_LONGCUT then EgtSetMachiningParam( MCH_MP.INVERT, true) EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT) dSal, dEal = dEal, dSal -- imposto uso della faccia EgtSetMachiningParam( MCH_MP.FACEUSE, EgtIf( k == 1, nFaceUse2, nFaceUse)) elseif bCanUseUnderBlade then if abs(nSide) ~= 2 then EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) end -- imposto uso della faccia EgtSetMachiningParam( MCH_MP.FACEUSE, EgtIf( k == 1, nFaceUse, nFaceUse2)) else -- imposto uso della faccia EgtSetMachiningParam( MCH_MP.FACEUSE, EgtIf( k == 1, nFaceUse, nFaceUse2)) end EgtSetMachiningParam( MCH_MP.STARTADDLEN, dSal) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal) -- imposto offset radiale EgtSetMachiningParam( MCH_MP.OFFSR, EgtIf( nSide == -1, -dOffset, dOffset)) -- imposto attacco/uscita EgtSetMachiningParam( MCH_MP.LITANG, dLioTang) EgtSetMachiningParam( MCH_MP.LIPERP, dLioPerp) EgtSetMachiningParam( MCH_MP.LOTANG, dLioTang) EgtSetMachiningParam( MCH_MP.LOPERP, dLioPerp) -- 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 if BD.USE_LONGCUT then nSCC = EgtIf( ( bFront and k == 1) or ( not bFront and k == 2), MCH_SCC.ADIR_YP, MCH_SCC.ADIR_YM) else nSCC = EgtIf( ( not bFront and k == 1) or ( bFront and k == 2), MCH_SCC.ADIR_YP, MCH_SCC.ADIR_YM) end end -- imposto posizione braccio porta testa per non ingombrare agli estremi EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end end end -- se non è sotto e non uso fresa di fianco: lavorazione Long2Cut elseif nSide ~= - 1 and nUseMillOnSide == 0 then -- determino la massima elevazione local dElev = BL.GetFaceElevation( Proc.Id, 0, nPartId) -- recupero la lavorazione local sMilling = ML.FindMilling( 'Long2Cut', dElev) if not sMilling then local sErr = 'Error : milling Long2Cut not found in library' EgtOutLog( sErr) return false, sErr end -- recupero i dati dell'utensile local dToolDiam = 0 local dMaxDepth = 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 end end -- se la fine (a sinistra) non è limitata e ho un pezzo successivo meno distante di metà raggio. setto la fine come limitata if dDistToNextPiece < dToolDiam/2 and not bLimXmin then bForcedLim = true bLimXmin = true end -- se chiuso e corto, applico svuotatura con fresa opportuna if bLimXmin and bLimXmax and Proc.Box:getDimX() < 2 * dToolDiam then return MakeByPocketing( Proc, nPhase, nRawId, nPartId) end -- 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 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 numero di parti in cui dividere la lavorazione local nC = ceil( ( dLen - dStartAccDist - dEndAccDist) / BD.LONGCUT_MAXLEN) local dC = 0 if nC > 0 then local nIncStep = 2 if bStartFixed and bEndFixed then dC = ( dLen - dStartAccDist - dEndAccDist) / nC -- se distanza rimanente è < della metà del minimo della distanza estremi allora aggiungo un passo in più local dMinDist = EgtIf( min( dStartAccDist, dEndAccDist) / 2 > 300 , 300, min( dStartAccDist, dEndAccDist) / 2) if dC <= dMinDist then dC = dLen / ( nC + 1) dStartAccDist = dC dEndAccDist = dC nIncStep = 1 elseif dC < min( dStartAccDist, dEndAccDist) then dC = dLen / ( nC + 2) dStartAccDist = dC dEndAccDist = dC end elseif bStartFixed then dC = ( dLen - dStartAccDist) / ( nC + 1) dEndAccDist = dC if dC < dStartAccDist then dC = dLen / ( nC + 2) dStartAccDist = dC dEndAccDist = dC end elseif bEndFixed then dC = ( dLen - dEndAccDist) / ( nC + 1) dStartAccDist = dC if dC < dEndAccDist then dC = dLen / ( nC + 2) dStartAccDist = dC dEndAccDist = dC end else dC = dLen / ( nC + 2) dStartAccDist = dC dEndAccDist = dC end nC = nC + nIncStep 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 -- determino l'utilizzo della faccia local nFaceUse = EgtIf( abs( vtN:getY()) > 0.01, MCH_MILL_FU.ORTHO_DOWN, EgtIf( bFront, MCH_MILL_FU.ORTHO_FRONT, MCH_MILL_FU.ORTHO_BACK)) -- si percorre il lato basso della faccia local nM = 0 local nCountMilHead = 0 for i = 1, nC do -- Posizione braccio portatesta local nSCC 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 -- ciclo sulle passate local nO = 1 local dStep = 0 if dWidth + 2 * BD.CUT_EXTRA > 0.8 * dToolDiam then nO = ceil(( dWidth + 2 * BD.CUT_EXTRA) / ( 0.6 * dToolDiam)) if nO > 1 then dStep = ( dWidth + 2 * BD.CUT_EXTRA) / nO end end for k = nO, 1, -1 do -- inserisco le parti di lavorazione nM = nM + 1 local sNameF = 'L2CH_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( nM) 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( {{ Proc.Id, 0}}) -- limito opportunamente la lavorazione local dSal = EgtIf( i == 1, -dStartDist, - dStartAccDist - ( i - 2) * dC) EgtSetMachiningParam( MCH_MP.STARTADDLEN, dSal) local dEal = EgtIf( i == nC, -dEndDist, - dEndAccDist - ( nC - i - 1) * dC) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal) -- imposto offset radiale EgtSetMachiningParam( MCH_MP.OFFSR, ( k - 1) * dStep - BD.CUT_EXTRA) -- imposto posizione braccio porta testa per non ingombrare agli estremi EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- imposto uso della faccia EgtSetMachiningParam( MCH_MP.FACEUSE, nFaceUse) -- verifico massimo affondamento rispetto ad elevazione if dElev > dMaxDepth + 10 * GEO.EPS_SMALL then sWarn = 'Warning in LongCut : depth (' .. EgtNumToString( dElev, 1) .. ') bigger than max tool depth (' .. EgtNumToString( dMaxDepth, 1) .. ')' end local dDepth = min( 0, dMaxDepth - dElev ) EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end end -- eventuale lavorazione della faccia limitante l'inizio if i == 1 and not bStartFixed then local vtIni = EgtIf( bFront, X_AX(), -X_AX()) for j = 1, Proc.Fct - 1 do local _, vtN = EgtSurfTmFacetCenter( Proc.Id, j, GDB_ID.ROOT) if vtIni * vtN > 0 and nCountMilHead < 2 then MakeSideFace( Proc.Id, j, nSide, sMilling, dToolDiam) nCountMilHead = nCountMilHead + 1 end end if bForcedLim and nCountMilHead < 1 then MakeSideFace( Proc.Id, 0, nSide, sMilling, dToolDiam, bForcedLim) nCountMilHead = nCountMilHead + 1 end end end -- eventuale lavorazione della faccia limitante la fine if not bEndFixed then local vtFin = EgtIf( bFront, -X_AX(), X_AX()) for j = 1, Proc.Fct - 1 do local _, vtN = EgtSurfTmFacetCenter( Proc.Id, j, GDB_ID.ROOT) if vtFin * vtN > 0 and nCountMilHead < 2 then MakeSideFace( Proc.Id, j, nSide, sMilling, dToolDiam) nCountMilHead = nCountMilHead + 1 end end if bForcedLim and nCountMilHead < 2 then MakeSideFace( Proc.Id, 0, nSide, sMilling, dToolDiam, bForcedLim) nCountMilHead = nCountMilHead + 1 end end -- altrimenti è da sotto ( lavorazione Long2CutDown) o abilitata lavorazione con fresa di fianco ( lavorazione Long2CutSide) else -- da Analisi con Fabio Squaratti 15/09/2020 -- variabile che indica se ripassare sul raggio rimasto dalla lavorazione di fianco local bRemoveToolRadius -- se nExtendMach = 0 la lavorazione rimane arretrata dalla fine della faccia del raggio utensile -- se nExtendMach = 1 la lavorazione arriva fino alla fine faccia (se non ha facce limite) ignorando il pezzo successivo -- se nExtendMach = 2 la lavorazione viene estesa ma arretra per non segnare il pezzo successivo (se non ha facce limite) local nExtendMach -- recupero la lavorazione local sMilling local sMillingDn local sPrefix local sPrefixDn if nSide ~= - 1 then sMilling = ML.FindMilling( 'Long2CutSide') sPrefix = 'L2CS_' nExtendMach = nUseMillOnSide if nUseMillOnSide == 2 then bRemoveToolRadius = true end -- se testa da sotto if nSide ~= 1 and BD.DOWN_HEAD then sMillingDn = ML.FindMilling( 'Long2CutSide_H2') sPrefixDn = 'L2CSH2_' end -- lavorazione da sotto else sMilling = ML.FindMilling( 'Long2CutDown') sPrefix = 'L2CD_' nExtendMach = 1 if nUseMillOnSide ~= 1 then nExtendMach = 2 -- arretro il minimo indispensabile per non segnare il pezzo successivo (se non ha facce limite) end -- se testa da sotto if BD.DOWN_HEAD then sMillingDn = ML.FindMilling( 'Long2CutDown_H2') sPrefixDn = 'L2CDH2_' end end if not sMilling then local sErr = 'Error : milling Long2CutSide or Long2CutDown not found in library' EgtOutLog( sErr) return false, sErr end if nSide ~= 1 and BD.DOWN_HEAD and not sMillingDn then local sErr = 'Error : milling Long2CutSide_H2 or Long2CutDown_H2 not found in library' EgtOutLog( sErr) return false, sErr end -- recupero i dati dell'utensile local dToolDiam = 0 local dToolLength = 0 local dMaxDepth = 0 local dThDiam = 0 local dThLen = 0 local dExtraForSafety = EgtIf( BD.DOWN_HEAD, 8.5, 6.5) -- corrisponde al doppio valore di sicurezza dell'mlpe + 0.5 -- local dExtraForSafetyDn = 8.5 -- 8.5 -- corrisponde al doppio valore di sicurezza dell'mlpe + 0.5 if EgtMdbSetCurrMachining( sMilling) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dToolDiam dToolLength = EgtTdbGetCurrToolParam( MCH_TP.LEN) or dToolLength dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth dThDiam = ( EgtTdbGetCurrToolThDiam() or dThDiam) dThLen = EgtTdbGetCurrToolThLength() or dThLen end end -- recupero i dati dell'utensile da sotto local dToolDiamDn = 0 local dToolLengthDn = 0 local dMaxDepthDn = 0 local dThDiamDn = 0 local dThLenDn = 0 if nSide ~= 1 and BD.DOWN_HEAD and EgtMdbSetCurrMachining( sMillingDn) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dToolDiamDn = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dToolDiamDn dToolLengthDn = EgtTdbGetCurrToolParam( MCH_TP.LEN) or dToolLengthDn dMaxDepthDn = EgtTdbGetCurrToolMaxDepth() or dMaxDepthDn dThDiamDn = (EgtTdbGetCurrToolThDiam() or dThDiamDn) dThLenDn = EgtTdbGetCurrToolThLength() or dThLenDn end end local dDistToEnd = dToolDiam / 2 local dDistToEndDn = dToolDiamDn / 2 -- calcolo l'elevazione della faccia principale local dFacElev = BL.GetFaceElevation( Proc.Id, 0, nPartId) -- se fresa di fianco o da sotto calcolo quanto l'utensile può andare vicino al limite se l'elevazione della faccia è minore del raggio utensile if nUseMillOnSide <= 1 or nSide == -1 then if dFacElev < dDistToEnd then dDistToEnd = sqrt( ( ( dToolDiam / 2) * ( dToolDiam / 2)) - ( ( dToolDiam / 2 - dFacElev) * (dToolDiam / 2 - dFacElev))) end if dFacElev < dDistToEndDn then dDistToEndDn = sqrt( ( ( dToolDiamDn / 2) * ( dToolDiamDn / 2)) - ( ( dToolDiamDn / 2 - dFacElev) * (dToolDiamDn / 2 - dFacElev))) end end -- se la fine è già limitata allora setto per arretrare del raggio utensile if bLimXmin then nExtendMach = 0 -- se la fine non è limitata e ho un pezzo successivo distante meno di metà raggio. setto la fine come limitata elseif ( dDistToNextPiece < dDistToEnd or dDistToNextPiece < dDistToEndDn) and nExtendMach ~= 1 then bLimXmin = true end -- larghezza faccia local _, _, dWidth = BL.GetFaceHvRefDim( Proc.Id, 0) -- aggiuntivo sull'affondamento local dAgg = BD.CUT_EXTRA -- determino gli estremi local dStartDist = 0 local dStartAccDist = BD.LONGCUT_ENDLEN local bStartFixed = true if ( bLimXmin and bFront) or ( bLimXmax and not bFront) then if ( bLimXmin and bFront) then dStartDist = EgtIf( nExtendMach == 2, dDistToEnd - dDistToNextPiece + 0.5, dDistToEnd) else dStartDist = dDistToEnd end dStartAccDist = BD.LONGCUT_MAXLEN bStartFixed = false end local dEndDist = 0 local dEndAccDist = BD.LONGCUT_ENDLEN local bEndFixed = true if ( bLimXmin and not bFront) or ( bLimXmax and bFront) then if ( bLimXmin and not bFront) then dEndDist = EgtIf( nExtendMach == 2, dDistToEnd - dDistToNextPiece + 0.5, dDistToEnd) else dEndDist = dDistToEnd end 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 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 -- verifico se posso farlo da due parti opposte o da solo una parte local dCollSic local dCollSicMin local dCollSicDn local dCollSicMinDn local dDepth local dDepthDn local dDepth2 local dDepth2Dn local nPass = 1 local dNz = EgtIf( abs(nSide) == 1, vtN:getY(), vtN:getZ()) local dNzMin = EgtIf( abs(vtN:getY()) >= abs(vtN:getZ()), vtN:getY(), vtN:getZ()) -- se faccia da sopra e angolo 45° o faccia da sotto e angolo 40° (con singola testa ) o faccia non da sopra e testa da sotto -- permette di eseguire due lavorazioni opposte if ( nSide == 1 and abs(vtN:getY()) <= 0.7072) or ( nSide == -1 and not BD.DOWN_HEAD and abs(vtN:getY()) < 0.6428) or ( nSide ~= 1 and BD.DOWN_HEAD) then -- verifico massimo affondamento (tengo conto dell'inclinazione utensile e della pinza con estremità conica) -- 08/09/2020 tolti i 3mm ( per la ghiera smussata) perchè nella verifica collisione vine creato un cilindro non smussato che rileva la collisione local dSicOnRad local dSicOnLegth if ( abs(nSide) == 1 and abs(vtN:getZ()) >= abs(vtN:getY())) or ( abs(nSide) == 2 and abs(vtN:getY()) >= abs(vtN:getZ())) then dSicOnRad = ( dThDiam + dExtraForSafety - dToolDiam) / 2 dSicOnLegth = 0 else dSicOnRad = ( dThDiam - dToolDiam) / 2 dSicOnLegth = dExtraForSafety / 2 end dCollSicMin = max( BD.COLL_SIC, ( dThDiam - dToolDiam) / 2 * abs( EgtIf( abs(vtN:getY()) >= abs(vtN:getZ()), vtN:getZ(), vtN:getY()) / dNzMin)) if bLarghAsFace then dCollSic = max( BD.COLL_SIC, dSicOnRad * abs( EgtIf( abs(vtN:getY()) >= abs(vtN:getZ()), vtN:getZ(), vtN:getY()) / dNzMin) + dSicOnLegth) else dCollSic = max( BD.COLL_SIC, dSicOnRad * EgtIf( abs(dNz) < GEO.EPS_SMALL, 1, abs( EgtIf( abs(nSide) == 1, vtN:getZ(), vtN:getY()) / dNz)) + dSicOnLegth) end if nSide ~= 1 and BD.DOWN_HEAD then local dSicOnRadDn local dSicOnLegthDn if ( abs(nSide) == 1 and abs(vtN:getZ()) >= abs(vtN:getY())) or ( abs(nSide) == 2 and abs(vtN:getY()) >= abs(vtN:getZ())) then dSicOnRadDn = ( dThDiamDn + dExtraForSafety - dToolDiamDn) / 2 dSicOnLegthDn = 0 else dSicOnRadDn = ( dThDiamDn - dToolDiamDn) / 2 dSicOnLegthDn = dExtraForSafety / 2 end dCollSicMinDn = max( BD.COLL_SIC, ( dThDiamDn - dToolDiamDn) / 2 * abs( EgtIf( abs(vtN:getY()) >= abs(vtN:getZ()), vtN:getZ(), vtN:getY()) / dNzMin)) if bLarghAsFace then dCollSicDn = max( BD.COLL_SIC, dSicOnRadDn * abs( EgtIf( abs(vtN:getY()) >= abs(vtN:getZ()), vtN:getZ(), vtN:getY()) / dNzMin) + dSicOnLegthDn) else dCollSicDn = max( BD.COLL_SIC, dSicOnRadDn * EgtIf( abs(dNz) < GEO.EPS_SMALL, 1, abs( EgtIf( abs(nSide) == 1, vtN:getZ(), vtN:getY()) / dNz)) + dSicOnLegthDn) end if dWidth + dAgg > dMaxDepth - dCollSic then nPass = 2 dAgg = 1 if ( 0.5 * dWidth) + dAgg > dMaxDepth - dCollSic then sWarn = 'Warning in LongCut : depth is bigger than max tool depth' end end if nPass == 1 and dWidth + dAgg > dMaxDepthDn - dCollSicDn then nPass = 2 dAgg = 1 if ( 0.5 * dWidth) + dAgg > dMaxDepthDn - dCollSicDn then sWarn = 'Warning in LongCut_2 : depth is bigger than max tool depth' end end else if dWidth + dAgg > dMaxDepth - dCollSic then nPass = 2 dAgg = 1 if ( 0.5 * dWidth) + dAgg > dMaxDepth - dCollSic then sWarn = 'Warning in LongCut : depth is bigger than max tool depth' end end end else -- verifico massimo affondamento (tengo conto dell'inclinazione utensile e della pinza con estremità conica) -- 08/09/2020 tolti i 3mm ( per la ghiera smussata) perchè nella verifica collisione vine creato un cilindro non smussato che rileva la collisione local dSicOnRad local dSicOnLegth if ( abs(nSide) == 1 and abs(vtN:getZ()) >= abs(vtN:getY())) or ( abs(nSide) == 2 and abs(vtN:getY()) >= abs(vtN:getZ())) then dSicOnRad = ( dThDiam + dExtraForSafety - dToolDiam) / 2 dSicOnLegth = 0 else dSicOnRad = ( dThDiam - dToolDiam) / 2 dSicOnLegth = dExtraForSafety / 2 end dCollSicMin = max( BD.COLL_SIC, ( dThDiam - dToolDiam) / 2 * abs( EgtIf( abs(vtN:getY()) >= abs(vtN:getZ()), vtN:getZ(), vtN:getY()) / dNzMin)) -- dCollSic = max( BD.COLL_SIC, dSicOnRad * EgtIf( abs(dNz) < GEO.EPS_SMALL, 1, abs( EgtIf( abs(nSide) == 1, vtN:getY(), vtN:getZ()) / dNz)) + dSicOnLegth) dCollSic = max( BD.COLL_SIC, dSicOnRad * abs( EgtIf( abs(vtN:getY()) >= abs(vtN:getZ()), vtN:getZ(), vtN:getY()) / dNzMin) + dSicOnLegth) if dWidth + dAgg > dMaxDepth - dCollSic then sWarn = 'Warning in LongCut : depth is bigger than max tool depth' end end -- profondità prima passata dDepth = min( dMaxDepth - dCollSicMin, dWidth + dAgg) -- profondità seconda passata dDepth2 = dWidth + dAgg - dDepth if not BD.DOWN_HEAD then if nPass == 2 and dDepth2 < dAgg then dDepth = min( dMaxDepth - dCollSicMin, dWidth + dAgg) / 2 dDepth2 = dWidth + dAgg - dDepth end end if nSide ~= 1 and BD.DOWN_HEAD then dDepthDn = min( dMaxDepthDn - dCollSicMinDn, dWidth + dAgg) dDepth2Dn = dWidth + dAgg - EgtIf( abs(nSide) == 2, dDepth, dDepthDn) if nPass == 2 and dDepth2Dn < dAgg then dDepthDn = min( dMaxDepthDn - dCollSicMinDn, dWidth + dAgg) / 2 dDepth2Dn = dWidth + dAgg - EgtIf( abs(nSide) == 2, dDepth, dDepthDn) end end -- ciclo sulle parti local nM = 0 local bMakeMillHeadEnd local bMakeMillHeadStart local dLioPerp1 = dFacElev + BD.COLL_SIC -- local dLioPerp2 = dWidth + BD.COLL_SIC local dLioPerp2 = dWidth * EgtIf( abs(dNz) < GEO.EPS_SMALL, 1, sqrt( 1 - dNz * dNz) / abs( dNz)) + BD.COLL_SIC -- valore sovrapposizione tra passate local dOverLapExtend = 2 for j = 1, nC do -- Limitazioni della lavorazione local nPos = EgtIf( bFront, j, nC - j + 1) 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 dExtraElev_1st = 0 local dExtraElevDn_1st = 0 for k = 1, nPass do -- if EgtIf( k == 1, bFront, not bFront) then 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 -- inserisco le parti di lavorazione nM = nM + 1 local sNameF local nMchFId if BD.DOWN_HEAD and k == 2 and nSide ~= 1 then sNameF = sPrefixDn .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( nM) nMchFId = EgtAddMachining( sNameF, sMillingDn) if not nMchFId then local sErr = 'Error adding machining ' .. sNameF .. '-' .. sMillingDn EgtOutLog( sErr) return false, sErr end else sNameF = sPrefix .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( nM) nMchFId = EgtAddMachining( sNameF, sMilling) if not nMchFId then local sErr = 'Error adding machining ' .. sNameF .. '-' .. sMilling EgtOutLog( sErr) return false, sErr end end -- aggiungo geometria EgtSetMachiningGeometry( {{ Proc.Id, 0}}) -- imposto posizione braccio porta testa per non ingombrare agli estremi EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- imposto uso faccia local nUseFace = MCH_MILL_FU.PARAL_DOWN if AreSameOrOppositeVectorApprox( vtN, Z_AX()) then nUseFace = MCH_MILL_FU.PARAL_BACK end EgtSetMachiningParam( MCH_MP.FACEUSE, nUseFace) -- imposto lato di lavoro e inversione if k == 1 then EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) EgtSetMachiningParam( MCH_MP.INVERT, true) else EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) EgtSetMachiningParam( MCH_MP.INVERT, false) EgtSetMachiningParam( MCH_MP.TOOLINVERT, true) dSal, dEal = dEal, dSal end -- limito opportunamente la lavorazione EgtSetMachiningParam( MCH_MP.STARTADDLEN, dSal) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEal) -- assegno affondamento local dExtraElev = 0 local dExtraElevDn = 0 if not BD.DOWN_HEAD then -- se prima lavorazione non da sotto o seconda lavorazione da sotto e componente Y <= 60° e > 0 if ( ( k == 1 and nSide ~= -1) or ( k == 2 and nSide == -1)) and abs(vtN:getY()) <= 0.866 and abs(vtN:getY()) > GEO.EPS_SMALL then -- verifico se può collidere in base alle dimensione del portapezzo local dDistToolTh = (dToolLength - EgtIf( k == 1, dDepth, ( dDepth2 + dExtraElev_1st)) - dThLen) / abs(vtN:getZ()) local dDistRadTh = dDistToolTh * abs(vtN:getY()) local dDistSurf = EgtIf( bFront, b3Solid:getMax():getY() - Proc.Box:getMax():getY(), Proc.Box:getMin():getY() - b3Solid:getMin():getY()) -- raggio portautensile e raggio utensile allora calcolo un arretramento profondità if dDistSurf > dDistToolTh and dDistRadTh < (( dThDiam - dToolDiam) / 2) then -- se devo premiare extra sicurezza su lunghezza utensile if abs(vtN:getY()) > abs(vtN:getZ()) then dExtraElev = ((( dThDiam - dToolDiam) / 2) - dDistRadTh) * abs(vtN:getZ()) / abs(vtN:getY()) + ( 0.5 * dExtraForSafety) / abs(vtN:getY()) -- altrimenti premio extra sicurezza su raggio utensile else dExtraElev = ((( dThDiam + dExtraForSafety - dToolDiam) / 2) - dDistRadTh) * abs(vtN:getZ()) / abs(vtN:getY()) end elseif abs(dDistSurf) > GEO.EPS_SMALL then if nSide ~= -1 then dDistSurf = b3Solid:getMax():getZ() - Proc.Box:getMax():getZ() else dDistSurf = Proc.Box:getMin():getZ() - b3Solid:getMin():getZ() end if dDistSurf * abs(vtN:getZ()) > (( dThDiam + dToolDiam) * 0.5) then dExtraElev = dDistSurf * abs(vtN:getY()) end end -- altrimenti prima lavorazione di fianco con componente Z negativa elseif k == 1 and abs(nSide) == 2 and vtN:getZ() > -0.866 and vtN:getZ() < - GEO.EPS_SMALL then -- verifico se può collidere in base alle dimensione del portapezzo local dDistToolTh = (dToolLength - dDepth - dThLen) / abs(vtN:getY()) local dDistRadTh = dDistToolTh * abs(vtN:getZ()) local dDistSurf = b3Solid:getMax():getZ() - Proc.Box:getMax():getZ() -- raggio portautensile e raggio utensile allora calcolo un arretramento profondità if dDistSurf > dDistToolTh and dDistRadTh < (( dThDiam - dToolDiam) / 2) then -- se devo premiare extra sicurezza su lunghezza utensile if abs(vtN:getY()) > abs(vtN:getZ()) then dExtraElev = ((( dThDiam - dToolDiam) / 2) - dDistRadTh) * abs(vtN:getY()) / abs(vtN:getZ()) + ( 0.5 * dExtraForSafety) / abs(vtN:getZ()) -- altrimenti premio extra sicurezza su raggio utensile else dExtraElev = ((( dThDiam + dExtraForSafety - dToolDiam) / 2) - dDistRadTh) * abs(vtN:getY()) / abs(vtN:getZ()) end elseif abs( dDistSurf) < GEO.EPS_SMALL then if bFront then dDistSurf = Proc.Box:getMin():getY() - b3Solid:getMin():getY() else dDistSurf = b3Solid:getMax():getY() - Proc.Box:getMax():getY() end if dDistSurf * abs(vtN:getY()) > (( dThDiam + dToolDiam) * 0.5) then dExtraElev = dDistSurf * abs(vtN:getZ()) end end end -- altrimenti con testa da sotto else -- se prima lavorazione non da sotto e componente y <= 60° e > 0 if ( k == 1 and nSide ~= -1) and abs(vtN:getY()) <= 0.866 and abs(vtN:getY()) > GEO.EPS_SMALL then -- verifico se può collidere in base alle dimensione del portapezzo local dDistToolTh = (dToolLength - dDepth - dThLen) / abs(vtN:getZ()) local dDistRadTh = dDistToolTh * abs(vtN:getY()) local dDistSurf = EgtIf( bFront, b3Solid:getMax():getY() - Proc.Box:getMax():getY(), Proc.Box:getMin():getY() - b3Solid:getMin():getY()) -- raggio portautensile e raggio utensile allora calcolo un arretramento profondità if dDistSurf > dDistToolTh and dDistRadTh < (( dThDiam - dToolDiam) * 0.5) then -- se devo premiare extra sicurezza su lunghezza utensile if abs(vtN:getZ()) > abs(vtN:getY()) then dExtraElev = ((( dThDiam - dToolDiam) * 0.5) - dDistRadTh) * abs(vtN:getZ()) / abs(vtN:getY()) + ( 0.5 * dExtraForSafety) / abs(vtN:getY()) -- altrimenti premio extra sicurezza su raggio utensile else dExtraElev = ((( dThDiam + dExtraForSafety - dToolDiam) * 0.5) - dDistRadTh) * abs(vtN:getZ()) / abs(vtN:getY()) end elseif abs(dDistSurf) < GEO.EPS_SMALL then dDistSurf = b3Solid:getMax():getZ() - Proc.Box:getMax():getZ() if dDistSurf * vtN:getZ() > (( dThDiam + dToolDiam) * 0.5) then dExtraElev = dDistSurf * abs(vtN:getY()) end end -- se seconda lavorazione sopra e componente Z > 0 elseif k == 2 and nSide == 1 and vtN:getZ() > GEO.EPS_SMALL then local dDistToolTh = (dToolLength - ( dDepth2 + dExtraElev_1st) - dThLen) / abs(vtN:getY()) local dDistRadTh = dDistToolTh * abs(vtN:getZ()) local dDistSurf = Proc.Box:getMin():getZ() - b3Solid:getMin():getZ() -- raggio portautensile e raggio utensile allora calcolo un arretramento profondità if dDistSurf > dDistToolTh and dDistRadTh < (( dThDiam - dToolDiam) * 0.5) then -- premio extra sicurezza su lunghezza utensile if abs(vtN:getZ()) > abs(vtN:getY()) then dExtraElev = ((( dThDiam - dToolDiam) * 0.5) - dDistRadTh) * abs(vtN:getY()) / abs(vtN:getZ()) + ( 0.5 * dExtraForSafety) / vtN:getZ() -- altrimenti premio extra sicurezza su raggio utensile else dExtraElev = ((( dThDiam + dExtraForSafety - dToolDiam) * 0.5) - dDistRadTh) * abs(vtN:getY()) / abs(vtN:getZ()) end end -- se prima lavorazione di fianco e componente Z > 0 elseif k == 1 and abs(nSide) == 2 and vtN:getZ() < GEO.EPS_SMALL then local dDistToolTh = (dToolLength - dDepth - dThLen) / abs(vtN:getY()) local dDistRadTh = dDistToolTh * abs(vtN:getZ()) local dDistSurf = b3Solid:getMax():getZ() - Proc.Box:getMax():getZ() -- raggio portautensile e raggio utensile allora calcolo un arretramento profondità if dDistSurf > dDistToolTh and dDistRadTh < (( dThDiam - dToolDiam) * 0.5) then -- se devo premiare extra sicurezza su lunghezza utensile if abs(vtN:getY()) > abs(vtN:getZ()) then dExtraElev = (dDistSurf - dDistToolTh + ( 0.5 * dExtraForSafety)) / abs(vtN:getY()) -- altrimenti premio extra sicurezza su raggio utensile else dExtraElev = (( dThDiam - dToolDiam) * 0.5) * abs(vtN:getY()) / abs(vtN:getZ()) - (dToolLength - dDepth - dThLen) + ( 0.5 * dExtraForSafety) / abs(vtN:getZ()) end elseif abs(dDistSurf) < GEO.EPS_SMALL then if bFront then dDistSurf = Proc.Box:getMin():getY() - b3Solid:getMin():getY() else dDistSurf = b3Solid:getMax():getY() - Proc.Box:getMax():getY() end if dDistSurf * abs(vtN:getY()) > (( dThDiam + dToolDiam) * 0.5) then dExtraElev = dDistSurf * abs(vtN:getZ()) end end -- se seconda lavorazione di fianco e componente Z > 0 elseif k == 2 and abs(nSide) == 2 and vtN:getZ() > GEO.EPS_SMALL then local dDistToolThDn = (dToolLengthDn - ( dDepth2Dn + dExtraElevDn_1st) - dThLenDn) / abs(vtN:getY()) local dDistRadThDn = dDistToolThDn * abs(vtN:getZ()) local dDistSurfDn = Proc.Box:getMin():getZ() - b3Solid:getMin():getZ() -- raggio portautensile e raggio utensile allora calcolo un arretramento profondità if dDistSurfDn > dDistToolThDn and dDistRadThDn < (( dThDiamDn - dToolDiamDn) * 0.5) then -- se devo premiare extra sicurezza su lunghezza utensile if abs(vtN:getY()) > abs(vtN:getZ()) then dExtraElevDn = ((( dThDiamDn - dToolDiamDn) * 0.5) - dDistRadThDn) * abs(vtN:getY()) / abs(vtN:getZ()) + ( 0.5 * dExtraForSafety) / vtN:getZ() -- altrimenti premio extra sicurezza su raggio utensile else dExtraElevDn = ((( dThDiamDn + dExtraForSafety - dToolDiamDn) * 0.5) - dDistRadThDn) * abs(vtN:getY()) / abs(vtN:getZ()) end elseif abs(dDistSurfDn) < GEO.EPS_SMALL then if bFront then dDistSurfDn = Proc.Box:getMin():getY() - b3Solid:getMin():getY() else dDistSurfDn = b3Solid:getMax():getY() - Proc.Box:getMax():getY() end if dDistSurfDn * abs(vtN:getY()) > (( dThDiamDn + dToolDiamDn) * 0.5) then dExtraElevDn = dDistSurfDn * abs(vtN:getZ()) end end -- se seconda lavorazione da sotto a componente Y < 60° e Y > 0 elseif ( k == 2 and nSide == -1) and abs(vtN:getY()) <= 0.866 and abs(vtN:getY()) > GEO.EPS_SMALL then -- verifico se può collidere in base alle dimensione del portapezzo local dDistToolThDn = (dToolLengthDn - ( dDepth2Dn + dExtraElevDn_1st) - dThLenDn) / abs(vtN:getY()) local dDistRadThDn = dDistToolThDn * abs(vtN:getZ()) local dDistSurfDn = EgtIf( bFront, b3Solid:getMax():getY() - Proc.Box:getMax():getY(), Proc.Box:getMin():getY() - b3Solid:getMin():getY()) -- raggio portautensile e raggio utensile allora calcolo un arretramento profondità if dDistSurfDn > dDistToolThDn and dDistRadThDn < (( dThDiamDn - dToolDiamDn) * 0.5) then -- se devo premiare extra sicurezza su lunghezza utensile if abs(vtN:getZ()) > abs(vtN:getY()) then dExtraElevDn = ((( dThDiamDn - dToolDiamDn) * 0.5) - dDistRadThDn) * abs(vtN:getY()) / abs(vtN:getZ()) + ( 0.5 * dExtraForSafety) / abs(vtN:getY()) -- altrimenti premio extra sicurezza su raggio utensile else dExtraElevDn = ((( dThDiamDn + dExtraForSafety - dToolDiamDn) * 0.5) - dDistRadThDn) * abs(vtN:getY()) / abs(vtN:getZ()) end elseif abs(dDistSurfDn) < GEO.EPS_SMALL then dDistSurfDn = Proc.Box:getMin():getZ() - b3Solid:getMin():getZ() if dDistSurfDn * abs(vtN:getZ()) > (( dThDiamDn + dToolDiamDn) * 0.5) then dExtraElevDn = dDistSurfDn * abs(vtN:getY()) end end end end if BD.DOWN_HEAD and k == 2 and nSide ~= 1 then EgtSetMachiningParam( MCH_MP.DEPTH, dDepth2Dn - dExtraElevDn) dExtraElevDn_1st = dExtraElevDn if dExtraElevDn > 0 and sWarn and #sWarn < 1 then sWarn = 'Warning in LongCut_2 : depth is bigger than max tool depth' end else EgtSetMachiningParam( MCH_MP.DEPTH, EgtIf( k == 1, dDepth, dDepth2) - dExtraElev) dExtraElev_1st = dExtraElev if dExtraElev > 0 and sWarn and #sWarn < 1 then sWarn = 'Warning in LongCut : depth is bigger than max tool depth' end end -- assegbo attacco perpendicolare EgtSetMachiningParam( MCH_MP.LIPERP, dLioPerp1) EgtSetMachiningParam( MCH_MP.LOPERP, dLioPerp1) -- eseguo if not EgtApplyMachining( true, false) then -- se feature orientata su faccia da sotto provo a cambiare l'attacco if nSide == -1 then EgtSetMachiningParam( MCH_MP.LIPERP, min( dLioPerp1, dLioPerp2)) EgtSetMachiningParam( MCH_MP.LOPERP, min( dLioPerp1, dLioPerp2)) if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) -- esco se non sono nella seconda lavorazione o non nella faccia da sotto if k < 2 or ( nSide ~= - 1 and not BD.DOWN_HEAD) then return false, sErr end end else local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) -- esco se non sono nella seconda lavorazione o non nella faccia da sotto if k < 2 or ( nSide ~= - 1 and not BD.DOWN_HEAD) then return false, sErr end end end -- eventuale lavorazione della faccia limitante la fine if j == EgtIf( bFront , 1, nC) and not bEndFixed and bRemoveToolRadius then local vtFin = EgtIf( bFront, -X_AX(), X_AX()) for i = 1, Proc.Fct - 1 do local _, vtN = EgtSurfTmFacetCenter( Proc.Id, i, GDB_ID.ROOT) if vtFin * vtN > 0 and not bMakeMillHeadEnd then MakeSideFace( Proc.Id, i, nSide, sMilling, dToolDiam) bMakeMillHeadEnd = true end end if bRemoveToolRadius and not bMakeMillHeadEnd then MakeSideFace( Proc.Id, 0, nSide, sMilling, dToolDiam, bRemoveToolRadius) end end -- eventuale lavorazione della faccia limitante l'inizio if j == EgtIf( bFront , nC, 1) and not bStartFixed and bRemoveToolRadius then local vtIni = EgtIf( bFront, X_AX(), -X_AX()) for i = 1, Proc.Fct - 1 do local _, vtN = EgtSurfTmFacetCenter( Proc.Id, i, GDB_ID.ROOT) if vtIni * vtN > 0 and not bMakeMillHeadStart then MakeSideFace( Proc.Id, i, nSide, sMilling, dToolDiam) bMakeMillHeadStart = true end end if bRemoveToolRadius and not bMakeMillHeadStart then MakeSideFace( Proc.Id, 0, nSide, sMilling, dToolDiam, bRemoveToolRadius) end end end end end return true, sWarn end --------------------------------------------------------------------- return ProcessLongCut